summaryrefslogtreecommitdiff
path: root/src/switch-input.c
blob: cdf490c2b5184b969916313d77cdf2300ddd1ceb (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
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>

int main( int argc, char* argv[]) {
	printf("hallo\n");
	Display* display;
	int display_cnt;
	char* display_name;
	int current_screen, new_screen;

	Window current_focus;
	Window new_root;
	XWindowAttributes current_focus_attributes;

	display_name = getenv("DISPLAY");
	if ( display_name == NULL ) {
		printf("DISPLAY is not set.\n");
		return 1;
	}

	display = XOpenDisplay(display_name);
	if (! display ) {
		printf("Could not open display.\n");
		return 1;
	}

	display_cnt = ScreenCount(display);

	printf("Number of displays: %i\n", display_cnt);
	if (display_cnt < 2) {
		printf("Not enough screens :'(\n");
		return 1;
	}

	int revert; //Unused
	XGetInputFocus ( display, &current_focus, &revert );
	XGetWindowAttributes ( display, current_focus, &current_focus_attributes );

	current_screen = XScreenNumberOfScreen( current_focus_attributes.screen );

	printf("current: %i\n", current_screen);

	// Cycle through screens
	new_screen = current_screen < (display_cnt -1) ? current_screen + 1 : 0;

	new_root = RootWindow( display, new_screen );

	XSetInputFocus ( display, new_root, RevertToParent, CurrentTime );

	XGetWindowAttributes ( display, new_root, &current_focus_attributes );
	int new_x = (current_focus_attributes.width / 2);
	int new_y = (current_focus_attributes.height / 2);
	XWarpPointer( display, None, new_root, 0,0,0,0, new_x, new_y);

	XCloseDisplay(display);
	return 0;
}