From cfb733de09bb4e573819fdba98be0348a11333b0 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 20 Sep 2025 15:28:23 +0900 Subject: [PATCH] sorry about monster commit --- Cargo.lock | 29 +- wgui/src/parser/mod.rs | 39 ++ wgui/src/widget/label.rs | 19 +- wlx-capture/src/frame.rs | 2 +- wlx-capture/src/wayland.rs | 34 +- wlx-capture/src/wlr_dmabuf.rs | 4 +- wlx-capture/src/wlr_screencopy.rs | 4 +- wlx-overlay-s/Cargo.toml | 2 +- wlx-overlay-s/src/assets/gui/watch.xml | 47 +- wlx-overlay-s/src/backend/common.rs | 28 +- wlx-overlay-s/src/backend/mod.rs | 1 + wlx-overlay-s/src/backend/openvr/mod.rs | 20 +- wlx-overlay-s/src/backend/openxr/mod.rs | 8 +- wlx-overlay-s/src/backend/overlay.rs | 4 +- wlx-overlay-s/src/backend/set.rs | 9 + wlx-overlay-s/src/graphics/mod.rs | 25 +- wlx-overlay-s/src/gui/README.md | 110 +++++ wlx-overlay-s/src/gui/panel/button.rs | 160 +++++++ wlx-overlay-s/src/gui/panel/helper.rs | 53 +++ wlx-overlay-s/src/gui/panel/label.rs | 434 ++++++++++++++++++ .../src/gui/{panel.rs => panel/mod.rs} | 108 ++++- wlx-overlay-s/src/overlays/anchor.rs | 2 +- wlx-overlay-s/src/overlays/bar.rs | 2 +- wlx-overlay-s/src/overlays/screen/backend.rs | 32 +- wlx-overlay-s/src/overlays/screen/capture.rs | 15 +- wlx-overlay-s/src/overlays/screen/mod.rs | 44 +- wlx-overlay-s/src/overlays/screen/wl.rs | 8 +- wlx-overlay-s/src/overlays/screen/x11.rs | 7 +- wlx-overlay-s/src/overlays/tooltip.rs | 98 ++++ wlx-overlay-s/src/overlays/watch.rs | 127 ++--- wlx-overlay-s/src/state.rs | 17 +- wlx-overlay-s/src/subsystem/input.rs | 5 + 32 files changed, 1208 insertions(+), 289 deletions(-) create mode 100644 wlx-overlay-s/src/backend/set.rs create mode 100644 wlx-overlay-s/src/gui/README.md create mode 100644 wlx-overlay-s/src/gui/panel/button.rs create mode 100644 wlx-overlay-s/src/gui/panel/helper.rs create mode 100644 wlx-overlay-s/src/gui/panel/label.rs rename wlx-overlay-s/src/gui/{panel.rs => panel/mod.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index c5fff4d..72e071e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -659,9 +659,9 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.72.0" +version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f72209734318d0b619a5e0f5129918b848c416e122a3c4ce054e03cb87b726f" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ "bitflags 2.9.1", "cexpr", @@ -1130,7 +1130,7 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceec7a6067e62d6f931a2baf6f3a751f4a892595bcec1461a3c94ef9949864b6" dependencies = [ - "bindgen 0.72.0", + "bindgen 0.72.1", ] [[package]] @@ -2740,9 +2740,9 @@ dependencies = [ [[package]] name = "mach2" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" dependencies = [ "libc", ] @@ -6213,23 +6213,6 @@ dependencies = [ "wayland-protocols", ] -[[package]] -name = "wlx-capture" -version = "0.5.3" -source = "git+https://github.com/galister/wlx-capture?tag=v0.5.3#4479bd4bdd2b570aec9692e55b513ec7c0a17e7f" -dependencies = [ - "ashpd", - "drm-fourcc", - "idmap", - "libc", - "log", - "pipewire", - "rxscreen", - "smithay-client-toolkit", - "wayland-client", - "wayland-protocols", -] - [[package]] name = "wlx-overlay-s" version = "25.4.2" @@ -6283,7 +6266,7 @@ dependencies = [ "wayvr_ipc", "wgui", "winit", - "wlx-capture 0.5.3 (git+https://github.com/galister/wlx-capture?tag=v0.5.3)", + "wlx-capture", "xcb", "xdg 3.0.0", "xkbcommon 0.8.0", diff --git a/wgui/src/parser/mod.rs b/wgui/src/parser/mod.rs index f6ff47a..7f1b080 100644 --- a/wgui/src/parser/mod.rs +++ b/wgui/src/parser/mod.rs @@ -766,6 +766,45 @@ impl CustomAttribsInfo<'_> { None } + + pub fn to_owned(&self) -> CustomAttribsInfoOwned { + CustomAttribsInfoOwned { + parent_id: self.parent_id, + widget_id: self.widget_id, + pairs: self + .pairs + .iter() + .map(|p| CustomAttribPairOwned { + attrib: p.attrib.to_string(), + value: p.value.to_string(), + }) + .collect(), + } + } +} + +pub struct CustomAttribPairOwned { + pub attrib: String, // without _ at the beginning + pub value: String, +} + +pub struct CustomAttribsInfoOwned { + pub parent_id: WidgetID, + pub widget_id: WidgetID, + pub pairs: Vec, +} + +impl CustomAttribsInfoOwned { + pub fn get_value(&self, attrib_name: &str) -> Option<&str> { + // O(n) search, these pairs won't be problematically big anyways + for pair in self.pairs.iter() { + if pair.attrib == attrib_name { + return Some(pair.value.as_str()); + } + } + + None + } } pub type OnCustomAttribsFunc = Box; diff --git a/wgui/src/widget/label.rs b/wgui/src/widget/label.rs index 709313a..f67ae47 100644 --- a/wgui/src/widget/label.rs +++ b/wgui/src/widget/label.rs @@ -1,6 +1,6 @@ use std::{cell::RefCell, rc::Rc}; -use cosmic_text::{Attrs, Buffer, Metrics, Shaping, Wrap}; +use cosmic_text::{Attrs, AttrsList, Buffer, Metrics, Shaping, Wrap}; use slotmap::Key; use taffy::AvailableSpace; @@ -10,7 +10,7 @@ use crate::{ globals::Globals, i18n::{I18n, Translation}, layout::WidgetID, - renderer_vk::text::{FONT_SYSTEM, TextStyle}, + renderer_vk::text::{TextStyle, FONT_SYSTEM}, }; use super::{WidgetObj, WidgetState}; @@ -84,12 +84,27 @@ impl WidgetLabel { true } + fn update_attrs(&mut self) { + let attrs = Attrs::from(&self.params.style); + for line in self.buffer.borrow_mut().lines.iter_mut() { + line.set_attrs_list(AttrsList::new(&attrs)); + } + } + // set text and check if it needs to be re-rendered/re-layouted pub fn set_text(&mut self, common: &mut CallbackDataCommon, translation: Translation) { if self.set_text_simple(&mut common.i18n(), translation) { common.mark_widget_dirty(self.id); } } + + pub fn set_color(&mut self, common: &mut CallbackDataCommon, color: drawing::Color, apply_to_existing_text: bool) { + self.params.style.color = Some(color); + if apply_to_existing_text { + self.update_attrs(); + common.mark_widget_dirty(self.id); + } + } } impl WidgetObj for WidgetLabel { diff --git a/wlx-capture/src/frame.rs b/wlx-capture/src/frame.rs index d90d8c4..7dfe5bd 100644 --- a/wlx-capture/src/frame.rs +++ b/wlx-capture/src/frame.rs @@ -59,7 +59,7 @@ pub enum WlxFrame { MemPtr(MemPtrFrame), } -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Copy, Default, PartialEq)] pub enum Transform { #[default] Undefined, diff --git a/wlx-capture/src/wayland.rs b/wlx-capture/src/wayland.rs index 3a60ecf..cb366ba 100644 --- a/wlx-capture/src/wayland.rs +++ b/wlx-capture/src/wayland.rs @@ -19,17 +19,19 @@ use smithay_client_toolkit::reexports::{ pub use wayland_client; use wayland_client::{ - Connection, Dispatch, EventQueue, Proxy, QueueHandle, backend::WaylandError, - globals::{GlobalList, GlobalListContents, registry_queue_init}, + globals::{registry_queue_init, GlobalList, GlobalListContents}, protocol::{ wl_output::{self, Transform, WlOutput}, wl_registry::{self, WlRegistry}, wl_seat::WlSeat, wl_shm::WlShm, }, + Connection, Dispatch, EventQueue, Proxy, QueueHandle, }; +use crate::frame; + pub enum OutputChangeEvent { /// New output has been created. Create(u32), @@ -50,7 +52,7 @@ pub struct WlxOutput { pub size: (i32, i32), pub logical_pos: (i32, i32), pub logical_size: (i32, i32), - pub transform: Transform, + pub transform: frame::Transform, done: bool, } @@ -125,7 +127,7 @@ impl WlxClient { size: (0, 0), logical_pos: (0, 0), logical_size: (0, 0), - transform: Transform::Normal, + transform: frame::Transform::Normal, done: false, }; @@ -192,17 +194,17 @@ impl WlxClient { } } -pub(crate) fn wl_transform_to_frame_transform(transform: Transform) -> crate::frame::Transform { +fn wl_transform_to_frame_transform(transform: Transform) -> frame::Transform { match transform { - Transform::Normal => crate::frame::Transform::Normal, - Transform::_90 => crate::frame::Transform::Rotated90, - Transform::_180 => crate::frame::Transform::Rotated180, - Transform::_270 => crate::frame::Transform::Rotated270, - Transform::Flipped => crate::frame::Transform::Flipped, - Transform::Flipped90 => crate::frame::Transform::Flipped90, - Transform::Flipped180 => crate::frame::Transform::Flipped180, - Transform::Flipped270 => crate::frame::Transform::Flipped270, - _ => crate::frame::Transform::Undefined, + Transform::Normal => frame::Transform::Normal, + Transform::_90 => frame::Transform::Rotated90, + Transform::_180 => frame::Transform::Rotated180, + Transform::_270 => frame::Transform::Rotated270, + Transform::Flipped => frame::Transform::Flipped, + Transform::Flipped90 => frame::Transform::Flipped90, + Transform::Flipped180 => frame::Transform::Flipped180, + Transform::Flipped270 => frame::Transform::Flipped270, + _ => frame::Transform::Undefined, } } @@ -327,8 +329,8 @@ impl Dispatch for WlxClient { if let Some(output) = state.outputs.get_mut(*data) { let transform = transform.into_result().unwrap_or(Transform::Normal); let old_transform = output.transform; - output.transform = transform; - if output.done && old_transform != transform { + output.transform = wl_transform_to_frame_transform(transform); + if output.done && old_transform != output.transform { log::info!( "{}: Transform changed {:?} -> {:?}", output.name, diff --git a/wlx-capture/src/wlr_dmabuf.rs b/wlx-capture/src/wlr_dmabuf.rs index f614519..8e23836 100644 --- a/wlx-capture/src/wlr_dmabuf.rs +++ b/wlx-capture/src/wlr_dmabuf.rs @@ -11,7 +11,7 @@ use wayland_client::{Connection, QueueHandle, Dispatch, Proxy}; use crate::{ frame::{DmabufFrame, DrmFormat, FramePlane, WlxFrame}, - wayland::{wl_transform_to_frame_transform, WlxClient}, + wayland::WlxClient, WlxCapture, }; @@ -146,7 +146,7 @@ fn request_dmabuf_frame( return client; }; - let transform = wl_transform_to_frame_transform(output.transform); + let transform = output.transform; let (tx, rx) = mpsc::sync_channel::(16); let name = output.name.clone(); diff --git a/wlx-capture/src/wlr_screencopy.rs b/wlx-capture/src/wlr_screencopy.rs index e5155e0..0e6477b 100644 --- a/wlx-capture/src/wlr_screencopy.rs +++ b/wlx-capture/src/wlr_screencopy.rs @@ -21,7 +21,7 @@ use crate::{ DrmFormat, FourCC, FrameFormat, FramePlane, MemFdFrame, WlxFrame, DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888, }, - wayland::{wl_transform_to_frame_transform, WlxClient}, + wayland::WlxClient, WlxCapture, }; @@ -194,7 +194,7 @@ where return client; }; - let transform = wl_transform_to_frame_transform(output.transform); + let transform = output.transform; let (tx, rx) = mpsc::sync_channel::(16); diff --git a/wlx-overlay-s/Cargo.toml b/wlx-overlay-s/Cargo.toml index 17a2d0f..223442c 100644 --- a/wlx-overlay-s/Cargo.toml +++ b/wlx-overlay-s/Cargo.toml @@ -58,7 +58,7 @@ smallvec = "1.13.2" strum = { version = "0.27.1", features = ["derive"] } sysinfo = { version = "0.35" } thiserror = "2.0" -wlx-capture = { git = "https://github.com/galister/wlx-capture", tag = "v0.5.3", default-features = false } +wlx-capture = { path = "../wlx-capture" } libmonado = { version = "1.3.2", optional = true } winit = { version = "0.30", optional = true } xdg = "3.0" diff --git a/wlx-overlay-s/src/assets/gui/watch.xml b/wlx-overlay-s/src/assets/gui/watch.xml index d9cc5e4..9ae2183 100644 --- a/wlx-overlay-s/src/assets/gui/watch.xml +++ b/wlx-overlay-s/src/assets/gui/watch.xml @@ -14,22 +14,26 @@ + +
- +
@@ -39,38 +43,33 @@
-
-