mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 11:12:49 +00:00
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
This commit is contained in:
parent
5c2ac6fa08
commit
df46c58244
6 changed files with 34 additions and 16 deletions
|
@ -22,8 +22,9 @@ ExitCommand: killall Hyprland
|
||||||
# The folder, where the battery sensors reside
|
# The folder, where the battery sensors reside
|
||||||
BatteryFolder: /sys/class/power_supply/BAT1
|
BatteryFolder: /sys/class/power_supply/BAT1
|
||||||
|
|
||||||
# Overrides the icon of the nth (in this case the first) workspace
|
# Overrides the icon of the nth (in this case the first) workspace.
|
||||||
# WorkspaceSymbol-1:
|
# 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
|
# The default symbol for the workspaces
|
||||||
DefaultWorkspaceSymbol:
|
DefaultWorkspaceSymbol:
|
||||||
|
@ -34,6 +35,9 @@ WorkspaceScrollOnMonitor: true
|
||||||
# When true: Scroll up -> Next workspace instead of previous workspace. Analogous with scroll down
|
# When true: Scroll up -> Next workspace instead of previous workspace. Analogous with scroll down
|
||||||
WorkspaceScrollInvert: false
|
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.
|
# 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,
|
# 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.
|
# since the protocol is not as feature complete as Hyprland IPC.
|
||||||
|
|
|
@ -233,7 +233,7 @@ in {
|
||||||
in attrsets.mapAttrs (name: value:
|
in attrsets.mapAttrs (name: value:
|
||||||
name + ": " + (anyToString value)) (filterAttrs (n2: v2: (isInt v2 || isString v2 || isBool v2))x);
|
name + ": " + (anyToString value)) (filterAttrs (n2: v2: (isInt v2 || isString v2 || isBool v2))x);
|
||||||
extractLists = l:
|
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: "SNIIconSize: ${n}, ${toString v}") l.SNIIconSize) ++
|
||||||
(mapAttrsToList (n: v: "SNIIconPaddingTop: ${n}, ${toString v}") l.SNIIconPaddingTop);
|
(mapAttrsToList (n: v: "SNIIconPaddingTop: ${n}, ${toString v}") l.SNIIconPaddingTop);
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ namespace Bar
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_WORKSPACES
|
#ifdef WITH_WORKSPACES
|
||||||
static std::array<Button*, 9> workspaces;
|
static std::vector<Button*> workspaces;
|
||||||
TimerResult UpdateWorkspaces(Box&)
|
TimerResult UpdateWorkspaces(Box&)
|
||||||
{
|
{
|
||||||
System::PollWorkspaces((uint32_t)monitorID, workspaces.size());
|
System::PollWorkspaces((uint32_t)monitorID, workspaces.size());
|
||||||
|
@ -765,6 +765,7 @@ namespace Bar
|
||||||
box->SetOrientation(Utils::GetOrientation());
|
box->SetOrientation(Utils::GetOrientation());
|
||||||
Utils::SetTransform(*box, {-1, true, Alignment::Left, 12, 0});
|
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++)
|
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
|
||||||
{
|
{
|
||||||
auto workspace = Widget::Create<Button>();
|
auto workspace = Widget::Create<Button>();
|
||||||
|
|
|
@ -194,11 +194,23 @@ void Config::Load()
|
||||||
AddConfigVar("DateTimeStyle", config.dateTimeStyle, lineView, foundProperty);
|
AddConfigVar("DateTimeStyle", config.dateTimeStyle, lineView, foundProperty);
|
||||||
AddConfigVar("DateTimeLocale", config.dateTimeLocale, lineView, foundProperty);
|
AddConfigVar("DateTimeLocale", config.dateTimeLocale, lineView, foundProperty);
|
||||||
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
|
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
|
||||||
|
|
||||||
|
// Legacy syntax
|
||||||
for (int i = 1; i < 10; i++)
|
for (int i = 1; i < 10; i++)
|
||||||
{
|
{
|
||||||
// Subtract 1 to index from 1 to 9 rather than 0 to 8
|
// Subtract 1 to index from 1 to 9 rather than 0 to 8
|
||||||
AddConfigVar("WorkspaceSymbol-" + std::to_string(i), config.workspaceSymbols[i - 1], lineView, foundProperty);
|
std::string symbol;
|
||||||
|
bool hasFoundProperty = foundProperty;
|
||||||
|
AddConfigVar("WorkspaceSymbol-" + std::to_string(i), symbol, lineView, foundProperty);
|
||||||
|
if (foundProperty && !hasFoundProperty)
|
||||||
|
{
|
||||||
|
config.workspaceSymbols[i] = symbol;
|
||||||
|
LOG("Warning: Legacy notation for WorkspaceSymbol used.");
|
||||||
|
LOG(" Please consider switching to \"WorkspaceSymbol: [number], [symbol]!\"");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Modern map syntax
|
||||||
|
AddConfigVar("WorkspaceSymbol", config.workspaceSymbols, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
|
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
|
||||||
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
|
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
|
||||||
|
@ -216,9 +228,8 @@ void Config::Load()
|
||||||
AddConfigVar("MaxDownloadBytes", config.maxDownloadBytes, lineView, foundProperty);
|
AddConfigVar("MaxDownloadBytes", config.maxDownloadBytes, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("CheckUpdateInterval", config.checkUpdateInterval, lineView, foundProperty);
|
AddConfigVar("CheckUpdateInterval", config.checkUpdateInterval, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("TimeSpace", config.timeSpace, lineView, foundProperty);
|
AddConfigVar("TimeSpace", config.timeSpace, lineView, foundProperty);
|
||||||
|
AddConfigVar("NumWorkspaces", config.numWorkspaces, lineView, foundProperty);
|
||||||
AddConfigVar("AudioScrollSpeed", config.audioScrollSpeed, lineView, foundProperty);
|
AddConfigVar("AudioScrollSpeed", config.audioScrollSpeed, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("AudioMinVolume", config.audioMinVolume, lineView, foundProperty);
|
AddConfigVar("AudioMinVolume", config.audioMinVolume, lineView, foundProperty);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
@ -13,7 +14,7 @@ public:
|
||||||
std::string lockCommand = ""; // idk, no standard way of doing this.
|
std::string lockCommand = ""; // idk, no standard way of doing this.
|
||||||
std::string exitCommand = ""; // idk, no standard way of doing this.
|
std::string exitCommand = ""; // idk, no standard way of doing this.
|
||||||
std::string batteryFolder = ""; // this can be BAT0, BAT1, etc. Usually in /sys/class/power_supply
|
std::string batteryFolder = ""; // this can be BAT0, BAT1, etc. Usually in /sys/class/power_supply
|
||||||
std::vector<std::string> workspaceSymbols = std::vector<std::string>(9, "");
|
std::map<uint32_t, std::string> workspaceSymbols;
|
||||||
std::string defaultWorkspaceSymbol = "";
|
std::string defaultWorkspaceSymbol = "";
|
||||||
std::string dateTimeStyle = "%a %D - %H:%M:%S %Z"; // A sane default
|
std::string dateTimeStyle = "%a %D - %H:%M:%S %Z"; // A sane default
|
||||||
std::string dateTimeLocale = ""; // use system locale
|
std::string dateTimeLocale = ""; // use system locale
|
||||||
|
@ -40,10 +41,9 @@ public:
|
||||||
uint32_t maxDownloadBytes = 10 * 1024 * 1024; // 10 MiB Top limit of the network widgets download. Everything above it is considered "over"
|
uint32_t maxDownloadBytes = 10 * 1024 * 1024; // 10 MiB Top limit of the network widgets download. Everything above it is considered "over"
|
||||||
|
|
||||||
uint32_t audioScrollSpeed = 5; // 5% each scroll
|
uint32_t audioScrollSpeed = 5; // 5% each scroll
|
||||||
|
|
||||||
uint32_t checkUpdateInterval = 5 * 60; // Interval to run the "checkPackagesCommand". In seconds
|
uint32_t checkUpdateInterval = 5 * 60; // Interval to run the "checkPackagesCommand". In seconds
|
||||||
|
|
||||||
uint32_t timeSpace = 300; // How much time should be reserved for the time widget.
|
uint32_t timeSpace = 300; // How much time should be reserved for the time widget.
|
||||||
|
uint32_t numWorkspaces = 9; // How many workspaces to display
|
||||||
|
|
||||||
char location = 'T'; // The Location of the bar. Can be L,R,T,B
|
char location = 'T'; // The Location of the bar. Can be L,R,T,B
|
||||||
|
|
||||||
|
|
|
@ -478,18 +478,20 @@ namespace System
|
||||||
}
|
}
|
||||||
std::string GetWorkspaceSymbol(int index)
|
std::string GetWorkspaceSymbol(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index > 9)
|
if (index < 0 || index > (int)Config::Get().numWorkspaces)
|
||||||
{
|
{
|
||||||
LOG("Workspace Symbol Index Out Of Bounds: " + std::to_string(index));
|
LOG("Workspace Symbol Index Out Of Bounds: " + std::to_string(index));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config::Get().workspaceSymbols[index].empty())
|
// workspaceSymbols is from [1-n], wsidx is from [0-n[
|
||||||
|
auto it = Config::Get().workspaceSymbols.find(index + 1);
|
||||||
|
if (it == Config::Get().workspaceSymbols.end())
|
||||||
{
|
{
|
||||||
return Config::Get().defaultWorkspaceSymbol + " ";
|
return Config::Get().defaultWorkspaceSymbol + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return Config::Get().workspaceSymbols[index] + " ";
|
return it->second + " ";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue