Update some warnings and deprecations
Getty Ritter
5 years ago
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | 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>>, | |
| 14 | 14 | bg_color: (f64, f64, f64), |
| 15 | 15 | fg_color: (f64, f64, f64), |
| 16 | 16 | font: String, |
| 48 | 48 | // the file descriptors we care about here |
| 49 | 49 | let window_fds: Vec<i32> = ws.iter_mut().map({ |w| w.get_fd() }).collect(); |
| 50 | 50 | let stdin_fd = std::io::stdin().as_raw_fd(); |
| 51 | let mut fds = unsafe { std::mem::uninitialized() }; | |
| 52 | 51 | |
| 53 | 52 | // To begin with, our left-hand side---which normally is whatever |
| 54 | 53 | // was last passed in on stdin---will start as a generic |
| 91 | 90 | let max_fd = window_fds.iter().max().unwrap_or(&0) + 1; |
| 92 | 91 | // we're gonna keep looping until we don't |
| 93 | 92 | loop { |
| 93 | let mut fds = std::mem::MaybeUninit::uninit(); | |
| 94 | ||
| 94 | 95 | unsafe { |
| 95 | 96 | // set up the FD set to be the X11 fd and the state of stdin |
| 96 |
libc::FD_ZERO( |
|
| 97 | libc::FD_ZERO(fds.as_mut_ptr()); | |
| 98 | fds.assume_init(); | |
| 97 | 99 | for fd in window_fds.iter() { |
| 98 |
libc::FD_SET(*fd, |
|
| 100 | libc::FD_SET(*fd, fds.as_mut_ptr()); | |
| 99 | 101 | } |
| 100 |
libc::FD_SET(stdin_fd, |
|
| 102 | libc::FD_SET(stdin_fd, fds.as_mut_ptr()); | |
| 101 | 103 | timer.tv_sec = 5; |
| 102 | 104 | |
| 103 | 105 | // this will block until there's input on either of the |
| 104 | 106 | // above FDs or until five seconds have passed, whichever comes first |
| 105 | 107 | libc::select( |
| 106 | 108 | max_fd, |
| 107 |
|
|
| 109 | fds.as_mut_ptr(), | |
| 108 | 110 | std::ptr::null_mut(), |
| 109 | 111 | std::ptr::null_mut(), |
| 110 | 112 | &mut timer, |
| 113 | 115 | |
| 114 | 116 | // if we _did_ have input on stdin, then read it in: that'll |
| 115 | 117 | // be our new left-hand text |
| 116 |
if unsafe { libc::FD_ISSET(stdin_fd, |
|
| 118 | if unsafe { libc::FD_ISSET(stdin_fd, fds.as_mut_ptr()) } { | |
| 117 | 119 | use std::io::BufRead; |
| 118 | 120 | input = String::new(); |
| 119 | 121 | stdin.read_line(&mut input)?; |
| 243 | 243 | /// handle things like keyboard input and mouse input later. This |
| 244 | 244 | /// will also only return values for events we care about |
| 245 | 245 | pub fn handle(&mut self) -> Option<Event> { |
| 246 | let mut e = unsafe { mem::uninitialized() }; | |
| 247 | unsafe { xlib::XNextEvent(self.display.display, &mut e) }; | |
| 248 |
|
|
| 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() { | |
| 249 | 252 | // Is it a quit event? We gotta do some tedious string |
| 250 | 253 | // comparison to find out |
| 251 | 254 | xlib::ClientMessage => { |
| 252 |
let xclient: xlib::XClientMessageEvent = |
|
| 255 | let xclient: xlib::XClientMessageEvent = unsafe { From::from(*e.as_ptr()) }; | |
| 253 | 256 | if xclient.message_type == self.wm_protocols && xclient.format == 32 { |
| 254 | 257 | let protocol = xclient.data.get_long(0) as xlib::Atom; |
| 255 | 258 | if protocol == self.wm_delete_window { |
| 263 | 266 | |
| 264 | 267 | // otherwise, it might be a mouse press event |
| 265 | 268 | xlib::GenericEvent => { |
| 266 |
let mut cookie: xlib::XGenericEventCookie = |
|
| 269 | let mut cookie: xlib::XGenericEventCookie = unsafe { From::from(*e.as_ptr()) }; | |
| 267 | 270 | unsafe { xlib::XGetEventData(self.display.display, &mut cookie) }; |
| 268 | 271 | match cookie.evtype { |
| 269 | 272 | xinput2::XI_ButtonPress => { |