Implement "active-window-position"
This commit is contained in:
@ -55,6 +55,9 @@ class Workspaces : public AModule, public EventHandler {
|
||||
auto onClickWindow() const -> std::string { return m_onClickWindow; }
|
||||
auto getIgnoredWindows() const -> std::vector<std::regex> { return m_ignoreWindows; }
|
||||
|
||||
enum class ActiveWindowPosition { NONE, FIRST, LAST };
|
||||
auto activeWindowPosition() const -> ActiveWindowPosition { return m_activeWindowPosition; }
|
||||
|
||||
std::string getRewrite(std::string window_class, std::string window_title);
|
||||
std::string& getWindowSeparator() { return m_formatWindowSeparator; }
|
||||
bool isWorkspaceIgnored(std::string const& workspace_name);
|
||||
@ -185,6 +188,13 @@ class Workspaces : public AModule, public EventHandler {
|
||||
int m_taskbarIconSize = 16;
|
||||
Gtk::Orientation m_taskbarOrientation = Gtk::ORIENTATION_HORIZONTAL;
|
||||
bool m_taskbarReverseDirection = false;
|
||||
util::EnumParser<ActiveWindowPosition> m_activeWindowEnumParser;
|
||||
ActiveWindowPosition m_activeWindowPosition = ActiveWindowPosition::NONE;
|
||||
std::map<std::string, ActiveWindowPosition> m_activeWindowPositionMap = {
|
||||
{"NONE", ActiveWindowPosition::NONE},
|
||||
{"FIRST", ActiveWindowPosition::FIRST},
|
||||
{"LAST", ActiveWindowPosition::LAST},
|
||||
};
|
||||
std::string m_onClickWindow;
|
||||
std::string m_currentActiveWindowAddress;
|
||||
|
||||
|
@ -60,6 +60,11 @@ This setting is ignored if *workspace-taskbar.enable* is set to true.
|
||||
default: false ++
|
||||
If true, the taskbar windows will be added in reverse order (right to left if orientation is horizontal, bottom to top if vertical).
|
||||
|
||||
*active-window-position*: ++
|
||||
typeof: "none" | "first" | "last" ++
|
||||
default: "none" ++
|
||||
If set to "first", the active window will be moved at the beginning of the taskbar. If set to "last", it will be moved at the end. It will only work if *update-active-window* is set to true.
|
||||
|
||||
*format*: ++
|
||||
typeof: string ++
|
||||
default: {icon} ++
|
||||
|
@ -104,8 +104,25 @@ void Workspace::initializeWindowMap(const Json::Value &clients_data) {
|
||||
}
|
||||
|
||||
void Workspace::setActiveWindow(WindowAddress const &addr) {
|
||||
for (auto &window : m_windowMap) {
|
||||
window.setActive(window.address == addr);
|
||||
std::optional<long> activeIdx;
|
||||
for (size_t i = 0; i < m_windowMap.size(); ++i) {
|
||||
auto &window = m_windowMap[i];
|
||||
bool isActive = (window.address == addr);
|
||||
window.setActive(isActive);
|
||||
if (isActive) {
|
||||
activeIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
auto activeWindowPos = m_workspaceManager.activeWindowPosition();
|
||||
if (activeIdx.has_value() && activeWindowPos != Workspaces::ActiveWindowPosition::NONE) {
|
||||
auto window = std::move(m_windowMap[*activeIdx]);
|
||||
m_windowMap.erase(m_windowMap.begin() + *activeIdx);
|
||||
if (activeWindowPos == Workspaces::ActiveWindowPosition::FIRST) {
|
||||
m_windowMap.insert(m_windowMap.begin(), std::move(window));
|
||||
} else if (activeWindowPos == Workspaces::ActiveWindowPosition::LAST) {
|
||||
m_windowMap.emplace_back(std::move(window));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -776,6 +776,18 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (workspaceTaskbar["active-window-position"].isString()) {
|
||||
auto posStr = workspaceTaskbar["active-window-position"].asString();
|
||||
try {
|
||||
m_activeWindowPosition =
|
||||
m_activeWindowEnumParser.parseStringToEnum(posStr, m_activeWindowPositionMap);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
spdlog::warn(
|
||||
"Invalid string representation for active-window-position. Falling back to 'none'.");
|
||||
m_activeWindowPosition = ActiveWindowPosition::NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::registerOrphanWindow(WindowCreationPayload create_window_payload) {
|
||||
|
@ -41,6 +41,7 @@ EnumType EnumParser<EnumType>::parseStringToEnum(const std::string& str,
|
||||
// Explicit instantiations for specific EnumType types you intend to use
|
||||
// Add explicit instantiations for all relevant EnumType types
|
||||
template struct EnumParser<modules::hyprland::Workspaces::SortMethod>;
|
||||
template struct EnumParser<modules::hyprland::Workspaces::ActiveWindowPosition>;
|
||||
template struct EnumParser<util::KillSignalAction>;
|
||||
|
||||
} // namespace waybar::util
|
||||
|
Reference in New Issue
Block a user