#pragma once #include #include #include #include #include #include #include #include #include #include "AModule.hpp" #include "xdg-output-unstable-v1-client-protocol.h" namespace waybar { class Factory; struct waybar_output { Glib::RefPtr monitor; std::string name; std::string identifier; int32_t width; int32_t height; std::unique_ptr xdg_output = { nullptr, &zxdg_output_v1_destroy}; }; enum class bar_layer : uint8_t { BOTTOM, TOP, OVERLAY, }; struct bar_margins { int top = 0; int right = 0; int bottom = 0; int left = 0; }; struct bar_mode { bar_layer layer; bool exclusive; bool passthrough; bool visible; }; #ifdef HAVE_SWAY namespace modules::sway { class BarIpcClient; } #endif // HAVE_SWAY class BarSurface { protected: BarSurface() = default; public: virtual void setExclusiveZone(bool enable) = 0; virtual void setLayer(bar_layer layer) = 0; virtual void setMargins(const struct bar_margins &margins) = 0; virtual void setPassThrough(bool enable) = 0; virtual void setPosition(const std::string_view &position) = 0; virtual void setSize(uint32_t width, uint32_t height) = 0; virtual void commit(){}; virtual ~BarSurface() = default; }; class Bar { public: using bar_mode_map = std::map; static const bar_mode_map PRESET_MODES; static const std::string_view MODE_DEFAULT; static const std::string_view MODE_INVISIBLE; Bar(struct waybar_output *w_output, const Json::Value &); Bar(const Bar &) = delete; ~Bar(); void setMode(const std::string_view &); 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; #ifdef HAVE_SWAY std::string bar_id; #endif private: void onMap(GdkEventAny *); auto setupWidgets() -> void; void getModules(const Factory &, const std::string &, Gtk::Box*); void setupAltFormatKeyForModule(const std::string &module_name); void setupAltFormatKeyForModuleList(const char *module_list_name); 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}; std::unique_ptr surface_impl_; Gtk::Box left_; Gtk::Box center_; Gtk::Box right_; Gtk::Box box_; std::vector> modules_left_; std::vector> modules_center_; std::vector> modules_right_; #ifdef HAVE_SWAY using BarIpcClient = modules::sway::BarIpcClient; std::unique_ptr _ipc_client; #endif std::vector> modules_all_; }; } // namespace waybar