Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load bars on monitor when it connects #405

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ impl Bar {
&self.name
}

/// The name of the output the bar is displayed on.
pub fn monitor_name(&self) -> &str {
&self.monitor_name
}

pub fn popup(&self) -> Rc<RefCell<Popup>> {
match &self.inner {
Inner::New { .. } => {
Expand Down
15 changes: 7 additions & 8 deletions src/clients/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use calloop_channel::Event::Msg;
use cfg_if::cfg_if;
use color_eyre::Report;
use smithay_client_toolkit::output::{OutputInfo, OutputState};
use smithay_client_toolkit::output::OutputState;
use smithay_client_toolkit::reexports::calloop::channel as calloop_channel;
use smithay_client_toolkit::reexports::calloop::{EventLoop, LoopHandle};
use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource;
Expand All @@ -25,12 +25,11 @@
use tokio::sync::{broadcast, mpsc};
use tracing::{debug, error, trace};
use wayland_client::globals::registry_queue_init;
use wayland_client::protocol::wl_seat::WlSeat;
use wayland_client::{Connection, QueueHandle};

use wlr_foreign_toplevel::manager::ToplevelManagerState;

pub use wl_output::OutputEvent;
pub use wl_output::{OutputEvent, OutputEventType};
pub use wlr_foreign_toplevel::{ToplevelEvent, ToplevelHandle, ToplevelInfo};

cfg_if! {
Expand All @@ -42,6 +41,7 @@
use self::wlr_data_control::manager::DataControlDeviceManagerState;
use self::wlr_data_control::source::CopyPasteSource;
use self::wlr_data_control::SelectionOfferItem;
use wayland_client::protocol::wl_seat::WlSeat;

pub use wlr_data_control::{ClipboardItem, ClipboardValue};

Expand All @@ -65,6 +65,7 @@
pub enum Request {
Roundtrip,

#[cfg(feature = "ipc")]
OutputInfoAll,

ToplevelInfoAll,
Expand All @@ -81,16 +82,13 @@
/// An empty success response
Ok,

OutputInfo(Option<OutputInfo>),
OutputInfoAll(Vec<OutputInfo>),
#[cfg(feature = "ipc")]
OutputInfoAll(Vec<smithay_client_toolkit::output::OutputInfo>),

ToplevelInfo(Option<ToplevelInfo>),
ToplevelInfoAll(Vec<ToplevelInfo>),

#[cfg(feature = "clipboard")]
ClipboardItem(Option<ClipboardItem>),

Seat(WlSeat),
}

#[derive(Debug)]
Expand Down Expand Up @@ -182,7 +180,7 @@
output_state: OutputState,
seat_state: SeatState,

queue_handle: QueueHandle<Self>,

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

View workflow job for this annotation

GitHub Actions / clippy

fields `queue_handle` and `loop_handle` are never read

warning: fields `queue_handle` and `loop_handle` are never read --> src/clients/wayland/mod.rs:183:5 | 178 | pub struct Environment { | ----------- fields in this struct ... 183 | queue_handle: QueueHandle<Self>, | ^^^^^^^^^^^^ 184 | loop_handle: LoopHandle<'static, Self>, | ^^^^^^^^^^^ | = note: `Environment` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default
loop_handle: LoopHandle<'static, Self>,

event_tx: mpsc::Sender<Event>,
Expand Down Expand Up @@ -303,6 +301,7 @@
debug!("received roundtrip request");
send!(env.response_tx, Response::Ok);
}
#[cfg(feature = "ipc")]
Msg(Request::OutputInfoAll) => {
let infos = env.output_info_all();
send!(env.response_tx, Response::OutputInfoAll(infos));
Expand Down
9 changes: 6 additions & 3 deletions src/clients/wayland/wl_output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Client, Environment, Event, Request, Response};
use super::{Client, Environment, Event};
use crate::try_send;
use smithay_client_toolkit::output::{OutputHandler, OutputInfo, OutputState};
use tokio::sync::broadcast;
Expand All @@ -8,8 +8,8 @@ use wayland_client::{Connection, QueueHandle};

#[derive(Debug, Clone)]
pub struct OutputEvent {
output: OutputInfo,
event_type: OutputEventType,
pub output: OutputInfo,
pub event_type: OutputEventType,
}

#[derive(Debug, Clone, Copy)]
Expand All @@ -21,7 +21,9 @@ pub enum OutputEventType {

impl Client {
/// Gets the information for all outputs.
#[cfg(feature = "ipc")]
pub fn output_info_all(&self) -> Vec<OutputInfo> {
use super::{Request, Response};
match self.send_request(Request::OutputInfoAll) {
Response::OutputInfoAll(info) => info,
_ => unreachable!(),
Expand All @@ -35,6 +37,7 @@ impl Client {
}

impl Environment {
#[cfg(feature = "ipc")]
pub fn output_info_all(&mut self) -> Vec<OutputInfo> {
self.output_state
.outputs()
Expand Down
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
CreateBars = 2,
}

pub const ERR_OUTPUTS: &str = "GTK and Wayland are reporting a different set of outputs - this is a severe bug and should never happen";
pub const ERR_MUTEX_LOCK: &str = "Failed to get lock on Mutex";
pub const ERR_READ_LOCK: &str = "Failed to get read lock";
pub const ERR_WRITE_LOCK: &str = "Failed to get write lock";
pub const ERR_CHANNEL_SEND: &str = "Failed to send message to channel";
pub const ERR_CHANNEL_RECV: &str = "Failed to receive message from channel";

pub const ERR_WAYLAND_DATA: &str = "Failed to get data for Wayland object";

Check warning on line 12 in src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `ERR_WAYLAND_DATA` is never used

warning: constant `ERR_WAYLAND_DATA` is never used --> src/error.rs:12:11 | 12 | pub const ERR_WAYLAND_DATA: &str = "Failed to get data for Wayland object"; | ^^^^^^^^^^^^^^^^
14 changes: 13 additions & 1 deletion src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,24 @@ impl Ipc {
}
Command::Reload => {
info!("Closing existing bars");
ironbar.bars.borrow_mut().clear();

let windows = application.windows();
for window in windows {
window.close();
}

*ironbar.bars.borrow_mut() = crate::load_interface(application, ironbar.clone());
let wl = ironbar.clients.borrow_mut().wayland();
let outputs = wl.output_info_all();

ironbar.reload_config();

for output in outputs {
match crate::load_output_bars(ironbar, application, output) {
Ok(mut bars) => ironbar.bars.borrow_mut().append(&mut bars),
Err(err) => error!("{err:?}"),
}
}

Response::Ok
}
Expand Down
Loading
Loading