mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-24 17:48:34 +02:00
feat(bar): add config struct with basic opts
This commit is contained in:
29
Cargo.lock
generated
29
Cargo.lock
generated
@@ -805,9 +805,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.13"
|
version = "4.5.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc"
|
checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
@@ -815,9 +815,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.13"
|
version = "4.5.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99"
|
checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@@ -828,9 +828,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.13"
|
version = "4.5.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0"
|
checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -1173,9 +1173,9 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dunce"
|
name = "dunce"
|
||||||
version = "1.0.5"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
|
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dyn-clone"
|
name = "dyn-clone"
|
||||||
@@ -3554,9 +3554,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.10.6"
|
version = "1.10.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
|
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -3875,12 +3875,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.122"
|
version = "1.0.120"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da"
|
checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@@ -5081,9 +5080,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "which"
|
name = "which"
|
||||||
version = "6.0.2"
|
version = "6.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d9c5ed668ee1f17edb3b627225343d210006a90bb1e3745ce1f30b1fb115075"
|
checksum = "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
"home",
|
"home",
|
||||||
|
|||||||
@@ -15,44 +15,93 @@ use eframe::egui::CursorIcon;
|
|||||||
use eframe::egui::Layout;
|
use eframe::egui::Layout;
|
||||||
use eframe::egui::ViewportBuilder;
|
use eframe::egui::ViewportBuilder;
|
||||||
use eframe::egui::Visuals;
|
use eframe::egui::Visuals;
|
||||||
|
use eframe::emath::Pos2;
|
||||||
|
use eframe::emath::Vec2;
|
||||||
use komorebi_client::SocketMessage;
|
use komorebi_client::SocketMessage;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use time::Time;
|
use time::Time;
|
||||||
|
|
||||||
fn main() -> eframe::Result<()> {
|
#[derive(Copy, Clone, Debug)]
|
||||||
let native_options = eframe::NativeOptions {
|
pub struct Position {
|
||||||
viewport: ViewportBuilder::default()
|
x: f32,
|
||||||
.with_decorations(false)
|
y: f32,
|
||||||
// TODO: expose via config
|
}
|
||||||
.with_transparent(true)
|
|
||||||
// TODO: expose via config
|
|
||||||
.with_position([0.0, 0.0])
|
|
||||||
// TODO: expose via config
|
|
||||||
.with_inner_size([5120.0, 20.0]),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(
|
impl Into<Vec2> for Position {
|
||||||
0,
|
fn into(self) -> Vec2 {
|
||||||
komorebi_client::Rect {
|
Vec2 {
|
||||||
|
x: self.x,
|
||||||
|
y: self.y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<Pos2> for Position {
|
||||||
|
fn into(self) -> Pos2 {
|
||||||
|
Pos2 {
|
||||||
|
x: self.x,
|
||||||
|
y: self.y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct Config {
|
||||||
|
inner_size: Position,
|
||||||
|
position: Position,
|
||||||
|
outer_margin: Position,
|
||||||
|
transparent: bool,
|
||||||
|
monitor_index: usize,
|
||||||
|
monitor_work_area_offset: Option<komorebi_client::Rect>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> eframe::Result<()> {
|
||||||
|
let config = Config {
|
||||||
|
inner_size: Position { x: 5120.0, y: 20.0 },
|
||||||
|
position: Position { x: 0.0, y: 0.0 },
|
||||||
|
outer_margin: Position { x: 10.0, y: 10.0 },
|
||||||
|
transparent: false,
|
||||||
|
monitor_index: 0,
|
||||||
|
monitor_work_area_offset: Some(komorebi_client::Rect {
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 40,
|
top: 40,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 40,
|
bottom: 40,
|
||||||
},
|
}),
|
||||||
))
|
};
|
||||||
.unwrap();
|
|
||||||
|
// TODO: ensure that config.monitor_index represents a valid komorebi monitor index
|
||||||
|
|
||||||
|
let native_options = eframe::NativeOptions {
|
||||||
|
viewport: ViewportBuilder::default()
|
||||||
|
.with_decorations(false)
|
||||||
|
.with_transparent(config.transparent)
|
||||||
|
.with_position(config.position)
|
||||||
|
.with_inner_size(config.inner_size),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(rect) = &config.monitor_work_area_offset {
|
||||||
|
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(
|
||||||
|
config.monitor_index,
|
||||||
|
*rect,
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let (tx_gui, rx_gui) = crossbeam_channel::unbounded();
|
let (tx_gui, rx_gui) = crossbeam_channel::unbounded();
|
||||||
|
let config_arc = Arc::new(config);
|
||||||
|
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"komorebi-bar",
|
"komorebi-bar",
|
||||||
native_options,
|
native_options,
|
||||||
Box::new(|cc| {
|
Box::new(|cc| {
|
||||||
let frame = cc.egui_ctx.clone();
|
let frame = cc.egui_ctx.clone();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let listener = komorebi_client::subscribe("komorebi-bar").unwrap();
|
let listener = komorebi_client::subscribe("komorebi-bar").unwrap();
|
||||||
|
|
||||||
@@ -87,12 +136,13 @@ fn main() -> eframe::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(Box::new(Komobar::new(cc, rx_gui)))
|
Ok(Box::new(Komobar::new(cc, rx_gui, config_arc)))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Komobar {
|
struct Komobar {
|
||||||
|
config: Config,
|
||||||
state_receiver: Receiver<komorebi_client::Notification>,
|
state_receiver: Receiver<komorebi_client::Notification>,
|
||||||
selected_workspace: String,
|
selected_workspace: String,
|
||||||
workspaces: Vec<String>,
|
workspaces: Vec<String>,
|
||||||
@@ -103,13 +153,18 @@ struct Komobar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Komobar {
|
impl Komobar {
|
||||||
fn new(_cc: &eframe::CreationContext<'_>, rx: Receiver<komorebi_client::Notification>) -> Self {
|
fn new(
|
||||||
|
_cc: &eframe::CreationContext<'_>,
|
||||||
|
rx: Receiver<komorebi_client::Notification>,
|
||||||
|
config: Arc<Config>,
|
||||||
|
) -> Self {
|
||||||
// Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
|
// Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
|
||||||
// Restore app state using cc.storage (requires the "persistence" feature).
|
// Restore app state using cc.storage (requires the "persistence" feature).
|
||||||
// Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
|
// Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
|
||||||
// for e.g. egui::PaintCallback.
|
// for e.g. egui::PaintCallback.
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
config: *config.as_ref(),
|
||||||
state_receiver: rx,
|
state_receiver: rx,
|
||||||
selected_workspace: String::new(),
|
selected_workspace: String::new(),
|
||||||
workspaces: vec![],
|
workspaces: vec![],
|
||||||
@@ -126,8 +181,7 @@ impl Komobar {
|
|||||||
if let Ok(notification) = self.state_receiver.try_recv() {
|
if let Ok(notification) = self.state_receiver.try_recv() {
|
||||||
self.workspaces = {
|
self.workspaces = {
|
||||||
let mut workspaces = vec![];
|
let mut workspaces = vec![];
|
||||||
// TODO: komobar only operates on the 0th monitor (for now)
|
let monitor = ¬ification.state.monitors.elements()[self.config.monitor_index];
|
||||||
let monitor = ¬ification.state.monitors.elements()[0];
|
|
||||||
let focused_workspace_idx = monitor.focused_workspace_idx();
|
let focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
self.selected_workspace = monitor.workspaces()[focused_workspace_idx]
|
self.selected_workspace = monitor.workspaces()[focused_workspace_idx]
|
||||||
.name()
|
.name()
|
||||||
@@ -159,7 +213,10 @@ impl eframe::App for Komobar {
|
|||||||
.frame(
|
.frame(
|
||||||
egui::Frame::none()
|
egui::Frame::none()
|
||||||
// TODO: make this configurable
|
// TODO: make this configurable
|
||||||
.outer_margin(egui::Margin::symmetric(10.0, 10.0)),
|
.outer_margin(egui::Margin::symmetric(
|
||||||
|
self.config.outer_margin.x,
|
||||||
|
self.config.outer_margin.y,
|
||||||
|
)),
|
||||||
)
|
)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
|||||||
Reference in New Issue
Block a user