Getting the active window when resizing [PB5.20]

Linux specific forum
TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Getting the active window when resizing [PB5.20]

Post 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
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

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

Post 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() ;
Windows 11, Manjaro, Raspberry Pi OS
Image
TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

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

Post 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
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

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

Post 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
Windows 11, Manjaro, Raspberry Pi OS
Image
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

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

Post 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
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply