X11: get notified when a window is moved

My apps need to know when this window is moved (I need to know the exact position of my app's window relative to the screen (root window / absolute position) - like the one that comes back xcb_translate_coordinates

, with dst_window set to the root window of the screen).

The problem is I need to get an event if my window is moved by the user. I added XCB_EVENT_MASK_STRUCTURE_NOTIFY

events to the mask as suggested here on SO, my application only receives an event when its relative position changes to the window manager frame (which in turn, the X server does not fire any event for my application if the window is moved by the user because it does not change relative position to the window manager frame). For more information, here's the code for creating the window:

uint32_t events = XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_KEY_PRESS;
xcb_create_window(conn, XCB_COPY_FROM_PARENT, main_window, scr->root, 0, 0, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
                  scr->root_visual, XCB_CW_EVENT_MASK , &events);
xcb_map_window(conn, main_window);

      

I've tried this on my desktop and Xephyr, with Xfwm4, Openbox and metacity, both in layout mode and non-layout mode, and it still gives the same result.

What is the solution so that I can be notified of window motion events? I do not want to include override_redirect

because I also need my application to be controlled by a window manager.

+3


source to share


1 answer


Finally, after some research, it turned out that most window managers, at least those that do reparenting, stacking and / or layout, send an event to ConfigureNotify

their clients with <t21> flag set to true (for example, with MSB set to XCB response_type

), whose x

and y

set the absolute position of the client window. Verified with Xfwm4, Openbox, metacity and KWin.



+2


source







All Articles