From 06bd3d9ac5a9e808ea17568296a65a891ac8de7f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 10 Dec 2024 19:41:34 +0100 Subject: Timeout window creation position hack, force floating --- TODO | 1 + src/main.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..4f74e40 --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +XFixes for hiding portion of window doesn't work in Hyprland. That means when the window is animated then a portion of it can be visible on another monitor. diff --git a/src/main.cpp b/src/main.cpp index 25cb72a..8f2b849 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -169,10 +170,11 @@ static const mgl_monitor* find_monitor_at_position(mgl::Window &window, mgl::vec } static mgl::vec2i create_window_get_center_position(Display *display) { + const int size = 16; XSetWindowAttributes window_attr; window_attr.event_mask = StructureNotifyMask; window_attr.background_pixel = 0; - const Window window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 16, 16, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &window_attr); + const Window window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, size, size, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &window_attr); if(!window) return {0, 0}; @@ -191,12 +193,36 @@ static mgl::vec2i create_window_get_center_position(Display *display) { const unsigned long opacity = (unsigned long)(0xFFFFFFFFul * alpha); XChangeProperty(display, window, net_wm_window_opacity, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L); + XSizeHints *size_hints = XAllocSizeHints(); + size_hints->width = size; + size_hints->min_width = size; + size_hints->max_width = size; + size_hints->height = size; + size_hints->min_height = size; + size_hints->max_height = size; + size_hints->flags = PSize | PMinSize | PMaxSize; + XSetWMNormalHints(display, window, size_hints); + XFree(size_hints); + XMapWindow(display, window); XFlush(display); + const int x_fd = XConnectionNumber(display); mgl::vec2i window_pos; XEvent xev; while(true) { + struct pollfd poll_fd; + poll_fd.fd = x_fd; + poll_fd.events = POLLIN; + poll_fd.revents = 0; + const int fds_ready = poll(&poll_fd, 1, 1000); + if(fds_ready == 0) { + fprintf(stderr, "Error: timed out waiting for ConfigureNotify after XCreateWindow\n"); + break; + } else if(fds_ready == -1 || !(poll_fd.revents & POLLIN)) { + continue; + } + XNextEvent(display, &xev); if(xev.type == ConfigureNotify) { window_pos.x = xev.xconfigure.x + xev.xconfigure.width / 2; -- cgit v1.2.3