Programmatically determining individual screen widths/heights in Linux (w/Xinerama, TwinView, and/or BigDesktop)
It looks like there's a libXinerama
API that can retrieve that information. I haven't found any detailed information on it yet though.
General X.org programming information can be found here (PDF file). Information on the functions provided by libXinerama
can be found here (online copy of a manpage, not a lot of information in it).
Here's a small C++ program that I whipped up from those references to retrieve the dimensions and offsets of each of the monitors hooked into Xinerama. It also works for nVidia TwinView; I don't presently have an ATI card to test it on their BigDesktop system, but I suspect it would work on it as well.
#include <cstdlib>
#include <iostream>
#include <X11/extensions/Xinerama.h>
using std::cout;
using std::endl;
int main(int argc, char *argv[]) {
bool success=false;
Display *d=XOpenDisplay(NULL);
if (d) {
int dummy1, dummy2;
if (XineramaQueryExtension(d, &dummy1, &dummy2)) {
if (XineramaIsActive(d)) {
int heads=0;
XineramaScreenInfo *p=XineramaQueryScreens(d, &heads);
if (heads>0) {
for (int x=0; x<heads; ++x)
cout << "Head " << x+1 << " of " << heads << ": " <<
p[x].width << "x" << p[x].height << " at " <<
p[x].x_org << "," << p[x].y_org << endl;
success=true;
} else cout << "XineramaQueryScreens says there aren't any" << endl;
XFree(p);
} else cout << "Xinerama not active" << endl;
} else cout << "No Xinerama extension" << endl;
XCloseDisplay(d);
} else cout << "Can't open display" << endl;
return (success ? EXIT_SUCCESS : EXIT_FAILURE);
}
C++ list screens to display images in the second monitor
It's likely that you need to query Xinerama, which is probably stitching your displays together.
This answer worked for me. I compiled their sample with:
g++ xinerama.c `pkg-config --cflags --libs x11 xinerama` -o test
gdk_screen_get_default() returns null
Answering my own question.
Finally, figured out the resolution. gtk_init( ) was missing before fetching the screen. Added that and respective include for gtk/gtk.h and now the code looks like
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv); // <---- added this
GdkScreen *screen = gdk_screen_get_default();
:
followed by rest of the code shared in the problem description above.
Related Topics
Dependency Walker Equivalent for Linux
Which Jdk's Distributions Can Run 'Javac -Source 1.6 -Target 1.5'
How to Name the 'Screen' Logfile from the -L Flag
Building Arm Gnu Cross Compiler
How to Determine the Process Memory Limit in Linux
How to Get the Exit Status a Loop in Bash
Extract Average Time from Ping -C
How to Change the Host Type for a 'Canadian Cross' Compilation of Gcc with Crosstool-Ng
How to Write Shell Command Within Pharo Smalltalk
Tomcat 7 with Java 8 on Windows and Linux
Branch-Specific Configuration File Maintenance with Git
How to Toggle Cr/Lf in Gnu Screen
How to Connect to Postgresql Server: Could Not Connect to Server: Permission Denied
Syntax Error Near Unexpected Token ' - Bash