summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-07-08 02:10:07 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-07-08 02:10:07 +0200
commitcb6265680c0154df59dc686001b73ef863823a8a (patch)
tree6c25df891809b0bd110d55eeae1e800ec9e71502
downloadx-cycle-screen-cb6265680c0154df59dc686001b73ef863823a8a.tar.gz
initial
-rw-r--r--Makefile39
-rw-r--r--src/switch-input.c58
2 files changed, 97 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..bf7a854
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,39 @@
+CC = clang
+CFLAGS = -Wall
+LDFLAGS = -lX11
+BUILDDIR = build
+SOURCEDIR = src
+OBJECTDIR = obj
+
+OUTPUT = switch-input
+
+SRCS = $(wildcard $(SOURCEDIR)/*.c)
+OBJS = $(SRCS:.c=.o)
+OBJ = $(OBJS:$(SOURCEDIR)/%=$(OBJECTDIR)/%)
+
+build: dir $(OBJ)
+ @echo LD $(OBJ)
+ @$(CC) $(CFLAGS) -o $(BUILDDIR)/$(OUTPUT) $(OBJ) $(LDFLAGS)
+
+debug: CFLAGS += -g -D _DEBUG
+debug: build;
+
+dir:
+ @mkdir -p $(OBJECTDIR)
+ @mkdir -p $(BUILDDIR)
+
+$(OBJECTDIR)/%.o: $(SOURCEDIR)/%.c
+ @echo CC $<
+ @$(CC) $(CFLAGS) -c $< -o $@
+
+.PHONY: clean
+clean:
+ @echo RM $(OBJ)
+ @echo RM $(BUILDDIR)/$(OUTPUT)
+ @rm -df $(OBJ)
+ @rm -Rdf $(BUILDDIR) $(OBJECTDIR)
+
+all: clean build
+
+run: build
+ @$(BUILDDIR)/$(OUTPUT)
diff --git a/src/switch-input.c b/src/switch-input.c
new file mode 100644
index 0000000..cdf490c
--- /dev/null
+++ b/src/switch-input.c
@@ -0,0 +1,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;
+}