monado task switcher: use client id instead of name

This commit is contained in:
galister 2026-08-02 13:00:25 +09:00
parent 4c918b0aaf
commit 75154d8375
4 changed files with 16 additions and 17 deletions

View File

@ -51,7 +51,7 @@ enum Task {
// `ProcessList` tab
ProcessListRefresh,
ProcessListFocusClient(String),
ProcessListFocusClient(i64),
// `DebugTimings` tab
DebugTimingsRefreshSessionList,
@ -157,9 +157,9 @@ impl<T> Tab<T> for TabMonado<T> {
process_list.refresh(frontend, data, &self.tasks)?;
}
}
Task::ProcessListFocusClient(client_name) => {
Task::ProcessListFocusClient(client_id) => {
if let Subtab::ProcessList(process_list) = &mut self.subtab {
process_list.focus_client(frontend, data, client_name, &self.tasks)?;
process_list.focus_client(frontend, data, client_id, &self.tasks)?;
}
}
Task::DebugTimingsRefreshSessionList => {
@ -676,10 +676,10 @@ impl SubtabProcessList {
let checkbox = state_cell.fetch_component_as::<ComponentCheckbox>("checkbox")?;
checkbox.on_toggle({
let tasks = tasks.clone();
let client_name = client.name.clone();
let client_id = client.id;
Box::new(move |_common, e| {
if e.checked {
tasks.push(Task::ProcessListFocusClient(client_name.clone()));
tasks.push(Task::ProcessListFocusClient(client_id));
}
Ok(())
})
@ -694,10 +694,10 @@ impl SubtabProcessList {
&mut self,
frontend: &mut Frontend<T>,
data: &mut T,
name: String,
client_id: i64,
tasks: &Tasks<Task>,
) -> anyhow::Result<()> {
frontend.interface.monado_client_focus(data, &name)?;
frontend.interface.monado_client_focus(data, client_id)?;
tasks.push(Task::ProcessListRefresh);
Ok(())
}

View File

@ -620,12 +620,12 @@ impl DashInterface<AppState> for DashInterfaceLive {
}
#[cfg(feature = "openxr")]
fn monado_client_focus(&mut self, app: &mut AppState, name: &str) -> anyhow::Result<()> {
fn monado_client_focus(&mut self, app: &mut AppState, client_id: i64) -> anyhow::Result<()> {
let Some(monado) = &mut app.monado_state else {
return Ok(()); // no monado available
};
monado_client_focus(&mut monado.ipc, name)
monado_client_focus(&mut monado.ipc, client_id)
}
#[cfg(feature = "openxr")]
@ -736,7 +736,7 @@ impl DashInterface<AppState> for DashInterfaceLive {
anyhow::bail!("Not supported in this build.")
}
#[cfg(not(feature = "openxr"))]
fn monado_client_focus(&mut self, _: &mut AppState, _: &str) -> anyhow::Result<()> {
fn monado_client_focus(&mut self, _: &mut AppState, _: i64) -> anyhow::Result<()> {
anyhow::bail!("Not supported in this build.")
}
#[cfg(not(feature = "openxr"))]
@ -804,16 +804,15 @@ fn monado_list_clients_filtered(
}
#[cfg(feature = "openxr")]
fn monado_client_focus(monado: &mut libmonado::Monado, name: &str) -> anyhow::Result<()> {
fn monado_client_focus(monado: &mut libmonado::Monado, client_id: i64) -> anyhow::Result<()> {
let clients = monado_list_clients_filtered(monado)?;
for mut client in clients {
let client_name = client.name()?;
if client_name != name {
if client.id() != client_id as u32 {
continue;
}
log::info!("Monado focus set to {client_name}");
log::info!("Monado focus set to {client_id}");
client.set_primary()?;
return Ok(());
}

View File

@ -80,7 +80,7 @@ pub trait DashInterface<T> {
fn process_list(&mut self, data: &mut T) -> anyhow::Result<Vec<WvrProcess>>;
fn process_terminate(&mut self, data: &mut T, handle: WvrProcessHandle) -> anyhow::Result<()>;
fn monado_client_list(&mut self, data: &mut T, filtered: bool) -> anyhow::Result<Vec<MonadoClient>>;
fn monado_client_focus(&mut self, data: &mut T, name: &str) -> anyhow::Result<()>;
fn monado_client_focus(&mut self, data: &mut T, client_id: i64) -> 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 monado_metrics_set_enabled(&mut self, data: &mut T, enabled: bool) -> bool;

View File

@ -251,14 +251,14 @@ impl DashInterface<()> for DashInterfaceEmulated {
Ok(self.monado_clients.clone())
}
fn monado_client_focus(&mut self, _data: &mut (), name: &str) -> anyhow::Result<()> {
fn monado_client_focus(&mut self, _data: &mut (), client_id: i64) -> anyhow::Result<()> {
for client in self.monado_clients.iter_mut() {
client.is_focused = false;
client.is_active = false;
client.is_primary = false;
}
if let Some(client) = self.monado_clients.iter_mut().find(|m| m.name == name) {
if let Some(client) = self.monado_clients.iter_mut().find(|m| m.id == client_id) {
client.is_active = true;
client.is_focused = true;
client.is_primary = true;