mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor: format && better output management
This commit is contained in:
110
include/bar.hpp
110
include/bar.hpp
@ -1,73 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
#include <glibmm/refptr.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/cssprovider.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/window.h>
|
||||
#include <json/json.h>
|
||||
#include "IModule.hpp"
|
||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||
#include "IModule.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
class Client;
|
||||
class Factory;
|
||||
|
||||
class Bar {
|
||||
public:
|
||||
Bar(const Client&, std::unique_ptr<struct wl_output *>&&, uint32_t);
|
||||
Bar(const Bar&) = delete;
|
||||
~Bar() = default;
|
||||
|
||||
auto toggle() -> void;
|
||||
void handleSignal(int);
|
||||
|
||||
const Client& client;
|
||||
Gtk::Window window;
|
||||
struct wl_surface *surface;
|
||||
struct zwlr_layer_surface_v1 *layer_surface;
|
||||
std::unique_ptr<struct wl_output *> output;
|
||||
std::string output_name;
|
||||
uint32_t wl_name;
|
||||
bool visible = true;
|
||||
bool vertical = false;
|
||||
private:
|
||||
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
|
||||
int32_t);
|
||||
static void handleLogicalSize(void *, struct zxdg_output_v1 *, int32_t,
|
||||
int32_t);
|
||||
static void handleDone(void *, struct zxdg_output_v1 *);
|
||||
static void handleName(void *, struct zxdg_output_v1 *, const char *);
|
||||
static void handleDescription(void *, struct zxdg_output_v1 *,
|
||||
const char *);
|
||||
static void layerSurfaceHandleConfigure(void *,
|
||||
struct zwlr_layer_surface_v1 *, uint32_t, uint32_t, uint32_t);
|
||||
static void layerSurfaceHandleClosed(void *,
|
||||
struct zwlr_layer_surface_v1 *);
|
||||
|
||||
void initBar();
|
||||
bool isValidOutput(const Json::Value &config);
|
||||
void destroyOutput();
|
||||
auto setupConfig() -> void;
|
||||
auto setupWidgets() -> void;
|
||||
auto setupCss() -> void;
|
||||
void getModules(const Factory&, const std::string&);
|
||||
|
||||
uint32_t width_ = 0;
|
||||
uint32_t height_ = 30;
|
||||
Json::Value config_;
|
||||
Glib::RefPtr<Gtk::StyleContext> style_context_;
|
||||
Glib::RefPtr<Gtk::CssProvider> css_provider_;
|
||||
struct zxdg_output_v1 *xdg_output_;
|
||||
Gtk::Box left_;
|
||||
Gtk::Box center_;
|
||||
Gtk::Box right_;
|
||||
Gtk::Box box_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_left_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_center_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_right_;
|
||||
struct waybar_output {
|
||||
struct wl_output *output;
|
||||
std::string name;
|
||||
uint32_t wl_name;
|
||||
struct zxdg_output_v1 *xdg_output;
|
||||
Json::Value config;
|
||||
};
|
||||
|
||||
}
|
||||
class Bar {
|
||||
public:
|
||||
Bar(struct waybar_output* w_output);
|
||||
Bar(const Bar &) = delete;
|
||||
~Bar() = default;
|
||||
|
||||
auto toggle() -> void;
|
||||
void handleSignal(int);
|
||||
|
||||
struct waybar_output* output;
|
||||
Gtk::Window window;
|
||||
struct wl_surface *surface;
|
||||
struct zwlr_layer_surface_v1 *layer_surface;
|
||||
bool visible = true;
|
||||
bool vertical = false;
|
||||
|
||||
private:
|
||||
static void layerSurfaceHandleConfigure(void *, struct zwlr_layer_surface_v1 *, uint32_t,
|
||||
uint32_t, uint32_t);
|
||||
static void layerSurfaceHandleClosed(void *, struct zwlr_layer_surface_v1 *);
|
||||
|
||||
void destroyOutput();
|
||||
void onWindowRealize();
|
||||
auto setupWidgets() -> void;
|
||||
void getModules(const Factory &, const std::string &);
|
||||
void setupAltFormatKeyForModule(const std::string &module_name);
|
||||
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
||||
|
||||
uint32_t width_ = 0;
|
||||
uint32_t height_ = 30;
|
||||
Gtk::Box left_;
|
||||
Gtk::Box center_;
|
||||
Gtk::Box right_;
|
||||
Gtk::Box box_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_left_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_center_;
|
||||
std::vector<std::unique_ptr<waybar::IModule>> modules_right_;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
@ -1,41 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <unistd.h>
|
||||
#include <wordexp.h>
|
||||
#include <fmt/format.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <wayland-client.h>
|
||||
#include <gdk/gdkwayland.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wordexp.h>
|
||||
#include "bar.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
class Client {
|
||||
public:
|
||||
Client(int argc, char *argv[]);
|
||||
int main(int argc, char *argv[]);
|
||||
public:
|
||||
static Client *inst();
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
Glib::RefPtr<Gtk::Application> gtk_app;
|
||||
std::string css_file;
|
||||
std::string config_file;
|
||||
Glib::RefPtr<Gdk::Display> gdk_display;
|
||||
struct wl_display *wl_display = nullptr;
|
||||
struct wl_registry *registry = nullptr;
|
||||
struct zwlr_layer_shell_v1 *layer_shell = nullptr;
|
||||
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr;
|
||||
struct wl_seat *seat = nullptr;
|
||||
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr;
|
||||
std::vector<std::unique_ptr<Bar>> bars;
|
||||
Glib::RefPtr<Gtk::Application> gtk_app;
|
||||
Glib::RefPtr<Gdk::Display> gdk_display;
|
||||
struct wl_display *wl_display = nullptr;
|
||||
struct wl_registry *registry = nullptr;
|
||||
struct zwlr_layer_shell_v1 *layer_shell = nullptr;
|
||||
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr;
|
||||
struct wl_seat *seat = nullptr;
|
||||
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr;
|
||||
std::vector<std::unique_ptr<Bar>> bars;
|
||||
|
||||
private:
|
||||
void setupConfigs(const std::string& config, const std::string& style);
|
||||
void bindInterfaces();
|
||||
const std::string getValidPath(std::vector<std::string> paths);
|
||||
private:
|
||||
Client();
|
||||
void setupConfigs(const std::string &config, const std::string &style);
|
||||
void bindInterfaces();
|
||||
const std::string getValidPath(std::vector<std::string> paths);
|
||||
void handleOutput(std::unique_ptr<struct waybar_output> &output);
|
||||
bool isValidOutput(const Json::Value &config, std::unique_ptr<struct waybar_output> &output);
|
||||
auto setupConfig() -> void;
|
||||
auto setupCss() -> void;
|
||||
|
||||
static void handleGlobal(void *data, struct wl_registry *registry,
|
||||
uint32_t name, const char *interface, uint32_t version);
|
||||
static void handleGlobalRemove(void *data,
|
||||
struct wl_registry *registry, uint32_t name);
|
||||
static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version);
|
||||
static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name);
|
||||
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t, int32_t);
|
||||
static void handleLogicalSize(void *, struct zxdg_output_v1 *, int32_t, int32_t);
|
||||
static void handleDone(void *, struct zxdg_output_v1 *);
|
||||
static void handleName(void *, struct zxdg_output_v1 *, const char *);
|
||||
static void handleDescription(void *, struct zxdg_output_v1 *, const char *);
|
||||
|
||||
Json::Value config_;
|
||||
std::string css_file_;
|
||||
std::string config_file_;
|
||||
Glib::RefPtr<Gtk::StyleContext> style_context_;
|
||||
Glib::RefPtr<Gtk::CssProvider> css_provider_;
|
||||
std::vector<std::unique_ptr<struct waybar_output>> outputs_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar
|
||||
|
@ -28,11 +28,10 @@
|
||||
#endif
|
||||
#include "modules/temperature.hpp"
|
||||
#include "modules/custom.hpp"
|
||||
#include "bar.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
class Bar;
|
||||
|
||||
class Factory {
|
||||
public:
|
||||
Factory(const Bar& bar, const Json::Value& config);
|
||||
|
@ -21,7 +21,7 @@ class Network : public ALabel {
|
||||
auto update() -> void;
|
||||
private:
|
||||
static const uint8_t MAX_RETRY = 5;
|
||||
static const uint8_t EPOLL_MAX = 255;
|
||||
static const uint8_t EPOLL_MAX = 200;
|
||||
|
||||
static int handleEvents(struct nl_msg*, void*);
|
||||
static int handleScan(struct nl_msg*, void*);
|
||||
|
@ -14,6 +14,9 @@ struct JsonParser {
|
||||
{
|
||||
Json::Value root;
|
||||
std::string err;
|
||||
if (data.empty()) {
|
||||
return root;
|
||||
}
|
||||
bool res =
|
||||
reader_->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
if (!res)
|
||||
|
Reference in New Issue
Block a user