Skip to content

Commit

Permalink
Merge pull request #404 from thmasq/master
Browse files Browse the repository at this point in the history
Make feature flags for the "focused" and launcher "modules"
  • Loading branch information
JakeStanger authored Jan 14, 2024
2 parents e737177 + ddf91b1 commit b9a42f0
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 14 deletions.
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -45,6 +47,10 @@ clipboard = ["nix"]

clock = ["chrono"]

focused = []

launcher = []

music = ["regex"]
"music+all" = ["music", "music+mpris", "music+mpd"]
"music+mpris" = ["music", "mpris"]
Expand Down
2 changes: 2 additions & 0 deletions docs/Compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
3 changes: 3 additions & 0 deletions docs/modules/Clipboard.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
3 changes: 3 additions & 0 deletions docs/modules/Focused.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions docs/modules/Launcher.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
44 changes: 34 additions & 10 deletions src/clients/wayland/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")] {
Expand All @@ -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),
Expand All @@ -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")]
Expand All @@ -85,6 +90,9 @@ pub enum Response {
#[cfg(feature = "ipc")]
OutputInfoAll(Vec<smithay_client_toolkit::output::OutputInfo>),

#[cfg(feature = "launcher")]
ToplevelInfo(Option<ToplevelInfo>),

Check warning on line 94 in src/clients/wayland/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variant `ToplevelInfo` is never constructed

warning: variant `ToplevelInfo` is never constructed --> src/clients/wayland/mod.rs:94:5 | 86 | pub enum Response { | -------- variant in this enum ... 94 | ToplevelInfo(Option<ToplevelInfo>), | ^^^^^^^^^^^^ | = note: `Response` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default
#[cfg(any(feature = "focused", feature = "launcher"))]
ToplevelInfoAll(Vec<ToplevelInfo>),

#[cfg(feature = "clipboard")]
Expand All @@ -106,6 +114,7 @@ pub struct Client {
rx: Arc<Mutex<std::sync::mpsc::Receiver<Response>>>,

output_channel: BroadcastChannel<OutputEvent>,
#[cfg(any(feature = "focused", feature = "launcher"))]
toplevel_channel: BroadcastChannel<ToplevelEvent>,
#[cfg(feature = "clipboard")]
clipboard_channel: BroadcastChannel<ClipboardItem>,
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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),
Expand All @@ -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(),
Expand Down Expand Up @@ -187,6 +200,7 @@ pub struct Environment {
response_tx: std::sync::mpsc::Sender<Response>,

// local state
#[cfg(any(feature = "focused", feature = "launcher"))]
handles: Vec<ToplevelHandle>,

// -- clipboard --
Expand All @@ -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")] {
Expand Down Expand Up @@ -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");

Expand All @@ -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")]
Expand Down Expand Up @@ -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
Expand All @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions src/clients/wayland/wlr_foreign_toplevel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => (),
Expand Down
15 changes: 14 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,8 +38,10 @@ pub enum ModuleConfig {
#[cfg(feature = "clock")]
Clock(Box<ClockModule>),
Custom(Box<CustomModule>),
#[cfg(feature = "focused")]
Focused(Box<FocusedModule>),
Label(Box<LabelModule>),
#[cfg(feature = "launcher")]
Launcher(Box<LauncherModule>),
#[cfg(feature = "music")]
Music(Box<MusicModule>),
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +70,7 @@ pub enum ModuleUpdateEvent<T: Clone> {
/// Force sets the popup open.
/// Takes the button ID.
OpenPopup(usize),
#[cfg(feature = "launcher")]
OpenPopupAt(WidgetGeometry),
/// Force sets the popup closed.
ClosePopup,
Expand Down Expand Up @@ -317,6 +320,7 @@ fn setup_receiver<TSend>(
has_popup_opened = true;
}
}
#[cfg(feature = "launcher")]
ModuleUpdateEvent::OpenPopupAt(geometry) => {
debug!("Opening popup for {} [#{}]", name, id);

Expand Down

0 comments on commit b9a42f0

Please sign in to comment.