gdritter repos knurling / f4aa185
Update some warnings and deprecations Getty Ritter 4 years ago
3 changed file(s) with 18 addition(s) and 13 deletion(s). Collapse all Expand all
99 }
1010
1111 pub struct Config {
12 left: Vec<Box<w::Widget>>,
13 right: Vec<Box<w::Widget>>,
12 left: Vec<Box<dyn w::Widget>>,
13 right: Vec<Box<dyn w::Widget>>,
1414 bg_color: (f64, f64, f64),
1515 fg_color: (f64, f64, f64),
1616 font: String,
4848 // the file descriptors we care about here
4949 let window_fds: Vec<i32> = ws.iter_mut().map({ |w| w.get_fd() }).collect();
5050 let stdin_fd = std::io::stdin().as_raw_fd();
51 let mut fds = unsafe { std::mem::uninitialized() };
5251
5352 // To begin with, our left-hand side---which normally is whatever
5453 // was last passed in on stdin---will start as a generic
9190 let max_fd = window_fds.iter().max().unwrap_or(&0) + 1;
9291 // we're gonna keep looping until we don't
9392 loop {
93 let mut fds = std::mem::MaybeUninit::uninit();
94
9495 unsafe {
9596 // set up the FD set to be the X11 fd and the state of stdin
96 libc::FD_ZERO(&mut fds);
97 libc::FD_ZERO(fds.as_mut_ptr());
98 fds.assume_init();
9799 for fd in window_fds.iter() {
98 libc::FD_SET(*fd, &mut fds);
100 libc::FD_SET(*fd, fds.as_mut_ptr());
99101 }
100 libc::FD_SET(stdin_fd, &mut fds);
102 libc::FD_SET(stdin_fd, fds.as_mut_ptr());
101103 timer.tv_sec = 5;
102104
103105 // this will block until there's input on either of the
104106 // above FDs or until five seconds have passed, whichever comes first
105107 libc::select(
106108 max_fd,
107 &mut fds,
109 fds.as_mut_ptr(),
108110 std::ptr::null_mut(),
109111 std::ptr::null_mut(),
110112 &mut timer,
113115
114116 // if we _did_ have input on stdin, then read it in: that'll
115117 // be our new left-hand text
116 if unsafe { libc::FD_ISSET(stdin_fd, &mut fds) } {
118 if unsafe { libc::FD_ISSET(stdin_fd, fds.as_mut_ptr()) } {
117119 use std::io::BufRead;
118120 input = String::new();
119121 stdin.read_line(&mut input)?;
243243 /// handle things like keyboard input and mouse input later. This
244244 /// will also only return values for events we care about
245245 pub fn handle(&mut self) -> Option<Event> {
246 let mut e = unsafe { mem::uninitialized() };
247 unsafe { xlib::XNextEvent(self.display.display, &mut e) };
248 match e.get_type() {
246 let mut e = mem::MaybeUninit::uninit();
247 unsafe {
248 xlib::XNextEvent(self.display.display, e.as_mut_ptr());
249 e.assume_init();
250 }
251 match unsafe { *e.as_ptr() }.get_type() {
249252 // Is it a quit event? We gotta do some tedious string
250253 // comparison to find out
251254 xlib::ClientMessage => {
252 let xclient: xlib::XClientMessageEvent = From::from(e);
255 let xclient: xlib::XClientMessageEvent = unsafe { From::from(*e.as_ptr()) };
253256 if xclient.message_type == self.wm_protocols && xclient.format == 32 {
254257 let protocol = xclient.data.get_long(0) as xlib::Atom;
255258 if protocol == self.wm_delete_window {
263266
264267 // otherwise, it might be a mouse press event
265268 xlib::GenericEvent => {
266 let mut cookie: xlib::XGenericEventCookie = From::from(e);
269 let mut cookie: xlib::XGenericEventCookie = unsafe { From::from(*e.as_ptr()) };
267270 unsafe { xlib::XGetEventData(self.display.display, &mut cookie) };
268271 match cookie.evtype {
269272 xinput2::XI_ButtonPress => {