Implement _NET_WM_PING for X11 (#977)

This commit is contained in:
Ho-Yon Mak 2019-06-28 01:40:27 +01:00 committed by Hal Gentz
parent dd38fab2f3
commit 23354cf1a5
4 changed files with 18 additions and 2 deletions

View file

@ -3,6 +3,7 @@
- On Mac, implement `DeviceEvent::Button`.
- Change `Event::Suspended(true / false)` to `Event::Suspended` and `Event::Resumed`.
- On X11, fix sanity check which checks that a monitor's reported width and height (in millimeters) are non-zero when calculating the DPI factor.
- On X11, implement `_NET_WM_PING` to allow desktop environment to kill unresponsive programs.
- On Windows, when a window is initially invisible, it won't take focus from the existing visible windows.
# 0.20.0 Alpha 1

View file

@ -131,6 +131,16 @@ impl<T: 'static> EventProcessor<T> {
window_id,
event: WindowEvent::CloseRequested,
});
} else if client_msg.data.get_long(0) as ffi::Atom == wt.net_wm_ping {
let response_msg: &mut ffi::XClientMessageEvent = xev.as_mut();
response_msg.window = wt.root;
wt.xconn
.send_event(
wt.root,
Some(ffi::SubstructureNotifyMask | ffi::SubstructureRedirectMask),
*response_msg,
)
.queue();
} else if client_msg.message_type == self.dnd.atoms.enter {
let source_window = client_msg.data.get_long(0) as c_ulong;
let flags = client_msg.data.get_long(1);

View file

@ -46,6 +46,7 @@ use crate::{
pub struct EventLoopWindowTarget<T> {
xconn: Arc<XConnection>,
wm_delete_window: ffi::Atom,
net_wm_ping: ffi::Atom,
ime_sender: ImeSender,
root: ffi::Window,
ime: RefCell<Ime>,
@ -75,6 +76,8 @@ impl<T: 'static> EventLoop<T> {
let wm_delete_window = unsafe { xconn.get_atom_unchecked(b"WM_DELETE_WINDOW\0") };
let net_wm_ping = unsafe { xconn.get_atom_unchecked(b"_NET_WM_PING\0") };
let dnd = Dnd::new(Arc::clone(&xconn))
.expect("Failed to call XInternAtoms when initializing drag and drop");
@ -142,6 +145,7 @@ impl<T: 'static> EventLoop<T> {
ime_sender,
xconn,
wm_delete_window,
net_wm_ping,
pending_redraws: Default::default(),
}),
_marker: ::std::marker::PhantomData,

View file

@ -330,8 +330,9 @@ impl UnownedWindow {
(xconn.xlib.XSetWMProtocols)(
xconn.display,
window.xwindow,
&event_loop.wm_delete_window as *const ffi::Atom as *mut ffi::Atom,
1,
&[event_loop.wm_delete_window, event_loop.net_wm_ping] as *const ffi::Atom
as *mut ffi::Atom,
2,
);
} //.queue();