Add widget: LeftWM Window Title
- Display the title of the current window - Only for LeftWM - Use `leftwm-state -q`
This commit is contained in:
parent
6ac513f301
commit
c284df88a1
49
src/widgets/leftwmdata.rs
Normal file
49
src/widgets/leftwmdata.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
use crate::TopBar;
|
||||||
|
use slint::{ComponentHandle, Timer, TimerMode, SharedString};
|
||||||
|
use std::process::Command;
|
||||||
|
use std::time::Duration;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
// Minimal JSON structure
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct LeftState {
|
||||||
|
window_title: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run leftwm-state and return JSON output (or empty string)
|
||||||
|
fn get_leftwm_state() -> String {
|
||||||
|
Command::new("leftwm-state")
|
||||||
|
.arg("-q")
|
||||||
|
.output()
|
||||||
|
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse only the window title
|
||||||
|
fn parse_window_title(json: &str) -> String {
|
||||||
|
serde_json::from_str::<LeftState>(json)
|
||||||
|
.map(|v| v.window_title)
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main updater loop
|
||||||
|
fn start_leftwm_updater(ui: &TopBar) {
|
||||||
|
let weak = ui.as_weak();
|
||||||
|
|
||||||
|
let timer = Box::leak(Box::new(Timer::default()));
|
||||||
|
|
||||||
|
// Poll every ~300 ms (fast enough for responsiveness)
|
||||||
|
timer.start(TimerMode::Repeated, Duration::from_millis(300), move || {
|
||||||
|
if let Some(ui) = weak.upgrade() {
|
||||||
|
let state = get_leftwm_state();
|
||||||
|
let title = parse_window_title(&state);
|
||||||
|
// Send to UI
|
||||||
|
ui.set_current_window_title(SharedString::from(title));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public entry
|
||||||
|
pub fn install(ui: &TopBar) {
|
||||||
|
start_leftwm_updater(ui);
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ mod timewidget;
|
|||||||
mod volumewidget;
|
mod volumewidget;
|
||||||
mod weatherwidget;
|
mod weatherwidget;
|
||||||
mod wifiwidget;
|
mod wifiwidget;
|
||||||
|
mod leftwmdata;
|
||||||
|
|
||||||
use crate::TopBar;
|
use crate::TopBar;
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ pub fn install_callbacks(ui: &TopBar) {
|
|||||||
brightnesswidget::install(ui);
|
brightnesswidget::install(ui);
|
||||||
wifiwidget::install(ui);
|
wifiwidget::install(ui);
|
||||||
weatherwidget::install(ui);
|
weatherwidget::install(ui);
|
||||||
|
leftwmdata::install(ui);
|
||||||
|
|
||||||
// In the future:
|
// In the future:
|
||||||
// notifwidget::install(ui);
|
// notifwidget::install(ui);
|
||||||
|
|||||||
@ -9,7 +9,9 @@ export component TopBar inherits Window {
|
|||||||
in property<int> bar_height;
|
in property<int> bar_height;
|
||||||
in property<int> def_font_size;
|
in property<int> def_font_size;
|
||||||
in property<string> def_font_fam;
|
in property<string> def_font_fam;
|
||||||
background: #00000000;
|
|
||||||
|
// Right side
|
||||||
|
in property<string> current_window_title;
|
||||||
|
|
||||||
// Time widget
|
// Time widget
|
||||||
in-out property <string> time_text;
|
in-out property <string> time_text;
|
||||||
@ -92,6 +94,7 @@ export component TopBar inherits Window {
|
|||||||
y: 0px;
|
y: 0px;
|
||||||
default-font-family: def_font_fam;
|
default-font-family: def_font_fam;
|
||||||
default-font-size: def_font_size *1px;
|
default-font-size: def_font_size *1px;
|
||||||
|
background: #00000000;
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
x: 0px;
|
x: 0px;
|
||||||
@ -110,8 +113,21 @@ export component TopBar inherits Window {
|
|||||||
|
|
||||||
// Left side
|
// Left side
|
||||||
Rectangle {
|
Rectangle {
|
||||||
background: #79a9af7b;
|
|
||||||
width: parent.width/3;
|
width: parent.width/3;
|
||||||
|
//background: #46adbb79;
|
||||||
|
HorizontalLayout {
|
||||||
|
alignment: start; // Left-align
|
||||||
|
padding-left: 4px;
|
||||||
|
padding-right: 4px;
|
||||||
|
|
||||||
|
// CUrrent Window Title
|
||||||
|
Text {
|
||||||
|
text: root.current_window_title;
|
||||||
|
vertical-alignment: center;
|
||||||
|
wrap: no-wrap;
|
||||||
|
overflow: elide;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Middle
|
// Middle
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user