2018-08-08 21:54:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-28 03:57:23 +00:00
|
|
|
#include <gdkmm/monitor.h>
|
2019-01-08 20:05:44 +00:00
|
|
|
#include <glibmm/refptr.h>
|
2019-07-15 08:06:01 +00:00
|
|
|
#include <gtkmm/box.h>
|
2019-01-08 20:05:44 +00:00
|
|
|
#include <gtkmm/cssprovider.h>
|
2019-04-18 15:43:16 +00:00
|
|
|
#include <gtkmm/main.h>
|
2019-01-08 20:05:44 +00:00
|
|
|
#include <gtkmm/window.h>
|
2019-04-18 15:43:16 +00:00
|
|
|
#include <json/json.h>
|
2020-10-22 05:16:12 +00:00
|
|
|
|
2020-10-20 02:34:48 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-06-15 12:57:52 +00:00
|
|
|
#include "AModule.hpp"
|
2018-08-10 22:32:59 +00:00
|
|
|
#include "xdg-output-unstable-v1-client-protocol.h"
|
2018-08-08 21:54:58 +00:00
|
|
|
|
|
|
|
namespace waybar {
|
|
|
|
|
2018-08-19 11:39:57 +00:00
|
|
|
class Factory;
|
2019-04-18 15:43:16 +00:00
|
|
|
struct waybar_output {
|
2019-08-28 03:57:23 +00:00
|
|
|
Glib::RefPtr<Gdk::Monitor> monitor;
|
|
|
|
std::string name;
|
2020-12-25 20:54:38 +00:00
|
|
|
std::string identifier;
|
2019-08-28 03:57:23 +00:00
|
|
|
|
|
|
|
std::unique_ptr<struct zxdg_output_v1, decltype(&zxdg_output_v1_destroy)> xdg_output = {
|
|
|
|
nullptr, &zxdg_output_v1_destroy};
|
2019-04-18 15:43:16 +00:00
|
|
|
};
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2020-10-23 06:04:58 +00:00
|
|
|
enum class bar_layer : uint8_t {
|
|
|
|
BOTTOM,
|
|
|
|
TOP,
|
|
|
|
OVERLAY,
|
|
|
|
};
|
|
|
|
|
2020-10-22 05:16:12 +00:00
|
|
|
struct bar_margins {
|
|
|
|
int top = 0;
|
|
|
|
int right = 0;
|
|
|
|
int bottom = 0;
|
|
|
|
int left = 0;
|
|
|
|
};
|
|
|
|
|
2021-11-20 03:29:51 +00:00
|
|
|
struct bar_mode {
|
|
|
|
bar_layer layer;
|
|
|
|
bool exclusive;
|
|
|
|
bool passthrough;
|
|
|
|
bool visible;
|
|
|
|
};
|
|
|
|
|
2020-10-20 02:34:48 +00:00
|
|
|
#ifdef HAVE_SWAY
|
|
|
|
namespace modules::sway {
|
|
|
|
class BarIpcClient;
|
|
|
|
}
|
|
|
|
#endif // HAVE_SWAY
|
|
|
|
|
2020-10-22 05:16:12 +00:00
|
|
|
class BarSurface {
|
|
|
|
protected:
|
|
|
|
BarSurface() = default;
|
|
|
|
|
|
|
|
public:
|
2020-10-28 15:06:40 +00:00
|
|
|
virtual void setExclusiveZone(bool enable) = 0;
|
2020-10-23 06:04:58 +00:00
|
|
|
virtual void setLayer(bar_layer layer) = 0;
|
2020-10-28 15:06:40 +00:00
|
|
|
virtual void setMargins(const struct bar_margins &margins) = 0;
|
2021-01-17 09:05:18 +00:00
|
|
|
virtual void setPassThrough(bool enable) = 0;
|
2020-10-28 15:06:40 +00:00
|
|
|
virtual void setPosition(const std::string_view &position) = 0;
|
|
|
|
virtual void setSize(uint32_t width, uint32_t height) = 0;
|
2020-10-23 07:13:23 +00:00
|
|
|
virtual void commit(){};
|
2020-10-22 05:16:12 +00:00
|
|
|
|
|
|
|
virtual ~BarSurface() = default;
|
|
|
|
};
|
|
|
|
|
2018-08-16 12:29:41 +00:00
|
|
|
class Bar {
|
2019-04-18 15:43:16 +00:00
|
|
|
public:
|
2021-11-20 03:29:51 +00:00
|
|
|
using bar_mode_map = std::map<std::string_view, struct bar_mode>;
|
|
|
|
static const bar_mode_map PRESET_MODES;
|
|
|
|
static const std::string_view MODE_DEFAULT;
|
|
|
|
static const std::string_view MODE_INVISIBLE;
|
|
|
|
|
2019-05-09 13:10:13 +00:00
|
|
|
Bar(struct waybar_output *w_output, const Json::Value &);
|
2019-04-18 15:43:16 +00:00
|
|
|
Bar(const Bar &) = delete;
|
2020-10-20 02:34:48 +00:00
|
|
|
~Bar();
|
2019-04-18 15:43:16 +00:00
|
|
|
|
2021-11-20 03:29:51 +00:00
|
|
|
void setMode(const std::string_view &);
|
2020-10-22 05:16:12 +00:00
|
|
|
void setVisible(bool visible);
|
|
|
|
void toggle();
|
2019-04-18 15:43:16 +00:00
|
|
|
void handleSignal(int);
|
|
|
|
|
2019-12-28 00:31:18 +00:00
|
|
|
struct waybar_output *output;
|
|
|
|
Json::Value config;
|
2021-11-20 03:29:51 +00:00
|
|
|
struct wl_surface *surface;
|
2019-12-28 00:31:18 +00:00
|
|
|
bool visible = true;
|
|
|
|
bool vertical = false;
|
2020-05-27 07:10:38 +00:00
|
|
|
Gtk::Window window;
|
2019-04-18 15:43:16 +00:00
|
|
|
|
2020-10-20 02:34:48 +00:00
|
|
|
#ifdef HAVE_SWAY
|
|
|
|
std::string bar_id;
|
|
|
|
#endif
|
|
|
|
|
2019-04-18 15:43:16 +00:00
|
|
|
private:
|
2020-10-22 05:16:12 +00:00
|
|
|
void onMap(GdkEventAny *);
|
2019-04-18 15:43:16 +00:00
|
|
|
auto setupWidgets() -> void;
|
2021-10-31 22:55:13 +00:00
|
|
|
void getModules(const Factory &, const std::string &, Gtk::Box*);
|
2019-04-18 15:43:16 +00:00
|
|
|
void setupAltFormatKeyForModule(const std::string &module_name);
|
|
|
|
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
2021-11-20 03:29:51 +00:00
|
|
|
void setMode(const bar_mode &);
|
|
|
|
|
|
|
|
/* Copy initial set of modes to allow customization */
|
|
|
|
bar_mode_map configured_modes = PRESET_MODES;
|
|
|
|
std::string last_mode_{MODE_DEFAULT};
|
2019-04-18 15:43:16 +00:00
|
|
|
|
2020-10-22 05:16:12 +00:00
|
|
|
std::unique_ptr<BarSurface> surface_impl_;
|
2019-04-18 15:52:00 +00:00
|
|
|
Gtk::Box left_;
|
|
|
|
Gtk::Box center_;
|
|
|
|
Gtk::Box right_;
|
|
|
|
Gtk::Box box_;
|
2021-12-03 22:56:51 +00:00
|
|
|
std::vector<std::shared_ptr<waybar::AModule>> modules_left_;
|
|
|
|
std::vector<std::shared_ptr<waybar::AModule>> modules_center_;
|
|
|
|
std::vector<std::shared_ptr<waybar::AModule>> modules_right_;
|
2020-10-20 02:34:48 +00:00
|
|
|
#ifdef HAVE_SWAY
|
|
|
|
using BarIpcClient = modules::sway::BarIpcClient;
|
|
|
|
std::unique_ptr<BarIpcClient> _ipc_client;
|
|
|
|
#endif
|
2021-12-03 22:56:51 +00:00
|
|
|
std::vector<std::shared_ptr<waybar::AModule>> modules_all_;
|
2018-08-16 12:29:41 +00:00
|
|
|
};
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2019-04-18 15:43:16 +00:00
|
|
|
} // namespace waybar
|