0

I found this question related, but not directly answering my question, which is:

How to get combined resolution of all connected displays to Linux machine in C++? (rectangle around all monitors, whichever placed)

I know quite little of C++, but I've written this code, unsure if it does the job correctly or not, as I do not have multiple monitors layout, I'm just coding something which will have to take into account all connected monitors.

Excerpt of my code follows:

#include <X11/Xlib.h>
#include <iostream>


        Display * my_display = XOpenDisplay(NULL);
        Screen * my_screen = XDefaultScreenOfDisplay(my_display);

        const int screen_width = my_screen->width;
        const int screen_height = my_screen->height;

        if (x_coord >= screen_width)
        {
            std::cerr
                << "X coord bigger than the screen width\n";

            return 1;
        }

        if (y_coord >= screen_height)
        {
            std::cerr
                << "Y coord bigger than the screen height\n";

            return 1;
        }

Thank you.

selbie
  • 100,020
  • 15
  • 103
  • 173
Vlastimil Burián
  • 3,024
  • 2
  • 31
  • 52

1 Answers1

0

One possible way seems to be (invoking shell commands not included in the answer, but shall be very simple):

xdpyinfo | awk '/dimensions:/ { print $2 }'

Comment: In a multi-monitor setup this will show the dimensions of the bounding box which contains all monitors.

Credit: https://unix.stackexchange.com/a/2682/126755

Vlastimil Burián
  • 3,024
  • 2
  • 31
  • 52