I haven't found anything related here on the forum (even if I thought to have seen something before), so I'm asking here:
If I want to create perfectly matching windows, which aren't overlapping Windows task bar or MacOS dock panel, I need to know their size and position (as, at least on Windows, the position can be top / bottom / left or right).
Anyone could point me to some example code, how to determine such informations (for Win + OSX)?
Thank you in advance
PS: I'm aware of the #PB_Window_Maximize flag for OpenWindow(), but I want to allow the user of my program his own user-setting for window size / position. So I need to know, what is possible at maximum.
PPS: I think it would be a good improvemt, if the Desktop library would provide some native commands for this...
Be aware of task bar/dock panel size and position?
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Be aware of task bar/dock panel size and position?
Windows, anyway. No idea for Mac.
Code: Select all
SystemParametersInfo_(#SPI_GETWORKAREA,0,@wr.RECT,0)
OpenWindow(0,0,0,wr\right-wr\left-GetSystemMetrics_(#SM_CXBORDER)*2,wr\bottom-wr\top-(GetSystemMetrics_(#SM_CYCAPTION)+GetSystemMetrics_(#SM_CYBORDER)*2),"")
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: Be aware of task bar/dock panel size and position?
@netmaestro: thank you, works well. Successfully tested on Win10, even if I move the Windows task bar from bottom to the right it gives the correct values...
Someone an idea for MacOS? As it seems, the could be changed the size and the position of the Dock panel too... (see here: https://support.apple.com/guide/mac-hel ... /mac/10.13)
Someone an idea for MacOS? As it seems, the could be changed the size and the position of the Dock panel too... (see here: https://support.apple.com/guide/mac-hel ... /mac/10.13)
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: Be aware of task bar/dock panel size and position?
According to the MacOS-related part of my question I just found this 6 years old example code:
viewtopic.php?f=19&t=50795&p=451119&hil ... ze#p451119
I'm wondering, if this still works on all newer OS X versions?
Or is there another/better method available (now), instead of opening a invisible window directly reading the OS X system settings?
viewtopic.php?f=19&t=50795&p=451119&hil ... ze#p451119
I'm wondering, if this still works on all newer OS X versions?
Or is there another/better method available (now), instead of opening a invisible window directly reading the OS X system settings?
Re: Be aware of task bar/dock panel size and position?
On MacOS the dock may also be located on the left or right side and not only at the bottom...Andre wrote:..., I need to know their size and position (as, at least on Windows, the position can be top / bottom / left or right).
The following MacOS example calculates the usable desktop area for a window on the current screen (the screen with keyboard focus, if you have attached more than one screen). It automatically subtracts the area of the dock, irrespective whether the dock is located at the left or right side or at the bottom. If the dock option to automatically slide in/out is activated, the area of the dock is not subtracted. And it calculates the MenuBar's height and also subtracts it from the usable desktop height.
At last for demonstration purposes a maximized window is displayed which doesn't cover MenuBar and Dock. Even if the dock is positioned to the left or right, the window will be positioned and sized correctly!
Code: Select all
EnableExplicit
Define ActiveScreen.I
Define MaxWindowHeight.I
Define MaxWindowWidth.I
Define MenuBarHeight.CGFloat
Define UsableDesktopArea.NSRect
; ----- Get screen area with subtracted dock size
ActiveScreen = CocoaMessage(0, 0, "NSScreen mainScreen")
CocoaMessage(@UsableDesktopArea, ActiveScreen, "visibleFrame")
MaxWindowHeight = UsableDesktopArea\size\height
MaxWindowWidth = UsableDesktopArea\size\width
; ----- Get height of MenuBar
CocoaMessage(@MenuBarHeight, CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "mainMenu"), "menuBarHeight")
; ----- Subtract height of MenuBar
MaxWindowHeight - MenuBarHeight
; ----- Display maximized window respecting Dock and MenuBar
OpenWindow(0, 0, 0, MaxWindowWidth, MaxWindowHeight,
"Maximized window respecting Dock")
SetWindowTitle(0, "Usable desktop area: " + Str(MaxWindowWidth) +
" x " + MaxWindowHeight)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Be aware of task bar/dock panel size and position?
If you can get the right dimensions of the working area after #PB_Event_MaximizeWindow|#PB_Event_Repaint events then the next is the right way
- For Windows
- For Windows
Code: Select all
OpenWindow(0,0,0,800,600,"Window & TaskBar",#PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_MaximizeWindow|#PB_Event_Repaint
SystemParametersInfo_(#SPI_GETWORKAREA,0,r.RECT,0)
ResizeWindow(0,r\left,r\top,r\right-r\left,r\bottom-r\top)
EndSelect
Until Quit = 1
Egypt my love
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: Be aware of task bar/dock panel size and position?
Thanks Shardik and Rashad for your help, very welcome!
As I prefer the option, to avoid any (hidden) window, I used Shardik's code and created the following procedure:
(not tested on MacOS yet)
@Windows-only:
I'm wondering a bit about the different output regarding DPI-aware on/off setting...
So my first question is: Is this the expected behaviour? (returned values for DPI off!? - should I really limit my window to these smaller values)
And the second one is: How to deal now correctly with these values, regarding correct image + canvas sizes to use when creating a GUI (all other gadget types are correctly automatically resized, as I'm using PB's Dialog library)...any hints?
As I prefer the option, to avoid any (hidden) window, I used Shardik's code and created the following procedure:
(not tested on MacOS yet)
Code: Select all
Structure screen
Width.i
Height.i
EndStructure
Define ScreenSize.screen
Procedure GetScreenWorkAreaSize(*size.screen)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
; A check for the 'working area' on the Windows desktop, being aware of the size/position of the task bar:
; (see my question / answer by netmaestro here: https://www.purebasic.fr/english/viewtopic.php?f=13&t=75410)
SystemParametersInfo_(#SPI_GETWORKAREA,0,@wr.RECT,0)
*size\width = wr\right-wr\left-GetSystemMetrics_(#SM_CXBORDER)*2
*size\height = wr\bottom-wr\top-(GetSystemMetrics_(#SM_CYCAPTION)+GetSystemMetrics_(#SM_CYBORDER)*2)
CompilerCase #PB_OS_MacOS
Protected ActiveScreen.i, MaxWindowHeight.i, MaxWindowWidth.i
Protected MenuBarHeight.CGFloat
Protected UsableDesktopArea.NSRect
; ----- Get screen area with subtracted dock size:
ActiveScreen = CocoaMessage(0, 0, "NSScreen mainScreen")
CocoaMessage(@UsableDesktopArea, ActiveScreen, "visibleFrame")
MaxWindowHeight = UsableDesktopArea\size\height
MaxWindowWidth = UsableDesktopArea\size\width
; ----- Get height of MenuBar:
CocoaMessage(@MenuBarHeight, CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "mainMenu"), "menuBarHeight")
; ----- Subtract height of MenuBar
MaxWindowHeight - MenuBarHeight
*size\Width = MaxWindowWidth
*size\Height = MaxWindowHeight
CompilerCase #PB_OS_Linux
; TODO!
CompilerEndSelect
EndProcedure
; Example - fill the pre-defined variable with the width/height values:
GetScreenWorkAreaSize(@ScreenSize)
Debug "Working area size = " + ScreenSize\width + "x" + ScreenSize\height
; Test output on my PC with Win10, FullHD (1920x1024) and 125% DPI setting:
; -------------------------------------------------------------------------
; compiled with PB compiler options =
; a) DPI-aware off: 1534x799
; b) DPI-aware on: 1918x999
;
; (Please note, that the PB functions DesktopWidth()/DesktopHeight() always output 1920x1024 independent of the DPI-aware option!)
;
; Test output on my Mac:
; -------------------------------------------------------------------------
; TODO!
I'm wondering a bit about the different output regarding DPI-aware on/off setting...
So my first question is: Is this the expected behaviour? (returned values for DPI off!? - should I really limit my window to these smaller values)
And the second one is: How to deal now correctly with these values, regarding correct image + canvas sizes to use when creating a GUI (all other gadget types are correctly automatically resized, as I'm using PB's Dialog library)...any hints?