Implemented focus_window (#1944)
This commit is contained in:
parent
91591c4e94
commit
b371b406d5
10 changed files with 107 additions and 0 deletions
|
|
@ -430,6 +430,14 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn focus_window(&self) {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
&Window::X(ref w) => w.focus_window(),
|
||||
#[cfg(feature = "wayland")]
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
pub fn request_user_attention(&self, _request_type: Option<UserAttentionType>) {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
use x11_dl::xmd::CARD32;
|
||||
pub use x11_dl::{
|
||||
error::OpenError, keysym::*, xcursor::*, xinput::*, xinput2::*, xlib::*, xlib_xcb::*,
|
||||
xrandr::*, xrender::*,
|
||||
};
|
||||
|
||||
// Isn't defined by x11_dl
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const IconicState: CARD32 = 3;
|
||||
|
|
|
|||
|
|
@ -1340,6 +1340,41 @@ impl UnownedWindow {
|
|||
self.set_ime_position_physical(x, y);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn focus_window(&self) {
|
||||
let state_atom = unsafe { self.xconn.get_atom_unchecked(b"WM_STATE\0") };
|
||||
let state_type_atom = unsafe { self.xconn.get_atom_unchecked(b"CARD32\0") };
|
||||
let is_minimized = if let Ok(state) =
|
||||
self.xconn
|
||||
.get_property(self.xwindow, state_atom, state_type_atom)
|
||||
{
|
||||
state.contains(&(ffi::IconicState as c_ulong))
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let is_visible = match self.shared_state.lock().visibility {
|
||||
Visibility::Yes => true,
|
||||
Visibility::YesWait | Visibility::No => false,
|
||||
};
|
||||
|
||||
if is_visible && !is_minimized {
|
||||
let atom = unsafe { self.xconn.get_atom_unchecked(b"_NET_ACTIVE_WINDOW\0") };
|
||||
let flusher = self.xconn.send_client_msg(
|
||||
self.xwindow,
|
||||
self.root,
|
||||
atom,
|
||||
Some(ffi::SubstructureRedirectMask | ffi::SubstructureNotifyMask),
|
||||
[1, ffi::CurrentTime as c_long, 0, 0, 0],
|
||||
);
|
||||
if let Err(e) = flusher.flush() {
|
||||
log::error!(
|
||||
"`flush` returned an error when focusing the window. Error was: {}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
||||
let mut wm_hints = self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue