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>
|
2023-09-22 21:18:02 +00:00
|
|
|
#include <json/value.h>
|
2023-07-03 22:24:34 +00:00
|
|
|
|
2023-09-22 19:37:26 +00:00
|
|
|
#include <cstdint>
|
2023-09-02 20:22:26 +00:00
|
|
|
#include <map>
|
2023-07-03 22:17:26 +00:00
|
|
|
#include <memory>
|
2023-10-11 13:59:33 +00:00
|
|
|
#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"
|
2023-10-09 16:53:00 +00:00
|
|
|
#include "util/regex_collection.hpp"
|
2023-06-27 23:52:01 +00:00
|
|
|
|
2023-09-22 19:37:26 +00:00
|
|
|
using WindowAddress = std::string;
|
2023-10-09 16:53:00 +00:00
|
|
|
|
2023-06-27 23:52:01 +00:00
|
|
|
namespace waybar::modules::hyprland {
|
|
|
|
|
2023-08-10 17:40:14 +00:00
|
|
|
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();
|
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
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; }
|
2024-03-04 12:17:30 +00:00
|
|
|
auto moveToMonitor() const -> bool { return m_moveToMonitor; }
|
2023-07-15 17:44:57 +00:00
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
auto getBarOutput() const -> std::string { return m_bar.output->name; }
|
2023-07-15 17:44:57 +00:00
|
|
|
|
2023-12-04 11:10:16 +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);
|
2023-09-22 21:18:02 +00:00
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
bool windowRewriteConfigUsesTitle() const { return m_anyWindowRewriteRuleUsesTitle; }
|
2023-10-11 14:40:49 +00:00
|
|
|
|
2023-06-27 23:52:01 +00:00
|
|
|
private:
|
2023-10-21 14:52:23 +00:00
|
|
|
void onEvent(const std::string& e) override;
|
2023-12-04 11:10:16 +00:00
|
|
|
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);
|
2023-12-04 11:10:16 +00:00
|
|
|
void removeWorkspace(std::string const& name);
|
|
|
|
void setUrgentWorkspace(std::string const& windowaddress);
|
2024-05-24 15:58:03 +00:00
|
|
|
|
|
|
|
// Config
|
2023-12-04 11:10:16 +00:00
|
|
|
void parseConfig(const Json::Value& config);
|
2024-05-24 15:58:03 +00:00
|
|
|
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;
|
2024-05-24 15:58:03 +00:00
|
|
|
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;
|
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
void registerIpc();
|
2023-07-15 17:44:57 +00:00
|
|
|
|
2023-10-21 17:33:55 +00:00
|
|
|
// workspace events
|
2023-12-04 11:10:16 +00:00
|
|
|
void onWorkspaceActivated(std::string const& payload);
|
2024-02-07 15:33:19 +00:00
|
|
|
void onSpecialWorkspaceActivated(std::string const& payload);
|
2023-12-04 11:10:16 +00:00
|
|
|
void onWorkspaceDestroyed(std::string const& payload);
|
2024-01-08 23:11:39 +00:00
|
|
|
void onWorkspaceCreated(std::string const& workspaceName,
|
|
|
|
Json::Value const& clientsData = Json::Value::nullRef);
|
2023-12-04 11:10:16 +00:00
|
|
|
void onWorkspaceMoved(std::string const& payload);
|
|
|
|
void onWorkspaceRenamed(std::string const& payload);
|
2023-10-21 17:33:55 +00:00
|
|
|
|
|
|
|
// monitor events
|
2023-12-04 11:10:16 +00:00
|
|
|
void onMonitorFocused(std::string const& payload);
|
2023-10-21 17:33:55 +00:00
|
|
|
|
|
|
|
// window events
|
2023-12-04 11:10:16 +00:00
|
|
|
void onWindowOpened(std::string const& payload);
|
|
|
|
void onWindowClosed(std::string const& addr);
|
|
|
|
void onWindowMoved(std::string const& payload);
|
|
|
|
|
|
|
|
void onWindowTitleEvent(std::string const& payload);
|
|
|
|
|
2023-10-21 16:13:44 +00:00
|
|
|
void onConfigReloaded();
|
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
int windowRewritePriorityFunction(std::string const& window_rule);
|
|
|
|
|
2024-05-24 18:53:39 +00:00
|
|
|
// Update methods
|
2024-01-05 05:49:11 +00:00
|
|
|
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();
|
2024-05-28 23:52:42 +00:00
|
|
|
void updateWorkspaceStates();
|
2024-05-24 18:53:39 +00:00
|
|
|
bool updateWindowsToCreate();
|
2024-01-05 05:49:11 +00:00
|
|
|
|
2024-01-08 20:10:13 +00:00
|
|
|
void extendOrphans(int workspaceId, Json::Value const& clientsJson);
|
2023-10-21 16:13:44 +00:00
|
|
|
void registerOrphanWindow(WindowCreationPayload create_window_payload);
|
|
|
|
|
|
|
|
void initializeWorkspaces();
|
|
|
|
void setCurrentMonitorId();
|
|
|
|
void loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson);
|
|
|
|
void loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson);
|
2024-01-08 20:10:13 +00:00
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
bool m_allOutputs = false;
|
|
|
|
bool m_showSpecial = false;
|
|
|
|
bool m_activeOnly = false;
|
2024-05-28 14:57:47 +00:00
|
|
|
bool m_specialVisibleOnly = false;
|
2024-03-04 12:17:30 +00:00
|
|
|
bool m_moveToMonitor = false;
|
2023-10-21 16:13:44 +00:00
|
|
|
Json::Value m_persistentWorkspaceConfig;
|
2023-12-04 11:10:16 +00:00
|
|
|
|
2024-01-08 20:10:13 +00:00
|
|
|
// 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;
|
|
|
|
|
2023-12-04 11:10:16 +00:00
|
|
|
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;
|
2024-02-07 15:33:19 +00:00
|
|
|
std::string m_activeSpecialWorkspaceName;
|
2023-12-04 11:10:16 +00:00
|
|
|
std::vector<std::unique_ptr<Workspace>> m_workspaces;
|
2024-01-08 23:11:39 +00:00
|
|
|
std::vector<std::pair<Json::Value, Json::Value>> m_workspacesToCreate;
|
2023-12-04 11:10:16 +00:00
|
|
|
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
|