Actual desktop

Just starting out? Need help? Post your questions and find answers here.
johnstock
New User
New User
Posts: 8
Joined: Sat Aug 04, 2012 4:32 pm
Location: Italy
Contact:

Actual desktop

Post by johnstock »

Hi there, i'm new and i was evaluating PB using demo version, so no API.

I'm testing with this situation on a VM:
display1 (main): 1024x768 (DesktopX=0)
display2 (@left): 800x600 (DesktopX=-800)
display3 (@right): 1280x1024 (DesktopX=1024)
maybe in future i can add more display @left or @right

I can't figure out to get the actual display of a running app.
Can someone help me??

Code: Select all

Enumeration #PB_Compiler_EnumerationValue
  #Window_0
EndEnumeration

Enumeration #PB_Compiler_EnumerationValue
  #ListIcon_0
  #Button_0
  #Text_0
  #Text_1
  #Text_2
EndEnumeration

Procedure OpenWindow_0()
  OpenWindow(#Window_0, DesktopMouseX(), DesktopMouseY(), 400, 245, "", #PB_Window_SystemMenu)
  ListIconGadget(#ListIcon_0, 10, 10, 380, 140, "Display", 90,#PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#ListIcon_0, 1, "Width", 45)
  AddGadgetColumn(#ListIcon_0, 2, "Height", 45)
  AddGadgetColumn(#ListIcon_0, 3, "DesktopX", 60)
  AddGadgetColumn(#ListIcon_0, 4, "DesktopY", 60)
  ButtonGadget(#Button_0, 10, 155, 380, 45, "Update")
  TextGadget(#Text_0, 10, 210, 210, 25, "Actual display: ", #PB_Text_Border)
  TextGadget(#Text_1, 230, 210, 75, 25, "X:", #PB_Text_Border)
  TextGadget(#Text_2, 315, 210, 75, 25, "Y:", #PB_Text_Border)
EndProcedure

Procedure Update()
  ClearGadgetItems(#ListIcon_0)
  
For i=0 To ExamineDesktops()-1
  AddGadgetItem(#ListIcon_0, -1, DesktopName(i)+Chr(10)+DesktopWidth(i)+Chr(10)+DesktopHeight(i)+Chr(10)+Str(DesktopX(i))+Chr(10)+Str(DesktopY(i)))
Next i

SetGadgetText(#Text_1, "X: "+Str(WindowX(#Window_0)))
SetGadgetText(#Text_2, "Y: "+Str(WindowY(#Window_0)))

EndProcedure

Procedure Moving()
  
  SetGadgetText(#Text_1, "X: "+Str(WindowX(#Window_0)))
  SetGadgetText(#Text_2, "Y: "+Str(WindowY(#Window_0)))
  
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
      
    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0
          Update()
      EndSelect
      
    Case #PB_Event_MoveWindow
      Moving()

EndSelect
ProcedureReturn #True
EndProcedure

OpenWindow_0()
Update()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

End
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Actual desktop

Post by charvista »

Johnstock,
Welcome to PureBasic and the PureBasic forum! :D
johnstock wrote:I can't figure out to get the actual display of a running app.
Interesting question. I have no good experience of multi-displays, but I think it simulates one very big single display. So, because you know the width of each display, you can easily calculate on which display your app is located, based on the x-position of a window with WX=WindowX(Win).

Cheers
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Actual desktop

Post by ts-soft »

Code: Select all

Procedure DesktopFromPoint(x, y)
  Protected Count = ExamineDesktops()
  Protected i, dx, dy, dw, dh
  
  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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
johnstock
New User
New User
Posts: 8
Joined: Sat Aug 04, 2012 4:32 pm
Location: Italy
Contact:

Re: Actual desktop

Post by johnstock »

Thanks charvista.
Thanks!! ts-soft, you make it sound easy with your procedure..
I was ending up with this, but your is absolutely better:

Code: Select all

Procedure Update()
  ClearGadgetItems(#ListIcon_0)
  
  Dim MultiArray.i(ExamineDesktops(),7)
  
  For i=0 To ExamineDesktops()-1
    
    MultiArray(i,1) = i
    MultiArray(i,2) = DesktopWidth(i)  ;absolute width display (always positive)
    MultiArray(i,3) = DesktopX(i)  ;Min X
    
    If Sign(DesktopX(i)) <0  ;negative value (@left)
      For n=DesktopX(i) To DesktopX(i)+(DesktopWidth(i))-1
      Next n
      
    ElseIf Sign(DesktopX(i)) >=1  ;positive value (@right)
      For n=DesktopX(i) To DesktopX(i)+DesktopWidth(i)-1
      Next n
      
    Else  ;neutral value (@central)
      For n=DesktopX(i) To DesktopWidth(i)-1
      Next n
      
    EndIf
    MultiArray(i,4) = n-1  ;Max X
    
    MultiArray(i,5) = DesktopHeight(i)   ;absolute height display (always positive)
    MultiArray(i,6) = DesktopY(i)  ;Min Y
    MultiArray(i,7) = DesktopY(i)-DesktopHeight(i)  ;Max Y
    
    AddGadgetItem(#ListIcon_0, -1, DesktopName(MultiArray(i,1))+Chr(10)+MultiArray(i,2)+Chr(10)+MultiArray(i,5)+Chr(10)+MultiArray(i,3)+Chr(10)+MultiArray(i,6)+Chr(10)+MultiArray(i,3)+Chr(10)+MultiArray(i,4))
    
    SetGadgetText(#Text_1, "X: "+Str(WindowX(#Window_0)))
    SetGadgetText(#Text_2, "Y: "+Str(WindowY(#Window_0)))
  Next i
  
  For d=0 To ExamineDesktops()-1
    
    If DesktopMouseX() >= MultiArray(d,3) And DesktopMouseX() <= MultiArray(d,4)
      SetGadgetText(#Text_0, "Actual display: "+ DesktopName(MultiArray(d,1)))
    Else
      ;something strange happen...
    EndIf
  Next d
  
EndProcedure
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Actual desktop

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply