summaryrefslogtreecommitdiff
path: root/xineramainfo/xgetxineramainfo.c
blob: 0b80e1d1968626b5a839facf518b235a45ac336f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright (C) 2008, Kristian Lyngstol <kristian@bohemians.org>
 *
 * GNU GPLv2 goes here.
 *
 * Tiny utility app to fetch xinerama info. Maybe some day I'll make it
 * actually helpful.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xinerama.h>

int xineramaEvent, xineramaError;
int majorVersion, minorVersion;
Display *dpy;
XineramaScreenInfo *screenInfo;
int nScreenInfo;

void bail(char *str)
{
    perror ("The flux capacitor is broken! Bailing!");
    perror (str);
    exit (1);
}

void verbose (char *str)
{
    printf (str);
}

void printVersion ()
{
    Status ret;
    ret = XineramaQueryVersion (dpy, &majorVersion, &minorVersion);
    printf ("Xinerama version: %d.%d\n", majorVersion,minorVersion);
    if (!ret)
	bail ("Incompatible xinerama version. XineramaQueryVersion "\
	      "false.");
}

int main (int argc, char **argv)
{
    Bool ret;
    dpy = XOpenDisplay (0);
    if (!dpy)
	bail ("Couldn't open display.");

    ret = XineramaQueryExtension (dpy, &xineramaEvent, &xineramaError);
    if (!ret)
	bail ("No xinerama extension");

    printVersion ();
    verbose ("Attempting to get screen info.\n");
    screenInfo = XineramaQueryScreens (dpy, &nScreenInfo);
    int i;
    if (nScreenInfo == 0) 
	verbose ("nScreenInfo == 0. No screen info found.\n");
    printf ("Screen\tx_org\ty_org\twidth\theight\n");
    for (i = 0; i < nScreenInfo; i++)
	printf ("%d\t%d\t%d\t%d\t%d\n",
		screenInfo[i].screen_number,
		screenInfo[i].x_org,
		screenInfo[i].y_org,
		screenInfo[i].width,
		screenInfo[i].height);
    verbose ("Done.\n");
    return 0;
}