2022-08-14 14:30:13 +01:00
|
|
|
mod bar;
|
|
|
|
mod collection;
|
|
|
|
mod config;
|
2022-08-14 20:40:11 +01:00
|
|
|
mod icon;
|
2022-08-14 14:30:13 +01:00
|
|
|
mod modules;
|
|
|
|
mod popup;
|
|
|
|
mod style;
|
2022-08-14 20:40:11 +01:00
|
|
|
mod sway;
|
2022-08-14 14:30:13 +01:00
|
|
|
|
|
|
|
use crate::bar::create_bar;
|
2022-08-15 17:06:42 +01:00
|
|
|
use crate::config::{Config, MonitorConfig};
|
2022-08-14 14:30:13 +01:00
|
|
|
use crate::style::load_css;
|
2022-08-14 20:40:11 +01:00
|
|
|
use crate::sway::SwayOutput;
|
2022-08-14 14:30:13 +01:00
|
|
|
use dirs::config_dir;
|
|
|
|
use gtk::prelude::*;
|
|
|
|
use gtk::{gdk, Application};
|
2022-08-14 16:23:41 +01:00
|
|
|
use ksway::client::Client;
|
|
|
|
use ksway::IpcCommand;
|
2022-08-14 14:30:13 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let app = Application::builder()
|
|
|
|
.application_id("dev.jstanger.waylandbar")
|
|
|
|
.build();
|
|
|
|
|
2022-08-14 16:23:41 +01:00
|
|
|
let mut sway_client = Client::connect().expect("Failed to connect to Sway IPC");
|
2022-08-14 20:40:11 +01:00
|
|
|
let outputs = sway_client
|
|
|
|
.ipc(IpcCommand::GetOutputs)
|
|
|
|
.expect("Failed to get Sway outputs");
|
|
|
|
let outputs = serde_json::from_slice::<Vec<SwayOutput>>(&outputs)
|
|
|
|
.expect("Failed to deserialize outputs message from Sway IPC");
|
2022-08-14 16:23:41 +01:00
|
|
|
|
|
|
|
app.connect_activate(move |app| {
|
2022-08-14 14:30:13 +01:00
|
|
|
let config = Config::load().unwrap_or_default();
|
|
|
|
|
|
|
|
// TODO: Better logging (https://crates.io/crates/tracing)
|
|
|
|
// TODO: error handling (https://crates.io/crates/color-eyre)
|
|
|
|
|
|
|
|
// TODO: Embedded Deno/lua - build custom modules via script???
|
|
|
|
|
|
|
|
let display = gdk::Display::default().expect("Failed to get default GDK display");
|
|
|
|
let num_monitors = display.n_monitors();
|
2022-08-15 17:06:42 +01:00
|
|
|
|
2022-08-14 14:30:13 +01:00
|
|
|
for i in 0..num_monitors {
|
|
|
|
let monitor = display.monitor(i).unwrap();
|
2022-08-14 20:40:11 +01:00
|
|
|
let monitor_name = &outputs
|
|
|
|
.get(i as usize)
|
|
|
|
.expect("GTK monitor output differs from Sway's")
|
|
|
|
.name;
|
2022-08-14 14:30:13 +01:00
|
|
|
|
2022-08-15 21:11:17 +01:00
|
|
|
config.monitors.as_ref().map_or_else(
|
|
|
|
|| {
|
|
|
|
create_bar(app, &monitor, monitor_name, config.clone());
|
|
|
|
},
|
|
|
|
|config| {
|
|
|
|
let config = config.get(monitor_name);
|
|
|
|
match &config {
|
|
|
|
Some(MonitorConfig::Single(config)) => {
|
2022-08-15 17:06:42 +01:00
|
|
|
create_bar(app, &monitor, monitor_name, config.clone());
|
|
|
|
}
|
2022-08-15 21:11:17 +01:00
|
|
|
Some(MonitorConfig::Multiple(configs)) => {
|
|
|
|
for config in configs {
|
|
|
|
create_bar(app, &monitor, monitor_name, config.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
2022-08-15 17:06:42 +01:00
|
|
|
}
|
2022-08-15 21:11:17 +01:00
|
|
|
},
|
|
|
|
)
|
2022-08-14 14:30:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let style_path = config_dir()
|
|
|
|
.expect("Failed to locate user config dir")
|
|
|
|
.join("ironbar")
|
|
|
|
.join("style.css");
|
|
|
|
|
|
|
|
if style_path.exists() {
|
|
|
|
load_css(style_path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.run();
|
|
|
|
}
|