Get screen resolution, scale factor and width and height in mm for wayland

I tried that six months ago, for 90 minutes, and gave up.

Now I remembered the advice of Mr. Bassi (that thread was closed recently due to the 14 days limit) and tried again. And it works!

import gintro/[gtk4, gdk4, gobject, gio]

proc printData(widget: Button; window: ApplicationWindow) =
  let surface: gdk4.Surface = window.getSurface
  let display: gdk4.Display = surface.getDisplay
  let monitor: gdk4.Monitor = display.getMonitorAtSurface(surface)
  echo monitor.getWidthmm
  echo monitor.getHeightmm
  let geometry: gdk4.Rectangle = monitor.getGeometry
  echo geometry
  echo monitor.getScaleFactor
  echo surface.getScaleFactor

proc activate(app: gtk4.Application) =
  let window = newApplicationWindow(app)
  let button = newButton("Print Data")
  button.connect("clicked", printData, window)

proc main =
  let app = newApplication("org.gtk.example")
  app.connect("activate", activate)
  let status =


(x: 0, y: 0, width: 3840, height: 2160)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.