Skip to content

Commit

Permalink
X11: getting a key event implies having focus
Browse files Browse the repository at this point in the history
There are cases commented in #2841, such a bare X11 server without
a Window Manager, where focus events can't be trusted.
  • Loading branch information
rodrigorc committed Sep 9, 2024
1 parent bc917de commit d4eff84
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,12 +869,30 @@ impl EventProcessor {
// Set the timestamp.
self.target.xconn.set_timestamp(xev.time as xproto::Timestamp);

// A key input implies being the active window
let window = match self.active_window {
Some(window) => window,
None => return,
None => *self.active_window.insert(xev.window as xproto::Window),
};

let window_id = mkwid(window);
// A key input also implies having the focus.
// `focused` indicates if the focus has been gained here and we have to
// notify the user callback.
let focused = self.with_window(window, |window| {
let mut shared_state_lock = window.shared_state_lock();
if !shared_state_lock.has_focus {
shared_state_lock.has_focus = true;
true
} else {
false
}
});
if focused == Some(true) {
let event = Event::WindowEvent { window_id, event: WindowEvent::Focused(true) };
callback(&self.target, event);
}

let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD);

let keycode = xev.keycode as _;
Expand Down

0 comments on commit d4eff84

Please sign in to comment.