mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(swaybar-ipc): add swaybar IPC client
This commit is contained in:
@ -8,6 +8,9 @@
|
||||
#include <gtkmm/window.h>
|
||||
#include <json/json.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "AModule.hpp"
|
||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
||||
|
||||
@ -43,6 +46,12 @@ struct bar_mode {
|
||||
bool visible;
|
||||
};
|
||||
|
||||
#ifdef HAVE_SWAY
|
||||
namespace modules::sway {
|
||||
class BarIpcClient;
|
||||
}
|
||||
#endif // HAVE_SWAY
|
||||
|
||||
class BarSurface {
|
||||
protected:
|
||||
BarSurface() = default;
|
||||
@ -68,7 +77,7 @@ class Bar {
|
||||
|
||||
Bar(struct waybar_output *w_output, const Json::Value &);
|
||||
Bar(const Bar &) = delete;
|
||||
~Bar() = default;
|
||||
~Bar();
|
||||
|
||||
void setMode(const std::string_view &);
|
||||
void setVisible(bool visible);
|
||||
@ -82,6 +91,10 @@ class Bar {
|
||||
bool vertical = false;
|
||||
Gtk::Window window;
|
||||
|
||||
#ifdef HAVE_SWAY
|
||||
std::string bar_id;
|
||||
#endif
|
||||
|
||||
private:
|
||||
void onMap(GdkEventAny *);
|
||||
auto setupWidgets() -> void;
|
||||
@ -102,6 +115,10 @@ class Bar {
|
||||
std::vector<std::unique_ptr<waybar::AModule>> modules_left_;
|
||||
std::vector<std::unique_ptr<waybar::AModule>> modules_center_;
|
||||
std::vector<std::unique_ptr<waybar::AModule>> modules_right_;
|
||||
#ifdef HAVE_SWAY
|
||||
using BarIpcClient = modules::sway::BarIpcClient;
|
||||
std::unique_ptr<BarIpcClient> _ipc_client;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
48
include/modules/sway/bar.hpp
Normal file
48
include/modules/sway/bar.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
#include "util/SafeSignal.hpp"
|
||||
#include "util/json.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
class Bar;
|
||||
|
||||
namespace modules::sway {
|
||||
|
||||
/*
|
||||
* Supported subset of i3/sway IPC barconfig object
|
||||
*/
|
||||
struct swaybar_config {
|
||||
std::string id;
|
||||
std::string mode;
|
||||
std::string hidden_state;
|
||||
std::string position;
|
||||
};
|
||||
|
||||
/**
|
||||
* swaybar IPC client
|
||||
*/
|
||||
class BarIpcClient {
|
||||
public:
|
||||
BarIpcClient(waybar::Bar& bar);
|
||||
|
||||
private:
|
||||
void onInitialConfig(const struct Ipc::ipc_response& res);
|
||||
void onIpcEvent(const struct Ipc::ipc_response&);
|
||||
void onConfigUpdate(const swaybar_config& config);
|
||||
void onVisibilityUpdate(bool visible_by_modifier);
|
||||
|
||||
Bar& bar_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
|
||||
swaybar_config bar_config_;
|
||||
|
||||
SafeSignal<bool> signal_visible_;
|
||||
SafeSignal<swaybar_config> signal_config_;
|
||||
};
|
||||
|
||||
} // namespace modules::sway
|
||||
} // namespace waybar
|
Reference in New Issue
Block a user