diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2016-06-03 16:25:16 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2016-06-03 16:25:16 -0300 |
commit | 25034f8d4d70b4048d7540264fc18461982406aa (patch) | |
tree | be189be1386f9e75b964ac7e0914832075cdeb1d | |
parent | da3fa00ccf4cde76d1d6489c6043d7e56d4f52c5 (diff) | |
download | dotwm-25034f8d4d70b4048d7540264fc18461982406aa.tar.gz |
Add Clippy as dependency.
This brings a lot of clean up on the code.
-rw-r--r-- | Cargo.lock | 69 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/desktop.rs | 23 | ||||
-rw-r--r-- | src/dotwm.rs | 9 | ||||
-rw-r--r-- | src/event.rs | 30 | ||||
-rw-r--r-- | src/main.rs | 9 | ||||
-rw-r--r-- | src/safe_x11/mod.rs | 5 | ||||
-rw-r--r-- | src/safe_x11/window.rs | 12 | ||||
-rw-r--r-- | src/socket/mod.rs | 13 | ||||
-rw-r--r-- | src/socket/parser.rs | 8 |
10 files changed, 129 insertions, 53 deletions
@@ -2,6 +2,7 @@ name = "dotwm" version = "0.1.0" dependencies = [ + "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -14,6 +15,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "clippy" +version = "0.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clippy_lints 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "quine-mc_cluskey 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "clippy_lints" +version = "0.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quine-mc_cluskey 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "lazy_static" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -24,11 +52,52 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "nom" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "pkg-config" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "quine-mc_cluskey" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "regex-syntax" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rustc-serialize" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "semver" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nom 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "toml" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "unix_socket" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -7,7 +7,11 @@ authors = ["Matias Linares <matiaslina@openmailbox.org>"] libc = "0.2.*" unix_socket = "*" lazy_static = "0.1.15" +clippy = { version ="*", optional = true } [dependencies.x11] version = "*" features = ["xlib"] + +[features] +default = [] diff --git a/src/desktop.rs b/src/desktop.rs index afe6a28..aac472f 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -69,18 +69,15 @@ impl Desktop { pub fn remove_window(&mut self, w: xlib::Window) { let pos = self.window_list.iter().position(|xw| xw.inner == w); - match pos { - Some(idx) => { - let new_idx = if idx == 0 { - if self.window_list.len() == 1 { usize::max_value() } else { 0 } - } else { - idx - 1 - }; - self.window_list.remove(idx); - self.cw_idx = new_idx; - self.focus_current_window(); - }, - None => (), + if let Some(idx) = pos { + let new_idx = if idx == 0 { + if self.window_list.len() == 1 { usize::max_value() } else { 0 } + } else { + idx - 1 + }; + self.window_list.remove(idx); + self.cw_idx = new_idx; + self.focus_current_window(); } } @@ -160,7 +157,7 @@ impl Desktop { (screen_width as i32, screen_height as i32), ]; - for w in self.window_list.iter() { + for w in &self.window_list { let attrs = w.attributes(); result.push((attrs.x, attrs.y)); result.push((attrs.x + attrs.width, attrs.y + attrs.height)); diff --git a/src/dotwm.rs b/src/dotwm.rs index 666deff..fd28765 100644 --- a/src/dotwm.rs +++ b/src/dotwm.rs @@ -51,6 +51,7 @@ pub enum WmAtom { } #[derive(Hash,Eq,PartialEq)] +#[allow(enum_variant_names)] pub enum NetAtom { NetSupported, NetFullscreen, @@ -74,7 +75,7 @@ pub struct DotWM { pub desktops: Vec<Desktop>, } -/// DotWM state. +/// `DotWM` state. impl DotWM { /// Create a state of the Dot Window Manager pub fn new() -> DotWM { @@ -218,6 +219,12 @@ impl DotWM { } } +impl Default for DotWM { + fn default() -> Self { + DotWM::new() + } +} + impl Drop for DotWM { fn drop(&mut self) { close_display(self.display); diff --git a/src/event.rs b/src/event.rs index b97686f..768e37a 100644 --- a/src/event.rs +++ b/src/event.rs @@ -56,21 +56,21 @@ pub enum Event { impl fmt::Debug for Event { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = match self { - &Event::Key(ev, pressed) => format!("Key({}, {})", XEvent::from(ev).get_type(), pressed), - &Event::Button(ev, pressed) => format!("Button({}, {})", XEvent::from(ev).get_type(), pressed), - &Event::Drag(ev) => format!("Drag({})", XEvent::from(ev).get_type()), - &Event::Generic(ev) => format!("Generic({})", XEvent::from(ev).get_type()), - &Event::Enter(ev) => format!("Enter({})", XEvent::from(ev).get_type()), - &Event::Leave(ev) => format!("Enter({})", XEvent::from(ev).get_type()), - &Event::Create(ev) => format!("Create({})", XEvent::from(ev).get_type()), - &Event::Destroy(ev) => format!("Destroy({})", XEvent::from(ev).get_type()), - &Event::Unmap(ev) => format!("Unmap({})", XEvent::from(ev).get_type()), - &Event::Map(ev) => format!("Map({})", XEvent::from(ev).get_type()), - &Event::Configure(ev) => format!("Configure({})", XEvent::from(ev).get_type()), - &Event::Expose(ev) => format!("Expose({})", XEvent::from(ev).get_type()), - &Event::Socket(_) => format!("Socket()"), - &Event::NoEvent => format!("NoEvent"), + let s = match *self { + Event::Key(ev, pressed) => format!("Key({}, {})", XEvent::from(ev).get_type(), pressed), + Event::Button(ev, pressed) => format!("Button({}, {})", XEvent::from(ev).get_type(), pressed), + Event::Drag(ev) => format!("Drag({})", XEvent::from(ev).get_type()), + Event::Generic(ev) => format!("Generic({})", XEvent::from(ev).get_type()), + Event::Enter(ev) => format!("Enter({})", XEvent::from(ev).get_type()), + Event::Leave(ev) => format!("Enter({})", XEvent::from(ev).get_type()), + Event::Create(ev) => format!("Create({})", XEvent::from(ev).get_type()), + Event::Destroy(ev) => format!("Destroy({})", XEvent::from(ev).get_type()), + Event::Unmap(ev) => format!("Unmap({})", XEvent::from(ev).get_type()), + Event::Map(ev) => format!("Map({})", XEvent::from(ev).get_type()), + Event::Configure(ev) => format!("Configure({})", XEvent::from(ev).get_type()), + Event::Expose(ev) => format!("Expose({})", XEvent::from(ev).get_type()), + Event::Socket(_) => String::from("Socket()"), + Event::NoEvent => String::from("NoEvent"), }; write!(f, "{}", s) diff --git a/src/main.rs b/src/main.rs index 4f292b6..b1873f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ // See LICENSE file for copyright and license details. +#![cfg_attr(feature="clippy", feature(plugin))] +#![cfg_attr(feature="clippy", plugin(clippy))] extern crate libc; extern crate x11; extern crate unix_socket; @@ -32,9 +34,8 @@ const SOCKET_PATH: &'static str = "./dotwm.sock"; fn run_autostart() { let paths = &["./autostart", "/home/matias/.config/dotwm/autostart"]; for path in paths { - match exec_cmd(path, &[]) { - Ok(_) => break, - Err(_) => (), + if exec_cmd(path, &[]).is_ok() { + break; } } } @@ -86,7 +87,7 @@ fn main() { s.read_to_string(&mut buf).unwrap(); for line in buf.lines() { - let res = parser::parse(&line); + let res = parser::parse(line); match res { Ok(pcmd) => { pcmd.handle(&mut dotwm, &mut bindings); diff --git a/src/safe_x11/mod.rs b/src/safe_x11/mod.rs index 3d08a4e..613424a 100644 --- a/src/safe_x11/mod.rs +++ b/src/safe_x11/mod.rs @@ -74,13 +74,13 @@ pub fn close_display(display: *mut Display) { unsafe { xlib::XCloseDisplay(display); } } -/// Get the file descriptor for the XServer +/// Get the file descriptor for the `XServer` pub fn x11_fd(display: *mut Display) -> c_int { unsafe { XConnectionNumber(display) } } /// Get the next event from the xserver. This call will not block forever -/// (like XNextEvent), instead it will wait for a certain time (1 second +/// (like `XNextEvent`), instead it will wait for a certain time (1 second /// for now, but it can change) so we're not blocking the socket interface /// on the main thread. pub fn next_xevent(display: *mut Display) -> XEvent { @@ -124,6 +124,7 @@ pub fn root_window(display: *mut Display) -> Window { /// 0, 0 /// ); /// ``` +#[allow(too_many_arguments)] pub fn grab_button(display: *mut Display, button: u32, modifiers: u32, owner_events: bool, event_mask: i64, pointer_mode: i32, keyboard_mode: i32, confine_to: Window, diff --git a/src/safe_x11/window.rs b/src/safe_x11/window.rs index 6d1e54e..eac4dbd 100644 --- a/src/safe_x11/window.rs +++ b/src/safe_x11/window.rs @@ -260,7 +260,7 @@ impl XWindow { .next() { let diff = attrs.width - (*v - attrs.x); if *v - attrs.x > 0 { - let _ = self.resize_to(attrs.width - diff, attrs.height); + self.resize_to(attrs.width - diff, attrs.height); } } } @@ -273,7 +273,7 @@ impl XWindow { .skip_while(|&a| *a <= win_bound) .next() { let new_width = *v - attrs.x; - let _ = self.resize_to(new_width, attrs.height); + self.resize_to(new_width, attrs.height); } } @@ -285,7 +285,7 @@ impl XWindow { .next() { let diff = attrs.height - (*v - attrs.y); if *v - attrs.y > 0 { - let _ = self.resize_to(attrs.width, attrs.height - diff); + self.resize_to(attrs.width, attrs.height - diff); } } } @@ -298,7 +298,7 @@ impl XWindow { .skip_while(|&a| *a <= win_bound) .next() { let new_height = *v - attrs.y; - let _ = self.resize_to(attrs.width, new_height); + self.resize_to(attrs.width, new_height); } } @@ -363,8 +363,8 @@ impl XWindow { let gc = xlib::XCreateGC(self.display, self.inner, 0, ptr::null_mut()); xlib::XSetForeground(self.display, gc, XWhitePixel(self.display, 0)); xlib::XSetBackground(self.display, gc, XBlackPixel(self.display, 0)); - println!("Loading fixed"); - let font: xlib::XFontStruct = ptr::read(xlib::XLoadQueryFont(self.display, CString::new("fixed").unwrap().as_ptr())); + let cstring = CString::new("fixed").unwrap(); + let font: xlib::XFontStruct = ptr::read(xlib::XLoadQueryFont(self.display, cstring.as_ptr())); xlib::XSetFont(self.display, gc, font.fid); xlib::XClearWindow(self.display, self.inner); XDrawString(self.display, self.inner, gc, diff --git a/src/socket/mod.rs b/src/socket/mod.rs index 66dae16..c29db2b 100644 --- a/src/socket/mod.rs +++ b/src/socket/mod.rs @@ -25,14 +25,11 @@ pub struct ParsedCmd<'a> { impl<'a> ParsedCmd<'a> { pub fn handle(self, wm: &mut DotWM, bindings: &mut BindingHash) { - match self.f { - FnType::Bind => { - let modifier: u32 = self.modifiers.iter() - .fold(0, |acc, x| acc | x ); - add_binding(wm, bindings, - self.key, modifier, self.func, &self.args); - }, - _ => (), + if self.f == FnType::Bind { + let modifier: u32 = self.modifiers.iter() + .fold(0, |acc, x| acc | x ); + add_binding(wm, bindings, + self.key, modifier, self.func, &self.args); } } } diff --git a/src/socket/parser.rs b/src/socket/parser.rs index 30487d8..e475962 100644 --- a/src/socket/parser.rs +++ b/src/socket/parser.rs @@ -36,7 +36,7 @@ fn modifier_from<'a>(s: &'a str) -> Result<u32, &'static str> { fn modifiers<'a>(s: &'a str) -> Result<Vec<u32>, &'static str> { let mut result = vec![]; - for smod in s.split("-") { + for smod in s.split('-') { let modifier = simple_try!(modifier_from(smod)); result.push(modifier); } @@ -128,8 +128,8 @@ pub fn parse<'a>(input: &'a str) -> Result<ParsedCmd<'a>, &'static str> { match args.first() { Some(cmd) => { - match cmd { - &"bind" => { + match *cmd { + "bind" => { if args.len() > 2 { let modifiers = simple_try!(modifiers(args[1])); let key = simple_try!(key(args[2])); @@ -147,7 +147,7 @@ pub fn parse<'a>(input: &'a str) -> Result<ParsedCmd<'a>, &'static str> { Err("missing arguments") } }, - &"exec" => { + "exec" => { Ok(ParsedCmd { f: FnType::Exec, modifiers: vec![], |