aboutsummaryrefslogtreecommitdiff
path: root/xcross.c
blob: 0f531f86d9c82b2a1d3adfa632d83c7be22cf0c4 (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
// edit source code from:
// https://github.com/gvalkov/xrectsel

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

//int main (int argc, char *argv[])
int main (void)
{
	// useless trash vars
	int int_tmp;
	unsigned int uint_tmp;
	Window window_tmp;

	int rootx, rooty;
	Display * disp = XOpenDisplay(NULL);
	Screen * scr = ScreenOfDisplay(disp, DefaultScreen(disp));
	Window root = RootWindow(disp, XScreenNumberOfScreen(scr));

	// not completely understood
	XGCValues gcval;
	gcval.foreground = XWhitePixel(disp, 0);
	gcval.function   = GXxor;
	gcval.background = XBlackPixel(disp, 0);
	gcval.plane_mask = gcval.background ^ gcval.foreground;
	gcval.subwindow_mode = IncludeInferiors;
	GC gc = XCreateGC(disp, root, GCFunction|GCForeground|GCBackground|GCSubwindowMode, &gcval);

	XQueryPointer(disp, root, &window_tmp, &window_tmp, &rootx, &rooty, &int_tmp, &int_tmp, &uint_tmp);
	//printf("pointer coordinates x: %d, y: %d\n", rootx, rooty);
	//printf("screen width: %d, height: %d\n", scr->width, scr->height);
	XDrawLine(disp, root, gc, rootx, 0, rootx, scr->height);
	XDrawLine(disp, root, gc, 0, rooty, scr->width, rooty);

	// not completely understood
	XFlush(disp);
	XFreeGC(disp, gc);
	XSync(disp, True);

	// man XCloseDisplay says: "Before exiting, you should call XCloseDisplay explicitly so that any pending errors are reported as XCloseDisplay performs a final XSync operation."
	XCloseDisplay(disp);

	return 0;
}