Loop your X cursor around the screen 👉😎👉
git clone https://mcol.xyz/code/xoop
Log | Files | Refs | README | LICENSE

commit 752261d295cb5681f474549e4bd197864f975669
parent e55f495331271a372ae1b603d2a94966a995f828
Author: mcol <mcol@posteo.net>
Date:   Sat, 18 Apr 2020 18:41:28 +0100

Set window shape as 1px inside border of screen

Diffstat:
Mmakefile | 2+-
Mxoop.c | 93++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
2 files changed, 62 insertions(+), 33 deletions(-)

diff --git a/makefile b/makefile @@ -1,6 +1,6 @@ OUT = xoop SRC = xoop.c -CFLAGS += -Wall -Wextra -pedantic -lxcb +CFLAGS += -Wall -Wextra -pedantic -lxcb -lxcb-shape PREFIX ?= /usr/local BINPREFIX ?= $(PREFIX)/bin diff --git a/xoop.c b/xoop.c @@ -2,35 +2,13 @@ #include <stdio.h> #include <string.h> #include <xcb/xcb.h> +#include <xcb/shape.h> xcb_connection_t *conn; xcb_screen_t *screen; -void clip_window(xcb_window_t wid) -{ - uint32_t mask; - xcb_gcontext_t gc; - - mask = XCB_GC_CLIP_ORIGIN_X | XCB_GC_CLIP_ORIGIN_Y;// | XCB_GC_CLIP_MASK - - const uint32_t values[] = { - 1, - 1, - }; - - gc = xcb_generate_id(conn); - xcb_create_gc( - conn, - gc, - wid, - mask, - values - ); -} - - void set_window_type(xcb_window_t wid) { xcb_intern_atom_cookie_t cookie1, cookie2; xcb_intern_atom_reply_t *reply1, *reply2; @@ -55,12 +33,67 @@ void set_window_type(xcb_window_t wid) { } +void set_window_shape(xcb_window_t wid) +{ + xcb_gcontext_t gc = xcb_generate_id(conn); + xcb_pixmap_t pixmap = xcb_generate_id(conn); + + xcb_create_pixmap( + conn, + 1, + pixmap, + wid, + screen->width_in_pixels, + screen->height_in_pixels + ); + + const uint32_t values[] = { + screen->white_pixel, + }; + + xcb_create_gc( + conn, + gc, + pixmap, + XCB_GC_FOREGROUND, + values + ); + + xcb_rectangle_t rect = { + 1, + 1, + screen->width_in_pixels - 2, + screen->height_in_pixels - 2 + }; + xcb_poly_fill_rectangle( + conn, + pixmap, + gc, + 1, + &rect + ); + + xcb_shape_mask( + conn, + XCB_SHAPE_SO_SUBTRACT, + XCB_SHAPE_SK_INPUT, + wid, + 0, + 0, + pixmap + ); + + xcb_free_gc(conn, gc); + xcb_free_pixmap(conn, pixmap); +} + + xcb_window_t setup_window() { xcb_window_t wid = xcb_generate_id(conn); - uint32_t mask_val = 0; - mask_val |= XCB_EVENT_MASK_ENTER_WINDOW; + uint32_t values = 0; + values |= XCB_EVENT_MASK_ENTER_WINDOW; xcb_create_window( conn, @@ -69,17 +102,17 @@ xcb_window_t setup_window() screen->root, 0, 0, - 1, // screen->width_in_pixels + screen->width_in_pixels, screen->height_in_pixels, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, - &mask_val + &values ); set_window_type(wid); - clip_window(wid); + set_window_shape(wid); uint32_t above = XCB_STACK_MODE_ABOVE; xcb_configure_window(conn, wid, XCB_CONFIG_WINDOW_STACK_MODE, &above); @@ -111,10 +144,6 @@ void event_loop() case XCB_ENTER_NOTIFY: printf("# enter window\n"); break; - - default: - printf("# %d\n", event->response_type); - break; } free(event);