Waybar/include/modules/hyprland/workspaces.hpp

156 lines
5.5 KiB
C++
Raw Normal View History

2023-09-02 20:22:26 +00:00
#pragma once
2023-06-27 23:52:01 +00:00
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <json/value.h>
2023-07-03 22:24:34 +00:00
#include <cstdint>
2023-09-02 20:22:26 +00:00
#include <map>
2023-07-03 22:17:26 +00:00
#include <memory>
#include <regex>
2023-09-02 20:22:26 +00:00
#include <string>
#include <vector>
2023-06-27 23:52:01 +00:00
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
2024-05-24 19:07:12 +00:00
#include "modules/hyprland/windowcreationpayload.hpp"
#include "modules/hyprland/workspace.hpp"
2023-09-09 14:32:55 +00:00
#include "util/enum.hpp"
#include "util/regex_collection.hpp"
2023-06-27 23:52:01 +00:00
using WindowAddress = std::string;
2023-06-27 23:52:01 +00:00
namespace waybar::modules::hyprland {
class Workspaces;
2023-06-27 23:52:01 +00:00
class Workspaces : public AModule, public EventHandler {
public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
2023-07-16 12:47:14 +00:00
~Workspaces() override;
2023-06-27 23:52:01 +00:00
void update() override;
void init();
auto allOutputs() const -> bool { return m_allOutputs; }
auto showSpecial() const -> bool { return m_showSpecial; }
auto activeOnly() const -> bool { return m_activeOnly; }
2024-05-28 14:57:47 +00:00
auto specialVisibleOnly() const -> bool { return m_specialVisibleOnly; }
auto moveToMonitor() const -> bool { return m_moveToMonitor; }
2023-07-15 17:44:57 +00:00
auto getBarOutput() const -> std::string { return m_bar.output->name; }
2023-07-15 17:44:57 +00:00
std::string getRewrite(std::string window_class, std::string window_title);
std::string& getWindowSeparator() { return m_formatWindowSeparator; }
bool isWorkspaceIgnored(std::string const& workspace_name);
bool windowRewriteConfigUsesTitle() const { return m_anyWindowRewriteRuleUsesTitle; }
2023-06-27 23:52:01 +00:00
private:
2023-10-21 14:52:23 +00:00
void onEvent(const std::string& e) override;
void updateWindowCount();
void sortWorkspaces();
2024-06-23 04:19:48 +00:00
void createWorkspace(Json::Value const& workspace_data,
Json::Value const& clients_data = Json::Value::nullRef);
2024-05-24 19:41:52 +00:00
2024-06-23 04:19:48 +00:00
static Json::Value createMonitorWorkspaceData(std::string const& name,
std::string const& monitor);
void removeWorkspace(std::string const& name);
void setUrgentWorkspace(std::string const& windowaddress);
// Config
void parseConfig(const Json::Value& config);
auto populateIconsMap(const Json::Value& formatIcons) -> void;
2024-09-13 06:55:14 +00:00
static auto populateBoolConfig(const Json::Value& config, const std::string& key,
bool& member) -> void;
auto populateSortByConfig(const Json::Value& config) -> void;
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
auto populateWindowRewriteConfig(const Json::Value& config) -> void;
void registerIpc();
2023-07-15 17:44:57 +00:00
// workspace events
void onWorkspaceActivated(std::string const& payload);
void onSpecialWorkspaceActivated(std::string const& payload);
void onWorkspaceDestroyed(std::string const& payload);
void onWorkspaceCreated(std::string const& workspaceName,
Json::Value const& clientsData = Json::Value::nullRef);
void onWorkspaceMoved(std::string const& payload);
void onWorkspaceRenamed(std::string const& payload);
// monitor events
void onMonitorFocused(std::string const& payload);
// window events
void onWindowOpened(std::string const& payload);
void onWindowClosed(std::string const& addr);
void onWindowMoved(std::string const& payload);
void onWindowTitleEvent(std::string const& payload);
void onConfigReloaded();
int windowRewritePriorityFunction(std::string const& window_rule);
2024-05-24 18:53:39 +00:00
// Update methods
void doUpdate();
2024-05-24 18:53:39 +00:00
void removeWorkspacesToRemove();
void createWorkspacesToCreate();
2024-06-23 04:19:48 +00:00
static std::vector<std::string> getVisibleWorkspaces();
void updateWorkspaceStates();
2024-05-24 18:53:39 +00:00
bool updateWindowsToCreate();
void extendOrphans(int workspaceId, Json::Value const& clientsJson);
void registerOrphanWindow(WindowCreationPayload create_window_payload);
void initializeWorkspaces();
void setCurrentMonitorId();
void loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson);
void loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson);
bool m_allOutputs = false;
bool m_showSpecial = false;
bool m_activeOnly = false;
2024-05-28 14:57:47 +00:00
bool m_specialVisibleOnly = false;
bool m_moveToMonitor = false;
Json::Value m_persistentWorkspaceConfig;
// 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;
enum class SortMethod { ID, NAME, NUMBER, DEFAULT };
util::EnumParser<SortMethod> m_enumParser;
SortMethod m_sortBy = SortMethod::DEFAULT;
std::map<std::string, SortMethod> m_sortMap = {{"ID", SortMethod::ID},
{"NAME", SortMethod::NAME},
{"NUMBER", SortMethod::NUMBER},
{"DEFAULT", SortMethod::DEFAULT}};
std::string m_format;
std::map<std::string, std::string> m_iconsMap;
util::RegexCollection m_windowRewriteRules;
bool m_anyWindowRewriteRuleUsesTitle = false;
std::string m_formatWindowSeparator;
bool m_withIcon;
uint64_t m_monitorId;
std::string m_activeWorkspaceName;
std::string m_activeSpecialWorkspaceName;
std::vector<std::unique_ptr<Workspace>> m_workspaces;
std::vector<std::pair<Json::Value, Json::Value>> m_workspacesToCreate;
std::vector<std::string> m_workspacesToRemove;
std::vector<WindowCreationPayload> m_windowsToCreate;
std::vector<std::regex> m_ignoreWorkspaces;
std::mutex m_mutex;
const Bar& m_bar;
Gtk::Box m_box;
2023-06-27 23:52:01 +00:00
};
} // namespace waybar::modules::hyprland