Update Monado IPC, display brightness slider

This commit is contained in:
Aleksander
2026-01-08 20:54:43 +01:00
parent e421c39539
commit b260c6c625
12 changed files with 225 additions and 154 deletions

3
Cargo.lock generated
View File

@@ -2884,8 +2884,7 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "libmonado"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f56d8582a273a05076c57d5478faa51c39958744760938f2da770e890b43c62d"
source = "git+https://github.com/technobaboo/libmonado-rs.git?rev=26292e5b14663ee2f089f66f0851438a0c00ee67#26292e5b14663ee2f089f66f0851438a0c00ee67"
dependencies = [
"bindgen",
"cmake",

View File

@@ -28,8 +28,13 @@
<elements>
<TabTitle translation="MONADO_RUNTIME" icon="dashboard/monado.svg" />
<label translation="DISPLAY_BRIGHTNESS" />
<Slider id="slider_brightness" width="300" height="24" min_value="0" max_value="140" />
<label translation="LIST_OF_PROCESSES" />
<div id="list_parent" flex_direction="column" gap="8">
<!-- filled at runtime -->
</div>
</elements>
</layout>

View File

@@ -144,5 +144,6 @@
},
"AUTOSTART": "Automatisch beim Start ausführen",
"LAUNCH": "Starten"
}
},
"DISPLAY_BRIGHTNESS": "Bildschirmhelligkeit"
}

View File

@@ -113,6 +113,7 @@
"VOLUME": "Volume"
},
"CLOSE_WINDOW": "Close window",
"DISPLAY_BRIGHTNESS": "Display brightness",
"FAILED_TO_LAUNCH_APPLICATION": "Failed to launch a application:",
"GAME_LAUNCHED": "Game launched",
"GAME_LIST": {

View File

@@ -144,5 +144,6 @@
},
"AUTOSTART": "Ejecutar automáticamente al inicio",
"LAUNCH": "Iniciar"
}
},
"DISPLAY_BRIGHTNESS": "Brillo de la pantalla"
}

View File

@@ -144,5 +144,6 @@
},
"AUTOSTART": "起動時に自動実行",
"LAUNCH": "起動"
}
},
"DISPLAY_BRIGHTNESS": "ディスプレイの明るさ"
}

View File

@@ -144,5 +144,6 @@
},
"AUTOSTART": "Uruchom automatycznie przy starcie",
"LAUNCH": "Uruchom"
}
},
"DISPLAY_BRIGHTNESS": "Jasność wyświetlacza"
}

View File

