Skip to content

Commit

Permalink
fix: add REMOVE_HTML_FROM_WORKSPACE_NAME flag
Browse files Browse the repository at this point in the history
Signed-off-by: Enrico Stemmer <[email protected]>
  • Loading branch information
H3rmt committed Jan 8, 2025
1 parent 0b09905 commit 41f572f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<span>{}</span>`) 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
Expand Down
13 changes: 11 additions & 2 deletions src/daemon/gui/windows/init.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"<span[^>]*>(.*?)</span>")
.unwrap()
.replace_all(&workspace.name, "$1")
} else {
Cow::from(&workspace.name)
}
} else {
&id_string
Cow::from(&id_string)
};

let workspace_frame = Frame::builder()
Expand Down
5 changes: 4 additions & 1 deletion src/envs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 41f572f

Please sign in to comment.