From ddf91b18cc7a6a90f6066ef2358e8e1efba09a02 Mon Sep 17 00:00:00 2001 From: thmasq Date: Sat, 13 Jan 2024 22:08:31 -0300 Subject: [PATCH] build: add `focused` and `launcher` feature flags --- Cargo.toml | 12 +++-- docs/Compiling.md | 2 + docs/modules/Clipboard.md | 3 ++ docs/modules/Focused.md | 3 ++ docs/modules/Launcher.md | 3 ++ src/bar.rs | 2 + src/clients/wayland/mod.rs | 44 ++++++++++++++----- .../wayland/wlr_foreign_toplevel/mod.rs | 1 + src/config/mod.rs | 15 ++++++- src/modules/mod.rs | 4 ++ 10 files changed, 75 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0d7f5e65..15120a02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,13 @@ keywords = ["gtk", "bar", "wayland", "wlroots", "gtk-layer-shell"] [features] default = [ "cli", - "ipc", - "http", - "config+all", "clipboard", "clock", + "config+all", + "focused", + "http", + "ipc", + "launcher", "music+all", "sys_info", "tray", @@ -45,6 +47,10 @@ clipboard = ["nix"] clock = ["chrono"] +focused = [] + +launcher = [] + music = ["regex"] "music+all" = ["music", "music+mpris", "music+mpd"] "music+mpris" = ["music", "mpris"] diff --git a/docs/Compiling.md b/docs/Compiling.md index 91ca54d4..22248e87 100644 --- a/docs/Compiling.md +++ b/docs/Compiling.md @@ -73,6 +73,8 @@ cargo build --release --no-default-features \ | **Modules** | | | clipboard | Enables the `clipboard` module. | | clock | Enables the `clock` module. | +| focused | Enables the `focused` module. | +| launcher | Enables the `launcher` module. | | music+all | Enables the `music` module with support for all player types. | | music+mpris | Enables the `music` module with MPRIS support. | | music+mpd | Enables the `music` module with MPD support. | diff --git a/docs/modules/Clipboard.md b/docs/modules/Clipboard.md index 3daa5be7..7aa3b7f2 100644 --- a/docs/modules/Clipboard.md +++ b/docs/modules/Clipboard.md @@ -1,3 +1,6 @@ +> [!NOTE] +> This module requires a `wlroots-based` compositor. It will not work without the [wlr data control](https://wayland.app/protocols/wlr-data-control-unstable-v1) protocol. + Shows recent clipboard items, allowing you to switch between them to re-copy previous values. Clicking the icon button opens the popup containing all functionality. diff --git a/docs/modules/Focused.md b/docs/modules/Focused.md index bacf72e8..009b1251 100644 --- a/docs/modules/Focused.md +++ b/docs/modules/Focused.md @@ -1,3 +1,6 @@ +> [!NOTE] +> This module requires a `wlroots-based` compositor. It will not work without the [wlr-foreign-toplevel-management](https://wayland.app/protocols/wlr-foreign-toplevel-management-unstable-v1) protocol. + Displays the title and/or icon of the currently focused window. ![Screenshot of focused widget, showing this page open on firefox](https://user-images.githubusercontent.com/5057870/184714118-c1fb1c67-cd8c-4cc0-b5cd-6faccff818ac.png) diff --git a/docs/modules/Launcher.md b/docs/modules/Launcher.md index 8e0d7d3e..7f8e500f 100644 --- a/docs/modules/Launcher.md +++ b/docs/modules/Launcher.md @@ -1,3 +1,6 @@ +> [!NOTE] +> This module requires a `wlroots-based` compositor. It will not work without the [wlr-foreign-toplevel-management](https://wayland.app/protocols/wlr-foreign-toplevel-management-unstable-v1) protocol. + Windows-style taskbar that displays running windows, grouped by program. Hovering over a program with multiple windows open shows a popup with each window. Clicking an icon/popup item focuses or launches the program. diff --git a/src/bar.rs b/src/bar.rs index 1c78fd7d..510e1573 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -377,8 +377,10 @@ fn add_modules( #[cfg(feature = "clock")] ModuleConfig::Clock(mut module) => add_module!(module, id), ModuleConfig::Custom(mut module) => add_module!(module, id), + #[cfg(feature = "focused")] ModuleConfig::Focused(mut module) => add_module!(module, id), ModuleConfig::Label(mut module) => add_module!(module, id), + #[cfg(feature = "launcher")] ModuleConfig::Launcher(mut module) => add_module!(module, id), #[cfg(feature = "music")] ModuleConfig::Music(mut module) => add_module!(module, id), diff --git a/src/clients/wayland/mod.rs b/src/clients/wayland/mod.rs index 94dbbf9e..4d50da24 100644 --- a/src/clients/wayland/mod.rs +++ b/src/clients/wayland/mod.rs @@ -1,13 +1,9 @@ mod macros; mod wl_output; mod wl_seat; -mod wlr_foreign_toplevel; use crate::error::ERR_CHANNEL_RECV; -use crate::{ - arc_mut, delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager, lock, - register_client, send, Ironbar, -}; +use crate::{arc_mut, lock, register_client, send, Ironbar}; use std::sync::{Arc, Mutex}; use calloop_channel::Event::Msg; @@ -26,11 +22,17 @@ use tokio::sync::{broadcast, mpsc}; use tracing::{debug, error, trace}; use wayland_client::globals::registry_queue_init; use wayland_client::{Connection, QueueHandle}; +pub use wl_output::{OutputEvent, OutputEventType}; -use wlr_foreign_toplevel::manager::ToplevelManagerState; +cfg_if! { + if #[cfg(any(feature = "focused", feature = "launcher"))] { + mod wlr_foreign_toplevel; + use crate::{delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager}; + use wlr_foreign_toplevel::manager::ToplevelManagerState; + pub use wlr_foreign_toplevel::{ToplevelEvent, ToplevelHandle, ToplevelInfo}; -pub use wl_output::{OutputEvent, OutputEventType}; -pub use wlr_foreign_toplevel::{ToplevelEvent, ToplevelHandle, ToplevelInfo}; + } +} cfg_if! { if #[cfg(feature = "clipboard")] { @@ -56,6 +58,7 @@ cfg_if! { #[derive(Debug)] pub enum Event { Output(OutputEvent), + #[cfg(any(feature = "focused", feature = "launcher"))] Toplevel(ToplevelEvent), #[cfg(feature = "clipboard")] Clipboard(ClipboardItem), @@ -68,7 +71,9 @@ pub enum Request { #[cfg(feature = "ipc")] OutputInfoAll, + #[cfg(any(feature = "focused", feature = "launcher"))] ToplevelInfoAll, + #[cfg(feature = "launcher")] ToplevelFocus(usize), #[cfg(feature = "clipboard")] @@ -85,6 +90,9 @@ pub enum Response { #[cfg(feature = "ipc")] OutputInfoAll(Vec), + #[cfg(feature = "launcher")] + ToplevelInfo(Option), + #[cfg(any(feature = "focused", feature = "launcher"))] ToplevelInfoAll(Vec), #[cfg(feature = "clipboard")] @@ -106,6 +114,7 @@ pub struct Client { rx: Arc>>, output_channel: BroadcastChannel, + #[cfg(any(feature = "focused", feature = "launcher"))] toplevel_channel: BroadcastChannel, #[cfg(feature = "clipboard")] clipboard_channel: BroadcastChannel, @@ -119,6 +128,7 @@ impl Client { let (response_tx, response_rx) = std::sync::mpsc::channel(); let output_channel = broadcast::channel(32); + #[cfg(any(feature = "focused", feature = "launcher"))] let toplevel_channel = broadcast::channel(32); #[cfg(feature = "clipboard")] @@ -131,6 +141,7 @@ impl Client { // listen to events { let output_tx = output_channel.0.clone(); + #[cfg(any(feature = "focused", feature = "launcher"))] let toplevel_tx = toplevel_channel.0.clone(); #[cfg(feature = "clipboard")] @@ -141,6 +152,7 @@ impl Client { while let Some(event) = event_rx.recv().await { match event { Event::Output(event) => send!(output_tx, event), + #[cfg(any(feature = "focused", feature = "launcher"))] Event::Toplevel(event) => send!(toplevel_tx, event), #[cfg(feature = "clipboard")] Event::Clipboard(item) => send!(clipboard_tx, item), @@ -154,6 +166,7 @@ impl Client { rx: arc_mut!(response_rx), output_channel: output_channel.into(), + #[cfg(any(feature = "focused", feature = "launcher"))] toplevel_channel: toplevel_channel.into(), #[cfg(feature = "clipboard")] clipboard_channel: clipboard_channel.into(), @@ -187,6 +200,7 @@ pub struct Environment { response_tx: std::sync::mpsc::Sender, // local state + #[cfg(any(feature = "focused", feature = "launcher"))] handles: Vec, // -- clipboard -- @@ -210,8 +224,12 @@ delegate_registry!(Environment); delegate_output!(Environment); delegate_seat!(Environment); -delegate_foreign_toplevel_manager!(Environment); -delegate_foreign_toplevel_handle!(Environment); +cfg_if! { + if #[cfg(any(feature = "focused", feature = "launcher"))] { + delegate_foreign_toplevel_manager!(Environment); + delegate_foreign_toplevel_handle!(Environment); + } +} cfg_if! { if #[cfg(feature = "clipboard")] { @@ -247,6 +265,7 @@ impl Environment { let output_state = OutputState::new(&globals, &qh); let seat_state = SeatState::new(&globals, &qh); + #[cfg(any(feature = "focused", feature = "launcher"))] ToplevelManagerState::bind(&globals, &qh) .expect("to bind to wlr_foreign_toplevel_manager global"); @@ -264,6 +283,7 @@ impl Environment { loop_handle: loop_handle.clone(), event_tx, response_tx, + #[cfg(any(feature = "focused", feature = "launcher"))] handles: vec![], #[cfg(feature = "clipboard")] @@ -306,6 +326,7 @@ impl Environment { let infos = env.output_info_all(); send!(env.response_tx, Response::OutputInfoAll(infos)); } + #[cfg(any(feature = "focused", feature = "launcher"))] Msg(Request::ToplevelInfoAll) => { let infos = env .handles @@ -314,15 +335,18 @@ impl Environment { .collect(); send!(env.response_tx, Response::ToplevelInfoAll(infos)); } + #[cfg(feature = "launcher")] Msg(Request::ToplevelFocus(id)) => { let handle = env .handles .iter() .find(|handle| handle.info().map_or(false, |info| info.id == id)); + if let Some(handle) = handle { let seat = env.default_seat(); handle.focus(&seat); } + send!(env.response_tx, Response::Ok); } #[cfg(feature = "clipboard")] diff --git a/src/clients/wayland/wlr_foreign_toplevel/mod.rs b/src/clients/wayland/wlr_foreign_toplevel/mod.rs index a66df66a..d0c3d9e8 100644 --- a/src/clients/wayland/wlr_foreign_toplevel/mod.rs +++ b/src/clients/wayland/wlr_foreign_toplevel/mod.rs @@ -28,6 +28,7 @@ impl Client { } /// Focuses the toplevel with the provided ID. + #[cfg(feature = "launcher")] pub fn toplevel_focus(&self, handle_id: usize) { match self.send_request(Request::ToplevelFocus(handle_id)) { Response::Ok => (), diff --git a/src/config/mod.rs b/src/config/mod.rs index faa5ecaf..bb0d61f2 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -7,8 +7,10 @@ use crate::modules::clipboard::ClipboardModule; #[cfg(feature = "clock")] use crate::modules::clock::ClockModule; use crate::modules::custom::CustomModule; +#[cfg(feature = "focused")] use crate::modules::focused::FocusedModule; use crate::modules::label::LabelModule; +#[cfg(feature = "launcher")] use crate::modules::launcher::LauncherModule; #[cfg(feature = "music")] use crate::modules::music::MusicModule; @@ -36,8 +38,10 @@ pub enum ModuleConfig { #[cfg(feature = "clock")] Clock(Box), Custom(Box), + #[cfg(feature = "focused")] Focused(Box), Label(Box), + #[cfg(feature = "launcher")] Launcher(Box), #[cfg(feature = "music")] Music(Box), @@ -127,6 +131,15 @@ impl Default for Config { } } + cfg_if! { + if #[cfg(feature = "focused")] { + let center = Some(vec![ModuleConfig::Focused(Box::default())]); + } + else { + let center = None; + } + } + Self { position: BarPosition::default(), height: default_bar_height(), @@ -140,7 +153,7 @@ impl Default for Config { start: Some(vec![ModuleConfig::Label( LabelModule::new("ℹ️ Using default config".to_string()).into(), )]), - center: Some(vec![ModuleConfig::Focused(Box::default())]), + center, end, anchor_to_edges: default_true(), monitors: None, diff --git a/src/modules/mod.rs b/src/modules/mod.rs index dd543da2..a293d0f0 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -28,8 +28,10 @@ pub mod clipboard; #[cfg(feature = "clock")] pub mod clock; pub mod custom; +#[cfg(feature = "focused")] pub mod focused; pub mod label; +#[cfg(feature = "launcher")] pub mod launcher; #[cfg(feature = "music")] pub mod music; @@ -68,6 +70,7 @@ pub enum ModuleUpdateEvent { /// Force sets the popup open. /// Takes the button ID. OpenPopup(usize), + #[cfg(feature = "launcher")] OpenPopupAt(WidgetGeometry), /// Force sets the popup closed. ClosePopup, @@ -317,6 +320,7 @@ fn setup_receiver( has_popup_opened = true; } } + #[cfg(feature = "launcher")] ModuleUpdateEvent::OpenPopupAt(geometry) => { debug!("Opening popup for {} [#{}]", name, id);