GDK Screen vs Monitor vs Display?
Asked Answered
H

1

6

I'm currently working on a small app to take a screenshot of all the physical monitors. I am getting very confused though between all the terminology. I understand:

  1. that we can have multiple displays
  2. each display can have multiple monitors, which are known as screens?

I'm confused because I'm thinking maybe screens are desktops? My app is to not concern itself with the non-visible desktops, just take screenshots of what is currently on all the monitors.

Is my understanding correct?

This was my GDK pseudo-code so far:

var rezArr = [];
gdk_display_manager_list_displays

for (var d=0; d<displays.length; d++) {
    
    var nScreens = gdk_display_get_n_screens(displays[d]);
    
    for (var s=0; s<nScreens; s++) {
        var cScreen = gdk_display_get_screen(displays[d], s);
        // var nMonitors = gdk_screen_get_n_monitors(cScreen);
        // for (var m=0; m<nMonitors; m++) {
            // var gdkRect = GdkRectangle();
            // gdk_screen_get_monitor_geometry(cScreen, m, gdkRect);
        // }
        
        var cRootWin = gdk_screen_get_root_window(cScreen);
        var cWidth = gdk_screen_get_width(cScreen);
        var cHeight = gdk_screen_get_height(cScreen);
        var cColormap = GdkColormap();
        gdk_screen_set_default_colormap(cScreen, cColormap);
        var cPixbuf = gdk_pixbuf_new(COLORSPACE_RGB, false, 8, cWidth, cScreen);
        var cDrawable = ctypes.cast(cScreen, self.TYPE.GdkDrawable.ptr);
        var src_x = 0; // im guessing, i could not figure out screen geometry, i could only get its width and height
        var src_y = 0; // im guessing, i could not figure out screen geometry, i could only get its width and height
        var dest_x = 0;
        var dest_y = 0;
        gdk_pixbuf_get_from_drawable(cPixbuf, cDrawable, cColormap, src_x, src_y, dest_x, dest_y, cWidth, cHeight);
        rezArr.push(
            {
                // i dont know how to get x1, y1 yet. but x2 and y2 is just x1 + cWidth and y1 + cHeight
                // monitorTopLeftX: x1,
                // monitorTopLetY: y1,
                // monitorBottomRightX: x2,
                // monitorBottomRightY: y2,
                pixbuf: cPixbuf
            }
        );
    }
}

You can see I got confused with the monitors so then just commented it out.

Thanks much

Hyacinthus answered 13/5, 2015 at 6:50 Comment(0)
R
13

GdkDisplay is an object that represents a single connection to a display server, like the X11 server, or a Wayland compositor. Applications can have multiple connections, but GDK resources are associated to each GdkDisplay instance that created them.

GdkScreen is a "screen" in the same way that X11 has Screens; it's a virtual entity that may match multiple monitors, or parts of a monitor. Modern GDK/GTK code assumes a 1:1 match between GdkDisplay and GdkScreen.

GDK does not have an object representing a monitor; it has API on GdkDisplay and GdkScreen that takes a monitor index for things like the display geometry.

[Update] Starting with Gtk+ 3.22 there is a new GdkMonitor class that represents a monitor and which can be used to get information about the monitor geometry and more. [/Update]

From a window manager perspective, basically all X11 WMs use a single Screen covering all monitors, so you don't really need to iterate over them.

It seems you're trying to write code to grab a screenshot of the whole screen. The simplest solution is to grab the root window of the default GdkScreen and use gdk_pixbuf_get_from_window(); this will do all the work for you.

Rebane answered 13/5, 2015 at 16:42 Comment(8)
Thank you @Rebane for this detailed explanation. Gut if I get the root of the default GdkScreen will that get all of the monitors?Hyacinthus
I believe this is what Noitidart is trying to do.Charo
Thanks @andlabs! So i have a list of all the display in that array, so I was wondering if each display is connected to all monitors? As people are recommending just rt window, im worried root window wont get all monitors.Hyacinthus
As I said, a GdkDisplay is a display server connection. A GdkScreen is not a representation of a physical display: it can be a union of monitors or a subset of a monitor; in modern GDK, as well as modern systems, you only have one GdkScreen per GdkDisplay. Each GdkScreen has a "root" window. If all you want to do is take a screenshot of the contents of the screen, just take the root window and create a GdkPixbuf from that.Rebane
Thanks I did that its working i was just trying to understand why the existance of gdk_display_manager_list_displays its confusing me a lot could you please share some words on that.Hyacinthus
That function lists all GdkDisplay instances opened by a single process; each application can open multiple display connections, and each display connection is mapped to its own GdkDisplay instance.Rebane
@Rebane And why would an app create multiple connections to the same display?Customable
Applications seldom need those, but different components could use different display connections to isolate windowing system resources.Rebane

© 2022 - 2024 — McMap. All rights reserved.