Add max-windows option to hyprland/workspaces
This commit is contained in:
@@ -56,6 +56,7 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
auto taskbarReverseDirection() const -> bool { return m_taskbarReverseDirection; }
|
auto taskbarReverseDirection() const -> bool { return m_taskbarReverseDirection; }
|
||||||
auto onClickWindow() const -> std::string { return m_onClickWindow; }
|
auto onClickWindow() const -> std::string { return m_onClickWindow; }
|
||||||
auto getIgnoredWindows() const -> std::vector<std::regex> { return m_ignoreWindows; }
|
auto getIgnoredWindows() const -> std::vector<std::regex> { return m_ignoreWindows; }
|
||||||
|
auto maxWindows() const -> int { return m_maxWindows; }
|
||||||
|
|
||||||
enum class ActiveWindowPosition { NONE, FIRST, LAST };
|
enum class ActiveWindowPosition { NONE, FIRST, LAST };
|
||||||
auto activeWindowPosition() const -> ActiveWindowPosition { return m_activeWindowPosition; }
|
auto activeWindowPosition() const -> ActiveWindowPosition { return m_activeWindowPosition; }
|
||||||
@@ -89,6 +90,7 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
|
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
|
||||||
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
|
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
|
||||||
auto populateWindowRewriteConfig(const Json::Value& config) -> void;
|
auto populateWindowRewriteConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateMaxWindowsConfig(const Json::Value& config) -> void;
|
||||||
auto populateWorkspaceTaskbarConfig(const Json::Value& config) -> void;
|
auto populateWorkspaceTaskbarConfig(const Json::Value& config) -> void;
|
||||||
|
|
||||||
void registerIpc();
|
void registerIpc();
|
||||||
@@ -202,6 +204,7 @@ class Workspaces : public AModule, public EventHandler {
|
|||||||
};
|
};
|
||||||
std::string m_onClickWindow;
|
std::string m_onClickWindow;
|
||||||
std::string m_currentActiveWindowAddress;
|
std::string m_currentActiveWindowAddress;
|
||||||
|
int m_maxWindows = 0;
|
||||||
|
|
||||||
std::vector<std::regex> m_ignoreWorkspaces;
|
std::vector<std::regex> m_ignoreWorkspaces;
|
||||||
std::vector<std::regex> m_ignoreWindows;
|
std::vector<std::regex> m_ignoreWindows;
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ This setting is ignored if *workspace-taskbar.enable* is set to true.
|
|||||||
- {button} Pressed button number, see https://api.gtkd.org/gdk.c.types.GdkEventButton.button.html. ++
|
- {button} Pressed button number, see https://api.gtkd.org/gdk.c.types.GdkEventButton.button.html. ++
|
||||||
See https://github.com/Alexays/Waybar/wiki/Module:-Hyprland#workspace-taskbars-example for a full example.
|
See https://github.com/Alexays/Waybar/wiki/Module:-Hyprland#workspace-taskbars-example for a full example.
|
||||||
|
|
||||||
|
*max-windows*: ++
|
||||||
|
typeof: int ++
|
||||||
|
default: 0 (unlimited) ++
|
||||||
|
Maximum number of windows to show per workspace. When set, newest windows beyond the limit are not shown. Set to 0 for unlimited windows.
|
||||||
|
|
||||||
*show-special*: ++
|
*show-special*: ++
|
||||||
typeof: bool ++
|
typeof: bool ++
|
||||||
default: false ++
|
default: false ++
|
||||||
|
|||||||
@@ -247,13 +247,14 @@ void Workspace::update(const std::string& workspace_icon) {
|
|||||||
auto windowSeparator = m_workspaceManager.getWindowSeparator();
|
auto windowSeparator = m_workspaceManager.getWindowSeparator();
|
||||||
|
|
||||||
bool isNotFirst = false;
|
bool isNotFirst = false;
|
||||||
|
auto end_it = m_workspaceManager.maxWindows() == 0 ? m_windowMap.end() : m_windowMap.begin() + m_workspaceManager.maxWindows();
|
||||||
|
|
||||||
for (const auto& window_repr : m_windowMap) {
|
for (auto it = m_windowMap.begin(); it != end_it; ++it) {
|
||||||
if (isNotFirst) {
|
if (isNotFirst) {
|
||||||
windows.append(windowSeparator);
|
windows.append(windowSeparator);
|
||||||
}
|
}
|
||||||
isNotFirst = true;
|
isNotFirst = true;
|
||||||
windows.append(window_repr.repr_rewrite);
|
windows.append(it->repr_rewrite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,12 +340,16 @@ void Workspace::updateTaskbar(const std::string& workspace_icon) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (m_workspaceManager.taskbarReverseDirection()) {
|
if (m_workspaceManager.taskbarReverseDirection()) {
|
||||||
for (auto it = m_windowMap.rbegin(); it != m_windowMap.rend(); ++it) {
|
auto rend_it = m_workspaceManager.maxWindows() == 0 ? m_windowMap.rend() : m_windowMap.rbegin() + m_workspaceManager.maxWindows();
|
||||||
|
|
||||||
|
for (auto it = m_windowMap.rbegin(); it != rend_it; ++it) {
|
||||||
processWindow(*it);
|
processWindow(*it);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const auto& window_repr : m_windowMap) {
|
auto end_it = m_workspaceManager.maxWindows() == 0 ? m_windowMap.end() : m_windowMap.begin() + m_workspaceManager.maxWindows();
|
||||||
processWindow(window_repr);
|
|
||||||
|
for (auto it = m_windowMap.begin(); it != end_it; ++it) {
|
||||||
|
processWindow(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -665,6 +665,7 @@ auto Workspaces::parseConfig(const Json::Value& config) -> void {
|
|||||||
populateIgnoreWorkspacesConfig(config);
|
populateIgnoreWorkspacesConfig(config);
|
||||||
populateFormatWindowSeparatorConfig(config);
|
populateFormatWindowSeparatorConfig(config);
|
||||||
populateWindowRewriteConfig(config);
|
populateWindowRewriteConfig(config);
|
||||||
|
populateMaxWindowsConfig(config);
|
||||||
|
|
||||||
if (withWindows) {
|
if (withWindows) {
|
||||||
populateWorkspaceTaskbarConfig(config);
|
populateWorkspaceTaskbarConfig(config);
|
||||||
@@ -746,6 +747,15 @@ auto Workspaces::populateWindowRewriteConfig(const Json::Value& config) -> void
|
|||||||
[this](std::string& window_rule) { return windowRewritePriorityFunction(window_rule); });
|
[this](std::string& window_rule) { return windowRewritePriorityFunction(window_rule); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Workspaces::populateMaxWindowsConfig(const Json::Value& config) -> void {
|
||||||
|
if (config["max-windows"].isInt()) {
|
||||||
|
m_maxWindows = config["max-windows"].asInt();
|
||||||
|
if (m_maxWindows < 0) {
|
||||||
|
m_maxWindows = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value& config) -> void {
|
auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value& config) -> void {
|
||||||
const auto& workspaceTaskbar = config["workspace-taskbar"];
|
const auto& workspaceTaskbar = config["workspace-taskbar"];
|
||||||
if (!workspaceTaskbar.isObject()) {
|
if (!workspaceTaskbar.isObject()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user