Merge pull request #4395 from pol-rivero/workspace-taskbar-improvements
[hyprland/workspaces] Taskbar improvements
This commit is contained in:
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,6 +268,17 @@ void Workspace::update(const std::string &workspace_icon) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Workspace::isEmpty() const {
|
||||
auto ignore_list = m_workspaceManager.getIgnoredWindows();
|
||||
if (ignore_list.empty()) {
|
||||
return m_windows == 0;
|
||||
}
|
||||
// If there are windows but they are all ignored, consider the workspace empty
|
||||
return std::all_of(
|
||||
m_windowMap.begin(), m_windowMap.end(),
|
||||
[this, &ignore_list](const auto &window_repr) { return shouldSkipWindow(window_repr); });
|
||||
}
|
||||
|
||||
void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
for (auto child : m_content.get_children()) {
|
||||
if (child != &m_labelBefore) {
|
||||
@ -259,9 +287,9 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
}
|
||||
|
||||
bool isFirst = true;
|
||||
for (const auto &window_repr : m_windowMap) {
|
||||
auto processWindow = [&](const WindowRepr &window_repr) {
|
||||
if (shouldSkipWindow(window_repr)) {
|
||||
continue;
|
||||
return; // skip
|
||||
}
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
@ -270,6 +298,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
m_content.pack_start(*windowSeparator, false, false);
|
||||
windowSeparator->show();
|
||||
}
|
||||
|
||||
auto window_box = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL);
|
||||
window_box->set_tooltip_text(window_repr.window_title);
|
||||
window_box->get_style_context()->add_class("taskbar-window");
|
||||
@ -307,6 +336,16 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
|
||||
m_content.pack_start(*event_box, true, false);
|
||||
event_box->show_all();
|
||||
};
|
||||
|
||||
if (m_workspaceManager.taskbarReverseDirection()) {
|
||||
for (auto it = m_windowMap.rbegin(); it != m_windowMap.rend(); ++it) {
|
||||
processWindow(*it);
|
||||
}
|
||||
} else {
|
||||
for (const auto &window_repr : m_windowMap) {
|
||||
processWindow(window_repr);
|
||||
}
|
||||
}
|
||||
|
||||
auto formatAfter = m_workspaceManager.formatAfter();
|
||||
|
@ -728,6 +728,7 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
||||
|
||||
populateBoolConfig(workspaceTaskbar, "enable", m_enableTaskbar);
|
||||
populateBoolConfig(workspaceTaskbar, "update-active-window", m_updateActiveWindow);
|
||||
populateBoolConfig(workspaceTaskbar, "reverse-direction", m_taskbarReverseDirection);
|
||||
|
||||
if (workspaceTaskbar["format"].isString()) {
|
||||
/* The user defined a format string, use it */
|
||||
@ -775,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