Initial implementation of workspace taskbars

Add a list of window titles and icons to each workspace (like wlr/taskbar but grouped by workspace).

Only implemented on hyprland for now.
This commit is contained in:
Pol Rivero
2024-12-31 18:33:08 +01:00
parent bc2e143ac5
commit 69e2e249a6
6 changed files with 73 additions and 22 deletions

View File

@ -26,10 +26,19 @@ namespace waybar::modules::hyprland {
class Workspaces;
struct WindowRepr {
std::string window_class;
std::string window_title;
std::string repr_rewrite;
public:
bool empty() const { return repr_rewrite.empty(); }
};
class WindowCreationPayload {
public:
WindowCreationPayload(std::string workspace_name, WindowAddress window_address,
std::string window_repr);
WindowRepr window_repr);
WindowCreationPayload(std::string workspace_name, WindowAddress window_address,
std::string window_class, std::string window_title);
WindowCreationPayload(Json::Value const& client_data);
@ -37,7 +46,7 @@ class WindowCreationPayload {
int incrementTimeSpentUncreated();
bool isEmpty(Workspaces& workspace_manager);
bool reprIsReady() const { return std::holds_alternative<Repr>(m_window); }
std::string repr(Workspaces& workspace_manager);
WindowRepr repr(Workspaces& workspace_manager);
std::string getWorkspaceName() const { return m_workspaceName; }
WindowAddress getAddress() const { return m_windowAddress; }
@ -48,7 +57,7 @@ class WindowCreationPayload {
void clearAddr();
void clearWorkspaceName();
using Repr = std::string;
using Repr = WindowRepr;
using ClassAndTitle = std::pair<std::string, std::string>;
std::variant<Repr, ClassAndTitle> m_window;

View File

@ -56,11 +56,11 @@ class Workspace {
void setOutput(std::string const& value) { m_output = value; };
bool containsWindow(WindowAddress const& addr) const { return m_windowMap.contains(addr); }
void insertWindow(WindowCreationPayload create_window_paylod);
std::string removeWindow(WindowAddress const& addr);
WindowRepr removeWindow(WindowAddress const& addr);
void initializeWindowMap(const Json::Value& clients_data);
bool onWindowOpened(WindowCreationPayload const& create_window_paylod);
std::optional<std::string> closeWindow(WindowAddress const& addr);
std::optional<WindowRepr> closeWindow(WindowAddress const& addr);
void update(const std::string& format, const std::string& icon);
@ -78,7 +78,7 @@ class Workspace {
bool m_isUrgent = false;
bool m_isVisible = false;
std::map<WindowAddress, std::string> m_windowMap;
std::map<WindowAddress, WindowRepr, std::less<>> m_windowMap;
Gtk::Button m_button;
Gtk::Box m_content;

View File

@ -17,6 +17,7 @@
#include "modules/hyprland/windowcreationpayload.hpp"
#include "modules/hyprland/workspace.hpp"
#include "util/enum.hpp"
#include "util/icon_loader.hpp"
#include "util/regex_collection.hpp"
using WindowAddress = std::string;
@ -45,6 +46,7 @@ class Workspaces : public AModule, public EventHandler {
bool isWorkspaceIgnored(std::string const& workspace_name);
bool windowRewriteConfigUsesTitle() const { return m_anyWindowRewriteRuleUsesTitle; }
const IconLoader& iconLoader() const { return m_iconLoader; }
private:
void onEvent(const std::string& e) override;
@ -119,7 +121,7 @@ class Workspaces : public AModule, public EventHandler {
// Map for windows stored in workspaces not present in the current bar.
// This happens when the user has multiple monitors (hence, multiple bars)
// and doesn't share windows accross bars (a.k.a `all-outputs` = false)
std::map<WindowAddress, std::string> m_orphanWindowMap;
std::map<WindowAddress, WindowRepr> m_orphanWindowMap;
enum class SortMethod { ID, NAME, NUMBER, DEFAULT };
util::EnumParser<SortMethod> m_enumParser;
@ -136,6 +138,7 @@ class Workspaces : public AModule, public EventHandler {
bool m_anyWindowRewriteRuleUsesTitle = false;
std::string m_formatWindowSeparator;
IconLoader m_iconLoader;
bool m_withIcon;
uint64_t m_monitorId;
std::string m_activeWorkspaceName;