workspace taskbars: Fix windows not showing

Windows were not being shown or updated unless the window-rewrite config were present.
This commit is contained in:
Pol Rivero
2025-01-04 22:10:23 +01:00
parent 3948c0d154
commit 5ee0d1c7fe
4 changed files with 15 additions and 12 deletions

View File

@ -33,7 +33,7 @@ struct WindowRepr {
std::string repr_rewrite; std::string repr_rewrite;
public: public:
bool empty() const { return repr_rewrite.empty(); } bool empty() const { return address.empty(); }
}; };
class WindowCreationPayload { class WindowCreationPayload {

View File

@ -39,7 +39,7 @@ class Workspaces : public AModule, public EventHandler {
auto activeOnly() const -> bool { return m_activeOnly; } auto activeOnly() const -> bool { return m_activeOnly; }
auto specialVisibleOnly() const -> bool { return m_specialVisibleOnly; } auto specialVisibleOnly() const -> bool { return m_specialVisibleOnly; }
auto moveToMonitor() const -> bool { return m_moveToMonitor; } auto moveToMonitor() const -> bool { return m_moveToMonitor; }
auto enableWorkspaceTaskbar() const -> bool { return m_enableWorkspaceTaskbar; } auto enableTaskbar() const -> bool { return m_enableTaskbar; }
auto taskbarWithIcon() const -> bool { return m_taskbarWithIcon; } auto taskbarWithIcon() const -> bool { return m_taskbarWithIcon; }
auto getBarOutput() const -> std::string { return m_bar.output->name; } auto getBarOutput() const -> std::string { return m_bar.output->name; }
@ -159,8 +159,9 @@ class Workspaces : public AModule, public EventHandler {
std::vector<WindowCreationPayload> m_windowsToCreate; std::vector<WindowCreationPayload> m_windowsToCreate;
IconLoader m_iconLoader; IconLoader m_iconLoader;
bool m_enableWorkspaceTaskbar = false; bool m_enableTaskbar = false;
bool m_taskbarWithIcon = false; bool m_taskbarWithIcon = false;
bool m_taskbarWithTitle = false;
std::string m_taskbarFormatBefore; std::string m_taskbarFormatBefore;
std::string m_taskbarFormatAfter; std::string m_taskbarFormatAfter;
int m_taskbarIconSize = 16; int m_taskbarIconSize = 16;

View File

@ -32,7 +32,7 @@ Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_ma
false); false);
m_button.set_relief(Gtk::RELIEF_NONE); m_button.set_relief(Gtk::RELIEF_NONE);
if (m_workspaceManager.enableWorkspaceTaskbar()) { if (m_workspaceManager.enableTaskbar()) {
m_content.set_orientation(m_workspaceManager.taskbarOrientation()); m_content.set_orientation(m_workspaceManager.taskbarOrientation());
m_content.pack_start(m_labelBefore, false, false); m_content.pack_start(m_labelBefore, false, false);
} else { } else {
@ -105,7 +105,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_paylod) {
if (!create_window_paylod.isEmpty(m_workspaceManager)) { if (!create_window_paylod.isEmpty(m_workspaceManager)) {
auto repr = create_window_paylod.repr(m_workspaceManager); auto repr = create_window_paylod.repr(m_workspaceManager);
if (!repr.empty()) { if (!repr.empty() || m_workspaceManager.enableTaskbar()) {
auto addr = create_window_paylod.getAddress(); auto addr = create_window_paylod.getAddress();
auto it = std::ranges::find_if( 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; });
@ -213,8 +213,8 @@ void Workspace::update(const std::string &workspace_icon) {
std::string windows; std::string windows;
// Optimization: The {windows} substitution string is only possible if the taskbar is disabled, no // Optimization: The {windows} substitution string is only possible if the taskbar is disabled, no
// need to compute this if enableWorkspaceTaskbar() is true // need to compute this if enableTaskbar() is true
if (!m_workspaceManager.enableWorkspaceTaskbar()) { if (!m_workspaceManager.enableTaskbar()) {
auto windowSeparator = m_workspaceManager.getWindowSeparator(); auto windowSeparator = m_workspaceManager.getWindowSeparator();
bool isNotFirst = false; bool isNotFirst = false;
@ -233,7 +233,7 @@ void Workspace::update(const std::string &workspace_icon) {
fmt::arg("name", name()), fmt::arg("icon", workspace_icon), fmt::arg("name", name()), fmt::arg("icon", workspace_icon),
fmt::arg("windows", windows))); fmt::arg("windows", windows)));
if (m_workspaceManager.enableWorkspaceTaskbar()) { if (m_workspaceManager.enableTaskbar()) {
updateTaskbar(workspace_icon); updateTaskbar(workspace_icon);
} }
} }

View File

@ -589,7 +589,7 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
if (withWindows) { if (withWindows) {
populateWorkspaceTaskbarConfig(config); populateWorkspaceTaskbarConfig(config);
} }
if (m_enableWorkspaceTaskbar) { if (m_enableTaskbar) {
auto parts = split(m_formatBefore, "{windows}", 1); auto parts = split(m_formatBefore, "{windows}", 1);
m_formatBefore = parts[0]; m_formatBefore = parts[0];
m_formatAfter = parts.size() > 1 ? parts[1] : ""; m_formatAfter = parts.size() > 1 ? parts[1] : "";
@ -673,11 +673,13 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
return; return;
} }
populateBoolConfig(workspaceTaskbar, "enable", m_enableWorkspaceTaskbar); populateBoolConfig(workspaceTaskbar, "enable", m_enableTaskbar);
if (workspaceTaskbar["format"].isString()) { if (workspaceTaskbar["format"].isString()) {
/* The user defined a format string, use it */ /* The user defined a format string, use it */
auto parts = split(workspaceTaskbar["format"].asString(), "{icon}", 1); std::string format = workspaceTaskbar["format"].asString();
m_taskbarWithTitle = format.find("{title") != std::string::npos; /* {title} or {title.length} */
auto parts = split(format, "{icon}", 1);
m_taskbarFormatBefore = parts[0]; m_taskbarFormatBefore = parts[0];
if (parts.size() > 1) { if (parts.size() > 1) {
m_taskbarWithIcon = true; m_taskbarWithIcon = true;
@ -726,7 +728,7 @@ auto Workspaces::registerIpc() -> void {
gIPC->registerForIPC("urgent", this); gIPC->registerForIPC("urgent", this);
gIPC->registerForIPC("configreloaded", this); gIPC->registerForIPC("configreloaded", this);
if (windowRewriteConfigUsesTitle()) { if (windowRewriteConfigUsesTitle() || m_taskbarWithTitle) {
spdlog::info( spdlog::info(
"Registering for Hyprland's 'windowtitle' events because a user-defined window " "Registering for Hyprland's 'windowtitle' events because a user-defined window "
"rewrite rule uses the 'title' field."); "rewrite rule uses the 'title' field.");