Page 1 of 1

Getting the active window when resizing [PB5.20]

Posted: Thu Sep 26, 2013 4:46 am
by TassyJim
This code works as expected under Windows.
The active window is the same for 'normal' events and resizing.
Under Linux (Kubuntu 12.04), the active window during resizing is -1
The other events return '0' which is correct.

Code: Select all

If OpenWindow(0, 0, 0, 230, 190, "Event handling example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered  |#PB_Window_SizeGadget)

   ButtonGadget  (1, 10, 10, 200, 20, "Click me")
   CheckBoxGadget(2, 10, 40, 200, 20, "Check me")
   If CreateMenu(0, WindowID(0))
     MenuTitle("Menu")
     MenuItem(1, "Item 1")
     MenuItem(2, "Item 2")
     MenuItem(3, "Item 3")
   EndIf

   Repeat
     Event = WaitWindowEvent()
     
     Select Event
       Case #PB_Event_SizeWindow
         Debug "Window resized, Window: "+GetActiveWindow()
         
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 1 : Debug "Button 1 clicked!, Window: "+GetActiveWindow()
           Case 2 : Debug "Button 2 clicked!, Window: "+GetActiveWindow()
         EndSelect
       
       Case #PB_Event_Menu
         Select EventMenu()
           Case 1 : Debug "Menu item 1 clicked!, Window: "+GetActiveWindow()
           Case 2 : Debug "Menu item 2 clicked!, Window: "+GetActiveWindow()
           Case 3 : Debug "Menu item 3 clicked!, Window: "+GetActiveWindow()
         EndSelect
     
     EndSelect
   Until Event = #PB_Event_CloseWindow
 EndIf
Is this a normal Linux thing and is there a solution?

Jim

Re: Getting the active window when resizing [PB5.20]

Posted: Thu Sep 26, 2013 5:56 am
by idle
Jim might be better to use EventWindow in this case
the problem is probably a linux quirk but it might also be a bug

Code: Select all

 Repeat
     Event = WaitWindowEvent()
     EventWindow = EventWindow()
     Select Event
       Case #PB_Event_SizeWindow
         Debug "Window resized, Window: "+ EventWindow() ;

Re: Getting the active window when resizing [PB5.20]

Posted: Thu Sep 26, 2013 6:07 am
by TassyJim
Thanks,
I had just realised that EventWindow() was a better choice and it works the same for Windows and Linux.

Writing for both systems is more complicated/annoying than I was hoping.

Jim

Re: Getting the active window when resizing [PB5.20]

Posted: Thu Sep 26, 2013 6:11 am
by idle
yes can be a bit of a challenge, get it working on linux first
and it will likely work on windows without any change

Re: Getting the active window when resizing [PB5.20]

Posted: Thu Sep 26, 2013 4:18 pm
by BorisTheOld
TassyJim wrote:Writing for both systems is more complicated/annoying than I was hoping.
Actually, we've found it to be very easy, but it's sometimes necessary to be a little creative. Such as using the Canvas gadget to create replacements for some of the PB gadgets, so that we could get access to more events.

Idle's suggestion is the way to go.

We're a Linux shop and use PB to create cross-platform apps for Linux and Windows. Even though our apps only use one window, we found that we had to pick up EventWindow. And just to be on the safe side, we filter out anything that appears not to be for our one and only window.

The resulting code works perfectly for both Linux and Windows.

Code: Select all

  Repeat

    iWindowEvent  = WaitWindowEvent()       ; get an event
    iWindowNumber = EventWindow()           ; get the window number of the event
    
    If exiWindowNumber <> iWindowNumber
      Continue                              ; ignore the event if not for the application window
    EndIf

    Select iWindowEvent
        .
        .
        .
    EndSelect
    
  ForEver