1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 02:31:04 +02:00

feat: initial support for running outside sway

Progress is being tracked in #18. Currently the workspaces, focused and launcher modules are not supported.
This commit is contained in:
Jake Stanger 2022-09-27 20:24:16 +01:00
parent d22d954e83
commit b188bc7146
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
4 changed files with 143 additions and 15 deletions

View file

@ -8,6 +8,7 @@ mod modules;
mod popup;
mod style;
mod sway;
mod wayland;
use crate::bar::create_bar;
use crate::config::{Config, MonitorConfig};
@ -100,25 +101,16 @@ async fn main() -> Result<()> {
/// Creates each of the bars across each of the (configured) outputs.
async fn create_bars(app: &Application, display: &Display, config: &Config) -> Result<()> {
let outputs = {
let sway = get_client().await;
let mut sway = sway.lock().await;
let outputs = wayland::get_output_names();
let outputs = sway.get_outputs().await;
match outputs {
Ok(outputs) => Ok(outputs),
Err(err) => Err(err),
}
}?;
debug!("Received {} outputs from Sway IPC", outputs.len());
debug!("Received {} outputs from Wayland", outputs.len());
debug!("Output names: {:?}", outputs);
let num_monitors = display.n_monitors();
for i in 0..num_monitors {
let monitor = display.monitor(i).ok_or_else(|| Report::msg("GTK and Sway are reporting a different number of outputs - this is a severe bug and should never happen"))?;
let monitor_name = &outputs.get(i as usize).ok_or_else(|| Report::msg("GTK and Sway are reporting a different set of outputs - this is a severe bug and should never happen"))?.name;
let monitor_name = outputs.get(i as usize).ok_or_else(|| Report::msg("GTK and Sway are reporting a different set of outputs - this is a severe bug and should never happen"))?;
info!("Creating bar on '{}'", monitor_name);

49
src/wayland.rs Normal file
View file

@ -0,0 +1,49 @@
use std::cell::RefCell;
use std::rc::Rc;
use wayland_client::protocol::wl_output::{self, Event};
use wayland_client::{global_filter, Display as WlDisplay, GlobalManager, Main};
pub fn get_output_names() -> Vec<String> {
// Connect to the server
let display = WlDisplay::connect_to_env().unwrap();
let mut event_queue = display.create_event_queue();
let attached_display = (*display).clone().attach(event_queue.token());
let outputs = Rc::new(RefCell::new(Vec::<String>::new()));
let _globals = {
let outputs = outputs.clone();
GlobalManager::new_with_cb(&attached_display, {
global_filter!([
wl_output::WlOutput,
4,
move |output: Main<wl_output::WlOutput>, _: DispatchData| {
let outputs = outputs.clone();
output.quick_assign(move |_, event, _| match event {
Event::Name { name: title } => {
let outputs = outputs.clone();
outputs.as_ref().borrow_mut().push(title);
}
_ => {}
})
}
])
})
};
// A roundtrip synchronization to make sure the server received our registry
// creation and sent us the global list
event_queue
.sync_roundtrip(&mut (), |_, _, _| unreachable!())
.unwrap();
// for some reason we need to call this twice?
event_queue
.sync_roundtrip(&mut (), |_, _, _| unreachable!())
.unwrap();
outputs.take()
}