Merge remote-tracking branch 'origin/master' into pr-4694
# Conflicts: # src/modules/hyprland/workspace.cpp
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include <glibmm/main.h>
|
||||
#include <json/value.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -10,10 +13,37 @@
|
||||
#include "util/command.hpp"
|
||||
#include "util/icon_loader.hpp"
|
||||
|
||||
namespace {
|
||||
constexpr std::string_view kCssClassPrefix = "ws-";
|
||||
|
||||
// Convert a workspace name to a valid CSS class name.
|
||||
// Lowercases, replaces non-alphanumeric runs with single hyphens,
|
||||
// and prefixes digit-leading names (CSS classes can't start with a digit).
|
||||
std::string sanitizeCssClass(const std::string& name) {
|
||||
std::string result;
|
||||
result.reserve(name.size() + kCssClassPrefix.size());
|
||||
for (auto c : name) {
|
||||
auto uc = static_cast<unsigned char>(c);
|
||||
if (std::isalnum(uc)) {
|
||||
result += static_cast<char>(std::tolower(uc));
|
||||
} else if (!result.empty() && result.back() != '-') {
|
||||
result += '-';
|
||||
}
|
||||
}
|
||||
if (!result.empty() && result.back() == '-') {
|
||||
result.pop_back();
|
||||
}
|
||||
if (!result.empty() && std::isdigit(static_cast<unsigned char>(result.front()))) {
|
||||
result.insert(0, kCssClassPrefix);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager,
|
||||
const Json::Value &clients_data)
|
||||
Workspace::Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager,
|
||||
const Json::Value& clients_data)
|
||||
: m_workspaceManager(workspace_manager),
|
||||
m_id(workspace_data["id"].asInt()),
|
||||
m_name(workspace_data["name"].asString()),
|
||||
@@ -31,6 +61,11 @@ Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_ma
|
||||
}
|
||||
|
||||
m_button.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||
m_button.add_events(Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
|
||||
|
||||
m_button.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Workspace::handleEnter));
|
||||
m_button.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Workspace::handleLeave));
|
||||
|
||||
m_button.signal_button_press_event().connect(sigc::mem_fun(*this, &Workspace::handleClicked),
|
||||
false);
|
||||
|
||||
@@ -46,8 +81,14 @@ Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_ma
|
||||
initializeWindowMap(clients_data);
|
||||
}
|
||||
|
||||
void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext> &context, bool condition,
|
||||
const std::string &class_name) {
|
||||
Workspace::~Workspace() {
|
||||
// Disconnect the hover-check timeout so it can't fire on this destroyed
|
||||
// instance (Workspaces are removed at runtime while a check may be armed).
|
||||
stopHoverCheck();
|
||||
}
|
||||
|
||||
void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext>& context, bool condition,
|
||||
const std::string& class_name) {
|
||||
if (condition) {
|
||||
context->add_class(class_name);
|
||||
} else {
|
||||
@@ -55,9 +96,9 @@ void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext> &context, bool condi
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const &addr) {
|
||||
std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const& addr) {
|
||||
auto it = std::ranges::find_if(m_windowMap,
|
||||
[&addr](const auto &window) { return window.address == addr; });
|
||||
[&addr](const auto& window) { return window.address == addr; });
|
||||
// If the vector contains the address, remove it and return the window representation
|
||||
if (it != m_windowMap.end()) {
|
||||
WindowRepr windowRepr = *it;
|
||||
@@ -67,47 +108,141 @@ std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const &addr) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool Workspace::handleClicked(GdkEventButton *bt) const {
|
||||
bool Workspace::pointerInsideButton() {
|
||||
auto display = Gdk::Display::get_default();
|
||||
if (!display) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto seat = display->get_default_seat();
|
||||
if (!seat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pointer = seat->get_pointer();
|
||||
if (!pointer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Glib::RefPtr<Gdk::Screen> screen;
|
||||
int pointerRootX = 0;
|
||||
int pointerRootY = 0;
|
||||
|
||||
pointer->get_position(screen, pointerRootX, pointerRootY);
|
||||
|
||||
Gtk::Widget* toplevel = m_button.get_toplevel();
|
||||
if (toplevel == nullptr || !toplevel->get_window()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int buttonX = 0;
|
||||
int buttonY = 0;
|
||||
|
||||
if (!m_button.translate_coordinates(*toplevel, 0, 0, buttonX, buttonY)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int windowRootX = 0;
|
||||
int windowRootY = 0;
|
||||
toplevel->get_window()->get_root_origin(windowRootX, windowRootY);
|
||||
|
||||
const auto allocation = m_button.get_allocation();
|
||||
|
||||
const int buttonRootX = windowRootX + buttonX;
|
||||
const int buttonRootY = windowRootY + buttonY;
|
||||
const int buttonWidth = allocation.get_width();
|
||||
const int buttonHeight = allocation.get_height();
|
||||
|
||||
return pointerRootX >= buttonRootX && pointerRootY >= buttonRootY &&
|
||||
pointerRootX < buttonRootX + buttonWidth && pointerRootY < buttonRootY + buttonHeight;
|
||||
}
|
||||
|
||||
bool Workspace::syncHoverClass() {
|
||||
auto styleContext = m_button.get_style_context();
|
||||
|
||||
if (pointerInsideButton()) {
|
||||
styleContext->add_class("workspace-hover");
|
||||
return true;
|
||||
}
|
||||
|
||||
styleContext->remove_class("workspace-hover");
|
||||
stopHoverCheck();
|
||||
return false;
|
||||
}
|
||||
|
||||
void Workspace::startHoverCheck() {
|
||||
if (m_hoverCheckConnection.connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_hoverCheckConnection =
|
||||
Glib::signal_timeout().connect(sigc::mem_fun(*this, &Workspace::syncHoverClass), 50);
|
||||
}
|
||||
|
||||
void Workspace::stopHoverCheck() {
|
||||
if (m_hoverCheckConnection.connected()) {
|
||||
m_hoverCheckConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
bool Workspace::handleEnter(GdkEventCrossing* /*event*/) {
|
||||
m_button.get_style_context()->add_class("workspace-hover");
|
||||
startHoverCheck();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Workspace::handleLeave(GdkEventCrossing* /*event*/) {
|
||||
/*
|
||||
* Do not remove immediately.
|
||||
* Workspace taskbar children can fire misleading leave events while the
|
||||
* pointer is still visually inside the workspace button.
|
||||
*
|
||||
* The polling check will remove the class once the pointer really leaves.
|
||||
*/
|
||||
startHoverCheck();
|
||||
return false;
|
||||
}
|
||||
bool Workspace::handleClicked(GdkEventButton* bt) const {
|
||||
if (bt->type == GDK_BUTTON_PRESS) {
|
||||
try {
|
||||
if (id() > 0) { // normal
|
||||
if (m_workspaceManager.moveToMonitor()) {
|
||||
m_ipc.getSocket1Reply("dispatch focusworkspaceoncurrentmonitor " + std::to_string(id()));
|
||||
IPC::dispatch("focusworkspaceoncurrentmonitor", std::to_string(id()));
|
||||
} else {
|
||||
m_ipc.getSocket1Reply("dispatch workspace " + std::to_string(id()));
|
||||
IPC::dispatch("workspace", std::to_string(id()));
|
||||
}
|
||||
} else if (!isSpecial()) { // named (this includes persistent)
|
||||
if (m_workspaceManager.moveToMonitor()) {
|
||||
m_ipc.getSocket1Reply("dispatch focusworkspaceoncurrentmonitor name:" + name());
|
||||
IPC::dispatch("focusworkspaceoncurrentmonitor", "name:" + name());
|
||||
} else {
|
||||
m_ipc.getSocket1Reply("dispatch workspace name:" + name());
|
||||
IPC::dispatch("workspace", "name:" + name());
|
||||
}
|
||||
} else if (id() != -99) { // named special
|
||||
m_ipc.getSocket1Reply("dispatch togglespecialworkspace " + name());
|
||||
IPC::dispatch("togglespecialworkspace", name());
|
||||
} else { // special
|
||||
m_ipc.getSocket1Reply("dispatch togglespecialworkspace");
|
||||
IPC::dispatch("togglespecialworkspace", "");
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Failed to dispatch workspace: {}", e.what());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Workspace::initializeWindowMap(const Json::Value &clients_data) {
|
||||
void Workspace::initializeWindowMap(const Json::Value& clients_data) {
|
||||
m_windowMap.clear();
|
||||
for (auto client : clients_data) {
|
||||
for (const auto& client : clients_data) {
|
||||
if (client["workspace"]["id"].asInt() == id()) {
|
||||
insertWindow({client});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Workspace::setActiveWindow(WindowAddress const &addr) {
|
||||
void Workspace::setActiveWindow(WindowAddress const& addr) {
|
||||
std::optional<long> activeIdx;
|
||||
for (size_t i = 0; i < m_windowMap.size(); ++i) {
|
||||
auto &window = m_windowMap[i];
|
||||
auto& window = m_windowMap[i];
|
||||
bool isActive = (window.address == addr);
|
||||
window.setActive(isActive);
|
||||
if (isActive) {
|
||||
@@ -116,7 +251,10 @@ void Workspace::setActiveWindow(WindowAddress const &addr) {
|
||||
}
|
||||
|
||||
auto activeWindowPos = m_workspaceManager.activeWindowPosition();
|
||||
if (activeIdx.has_value() && activeWindowPos != Workspaces::ActiveWindowPosition::NONE) {
|
||||
const bool has_active_window =
|
||||
activeIdx.has_value() && activeWindowPos != Workspaces::ActiveWindowPosition::NONE;
|
||||
|
||||
if (has_active_window) {
|
||||
auto window = std::move(m_windowMap[*activeIdx]);
|
||||
m_windowMap.erase(m_windowMap.begin() + *activeIdx);
|
||||
if (activeWindowPos == Workspaces::ActiveWindowPosition::FIRST) {
|
||||
@@ -131,10 +269,12 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) {
|
||||
if (!create_window_payload.isEmpty(m_workspaceManager)) {
|
||||
auto repr = create_window_payload.repr(m_workspaceManager);
|
||||
|
||||
if (!repr.empty() || m_workspaceManager.enableTaskbar()) {
|
||||
const bool should_display = !repr.empty() || m_workspaceManager.enableTaskbar();
|
||||
|
||||
if (should_display) {
|
||||
auto addr = create_window_payload.getAddress();
|
||||
auto it = std::ranges::find_if(
|
||||
m_windowMap, [&addr](const auto &window) { return window.address == addr; });
|
||||
m_windowMap, [&addr](const auto& window) { return window.address == addr; });
|
||||
// If the vector contains the address, update the window representation, otherwise insert it
|
||||
if (it != m_windowMap.end()) {
|
||||
*it = repr;
|
||||
@@ -143,9 +283,9 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payload) {
|
||||
bool Workspace::onWindowOpened(WindowCreationPayload const& create_window_payload) {
|
||||
if (create_window_payload.getWorkspaceName() == name()) {
|
||||
insertWindow(create_window_payload);
|
||||
return true;
|
||||
@@ -153,16 +293,37 @@ bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payloa
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map) {
|
||||
std::string& Workspace::selectIcon(std::map<std::string, std::string>& icons_map) {
|
||||
spdlog::trace("Selecting icon for workspace {}", name());
|
||||
if (isUrgent()) {
|
||||
auto urgentNamedIconIt = icons_map.find("urgent:" + name());
|
||||
if (urgentNamedIconIt != icons_map.end()) {
|
||||
return urgentNamedIconIt->second;
|
||||
}
|
||||
|
||||
auto urgentIconIt = icons_map.find("urgent");
|
||||
if (urgentIconIt != icons_map.end()) {
|
||||
return urgentIconIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (isActive() && isSpecial()) {
|
||||
auto activeIconIt = icons_map.find("active:" + name());
|
||||
if (activeIconIt != icons_map.end()) {
|
||||
return activeIconIt->second;
|
||||
}
|
||||
auto namedIconIt = icons_map.find(name());
|
||||
if (namedIconIt != icons_map.end()) {
|
||||
return namedIconIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (isActive()) {
|
||||
auto activeNamedIconIt = icons_map.find("active:" + name());
|
||||
if (activeNamedIconIt != icons_map.end()) {
|
||||
return activeNamedIconIt->second;
|
||||
}
|
||||
|
||||
auto activeIconIt = icons_map.find("active");
|
||||
if (activeIconIt != icons_map.end()) {
|
||||
return activeIconIt->second;
|
||||
@@ -170,6 +331,11 @@ std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map
|
||||
}
|
||||
|
||||
if (isSpecial()) {
|
||||
auto specialNamedIconIt = icons_map.find("special:" + name());
|
||||
if (specialNamedIconIt != icons_map.end()) {
|
||||
return specialNamedIconIt->second;
|
||||
}
|
||||
|
||||
auto specialIconIt = icons_map.find("special");
|
||||
if (specialIconIt != icons_map.end()) {
|
||||
return specialIconIt->second;
|
||||
@@ -210,12 +376,21 @@ std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Workspace::update(const std::string &workspace_icon) {
|
||||
void Workspace::update(const std::string& workspace_icon) {
|
||||
if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) {
|
||||
m_button.hide();
|
||||
return;
|
||||
}
|
||||
// clang-format off
|
||||
if (this->m_workspaceManager.hideActive() && \
|
||||
this->isActive() && \
|
||||
!this->isPersistent() && \
|
||||
!this->isSpecial()) {
|
||||
// clang-format on
|
||||
m_button.hide();
|
||||
return;
|
||||
}
|
||||
// clang-format off
|
||||
if (this->m_workspaceManager.activeOnly() && \
|
||||
!this->isActive() && \
|
||||
!this->isPersistent() && \
|
||||
@@ -235,26 +410,79 @@ void Workspace::update(const std::string &workspace_icon) {
|
||||
auto styleContext = m_button.get_style_context();
|
||||
addOrRemoveClass(styleContext, isActive(), "active");
|
||||
addOrRemoveClass(styleContext, isSpecial(), "special");
|
||||
addOrRemoveClass(styleContext, isSpecial(), name());
|
||||
addOrRemoveClass(styleContext, isEmpty(), "empty");
|
||||
addOrRemoveClass(styleContext, isPersistent(), "persistent");
|
||||
addOrRemoveClass(styleContext, isUrgent(), "urgent");
|
||||
addOrRemoveClass(styleContext, isVisible(), "visible");
|
||||
addOrRemoveClass(styleContext, m_workspaceManager.getBarOutput() == output(), "hosting-monitor");
|
||||
|
||||
// Add workspace name as CSS class for per-workspace styling
|
||||
if (!m_prevNameClass.empty()) {
|
||||
styleContext->remove_class(m_prevNameClass);
|
||||
m_prevNameClass.clear();
|
||||
}
|
||||
auto nameClass = sanitizeCssClass(name());
|
||||
if (!nameClass.empty()) {
|
||||
styleContext->add_class(nameClass);
|
||||
m_prevNameClass = nameClass;
|
||||
}
|
||||
|
||||
std::string windows;
|
||||
// Optimization: The {windows} substitution string is only possible if the taskbar is disabled, no
|
||||
// need to compute this if enableTaskbar() is true
|
||||
if (!m_workspaceManager.enableTaskbar()) {
|
||||
auto windowSeparator = m_workspaceManager.getWindowSeparator();
|
||||
auto groupThreshold = m_workspaceManager.windowRewriteGroupThreshold();
|
||||
|
||||
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) {
|
||||
if (isNotFirst) {
|
||||
windows.append(windowSeparator);
|
||||
if (groupThreshold > 0) {
|
||||
// Build ordered counts of each unique icon (including singular ones when threshold set to 1)
|
||||
std::vector<std::pair<std::string, int>> iconCounts;
|
||||
for (auto it = m_windowMap.begin(); it != end_it; ++it) {
|
||||
const auto& window_repr = *it;
|
||||
auto found = std::ranges::find_if(
|
||||
iconCounts, [&](const auto& p) { return p.first == window_repr.repr_rewrite; });
|
||||
if (found != iconCounts.end()) {
|
||||
found->second++;
|
||||
} else {
|
||||
iconCounts.emplace_back(window_repr.repr_rewrite, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Format the group string
|
||||
auto groupFormat = m_workspaceManager.getWindowRewriteGroupFormat();
|
||||
bool isNotFirst = false;
|
||||
for (const auto& [icon, count] : iconCounts) {
|
||||
if (count >= groupThreshold) {
|
||||
if (isNotFirst) windows.append(windowSeparator);
|
||||
isNotFirst = true;
|
||||
try {
|
||||
windows.append(fmt::format(fmt::runtime(groupFormat), fmt::arg("icon", icon),
|
||||
fmt::arg("count", count)));
|
||||
} catch (const fmt::format_error& e) {
|
||||
spdlog::warn("Formatting window-rewrite-group-format error: {}", e.what());
|
||||
windows.append(icon);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (isNotFirst) windows.append(windowSeparator);
|
||||
isNotFirst = true;
|
||||
windows.append(icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not grouping icons
|
||||
bool isNotFirst = false;
|
||||
for (auto it = m_windowMap.begin(); it != end_it; ++it) {
|
||||
if (isNotFirst) windows.append(windowSeparator);
|
||||
isNotFirst = true;
|
||||
windows.append(it->repr_rewrite);
|
||||
}
|
||||
isNotFirst = true;
|
||||
windows.append(window_repr.repr_rewrite);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,16 +499,18 @@ void Workspace::update(const std::string &workspace_icon) {
|
||||
|
||||
bool Workspace::isEmpty() const {
|
||||
auto ignore_list = m_workspaceManager.getIgnoredWindows();
|
||||
if (ignore_list.empty()) {
|
||||
const bool no_ignore_rules = ignore_list.empty();
|
||||
|
||||
if (no_ignore_rules) {
|
||||
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); });
|
||||
[this, &ignore_list](const auto& window_repr) { return shouldSkipWindow(window_repr); });
|
||||
}
|
||||
|
||||
void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
void Workspace::updateTaskbar(const std::string& workspace_icon) {
|
||||
for (auto child : m_content.get_children()) {
|
||||
if (child != &m_labelBefore) {
|
||||
m_content.remove(*child);
|
||||
@@ -289,10 +519,10 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
|
||||
// Build a list of windows to display, removing duplicates by window_class
|
||||
// and respecting max-icons limit
|
||||
std::vector<const WindowRepr *> windowsToShow;
|
||||
std::vector<const WindowRepr*> windowsToShow;
|
||||
std::set<std::string> seenClasses;
|
||||
|
||||
auto addWindowIfUnique = [&](const WindowRepr &window_repr) {
|
||||
auto addWindowIfUnique = [&](const WindowRepr& window_repr) {
|
||||
if (shouldSkipWindow(window_repr)) {
|
||||
return;
|
||||
}
|
||||
@@ -309,7 +539,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
addWindowIfUnique(*it);
|
||||
}
|
||||
} else {
|
||||
for (const auto &window_repr : m_windowMap) {
|
||||
for (const auto& window_repr : m_windowMap) {
|
||||
addWindowIfUnique(window_repr);
|
||||
}
|
||||
}
|
||||
@@ -320,8 +550,14 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
windowsToShow.resize(maxIcons);
|
||||
}
|
||||
|
||||
// Apply max-windows limit if configured
|
||||
int maxWindows = m_workspaceManager.maxWindows();
|
||||
if (maxWindows > 0 && static_cast<int>(windowsToShow.size()) > maxWindows) {
|
||||
windowsToShow.resize(maxWindows);
|
||||
}
|
||||
|
||||
bool isFirst = true;
|
||||
for (const auto *window_repr : windowsToShow) {
|
||||
for (const auto* window_repr : windowsToShow) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
} else if (m_workspaceManager.getWindowSeparator() != "") {
|
||||
@@ -331,16 +567,18 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
}
|
||||
|
||||
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");
|
||||
window_box->set_tooltip_markup(window_repr->window_title);
|
||||
|
||||
auto button = Gtk::manage(new Gtk::Button());
|
||||
button->set_relief(Gtk::RELIEF_NONE);
|
||||
button->add(*window_box);
|
||||
button->get_style_context()->add_class("taskbar-window");
|
||||
if (window_repr->isActive) {
|
||||
window_box->get_style_context()->add_class("active");
|
||||
button->get_style_context()->add_class("active");
|
||||
}
|
||||
auto event_box = Gtk::manage(new Gtk::EventBox());
|
||||
event_box->add(*window_box);
|
||||
if (m_workspaceManager.onClickWindow() != "") {
|
||||
event_box->signal_button_press_event().connect(
|
||||
sigc::bind(sigc::mem_fun(*this, &Workspace::handleClick), window_repr->address));
|
||||
button->signal_button_press_event().connect(
|
||||
sigc::bind(sigc::mem_fun(*this, &Workspace::handleClick), window_repr->address), false);
|
||||
}
|
||||
|
||||
auto text_before = fmt::format(fmt::runtime(m_workspaceManager.taskbarFormatBefore()),
|
||||
@@ -365,12 +603,14 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
window_box->pack_start(*window_label_after, true, true);
|
||||
}
|
||||
|
||||
m_content.pack_start(*event_box, true, false);
|
||||
event_box->show_all();
|
||||
m_content.pack_start(*button, true, false);
|
||||
button->show_all();
|
||||
}
|
||||
|
||||
auto formatAfter = m_workspaceManager.formatAfter();
|
||||
if (!formatAfter.empty()) {
|
||||
const bool has_format_after = !formatAfter.empty();
|
||||
|
||||
if (has_format_after) {
|
||||
m_labelAfter.set_markup(fmt::format(fmt::runtime(formatAfter), fmt::arg("id", id()),
|
||||
fmt::arg("name", name()),
|
||||
fmt::arg("icon", workspace_icon)));
|
||||
@@ -379,7 +619,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress const &addr) const {
|
||||
bool Workspace::handleClick(const GdkEventButton* event_button, WindowAddress const& addr) const {
|
||||
if (event_button->type == GDK_BUTTON_PRESS) {
|
||||
std::string command = std::regex_replace(m_workspaceManager.onClickWindow(),
|
||||
std::regex("\\{address\\}"), "0x" + addr);
|
||||
@@ -393,9 +633,9 @@ bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress co
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Workspace::shouldSkipWindow(const WindowRepr &window_repr) const {
|
||||
bool Workspace::shouldSkipWindow(const WindowRepr& window_repr) const {
|
||||
auto ignore_list = m_workspaceManager.getIgnoredWindows();
|
||||
auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto &ignoreItem) {
|
||||
auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto& ignoreItem) {
|
||||
return std::regex_match(window_repr.window_class, ignoreItem) ||
|
||||
std::regex_match(window_repr.window_title, ignoreItem);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user