Waybar/include/modules/sway/workspaces.hpp

48 lines
1.7 KiB
C++
Raw Normal View History

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>
#include "IModule.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-04-18 15:52:00 +00:00
#include "util/sleeper_thread.hpp"
2019-05-07 11:43:48 +00:00
#include "util/json.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-05-13 13:15:50 +00:00
class Workspaces : public IModule, public sigc::trackable {
2019-04-18 15:52:00 +00:00
public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
~Workspaces() = default;
auto update() -> void;
operator Gtk::Widget&();
private:
2019-04-24 10:37:24 +00:00
void onCmd(const struct Ipc::ipc_response&);
void onEvent(const struct Ipc::ipc_response&);
2019-04-18 15:52:00 +00:00
void worker();
bool filterButtons();
Gtk::Button& addButton(const Json::Value&);
2019-04-18 15:52:00 +00:00
void onButtonReady(const Json::Value&, Gtk::Button&);
std::string getIcon(const std::string&, const Json::Value&);
bool handleScroll(GdkEventScroll*);
const std::string getCycleWorkspace(std::vector<Json::Value>::iterator, bool prev) const;
uint16_t getWorkspaceIndex(const std::string& name) const;
2019-04-18 15:52:00 +00:00
std::string trimWorkspaceName(std::string);
2018-08-16 12:29:41 +00:00
2019-04-18 15:52:00 +00:00
const Bar& bar_;
const Json::Value& config_;
std::vector<Json::Value> workspaces_;
2019-04-18 15:52:00 +00:00
waybar::util::SleeperThread thread_;
std::mutex mutex_;
2019-04-18 15:52:00 +00:00
Gtk::Box box_;
Ipc ipc_;
2019-05-07 11:43:48 +00:00
util::JsonParser parser_;
2019-04-18 15:52:00 +00:00
bool scrolling_;
std::unordered_map<std::string, Gtk::Button> buttons_;
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