Bug getting invisible window size

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

Bug getting invisible window size

Post by marcoagpinto »

Heya,

This code has a bug on Ubuntu 22.04 LTS (it gives the wrong size of an invisible window)

Windows results:
desktop_resolution$:1920x1080
window_resolution_max_width:1920
window_resolution_max_height:1057

Ubuntu 22.04 results:
desktop_resolution$:1920x969
window_resolution_max_width:10
window_resolution_max_height:10

After around a year without releasing an update for Proofing Tool GUI, I thought it was about time and found this.

Code: Select all

; Gets the maximum size a window can become in the desktop.
; (width)
;
; It opens an invisible full desktop window to find the value.
;
; V1.0 - 14/AUG/2022
;
Procedure GetMaxWindowDesktopWidth()
 
    MARCOAGPINTO_dynamic_value_for_window=3000
  
    If OpenWindow(MARCOAGPINTO_dynamic_value_for_window,0,0,10,10,"Getting Maximum Window Size",#PB_Window_Maximize|#PB_Window_Invisible)=0 : MessageRequester("Error", "Can't open a window.",#PB_MessageRequester_Error) : EndIf
      MARCOAGPINTO_max_width=WindowWidth(MARCOAGPINTO_dynamic_value_for_window)
    CloseWindow(MARCOAGPINTO_dynamic_value_for_window)  
  
    ProcedureReturn MARCOAGPINTO_max_width
    
EndProcedure




; Gets the maximum size a window can become in the desktop.
; (height)
;
; It opens an invisible full desktop window to find the value.
;
; V1.0 - 14/AUG/2022
;
Procedure GetMaxWindowDesktopHeight()
  
    MARCOAGPINTO_dynamic_value_for_window=3000
  
    If OpenWindow(MARCOAGPINTO_dynamic_value_for_window,0,0,10,10,"Getting Maximum Window Size",#PB_Window_Maximize|#PB_Window_Invisible)=0 : MessageRequester("Error", "Can't open a window.",#PB_MessageRequester_Error) : EndIf
      MARCOAGPINTO_max_height=WindowHeight(MARCOAGPINTO_dynamic_value_for_window)
    CloseWindow(MARCOAGPINTO_dynamic_value_for_window)  
    
    ProcedureReturn MARCOAGPINTO_max_height
  
EndProcedure






    ; Get maximum window size from an invisible window
    ExamineDesktops()
    desktop_resolution$=Str(DesktopWidth(0))+"x"+Str(DesktopHeight(0))   
    Debug "desktop_resolution$:"+desktop_resolution$
    window_resolution_max_width=GetMaxWindowDesktopWidth()
    Debug "window_resolution_max_width:"+Str(window_resolution_max_width)
    window_resolution_max_height=GetMaxWindowDesktopHeight()
    Debug "window_resolution_max_height:"+window_resolution_max_height
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.04] Bug getting invisible window size

Post by Fred »

Unfortunately, the way the Linux window manager works doesn't allow the do these kind of tricks as the resize will be performed asyncronously.
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug getting invisible window size

Post by infratec »

Also the coding was wrong. At least CloseWindow() should only be executed when the window was opened.

Maybe this version works also in Linux:

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf


Structure GetMaxWindowDesktopSize_Structure
  InnerWidth.i
  InnerHeight.i
  OuterWidth.i
  OuterHeight.i
EndStructure

Procedure.i GetMaxWindowDesktopSize(*Size.GetMaxWindowDesktopSize_Structure)
  
  Protected.i Win, Event, Result
  
  Win = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_MaximizeGadget|#PB_Window_Maximize|#PB_Window_Invisible)
  If Win
    AddWindowTimer(Win, 1, 10)
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Timer And EventTimer() = 1
        RemoveWindowTimer(Win, 1)
        Break
      EndIf
    ForEver
    *Size\InnerWidth = WindowWidth(Win, #PB_Window_InnerCoordinate)
    *Size\InnerHeight = WindowHeight(Win, #PB_Window_InnerCoordinate)
    *Size\OuterWidth = WindowWidth(Win, #PB_Window_FrameCoordinate)
    *Size\OuterHeight = WindowHeight(Win, #PB_Window_FrameCoordinate)
    CloseWindow(Win)
    Result = #True
  Else
    MessageRequester("Error", "Can't open window.", #PB_MessageRequester_Error)
  EndIf
  
  ProcedureReturn Result
  
EndProcedure


CompilerIf #PB_Compiler_IsMainFile
  
  Define Help.GetMaxWindowDesktopSize_Structure
  
  If GetMaxWindowDesktopSize(@Help)
    Debug Str(Help\InnerWidth) + "/" + Str(Help\InnerHeight) + " " + Str(Help\OuterWidth) + "/" + Str(Help\OuterHeight)
  EndIf
  
CompilerEndIf
Maybe the value of the timer needs to be larger.
User avatar
marcoagpinto
Addict
Addict
Posts: 1051
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: [PB6.04] Bug getting invisible window size

Post by marcoagpinto »

Fred wrote: Sat Jul 27, 2024 5:47 pm Unfortunately, the way the Linux window manager works doesn't allow the do these kind of tricks as the resize will be performed asyncronously.
What is that? Asynchronously? Do you mean it only appears later? As a workaround, could you place a “pause” in certain commands waiting for windows and others to appear opened? This would fix all issues of asynchronoument.
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Bug getting invisible window size

Post by Fred »

Unfortunately, it doesn't work like that. Even flushing all the remaining event are not enough, you need to wait than the window is 'realized' ie really created by the X window manager (basically GTK ask for a new window on the X server and when it's really created and event is sent back to GTK). Also when the window is invisible it's not realized so it doesn't have proper size info.
User avatar
marcoagpinto
Addict
Addict
Posts: 1051
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Bug getting invisible window size

Post by marcoagpinto »

Fred wrote: Tue Jul 30, 2024 10:36 am Unfortunately, it doesn't work like that. Even flushing all the remaining event are not enough, you need to wait than the window is 'realized' ie really created by the X window manager (basically GTK ask for a new window on the X server and when it's really created and event is sent back to GTK). Also when the window is invisible it's not realized so it doesn't have proper size info.
Fred, my last idea:

Code: Select all

open window blah blah

repeat
     waitwindowevent()
until iswindow(blah blah)
This done under the hood wouldn't solve it?

Thanks and I won't bother you anymore with this.
Post Reply