PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Linux specific forum
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by marcoagpinto »

Heya,

Sorry for bringing this back again, but it still doesn't work on Ubuntu 24.04.

The help documentation states:

Code: Select all

#PB_Window_Maximize      : Opens the window maximized. (Note: on Linux, not all Windowmanagers support this)
But I have downloaded the specific Ubuntu 24.04 version of PureBasic so it should be 100% compatible with Ubuntu 24.04 (at least with the Windowmanager since it was made for that specific version of Ubuntu?).

Right now, I can't compile my open-source tool for Ubuntu because the code below returns from debugger:

Code: Select all

10
30
Which results in negative values while opening a dynamic preferences window in my app.

Here is the source-code:

Code: Select all

; Display a requester with an error message.
;
; To clean up the code
;
; V1.0 - 07/APR/2024
;
Procedure MessageRequesterError(MARCOAGPINTO_error_text$)
  
  MessageRequester("Error!",MARCOAGPINTO_error_text$,#PB_MessageRequester_Error)
  
EndProcedure





; Gets the maximum size a window can become in the desktop.
; (height)
;
; It opens an invisible full desktop window to find the value.
;
; 30/JUL/2024: Now asynchronous trick for Linux
;
;
; V1.0 - 14/AUG/2022
; V1.1 - 27/FEB/2024
;        o Use of flag: #PB_Window_MaximizeGadget
; V1.2 - 31/MAR/2024
;        o Check if temp window already exists, opening a message requester warning and exits the procedure with #False
; V1.3 - 30/JUL/2024
;        o Now asynchronous trick for Linux
;
Procedure GetMaxWindowDesktopHeight()
  
    MARCOAGPINTO_dynamic_value_for_window=3000
    
    ; Check if window already exists
    If IsWindow(MARCOAGPINTO_dynamic_value_for_window)=#True
      MessageRequesterError("Window number "+Str(MARCOAGPINTO_dynamic_value_for_window)+" already exists.")
      ProcedureReturn #False
    EndIf
    
    If OpenWindow(MARCOAGPINTO_dynamic_value_for_window,0,0,10,10,"Getting Maximum Window Size",#PB_Window_Maximize|#PB_Window_Invisible|#PB_Window_MaximizeGadget)=0
      MessageRequesterError("Can't open a window.")
      ProcedureReturn 0
    EndIf
    Repeat
      MARCOAGPINTO_event=WindowEvent()
    Until IsWindow(MARCOAGPINTO_dynamic_value_for_window)    
    MARCOAGPINTO_max_height=WindowHeight(MARCOAGPINTO_dynamic_value_for_window)
    CloseWindow(MARCOAGPINTO_dynamic_value_for_window)  
    
    ProcedureReturn MARCOAGPINTO_max_height
  
EndProcedure



; SAME PROCEDURE AS ABOVE BUT NOT WITH INVISIBLE WINDOW
Procedure GetMaxWindowDesktopHeight_not_invisible()
  
    MARCOAGPINTO_dynamic_value_for_window=3000
    
    ; Check if window already exists
    If IsWindow(MARCOAGPINTO_dynamic_value_for_window)=#True
      MessageRequesterError("Window number "+Str(MARCOAGPINTO_dynamic_value_for_window)+" already exists.")
      ProcedureReturn #False
    EndIf
    
    If OpenWindow(MARCOAGPINTO_dynamic_value_for_window,0,0,10,10,"Getting Maximum Window Size",#PB_Window_Maximize|#PB_Window_MaximizeGadget)=0
      MessageRequesterError("Can't open a window.")
      ProcedureReturn 0
    EndIf
    Repeat
      MARCOAGPINTO_event=WindowEvent()
    Until IsWindow(MARCOAGPINTO_dynamic_value_for_window)    
    MARCOAGPINTO_max_height=WindowHeight(MARCOAGPINTO_dynamic_value_for_window)
    CloseWindow(MARCOAGPINTO_dynamic_value_for_window)  
    
    ProcedureReturn MARCOAGPINTO_max_height
  
EndProcedure


Debug GetMaxWindowDesktopHeight()
Debug GetMaxWindowDesktopHeight_not_invisible()
Thanks!
User avatar
mk-soft
Always Here
Always Here
Posts: 6206
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by mk-soft »

This is the internal asynchronous processing of GTK.
After searching not only PureBasic has the problem.

Solution:

Code: Select all

;-TOP


Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
  
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 500, "Test Window", #WinStyle | #PB_Window_Maximize)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Wait GTK Finished
    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      Protected gtk_time
      gtk_time = ElapsedMilliseconds()
      Repeat
        Select WaitWindowEvent(100)
          Case #PB_Event_SizeWindow
            Break
        EndSelect
        If ElapsedMilliseconds() - gtk_time > 5000
          ; Timeout
          Break
        EndIf
      ForEver
    CompilerEndIf
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    Debug "Size: " + dx + "/" + dy
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by marcoagpinto »

mk-soft wrote: Sat Apr 19, 2025 12:11 pm This is the internal asynchronous processing of GTK.
After searching not only PureBasic has the problem.

Solution:

Code: Select all

;-TOP


Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
  
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 500, "Test Window", #WinStyle | #PB_Window_Maximize)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Wait GTK Finished
    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      Protected gtk_time
      gtk_time = ElapsedMilliseconds()
      Repeat
        Select WaitWindowEvent(100)
          Case #PB_Event_SizeWindow
            Break
        EndSelect
        If ElapsedMilliseconds() - gtk_time > 5000
          ; Timeout
          Break
        EndIf
      ForEver
    CompilerEndIf
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    Debug "Size: " + dx + "/" + dy
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
But, MK,

I know they are asynchronous and that is why in my code I loop until IsWindow=#True so that it only breaks the loop when the window is considered open/valid.
User avatar
mk-soft
Always Here
Always Here
Posts: 6206
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by mk-soft »

Ups ...

I didn't try your second example ;)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by Fred »

It's a GTK issue with async events and we won't patch the commands to have sync behaviour as it can introduce other issues. You can use the workaround from mk-soft which seems to work as expected here ! BTW IsWindow() just check than the internal window object is OK, nothing more. It doesn't help here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by marcoagpinto »

Fred wrote: Fri May 02, 2025 3:45 pm It's a GTK issue with async events and we won't patch the commands to have sync behaviour as it can introduce other issues. You can use the workaround from mk-soft which seems to work as expected here ! BTW IsWindow() just check than the internal window object is OK, nothing more. It doesn't help here.
@Fred,

But not even a "Delay(500)" before getting the size works well. 500 ms should be more than enough to draw the window?
User avatar
marcoagpinto
Addict
Addict
Posts: 1045
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: PB 6.21 beta 5: #PB_Window_Maximize doesn't work Ubuntu 24.04

Post by marcoagpinto »

@Fred

Ahhhh... okay, I will try the workaround.

Thank you guys!

:twisted: :twisted: :twisted: :twisted:
Post Reply