Skip to content

Commit

Permalink
Simplify cursor checking
Browse files Browse the repository at this point in the history
Additional tweaks and docs improvements

Signed-off-by: Tin <[email protected]>
  • Loading branch information
Caellian committed Nov 10, 2023
1 parent 670323e commit 8f98f68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
4 changes: 2 additions & 2 deletions doc/config_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions src/display-x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 14 additions & 19 deletions src/x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Window last = None;
// 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;

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];
}
}
}
Window last = None;
XQueryPointer(display, window.root, &root_return, &last,
&root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return
);

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);
}

Expand Down
1 change: 0 additions & 1 deletion src/x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit 8f98f68

Please sign in to comment.