From df46c58244697dac16c20006e8fbb2fcf1d8aa9f Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Sat, 2 Sep 2023 00:05:08 +0200 Subject: [PATCH] Add config for number of workspaces Adds NumWorkspaces config, https://github.com/scorpion-26/gBar/issues/45 The WorkspaceSymbols syntax was also upgraded to use maps, since the -n was hardcoded to query for numbers from 1-9, which is now no longer correct. The old syntax for WorkspaceSymbols still works, but only for ws 1-9 --- data/config | 8 ++++++-- module.nix | 2 +- src/Bar.cpp | 3 ++- src/Config.cpp | 17 ++++++++++++++--- src/Config.h | 12 ++++++------ src/System.cpp | 8 +++++--- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/data/config b/data/config index d4554dd..66e07cd 100644 --- a/data/config +++ b/data/config @@ -22,8 +22,9 @@ ExitCommand: killall Hyprland # The folder, where the battery sensors reside BatteryFolder: /sys/class/power_supply/BAT1 -# Overrides the icon of the nth (in this case the first) workspace -# WorkspaceSymbol-1:  +# Overrides the icon of the nth (in this case the first) workspace. +# Please note the missing space between "," and the symbol. Adding a space here adds it to the bar too! +#WorkspaceSymbol: 1, # The default symbol for the workspaces DefaultWorkspaceSymbol:  @@ -34,6 +35,9 @@ WorkspaceScrollOnMonitor: true # When true: Scroll up -> Next workspace instead of previous workspace. Analogous with scroll down WorkspaceScrollInvert: false +# Number of workspaces to display. Displayed workspace IDs are 1-n (Default: 1-9) +NumWorkspaces: 9 + # Use Hyprland IPC instead of the ext_workspace protocol for workspace polling. # Hyprland IPC is *slightly* less performant (+0.1% one core), but way less bug prone, # since the protocol is not as feature complete as Hyprland IPC. diff --git a/module.nix b/module.nix index 4c1a0f6..fd55eca 100644 --- a/module.nix +++ b/module.nix @@ -233,7 +233,7 @@ in { in attrsets.mapAttrs (name: value: name + ": " + (anyToString value)) (filterAttrs (n2: v2: (isInt v2 || isString v2 || isBool v2))x); extractLists = l: - (imap1 (i: v: "WorkspaceSymbol-${toString i}: " + v) l.WorkspaceSymbols) ++ + (imap1 (i: v: "WorkspaceSymbol: ${toString i}," + v) l.WorkspaceSymbols) ++ (mapAttrsToList (n: v: "SNIIconSize: ${n}, ${toString v}") l.SNIIconSize) ++ (mapAttrsToList (n: v: "SNIIconPaddingTop: ${n}, ${toString v}") l.SNIIconPaddingTop); diff --git a/src/Bar.cpp b/src/Bar.cpp index 883a179..f33e977 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -261,7 +261,7 @@ namespace Bar } #ifdef WITH_WORKSPACES - static std::array workspaces; + static std::vector workspaces; TimerResult UpdateWorkspaces(Box&) { System::PollWorkspaces((uint32_t)monitorID, workspaces.size()); @@ -765,6 +765,7 @@ namespace Bar box->SetOrientation(Utils::GetOrientation()); Utils::SetTransform(*box, {-1, true, Alignment::Left, 12, 0}); { + DynCtx::workspaces.resize(Config::Get().numWorkspaces); for (size_t i = 0; i < DynCtx::workspaces.size(); i++) { auto workspace = Widget::Create