Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor x11 event handling #1819

Merged
merged 10 commits into from
Apr 12, 2024
Merged

Refactor x11 event handling #1819

merged 10 commits into from
Apr 12, 2024

Conversation

Caellian
Copy link
Collaborator

This PR refactors event handling into separate functions in order to make the event handling code more readable. It's separated out of #1807 in order to make that future PR cleaner.

Copy link

netlify bot commented Apr 12, 2024

Deploy Preview for conkyweb canceled.

Name Link
🔨 Latest commit 4234463
🔍 Latest deploy log https://app.netlify.com/sites/conkyweb/deploys/6619275f69a5e40008d4a677

@github-actions github-actions bot added the sources PR modifies project sources label Apr 12, 2024
*consumed = false;
#endif /* BUILD_MOUSE_EVENTS */

if (!own_window.get(*state)) return true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only part that changes functionality.

@@ -1411,6 +1413,9 @@ void propagate_x11_event(XEvent &ev) {

XUngrabPointer(display, CurrentTime);
XSendEvent(display, i_ev->common.window, True, ev_to_mask(i_ev->type), &ev);
if (focus) {
XSetInputFocus(display, i_ev->common.window, RevertToParent, CurrentTime);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved XSetInputFocus here, after sending the event, if it's a ButtonPress.

break;
}
}
break;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These consecutive breaks made no sense to me, so I tracked down that the window type check was intended to avoid propagation of events (inner break) in the original code.

Over several commits, I seem to have made it do nothing.

case window_type::TYPE_UTILITY:
// decorated normal windows always consume events
if (!TEST_HINT(own_window_hints.get(*state), HINT_UNDECORATED)) {
*consumed = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now, it still passes the events to Lua, but force-disables propagation in case of normal decorated window, or desktop. Also added comments to make it clear in future.

Events now get correctly propagated to a window (or root if none) behind conky.
This was a necessary change to handle cases such as MATE+caja where caja
is used between conky and background to show icons and desktop menu.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Atoms should be faster than graph traversal, and also don't include
decorations (windows) inserted by WM/DEs, nor special 1x1 windows.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Causes input focus flickering, especially with WMs where focus follows
pointer. This looks weird (carret flashing) and effectively acheives
nothing. So I'm, leaving it up to WMs to manage focus.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
display_output_x11::main_loop_wait was getting long and hard to read.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
I think splitting it out into separate functions makes each part much
clearer and easier to follow, as well as reducing the complexity of
define conditions

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
@Caellian Caellian changed the title Fix/separate x11 events Refactor x11 event handling Apr 12, 2024
src/display-x11.cc Outdated Show resolved Hide resolved
This commit is final refactor commit that's fully functional and
contains fixes to old bugs and previously introduced regressions.

There's some extra arguments (cookie) that aren't used yet, but will be
in commits that succeed this one.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
bool handle_event(conky::display_output_x11 *surface, Display *display,
XEvent &ev, bool *consumed, void **cookie) {
return false;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced EV_HANDLER macro with a templated function.

Nice perk with this is that there's no need for explicit NOOP_EV_HANDLER.

@@ -675,33 +708,30 @@ EV_HANDLER(damage) {
x11_stuff.part);
return true;
}
#else
NOOP_EV_HANDLER(damage)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which removes these #else blocks

if (handle_event<x_event_handler::event>(surface, display, ev, consumed, \
cookie)) { \
return true; \
}
Copy link
Collaborator Author

@Caellian Caellian Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I keep a macro here?

It's right next to invocation, won't be called anywhere else, and quarters the code below. I would use a "compile-time for loop" to loop over all x_event_handler values, but those don't exist in C++.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this particular case is fine.

Copy link
Owner

@brndnmtthws brndnmtthws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

if (handle_event<x_event_handler::event>(surface, display, ev, consumed, \
cookie)) { \
return true; \
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this particular case is fine.

@Caellian Caellian merged commit c2dfa29 into main Apr 12, 2024
62 checks passed
@Caellian Caellian deleted the fix/separate-x11-events branch April 12, 2024 14:46
Caellian added a commit that referenced this pull request Apr 12, 2024
Move event handling code into separate functions.
Caellian added a commit that referenced this pull request Apr 12, 2024
Move event handling code into separate functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sources PR modifies project sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants