Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDK Screen vs Monitor vs Display?

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

like image 228
Noitidart Avatar asked May 13 '15 06:05

Noitidart


1 Answers

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.

like image 167
ebassi Avatar answered Sep 30 '22 06:09

ebassi