@@ -2,7 +2,7 @@ use std::{collections::HashMap, marker::PhantomData, rc::Rc};
use wgui::{
assets::AssetPath,
components::checkbox::ComponentCheckbox,
components::{checkbox::ComponentCheckbox, slider::ComponentSlider},
globals::WguiGlobals,
layout::WidgetID,
parser::{self, Fetchable, ParseDocumentParams, ParserState},
@@ -19,6 +19,7 @@ use crate::{
enum Task {
Refresh,
FocusClient(String),
SetBrightness(f32),
}
pub struct TabMonado<T> {
@@ -46,6 +47,7 @@ impl<T> Tab<T> for TabMonado<T> {
match task {
Task::Refresh => self.refresh(frontend, data)?,
Task::FocusClient(name) => self.focus_client(frontend, data, name)?,
Task::SetBrightness(brightness) => self.set_brightness(frontend, data, brightness),
}
}
@@ -152,6 +154,22 @@ impl<T> TabMonado<T> {
self.mount_client(frontend, &client)?;
}
// get brightness
let slider_brightness = self.state.fetch_component_as::<ComponentSlider>("slider_brightness")?;
if let Some(brightness) = frontend.interface.monado_brightness_get(data) {
let mut c = frontend.layout.start_common();
slider_brightness.set_value(&mut c.common(), brightness * 100.0);
c.finish()?;
slider_brightness.on_value_changed({
let tasks = self.tasks.clone();
Box::new(move |_common, e| {
tasks.push(Task::SetBrightness(e.value / 100.0));
Ok(())
})
});
}
Ok(())
}
@@ -160,4 +178,8 @@ impl<T> TabMonado<T> {
self.tasks.push(Task::Refresh);
Ok(())
}
fn set_brightness(&mut self, frontend: &mut Frontend<T>, data: &mut T, brightness: f32) {
frontend.interface.monado_brightness_set(data, brightness);
}
}

View File

@@ -31,6 +31,8 @@ pub trait DashInterface<T> {
fn process_terminate(&mut self, data: &mut T, handle: WvrProcessHandle) -> anyhow::Result<()>;
fn monado_client_list(&mut self, data: &mut T) -> anyhow::Result<Vec<MonadoClient>>;
fn monado_client_focus(&mut self, data: &mut T, name: &str) -> anyhow::Result<()>;
fn monado_brightness_get(&mut self, data: &mut T) -> Option<f32>;
fn monado_brightness_set(&mut self, data: &mut T, brightness: f32) -> Option<()>;
fn recenter_playspace(&mut self, data: &mut T) -> anyhow::Result<()>;
fn desktop_finder<'a>(&'a mut self, data: &'a mut T) -> &'a mut DesktopFinder;
fn general_config<'a>(&'a mut self, data: &'a mut T) -> &'a mut GeneralConfig;

View File

@@ -62,6 +62,7 @@ pub struct DashInterfaceEmulated {
desktop_finder: DesktopFinder,
general_config: GeneralConfig,
monado_clients: Vec<dash_interface::MonadoClient>,
brightness: f32,
}
impl DashInterfaceEmulated {
@@ -119,6 +120,7 @@ impl DashInterfaceEmulated {
desktop_finder,
general_config,
monado_clients,
brightness: 1.0,
}
}
}
@@ -243,4 +245,13 @@ impl DashInterface<()> for DashInterfaceEmulated {
}
Ok(())
}
fn monado_brightness_get(&mut self, _: &mut ()) -> Option<f32> {
Some(self.brightness)
}
fn monado_brightness_set(&mut self, _: &mut (), brightness: f32) -> Option<()> {
self.brightness = brightness;
Some(())
}
}

View File

@@ -57,7 +57,7 @@ interprocess = { version = "2.2.3" }
json = { version = "0.12.4", optional = true }
json5 = "1.3.0"
libc = "0.2.178"
libmonado = { version = "1.3.2", optional = true }
libmonado = { git = "https://github.com/technobaboo/libmonado-rs.git", rev = "26292e5b14663ee2f089f66f0851438a0c00ee67", optional = true }
log-panics = { version = "2.1.0", features = ["with-backtrace"] }
mint = "0.5.9"
openxr = { git = "https://github.com/Ralith/openxrs", rev = "d0afdd3365bc1e14de28f6a3a21f457e788a702e", features = [

View File

@@ -487,10 +487,37 @@ impl DashInterface<AppState> for DashInterfaceLive {
app.monado_init();
Ok(())
}
fn monado_brightness_get(&mut self, app: &mut AppState) -> Option<f32> {
let Some(monado) = &mut app.monado else {
return None;
};
monado_get_brightness(monado)
}
fn monado_brightness_set(&mut self, app: &mut AppState, brightness: f32) -> Option<()> {
let Some(monado) = &mut app.monado else {
return None;
};
monado_set_brightness(monado, brightness).ok()
}
}
const CLIENT_NAME_BLACKLIST: [&str; 2] = ["wlx-overlay-s", "libmonado"];
fn monado_get_brightness(monado: &mut libmonado::Monado) -> Option<f32> {
let device = monado.device_from_role(libmonado::DeviceRole::Head).ok()?;
device.brightness().ok()
}
fn monado_set_brightness(monado: &mut libmonado::Monado, brightness: f32) -> anyhow::Result<()> {
let device = monado.device_from_role(libmonado::DeviceRole::Head)?;
device.set_brightness(brightness, false)?;
Ok(())
}
fn monado_list_clients_filtered(
monado: &mut libmonado::Monado,
) -> anyhow::Result<Vec<libmonado::Client<'_>>> {