wzrd

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in Rust
git clone git://git.deurzen.net/wzrd
Log | Files | Refs | LICENSE

commit 216a42d55ffb3742b28bec13f4d0b8cacaf048b3
parent e2101e4f7f1472c31d871f482ac4275ebec61d7c
Author: deurzen <m.deurzen@tum.de>
Date:   Wed, 24 Mar 2021 12:10:43 +0100

initial move to RefCell implementation

Diffstat:
Msrc/core/client.rs | 783+++++--------------------------------------------------------------------------
Asrc/core/compare.rs | 11+++++++++++
Msrc/core/jump.rs | 19++++---------------
Msrc/core/layout.rs | 2+-
Msrc/core/main.rs | 14+++++++-------
Msrc/core/model.rs | 154+++++++++++++++++++++++++++++++++++--------------------------------------------
Msrc/winsys/geometry.rs | 8++++----
7 files changed, 138 insertions(+), 853 deletions(-)

diff --git a/src/core/client.rs b/src/core/client.rs @@ -1,3 +1,4 @@ +use crate::compare::MatchMethod; use crate::decoration::Decoration; use crate::identify::Ident; use crate::identify::Identify; @@ -20,741 +21,6 @@ pub struct Client { zone: ZoneId, window: Window, frame: Window, - name: String, - class: String, - instance: String, - context: usize, - workspace: usize, - window_type: WindowType, - active_region: Region, - previous_region: Region, - inner_region: Region, - free_region: Region, - tile_region: Region, - decoration: Decoration, - size_hints: Option<SizeHints>, - warp_pos: Option<Pos>, - parent: Option<Window>, - children: Vec<Window>, - leader: Option<Window>, - producer: Option<Window>, - consumers: Vec<Window>, - focused: bool, - mapped: bool, - managed: bool, - in_window: bool, - floating: bool, - fullscreen: bool, - iconified: bool, - disowned: bool, - sticky: bool, - invincible: bool, - urgent: bool, - consuming: bool, - producing: bool, - pid: Option<Pid>, - ppid: Option<Pid>, - last_focused: SystemTime, - managed_since: SystemTime, - expected_unmap_count: u8, -} - -impl Identify for Client { - fn id(&self) -> Ident { - self.window as Ident - } -} - -impl Client { - pub fn new( - window: Window, - frame: Window, - name: String, - class: String, - instance: String, - window_type: WindowType, - pid: Option<Pid>, - ppid: Option<Pid>, - ) -> Self { - Self { - zone: 0, - window, - frame, - name, - class, - instance, - context: 0, - workspace: 0, - window_type, - active_region: Default::default(), - previous_region: Default::default(), - inner_region: Default::default(), - free_region: Default::default(), - tile_region: Default::default(), - decoration: Default::default(), - size_hints: None, - warp_pos: None, - parent: None, - children: Vec::new(), - leader: None, - producer: None, - consumers: Vec::new(), - focused: false, - mapped: false, - managed: true, - in_window: false, - floating: false, - fullscreen: false, - iconified: false, - disowned: false, - sticky: false, - invincible: false, - urgent: false, - consuming: false, - producing: true, - pid, - ppid, - last_focused: SystemTime::now(), - managed_since: SystemTime::now(), - expected_unmap_count: 0, - } - } - - #[inline] - pub fn zone(&self) -> ZoneId { - self.zone - } - - #[inline] - pub fn set_zone( - &mut self, - zone: ZoneId, - ) { - self.zone = zone; - } - - #[inline] - pub fn windows(&self) -> (Window, Window) { - (self.window, self.frame) - } - - #[inline] - pub fn window(&self) -> Window { - self.window - } - - #[inline] - pub fn frame(&self) -> Window { - self.frame - } - - #[inline] - pub fn name(&self) -> &str { - &self.name - } - - #[inline] - pub fn set_name( - &mut self, - name: impl Into<String>, - ) { - self.name = name.into(); - } - - #[inline] - pub fn class(&self) -> &str { - &self.class - } - - #[inline] - pub fn set_class( - &mut self, - class: impl Into<String>, - ) { - self.class = class.into(); - } - - #[inline] - pub fn instance(&self) -> &str { - &self.instance - } - - #[inline] - pub fn set_instance( - &mut self, - instance: impl Into<String>, - ) { - self.instance = instance.into(); - } - - #[inline] - pub fn context(&self) -> usize { - self.context - } - - #[inline] - pub fn set_context( - &mut self, - context: usize, - ) { - self.context = context; - } - - #[inline] - pub fn workspace(&self) -> usize { - self.workspace - } - - #[inline] - pub fn set_workspace( - &mut self, - workspace: usize, - ) { - self.workspace = workspace; - } - - #[inline] - pub fn window_type(&self) -> WindowType { - self.window_type - } - - #[inline] - pub fn active_region(&self) -> &Region { - &self.active_region - } - - #[inline] - fn set_active_region( - &mut self, - active_region: &Region, - ) { - self.previous_region = self.active_region; - self.active_region = *active_region; - self.set_inner_region(active_region); - } - - #[inline] - pub fn previous_region(&self) -> &Region { - &self.previous_region - } - - #[inline] - pub fn inner_region(&self) -> &Region { - &self.inner_region - } - - #[inline] - fn set_inner_region( - &mut self, - active_region: &Region, - ) { - self.inner_region = if let Some(frame) = self.decoration.frame { - let extents = frame.extents; - let mut inner_region = *active_region - extents; - - inner_region.pos.x = extents.left as i32; - inner_region.pos.y = extents.top as i32; - - inner_region.dim.w = active_region.dim.w - extents.left - extents.right; - inner_region.dim.h = active_region.dim.h - extents.top - extents.bottom; - - inner_region - } else { - let mut inner_region = *active_region; - - inner_region.pos.x = 0; - inner_region.pos.y = 0; - - inner_region - }; - } - - #[inline] - pub fn free_region(&self) -> &Region { - &self.free_region - } - - #[inline] - pub fn set_free_region( - &mut self, - free_region: &Region, - ) { - if let Some(warp_pos) = self.warp_pos { - if !free_region.encompasses(self.active_region.pos + warp_pos) { - self.unset_warp_pos(); - } - } - - self.free_region = *free_region; - self.set_active_region(free_region); - } - - #[inline] - pub fn tile_region(&self) -> &Region { - &self.tile_region - } - - #[inline] - pub fn set_tile_region( - &mut self, - tile_region: &Region, - ) { - if let Some(warp_pos) = self.warp_pos { - if !tile_region.encompasses(self.active_region.pos + warp_pos) { - self.unset_warp_pos(); - } - } - - self.tile_region = *tile_region; - self.set_active_region(tile_region); - } - - #[inline] - pub fn decoration(&self) -> &Decoration { - &self.decoration - } - - #[inline] - pub fn frame_extents(&self) -> Extents { - Extents { - left: 0, - right: 0, - top: 0, - bottom: 0, - } + self.decoration - } - - #[inline] - pub fn set_decoration( - &mut self, - decoration: Decoration, - ) { - self.decoration = decoration; - } - - #[inline] - pub fn size_hints(&self) -> &Option<SizeHints> { - &self.size_hints - } - - #[inline] - pub fn set_size_hints( - &mut self, - size_hints: Option<SizeHints>, - ) { - self.size_hints = size_hints; - } - - #[inline] - pub fn warp_pos(&self) -> &Option<Pos> { - &self.warp_pos - } - - #[inline] - pub fn set_warp_pos( - &mut self, - pointer_pos: Pos, - ) { - let pointer_rpos = pointer_pos.relative_to(self.active_region.pos); - - self.warp_pos = if self.active_region.encompasses(pointer_pos) { - Some(pointer_rpos) - } else { - None - }; - } - - #[inline] - pub fn unset_warp_pos(&mut self) { - self.warp_pos = None; - } - - #[inline] - pub fn set_parent( - &mut self, - parent: Window, - ) { - self.parent = Some(parent); - } - - #[inline] - pub fn parent(&self) -> Option<Window> { - self.parent - } - - #[inline] - pub fn add_child( - &mut self, - child: Window, - ) { - self.children.push(child); - } - - #[inline] - pub fn remove_child( - &mut self, - child: Window, - ) { - if let Some(index) = self.children.iter().rposition(|c| *c == child) { - self.children.remove(index); - } - } - - #[inline] - pub fn set_leader( - &mut self, - leader: Window, - ) { - self.leader = Some(leader); - } - - #[inline] - pub fn leader(&self) -> Option<Window> { - self.leader - } - - #[inline] - pub fn set_producer( - &mut self, - producer: Window, - ) { - self.producer = Some(producer); - } - - #[inline] - pub fn unset_producer(&mut self) { - self.producer = None; - } - - #[inline] - pub fn producer(&self) -> Option<Window> { - self.producer - } - - #[inline] - pub fn consumer_len(&self) -> usize { - self.consumers.len() - } - - #[inline] - pub fn add_consumer( - &mut self, - consumer: Window, - ) { - self.consumers.push(consumer); - } - - #[inline] - pub fn remove_consumer( - &mut self, - consumer: Window, - ) { - if let Some(index) = self.consumers.iter().rposition(|c| *c == consumer) { - self.consumers.remove(index); - } - } - - #[inline] - pub fn is_free(&self) -> bool { - self.floating || self.disowned || !self.managed - } - - #[inline] - pub fn is_focused(&self) -> bool { - self.focused - } - - #[inline] - pub fn set_focused( - &mut self, - focused: bool, - ) { - if focused { - self.last_focused = SystemTime::now(); - } - - self.focused = focused; - } - - #[inline] - pub fn is_mapped(&self) -> bool { - self.mapped - } - - #[inline] - pub fn set_mapped( - &mut self, - mapped: bool, - ) { - self.mapped = mapped; - } - - #[inline] - pub fn is_managed(&self) -> bool { - self.managed - } - - #[inline] - pub fn set_managed( - &mut self, - managed: bool, - ) { - self.managed = managed; - } - - #[inline] - pub fn is_in_window(&self) -> bool { - self.in_window - } - - #[inline] - pub fn set_in_window( - &mut self, - in_window: bool, - ) { - self.in_window = in_window; - } - - #[inline] - pub fn is_floating(&self) -> bool { - self.floating - } - - #[inline] - pub fn set_floating( - &mut self, - floating: bool, - ) { - self.floating = floating; - } - - #[inline] - pub fn is_fullscreen(&self) -> bool { - self.fullscreen - } - - #[inline] - pub fn set_fullscreen( - &mut self, - fullscreen: bool, - ) { - self.fullscreen = fullscreen; - } - - #[inline] - pub fn is_iconified(&self) -> bool { - self.iconified - } - - #[inline] - pub fn set_iconified( - &mut self, - iconified: bool, - ) { - self.iconified = iconified; - } - - #[inline] - pub fn is_disowned(&self) -> bool { - self.disowned - } - - #[inline] - pub fn set_disowned( - &mut self, - disowned: bool, - ) { - self.disowned = disowned; - } - - #[inline] - pub fn is_sticky(&self) -> bool { - self.sticky - } - - #[inline] - pub fn set_sticky( - &mut self, - sticky: bool, - ) { - self.sticky = sticky; - } - - #[inline] - pub fn is_invincible(&self) -> bool { - self.invincible - } - - #[inline] - pub fn set_invincible( - &mut self, - invincible: bool, - ) { - self.invincible = invincible; - } - - #[inline] - pub fn is_urgent(&self) -> bool { - self.urgent - } - - #[inline] - pub fn set_urgent( - &mut self, - urgent: bool, - ) { - self.urgent = urgent; - } - - #[inline] - pub fn is_consuming(&self) -> bool { - self.consuming - } - - #[inline] - pub fn set_consuming( - &mut self, - consuming: bool, - ) { - self.consuming = consuming; - } - - #[inline] - pub fn is_producing(&self) -> bool { - self.producing - } - - #[inline] - pub fn set_producing( - &mut self, - producing: bool, - ) { - self.producing = producing; - } - - #[inline] - pub fn pid(&self) -> Option<Pid> { - self.pid - } - - #[inline] - pub fn ppid(&self) -> Option<Pid> { - self.ppid - } - - #[inline] - pub fn last_focused(&self) -> SystemTime { - self.last_focused - } - - #[inline] - pub fn managed_since(&self) -> SystemTime { - self.managed_since - } - - #[inline] - pub fn expect_unmap(&mut self) { - self.expected_unmap_count += 1; - } - - #[inline] - pub fn is_expecting_unmap(&self) -> bool { - self.expected_unmap_count > 0 - } - - #[inline] - pub fn consume_unmap_if_expecting(&mut self) -> bool { - let expecting = self.expected_unmap_count > 0; - - if expecting { - self.expected_unmap_count -= 1; - } - - expecting - } -} - -impl PartialEq for Client { - fn eq( - &self, - other: &Self, - ) -> bool { - self.window == other.window - } -} - -pub struct Hex32(pub u32); - -impl std::fmt::Debug for Hex32 { - fn fmt( - &self, - f: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - write!(f, "{:#0x}", &self.0) - } -} - -impl std::fmt::Debug for Client { - fn fmt( - &self, - f: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - f.debug_struct("Client") - .field("window", &Hex32(self.window)) - .field("frame", &Hex32(self.frame)) - .field("name", &self.name) - .field("class", &self.class) - .field("instance", &self.instance) - .field("context", &self.context) - .field("workspace", &self.workspace) - .field("window_type", &self.window_type) - .field("active_region", &self.active_region) - .field("previous_region", &self.previous_region) - .field("inner_region", &self.inner_region) - .field("free_region", &self.free_region) - .field("tile_region", &self.tile_region) - .field("decoration", &self.decoration) - .field("size_hints", &self.size_hints) - .field("warp_pos", &self.warp_pos) - .field("parent", &self.parent.map(|parent| Hex32(parent))) - .field( - "children", - &self - .children - .iter() - .map(|&child| Hex32(child)) - .collect::<Vec<Hex32>>(), - ) - .field("leader", &self.leader) - .field("producer", &self.producer) - .field("consumers", &self.consumers) - .field("focused", &self.focused) - .field("mapped", &self.mapped) - .field("managed", &self.managed) - .field("in_window", &self.in_window) - .field("floating", &self.floating) - .field("fullscreen", &self.fullscreen) - .field("iconified", &self.iconified) - .field("disowned", &self.disowned) - .field("sticky", &self.sticky) - .field("invincible", &self.invincible) - .field("urgent", &self.urgent) - .field("consuming", &self.consuming) - .field("pid", &self.pid) - .field("ppid", &self.ppid) - .field("last_focused", &self.last_focused) - .field("managed_since", &self.managed_since) - .field("expected_unmap_count", &self.expected_unmap_count) - .finish() - } -} - -// ----------------------------------------------------------- - -pub struct Client2 { - zone: ZoneId, - window: Window, - frame: Window, name: RefCell<String>, class: RefCell<String>, instance: RefCell<String>, @@ -794,13 +60,13 @@ pub struct Client2 { expected_unmap_count: RefCell<u8>, } -impl<'client> Identify for Client2 { +impl<'client> Identify for Client { fn id(&self) -> Ident { self.window as Ident } } -impl<'client> Client2 { +impl<'client> Client { pub fn new( zone: ZoneId, window: Window, @@ -882,6 +148,14 @@ impl<'client> Client2 { } #[inline] + pub fn name_matches(&self, match_method: MatchMethod<&'static str>) -> bool { + match match_method { + MatchMethod::Equals(comp) => &*self.name.borrow() == comp, + MatchMethod::Contains(comp) => (&*self.name.borrow()).contains(comp), + } + } + + #[inline] pub fn set_name( &self, name: impl Into<String>, @@ -895,6 +169,14 @@ impl<'client> Client2 { } #[inline] + pub fn class_matches(&self, match_method: MatchMethod<&'static str>) -> bool { + match match_method { + MatchMethod::Equals(comp) => &*self.class.borrow() == comp, + MatchMethod::Contains(comp) => (&*self.class.borrow()).contains(comp), + } + } + + #[inline] pub fn set_class( &self, class: impl Into<String>, @@ -908,6 +190,14 @@ impl<'client> Client2 { } #[inline] + pub fn instance_matches(&self, match_method: MatchMethod<&'static str>) -> bool { + match match_method { + MatchMethod::Equals(comp) => &*self.instance.borrow() == comp, + MatchMethod::Contains(comp) => (&*self.instance.borrow()).contains(comp), + } + } + + #[inline] pub fn set_instance( &self, instance: impl Into<String>, @@ -1017,9 +307,11 @@ impl<'client> Client2 { match region { PlacementClass::Free(region) => { self.free_region.replace(region); + self.set_active_region(region); }, PlacementClass::Tile(region) => { self.tile_region.replace(region); + self.set_active_region(region); }, } } @@ -1384,7 +676,7 @@ impl<'client> Client2 { } } -impl<'client> PartialEq for Client2 { +impl<'client> PartialEq for Client { fn eq( &self, other: &Self, @@ -1393,12 +685,23 @@ impl<'client> PartialEq for Client2 { } } -impl<'client> std::fmt::Debug for Client2 { +pub struct Hex32(pub u32); + +impl std::fmt::Debug for Hex32 { + fn fmt( + &self, + f: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + write!(f, "{:#0x}", &self.0) + } +} + +impl<'client> std::fmt::Debug for Client { fn fmt( &self, f: &mut std::fmt::Formatter<'_>, ) -> std::fmt::Result { - f.debug_struct("Client2") + f.debug_struct("Client") .field("window", &Hex32(self.window)) .field("frame", &Hex32(self.frame)) .field("name", &self.name) diff --git a/src/core/compare.rs b/src/core/compare.rs @@ -0,0 +1,11 @@ +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum Order { + Ascending, + Descending, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum MatchMethod<T> { + Equals(T), + Contains(T), +} diff --git a/src/core/jump.rs b/src/core/jump.rs @@ -1,24 +1,13 @@ use crate::client::Client; +use crate::compare::MatchMethod; use crate::identify::Index; use crate::workspace::ClientSelector; -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum Order { - Ascending, - Descending, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum MatchMethod { - Equals, - Contains, -} - #[derive(Clone, Copy)] pub enum JumpCriterium { OnWorkspaceBySelector(Index, &'static ClientSelector), - ByName(&'static str, MatchMethod), - ByClass(&'static str, MatchMethod), - ByInstance(&'static str, MatchMethod), + ByName(MatchMethod<&'static str>), + ByClass(MatchMethod<&'static str>), + ByInstance(MatchMethod<&'static str>), ForCond(&'static dyn Fn(&Client) -> bool), } diff --git a/src/core/layout.rs b/src/core/layout.rs @@ -490,7 +490,7 @@ impl LayoutKind { pos, dim, } - .from_absolute_inner_center(&Dim { + .from_absolute_inner_center(Dim { w: (dim.w as f32 * w_ratio) as i32, h: (dim.h as f32 * h_ratio) as i32, }), diff --git a/src/core/main.rs b/src/core/main.rs @@ -23,6 +23,7 @@ mod defaults; mod binding; mod change; mod client; +mod compare; mod consume; mod cycle; mod decoration; @@ -43,8 +44,8 @@ use binding::KeyBindings; use binding::MouseBindings; use change::Change; use change::Direction; +use compare::MatchMethod; use jump::JumpCriterium; -use jump::MatchMethod; use layout::LayoutKind; use model::Model; use workspace::ClientSelector; @@ -277,21 +278,20 @@ fn init_bindings() -> (MouseBindings, KeyBindings) { // client jump criteria "1-b" => do_internal!(jump_client, - &JumpCriterium::ByClass("qutebrowser", MatchMethod::Equals) + &JumpCriterium::ByClass(MatchMethod::Equals("qutebrowser")) ), "1-S-b" => do_internal!(jump_client, - &JumpCriterium::ByClass("Firefox", MatchMethod::Equals) + &JumpCriterium::ByClass(MatchMethod::Equals("Firefox")) ), "1-C-b" => do_internal!(jump_client, - &JumpCriterium::ByClass("Chromium", MatchMethod::Equals) + &JumpCriterium::ByClass(MatchMethod::Equals("Chromium")) ), "1-2-space" => do_internal!(jump_client, - &JumpCriterium::ByClass("Spotify", MatchMethod::Equals) + &JumpCriterium::ByClass(MatchMethod::Equals("Spotify")) ), "1-e" => do_internal_block!(model, { model.jump_client(&JumpCriterium::ByName( - "[vim]", - MatchMethod::Contains, + MatchMethod::Contains("[vim]"), )); }), "1-slash" => do_internal_block!(model, { diff --git a/src/core/model.rs b/src/core/model.rs @@ -11,11 +11,11 @@ use crate::decoration::Decoration; use crate::error::StateChangeError; use crate::identify::Index; use crate::jump::JumpCriterium; -use crate::jump::MatchMethod; use crate::layout::Layout; use crate::layout::LayoutKind; use crate::partition::Partition; use crate::placement::Placement; +use crate::placement::PlacementClass; use crate::placement::PlacementMethod; use crate::placement::PlacementRegion; use crate::placement::PlacementTarget; @@ -682,20 +682,15 @@ impl<'a> Model<'a> { geometry = if size_hints.is_some() { geometry .with_size_hints(&size_hints) - .with_extents(&Decoration::FREE_DECORATION.extents()) + .with_extents(Decoration::FREE_DECORATION.extents()) } else { geometry .with_minimum_dim(&Client::MIN_CLIENT_DIM) - .with_extents(&Decoration::FREE_DECORATION.extents()) + .with_extents(Decoration::FREE_DECORATION.extents()) }; let parent = self.conn.get_icccm_window_transient_for(window); - let leader = self - .conn - .get_icccm_window_client_leader(window) - .and_then(|leader| self.client_any(leader)); - // TODO: startup sequence/notification // TODO: MOTIF decorations for old-style applications @@ -726,10 +721,19 @@ impl<'a> Model<'a> { { geometry = screen .full_region() - .from_absolute_inner_center(&geometry.dim); + .from_absolute_inner_center(geometry.dim); } + let parent_zone = self.workspaces[workspace] + .active_spawn_zone() + .map(|id| self.zone_manager.nearest_cycle(id)); + + let zone = self + .zone_manager + .new_zone(parent_zone, ZoneContent::Client(window)); + let mut client = Client::new( + zone, window, frame, name, @@ -749,6 +753,11 @@ impl<'a> Model<'a> { client.set_parent(parent); } + let leader = self + .conn + .get_icccm_window_client_leader(window) + .and_then(|leader| self.client_any(leader)); + if let Some(leader) = leader { let leader_window = leader.window(); if leader_window != window { @@ -764,7 +773,7 @@ impl<'a> Model<'a> { rules.float(&mut floating); client.set_floating(floating); - client.set_free_region(&geometry); + client.set_region(PlacementClass::Free(geometry)); client.set_size_hints(size_hints); client.set_context(context); client.set_workspace(workspace); @@ -775,23 +784,7 @@ impl<'a> Model<'a> { y: extents.top as i32, }); - self.conn - .set_icccm_window_state(window, IcccmWindowState::Normal); - - if let Some(current_workspace) = self.workspaces.get(workspace) { - let parent_zone = current_workspace - .active_spawn_zone() - .map(|id| self.zone_manager.nearest_cycle(id)); - - let id = self - .zone_manager - .new_zone(parent_zone, ZoneContent::Client(window)); - - client.set_zone(id); - - let current_workspace = self.workspaces.get_mut(workspace).unwrap(); - current_workspace.add_client(window, &InsertPos::Back); - } + self.workspaces[workspace].add_client(window, &InsertPos::Back); if let Some(parent) = parent { if let Some(parent) = self.client_any_mut(parent) { @@ -805,8 +798,7 @@ impl<'a> Model<'a> { self.pid_map.insert(pid, window); } - info!("managing client {:#?}", client); - + self.conn.set_icccm_window_state(window, IcccmWindowState::Normal); self.client_map.insert(window, client); self.frame_map.insert(frame, window); self.window_map.insert(window, frame); @@ -855,6 +847,8 @@ impl<'a> Model<'a> { if let Some(warp_pos) = active_region.quadrant_center_from_pos(current_pos) { self.conn.warp_pointer(warp_pos); } + + info!("managing client {:#?}", client); } fn remanage( @@ -1129,7 +1123,7 @@ impl<'a> Model<'a> { PlacementTarget::Client(window) => { let client = self.client_mut(window).unwrap(); let region = match placement.region { - PlacementRegion::FreeRegion => *client.free_region(), + PlacementRegion::FreeRegion => client.free_region(), PlacementRegion::NewRegion(region) => region, PlacementRegion::NoRegion => return, }; @@ -1139,7 +1133,7 @@ impl<'a> Model<'a> { match placement.method { PlacementMethod::Free => { let id = client.zone(); - client.set_free_region(&region); + client.set_region(PlacementClass::Free(region)); let zone = self.zone_manager.zone_mut(id); zone.set_region(region); @@ -1147,7 +1141,7 @@ impl<'a> Model<'a> { }, PlacementMethod::Tile => { let id = client.zone(); - client.set_tile_region(&region); + client.set_region(PlacementClass::Tile(region)); let zone = self.zone_manager.zone_mut(id); zone.set_method(placement.method); @@ -1168,11 +1162,11 @@ impl<'a> Model<'a> { let (window, frame) = client.windows(); let inner_region = client.inner_region(); - self.conn.place_window(window, inner_region); + self.conn.place_window(window, &inner_region); - self.conn.place_window(frame, match method { - PlacementMethod::Free => &client.free_region(), - PlacementMethod::Tile => &client.tile_region(), + self.conn.place_window(frame, &match method { + PlacementMethod::Free => client.free_region(), + PlacementMethod::Tile => client.tile_region(), }); self.redraw_client(window); @@ -1422,9 +1416,9 @@ impl<'a> Model<'a> { let center = screen .full_region() - .from_absolute_inner_center(&client.free_region().dim); + .from_absolute_inner_center(client.free_region().dim); - let mut free_region = *client.free_region(); + let mut free_region = client.free_region(); free_region.pos = center.pos; info!("centering client with window {:#0x}", client.window()); @@ -1432,7 +1426,7 @@ impl<'a> Model<'a> { self.conn.move_window(client.frame(), center.pos); self.client_mut(window) .unwrap() - .set_free_region(&free_region); + .set_region(PlacementClass::Free(free_region)); } } } @@ -1450,10 +1444,10 @@ impl<'a> Model<'a> { windows.into_iter().for_each(|w| { let client = self.client(w).unwrap(); - let active_region = *client.active_region(); + let active_region = client.active_region(); let client = self.client_mut(w).unwrap(); - client.set_free_region(&active_region); + client.set_region(PlacementClass::Free(active_region)); }); drop(self.set_layout(LayoutKind::Float)); @@ -2024,16 +2018,12 @@ impl<'a> Model<'a> { *window.unwrap() }, - JumpCriterium::ByName(name, match_method) => { + JumpCriterium::ByName(match_method) => { let mut clients = self .client_map .iter() .filter(|&(_, client)| { - client.is_managed() - && match match_method { - MatchMethod::Equals => client.name() == *name, - MatchMethod::Contains => client.name().contains(name), - } + client.is_managed() && client.name_matches(*match_method) }) .map(|(_, client)| client) .collect::<Vec<&Client>>(); @@ -2046,16 +2036,12 @@ impl<'a> Model<'a> { return; } }, - JumpCriterium::ByClass(class, match_method) => { + JumpCriterium::ByClass(match_method) => { let mut clients = self .client_map .iter() .filter(|&(_, client)| { - client.is_managed() - && match match_method { - MatchMethod::Equals => client.class() == *class, - MatchMethod::Contains => client.class().contains(class), - } + client.is_managed() && client.class_matches(*match_method) }) .map(|(_, client)| client) .collect::<Vec<&Client>>(); @@ -2068,16 +2054,12 @@ impl<'a> Model<'a> { return; } }, - JumpCriterium::ByInstance(instance, match_method) => { + JumpCriterium::ByInstance(match_method) => { let mut clients = self .client_map .iter() .filter(|&(_, client)| { - client.is_managed() - && match match_method { - MatchMethod::Equals => client.instance() == *instance, - MatchMethod::Contains => client.instance().contains(instance), - } + client.is_managed() && client.instance_matches(*match_method) }) .map(|(_, client)| client) .collect::<Vec<&Client>>(); @@ -2133,7 +2115,7 @@ impl<'a> Model<'a> { window: Window, ) { if let Some(client) = self.client(window) { - let free_region = *client.free_region(); + let free_region = client.free_region(); let window = client.window(); info!("enabling fullscreen for client with window {:#0x}", window); @@ -2169,7 +2151,7 @@ impl<'a> Model<'a> { client.set_fullscreen(false); if let Some(free_region) = free_region { - client.set_free_region(&free_region); + client.set_region(PlacementClass::Free(free_region)); } let workspace = client.workspace(); @@ -2366,7 +2348,7 @@ impl<'a> Model<'a> { if self.is_free(client) { let screen = self.active_screen(); let placeable_region = screen.placeable_region(); - let mut region = *client.free_region(); + let mut region = client.free_region(); let window = client.window(); info!( @@ -2394,7 +2376,7 @@ impl<'a> Model<'a> { kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *client.decoration(), + decoration: client.decoration(), }; self.update_client_placement(&placement); @@ -2421,7 +2403,7 @@ impl<'a> Model<'a> { ) { if let Some(client) = self.client(window) { if self.is_free(client) { - let mut region = *client.free_region(); + let mut region = client.free_region(); let window = client.window(); info!( @@ -2441,7 +2423,7 @@ impl<'a> Model<'a> { kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *client.decoration(), + decoration: client.decoration(), }; self.update_client_placement(&placement); @@ -2458,7 +2440,7 @@ impl<'a> Model<'a> { if let Some(client) = self.client(window) { if self.is_free(client) { let frame_extents = client.frame_extents(); - let original_region = *client.free_region(); + let original_region = client.free_region(); let region = original_region; let window = client.window(); let (width, height) = region.dim.values(); @@ -2469,7 +2451,7 @@ impl<'a> Model<'a> { let width_inc = width_inc.round() as i32; let height_inc = height_inc.round() as i32; - let mut region = region.without_extents(&frame_extents); + let mut region = region.without_extents(frame_extents); if (width_inc.is_negative() && -width_inc >= region.dim.w) || (height_inc.is_negative() && -height_inc >= region.dim.h) @@ -2489,7 +2471,7 @@ impl<'a> Model<'a> { region.dim.w = region.dim.w + width_inc; region.dim.h = region.dim.h + height_inc; - let mut region = region.with_extents(&frame_extents); + let mut region = region.with_extents(frame_extents); let dx = region.dim.w - original_region.dim.w; let dy = region.dim.h - original_region.dim.h; @@ -2504,7 +2486,7 @@ impl<'a> Model<'a> { kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *client.decoration(), + decoration: client.decoration(), }; self.update_client_placement(&placement); @@ -2533,7 +2515,7 @@ impl<'a> Model<'a> { if self.is_free(client) { let frame_extents = client.frame_extents(); let window = client.window(); - let mut region = (*client.free_region()).without_extents(&frame_extents); + let mut region = client.free_region().without_extents(frame_extents); info!( "stretching client with window {:#0x} at the {:?} by {}", @@ -2592,13 +2574,13 @@ impl<'a> Model<'a> { } let window = client.window(); - let region = region.with_extents(&frame_extents); + let region = region.with_extents(frame_extents); let placement = Placement { method: PlacementMethod::Free, kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *client.decoration(), + decoration: client.decoration(), }; self.update_client_placement(&placement); @@ -2614,7 +2596,7 @@ impl<'a> Model<'a> { if !self.move_buffer.is_occupied() && !self.resize_buffer.is_occupied() { if let Some(client) = self.client(window) { let current_pos = self.conn.get_pointer_position(); - let client_region = *client.free_region(); + let client_region = client.free_region(); self.move_buffer.set( window, @@ -2654,7 +2636,7 @@ impl<'a> Model<'a> { kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *client.decoration(), + decoration: client.decoration(), }; self.update_client_placement(&placement); @@ -2672,7 +2654,7 @@ impl<'a> Model<'a> { if !self.move_buffer.is_occupied() && !self.resize_buffer.is_occupied() { if let Some(client) = self.client(window) { let current_pos = self.conn.get_pointer_position(); - let client_region = *client.free_region(); + let client_region = client.free_region(); let corner = client.free_region().nearest_corner(current_pos); self.resize_buffer @@ -2703,11 +2685,11 @@ impl<'a> Model<'a> { let grip = self.resize_buffer.grip().unwrap(); let current_pos = *pos; - let previous_region = *client.previous_region(); + let previous_region = client.previous_region(); let decoration = client.decoration(); let (pos, mut dim) = client .free_region() - .without_extents(&decoration.extents()) + .without_extents(decoration.extents()) .values(); let top_grip = grip.is_top_grip(); @@ -2737,7 +2719,7 @@ impl<'a> Model<'a> { pos, dim, }) - .with_extents(&decoration.extents()); + .with_extents(decoration.extents()); if top_grip { region.pos.y = window_region.pos.y + (window_region.dim.h - region.dim.h); @@ -2757,7 +2739,7 @@ impl<'a> Model<'a> { kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *decoration, + decoration, }; self.update_client_placement(&placement); @@ -3269,14 +3251,14 @@ impl<'a> Model<'a> { .map(|region| { if client.size_hints().is_some() { region - .without_extents(&frame_extents) + .without_extents(frame_extents) .with_size_hints(&client.size_hints()) - .with_extents(&frame_extents) + .with_extents(frame_extents) } else { region - .without_extents(&frame_extents) + .without_extents(frame_extents) .with_minimum_dim(&Client::MIN_CLIENT_DIM) - .with_extents(&frame_extents) + .with_extents(frame_extents) } }); @@ -3286,7 +3268,7 @@ impl<'a> Model<'a> { kind: PlacementTarget::Client(window), zone: client.zone(), region: PlacementRegion::NewRegion(region), - decoration: *client.decoration(), + decoration: client.decoration(), }; self.update_client_placement(&placement); @@ -3330,7 +3312,7 @@ impl<'a> Model<'a> { if let Some(client) = self.client(window) { let current_pos = self.conn.get_pointer_position(); - let client_region = *client.free_region(); + let client_region = client.free_region(); self.resize_buffer .set(window, grip, current_pos, client_region); @@ -3418,7 +3400,7 @@ impl<'a> Model<'a> { let client = self.client_any_mut(window).unwrap(); client.set_size_hints(size_hints); - client.set_free_region(&geometry); + client.set_region(PlacementClass::Free(geometry)); if client.is_managed() && workspace == self.active_workspace() { self.apply_layout(workspace, true); diff --git a/src/winsys/geometry.rs b/src/winsys/geometry.rs @@ -406,7 +406,7 @@ impl Region { pub fn from_absolute_inner_center( self, - dim: &Dim, + dim: Dim, ) -> Self { if dim.w > self.dim.w || dim.h > self.dim.h { return self; @@ -417,13 +417,13 @@ impl Region { x: self.pos.x + ((self.dim.w - dim.w) as f32 / 2f32) as i32, y: self.pos.y + ((self.dim.h - dim.h) as f32 / 2f32) as i32, }, - dim: *dim, + dim, } } pub fn without_extents( mut self, - extents: &Extents, + extents: Extents, ) -> Self { self.pos.x += extents.left; self.pos.y += extents.top; @@ -434,7 +434,7 @@ impl Region { pub fn with_extents( mut self, - extents: &Extents, + extents: Extents, ) -> Self { self.pos.x -= extents.left; self.pos.y -= extents.top;