waybar/include/bar.hpp

85 lines
2.4 KiB
C++
Raw Normal View History

2018-08-08 23:54:58 +02:00
#pragma once
#include <gdkmm/monitor.h>
#include <glibmm/refptr.h>
2019-07-15 10:06:01 +02:00
#include <gtkmm/box.h>
#include <gtkmm/cssprovider.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <json/json.h>
2019-06-15 14:57:52 +02:00
#include "AModule.hpp"
#include "idle-inhibit-unstable-v1-client-protocol.h"
2018-08-08 23:54:58 +02:00
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
2018-08-08 23:54:58 +02:00
namespace waybar {
2018-08-19 13:39:57 +02:00
class Factory;
struct waybar_output {
Glib::RefPtr<Gdk::Monitor> monitor;
std::string name;
std::unique_ptr<struct zxdg_output_v1, decltype(&zxdg_output_v1_destroy)> xdg_output = {
nullptr, &zxdg_output_v1_destroy};
};
2018-08-08 23:54:58 +02:00
struct bar_margins {
int top = 0;
int right = 0;
int bottom = 0;
int left = 0;
};
class BarSurface {
protected:
BarSurface() = default;
public:
virtual void set_exclusive_zone(bool enable) = 0;
virtual void set_layer(const std::string_view &layer) = 0;
virtual void set_margins(const struct bar_margins &margins) = 0;
virtual void set_position(const std::string_view &position) = 0;
virtual void set_size(uint32_t width, uint32_t height) = 0;
virtual ~BarSurface() = default;
};
2018-08-16 14:29:41 +02:00
class Bar {
public:
2019-05-09 15:10:13 +02:00
Bar(struct waybar_output *w_output, const Json::Value &);
Bar(const Bar &) = delete;
~Bar() = default;
void setVisible(bool visible);
void toggle();
void handleSignal(int);
struct waybar_output *output;
Json::Value config;
struct wl_surface * surface;
bool visible = true;
bool vertical = false;
Gtk::Window window;
private:
void onMap(GdkEventAny *);
auto setupWidgets() -> void;
void getModules(const Factory &, const std::string &);
void setupAltFormatKeyForModule(const std::string &module_name);
void setupAltFormatKeyForModuleList(const char *module_list_name);
std::unique_ptr<BarSurface> surface_impl_;
2019-04-18 17:52:00 +02:00
uint32_t width_ = 0;
2019-04-24 12:37:24 +02:00
uint32_t height_ = 1;
2019-04-18 17:52:00 +02:00
Gtk::Box left_;
Gtk::Box center_;
Gtk::Box right_;
Gtk::Box box_;
2019-06-15 14:57:52 +02:00
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_;
2018-08-16 14:29:41 +02:00
};
2018-08-08 23:54:58 +02:00
} // namespace waybar