From 89b5f3f87c8022f2d32c422c3516fca2f1538d69 Mon Sep 17 00:00:00 2001 From: tcmal Date: Tue, 6 Aug 2024 14:39:55 +0100 Subject: Add tags/workspaces --- src/clients/monitors.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/clients/monitors.rs') diff --git a/src/clients/monitors.rs b/src/clients/monitors.rs index 6790632..16348ea 100644 --- a/src/clients/monitors.rs +++ b/src/clients/monitors.rs @@ -1,6 +1,6 @@ use xcb::xinerama::ScreenInfo; -use super::Client; +use super::{Client, Tag}; /// Info stored for each monitor #[derive(Debug)] @@ -8,15 +8,47 @@ pub struct MonitorInfo { /// Clients attached to that monitor pub clients: Vec, + /// How clients should be filtered by tag + pub focused_tag: TagFocus, + /// The monitor's geometry pub screen_info: MonitorGeometry, } +/// How clients are currently being filtered by tag +#[derive(Debug, Clone, Copy)] +pub enum TagFocus { + /// Only show clients with the given tag + Tag(Tag), + + /// Show all clients + All, +} +impl TagFocus { + /// Check if a client with the given tag should be displayed when using this filter + pub const fn matches(&self, tag: Tag) -> bool { + match self { + Self::Tag(x) => *x == tag, + Self::All => true, + } + } + + /// Get the tag that new clients should be assigned when using this filter + pub const fn create_tag(&self) -> Tag { + match self { + Self::Tag(x) => *x, + Self::All => 1, + } + } +} + impl MonitorInfo { /// Iterate over all tiled clients, returning a mutable reference to each. pub fn clients_tiled_mut(&mut self) -> impl Iterator { - // TODO: tag filtering - self.clients.iter_mut().filter(|c| c.tiled()) + self.clients + .iter_mut() + .filter(|c| c.tiled()) + .filter(|c| self.focused_tag.matches(c.tag)) } } @@ -30,6 +62,7 @@ impl Default for MonitorInfo { width: 0, height: 0, }, + focused_tag: TagFocus::Tag(1), } } } -- cgit v1.2.3