2018-08-08 23:54:58 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-08-27 20:57:23 -07:00
|
|
|
#include <gdkmm/monitor.h>
|
2019-01-08 21:05:44 +01:00
|
|
|
#include <glibmm/refptr.h>
|
2019-07-15 10:06:01 +02:00
|
|
|
#include <gtkmm/box.h>
|
2019-01-08 21:05:44 +01:00
|
|
|
#include <gtkmm/cssprovider.h>
|
2019-04-18 17:43:16 +02:00
|
|
|
#include <gtkmm/main.h>
|
2019-01-08 21:05:44 +01:00
|
|
|
#include <gtkmm/window.h>
|
2019-04-18 17:43:16 +02:00
|
|
|
#include <json/json.h>
|
2020-10-21 22:16:12 -07:00
|
|
|
|
2020-10-19 19:34:48 -07:00
|
|
|
#include <memory>
|
2024-05-28 09:19:21 +02:00
|
|
|
#include <optional>
|
2020-10-19 19:34:48 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
2019-06-15 14:57:52 +02:00
|
|
|
#include "AModule.hpp"
|
2023-10-14 13:08:44 -03:00
|
|
|
#include "group.hpp"
|
2025-02-09 13:05:36 +02:00
|
|
|
#include "util/kill_signal.hpp"
|
2018-08-11 00:32:59 +02:00
|
|
|
#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;
|
2019-04-18 17:43:16 +02:00
|
|
|
struct waybar_output {
|
2019-08-27 20:57:23 -07:00
|
|
|
Glib::RefPtr<Gdk::Monitor> monitor;
|
2022-04-06 08:37:19 +02:00
|
|
|
std::string name;
|
|
|
|
|
std::string identifier;
|
2019-08-27 20:57:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<struct zxdg_output_v1, decltype(&zxdg_output_v1_destroy)> xdg_output = {
|
|
|
|
|
nullptr, &zxdg_output_v1_destroy};
|
2018-08-16 14:29:41 +02:00
|
|
|
};
|
2018-08-08 23:54:58 +02:00
|
|
|
|
2020-10-22 23:04:58 -07:00
|
|
|
enum class bar_layer : uint8_t {
|
|
|
|
|
BOTTOM,
|
|
|
|
|
TOP,
|
|
|
|
|
OVERLAY,
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-21 22:16:12 -07:00
|
|
|
struct bar_margins {
|
|
|
|
|
int top = 0;
|
|
|
|
|
int right = 0;
|
|
|
|
|
int bottom = 0;
|
|
|
|
|
int left = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-19 19:29:51 -08:00
|
|
|
struct bar_mode {
|
2024-08-17 22:40:56 -07:00
|
|
|
bar_layer layer;
|
2022-04-06 08:37:19 +02:00
|
|
|
bool exclusive;
|
|
|
|
|
bool passthrough;
|
|
|
|
|
bool visible;
|
2021-11-19 19:29:51 -08:00
|
|
|
};
|
|
|
|
|
|
2020-10-19 19:34:48 -07:00
|
|
|
#ifdef HAVE_SWAY
|
|
|
|
|
namespace modules::sway {
|
|
|
|
|
class BarIpcClient;
|
|
|
|
|
}
|
|
|
|
|
#endif // HAVE_SWAY
|
|
|
|
|
|
2024-08-19 12:35:52 +08:00
|
|
|
class Bar : public sigc::trackable {
|
2019-04-18 17:43:16 +02:00
|
|
|
public:
|
2024-02-19 01:50:40 -08:00
|
|
|
using bar_mode_map = std::map<std::string, struct bar_mode>;
|
2022-04-06 08:37:19 +02:00
|
|
|
static const bar_mode_map PRESET_MODES;
|
2024-02-19 01:50:40 -08:00
|
|
|
static const std::string MODE_DEFAULT;
|
|
|
|
|
static const std::string MODE_INVISIBLE;
|
2021-11-19 19:29:51 -08:00
|
|
|
|
2019-05-09 15:10:13 +02:00
|
|
|
Bar(struct waybar_output *w_output, const Json::Value &);
|
2019-04-18 17:43:16 +02:00
|
|
|
Bar(const Bar &) = delete;
|
2020-10-19 19:34:48 -07:00
|
|
|
~Bar();
|
2019-04-18 17:43:16 +02:00
|
|
|
|
2024-02-19 01:50:40 -08:00
|
|
|
void setMode(const std::string &mode);
|
2024-07-20 09:33:13 -05:00
|
|
|
void setVisible(bool value);
|
2020-10-21 22:16:12 -07:00
|
|
|
void toggle();
|
2025-02-09 13:05:36 +02:00
|
|
|
void show();
|
|
|
|
|
void hide();
|
2019-04-18 17:43:16 +02:00
|
|
|
void handleSignal(int);
|
2025-02-09 13:05:36 +02:00
|
|
|
util::KillSignalAction getOnSigusr1Action();
|
|
|
|
|
util::KillSignalAction getOnSigusr2Action();
|
2019-04-18 17:43:16 +02:00
|
|
|
|
2019-12-27 16:31:18 -08:00
|
|
|
struct waybar_output *output;
|
2022-04-06 08:37:19 +02:00
|
|
|
Json::Value config;
|
|
|
|
|
struct wl_surface *surface;
|
|
|
|
|
bool visible = true;
|
|
|
|
|
Gtk::Window window;
|
2024-02-14 19:14:39 -08:00
|
|
|
Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL;
|
|
|
|
|
Gtk::PositionType position = Gtk::POS_TOP;
|
2019-04-18 17:43:16 +02:00
|
|
|
|
2023-08-21 22:03:20 +03:00
|
|
|
int x_global;
|
|
|
|
|
int y_global;
|
|
|
|
|
|
2020-10-19 19:34:48 -07:00
|
|
|
#ifdef HAVE_SWAY
|
|
|
|
|
std::string bar_id;
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-04-18 17:43:16 +02:00
|
|
|
private:
|
2020-10-21 22:16:12 -07:00
|
|
|
void onMap(GdkEventAny *);
|
2019-04-18 17:43:16 +02:00
|
|
|
auto setupWidgets() -> void;
|
2023-10-14 13:08:44 -03:00
|
|
|
void getModules(const Factory &, const std::string &, waybar::Group *);
|
2019-04-18 17:43:16 +02:00
|
|
|
void setupAltFormatKeyForModule(const std::string &module_name);
|
|
|
|
|
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
2021-11-19 19:29:51 -08:00
|
|
|
void setMode(const bar_mode &);
|
2024-02-19 02:55:55 -08:00
|
|
|
void setPassThrough(bool passthrough);
|
|
|
|
|
void setPosition(Gtk::PositionType position);
|
2023-08-21 22:03:20 +03:00
|
|
|
void onConfigure(GdkEventConfigure *ev);
|
|
|
|
|
void configureGlobalOffset(int width, int height);
|
|
|
|
|
void onOutputGeometryChanged();
|
2021-11-19 19:29:51 -08:00
|
|
|
|
|
|
|
|
/* Copy initial set of modes to allow customization */
|
|
|
|
|
bar_mode_map configured_modes = PRESET_MODES;
|
2022-04-06 08:37:19 +02:00
|
|
|
std::string last_mode_{MODE_DEFAULT};
|
2019-04-18 17:43:16 +02:00
|
|
|
|
2023-08-21 22:03:20 +03:00
|
|
|
struct bar_margins margins_;
|
2024-02-19 02:55:55 -08:00
|
|
|
uint32_t width_, height_;
|
|
|
|
|
bool passthrough_;
|
2023-08-21 22:03:20 +03:00
|
|
|
|
2022-04-06 08:37:19 +02:00
|
|
|
Gtk::Box left_;
|
|
|
|
|
Gtk::Box center_;
|
|
|
|
|
Gtk::Box right_;
|
|
|
|
|
Gtk::Box box_;
|
2021-12-03 23:56:51 +01: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-19 19:34:48 -07:00
|
|
|
#ifdef HAVE_SWAY
|
|
|
|
|
using BarIpcClient = modules::sway::BarIpcClient;
|
|
|
|
|
std::unique_ptr<BarIpcClient> _ipc_client;
|
|
|
|
|
#endif
|
2021-12-03 23:56:51 +01:00
|
|
|
std::vector<std::shared_ptr<waybar::AModule>> modules_all_;
|
2025-02-09 13:05:36 +02:00
|
|
|
|
2025-03-07 07:45:11 +02:00
|
|
|
waybar::util::KillSignalAction onSigusr1 = util::SIGNALACTION_DEFAULT_SIGUSR1;
|
|
|
|
|
waybar::util::KillSignalAction onSigusr2 = util::SIGNALACTION_DEFAULT_SIGUSR2;
|
2019-04-18 17:43:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace waybar
|