2018-08-08 21:54:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2019-04-18 15:52:00 +00:00
|
|
|
#include <gtkmm/button.h>
|
|
|
|
#include <gtkmm/label.h>
|
2022-04-06 06:37:19 +00:00
|
|
|
|
2023-01-16 21:24:55 +00:00
|
|
|
#include <string_view>
|
2019-08-09 09:05:34 +00:00
|
|
|
#include <unordered_map>
|
2022-04-06 06:37:19 +00:00
|
|
|
|
2019-06-15 12:57:52 +00:00
|
|
|
#include "AModule.hpp"
|
2018-08-08 21:54:58 +00:00
|
|
|
#include "bar.hpp"
|
|
|
|
#include "client.hpp"
|
2018-08-20 12:50:45 +00:00
|
|
|
#include "modules/sway/ipc/client.hpp"
|
2019-05-07 11:43:48 +00:00
|
|
|
#include "util/json.hpp"
|
2023-12-27 22:06:09 +00:00
|
|
|
#include "util/regex_collection.hpp"
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2018-08-15 18:17:17 +00:00
|
|
|
namespace waybar::modules::sway {
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2019-06-15 12:57:52 +00:00
|
|
|
class Workspaces : public AModule, public sigc::trackable {
|
2019-04-18 15:52:00 +00:00
|
|
|
public:
|
|
|
|
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
2023-03-02 13:57:07 +00:00
|
|
|
virtual ~Workspaces() = default;
|
|
|
|
auto update() -> void override;
|
2019-04-18 15:52:00 +00:00
|
|
|
|
|
|
|
private:
|
2023-01-16 21:24:55 +00:00
|
|
|
static constexpr std::string_view workspace_switch_cmd_ = "workspace {} \"{}\"";
|
|
|
|
static constexpr std::string_view persistent_workspace_switch_cmd_ =
|
|
|
|
R"(workspace {} "{}"; move workspace to output "{}"; workspace {} "{}")";
|
2020-06-07 18:51:43 +00:00
|
|
|
|
2020-07-27 08:56:49 +00:00
|
|
|
static int convertWorkspaceNameToNum(std::string name);
|
2023-12-27 22:06:09 +00:00
|
|
|
static int windowRewritePriorityFunction(std::string const& window_rule);
|
2020-07-27 08:56:49 +00:00
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
void onCmd(const struct Ipc::ipc_response&);
|
|
|
|
void onEvent(const struct Ipc::ipc_response&);
|
|
|
|
bool filterButtons();
|
2023-12-27 22:06:09 +00:00
|
|
|
static bool hasFlag(const Json::Value&, const std::string&);
|
|
|
|
void updateWindows(const Json::Value&, std::string&);
|
2022-04-06 06:37:19 +00:00
|
|
|
Gtk::Button& addButton(const Json::Value&);
|
|
|
|
void onButtonReady(const Json::Value&, Gtk::Button&);
|
|
|
|
std::string getIcon(const std::string&, const Json::Value&);
|
2019-04-19 14:48:02 +00:00
|
|
|
const std::string getCycleWorkspace(std::vector<Json::Value>::iterator, bool prev) const;
|
2022-04-06 06:37:19 +00:00
|
|
|
uint16_t getWorkspaceIndex(const std::string& name) const;
|
|
|
|
std::string trimWorkspaceName(std::string);
|
2023-03-02 13:57:07 +00:00
|
|
|
bool handleScroll(GdkEventScroll*) override;
|
2022-04-06 06:37:19 +00:00
|
|
|
|
|
|
|
const Bar& bar_;
|
|
|
|
std::vector<Json::Value> workspaces_;
|
2023-07-20 19:56:15 +00:00
|
|
|
std::vector<std::string> high_priority_named_;
|
2022-04-06 06:37:19 +00:00
|
|
|
std::vector<std::string> workspaces_order_;
|
|
|
|
Gtk::Box box_;
|
2023-12-27 22:06:09 +00:00
|
|
|
std::string m_formatWindowSeperator;
|
|
|
|
std::string m_windowRewriteDefault;
|
|
|
|
util::RegexCollection m_windowRewriteRules;
|
2022-04-06 06:37:19 +00:00
|
|
|
util::JsonParser parser_;
|
2019-04-18 15:52:00 +00:00
|
|
|
std::unordered_map<std::string, Gtk::Button> buttons_;
|
2022-04-06 06:37:19 +00:00
|
|
|
std::mutex mutex_;
|
|
|
|
Ipc ipc_;
|
2018-08-16 12:29:41 +00:00
|
|
|
};
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2019-04-18 15:52:00 +00:00
|
|
|
} // namespace waybar::modules::sway
|