mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
style: clean class
This commit is contained in:
parent
a00894a5a6
commit
b987668f97
@ -13,18 +13,17 @@ namespace waybar {
|
|||||||
Client& client;
|
Client& client;
|
||||||
Gtk::Window window;
|
Gtk::Window window;
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
struct zwlr_layer_surface_v1 *layer_surface;
|
struct zwlr_layer_surface_v1 *layerSurface;
|
||||||
std::unique_ptr<struct wl_output *> output;
|
std::unique_ptr<struct wl_output *> output;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
auto set_width(int) -> void;
|
auto setWidth(int) -> void;
|
||||||
auto toggle() -> void;
|
auto toggle() -> void;
|
||||||
private:
|
private:
|
||||||
auto setup_widgets() -> void;
|
auto _setupWidgets() -> void;
|
||||||
auto setup_css() -> void;
|
auto _setupCss() -> void;
|
||||||
|
int _width = 10;
|
||||||
int width = 10;
|
Glib::RefPtr<Gtk::StyleContext> _styleContext;
|
||||||
Glib::RefPtr<Gtk::StyleContext> style_context;
|
Glib::RefPtr<Gtk::CssProvider> _cssProvider;
|
||||||
Glib::RefPtr<Gtk::CssProvider> css_provider;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,42 +11,42 @@ window {
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-selector button {
|
.workspaces button {
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: white;
|
color: white;
|
||||||
border-bottom: 3px solid transparent;
|
border-bottom: 3px solid transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-selector button.current {
|
.workspaces button.current {
|
||||||
background: #64727D;
|
background: #64727D;
|
||||||
border-bottom: 3px solid white;
|
border-bottom: 3px solid white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clock-widget, .battery-status, .cpu-widget, .memory-widget {
|
.clock, .battery, .cpu, .memory {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin: 0 5px;
|
margin: 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clock-widget {
|
.clock {
|
||||||
background-color: #64727D;
|
background-color: #64727D;
|
||||||
}
|
}
|
||||||
|
|
||||||
.battery-status {
|
.battery {
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.battery-status.battery-charging {
|
.battery.charging {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: #26A65B;
|
background-color: #26A65B;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cpu-widget {
|
.cpu {
|
||||||
background: #2ecc71;
|
background: #2ecc71;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.memory-widget {
|
.memory {
|
||||||
background: #9b59b6;
|
background: #9b59b6;
|
||||||
}
|
}
|
||||||
|
46
src/bar.cpp
46
src/bar.cpp
@ -21,8 +21,7 @@ static void handle_mode(void *data, struct wl_output *wl_output, uint32_t f,
|
|||||||
int32_t w, int32_t h, int32_t refresh)
|
int32_t w, int32_t h, int32_t refresh)
|
||||||
{
|
{
|
||||||
auto o = reinterpret_cast<waybar::Bar *>(data);
|
auto o = reinterpret_cast<waybar::Bar *>(data);
|
||||||
std::cout << fmt::format("Bar width configured: {}", w) << std::endl;
|
o->setWidth(w);
|
||||||
o->set_width(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_done(void *data, struct wl_output *)
|
static void handle_done(void *data, struct wl_output *)
|
||||||
@ -64,10 +63,10 @@ static void layer_surface_handle_closed(void *data,
|
|||||||
struct zwlr_layer_surface_v1 *surface)
|
struct zwlr_layer_surface_v1 *surface)
|
||||||
{
|
{
|
||||||
auto o = reinterpret_cast<waybar::Bar *>(data);
|
auto o = reinterpret_cast<waybar::Bar *>(data);
|
||||||
zwlr_layer_surface_v1_destroy(o->layer_surface);
|
zwlr_layer_surface_v1_destroy(o->layerSurface);
|
||||||
o->layer_surface = NULL;
|
o->layerSurface = nullptr;
|
||||||
wl_surface_destroy(o->surface);
|
wl_surface_destroy(o->surface);
|
||||||
o->surface = NULL;
|
o->surface = nullptr;
|
||||||
o->window.close();
|
o->window.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,45 +82,46 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
|
|||||||
wl_output_add_listener(*output, &outputListener, this);
|
wl_output_add_listener(*output, &outputListener, this);
|
||||||
window.set_title("waybar");
|
window.set_title("waybar");
|
||||||
window.set_decorated(false);
|
window.set_decorated(false);
|
||||||
// window.set_resizable(false);
|
_setupCss();
|
||||||
setup_css();
|
_setupWidgets();
|
||||||
setup_widgets();
|
|
||||||
gtk_widget_realize(GTK_WIDGET(window.gobj()));
|
gtk_widget_realize(GTK_WIDGET(window.gobj()));
|
||||||
GdkWindow *gdkWindow = gtk_widget_get_window(GTK_WIDGET(window.gobj()));
|
GdkWindow *gdkWindow = gtk_widget_get_window(GTK_WIDGET(window.gobj()));
|
||||||
gdk_wayland_window_set_use_custom_surface(gdkWindow);
|
gdk_wayland_window_set_use_custom_surface(gdkWindow);
|
||||||
surface = gdk_wayland_window_get_wl_surface(gdkWindow);
|
surface = gdk_wayland_window_get_wl_surface(gdkWindow);
|
||||||
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
layerSurface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
client.layer_shell, surface, *output, ZWLR_LAYER_SHELL_V1_LAYER_TOP,
|
client.layer_shell, surface, *output, ZWLR_LAYER_SHELL_V1_LAYER_TOP,
|
||||||
"waybar");
|
"waybar");
|
||||||
zwlr_layer_surface_v1_set_anchor(layer_surface,
|
zwlr_layer_surface_v1_set_anchor(layerSurface,
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
|
||||||
zwlr_layer_surface_v1_set_size(layer_surface, width, client.height);
|
zwlr_layer_surface_v1_set_size(layerSurface, _width, client.height);
|
||||||
zwlr_layer_surface_v1_add_listener(layer_surface, &layerSurfaceListener,
|
zwlr_layer_surface_v1_add_listener(layerSurface, &layerSurfaceListener,
|
||||||
this);
|
this);
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::Bar::setup_css() -> void
|
auto waybar::Bar::_setupCss() -> void
|
||||||
{
|
{
|
||||||
css_provider = Gtk::CssProvider::create();
|
_cssProvider = Gtk::CssProvider::create();
|
||||||
style_context = Gtk::StyleContext::create();
|
_styleContext = Gtk::StyleContext::create();
|
||||||
|
|
||||||
// load our css file, wherever that may be hiding
|
// load our css file, wherever that may be hiding
|
||||||
if (css_provider->load_from_path(client.css_file))
|
if (_cssProvider->load_from_path(client.css_file))
|
||||||
{
|
{
|
||||||
Glib::RefPtr<Gdk::Screen> screen = window.get_screen();
|
Glib::RefPtr<Gdk::Screen> screen = window.get_screen();
|
||||||
style_context->add_provider_for_screen(screen, css_provider,
|
_styleContext->add_provider_for_screen(screen, _cssProvider,
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::Bar::set_width(int width) -> void
|
auto waybar::Bar::setWidth(int width) -> void
|
||||||
{
|
{
|
||||||
this->width = width;
|
std::cout << fmt::format("Bar width configured: {}", width) << std::endl;
|
||||||
|
if (width == this->_width) return;
|
||||||
|
this->_width = width;
|
||||||
window.set_size_request(width);
|
window.set_size_request(width);
|
||||||
window.resize(width, client.height);
|
window.resize(width, client.height);
|
||||||
zwlr_layer_surface_v1_set_size(layer_surface, width, 40);
|
zwlr_layer_surface_v1_set_size(layerSurface, width, 40);
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +129,11 @@ auto waybar::Bar::toggle() -> void
|
|||||||
{
|
{
|
||||||
visible = !visible;
|
visible = !visible;
|
||||||
auto zone = visible ? client.height : 0;
|
auto zone = visible ? client.height : 0;
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, zone);
|
zwlr_layer_surface_v1_set_exclusive_zone(layerSurface, zone);
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::Bar::setup_widgets() -> void
|
auto waybar::Bar::_setupWidgets() -> void
|
||||||
{
|
{
|
||||||
auto &left = *Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
|
auto &left = *Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
|
||||||
auto ¢er = *Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
|
auto ¢er = *Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
|
||||||
|
@ -13,7 +13,7 @@ waybar::modules::Battery::Battery()
|
|||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
_label.get_style_context()->add_class("battery-status");
|
_label.get_style_context()->add_class("battery");
|
||||||
|
|
||||||
_thread = [this] {
|
_thread = [this] {
|
||||||
update();
|
update();
|
||||||
@ -31,9 +31,9 @@ auto waybar::modules::Battery::update() -> void
|
|||||||
std::ifstream(bat / "charge_full") >> full;
|
std::ifstream(bat / "charge_full") >> full;
|
||||||
std::ifstream(bat / "status") >> status;
|
std::ifstream(bat / "status") >> status;
|
||||||
if (status == "Charging") {
|
if (status == "Charging") {
|
||||||
_label.get_style_context()->add_class("battery-charging");
|
_label.get_style_context()->add_class("charging");
|
||||||
} else {
|
} else {
|
||||||
_label.get_style_context()->remove_class("battery-charging");
|
_label.get_style_context()->remove_class("charging");
|
||||||
}
|
}
|
||||||
int pct = float(now) / float(full) * 100.f;
|
int pct = float(now) / float(full) * 100.f;
|
||||||
_label.set_text_with_mnemonic(fmt::format("{}% {}", pct, ""));
|
_label.set_text_with_mnemonic(fmt::format("{}% {}", pct, ""));
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
waybar::modules::Clock::Clock()
|
waybar::modules::Clock::Clock()
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("clock-widget");
|
_label.get_style_context()->add_class("clock");
|
||||||
_thread = [this] {
|
_thread = [this] {
|
||||||
auto now = waybar::chrono::clock::now();
|
auto now = waybar::chrono::clock::now();
|
||||||
auto t = std::time(nullptr);
|
auto t = std::time(nullptr);
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
|
|
||||||
waybar::modules::Cpu::Cpu()
|
waybar::modules::Cpu::Cpu()
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("cpu-widget");
|
_label.get_style_context()->add_class("cpu");
|
||||||
_thread = [this] {
|
_thread = [this] {
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
if (!sysinfo(&info)) {
|
if (!sysinfo(&info)) {
|
||||||
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
|
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
|
||||||
_label.set_text(fmt::format("{:.{}f}% ",
|
_label.set_text(fmt::format("{:.{}f}% ",
|
||||||
info.loads[0] * f_load * 100 / get_nprocs(), 1));
|
info.loads[0] * f_load * 100 / get_nprocs(), 0));
|
||||||
}
|
}
|
||||||
_thread.sleep_for(chrono::seconds(30));
|
_thread.sleep_for(chrono::seconds(10));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,13 +3,12 @@
|
|||||||
|
|
||||||
waybar::modules::Memory::Memory()
|
waybar::modules::Memory::Memory()
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("memory-widget");
|
_label.get_style_context()->add_class("memory");
|
||||||
_thread = [this] {
|
_thread = [this] {
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
if (!sysinfo(&info)) {
|
if (!sysinfo(&info)) {
|
||||||
double available = (double)info.freeram / (double)info.totalram;
|
double available = (double)info.freeram / (double)info.totalram;
|
||||||
std::cout << available << std::endl;
|
_label.set_text(fmt::format("{:.{}f}% ", available * 100, 0));
|
||||||
_label.set_text(fmt::format("{:.{}f}% ", available * 100, 1));
|
|
||||||
}
|
}
|
||||||
_thread.sleep_for(chrono::seconds(30));
|
_thread.sleep_for(chrono::seconds(30));
|
||||||
};
|
};
|
||||||
|
@ -24,7 +24,7 @@ static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
|
|||||||
waybar::modules::WorkspaceSelector::WorkspaceSelector(Bar &bar)
|
waybar::modules::WorkspaceSelector::WorkspaceSelector(Bar &bar)
|
||||||
: thread(nullptr), _bar(bar), _box(Gtk::manage(new Gtk::Box))
|
: thread(nullptr), _bar(bar), _box(Gtk::manage(new Gtk::Box))
|
||||||
{
|
{
|
||||||
_box->get_style_context()->add_class("workspace-selector");
|
_box->get_style_context()->add_class("workspaces");
|
||||||
std::string socketPath = get_socketpath();
|
std::string socketPath = get_socketpath();
|
||||||
_ipcSocketfd = ipc_open_socket(socketPath);
|
_ipcSocketfd = ipc_open_socket(socketPath);
|
||||||
_ipcEventSocketfd = ipc_open_socket(socketPath);
|
_ipcEventSocketfd = ipc_open_socket(socketPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user