From 44b986c762815874ccfb636152ae452ecba48764 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 30 Mar 2022 01:19:50 +0200 Subject: wip --- .gitignore | 5 +++++ main.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ project.conf | 8 +++++++ 3 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 main.cpp create mode 100644 project.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..636c6b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Compiled sibs files +sibs-build/ +compile_commands.json +tests/sibs-build/ +tests/compile_commands.json diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ee58e4d --- /dev/null +++ b/main.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + +static int x11_error_handler(Display *dpy, XErrorEvent *ev) { + return 0; +} + +static void usage() { + fprintf(stderr, "usage: window-overlay \n"); + exit(1); +} + +static bool string_to_i64(const char *str, int64_t *result) { + errno = 0; + char *endptr = nullptr; + int64_t res = strtoll(str, &endptr, 0); + if(endptr == str || errno != 0) + return false; + + *result = res; + return true; +} + +int main(int argc, char **argv) { + if(argc != 2) + usage(); + + int64_t target_window; + if(!string_to_i64(argv[1], &target_window)) { + fprintf(stderr, "Error: invalid number '%s' was specific for window argument\n", argv[1]); + return 1; + } + + XSetErrorHandler(x11_error_handler); + + Display *display = XOpenDisplay(NULL); + if(!display) { + fprintf(stderr, "Error: XOpenDisplay failed\n"); + return 1; + } + + //const Window root_window = DefaultRootWindow(display); + const int screen = DefaultScreen(display); + + XSetWindowAttributes attr; + attr.background_pixel = XWhitePixel(display, screen); + attr.override_redirect = True; + + Window overlay_window = XCreateWindow(display, target_window, 0, 0, 256, 256, 0, DefaultDepth(display, screen), InputOutput, XDefaultVisual(display, screen), CWBackPixel|CWOverrideRedirect, &attr); + if(!overlay_window) { + fprintf(stderr, "Error: failed to create overlay window\n"); + return 1; + } + + Cursor default_cursor = XCreateFontCursor(display, XC_arrow); + + XMapWindow(display, overlay_window); + XGrabPointer(display, overlay_window, True, ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeSync, None, default_cursor, CurrentTime); + sleep(3); + + /*XEvent xev; + for(;;) { + XNextEvent(display, &xev); + }*/ + + return 0; +} diff --git a/project.conf b/project.conf new file mode 100644 index 0000000..2805290 --- /dev/null +++ b/project.conf @@ -0,0 +1,8 @@ +[package] +name = "window-overlay" +type = "executable" +version = "0.1.0" +platforms = ["posix"] + +[dependencies] +x11 = ">=1" -- cgit v1.2.3