App runs on #Desktop?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

App runs on #Desktop?

Post by Frarth »

Is there a way to find out the specific desktop an application is running on if a user has multiple desktops? This seems useful if one is to examine the minimum allowed resolution for one's app...

Any insight greatly appreciated

Frank
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: App runs on #Desktop?

Post by ts-soft »

Use the Desktop lib in PB. If you subtract the y pos from desktopweigth without negative you are on second desktop, and so on :wink:
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: App runs on #Desktop?

Post by Frarth »

You mean desktopheight?
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: App runs on #Desktop?

Post by ts-soft »

desktop width!

Code: Select all

Res. 16:10
1680 * 1050

Desktop Primary 1        Secundary 2       ... 3

-----------------------------------------------------
                  |                   |
 0 - 1679          |       1680 - 3359 | 3360 -
                  |                   |
------------------------------------------------------
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: App runs on #Desktop?

Post by Frarth »

Ah, so if the first desktop has width 1440, where X = 0, then the second desktop's X will be 1440, right?

Edit: right, you just added the answer to my question... Thankx!
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: App runs on #Desktop?

Post by freak »

You are assuming that the monitors are all next to each other (with the primary one on the left), but that does not have to be the case.

You should use DesktopX() and DesktopY() so it will work with all possible configurations.
quidquid Latine dictum sit altum videtur
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: App runs on #Desktop?

Post by ts-soft »

but how can i test which desktop, if the user moves the window to secondary?
I can only use WindowX(0), and this give me a value like my description above.

The primary is not always on the left, but the values of WindowX(0) works in this way!
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: App runs on #Desktop?

Post by freak »

All coordinates in PB are "virtual screen coordinates". This means they are relative to the top/left corner of the primary monitor, even if you are on another monitor. DesktopX/DesktopY tells you the location of the monitors in these coordinates as well. (so its the location of the top/left corner of the specified monitor in relation to the primary one.

See here about the virtual screen: http://msdn.microsoft.com/en-us/library/dd145136.aspx

Example:

Code: Select all

Procedure DesktopFromPoint(x, y)
  Count = ExamineDesktops()
  For i = 0 To Count-1
    dx = DesktopX(i)
    dy = DesktopY(i)
    dw = DesktopWidth(i)
    dh = DesktopHeight(i)
    
    If x >= dx And x <= dx+dw And y >= dy And y <= dy+dh
      ProcedureReturn i
    EndIf  
  Next i  
  
  ProcedureReturn -1 ; point is outside of all monitors
EndProcedure

OpenWindow(0, 100, 100, 200, 50, "Monitor check", #PB_Window_SystemMenu)
TextGadget(0, 10, 10, 180, 25, "Window is on Desktop: " + Str(DesktopFromPoint(WindowX(0), WindowY(0))))

Repeat
  Select WaitWindowEvent()
  
    Case #PB_Event_CloseWindow
      End
      
    Case #PB_Event_MoveWindow
      SetGadgetText(0, "Window is on Desktop: " + Str(DesktopFromPoint(WindowX(0), WindowY(0))))
    
  EndSelect
ForEver
This will work with any monitor configuration.
quidquid Latine dictum sit altum videtur
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: App runs on #Desktop?

Post by ts-soft »

Nice code, thanks
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: App runs on #Desktop?

Post by Frarth »

freak wrote:

Code: Select all

    If x >= dx And x <= dx+dw And y >= dy And y <= dy+dh
      ProcedureReturn i
    EndIf
On the sideline, would it not be more optimal to code:

Code: Select all

If x >= dx 
  If x <= dx+dw
    If y >= dy
      If y <= dy+dh
        ProcedureReturn i
      EndIf
    EndIf
  EndIf
EndIf
This would be the case if the compiler were to examine all conditions, even if the first fails.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
User avatar
Demivec
Addict
Addict
Posts: 4280
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: App runs on #Desktop?

Post by Demivec »

Frarth wrote:
freak wrote:

Code: Select all

    If x >= dx And x <= dx+dw And y >= dy And y <= dy+dh
      ProcedureReturn i
    EndIf
On the sideline, would it not be more optimal to code:

Code: Select all

If x >= dx 
  If x <= dx+dw
    If y >= dy
      If y <= dy+dh
        ProcedureReturn i
      EndIf
    EndIf
  EndIf
EndIf
This would be the case if the compiler were to examine all conditions, even if the first fails.
You wouldn't have to do that because the complier uses shortcut evaluation. It will only evaluate all the conditions if each one is successively and sequentially true.
Fred
Administrator
Administrator
Posts: 18344
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: App runs on #Desktop?

Post by Fred »

Yes, both are equivalent, so the shorted the better ;)
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: App runs on #Desktop?

Post by Frarth »

Thanks for elaborating on this!

Frank
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Post Reply