From 07c91c200a284f308f2e621b5a360b175f33374e Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 24 May 2024 14:07:12 -0500 Subject: [PATCH] hyprland/workspaces: break up headers --- .../hyprland/windowcreationpayload.hpp | 61 ++++++++++++ include/modules/hyprland/workspace.hpp | 88 ++++++++++++++++++ include/modules/hyprland/workspaces.hpp | 93 +------------------ 3 files changed, 151 insertions(+), 91 deletions(-) create mode 100644 include/modules/hyprland/windowcreationpayload.hpp create mode 100644 include/modules/hyprland/workspace.hpp diff --git a/include/modules/hyprland/windowcreationpayload.hpp b/include/modules/hyprland/windowcreationpayload.hpp new file mode 100644 index 00000000..45229ed4 --- /dev/null +++ b/include/modules/hyprland/windowcreationpayload.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AModule.hpp" +#include "bar.hpp" +#include "modules/hyprland/backend.hpp" +#include "util/enum.hpp" +#include "util/regex_collection.hpp" + +using WindowAddress = std::string; + +namespace waybar::modules::hyprland { + +class Workspaces; + +class WindowCreationPayload { + public: + WindowCreationPayload(std::string workspace_name, WindowAddress window_address, + std::string window_repr); + WindowCreationPayload(std::string workspace_name, WindowAddress window_address, + std::string window_class, std::string window_title); + WindowCreationPayload(Json::Value const& client_data); + + int incrementTimeSpentUncreated(); + bool isEmpty(Workspaces& workspace_manager); + bool reprIsReady() const { return std::holds_alternative(m_window); } + std::string repr(Workspaces& workspace_manager); + + std::string getWorkspaceName() const { return m_workspaceName; } + WindowAddress getAddress() const { return m_windowAddress; } + + void moveToWorksace(std::string& new_workspace_name); + + private: + void clearAddr(); + void clearWorkspaceName(); + + using Repr = std::string; + using ClassAndTitle = std::pair; + std::variant m_window; + + WindowAddress m_windowAddress; + std::string m_workspaceName; + + int m_timeSpentUncreated = 0; +}; + +} // namespace waybar::modules::hyprland diff --git a/include/modules/hyprland/workspace.hpp b/include/modules/hyprland/workspace.hpp new file mode 100644 index 00000000..f1fea4e8 --- /dev/null +++ b/include/modules/hyprland/workspace.hpp @@ -0,0 +1,88 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AModule.hpp" +#include "bar.hpp" +#include "modules/hyprland/backend.hpp" +#include "modules/hyprland/windowcreationpayload.hpp" +#include "util/enum.hpp" +#include "util/regex_collection.hpp" + +using WindowAddress = std::string; + +namespace waybar::modules::hyprland { + +class Workspaces; +class Workspace { + public: + explicit Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager, + const Json::Value& clients_data = Json::Value::nullRef); + std::string& selectIcon(std::map& icons_map); + Gtk::Button& button() { return m_button; }; + + int id() const { return m_id; }; + std::string name() const { return m_name; }; + std::string output() const { return m_output; }; + bool isActive() const { return m_isActive; }; + bool isSpecial() const { return m_isSpecial; }; + bool isPersistent() const { return m_isPersistentRule || m_isPersistentConfig; }; + bool isPersistentConfig() const { return m_isPersistentConfig; }; + bool isPersistentRule() const { return m_isPersistentRule; }; + bool isVisible() const { return m_isVisible; }; + bool isEmpty() const { return m_windows == 0; }; + bool isUrgent() const { return m_isUrgent; }; + + bool handleClicked(GdkEventButton* bt) const; + void setActive(bool value = true) { m_isActive = value; }; + void setPersistentRule(bool value = true) { m_isPersistentRule = value; }; + void setPersistentConfig(bool value = true) { m_isPersistentConfig = value; }; + void setUrgent(bool value = true) { m_isUrgent = value; }; + void setVisible(bool value = true) { m_isVisible = value; }; + void setWindows(uint value) { m_windows = value; }; + void setName(std::string const& value) { m_name = value; }; + 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); + void initializeWindowMap(const Json::Value& clients_data); + + bool onWindowOpened(WindowCreationPayload const& create_window_paylod); + std::optional closeWindow(WindowAddress const& addr); + + void update(const std::string& format, const std::string& icon); + + private: + Workspaces& m_workspaceManager; + + int m_id; + std::string m_name; + std::string m_output; + uint m_windows; + bool m_isActive = false; + bool m_isSpecial = false; + bool m_isPersistentRule = false; // represents the persistent state in hyprland + bool m_isPersistentConfig = false; // represents the persistent state in the Waybar config + bool m_isUrgent = false; + bool m_isVisible = false; + + std::map m_windowMap; + + Gtk::Button m_button; + Gtk::Box m_content; + Gtk::Label m_label; +}; + +} // namespace waybar::modules::hyprland diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 3c19bc4b..23e3e27f 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -17,6 +17,8 @@ #include "AModule.hpp" #include "bar.hpp" #include "modules/hyprland/backend.hpp" +#include "modules/hyprland/windowcreationpayload.hpp" +#include "modules/hyprland/workspace.hpp" #include "util/enum.hpp" #include "util/regex_collection.hpp" @@ -26,97 +28,6 @@ namespace waybar::modules::hyprland { class Workspaces; -class WindowCreationPayload { - public: - WindowCreationPayload(std::string workspace_name, WindowAddress window_address, - std::string window_repr); - WindowCreationPayload(std::string workspace_name, WindowAddress window_address, - std::string window_class, std::string window_title); - WindowCreationPayload(Json::Value const& client_data); - - int incrementTimeSpentUncreated(); - bool isEmpty(Workspaces& workspace_manager); - bool reprIsReady() const { return std::holds_alternative(m_window); } - std::string repr(Workspaces& workspace_manager); - - std::string getWorkspaceName() const { return m_workspaceName; } - WindowAddress getAddress() const { return m_windowAddress; } - - void moveToWorksace(std::string& new_workspace_name); - - private: - void clearAddr(); - void clearWorkspaceName(); - - using Repr = std::string; - using ClassAndTitle = std::pair; - std::variant m_window; - - WindowAddress m_windowAddress; - std::string m_workspaceName; - - int m_timeSpentUncreated = 0; -}; - -class Workspace { - public: - explicit Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager, - const Json::Value& clients_data = Json::Value::nullRef); - std::string& selectIcon(std::map& icons_map); - Gtk::Button& button() { return m_button; }; - - int id() const { return m_id; }; - std::string name() const { return m_name; }; - std::string output() const { return m_output; }; - bool isActive() const { return m_isActive; }; - bool isSpecial() const { return m_isSpecial; }; - bool isPersistent() const { return m_isPersistentRule || m_isPersistentConfig; }; - bool isPersistentConfig() const { return m_isPersistentConfig; }; - bool isPersistentRule() const { return m_isPersistentRule; }; - bool isVisible() const { return m_isVisible; }; - bool isEmpty() const { return m_windows == 0; }; - bool isUrgent() const { return m_isUrgent; }; - - bool handleClicked(GdkEventButton* bt) const; - void setActive(bool value = true) { m_isActive = value; }; - void setPersistentRule(bool value = true) { m_isPersistentRule = value; }; - void setPersistentConfig(bool value = true) { m_isPersistentConfig = value; }; - void setUrgent(bool value = true) { m_isUrgent = value; }; - void setVisible(bool value = true) { m_isVisible = value; }; - void setWindows(uint value) { m_windows = value; }; - void setName(std::string const& value) { m_name = value; }; - 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); - void initializeWindowMap(const Json::Value& clients_data); - - bool onWindowOpened(WindowCreationPayload const& create_window_paylod); - std::optional closeWindow(WindowAddress const& addr); - - void update(const std::string& format, const std::string& icon); - - private: - Workspaces& m_workspaceManager; - - int m_id; - std::string m_name; - std::string m_output; - uint m_windows; - bool m_isActive = false; - bool m_isSpecial = false; - bool m_isPersistentRule = false; // represents the persistent state in hyprland - bool m_isPersistentConfig = false; // represents the persistent state in the Waybar config - bool m_isUrgent = false; - bool m_isVisible = false; - - std::map m_windowMap; - - Gtk::Button m_button; - Gtk::Box m_content; - Gtk::Label m_label; -}; - class Workspaces : public AModule, public EventHandler { public: Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);