Desktop frequency

Linux specific forum
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Desktop frequency

Post by coco2 »

Is there a way to get the desktop frequency in Linux?
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Desktop frequency

Post by mk-soft »

Over gdk.monitor api ...

Code: Select all

;-TOP by mk-soft, v1.01.0, 02.11.2024

Macro _dq_
  "
EndMacro

Macro LIBFUNC(_libFunction_, _library_=lib)
  Global _libFunction_._libFunction_ = GetFunction(_library_, _dq_#_libFunction_#_dq_)
  CompilerIf #PB_Compiler_Debugger
    If _libfunction_ = 0
      Debug "Error: Invalid Library Function '" + _dq_#_libFunction_#_dq_ + "'"
      CallDebugger
    EndIf
  CompilerEndIf
EndMacro

; ----

PrototypeC gdk_display_get_default() ; r1 = gdkdisplay
PrototypeC gdk_display_get_monitor_at_window(*display, *gdkwindow); r1 = gdkmonitor

; ----

PrototypeC gdk_monitor_get_display(*monitor)
PrototypeC gdk_monitor_get_refresh_rate(*monitor)
PrototypeC gdk_monitor_get_geometry(*monitor, *geometry)

; ----

Procedure InitGDK()
  Protected lib
  lib = OpenLibrary(#PB_Any, "libgdk-3.so")
  If lib
    ; Display
    LIBFUNC(gdk_display_get_monitor_at_window)
    LIBFUNC(gdk_display_get_default)
    
    ; Monitor
    LIBFUNC(gdk_monitor_get_display)
    LIBFUNC(gdk_monitor_get_refresh_rate)
    LIBFUNC(gdk_monitor_get_geometry)
    
  Else
    Debug "Error open library 'libgdk-3.so'"
  EndIf
  ProcedureReturn lib
EndProcedure : InitGDK()

;-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, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ;Test
    *display = gdk_display_get_default();
    *gdkwindow = gdk_get_default_root_window_();
    *monitor = gdk_display_get_monitor_at_window(*display, *gdkwindow);
    rate.i = gdk_monitor_get_refresh_rate(*monitor)
    gdk_monitor_get_geometry(*monitor, geometry.GdkRectangle)
    
    dblRate.d = rate / 1000.0
    With geometry
      temp.s = "Geometry: " + \x + ", " + \y + " - " + \width + ", " + \height + "; Rate: " + StrD(dblRate, 3)
      Debug temp.s
    EndWith
    
    ; 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
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Desktop frequency

Post by coco2 »

Works well, thank you.
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Desktop frequency

Post by mk-soft »

Now more functions ;)

Link: GDK.Monitor Functions
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
Post Reply