1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +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

87
Cargo.lock generated
View file

@ -594,6 +594,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "downcast-rs"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]] [[package]]
name = "either" name = "either"
version = "1.7.0" version = "1.7.0"
@ -1133,6 +1139,8 @@ dependencies = [
"tracing-error", "tracing-error",
"tracing-subscriber", "tracing-subscriber",
"walkdir", "walkdir",
"wayland-client",
"wayland-protocols",
] ]
[[package]] [[package]]
@ -1281,6 +1289,18 @@ dependencies = [
"memoffset", "memoffset",
] ]
[[package]]
name = "nix"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [
"bitflags",
"cfg-if",
"libc",
"memoffset",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.1" version = "7.1.1"
@ -2280,6 +2300,65 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wayland-client"
version = "0.29.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715"
dependencies = [
"bitflags",
"downcast-rs",
"libc",
"nix 0.24.2",
"wayland-commons",
"wayland-scanner",
"wayland-sys",
]
[[package]]
name = "wayland-commons"
version = "0.29.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902"
dependencies = [
"nix 0.24.2",
"once_cell",
"smallvec",
"wayland-sys",
]
[[package]]
name = "wayland-protocols"
version = "0.29.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6"
dependencies = [
"bitflags",
"wayland-client",
"wayland-commons",
"wayland-scanner",
]
[[package]]
name = "wayland-scanner"
version = "0.29.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53"
dependencies = [
"proc-macro2",
"quote",
"xml-rs",
]
[[package]]
name = "wayland-sys"
version = "0.29.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4"
dependencies = [
"pkg-config",
]
[[package]] [[package]]
name = "wepoll-ffi" name = "wepoll-ffi"
version = "0.1.2" version = "0.1.2"
@ -2363,6 +2442,12 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "xml-rs"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
[[package]] [[package]]
name = "zbus" name = "zbus"
version = "2.3.2" version = "2.3.2"
@ -2386,7 +2471,7 @@ dependencies = [
"futures-util", "futures-util",
"hex", "hex",
"lazy_static", "lazy_static",
"nix", "nix 0.23.1",
"once_cell", "once_cell",
"ordered-stream", "ordered-stream",
"rand", "rand",

View file

@ -35,4 +35,6 @@ walkdir = "2.3.2"
notify = "5.0.0" notify = "5.0.0"
mpd_client = "1.0.0" mpd_client = "1.0.0"
swayipc-async = { git = "https://github.com/JakeStanger/swayipc-rs.git", branch = "feat/derive-clone" } swayipc-async = { git = "https://github.com/JakeStanger/swayipc-rs.git", branch = "feat/derive-clone" }
sysinfo = "0.26.2" sysinfo = "0.26.2"
wayland-client = "0.29.5"
wayland-protocols = { version = "0.29.5", features=["unstable_protocols", "client"] }

View file

@ -8,6 +8,7 @@ mod modules;
mod popup; mod popup;
mod style; mod style;
mod sway; mod sway;
mod wayland;
use crate::bar::create_bar; use crate::bar::create_bar;
use crate::config::{Config, MonitorConfig}; use crate::config::{Config, MonitorConfig};
@ -100,25 +101,16 @@ async fn main() -> Result<()> {
/// Creates each of the bars across each of the (configured) outputs. /// Creates each of the bars across each of the (configured) outputs.
async fn create_bars(app: &Application, display: &Display, config: &Config) -> Result<()> { async fn create_bars(app: &Application, display: &Display, config: &Config) -> Result<()> {
let outputs = { let outputs = wayland::get_output_names();
let sway = get_client().await;
let mut sway = sway.lock().await;
let outputs = sway.get_outputs().await; debug!("Received {} outputs from Wayland", outputs.len());
debug!("Output names: {:?}", outputs);
match outputs {
Ok(outputs) => Ok(outputs),
Err(err) => Err(err),
}
}?;
debug!("Received {} outputs from Sway IPC", outputs.len());
let num_monitors = display.n_monitors(); let num_monitors = display.n_monitors();
for i in 0..num_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 = 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); 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()
}