Skip to content

Commit

Permalink
feat: load bars on monitor when it connects
Browse files Browse the repository at this point in the history
Finally, Ironbar will respond to events of monitors being (dis)connected, and will create bars when a monitor connects.

This means at last - resolves #291

yaay
  • Loading branch information
JakeStanger committed Jan 13, 2024
1 parent 3dc198e commit 8371a92
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 97 deletions.
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 std::sync::{Arc, Mutex};
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 smithay_client_toolkit::{
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 @@ cfg_if! {
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 Event {
pub enum Request {
Roundtrip,

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

ToplevelInfoAll,
Expand All @@ -81,16 +82,13 @@ pub enum Response {
/// 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 @@ -303,6 +301,7 @@ impl Environment {
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 @@ pub enum ExitCode {
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

0 comments on commit 8371a92

Please sign in to comment.