bar dropdown backend logic

This commit is contained in:
galister
2026-01-05 20:36:44 +09:00
parent b56aa1a8de
commit ac9bfc9fc4
18 changed files with 476 additions and 185 deletions

View File

@@ -30,7 +30,10 @@ use crate::{
backend::{
input::{Haptics, HoverResult, PointerHit, PointerMode},
task::{OverlayTask, PlayspaceTask, TaskType},
wayvr::{process::ProcessHandle, window::WindowHandle},
wayvr::{
process::{KillSignal, ProcessHandle},
window::WindowHandle,
},
},
ipc::ipc_server::{gen_args_vec, gen_env_vec},
state::AppState,
@@ -402,7 +405,7 @@ impl DashInterface<AppState> for DashInterfaceLive {
handle: WvrProcessHandle,
) -> anyhow::Result<()> {
let wvr_server = app.wvr_server.as_mut().unwrap();
wvr_server.terminate_process(ProcessHandle::from_packet(handle));
wvr_server.terminate_process(ProcessHandle::from_packet(handle), KillSignal::Term);
Ok(())
}

View File

@@ -1,15 +1,28 @@
use std::{collections::{HashMap}, rc::Rc, time::Duration};
use std::{collections::HashMap, rc::Rc, time::Duration};
use crate::{
app_misc,
gui::{panel::{GuiPanel, NewGuiPanelParams}, timer::GuiTimer},
gui::{
panel::{GuiPanel, NewGuiPanelParams},
timer::GuiTimer,
},
state::AppState,
subsystem::hid::XkbKeymap, windowing::{backend::OverlayEventData, window::OverlayCategory},
subsystem::hid::XkbKeymap,
windowing::{backend::OverlayEventData, window::OverlayCategory},
};
use anyhow::Context;
use glam::{FloatExt, Mat4, Vec2, vec2, vec3};
use wgui::{
animation::{Animation, AnimationEasing}, assets::AssetPath, components::button::ComponentButton, drawing::{self, Color}, event::{self, CallbackDataCommon, CallbackMetadata, EventAlterables, EventListenerKind}, layout::LayoutUpdateParams, parser::{Fetchable, ParseDocumentParams}, renderer_vk::util, taffy::{self, prelude::length}, widget::{div::WidgetDiv, rectangle::WidgetRectangle, EventResult}
animation::{Animation, AnimationEasing},
assets::AssetPath,
components::button::ComponentButton,
drawing::{self, Color},
event::{self, CallbackDataCommon, CallbackMetadata, EventAlterables, EventListenerKind},
layout::LayoutUpdateParams,
parser::{Fetchable, ParseDocumentParams},
renderer_vk::util,
taffy::{self, prelude::length},
widget::{EventResult, div::WidgetDiv, rectangle::WidgetRectangle},
};
use super::{
@@ -276,7 +289,7 @@ pub(super) fn create_keyboard_panel(
for i in 0..num_sets {
let mut params = HashMap::new();
params.insert("idx".into(), i.to_string().into());
params.insert("display".into(), (i+1).to_string().into());
params.insert("display".into(), (i + 1).to_string().into());
panel.parser_state.instantiate_template(
&doc_params,
"Set",
@@ -284,14 +297,16 @@ pub(super) fn create_keyboard_panel(
sets_root,
params,
)?;
let set_button = panel.parser_state.fetch_component_as::<ComponentButton>(&format!("set_{i}"))?;
let set_button = panel
.parser_state
.fetch_component_as::<ComponentButton>(&format!("set_{i}"))?;
if panel.state.current_set == Some(i) {
let mut com = CallbackDataCommon {
alterables: &mut alterables,
state: &panel.layout.state,
};
set_button.set_sticky_state(&mut com, true);
}
}
panel.state.set_buttons.push(set_button);
}
panel.process_custom_elems(app);
@@ -308,21 +323,34 @@ pub(super) fn create_keyboard_panel(
let (template, root) = match meta.category {
OverlayCategory::Screen => {
params.insert("display".into(), format!("{}{}", (*meta.name).chars().next().unwrap_or_default(), (*meta.name).chars().last().unwrap_or_default()).into());
params.insert(
"display".into(),
format!(
"{}{}",
(*meta.name).chars().next().unwrap_or_default(),
(*meta.name).chars().last().unwrap_or_default()
)
.into(),
);
("Screen", panels_root)
},
}
OverlayCategory::Mirror => {
params.insert("display".into(), meta.name.as_ref().into());
("Mirror", panels_root)
},
OverlayCategory::Panel => {
("Panel", panels_root)
},
}
OverlayCategory::Panel => ("Panel", panels_root),
OverlayCategory::WayVR => {
params.insert("icon".into(), meta.icon.as_ref().expect("WayVR overlay without Icon attribute!").as_ref().into());
params.insert(
"icon".into(),
meta.icon
.as_ref()
.expect("WayVR overlay without Icon attribute!")
.as_ref()
.into(),
);
("App", apps_root)
},
_ => continue
}
_ => continue,
};
params.insert("idx".into(), i.to_string().into());
@@ -334,14 +362,16 @@ pub(super) fn create_keyboard_panel(
root,
params,
)?;
let overlay_buttons = panel.parser_state.fetch_component_as::<ComponentButton>(&format!("overlay_{i}"))?;
let overlay_buttons = panel
.parser_state
.fetch_component_as::<ComponentButton>(&format!("overlay_{i}"))?;
if meta.visible {
let mut com = CallbackDataCommon {
alterables: &mut alterables,
state: &panel.layout.state,
};
overlay_buttons.set_sticky_state(&mut com, true);
}
}
panel.state.overlay_buttons.insert(meta.id, overlay_buttons);
}
panel.process_custom_elems(app);
@@ -354,8 +384,7 @@ pub(super) fn create_keyboard_panel(
let mut overlay_buttons = panel.state.overlay_buttons.clone();
for visible in &*overlays {
if let Some(btn) = overlay_buttons.remove(*visible)
{
if let Some(btn) = overlay_buttons.remove(*visible) {
btn.set_sticky_state(&mut com, true);
}
}

View File

@@ -1,24 +1,42 @@
use std::{
cell::Cell, collections::HashMap, process::{Child, Command}, rc::Rc, sync::atomic::Ordering
cell::Cell,
collections::{HashMap, HashSet},
process::{Child, Command},
rc::Rc,
sync::atomic::Ordering,
};
use crate::{
backend::input::{HoverResult, PointerHit}, gui::panel::GuiPanel, overlays::keyboard::{builder::create_keyboard_panel, layout::AltModifier}, state::AppState, subsystem::{
KEYMAP_CHANGE,
backend::input::{HoverResult, PointerHit},
gui::panel::GuiPanel,
overlays::keyboard::{builder::create_keyboard_panel, layout::AltModifier},
state::AppState,
subsystem::{
dbus::DbusConnector,
hid::{
get_keymap_wl, get_keymap_x11, KeyModifier, VirtualKey, WheelDelta, XkbKeymap, ALT, CTRL, META, SHIFT, SUPER
ALT, CTRL, KeyModifier, META, SHIFT, SUPER, VirtualKey, WheelDelta, XkbKeymap,
get_keymap_wl, get_keymap_x11,
},
}, windowing::{
backend::{FrameMeta, OverlayBackend, OverlayEventData, OverlayMeta, RenderResources, ShouldRender},
window::{OverlayCategory, OverlayWindowConfig}, OverlayID,
}, KEYMAP_CHANGE
},
windowing::{
OverlayID,
backend::{
FrameMeta, OverlayBackend, OverlayEventData, OverlayMeta, RenderResources, ShouldRender,
},
window::{OverlayCategory, OverlayWindowConfig},
},
};
use anyhow::Context;
use glam::{Affine3A, Quat, Vec3, vec3};
use regex::Regex;
use slotmap::{new_key_type, SecondaryMap, SlotMap};
use slotmap::{SecondaryMap, SlotMap, new_key_type};
use wgui::{
components::button::ComponentButton, drawing, event::{InternalStateChangeEvent, MouseButton, MouseButtonIndex}
components::button::ComponentButton,
drawing,
event::{InternalStateChangeEvent, MouseButton, MouseButtonIndex},
layout::{Layout, WidgetID},
parser::ParserState,
};
use wlx_common::overlays::{BackendAttrib, BackendAttribValue};
use wlx_common::windowing::{OverlayWindowState, Positioning};
@@ -329,7 +347,7 @@ impl KeyboardState {
overlay_buttons
},
overlay_metas: {
let mut overlay_metas= SecondaryMap::new();
let mut overlay_metas = SecondaryMap::new();
std::mem::swap(&mut overlay_metas, &mut self.overlay_metas);
overlay_metas
},

View File

@@ -28,7 +28,7 @@ use crate::{
backend::{
XrBackend,
input::{self, HoverResult},
wayvr::{self, SurfaceBufWithImage, window::WindowHandle},
wayvr::{self, SurfaceBufWithImage, process::KillSignal, window::WindowHandle},
},
graphics::{ExtentExt, Vert2Uv, upload_quad_vertices},
gui::panel::{GuiPanel, NewGuiPanelParams, OnCustomAttribFunc, button::BUTTON_EVENTS},
@@ -44,6 +44,11 @@ use crate::{
},
};
pub enum WvrCommand {
CloseWindow,
KillProcess(KillSignal),
}
const BORDER_SIZE: u32 = 5;
const BAR_SIZE: u32 = 48;
@@ -421,10 +426,24 @@ impl OverlayBackend for WvrWindowBackend {
app: &mut state::AppState,
event_data: OverlayEventData,
) -> anyhow::Result<()> {
if let OverlayEventData::IdAssigned(oid) = event_data {
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
wvr_server.overlay_added(oid, self.window);
match event_data {
OverlayEventData::IdAssigned(oid) => {
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
wvr_server.overlay_added(oid, self.window);
}
OverlayEventData::WvrCommand(WvrCommand::CloseWindow) => {
app.wvr_server.as_mut().unwrap().close_window(self.window);
}
OverlayEventData::WvrCommand(WvrCommand::KillProcess(signal)) => {
let wvr_server = app.wvr_server.as_mut().unwrap();
let Some(p) = wvr_server.wm.windows.get(&self.window) else {
return Ok(());
};
wvr_server.terminate_process(p.process, signal);
}
_ => {}
}
Ok(())
}