diff --git a/Cargo.lock b/Cargo.lock index 6d64b97..ca94b75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1058,6 +1058,7 @@ dependencies = [ "notify-rust", "rand", "random_color", + "regex", "semver", "serde", "svg", diff --git a/Cargo.toml b/Cargo.toml index f3ddbcc..c6850f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ rand = { version = "0.8.5" } semver = "1.0.24" bincode = { version = "1.3.3" } serde = { version = "1.0.217", features = ["derive"] } +regex = "1.11.1" gtk4 = { version = "0.9.5", default-features = false } gtk4-layer-shell = { version = "0.4.0" } diff --git a/README.md b/README.md index 5959088..f7ee2e3 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,7 @@ bind = $mod $reverse, $key, exec, hyprswitch gui --mod-key $mod --key $key --clo - `ICON_SIZE` i32 [default: 512]: Argument passed to the theme.lookup_icon function (Determines the resolution of the Icon, as it gets scaled to the windowsize regardless of the resolution of the icon) - `SHOW_DEFAULT_ICON` bool [default: false]: Show a icon if no icon was found (`application-x-executable` doesn't scale good) +- `REMOVE_HTML_FROM_WORKSPACE_NAME` bool [default: true]: Remove HTML tag (currently only `{}`) from workspace name - `SHOW_LAUNCHER` bool [default: true]: Show a Launcher Icon in the GUI when using default `--close` mode - `LAUNCHER_MAX_ITEMS` i32 [default: 5]: Maximum number of items in the Launcher - `DEFAULT_TERMINAL` string [default: ""]: Terminal to use for launching terminal applications, e.g., `alacritty`. (If diff --git a/src/daemon/gui/windows/init.rs b/src/daemon/gui/windows/init.rs index 31e28c7..b716df0 100644 --- a/src/daemon/gui/windows/init.rs +++ b/src/daemon/gui/windows/init.rs @@ -1,9 +1,12 @@ use crate::daemon::gui::icon::set_icon; use crate::daemon::gui::windows::click::{click_client, click_workspace}; use crate::daemon::gui::MonitorData; +use crate::envs::REMOVE_HTML_FROM_WORKSPACE_NAME; use crate::{ClientData, Share, WorkspaceData}; use gtk4::{pango, prelude::*, Fixed, Frame, Image, Label, Overflow, Overlay}; use hyprland::shared::{Address, WorkspaceId}; +use regex::Regex; +use std::borrow::Cow; fn scale(value: i16, size_factor: f64) -> i32 { (value as f64 / 30.0 * size_factor) as i32 @@ -37,9 +40,15 @@ pub fn init_windows( let id_string = wid.to_string(); let title = if show_title && !workspace.name.trim().is_empty() { - &workspace.name + if *REMOVE_HTML_FROM_WORKSPACE_NAME { + Regex::new(r"]*>(.*?)") + .unwrap() + .replace_all(&workspace.name, "$1") + } else { + Cow::from(&workspace.name) + } } else { - &id_string + Cow::from(&id_string) }; let workspace_frame = Frame::builder() diff --git a/src/envs.rs b/src/envs.rs index 5b9f870..e08b18e 100644 --- a/src/envs.rs +++ b/src/envs.rs @@ -29,8 +29,11 @@ lazy_static! { pub static ref LOG_MODULE_PATH: bool = env::var("LOG_MODULE_PATH") .map(|s| s.parse().expect("Failed to parse LOG_MODULE_PATH")) .unwrap_or(false); + pub static ref REMOVE_HTML_FROM_WORKSPACE_NAME: bool = env::var("REMOVE_HTML_FROM_WORKSPACE_NAME") + .map(|s| s.parse().expect("Failed to parse REMOVE_HTML_FROM_WORKSPACE_NAME")) + .unwrap_or(true); } pub fn envvar_dump() { - debug!("ENV dump: ICON_SIZE: {}, SHOW_DEFAULT_ICON: {}, SHOW_LAUNCHER: {}, LAUNCHER_MAX_ITEMS: {}, DEFAULT_TERMINAL: {:?}, ASYNC_SOCKET: {:?}, LOG_MODULE_PATH: {:?}", *ICON_SIZE, *SHOW_DEFAULT_ICON, *SHOW_LAUNCHER, *LAUNCHER_MAX_ITEMS, *DEFAULT_TERMINAL, *ASYNC_SOCKET, *LOG_MODULE_PATH); + debug!("ENV dump: ICON_SIZE: {}, SHOW_DEFAULT_ICON: {}, SHOW_LAUNCHER: {}, LAUNCHER_MAX_ITEMS: {}, DEFAULT_TERMINAL: {:?}, ASYNC_SOCKET: {:?}, LOG_MODULE_PATH: {:?}, REMOVE_HTML_FROM_WORKSPACE_NAME: {:?}", *ICON_SIZE, *SHOW_DEFAULT_ICON, *SHOW_LAUNCHER, *LAUNCHER_MAX_ITEMS, *DEFAULT_TERMINAL, *ASYNC_SOCKET, *LOG_MODULE_PATH, *REMOVE_HTML_FROM_WORKSPACE_NAME); }