commit 8b7bfcc67fc84ec5aa4e86a859741a74a4e65456
parent e006f590491bb3af9884ca243519b466f96c81b5
Author: deurzen <m.deurzen@tum.de>
Date: Sun, 20 Jun 2021 00:23:27 +0200
refactors code
Diffstat:
12 files changed, 103 insertions(+), 100 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -7,7 +7,7 @@ license = "BSD3"
repository = "https://github.com/deurzen/wzrd"
documentation = "https://docs.rs/wzrd"
readme = "README.md"
-default-run = "wzrd"
+default-run = "core"
description = """
An ICCCM & EWMH compliant X11 reparenting, tiling window manager, written in Rust
"""
@@ -20,20 +20,19 @@ name = "winsys"
path = "src/winsys/mod.rs"
[[bin]]
-name = "wzrd"
+name = "core"
path = "src/core/main.rs"
[[bin]]
-name = "wzrdbar"
+name = "bar"
path = "src/bar/main.rs"
-required-features = ["bar"]
[[bin]]
-name = "wzrdclient"
+name = "client"
path = "src/client/main.rs"
-required-features = ["client"]
[features]
+core = []
bar = []
client = []
diff --git a/src/core/binding.rs b/src/core/binding.rs
@@ -7,8 +7,7 @@ use winsys::window::Window;
use std::collections::HashMap;
-pub type Action = Box<dyn FnMut(&mut Model<'_>)>;
-pub type MouseEvents = Box<dyn FnMut(&mut Model<'_>, Option<Window>)>;
-pub type KeyEvents = Box<dyn FnMut(&mut Model<'_>)>;
-pub type KeyBindings = HashMap<KeyCode, KeyEvents>;
-pub type MouseBindings = HashMap<(MouseEventKey, MouseShortcut), (MouseEvents, bool)>;
+pub type KeyAction = Box<dyn FnMut(&mut Model<'_>)>;
+pub type MouseAction = Box<dyn FnMut(&mut Model<'_>, Option<Window>)>;
+pub type KeyBindings = HashMap<KeyCode, KeyAction>;
+pub type MouseBindings = HashMap<(MouseEventKey, MouseShortcut), (MouseAction, bool)>;
diff --git a/src/core/decoration.rs b/src/core/decoration.rs
@@ -45,13 +45,13 @@ impl Add<Border> for Padding {
fn add(
self,
- _: Border,
+ border: Border,
) -> Self::Output {
Self::Output {
- left: self.left + 1,
- right: self.right + 1,
- top: self.top + 1,
- bottom: self.bottom + 1,
+ left: self.left + border.width as i32,
+ right: self.right + border.width as i32,
+ top: self.top + border.width as i32,
+ bottom: self.bottom + border.width as i32,
}
}
}
diff --git a/src/core/macros.rs b/src/core/macros.rs
@@ -10,13 +10,13 @@ macro_rules! do_internal(
($func:ident) => {
Box::new(|model: &mut $crate::model::Model<'_>| {
drop(model.$func());
- }) as $crate::binding::KeyEvents
+ }) as $crate::binding::KeyAction
};
($func:ident, $($arg:expr),+) => {
Box::new(move |model: &mut $crate::model::Model<'_>| {
drop(model.$func($($arg),+));
- }) as $crate::binding::KeyEvents
+ }) as $crate::binding::KeyAction
};
);
@@ -25,14 +25,14 @@ macro_rules! do_internal_block(
($model:ident, $body:block) => {
Box::new(|$model: &mut $crate::model::Model<'_>| {
$body
- }) as $crate::binding::KeyEvents
+ }) as $crate::binding::KeyAction
};
);
#[macro_export]
macro_rules! do_nothing(
() => {
- Box::new(|_: &mut $crate::model::Model<'_>, _| {}) as $crate::binding::MouseEvents
+ Box::new(|_: &mut $crate::model::Model<'_>, _| {}) as $crate::binding::MouseAction
};
);
@@ -41,13 +41,13 @@ macro_rules! do_internal_mouse(
($func:ident) => {
Box::new(|model: &mut $crate::model::Model<'_>, _| {
drop(model.$func());
- }) as $crate::binding::MouseEvents
+ }) as $crate::binding::MouseAction
};
($func:ident, $($arg:expr),+) => {
Box::new(|model: &mut $crate::model::Model<'_>, _| {
drop(model.$func($($arg),+));
- }) as $crate::binding::MouseEvents
+ }) as $crate::binding::MouseAction
};
);
@@ -56,7 +56,7 @@ macro_rules! do_internal_mouse_block(
($model:ident, $window:ident, $body:block) => {
Box::new(|$model: &mut $crate::model::Model<'_>, $window: Option<winsys::window::Window>| {
$body
- }) as $crate::binding::MouseEvents
+ }) as $crate::binding::MouseAction
};
);
@@ -66,7 +66,7 @@ macro_rules! spawn_external(
{
Box::new(move |_: &mut $crate::model::Model<'_>| {
$crate::util::Util::spawn($cmd);
- }) as $crate::binding::KeyEvents
+ }) as $crate::binding::KeyAction
}
};
);
@@ -77,7 +77,7 @@ macro_rules! spawn_from_shell(
{
Box::new(move |_: &mut $crate::model::Model<'_>| {
$crate::util::Util::spawn_shell($cmd);
- }) as $crate::binding::KeyEvents
+ }) as $crate::binding::KeyAction
}
};
);
diff --git a/src/core/main.rs b/src/core/main.rs
@@ -215,7 +215,7 @@ fn init_bindings() -> (MouseBindings, KeyBindings) {
// "1-C-j" => do_internal!(cycle_zones, Direction::Forward),
// "1-C-k" => do_internal!(cycle_zones, Direction::Backward),
- // active workspace layout setters
+ // active workspace layout modifiers
"1-S-f" => do_internal!(set_layout, LayoutKind::Float),
"1-S-l" => do_internal!(set_layout, LayoutKind::BLFloat),
"1-z" => do_internal!(set_layout, LayoutKind::SingleFloat),
@@ -235,7 +235,7 @@ fn init_bindings() -> (MouseBindings, KeyBindings) {
"1-C-S-f" => do_internal!(apply_float_retain_region),
"1-space" => do_internal!(toggle_layout),
- // active workspace layout-data modifiers
+ // active workspace layout data modifiers
"1-plus" => do_internal!(change_gap_size, Change::Inc(5u32)),
"1-minus" => do_internal!(change_gap_size, Change::Dec(5u32)),
"1-S-equal" => do_internal!(reset_gap_size),
@@ -270,7 +270,7 @@ fn init_bindings() -> (MouseBindings, KeyBindings) {
"1-9" => do_internal!(activate_workspace, 8),
"1-0" => do_internal!(activate_workspace, 9),
- // workspace client movement
+ // workspace client movers
"1-S-bracketleft" => do_internal!(move_focus_to_next_workspace, Direction::Backward),
"1-S-bracketright" => do_internal!(move_focus_to_next_workspace, Direction::Forward),
"1-S-1" => do_internal!(move_focus_to_workspace, 0),
diff --git a/src/core/model.rs b/src/core/model.rs
@@ -652,9 +652,9 @@ impl<'model> Model<'model> {
ppid,
);
+ let mut floating = self.conn.must_free_window(window) | rules.float();
let fullscreen = self.conn.window_is_fullscreen(window) | rules.fullscreen();
let sticky = self.conn.window_is_sticky(window);
- let mut floating = self.conn.must_free_window(window) | rules.float();
if let Some(parent) = parent {
floating = true;
@@ -2733,11 +2733,7 @@ impl<'model> Model<'model> {
window,
on_root,
} => self.handle_frame_extents_request(window, on_root),
- Event::Mapping {
- request,
- } => self.handle_mapping(request),
Event::ScreenChange => self.handle_screen_change(),
- Event::Randr => self.handle_randr(),
}
}
@@ -3211,8 +3207,8 @@ impl<'model> Model<'model> {
};
let extents = client.frame_extents();
- let region = if window == client.window() {
- Some(Region {
+ let mut region = if window == client.window() {
+ Region {
pos: if let Some(pos) = pos {
Pos {
x: pos.x - extents.left,
@@ -3229,35 +3225,32 @@ impl<'model> Model<'model> {
} else {
client.free_region().dim
},
- })
+ }
} else {
- Some(Region {
+ Region {
pos: pos.unwrap_or(client.free_region().pos),
dim: dim.unwrap_or(client.free_region().dim),
- })
- }
- .map(|region| {
- region
- .without_extents(extents)
- .with_size_hints(&client.size_hints())
- .with_minimum_dim(&Client::MIN_CLIENT_DIM)
- .with_extents(extents)
- });
+ }
+ };
- if let Some(region) = region {
- client.set_region(PlacementClass::Free(region));
+ region = region
+ .without_extents(extents)
+ .with_size_hints(&client.size_hints())
+ .with_minimum_dim(&Client::MIN_CLIENT_DIM)
+ .with_extents(extents);
- let placement = Placement {
- method: PlacementMethod::Free,
- kind: PlacementTarget::Client(window),
- zone: client.zone(),
- region: PlacementRegion::FreeRegion,
- decoration: client.decoration(),
- };
+ client.set_region(PlacementClass::Free(region));
- self.update_client_placement(client, &placement);
- self.place_client(client, placement.method);
- }
+ let placement = Placement {
+ method: PlacementMethod::Free,
+ kind: PlacementTarget::Client(window),
+ zone: client.zone(),
+ region: PlacementRegion::FreeRegion,
+ decoration: client.decoration(),
+ };
+
+ self.update_client_placement(client, &placement);
+ self.place_client(client, placement.method);
}
#[inline]
@@ -3402,26 +3395,13 @@ impl<'model> Model<'model> {
);
}
- #[inline]
- fn handle_mapping(
- &self,
- request: u8,
- ) {
- debug!("MAPPING with request {}", request);
- if self.conn.is_mapping_request(request) {}
- }
-
#[cold]
- fn handle_screen_change(&self) {
+ fn handle_screen_change(&mut self) {
debug!("SCREEN_CHANGE");
- self.workspaces
- .activate_for(&Selector::AtIndex(self.active_screen().number()));
- }
- #[cold]
- fn handle_randr(&mut self) {
- debug!("RANDR");
self.acquire_partitions();
+ self.workspaces
+ .activate_for(&Selector::AtIndex(self.active_screen().number()));
}
#[cold]
diff --git a/src/core/workspace.rs b/src/core/workspace.rs
@@ -44,7 +44,6 @@ pub enum ClientSelector {
pub enum BufferKind {
Move,
Resize,
- Scratchpad,
}
#[derive(Debug, Clone, PartialEq, Eq)]
diff --git a/src/main.rs b/src/main.rs
@@ -1 +0,0 @@
-fn main() {}
diff --git a/src/winsys/connection.rs b/src/winsys/connection.rs
@@ -43,10 +43,6 @@ pub trait Connection {
window: Window,
);
fn release_pointer(&self);
- fn is_mapping_request(
- &self,
- request: u8,
- ) -> bool;
fn cleanup(&self);
// Window manipulation
diff --git a/src/winsys/event.rs b/src/winsys/event.rs
@@ -98,11 +98,7 @@ pub enum Event {
window: Window,
on_root: bool,
},
- Mapping {
- request: u8,
- },
ScreenChange,
- Randr,
}
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
diff --git a/src/winsys/xdata/util.rs b/src/winsys/xdata/util.rs
@@ -0,0 +1,46 @@
+use super::super::input::Result;
+
+use std::collections::HashMap;
+use std::process::Command;
+
+pub type KeyMap = HashMap<String, u8>;
+pub type CodeMap = HashMap<u8, String>;
+
+pub struct Util;
+impl Util {
+ pub fn system_keymap() -> KeyMap {
+ match Command::new("xmodmap").arg("-pke").output() {
+ Err(err) => panic!("unable to fetch keycodes via xmodmap: {}", err),
+ Ok(out) => match String::from_utf8(out.stdout) {
+ Err(err) => panic!("invalid UTF8 from xmodmap: {}", err),
+ Ok(out) => out
+ .lines()
+ .flat_map(|l| {
+ let mut words = l.split_whitespace();
+ let key_code: u8 = words.nth(1).unwrap().parse().unwrap();
+
+ words.skip(1).map(move |name| (name.into(), key_code))
+ })
+ .collect::<KeyMap>(),
+ },
+ }
+ }
+
+ pub fn system_codemap() -> CodeMap {
+ match Command::new("xmodmap").arg("-pke").output() {
+ Err(err) => panic!("unable to fetch keycodes via xmodmap: {}", err),
+ Ok(out) => match String::from_utf8(out.stdout) {
+ Err(err) => panic!("invalid UTF8 from xmodmap: {}", err),
+ Ok(out) => out
+ .lines()
+ .flat_map(|l| {
+ let mut words = l.split_whitespace();
+ let key_code: u8 = words.nth(1).unwrap().parse().unwrap();
+
+ words.skip(1).map(move |name| (key_code, name.into()))
+ })
+ .collect::<CodeMap>(),
+ },
+ }
+ }
+}
diff --git a/src/winsys/xdata/xconnection.rs b/src/winsys/xdata/xconnection.rs
@@ -955,9 +955,7 @@ impl<'conn, Conn: connection::Connection> XConnection<'conn, Conn> {
&self,
event: &xproto::MappingNotifyEvent,
) -> Option<Event> {
- Some(Event::Mapping {
- request: u8::from(event.request),
- })
+ None
}
#[inline]
@@ -965,7 +963,7 @@ impl<'conn, Conn: connection::Connection> XConnection<'conn, Conn> {
&self,
_event: &randr::NotifyEvent,
) -> Option<Event> {
- Some(Event::Randr)
+ Some(Event::ScreenChange)
}
}
@@ -1162,15 +1160,6 @@ impl<'conn, Conn: connection::Connection> Connection for XConnection<'conn, Conn
}
}
- #[inline]
- fn is_mapping_request(
- &self,
- request: u8,
- ) -> bool {
- request == u8::from(xproto::Mapping::KEYBOARD)
- || request == u8::from(xproto::Mapping::MODIFIER)
- }
-
fn cleanup(&self) {
drop(
self.conn
@@ -1992,10 +1981,10 @@ impl<'conn, Conn: connection::Connection> Connection for XConnection<'conn, Conn
});
Some(Hints {
- input,
urgent,
- group,
+ input,
initial_state,
+ group,
})
}
@@ -2548,7 +2537,7 @@ impl<'conn, Conn: connection::Connection> Connection for XConnection<'conn, Conn
return None;
}
- let mut struts = Vec::with_capacity(1);
+ let mut struts = Vec::with_capacity(4);
for (i, &width) in widths.iter().enumerate() {
if i == 4 {