From 03cf6ed35f26299dde1fcd850691e650ef79ac71 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sat, 17 Nov 2018 19:08:47 +0100 Subject: [PATCH] seat: KeyboardHandle::has_focus --- src/wayland/seat/keyboard.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wayland/seat/keyboard.rs b/src/wayland/seat/keyboard.rs index 0ca99c6..2aaa0e2 100644 --- a/src/wayland/seat/keyboard.rs +++ b/src/wayland/seat/keyboard.rs @@ -11,7 +11,7 @@ use wayland_server::{ wl_keyboard::{Event, KeyState as WlKeyState, KeymapFormat, Request, WlKeyboard}, wl_surface::WlSurface, }, - NewResource, Resource, + Client, NewResource, Resource, }; use xkbcommon::xkb; pub use xkbcommon::xkb::{keysyms, Keysym}; @@ -392,6 +392,19 @@ impl KeyboardHandle { } } + /// Check if given client currently has keyboard focus + pub fn has_focus(&self, client: &Client) -> bool { + self.arc + .internal + .lock() + .unwrap() + .focus + .as_ref() + .and_then(|f| f.client()) + .map(|c| c.equals(client)) + .unwrap_or(false) + } + /// Register a new keyboard to this handler /// /// The keymap will automatically be sent to it