mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-03 03:31:03 +02:00
build: add focused
and launcher
feature flags
This commit is contained in:
parent
e737177ab0
commit
ddf91b18cc
10 changed files with 76 additions and 15 deletions
|
@ -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};
|
||||
|
||||
use wlr_foreign_toplevel::manager::ToplevelManagerState;
|
||||
|
||||
pub use wl_output::{OutputEvent, OutputEventType};
|
||||
pub use wlr_foreign_toplevel::{ToplevelEvent, ToplevelHandle, ToplevelInfo};
|
||||
|
||||
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};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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<smithay_client_toolkit::output::OutputInfo>),
|
||||
|
||||
#[cfg(feature = "launcher")]
|
||||
ToplevelInfo(Option<ToplevelInfo>),
|
||||
#[cfg(any(feature = "focused", feature = "launcher"))]
|
||||
ToplevelInfoAll(Vec<ToplevelInfo>),
|
||||
|
||||
#[cfg(feature = "clipboard")]
|
||||
|
@ -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>,
|
||||
|
@ -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<Response>,
|
||||
|
||||
// local state
|
||||
#[cfg(any(feature = "focused", feature = "launcher"))]
|
||||
handles: Vec<ToplevelHandle>,
|
||||
|
||||
// -- 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")]
|
||||
|
|
|
@ -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 => (),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue