feat: output configuration
This commit is contained in:
parent
4d3c2191cb
commit
0ddcf26a45
|
@ -18,7 +18,7 @@ class Bar {
|
||||||
public:
|
public:
|
||||||
Bar(const Client&, std::unique_ptr<struct wl_output *>&&, uint32_t);
|
Bar(const Client&, std::unique_ptr<struct wl_output *>&&, uint32_t);
|
||||||
Bar(const Bar&) = delete;
|
Bar(const Bar&) = delete;
|
||||||
~Bar() = default;
|
~Bar();
|
||||||
|
|
||||||
auto toggle() -> void;
|
auto toggle() -> void;
|
||||||
|
|
||||||
|
@ -44,6 +44,9 @@ class Bar {
|
||||||
static void layerSurfaceHandleClosed(void *,
|
static void layerSurfaceHandleClosed(void *,
|
||||||
struct zwlr_layer_surface_v1 *);
|
struct zwlr_layer_surface_v1 *);
|
||||||
|
|
||||||
|
void initBar();
|
||||||
|
bool isValidOutput(const Json::Value &config);
|
||||||
|
void destroyOutput();
|
||||||
auto setupConfig() -> void;
|
auto setupConfig() -> void;
|
||||||
auto setupWidgets() -> void;
|
auto setupWidgets() -> void;
|
||||||
auto setupCss() -> void;
|
auto setupCss() -> void;
|
||||||
|
|
62
src/bar.cpp
62
src/bar.cpp
|
@ -33,7 +33,15 @@ waybar::Bar::Bar(const Client& client,
|
||||||
GdkWindow *gdk_window = gtk_widget_get_window(wrap);
|
GdkWindow *gdk_window = gtk_widget_get_window(wrap);
|
||||||
gdk_wayland_window_set_use_custom_surface(gdk_window);
|
gdk_wayland_window_set_use_custom_surface(gdk_window);
|
||||||
surface = gdk_wayland_window_get_wl_surface(gdk_window);
|
surface = gdk_wayland_window_get_wl_surface(gdk_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
waybar::Bar::~Bar()
|
||||||
|
{
|
||||||
|
destroyOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::initBar()
|
||||||
|
{
|
||||||
std::size_t layer_top = config_["layer"] == "top"
|
std::size_t layer_top = 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(
|
||||||
|
@ -43,8 +51,7 @@ waybar::Bar::Bar(const Client& client,
|
||||||
.configure = layerSurfaceHandleConfigure,
|
.configure = layerSurfaceHandleConfigure,
|
||||||
.closed = layerSurfaceHandleClosed,
|
.closed = layerSurfaceHandleClosed,
|
||||||
};
|
};
|
||||||
zwlr_layer_surface_v1_add_listener(layer_surface,
|
zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, this);
|
||||||
&layer_surface_listener, this);
|
|
||||||
|
|
||||||
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
|
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
|
||||||
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
|
@ -65,6 +72,17 @@ waybar::Bar::Bar(const Client& client,
|
||||||
setupWidgets();
|
setupWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::destroyOutput()
|
||||||
|
{
|
||||||
|
if (layer_surface != nullptr) {
|
||||||
|
zwlr_layer_surface_v1_destroy(layer_surface);
|
||||||
|
}
|
||||||
|
if (surface != nullptr) {
|
||||||
|
wl_surface_destroy(surface);
|
||||||
|
}
|
||||||
|
wl_output_destroy(*output);
|
||||||
|
}
|
||||||
|
|
||||||
void waybar::Bar::handleLogicalPosition(void* /*data*/,
|
void waybar::Bar::handleLogicalPosition(void* /*data*/,
|
||||||
struct zxdg_output_v1* /*zxdg_output_v1*/, int32_t /*x*/, int32_t /*y*/)
|
struct zxdg_output_v1* /*zxdg_output_v1*/, int32_t /*x*/, int32_t /*y*/)
|
||||||
{
|
{
|
||||||
|
@ -84,11 +102,49 @@ void waybar::Bar::handleDone(void* /*data*/,
|
||||||
// Nothing here
|
// Nothing here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool waybar::Bar::isValidOutput(const Json::Value &config)
|
||||||
|
{
|
||||||
|
bool found = true;
|
||||||
|
if (config["output"].isArray()) {
|
||||||
|
bool in_array = false;
|
||||||
|
for (auto const &output : config["output"]) {
|
||||||
|
if (output.isString() && output.asString() == output_name) {
|
||||||
|
in_array = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found = in_array;
|
||||||
|
}
|
||||||
|
if (config["output"].isString() && config["output"].asString() != output_name) {
|
||||||
|
found = false;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
void waybar::Bar::handleName(void* data, struct zxdg_output_v1* /*xdg_output*/,
|
void waybar::Bar::handleName(void* data, struct zxdg_output_v1* /*xdg_output*/,
|
||||||
const char* name)
|
const char* name)
|
||||||
{
|
{
|
||||||
auto o = static_cast<waybar::Bar *>(data);
|
auto o = static_cast<waybar::Bar *>(data);
|
||||||
o->output_name = name;
|
o->output_name = name;
|
||||||
|
bool found = true;
|
||||||
|
if (o->config_.isArray()) {
|
||||||
|
bool in_array = false;
|
||||||
|
for (auto const &config : o->config_) {
|
||||||
|
if (config.isObject() && o->isValidOutput(config)) {
|
||||||
|
in_array = true;
|
||||||
|
o->config_ = config;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found = in_array;
|
||||||
|
} else {
|
||||||
|
found = o->isValidOutput(o->config_);
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
o->destroyOutput();
|
||||||
|
} else {
|
||||||
|
o->initBar();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Bar::handleDescription(void* /*data*/,
|
void waybar::Bar::handleDescription(void* /*data*/,
|
||||||
|
@ -102,7 +158,6 @@ void waybar::Bar::layerSurfaceHandleConfigure(void* data,
|
||||||
uint32_t height)
|
uint32_t height)
|
||||||
{
|
{
|
||||||
auto o = static_cast<waybar::Bar *>(data);
|
auto o = static_cast<waybar::Bar *>(data);
|
||||||
o->window.show_all();
|
|
||||||
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
||||||
if (width != o->width_ || height != o->height_) {
|
if (width != o->width_ || height != o->height_) {
|
||||||
o->width_ = width;
|
o->width_ = width;
|
||||||
|
@ -221,4 +276,5 @@ auto waybar::Bar::setupWidgets() -> void
|
||||||
for (auto const& module : modules_right_) {
|
for (auto const& module : modules_right_) {
|
||||||
right_.pack_end(*module, false, false, 0);
|
right_.pack_end(*module, false, false, 0);
|
||||||
}
|
}
|
||||||
|
window.show_all();
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ void waybar::modules::Network::createInfoSocket()
|
||||||
}
|
}
|
||||||
nl_socket_disable_seq_check(info_sock_);
|
nl_socket_disable_seq_check(info_sock_);
|
||||||
nl_socket_set_nonblocking(info_sock_);
|
nl_socket_set_nonblocking(info_sock_);
|
||||||
nl_socket_modify_cb(info_sock_, NL_CB_MSG_IN, NL_CB_CUSTOM, handleEvents, this);
|
nl_socket_modify_cb(info_sock_, NL_CB_VALID, NL_CB_CUSTOM, handleEvents, this);
|
||||||
efd_ = epoll_create1(0);
|
efd_ = epoll_create1(0);
|
||||||
if (efd_ < 0) {
|
if (efd_ < 0) {
|
||||||
throw std::runtime_error("Can't create epoll");
|
throw std::runtime_error("Can't create epoll");
|
||||||
|
|
Loading…
Reference in New Issue