From e99ad3688971fde57cf34d4a9f5dd89256c7ab78 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 22 Nov 2015 20:07:01 -0300 Subject: Move the file descriptor of the socket to the select event. --- src/event.rs | 5 +++-- src/main.rs | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/event.rs b/src/event.rs index f683c63..6f5c427 100644 --- a/src/event.rs +++ b/src/event.rs @@ -32,6 +32,7 @@ use std::fmt; use std::ptr; use std::mem::uninitialized; use std::cmp::max; +use std::os::unix::io::AsRawFd; use safe_x11::next_xevent; @@ -73,13 +74,13 @@ impl fmt::Debug for Event { } } -pub unsafe fn select_event(display: *mut Display, x11fd: c_int, socket_fd: c_int, - listener: &UnixListener) -> Event { +pub unsafe fn select_event(display: *mut Display, x11fd: c_int, listener: &UnixListener) -> Event { // Return right now if there're some XEvent on the queue if XPending(display) > 0 { return next_event(display); } + let socket_fd = listener.as_raw_fd(); let mut read_fdset: fd_set = uninitialized(); FD_ZERO(&mut read_fdset); diff --git a/src/main.rs b/src/main.rs index cd64f87..27c1a46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,6 @@ use x11::xlib; use x11::xlib::XEvent; use x11::keysym; -use std::os::unix::io::AsRawFd; use std::io::{Read,Write}; use unix_socket::UnixListener; @@ -46,13 +45,12 @@ fn main() { add_binding(&mut dotwm, &mut bindings, keysym::XK_q, xlib::Mod4Mask | xlib::ShiftMask, quit_dotwm, &[]); let listener = UnixListener::bind("./dotwm.sock").unwrap(); - let socket_fd = listener.as_raw_fd(); exec_cmd("./autostart", &[]).unwrap(); // Main loop loop { - let event = unsafe { select_event(dotwm.display, x11_fd, socket_fd, &listener) }; + let event = unsafe { select_event(dotwm.display, x11_fd, &listener) }; match event { Event::Key(mut e, true) => { let keysym = unsafe { xlib::XLookupKeysym(&mut e, 0) as u32 }; -- cgit v1.2.3-70-g09d2