Simplify cursor checking

Additional tweaks and docs improvements

Signed-off-by: Tin <tin.svagelj@live.com>
This commit is contained in:
Tin 2023-11-10 03:11:02 +01:00 committed by Brenden Matthews
parent a591228b71
commit 965d7dc0a4
No known key found for this signature in database
GPG Key ID: 137B7AC2BDFD8DF0
4 changed files with 18 additions and 25 deletions

View File

@ -369,7 +369,7 @@ values:
- name: overwrite_file
desc: Overwrite the file given as argument.
- name: own_window
desc: Boolean, create own window to draw.
desc: Boolean, draw conky in own window instead of drawing on root window.
- name: own_window_argb_value
desc: |-
When ARGB visuals are enabled, this use this to modify the
@ -388,7 +388,7 @@ values:
desc: |-
If own_window_transparent no, set a specified background
colour. Takes either a hex value (e.g. '#ffffff'),
a shorthand hex value (e.g. '#fff'), or a valid RGB nam
a shorthand hex value (e.g. '#fff'), or a valid RGB name
(see `/usr/lib/X11/rgb.txt`).
default: black
args:

View File

@ -382,13 +382,12 @@ bool display_output_x11::main_loop_wait(double t) {
XNextEvent(display, &ev);
#ifdef BUILD_XINPUT
#if defined(BUILD_MOUSE_EVENTS) && defined(BUILD_XINPUT)
if (ev.type == GenericEvent && ev.xcookie.extension == window.xi_opcode) {
XGetEventData(display, &ev.xcookie);
if (ev.xcookie.evtype == XI_Motion) {
auto *data = reinterpret_cast<XIDeviceEvent*>(ev.xcookie.data);
// XQueryPointer returns wrong results because conky is a weird window
Window query_result = query_x11_window_at_pos(display, data->root_x, data->root_y);
static bool cursor_inside = false;
@ -415,7 +414,7 @@ bool display_output_x11::main_loop_wait(double t) {
XFreeEventData(display, &ev.xcookie);
continue;
}
#endif /* BUILD_XINPUT */
#endif /* BUILD_MOUSE_EVENTS && BUILD_XINPUT */
// Any of the remaining events apply to conky window
if (ev.xany.window != window.window) continue;

View File

@ -1381,7 +1381,9 @@ void propagate_x11_event(XEvent &ev) {
}
#ifdef BUILD_MOUSE_EVENTS
Window last_descendant(Display* display, Window parent) {
// Assuming parent has a simple linear stack of descendants, this function
// returns the last leaf on the graph.
inline Window last_descendant(Display* display, Window parent) {
Window ignored, *children;
uint32_t count;
@ -1398,26 +1400,19 @@ Window last_descendant(Display* display, Window parent) {
Window query_x11_window_at_pos(Display* display, int x, int y) {
Window root = DefaultRootWindow(display);
Window root_return, parent_return, *windows;
unsigned int count;
// these values are ignored but NULL can't be passed
Window root_return;
int root_x_return, root_y_return, win_x_return, win_y_return;
unsigned int mask_return;
Window last = None;
XQueryPointer(display, window.root, &root_return, &last,
&root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return
);
XWindowAttributes attrs;
if (XQueryTree(display, root, &root_return, &parent_return, &windows, &count) != 0) {
for (unsigned int i = 0; i < count; i++) {
if (XGetWindowAttributes(display, windows[i], &attrs)) {
if (attrs.map_state == IsViewable && x >= attrs.x && x < (attrs.x + attrs.width) && y >= attrs.y && y < (attrs.y + attrs.height)) {
last = windows[i];
}
}
}
if (count != 0) {
XFree(windows);
}
}
// X11 correctly returns a window which covers conky area, but returned window
// is not window.window, but instead a parent node in some cases and the
// window.window we want to check for is a 1x1 child of that window.
return last_descendant(display, last);
}

View File

@ -150,7 +150,6 @@ InputEvent *xev_as_input_event(XEvent &ev);
void propagate_x11_event(XEvent &ev);
#ifdef BUILD_MOUSE_EVENTS
Window query_x11_window_at_pos(Display* display, int x, int y);
#endif /* BUILD_MOUSE_EVENTS */