mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat: allow waybar to be positioned on left/right
This commit is contained in:
parent
f700319d7f
commit
47142a61ae
@ -32,6 +32,7 @@ class Bar {
|
|||||||
std::string output_name;
|
std::string output_name;
|
||||||
uint32_t wl_name;
|
uint32_t wl_name;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
bool vertical = false;
|
||||||
private:
|
private:
|
||||||
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
|
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
|
||||||
int32_t);
|
int32_t);
|
||||||
|
@ -11,7 +11,7 @@ namespace waybar::modules::SNI {
|
|||||||
|
|
||||||
class Tray : public IModule {
|
class Tray : public IModule {
|
||||||
public:
|
public:
|
||||||
Tray(const std::string&, const Json::Value&);
|
Tray(const std::string&, const Bar&, const Json::Value&);
|
||||||
~Tray() = default;
|
~Tray() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget &();
|
operator Gtk::Widget &();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"layer": "top", // Waybar at top layer
|
"layer": "top", // Waybar at top layer
|
||||||
// "position": "bottom", // Waybar at the bottom of your screen
|
// "position": "bottom", // Waybar position (top|bottom|left|right)
|
||||||
// "height": 30, // Waybar height
|
// "height": 30, // Waybar height
|
||||||
// "width": 1280, // Waybar width
|
// "width": 1280, // Waybar width
|
||||||
// Choose the order of the modules
|
// Choose the order of the modules
|
||||||
|
49
src/bar.cpp
49
src/bar.cpp
@ -28,6 +28,12 @@ waybar::Bar::Bar(const Client& client,
|
|||||||
setupConfig();
|
setupConfig();
|
||||||
setupCss();
|
setupCss();
|
||||||
|
|
||||||
|
if (config_["position"] == "right" || config_["position"] == "left") {
|
||||||
|
vertical = true;
|
||||||
|
height_ = 0;
|
||||||
|
width_ = 30;
|
||||||
|
}
|
||||||
|
|
||||||
auto wrap = reinterpret_cast<GtkWidget*>(window.gobj());
|
auto wrap = reinterpret_cast<GtkWidget*>(window.gobj());
|
||||||
gtk_widget_realize(wrap);
|
gtk_widget_realize(wrap);
|
||||||
GdkWindow *gdk_window = gtk_widget_get_window(wrap);
|
GdkWindow *gdk_window = gtk_widget_get_window(wrap);
|
||||||
@ -84,10 +90,10 @@ void waybar::Bar::initBar()
|
|||||||
setupAltFormatKeyForModuleList("modules-left");
|
setupAltFormatKeyForModuleList("modules-left");
|
||||||
setupAltFormatKeyForModuleList("modules-right");
|
setupAltFormatKeyForModuleList("modules-right");
|
||||||
setupAltFormatKeyForModuleList("modules-center");
|
setupAltFormatKeyForModuleList("modules-center");
|
||||||
std::size_t layer_top = config_["layer"] == "top"
|
std::size_t layer = config_["layer"] == "top"
|
||||||
? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
|
? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
|
||||||
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
client.layer_shell, surface, *output, layer_top, "waybar");
|
client.layer_shell, surface, *output, layer, "waybar");
|
||||||
|
|
||||||
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
||||||
.configure = layerSurfaceHandleConfigure,
|
.configure = layerSurfaceHandleConfigure,
|
||||||
@ -95,18 +101,30 @@ void waybar::Bar::initBar()
|
|||||||
};
|
};
|
||||||
zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, this);
|
zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, this);
|
||||||
|
|
||||||
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
|
|
||||||
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
|
||||||
if (config_["position"] == "bottom") {
|
|
||||||
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
|
||||||
} else {
|
|
||||||
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto height = config_["height"].isUInt() ? config_["height"].asUInt() : height_;
|
auto height = config_["height"].isUInt() ? config_["height"].asUInt() : height_;
|
||||||
auto width = config_["width"].isUInt() ? config_["width"].asUInt() : width_;
|
auto width = config_["width"].isUInt() ? config_["width"].asUInt() : width_;
|
||||||
|
|
||||||
|
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
||||||
|
if (config_["position"] == "bottom") {
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||||
|
} else if (config_["position"] == "left") {
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
|
||||||
|
} else if (config_["position"] == "right") {
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
|
}
|
||||||
|
if (anchor == ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM || anchor == ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) {
|
||||||
|
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
|
} else if (anchor == ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT || anchor == ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
|
||||||
|
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||||
|
left_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
|
||||||
|
center_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
|
||||||
|
right_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
|
||||||
|
box_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
|
||||||
|
vertical = true;
|
||||||
|
}
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
|
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, height);
|
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, vertical ? width : height);
|
||||||
zwlr_layer_surface_v1_set_size(layer_surface, width, height);
|
zwlr_layer_surface_v1_set_size(layer_surface, width, height);
|
||||||
|
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
@ -213,13 +231,18 @@ void waybar::Bar::layerSurfaceHandleConfigure(void* data,
|
|||||||
o->window.set_size_request(o->width_, o->height_);
|
o->window.set_size_request(o->width_, o->height_);
|
||||||
o->window.resize(o->width_, o->height_);
|
o->window.resize(o->width_, o->height_);
|
||||||
|
|
||||||
int dummy_width, min_height;
|
int min_width, min_height;
|
||||||
o->window.get_size(dummy_width, min_height);
|
o->window.get_size(min_width, min_height);
|
||||||
if (o->height_ < static_cast<uint32_t>(min_height)) {
|
if (o->height_ < static_cast<uint32_t>(min_height)) {
|
||||||
std::cout << fmt::format("Requested height: {} exceeds the minimum \
|
std::cout << fmt::format("Requested height: {} exceeds the minimum \
|
||||||
height: {} required by the modules", o->height_, min_height) << std::endl;
|
height: {} required by the modules", o->height_, min_height) << std::endl;
|
||||||
o->height_ = min_height;
|
o->height_ = min_height;
|
||||||
}
|
}
|
||||||
|
if (o->width_ < static_cast<uint32_t>(min_width)) {
|
||||||
|
std::cout << fmt::format("Requested width: {} exceeds the minimum \
|
||||||
|
width: {} required by the modules", o->height_, min_width) << std::endl;
|
||||||
|
o->width_ = min_width;
|
||||||
|
}
|
||||||
std::cout << fmt::format(
|
std::cout << fmt::format(
|
||||||
"Bar configured (width: {}, height: {}) for output: {}",
|
"Bar configured (width: {}, height: {}) for output: {}",
|
||||||
o->width_, o->height_, o->output_name) << std::endl;
|
o->width_, o->height_, o->output_name) << std::endl;
|
||||||
|
@ -38,7 +38,7 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
|||||||
}
|
}
|
||||||
#ifdef HAVE_DBUSMENU
|
#ifdef HAVE_DBUSMENU
|
||||||
if (ref == "tray") {
|
if (ref == "tray") {
|
||||||
return new waybar::modules::SNI::Tray(id, config_[name]);
|
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBNL
|
#ifdef HAVE_LIBNL
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
waybar::modules::SNI::Tray::Tray(const std::string& id, const Json::Value &config)
|
waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar,
|
||||||
: config_(config), watcher_(), host_(nb_hosts_, config,
|
const Json::Value &config)
|
||||||
|
: config_(config),
|
||||||
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
|
watcher_(), host_(nb_hosts_, config,
|
||||||
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::onRemove, this, std::placeholders::_1))
|
std::bind(&Tray::onRemove, this, std::placeholders::_1))
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
waybar::modules::sway::Workspaces::Workspaces(const std::string& id, const Bar& bar,
|
waybar::modules::sway::Workspaces::Workspaces(const std::string& id, const Bar& bar,
|
||||||
const Json::Value& config)
|
const Json::Value& config)
|
||||||
: bar_(bar), config_(config), scrolling_(false)
|
: bar_(bar), config_(config),
|
||||||
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
|
scrolling_(false)
|
||||||
{
|
{
|
||||||
box_.set_name("workspaces");
|
box_.set_name("workspaces");
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user