Compare commits

...

13 Commits
master ... gtk4

Author SHA1 Message Date
Alexis Rouillard b54e2c16f3
Merge pull request #2927 from LukashonakV/gtk4
Gtk4. Pick up PR#2836
2024-02-19 22:42:00 +01:00
Aleksei Bavshin b32abf9966
refactor: merge BarSurface into Bar
With only one implementation left, the abstraction is no longer
necessary.
2024-02-19 23:02:47 +03:00
Aleksei Bavshin 2469851865
fix(bar): use std::string for mode names
`string_view` leads to UAF when reading custom mode definitions from the
configuration.
2024-02-19 22:47:25 +03:00
Aleksei Bavshin a6d33db20f
feat: add `module` class to the root elements of the modules
Previously, the only way to select all the module labels was with the
following kind of selector:
```css
.modules-left > widget > label,
.modules-center > widget > label,
.modules-right > widget > label {
    /* ... */
}
```
(and a matching block for the `box` containers).

Now, this can be expressed as
```css
label.module, box.module {
    /* ... */
}
```
2024-02-19 22:26:05 +03:00
Aleksei Bavshin 5a4a1a5595
refactor(bar): use Gtk enums for position and orientation
Ensure that the position and the corresponding CSS class on window are
always set.
2024-02-19 22:24:08 +03:00
Aleksei Bavshin d6d164a27d
feat!: drop RawSurfaceImpl with direct use of wlr-layer-shell
BREAKING CHANGE: gtk-layer-shell is now required and unconditionally
used. The corresponding config option is removed.

As a part of preparation for future versions of GTK, remove an ability
to use wlr-layer-shell directly. The APIs it required were dropped in
GTK4, and with the menus/tooltips positioning issue being practically
unsolvable it doesn't make sense to keep maintaining the code.
2024-02-17 22:00:38 +03:00
Aleksei Bavshin 8e33333c0b
chore: update gtk-layer-shell subproject to 0.8.2 2024-02-17 21:52:03 +03:00
Alex f1abc186b2 fix: merge 🥲 2024-01-12 10:08:20 +01:00
Alex d5bc2f3335 Merge remote-tracking branch 'luka/gtk4' into gtk4 2024-01-12 10:06:47 +01:00
Viktar Lukashonak f8eb01def2
Clean code
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2024-01-08 22:48:57 +03:00
Viktar Lukashonak 158767b5b4
Drop break point
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2024-01-08 22:26:13 +03:00
Viktar Lukashonak aa95c04842
Gtk4. Stylecontext
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2024-01-08 22:20:23 +03:00
Viktar Lukashonak 4a88cb693a
GTK4 base compilation
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2024-01-08 19:03:42 +03:00
34 changed files with 350 additions and 1343 deletions

View File

@ -25,7 +25,7 @@ class ALabel : public AModule {
bool alt_ = false; bool alt_ = false;
std::string default_format_; std::string default_format_;
bool handleToggle(GdkEventButton *const &e) override; //todo bool handleToggle(GdkEventButton *const &e) override;
virtual std::string getState(uint8_t value, bool lesser = false); virtual std::string getState(uint8_t value, bool lesser = false);
}; };

View File

@ -2,7 +2,7 @@
#include <glibmm/dispatcher.h> #include <glibmm/dispatcher.h>
#include <glibmm/markup.h> #include <glibmm/markup.h>
#include <gtkmm/eventbox.h> //#include <gtkmm/eventbox.h>
#include <json/json.h> #include <json/json.h>
#include "IModule.hpp" #include "IModule.hpp"
@ -11,6 +11,8 @@ namespace waybar {
class AModule : public IModule { class AModule : public IModule {
public: public:
static constexpr const char *MODULE_CLASS = "module";
virtual ~AModule(); virtual ~AModule();
auto update() -> void override; auto update() -> void override;
virtual auto refresh(int) -> void{}; virtual auto refresh(int) -> void{};
@ -28,25 +30,25 @@ class AModule : public IModule {
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT }; enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
SCROLL_DIR getScrollDir(GdkEventScroll *e); // SCROLL_DIR getScrollDir(GdkEventScroll *e);
bool tooltipEnabled(); bool tooltipEnabled();
const std::string name_; const std::string name_;
const Json::Value &config_; const Json::Value &config_;
Gtk::EventBox event_box_; // Gtk::EventBox event_box_;
virtual bool handleToggle(GdkEventButton *const &ev); // virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleScroll(GdkEventScroll *); // virtual bool handleScroll(GdkEventScroll *);
virtual bool handleRelease(GdkEventButton *const &ev); // virtual bool handleRelease(GdkEventButton *const &ev);
private: private:
bool handleUserEvent(GdkEventButton *const &ev); // bool handleUserEvent(GdkEventButton *const &ev);
const bool isTooltip; const bool isTooltip;
std::vector<int> pid_; std::vector<int> pid_;
gdouble distance_scrolled_y_; gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_; gdouble distance_scrolled_x_;
std::map<std::string, std::string> eventActionMap_; std::map<std::string, std::string> eventActionMap_;
static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{ /* static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"}, {std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
{std::make_pair(1, GdkEventType::GDK_BUTTON_RELEASE), "on-click-release"}, {std::make_pair(1, GdkEventType::GDK_BUTTON_RELEASE), "on-click-release"},
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"}, {std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
@ -66,7 +68,7 @@ class AModule : public IModule {
{std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"}, {std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"},
{std::make_pair(9, GdkEventType::GDK_BUTTON_RELEASE), "on-click-forward-release"}, {std::make_pair(9, GdkEventType::GDK_BUTTON_RELEASE), "on-click-forward-release"},
{std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"}, {std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"},
{std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}}; {std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}};*/
}; };
} // namespace waybar } // namespace waybar

View File

@ -1,18 +1,13 @@
#pragma once #pragma once
#include <gdkmm/monitor.h> #include <gdkmm/monitor.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/centerbox.h>
#include <gtkmm/cssprovider.h> #include <gtkmm/cssprovider.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <json/json.h>
#include <memory>
#include <vector>
#include "AModule.hpp" #include "AModule.hpp"
#include "group.hpp" //#include "group.hpp"
#include "xdg-output-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h"
namespace waybar { namespace waybar {
@ -53,34 +48,18 @@ class BarIpcClient;
} }
#endif // HAVE_SWAY #endif // HAVE_SWAY
class BarSurface {
protected:
BarSurface() = default;
public:
virtual void setExclusiveZone(bool enable) = 0;
virtual void setLayer(bar_layer layer) = 0;
virtual void setMargins(const struct bar_margins &margins) = 0;
virtual void setPassThrough(bool enable) = 0;
virtual void setPosition(const std::string_view &position) = 0;
virtual void setSize(uint32_t width, uint32_t height) = 0;
virtual void commit(){};
virtual ~BarSurface() = default;
};
class Bar { class Bar {
public: public:
using bar_mode_map = std::map<std::string_view, struct bar_mode>; using bar_mode_map = std::map<std::string, struct bar_mode>;
static const bar_mode_map PRESET_MODES; static const bar_mode_map PRESET_MODES;
static const std::string_view MODE_DEFAULT; static const std::string MODE_DEFAULT;
static const std::string_view MODE_INVISIBLE; static const std::string MODE_INVISIBLE;
Bar(struct waybar_output *w_output, const Json::Value &); Bar(struct waybar_output *w_output, const Json::Value &);
Bar(const Bar &) = delete; Bar(const Bar &) = delete;
~Bar(); ~Bar();
void setMode(const std::string_view &); void setMode(const std::string &mode);
void setVisible(bool visible); void setVisible(bool visible);
void toggle(); void toggle();
void handleSignal(int); void handleSignal(int);
@ -89,8 +68,10 @@ class Bar {
Json::Value config; Json::Value config;
struct wl_surface *surface; struct wl_surface *surface;
bool visible = true; bool visible = true;
bool vertical = false;
Gtk::Window window; Gtk::Window window;
Glib::RefPtr<Gdk::Surface> gdk_surface_;
Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL;
Gtk::PositionType position = Gtk::PositionType::TOP;
int x_global; int x_global;
int y_global; int y_global;
@ -100,13 +81,15 @@ class Bar {
#endif #endif
private: private:
void onMap(GdkEventAny *); void onMap();
auto setupWidgets() -> void; auto setupWidgets() -> void;
void getModules(const Factory &, const std::string &, waybar::Group *); // void getModules(const Factory &, const std::string &, waybar::Group *);
void setupAltFormatKeyForModule(const std::string &module_name); void setupAltFormatKeyForModule(const std::string &module_name);
void setupAltFormatKeyForModuleList(const char *module_list_name); void setupAltFormatKeyForModuleList(const char *module_list_name);
void setMode(const bar_mode &); void setMode(const bar_mode &);
void onConfigure(GdkEventConfigure *ev); void setPassThrough(bool passthrough);
void setPosition(Gtk::PositionType position);
void onConfigure(int width, int height);
void configureGlobalOffset(int width, int height); void configureGlobalOffset(int width, int height);
void onOutputGeometryChanged(); void onOutputGeometryChanged();
@ -115,12 +98,13 @@ class Bar {
std::string last_mode_{MODE_DEFAULT}; std::string last_mode_{MODE_DEFAULT};
struct bar_margins margins_; struct bar_margins margins_;
uint32_t width_, height_;
bool passthrough_;
std::unique_ptr<BarSurface> surface_impl_;
Gtk::Box left_; Gtk::Box left_;
Gtk::Box center_; Gtk::Box center_;
Gtk::Box right_; Gtk::Box right_;
Gtk::Box box_; Gtk::CenterBox box_;
std::vector<std::shared_ptr<waybar::AModule>> modules_left_; 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_center_;
std::vector<std::shared_ptr<waybar::AModule>> modules_right_; std::vector<std::shared_ptr<waybar::AModule>> modules_right_;

View File

@ -1,15 +1,11 @@
#pragma once #pragma once
#include <fmt/format.h> #include <gdk/wayland/gdkwayland.h>
#include <gdk/gdk.h>
#include <gdk/gdkwayland.h>
#include <wayland-client.h>
#include "bar.hpp" #include "bar.hpp"
#include "config.hpp" #include "config.hpp"
#include "util/portal.hpp" #include "util/portal.hpp"
struct zwlr_layer_shell_v1;
struct zwp_idle_inhibitor_v1; struct zwp_idle_inhibitor_v1;
struct zwp_idle_inhibit_manager_v1; struct zwp_idle_inhibit_manager_v1;
@ -25,7 +21,6 @@ class Client {
Glib::RefPtr<Gdk::Display> gdk_display; Glib::RefPtr<Gdk::Display> gdk_display;
struct wl_display *wl_display = nullptr; struct wl_display *wl_display = nullptr;
struct wl_registry *registry = nullptr; struct wl_registry *registry = nullptr;
struct zwlr_layer_shell_v1 *layer_shell = nullptr;
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr; struct zxdg_output_manager_v1 *xdg_output_manager = nullptr;
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr;
std::vector<std::unique_ptr<Bar>> bars; std::vector<std::unique_ptr<Bar>> bars;
@ -34,6 +29,7 @@ class Client {
private: private:
Client() = default; Client() = default;
Glib::RefPtr<Gio::ListModel> monitors_;
const std::string getStyle(const std::string &style, std::optional<Appearance> appearance); const std::string getStyle(const std::string &style, std::optional<Appearance> appearance);
void bindInterfaces(); void bindInterfaces();
void handleOutput(struct waybar_output &output); void handleOutput(struct waybar_output &output);
@ -51,7 +47,6 @@ class Client {
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor); void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
void handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> monitor); void handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> monitor);
Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_; Glib::RefPtr<Gtk::CssProvider> css_provider_;
std::unique_ptr<Portal> portal; std::unique_ptr<Portal> portal;
std::list<struct waybar_output> outputs_; std::list<struct waybar_output> outputs_;

View File

@ -19,7 +19,7 @@ class Group : public AModule {
virtual Gtk::Box& getBox(); virtual Gtk::Box& getBox();
void addWidget(Gtk::Widget& widget); void addWidget(Gtk::Widget& widget);
bool handleMouseHover(GdkEventCrossing* const& e); // bool handleMouseHover(GdkEventCrossing* const& e);
protected: protected:
Gtk::Box box; Gtk::Box box;

View File

@ -16,7 +16,7 @@ typedef struct wbcffi_module wbcffi_module;
typedef struct { typedef struct {
wbcffi_module* obj; wbcffi_module* obj;
const char* waybar_version; const char* waybar_version;
GtkContainer* (*get_root_widget)(wbcffi_module*); //todo GtkContainer* (*get_root_widget)(wbcffi_module*);
void (*queue_update)(wbcffi_module*); void (*queue_update)(wbcffi_module*);
} wbcffi_init_info; } wbcffi_init_info;

View File

@ -26,8 +26,8 @@ class Custom : public ALabel {
void parseOutputRaw(); void parseOutputRaw();
void parseOutputJson(); void parseOutputJson();
void handleEvent(); void handleEvent();
bool handleScroll(GdkEventScroll* e) override; //todo bool handleScroll(GdkEventScroll* e) override;
bool handleToggle(GdkEventButton* const& e) override; //todo bool handleToggle(GdkEventButton* const& e) override;
const std::string name_; const std::string name_;
const std::string output_name_; const std::string output_name_;

View File

@ -19,7 +19,7 @@ class IdleInhibitor : public ALabel {
static bool status; static bool status;
private: private:
bool handleToggle(GdkEventButton* const& e) override; //todo bool handleToggle(GdkEventButton* const& e) override;
void toggleStatus(); void toggleStatus();
const Bar& bar_; const Bar& bar_;

View File

@ -14,7 +14,7 @@ class User : public AIconLabel {
virtual ~User() = default; virtual ~User() = default;
auto update() -> void override; auto update() -> void override;
bool handleToggle(GdkEventButton* const& e) override; //todo bool handleToggle(GdkEventButton* const& e) override;
private: private:
util::SleeperThread thread_; util::SleeperThread thread_;

View File

@ -52,7 +52,7 @@ struct SafeSignal : sigc::signal<void(std::decay_t<Args>...)> {
using slot_t = decltype(std::declval<signal_t>().make_slot()); using slot_t = decltype(std::declval<signal_t>().make_slot());
using arg_tuple_t = std::tuple<std::decay_t<Args>...>; using arg_tuple_t = std::tuple<std::decay_t<Args>...>;
// ensure that unwrapped methods are not accessible // ensure that unwrapped methods are not accessible
using signal_t::emit_reverse; using signal_t::emit;
using signal_t::make_slot; using signal_t::make_slot;
void handle_event() { void handle_event() {

View File

@ -19,7 +19,7 @@ class Portal : private DBus::Proxy {
void refreshAppearance(); void refreshAppearance();
Appearance getAppearance(); Appearance getAppearance();
typedef sigc::signal<void, Appearance> type_signal_appearance_changed; typedef sigc::signal<void(Appearance)> type_signal_appearance_changed;
type_signal_appearance_changed signal_appearance_changed() { return m_signal_appearance_changed; } type_signal_appearance_changed signal_appearance_changed() { return m_signal_appearance_changed; }
private: private:

View File

@ -108,12 +108,6 @@ Also, a minimal example configuration can be found at the bottom of this man pag
Option to pass any pointer events to the window under the bar. Option to pass any pointer events to the window under the bar.
Intended to be used with either *top* or *overlay* layers and without exclusive zone. Intended to be used with either *top* or *overlay* layers and without exclusive zone.
*gtk-layer-shell* ++
typeof: bool ++
default: true ++
Option to disable the use of gtk-layer-shell for popups.
Only functional if compiled with gtk-layer-shell support.
*ipc* ++ *ipc* ++
typeof: bool ++ typeof: bool ++
default: false ++ default: false ++

View File

@ -1,10 +1,10 @@
project( project(
'waybar', 'cpp', 'c', 'waybar', 'cpp', 'c',
version: '0.9.24', version: '4.1.0',
license: 'MIT', license: 'MIT',
meson_version: '>= 0.50.0', meson_version: '>= 1.3.0',
default_options : [ default_options : [
'cpp_std=c++20', 'cpp_std=c++23',
'buildtype=release', 'buildtype=release',
'default_library=static' 'default_library=static'
], ],
@ -78,79 +78,19 @@ is_freebsd = host_machine.system() == 'freebsd'
is_netbsd = host_machine.system() == 'netbsd' is_netbsd = host_machine.system() == 'netbsd'
is_openbsd = host_machine.system() == 'openbsd' is_openbsd = host_machine.system() == 'openbsd'
thread_dep = dependency('threads') jsoncpp = dependency('jsoncpp', version : ['>=1.9.4'], fallback : ['jsoncpp', 'jsoncpp_dep'])
fmt = dependency('fmt', version : ['>=8.1.1'], fallback : ['fmt', 'fmt_dep'])
spdlog = dependency('spdlog', version : ['>=1.10.0'], fallback : ['spdlog', 'spdlog_dep'], default_options : ['external_fmt=enabled'])
wayland_client = dependency('wayland-client') wayland_client = dependency('wayland-client')
wayland_cursor = dependency('wayland-cursor') wayland_cursor = dependency('wayland-cursor')
wayland_protos = dependency('wayland-protocols') wayland_protos = dependency('wayland-protocols')
gtkmm = dependency('gtkmm-3.0', version : ['>=3.22.0']) sigcpp = dependency('sigc++-3.0', version: ['>=3.4.0'])
dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4', required: get_option('dbusmenu-gtk')) gtkmm = dependency('gtkmm-4.0', version : ['>=4.12.0'])
giounix = dependency('gio-unix-2.0', required: (get_option('dbusmenu-gtk').enabled() or giounix = dependency('gio-unix-2.0', version: ['>=2.76.4'])
get_option('logind').enabled() or spdlog = dependency('spdlog', version : ['>=1.10.0'], fallback : ['spdlog', 'spdlog_dep'], default_options : ['external_fmt=enabled'])
get_option('upower_glib').enabled() or
get_option('mpris').enabled()))
jsoncpp = dependency('jsoncpp', version : ['>=1.9.2'], fallback : ['jsoncpp', 'jsoncpp_dep'])
sigcpp = dependency('sigc++-2.0')
libinotify = dependency('libinotify', required: false)
libepoll = dependency('epoll-shim', required: false)
libinput = dependency('libinput', required: get_option('libinput'))
libnl = dependency('libnl-3.0', required: get_option('libnl'))
libnlgen = dependency('libnl-genl-3.0', required: get_option('libnl'))
upower_glib = dependency('upower-glib', required: get_option('upower_glib'))
pipewire = dependency('libpipewire-0.3', required: get_option('pipewire'))
playerctl = dependency('playerctl', version : ['>=2.0.0'], required: get_option('mpris'))
libpulse = dependency('libpulse', required: get_option('pulseaudio'))
libudev = dependency('libudev', required: get_option('libudev'))
libevdev = dependency('libevdev', required: get_option('libevdev'))
libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
xkbregistry = dependency('xkbregistry')
libjack = dependency('jack', required: get_option('jack'))
libwireplumber = dependency('wireplumber-0.4', required: get_option('wireplumber'))
libsndio = compiler.find_library('sndio', required: get_option('sndio')) gtk_layer_shell = dependency('gtk4-layer-shell-0',
if libsndio.found() version : ['>=1.0.2'],
if not compiler.has_function('sioctl_open', prefix: '#include <sndio.h>', dependencies: libsndio) fallback : ['gtk4-layer-shell', 'gtk_layer_shell'],
if get_option('sndio').enabled() default_options : ['introspection=false', 'vapi=false'])
error('libsndio is too old, required >=1.7.0')
else
warning('libsndio is too old, required >=1.7.0')
libsndio = dependency('', required: false)
endif
endif
endif
gtk_layer_shell = dependency('gtk-layer-shell-0',
required: get_option('gtk-layer-shell'),
fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep'])
systemd = dependency('systemd', required: get_option('systemd'))
cpp_lib_chrono = compiler.compute_int('__cpp_lib_chrono', prefix : '#include <chrono>')
have_chrono_timezones = cpp_lib_chrono >= 201611
if have_chrono_timezones
code = '''
#include <chrono>
using namespace std::chrono;
int main(int argc, char** argv) {
const time_zone* tz;
return 0;
}
'''
if not compiler.links(code)
have_chrono_timezones = false
endif
endif
if have_chrono_timezones
tz_dep = declare_dependency()
else
tz_dep = dependency('date',
required: false,
default_options : [ 'use_system_tzdb=true' ],
modules : [ 'date::date', 'date::date-tz' ],
fallback: [ 'date', 'tz_dep' ])
endif
prefix = get_option('prefix') prefix = get_option('prefix')
sysconfdir = get_option('sysconfdir') sysconfdir = get_option('sysconfdir')
@ -159,285 +99,32 @@ conf_data.set('prefix', prefix)
add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'cpp') add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'cpp')
if systemd.found()
user_units_dir = systemd.get_pkgconfig_variable('systemduserunitdir')
configure_file(
configuration: conf_data,
input: './resources/waybar.service.in',
output: '@BASENAME@',
install_dir: user_units_dir
)
endif
src_files = files( src_files = files(
'src/factory.cpp',
'src/AModule.cpp',
'src/ALabel.cpp',
'src/AIconLabel.cpp',
'src/AAppIconLabel.cpp',
'src/modules/custom.cpp',
'src/modules/disk.cpp',
'src/modules/idle_inhibitor.cpp',
'src/modules/image.cpp',
'src/modules/load.cpp',
'src/modules/temperature.cpp',
'src/modules/user.cpp',
'src/ASlider.cpp',
'src/main.cpp', 'src/main.cpp',
'src/bar.cpp',
'src/client.cpp', 'src/client.cpp',
'src/bar.cpp',
'src/config.cpp', 'src/config.cpp',
'src/group.cpp',
'src/util/portal.cpp', 'src/util/portal.cpp',
'src/util/enum.cpp',
'src/util/prepare_for_sleep.cpp', 'src/util/prepare_for_sleep.cpp',
'src/util/ustring_clen.cpp', # 'src/AModule.cpp',
'src/util/sanitize_str.cpp',
'src/util/rewrite_string.cpp',
'src/util/gtk_icon.cpp',
'src/util/regex_collection.cpp'
) )
inc_dirs = ['include'] inc_dirs = ['include']
if is_linux
add_project_arguments('-DHAVE_CPU_LINUX', language: 'cpp')
add_project_arguments('-DHAVE_MEMORY_LINUX', language: 'cpp')
add_project_arguments('-DHAVE_SYSTEMD_MONITOR', language: 'cpp')
src_files += files(
'src/modules/battery.cpp',
'src/modules/cffi.cpp',
'src/modules/cpu.cpp',
'src/modules/cpu_frequency/common.cpp',
'src/modules/cpu_frequency/linux.cpp',
'src/modules/cpu_usage/common.cpp',
'src/modules/cpu_usage/linux.cpp',
'src/modules/memory/common.cpp',
'src/modules/memory/linux.cpp',
'src/modules/systemd_failed_units.cpp',
)
elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
add_project_arguments('-DHAVE_CPU_BSD', language: 'cpp')
add_project_arguments('-DHAVE_MEMORY_BSD', language: 'cpp')
src_files += files(
'src/modules/cffi.cpp',
'src/modules/cpu.cpp',
'src/modules/cpu_frequency/bsd.cpp',
'src/modules/cpu_frequency/common.cpp',
'src/modules/cpu_usage/bsd.cpp',
'src/modules/cpu_usage/common.cpp',
'src/modules/memory/bsd.cpp',
'src/modules/memory/common.cpp',
)
if is_freebsd
src_files += files(
'src/modules/battery.cpp',
)
endif
endif
add_project_arguments('-DHAVE_SWAY', language: 'cpp')
src_files += [
'src/modules/sway/ipc/client.cpp',
'src/modules/sway/bar.cpp',
'src/modules/sway/mode.cpp',
'src/modules/sway/language.cpp',
'src/modules/sway/window.cpp',
'src/modules/sway/workspaces.cpp',
'src/modules/sway/scratchpad.cpp'
]
if true
add_project_arguments('-DHAVE_WLR', language: 'cpp')
src_files += 'src/modules/wlr/taskbar.cpp'
src_files += 'src/modules/wlr/workspace_manager.cpp'
src_files += 'src/modules/wlr/workspace_manager_binding.cpp'
endif
if true
add_project_arguments('-DHAVE_RIVER', language: 'cpp')
src_files += 'src/modules/river/mode.cpp'
src_files += 'src/modules/river/tags.cpp'
src_files += 'src/modules/river/window.cpp'
src_files += 'src/modules/river/layout.cpp'
endif
if true
add_project_arguments('-DHAVE_DWL', language: 'cpp')
src_files += 'src/modules/dwl/tags.cpp'
endif
if true
add_project_arguments('-DHAVE_HYPRLAND', language: 'cpp')
src_files += 'src/modules/hyprland/backend.cpp'
src_files += 'src/modules/hyprland/window.cpp'
src_files += 'src/modules/hyprland/language.cpp'
src_files += 'src/modules/hyprland/submap.cpp'
src_files += 'src/modules/hyprland/workspaces.cpp'
endif
if libnl.found() and libnlgen.found()
add_project_arguments('-DHAVE_LIBNL', language: 'cpp')
src_files += 'src/modules/network.cpp'
endif
if (giounix.found() and not get_option('logind').disabled())
add_project_arguments('-DHAVE_GAMEMODE', language: 'cpp')
src_files += 'src/modules/gamemode.cpp'
endif
if (upower_glib.found() and giounix.found() and not get_option('logind').disabled())
add_project_arguments('-DHAVE_UPOWER', language: 'cpp')
src_files += 'src/modules/upower/upower.cpp'
src_files += 'src/modules/upower/upower_tooltip.cpp'
endif
if (pipewire.found())
add_project_arguments('-DHAVE_PIPEWIRE', language: 'cpp')
src_files += 'src/modules/privacy/privacy.cpp'
src_files += 'src/modules/privacy/privacy_item.cpp'
src_files += 'src/util/pipewire_backend.cpp'
endif
if (playerctl.found() and giounix.found() and not get_option('logind').disabled())
add_project_arguments('-DHAVE_MPRIS', language: 'cpp')
src_files += 'src/modules/mpris/mpris.cpp'
endif
if libpulse.found()
add_project_arguments('-DHAVE_LIBPULSE', language: 'cpp')
src_files += 'src/modules/pulseaudio.cpp'
src_files += 'src/modules/pulseaudio_slider.cpp'
src_files += 'src/util/audio_backend.cpp'
endif
if libjack.found()
add_project_arguments('-DHAVE_LIBJACK', language: 'cpp')
src_files += 'src/modules/jack.cpp'
endif
if libwireplumber.found()
add_project_arguments('-DHAVE_LIBWIREPLUMBER', language: 'cpp')
src_files += 'src/modules/wireplumber.cpp'
endif
if dbusmenu_gtk.found()
add_project_arguments('-DHAVE_DBUSMENU', language: 'cpp')
src_files += files(
'src/modules/sni/tray.cpp',
'src/modules/sni/watcher.cpp',
'src/modules/sni/host.cpp',
'src/modules/sni/item.cpp'
)
endif
if libudev.found() and (is_linux or libepoll.found())
add_project_arguments('-DHAVE_LIBUDEV', language: 'cpp')
src_files += 'src/modules/backlight.cpp'
src_files += 'src/modules/backlight_slider.cpp'
src_files += 'src/util/backlight_backend.cpp'
endif
if libevdev.found() and (is_linux or libepoll.found()) and libinput.found() and (is_linux or libinotify.found())
add_project_arguments('-DHAVE_LIBEVDEV', language: 'cpp')
add_project_arguments('-DHAVE_LIBINPUT', language: 'cpp')
src_files += 'src/modules/keyboard_state.cpp'
endif
if libmpdclient.found()
add_project_arguments('-DHAVE_LIBMPDCLIENT', language: 'cpp')
src_files += 'src/modules/mpd/mpd.cpp'
src_files += 'src/modules/mpd/state.cpp'
endif
if gtk_layer_shell.found()
add_project_arguments('-DHAVE_GTK_LAYER_SHELL', language: 'cpp')
endif
if libsndio.found()
add_project_arguments('-DHAVE_LIBSNDIO', language: 'cpp')
src_files += 'src/modules/sndio.cpp'
endif
if (giounix.found() and not get_option('logind').disabled())
add_project_arguments('-DHAVE_GIO_UNIX', language: 'cpp')
src_files += 'src/modules/inhibitor.cpp'
src_files += 'src/modules/bluetooth.cpp'
endif
if get_option('rfkill').enabled() and is_linux
add_project_arguments('-DWANT_RFKILL', language: 'cpp')
src_files += files(
'src/util/rfkill.cpp'
)
endif
if have_chrono_timezones
add_project_arguments('-DHAVE_CHRONO_TIMEZONES', language: 'cpp')
src_files += 'src/modules/clock.cpp'
elif tz_dep.found()
add_project_arguments('-DHAVE_LIBDATE', language: 'cpp')
src_files += 'src/modules/clock.cpp'
else
src_files += 'src/modules/simpleclock.cpp'
endif
if get_option('experimental')
add_project_arguments('-DUSE_EXPERIMENTAL', language: 'cpp')
endif
cava = dependency('cava',
version : '>=0.9.1',
required: get_option('cava'),
fallback : ['cava', 'cava_dep'],
not_found_message: 'cava is not found. Building waybar without cava')
if cava.found()
add_project_arguments('-DHAVE_LIBCAVA', language: 'cpp')
src_files += 'src/modules/cava.cpp'
endif
subdir('protocol') subdir('protocol')
app_resources = []
subdir('resources/icons')
executable( executable(
'waybar', 'waybar',
[src_files, app_resources], [src_files],
dependencies: [ dependencies: [
thread_dep, gtk_layer_shell,
client_protos, gtkmm,
wayland_client, giounix,
fmt,
spdlog,
sigcpp, sigcpp,
jsoncpp, jsoncpp,
wayland_client,
wayland_cursor, wayland_cursor,
gtkmm, client_protos,
dbusmenu_gtk, spdlog
giounix,
libinput,
libnl,
libnlgen,
upower_glib,
pipewire,
playerctl,
libpulse,
libjack,
libwireplumber,
libudev,
libinotify,
libepoll,
libmpdclient,
libevdev,
gtk_layer_shell,
libsndio,
tz_dep,
xkbregistry,
cava
], ],
include_directories: inc_dirs, include_directories: inc_dirs,
install: true, install: true,
@ -448,113 +135,3 @@ install_data(
'./resources/style.css', './resources/style.css',
install_dir: sysconfdir + '/xdg/waybar' install_dir: sysconfdir + '/xdg/waybar'
) )
scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-pages'))
if scdoc.found()
scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true)
sh = find_program('sh', native: true)
main_manpage = configure_file(
input: 'man/waybar.5.scd.in',
output: 'waybar.5.scd',
configuration: {
'sysconfdir': join_paths(prefix, sysconfdir)
}
)
main_manpage_path = join_paths(meson.build_root(), '@0@'.format(main_manpage))
mandir = get_option('mandir')
man_files = [
main_manpage_path,
'waybar-backlight.5.scd',
'waybar-backlight-slider.5.scd',
'waybar-battery.5.scd',
'waybar-cava.5.scd',
'waybar-cffi.5.scd',
'waybar-clock.5.scd',
'waybar-cpu.5.scd',
'waybar-custom.5.scd',
'waybar-disk.5.scd',
'waybar-gamemode.5.scd',
'waybar-idle-inhibitor.5.scd',
'waybar-image.5.scd',
'waybar-keyboard-state.5.scd',
'waybar-memory.5.scd',
'waybar-mpd.5.scd',
'waybar-mpris.5.scd',
'waybar-network.5.scd',
'waybar-pulseaudio.5.scd',
'waybar-pulseaudio-slider.5.scd',
'waybar-privacy.5.scd',
'waybar-river-mode.5.scd',
'waybar-river-tags.5.scd',
'waybar-river-window.5.scd',
'waybar-river-layout.5.scd',
'waybar-sway-language.5.scd',
'waybar-sway-mode.5.scd',
'waybar-sway-scratchpad.5.scd',
'waybar-sway-window.5.scd',
'waybar-sway-workspaces.5.scd',
'waybar-systemd-failed-units.5.scd',
'waybar-temperature.5.scd',
'waybar-tray.5.scd',
'waybar-states.5.scd',
'waybar-wlr-taskbar.5.scd',
'waybar-wlr-workspaces.5.scd',
'waybar-bluetooth.5.scd',
'waybar-sndio.5.scd',
'waybar-upower.5.scd',
'waybar-wireplumber.5.scd',
'waybar-dwl-tags.5.scd',
]
if (giounix.found() and not get_option('logind').disabled())
man_files += 'waybar-inhibitor.5.scd'
endif
foreach file : man_files
path = '@0@'.format(file)
basename = path.split('/')[-1]
topic = basename.split('.')[-3]
section = basename.split('.')[-2]
output = '@0@.@1@'.format(topic, section)
custom_target(
output,
# drops the 'man' if `path` is an absolute path
input: join_paths('man', path),
output: output,
command: [
sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc_prog.path(), output)
],
install: true,
install_dir: '@0@/man@1@'.format(mandir, section)
)
endforeach
endif
catch2 = dependency(
'catch2',
version: '>=3.5.1',
fallback: ['catch2', 'catch2_dep'],
required: get_option('tests'),
)
if catch2.found()
subdir('test')
endif
clangtidy = find_program('clang-tidy', required: false)
if clangtidy.found()
run_target(
'tidy',
command: [
clangtidy,
'-checks=*,-fuchsia-default-arguments',
'-p', meson.build_root()
] + src_files)
endif

View File

@ -11,7 +11,6 @@ option('systemd', type: 'feature', value: 'auto', description: 'Install systemd
option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable support for tray') option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable support for tray')
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
option('mpd', type: 'feature', value: 'auto', description: 'Enable support for the Music Player Daemon') option('mpd', type: 'feature', value: 'auto', description: 'Enable support for the Music Player Daemon')
option('gtk-layer-shell', type: 'feature', value: 'auto', description: 'Use gtk-layer-shell library for popups support')
option('rfkill', type: 'feature', value: 'auto', description: 'Enable support for RFKILL') option('rfkill', type: 'feature', value: 'auto', description: 'Enable support for RFKILL')
option('sndio', type: 'feature', value: 'auto', description: 'Enable support for sndio') option('sndio', type: 'feature', value: 'auto', description: 'Enable support for sndio')
option('logind', type: 'feature', value: 'auto', description: 'Enable support for logind') option('logind', type: 'feature', value: 'auto', description: 'Enable support for logind')

View File

@ -25,7 +25,6 @@ client_protocols = [
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
[wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
['wlr-layer-shell-unstable-v1.xml'],
['wlr-foreign-toplevel-management-unstable-v1.xml'], ['wlr-foreign-toplevel-management-unstable-v1.xml'],
['ext-workspace-unstable-v1.xml'], ['ext-workspace-unstable-v1.xml'],
['river-status-unstable-v1.xml'], ['river-status-unstable-v1.xml'],

View File

@ -1,311 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_layer_shell_unstable_v1">
<copyright>
Copyright © 2017 Drew DeVault
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<interface name="zwlr_layer_shell_v1" version="3">
<description summary="create surfaces that are layers of the desktop">
Clients can use this interface to assign the surface_layer role to
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
rendered with a defined z-depth respective to each other. They may also be
anchored to the edges and corners of a screen and specify input handling
semantics. This interface should be suitable for the implementation of
many desktop shell components, and a broad number of other applications
that interact with the desktop.
</description>
<request name="get_layer_surface">
<description summary="create a layer_surface from a surface">
Create a layer surface for an existing surface. This assigns the role of
layer_surface, or raises a protocol error if another role is already
assigned.
Creating a layer surface from a wl_surface which has a buffer attached
or committed is a client error, and any attempts by a client to attach
or manipulate a buffer prior to the first layer_surface.configure call
must also be treated as errors.
You may pass NULL for output to allow the compositor to decide which
output to use. Generally this will be the one that the user most
recently interacted with.
Clients can specify a namespace that defines the purpose of the layer
surface.
</description>
<arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
<arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
<arg name="np" type="string" summary="namespace for the layer surface"/>
</request>
<enum name="error">
<entry name="role" value="0" summary="wl_surface has another role"/>
<entry name="invalid_layer" value="1" summary="layer value is invalid"/>
<entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
</enum>
<enum name="layer">
<description summary="available layers for surfaces">
These values indicate which layers a surface can be rendered in. They
are ordered by z depth, bottom-most first. Traditional shell surfaces
will typically be rendered between the bottom and top layers.
Fullscreen shell surfaces are typically rendered at the top layer.
Multiple surfaces can share a single layer, and ordering within a
single layer is undefined.
</description>
<entry name="background" value="0"/>
<entry name="bottom" value="1"/>
<entry name="top" value="2"/>
<entry name="overlay" value="3"/>
</enum>
<!-- Version 3 additions -->
<request name="destroy" type="destructor" since="3">
<description summary="destroy the layer_shell object">
This request indicates that the client will not use the layer_shell
object any more. Objects that have been created through this instance
are not affected.
</description>
</request>
</interface>
<interface name="zwlr_layer_surface_v1" version="3">
<description summary="layer metadata interface">
An interface that may be implemented by a wl_surface, for surfaces that
are designed to be rendered as a layer of a stacked desktop-like
environment.
Layer surface state (layer, size, anchor, exclusive zone,
margin, interactivity) is double-buffered, and will be applied at the
time wl_surface.commit of the corresponding wl_surface is called.
</description>
<request name="set_size">
<description summary="sets the size of the surface">
Sets the size of the surface in surface-local coordinates. The
compositor will display the surface centered with respect to its
anchors.
If you pass 0 for either value, the compositor will assign it and
inform you of the assignment in the configure event. You must set your
anchor to opposite edges in the dimensions you omit; not doing so is a
protocol error. Both values are 0 by default.
Size is double-buffered, see wl_surface.commit.
</description>
<arg name="width" type="uint"/>
<arg name="height" type="uint"/>
</request>
<request name="set_anchor">
<description summary="configures the anchor point of the surface">
Requests that the compositor anchor the surface to the specified edges
and corners. If two orthogonal edges are specified (e.g. 'top' and
'left'), then the anchor point will be the intersection of the edges
(e.g. the top left corner of the output); otherwise the anchor point
will be centered on that edge, or in the center if none is specified.
Anchor is double-buffered, see wl_surface.commit.
</description>
<arg name="anchor" type="uint" enum="anchor"/>
</request>
<request name="set_exclusive_zone">
<description summary="configures the exclusive geometry of this surface">
Requests that the compositor avoids occluding an area with other
surfaces. The compositor's use of this information is
implementation-dependent - do not assume that this region will not
actually be occluded.
A positive value is only meaningful if the surface is anchored to one
edge or an edge and both perpendicular edges. If the surface is not
anchored, anchored to only two perpendicular edges (a corner), anchored
to only two parallel edges or anchored to all edges, a positive value
will be treated the same as zero.
A positive zone is the distance from the edge in surface-local
coordinates to consider exclusive.
Surfaces that do not wish to have an exclusive zone may instead specify
how they should interact with surfaces that do. If set to zero, the
surface indicates that it would like to be moved to avoid occluding
surfaces with a positive exclusive zone. If set to -1, the surface
indicates that it would not like to be moved to accommodate for other
surfaces, and the compositor should extend it all the way to the edges
it is anchored to.
For example, a panel might set its exclusive zone to 10, so that
maximized shell surfaces are not shown on top of it. A notification
might set its exclusive zone to 0, so that it is moved to avoid
occluding the panel, but shell surfaces are shown underneath it. A
wallpaper or lock screen might set their exclusive zone to -1, so that
they stretch below or over the panel.
The default value is 0.
Exclusive zone is double-buffered, see wl_surface.commit.
</description>
<arg name="zone" type="int"/>
</request>
<request name="set_margin">
<description summary="sets a margin from the anchor point">
Requests that the surface be placed some distance away from the anchor
point on the output, in surface-local coordinates. Setting this value
for edges you are not anchored to has no effect.
The exclusive zone includes the margin.
Margin is double-buffered, see wl_surface.commit.
</description>
<arg name="top" type="int"/>
<arg name="right" type="int"/>
<arg name="bottom" type="int"/>
<arg name="left" type="int"/>
</request>
<request name="set_keyboard_interactivity">
<description summary="requests keyboard events">
Set to 1 to request that the seat send keyboard events to this layer
surface. For layers below the shell surface layer, the seat will use
normal focus semantics. For layers above the shell surface layers, the
seat will always give exclusive keyboard focus to the top-most layer
which has keyboard interactivity set to true.
Layer surfaces receive pointer, touch, and tablet events normally. If
you do not want to receive them, set the input region on your surface
to an empty region.
Events is double-buffered, see wl_surface.commit.
</description>
<arg name="keyboard_interactivity" type="uint"/>
</request>
<request name="get_popup">
<description summary="assign this layer_surface as an xdg_popup parent">
This assigns an xdg_popup's parent to this layer_surface. This popup
should have been created via xdg_surface::get_popup with the parent set
to NULL, and this request must be invoked before committing the popup's
initial state.
See the documentation of xdg_popup for more details about what an
xdg_popup is and how it is used.
</description>
<arg name="popup" type="object" interface="xdg_popup"/>
</request>
<request name="ack_configure">
<description summary="ack a configure event">
When a configure event is received, if a client commits the
surface in response to the configure event, then the client
must make an ack_configure request sometime before the commit
request, passing along the serial of the configure event.
If the client receives multiple configure events before it
can respond to one, it only has to ack the last configure event.
A client is not required to commit immediately after sending
an ack_configure request - it may even ack_configure several times
before its next surface commit.
A client may send multiple ack_configure requests before committing, but
only the last request sent before a commit indicates which configure
event the client really is responding to.
</description>
<arg name="serial" type="uint" summary="the serial from the configure event"/>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the layer_surface">
This request destroys the layer surface.
</description>
</request>
<event name="configure">
<description summary="suggest a surface change">
The configure event asks the client to resize its surface.
Clients should arrange their surface for the new states, and then send
an ack_configure request with the serial sent in this configure event at
some point before committing the new surface.
The client is free to dismiss all but the last configure event it
received.
The width and height arguments specify the size of the window in
surface-local coordinates.
The size is a hint, in the sense that the client is free to ignore it if
it doesn't resize, pick a smaller size (to satisfy aspect ratio or
resize in steps of NxM pixels). If the client picks a smaller size and
is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
surface will be centered on this axis.
If the width or height arguments are zero, it means the client should
decide its own window dimension.
</description>
<arg name="serial" type="uint"/>
<arg name="width" type="uint"/>
<arg name="height" type="uint"/>
</event>
<event name="closed">
<description summary="surface should be closed">
The closed event is sent by the compositor when the surface will no
longer be shown. The output may have been destroyed or the user may
have asked for it to be removed. Further changes to the surface will be
ignored. The client should destroy the resource after receiving this
event, and create a new surface if they so choose.
</description>
</event>
<enum name="error">
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
<entry name="invalid_size" value="1" summary="size is invalid"/>
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
</enum>
<enum name="anchor" bitfield="true">
<entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
<entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
<entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
<entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
</enum>
<!-- Version 2 additions -->
<request name="set_layer" since="2">
<description summary="change the layer of the surface">
Change the layer that the surface is rendered on.
Layer is double-buffered, see wl_surface.commit.
</description>
<arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
</request>
</interface>
</protocol>

View File

@ -20,6 +20,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
if (!id.empty()) { if (!id.empty()) {
label_.get_style_context()->add_class(id); label_.get_style_context()->add_class(id);
} }
label_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(label_); event_box_.add(label_);
if (config_["max-length"].isUInt()) { if (config_["max-length"].isUInt()) {
label_.set_max_width_chars(config_["max-length"].asInt()); label_.set_max_width_chars(config_["max-length"].asInt());

View File

@ -13,6 +13,7 @@ ASlider::ASlider(const Json::Value& config, const std::string& name, const std::
if (!id.empty()) { if (!id.empty()) {
scale_.get_style_context()->add_class(id); scale_.get_style_context()->add_class(id);
} }
scale_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(scale_); event_box_.add(scale_);
scale_.signal_value_changed().connect(sigc::mem_fun(*this, &ASlider::onValueChanged)); scale_.signal_value_changed().connect(sigc::mem_fun(*this, &ASlider::onValueChanged));

View File

@ -1,16 +1,11 @@
#ifdef HAVE_GTK_LAYER_SHELL #include "bar.hpp"
#include <gtk-layer-shell.h>
#endif
#include <gtk4-layer-shell.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <type_traits>
#include "bar.hpp"
#include "client.hpp" #include "client.hpp"
#include "factory.hpp" //#include "factory.hpp"
#include "group.hpp" //#include "group.hpp"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#ifdef HAVE_SWAY #ifdef HAVE_SWAY
#include "modules/sway/bar.hpp" #include "modules/sway/bar.hpp"
@ -25,9 +20,6 @@ static constexpr const char* MIN_WIDTH_MSG =
static constexpr const char* BAR_SIZE_MSG = "Bar configured (width: {}, height: {}) for output: {}"; static constexpr const char* BAR_SIZE_MSG = "Bar configured (width: {}, height: {}) for output: {}";
static constexpr const char* SIZE_DEFINED =
"{} size is defined in the config file so it will stay like that";
const Bar::bar_mode_map Bar::PRESET_MODES = { // const Bar::bar_mode_map Bar::PRESET_MODES = { //
{"default", {"default",
{// Special mode to hold the global bar configuration {// Special mode to hold the global bar configuration
@ -60,8 +52,8 @@ const Bar::bar_mode_map Bar::PRESET_MODES = { //
.passthrough = true, .passthrough = true,
.visible = true}}}; .visible = true}}};
const std::string_view Bar::MODE_DEFAULT = "default"; const std::string Bar::MODE_DEFAULT = "default";
const std::string_view Bar::MODE_INVISIBLE = "invisible"; const std::string Bar::MODE_INVISIBLE = "invisible";
const std::string_view DEFAULT_BAR_ID = "bar-0"; const std::string_view DEFAULT_BAR_ID = "bar-0";
/* Deserializer for enum bar_layer */ /* Deserializer for enum bar_layer */
@ -93,11 +85,37 @@ void from_json(const Json::Value& j, bar_mode& m) {
} }
} }
/* Deserializer for enum Gtk::PositionType */
void from_json(const Json::Value& j, Gtk::PositionType& pos) {
if (j == "left") {
pos = Gtk::PositionType::LEFT;
} else if (j == "right") {
pos = Gtk::PositionType::RIGHT;
} else if (j == "top") {
pos = Gtk::PositionType::TOP;
} else if (j == "bottom") {
pos = Gtk::PositionType::BOTTOM;
}
}
Glib::ustring to_string(Gtk::PositionType pos) {
switch (pos) {
case Gtk::PositionType::LEFT:
return "left";
case Gtk::PositionType::RIGHT:
return "right";
case Gtk::PositionType::TOP:
return "top";
case Gtk::PositionType::BOTTOM:
return "bottom";
}
}
/* Deserializer for JSON Object -> map<string compatible type, Value> /* Deserializer for JSON Object -> map<string compatible type, Value>
* Assumes that all the values in the object are deserializable to the same type. * Assumes that all the values in the object are deserializable to the same type.
*/ */
template <typename Key, typename Value, template <typename Key, typename Value,
typename = std::enable_if_t<std::is_convertible<std::string_view, Key>::value>> typename = std::enable_if_t<std::is_convertible<std::string, Key>::value>>
void from_json(const Json::Value& j, std::map<Key, Value>& m) { void from_json(const Json::Value& j, std::map<Key, Value>& m) {
if (j.isObject()) { if (j.isObject()) {
for (auto it = j.begin(); it != j.end(); ++it) { for (auto it = j.begin(); it != j.end(); ++it) {
@ -106,404 +124,37 @@ void from_json(const Json::Value& j, std::map<Key, Value>& m) {
} }
} }
#ifdef HAVE_GTK_LAYER_SHELL
struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
GLSSurfaceImpl(Gtk::Window& window, struct waybar_output& output) : window_{window} {
output_name_ = output.name;
// this has to be executed before GtkWindow.realize
gtk_layer_init_for_window(window_.gobj());
gtk_layer_set_keyboard_interactivity(window.gobj(), FALSE);
gtk_layer_set_monitor(window_.gobj(), output.monitor->gobj());
gtk_layer_set_namespace(window_.gobj(), "waybar");
window.signal_map_event().connect_notify(sigc::mem_fun(*this, &GLSSurfaceImpl::onMap));
window.signal_configure_event().connect_notify(
sigc::mem_fun(*this, &GLSSurfaceImpl::onConfigure));
}
void setExclusiveZone(bool enable) override {
if (enable) {
gtk_layer_auto_exclusive_zone_enable(window_.gobj());
} else {
gtk_layer_set_exclusive_zone(window_.gobj(), 0);
}
}
void setMargins(const struct bar_margins& margins) override {
gtk_layer_set_margin(window_.gobj(), GTK_LAYER_SHELL_EDGE_LEFT, margins.left);
gtk_layer_set_margin(window_.gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, margins.right);
gtk_layer_set_margin(window_.gobj(), GTK_LAYER_SHELL_EDGE_TOP, margins.top);
gtk_layer_set_margin(window_.gobj(), GTK_LAYER_SHELL_EDGE_BOTTOM, margins.bottom);
}
void setLayer(bar_layer value) override {
auto layer = GTK_LAYER_SHELL_LAYER_BOTTOM;
if (value == bar_layer::TOP) {
layer = GTK_LAYER_SHELL_LAYER_TOP;
} else if (value == bar_layer::OVERLAY) {
layer = GTK_LAYER_SHELL_LAYER_OVERLAY;
}
gtk_layer_set_layer(window_.gobj(), layer);
}
void setPassThrough(bool enable) override {
passthrough_ = enable;
auto gdk_window = window_.get_window();
if (gdk_window) {
Cairo::RefPtr<Cairo::Region> region;
if (enable) {
region = Cairo::Region::create();
}
gdk_window->input_shape_combine_region(region, 0, 0);
}
}
void setPosition(const std::string_view& position) override {
auto unanchored = GTK_LAYER_SHELL_EDGE_BOTTOM;
vertical_ = false;
if (position == "bottom") {
unanchored = GTK_LAYER_SHELL_EDGE_TOP;
} else if (position == "left") {
unanchored = GTK_LAYER_SHELL_EDGE_RIGHT;
vertical_ = true;
} else if (position == "right") {
vertical_ = true;
unanchored = GTK_LAYER_SHELL_EDGE_LEFT;
}
for (auto edge : {GTK_LAYER_SHELL_EDGE_LEFT, GTK_LAYER_SHELL_EDGE_RIGHT,
GTK_LAYER_SHELL_EDGE_TOP, GTK_LAYER_SHELL_EDGE_BOTTOM}) {
gtk_layer_set_anchor(window_.gobj(), edge, unanchored != edge);
}
// Disable anchoring for other edges too if the width
// or the height has been set to a value other than 'auto'
// otherwise the bar will use all space
if (vertical_ && height_ > 1) {
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_BOTTOM, false);
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_TOP, false);
} else if (!vertical_ && width_ > 1) {
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_LEFT, false);
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, false);
}
}
void setSize(uint32_t width, uint32_t height) override {
width_ = width;
height_ = height;
window_.set_size_request(width_, height_);
};
private:
Gtk::Window& window_;
std::string output_name_;
uint32_t width_;
uint32_t height_;
bool passthrough_ = false;
bool vertical_ = false;
void onMap(GdkEventAny* ev) { setPassThrough(passthrough_); }
void onConfigure(GdkEventConfigure* ev) {
/*
* GTK wants new size for the window.
* Actual resizing and management of the exclusve zone is handled within the gtk-layer-shell
* code. This event handler only updates stored size of the window and prints some warnings.
*
* Note: forced resizing to a window smaller than required by GTK would not work with
* gtk-layer-shell.
*/
if (vertical_) {
if (width_ > 1 && ev->width > static_cast<int>(width_)) {
spdlog::warn(MIN_WIDTH_MSG, width_, ev->width);
}
} else {
if (height_ > 1 && ev->height > static_cast<int>(height_)) {
spdlog::warn(MIN_HEIGHT_MSG, height_, ev->height);
}
}
width_ = ev->width;
height_ = ev->height;
spdlog::info(BAR_SIZE_MSG, width_, height_, output_name_);
}
};
#endif
struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
RawSurfaceImpl(Gtk::Window& window, struct waybar_output& output) : window_{window} {
output_ = gdk_wayland_monitor_get_wl_output(output.monitor->gobj());
output_name_ = output.name;
window.signal_realize().connect_notify(sigc::mem_fun(*this, &RawSurfaceImpl::onRealize));
window.signal_map_event().connect_notify(sigc::mem_fun(*this, &RawSurfaceImpl::onMap));
window.signal_configure_event().connect_notify(
sigc::mem_fun(*this, &RawSurfaceImpl::onConfigure));
if (window.get_realized()) {
onRealize();
}
}
void setExclusiveZone(bool enable) override {
exclusive_zone_ = enable;
if (layer_surface_) {
auto zone = 0;
if (enable) {
// exclusive zone already includes margin for anchored edge,
// only opposite margin should be added
if ((anchor_ & VERTICAL_ANCHOR) == VERTICAL_ANCHOR) {
zone += width_;
zone += (anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) ? margins_.right : margins_.left;
} else {
zone += height_;
zone += (anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) ? margins_.bottom : margins_.top;
}
}
spdlog::debug("Set exclusive zone {} for output {}", zone, output_name_);
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface_.get(), zone);
}
}
void setLayer(bar_layer layer) override {
layer_ = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
if (layer == bar_layer::TOP) {
layer_ = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
} else if (layer == bar_layer::OVERLAY) {
layer_ = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
}
// updating already mapped window
if (layer_surface_) {
if (zwlr_layer_surface_v1_get_version(layer_surface_.get()) >=
ZWLR_LAYER_SURFACE_V1_SET_LAYER_SINCE_VERSION) {
zwlr_layer_surface_v1_set_layer(layer_surface_.get(), layer_);
} else {
spdlog::warn("Unable to change layer: layer-shell implementation is too old");
}
}
}
void setMargins(const struct bar_margins& margins) override {
margins_ = margins;
// updating already mapped window
if (layer_surface_) {
zwlr_layer_surface_v1_set_margin(layer_surface_.get(), margins_.top, margins_.right,
margins_.bottom, margins_.left);
}
}
void setPassThrough(bool enable) override {
passthrough_ = enable;
/* GTK overwrites any region changes applied directly to the wl_surface,
* thus the same GTK region API as in the GLS impl has to be used. */
auto gdk_window = window_.get_window();
if (gdk_window) {
Cairo::RefPtr<Cairo::Region> region;
if (enable) {
region = Cairo::Region::create();
}
gdk_window->input_shape_combine_region(region, 0, 0);
}
}
void setPosition(const std::string_view& position) override {
anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
if (position == "bottom") {
anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
} else if (position == "left") {
anchor_ = VERTICAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
} else if (position == "right") {
anchor_ = VERTICAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
}
// updating already mapped window
if (layer_surface_) {
zwlr_layer_surface_v1_set_anchor(layer_surface_.get(), anchor_);
}
}
void setSize(uint32_t width, uint32_t height) override {
configured_width_ = width_ = width;
configured_height_ = height_ = height;
// layer_shell.configure handler should update exclusive zone if size changes
window_.set_size_request(width, height);
};
void commit() override {
if (surface_) {
wl_surface_commit(surface_);
}
}
private:
constexpr static uint8_t VERTICAL_ANCHOR =
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
constexpr static uint8_t HORIZONTAL_ANCHOR =
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
template <auto fn>
using deleter_fn = std::integral_constant<decltype(fn), fn>;
using layer_surface_ptr =
std::unique_ptr<zwlr_layer_surface_v1, deleter_fn<zwlr_layer_surface_v1_destroy>>;
Gtk::Window& window_;
std::string output_name_;
uint32_t configured_width_ = 0;
uint32_t configured_height_ = 0;
uint32_t width_ = 0;
uint32_t height_ = 0;
uint8_t anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
bool exclusive_zone_ = true;
bool passthrough_ = false;
struct bar_margins margins_;
zwlr_layer_shell_v1_layer layer_ = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
struct wl_output* output_ = nullptr; // owned by GTK
struct wl_surface* surface_ = nullptr; // owned by GTK
layer_surface_ptr layer_surface_;
void onRealize() {
auto gdk_window = window_.get_window()->gobj();
gdk_wayland_window_set_use_custom_surface(gdk_window);
}
void onMap(GdkEventAny* ev) {
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
.configure = onSurfaceConfigure,
.closed = onSurfaceClosed,
};
auto client = Client::inst();
auto gdk_window = window_.get_window()->gobj();
surface_ = gdk_wayland_window_get_wl_surface(gdk_window);
layer_surface_.reset(zwlr_layer_shell_v1_get_layer_surface(client->layer_shell, surface_,
output_, layer_, "waybar"));
zwlr_layer_surface_v1_add_listener(layer_surface_.get(), &layer_surface_listener, this);
zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface_.get(), false);
zwlr_layer_surface_v1_set_anchor(layer_surface_.get(), anchor_);
zwlr_layer_surface_v1_set_margin(layer_surface_.get(), margins_.top, margins_.right,
margins_.bottom, margins_.left);
setSurfaceSize(width_, height_);
setExclusiveZone(exclusive_zone_);
setPassThrough(passthrough_);
commit();
wl_display_roundtrip(client->wl_display);
}
void onConfigure(GdkEventConfigure* ev) {
/*
* GTK wants new size for the window.
*
* Prefer configured size if it's non-default.
* If the size is not set and the window is smaller than requested by GTK, request resize from
* layer surface.
*/
auto tmp_height = height_;
auto tmp_width = width_;
if (ev->height > static_cast<int>(height_)) {
// Default minimal value
if (height_ > 1) {
spdlog::warn(MIN_HEIGHT_MSG, height_, ev->height);
}
if (configured_height_ > 1) {
spdlog::info(SIZE_DEFINED, "Height");
} else {
tmp_height = ev->height;
}
}
if (ev->width > static_cast<int>(width_)) {
// Default minimal value
if (width_ > 1) {
spdlog::warn(MIN_WIDTH_MSG, width_, ev->width);
}
if (configured_width_ > 1) {
spdlog::info(SIZE_DEFINED, "Width");
} else {
tmp_width = ev->width;
}
}
if (tmp_width != width_ || tmp_height != height_) {
setSurfaceSize(tmp_width, tmp_height);
commit();
}
}
void setSurfaceSize(uint32_t width, uint32_t height) {
/* If the client is anchored to two opposite edges, layer_surface.configure will return
* size without margins for the axis.
* layer_surface.set_size, however, expects size with margins for the anchored axis.
* This is not specified by wlr-layer-shell and based on actual behavior of sway.
*
* If the size for unanchored axis is not set (0), change request to 1 to avoid automatic
* assignment by the compositor.
*/
if ((anchor_ & VERTICAL_ANCHOR) == VERTICAL_ANCHOR) {
width = width > 0 ? width : 1;
if (height > 1) {
height += margins_.top + margins_.bottom;
}
} else {
height = height > 0 ? height : 1;
if (width > 1) {
width += margins_.right + margins_.left;
}
}
spdlog::debug("Set surface size {}x{} for output {}", width, height, output_name_);
zwlr_layer_surface_v1_set_size(layer_surface_.get(), width, height);
}
static void onSurfaceConfigure(void* data, struct zwlr_layer_surface_v1* surface, uint32_t serial,
uint32_t width, uint32_t height) {
auto o = static_cast<RawSurfaceImpl*>(data);
if (width != o->width_ || height != o->height_) {
o->width_ = width;
o->height_ = height;
o->window_.set_size_request(o->width_, o->height_);
o->window_.resize(o->width_, o->height_);
o->setExclusiveZone(o->exclusive_zone_);
spdlog::info(BAR_SIZE_MSG, o->width_ == 1 ? "auto" : std::to_string(o->width_),
o->height_ == 1 ? "auto" : std::to_string(o->height_), o->output_name_);
o->commit();
}
zwlr_layer_surface_v1_ack_configure(surface, serial);
}
static void onSurfaceClosed(void* data, struct zwlr_layer_surface_v1* /* surface */) {
auto o = static_cast<RawSurfaceImpl*>(data);
o->layer_surface_.reset();
}
};
}; // namespace waybar }; // namespace waybar
waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
: output(w_output), : output(w_output),
config(w_config), config(w_config),
window{Gtk::WindowType::WINDOW_TOPLEVEL}, window{Gtk::Window()},
x_global(0), x_global(0),
y_global(0), y_global(0),
margins_{.top = 0, .right = 0, .bottom = 0, .left = 0}, margins_{.top = 0, .right = 0, .bottom = 0, .left = 0},
left_(Gtk::ORIENTATION_HORIZONTAL, 0), left_(Gtk::Orientation::HORIZONTAL, 0),
center_(Gtk::ORIENTATION_HORIZONTAL, 0), center_(Gtk::Orientation::HORIZONTAL, 0),
right_(Gtk::ORIENTATION_HORIZONTAL, 0), right_(Gtk::Orientation::HORIZONTAL, 0),
box_(Gtk::ORIENTATION_HORIZONTAL, 0) { box_{} {
window.set_title("waybar"); window.set_title("waybar");
window.set_name("waybar"); window.set_name("waybar");
window.set_decorated(false); window.set_decorated(false);
window.set_child(box_);
window.get_style_context()->add_class(output->name); window.get_style_context()->add_class(output->name);
window.get_style_context()->add_class(config["name"].asString()); window.get_style_context()->add_class(config["name"].asString());
window.get_style_context()->add_class(config["position"].asString());
auto position = config["position"].asString(); from_json(config["position"], position);
orientation = (position == Gtk::PositionType::LEFT || position == Gtk::PositionType::RIGHT)
? Gtk::Orientation::VERTICAL
: Gtk::Orientation::HORIZONTAL;
if (position == "right" || position == "left") { window.get_style_context()->add_class(to_string(position));
left_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
center_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0); left_.set_orientation(orientation);
right_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0); center_.set_orientation(orientation);
box_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0); right_.set_orientation(orientation);
vertical = true; box_.set_orientation(orientation);
}
left_.get_style_context()->add_class("modules-left"); left_.get_style_context()->add_class("modules-left");
center_.get_style_context()->add_class("modules-center"); center_.get_style_context()->add_class("modules-center");
@ -516,8 +167,8 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
right_.set_spacing(spacing); right_.set_spacing(spacing);
} }
uint32_t height = config["height"].isUInt() ? config["height"].asUInt() : 0; height_ = config["height"].isUInt() ? config["height"].asUInt() : 0;
uint32_t width = config["width"].isUInt() ? config["width"].asUInt() : 0; width_ = config["width"].isUInt() ? config["width"].asUInt() : 0;
if (config["margin-top"].isInt() || config["margin-right"].isInt() || if (config["margin-top"].isInt() || config["margin-right"].isInt() ||
config["margin-bottom"].isInt() || config["margin-left"].isInt()) { config["margin-bottom"].isInt() || config["margin-left"].isInt()) {
@ -564,25 +215,26 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps}; margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
} }
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure));
output->monitor->property_geometry().signal_changed().connect( output->monitor->property_geometry().signal_changed().connect(
sigc::mem_fun(*this, &Bar::onOutputGeometryChanged)); sigc::mem_fun(*this, &Bar::onOutputGeometryChanged));
#ifdef HAVE_GTK_LAYER_SHELL // this has to be executed before GtkWindow.realize
bool use_gls = config["gtk-layer-shell"].isBool() ? config["gtk-layer-shell"].asBool() : true; auto* gtk_window = window.gobj();
if (use_gls) { gtk_layer_init_for_window(gtk_window);
surface_impl_ = std::make_unique<GLSSurfaceImpl>(window, *output); gtk_layer_set_keyboard_mode(gtk_window, GTK_LAYER_SHELL_KEYBOARD_MODE_NONE);
} else gtk_layer_set_monitor(gtk_window, output->monitor->gobj());
#endif gtk_layer_set_namespace(gtk_window, "waybar");
{
surface_impl_ = std::make_unique<RawSurfaceImpl>(window, *output); gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, margins_.left);
} gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right);
gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top);
gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom);
window.set_size_request(width_, height_);
surface_impl_->setMargins(margins_);
surface_impl_->setSize(width, height);
// Position needs to be set after calculating the height due to the // Position needs to be set after calculating the height due to the
// GTK layer shell anchors logic relying on the dimensions of the bar. // GTK layer shell anchors logic relying on the dimensions of the bar.
surface_impl_->setPosition(position); setPosition(position);
/* Read custom modes if available */ /* Read custom modes if available */
if (auto modes = config.get("modes", {}); modes.isObject()) { if (auto modes = config.get("modes", {}); modes.isObject()) {
@ -602,7 +254,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
setVisible(false); setVisible(false);
} }
window.signal_map_event().connect_notify(sigc::mem_fun(*this, &Bar::onMap)); window.signal_map().connect(sigc::mem_fun(*this, &Bar::onMap));
#if HAVE_SWAY #if HAVE_SWAY
if (auto ipc = config["ipc"]; ipc.isBool() && ipc.asBool()) { if (auto ipc = config["ipc"]; ipc.isBool() && ipc.asBool()) {
@ -622,7 +274,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
#endif #endif
setupWidgets(); setupWidgets();
window.show_all(); window.show();
if (spdlog::should_log(spdlog::level::debug)) { if (spdlog::should_log(spdlog::level::debug)) {
// Unfortunately, this function isn't in the C++ bindings, so we have to call the C version. // Unfortunately, this function isn't in the C++ bindings, so we have to call the C version.
@ -638,7 +290,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
/* Need to define it here because of forward declared members */ /* Need to define it here because of forward declared members */
waybar::Bar::~Bar() = default; waybar::Bar::~Bar() = default;
void waybar::Bar::setMode(const std::string_view& mode) { void waybar::Bar::setMode(const std::string& mode) {
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
auto style = window.get_style_context(); auto style = window.get_style_context();
@ -659,9 +311,23 @@ void waybar::Bar::setMode(const std::string_view& mode) {
} }
void waybar::Bar::setMode(const struct bar_mode& mode) { void waybar::Bar::setMode(const struct bar_mode& mode) {
surface_impl_->setLayer(mode.layer); auto* gtk_window = window.gobj();
surface_impl_->setExclusiveZone(mode.exclusive);
surface_impl_->setPassThrough(mode.passthrough); auto layer = GTK_LAYER_SHELL_LAYER_BOTTOM;
if (mode.layer == bar_layer::TOP) {
layer = GTK_LAYER_SHELL_LAYER_TOP;
} else if (mode.layer == bar_layer::OVERLAY) {
layer = GTK_LAYER_SHELL_LAYER_OVERLAY;
}
gtk_layer_set_layer(gtk_window, layer);
if (mode.exclusive) {
gtk_layer_auto_exclusive_zone_enable(gtk_window);
} else {
gtk_layer_set_exclusive_zone(gtk_window, 0);
}
setPassThrough(passthrough_ = mode.passthrough);
if (mode.visible) { if (mode.visible) {
window.get_style_context()->remove_class("hidden"); window.get_style_context()->remove_class("hidden");
@ -670,16 +336,69 @@ void waybar::Bar::setMode(const struct bar_mode& mode) {
window.get_style_context()->add_class("hidden"); window.get_style_context()->add_class("hidden");
window.set_opacity(0); window.set_opacity(0);
} }
surface_impl_->commit();
} }
void waybar::Bar::onMap(GdkEventAny*) { void waybar::Bar::setPassThrough(bool passthrough) {
if (gdk_surface_) {
Cairo::RefPtr<Cairo::Region> region;
if (passthrough) {
region = Cairo::Region::create();
}
gdk_surface_->set_input_region(region);
}
}
void waybar::Bar::setPosition(Gtk::PositionType position) {
std::array<gboolean, GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER> anchors;
anchors.fill(TRUE);
auto orientation = (position == Gtk::PositionType::LEFT || position == Gtk::PositionType::RIGHT)
? Gtk::Orientation::VERTICAL
: Gtk::Orientation::HORIZONTAL;
switch (position) {
case Gtk::PositionType::LEFT:
anchors[GTK_LAYER_SHELL_EDGE_RIGHT] = FALSE;
break;
case Gtk::PositionType::RIGHT:
anchors[GTK_LAYER_SHELL_EDGE_LEFT] = FALSE;
break;
case Gtk::PositionType::BOTTOM:
anchors[GTK_LAYER_SHELL_EDGE_TOP] = FALSE;
break;
default: /* Gtk::POS_TOP */
anchors[GTK_LAYER_SHELL_EDGE_BOTTOM] = FALSE;
break;
};
// Disable anchoring for other edges too if the width
// or the height has been set to a value other than 'auto'
// otherwise the bar will use all space
uint32_t configured_width = config["width"].isUInt() ? config["width"].asUInt() : 0;
uint32_t configured_height = config["height"].isUInt() ? config["height"].asUInt() : 0;
if (orientation == Gtk::Orientation::VERTICAL && configured_height > 1) {
anchors[GTK_LAYER_SHELL_EDGE_TOP] = FALSE;
anchors[GTK_LAYER_SHELL_EDGE_BOTTOM] = FALSE;
} else if (orientation == Gtk::Orientation::HORIZONTAL && configured_width > 1) {
anchors[GTK_LAYER_SHELL_EDGE_LEFT] = FALSE;
anchors[GTK_LAYER_SHELL_EDGE_RIGHT] = FALSE;
}
for (auto edge : {GTK_LAYER_SHELL_EDGE_LEFT, GTK_LAYER_SHELL_EDGE_RIGHT, GTK_LAYER_SHELL_EDGE_TOP,
GTK_LAYER_SHELL_EDGE_BOTTOM}) {
gtk_layer_set_anchor(window.gobj(), edge, anchors[edge]);
}
}
void waybar::Bar::onMap() {
/* /*
* Obtain a pointer to the custom layer surface for modules that require it (idle_inhibitor). * Obtain a pointer to the custom layer surface for modules that require it (idle_inhibitor).
*/ */
auto gdk_window = window.get_window()->gobj(); gdk_surface_ = window.get_surface();
surface = gdk_wayland_window_get_wl_surface(gdk_window); surface = gdk_wayland_surface_get_wl_surface(gdk_surface_->gobj());
configureGlobalOffset(gdk_window_get_width(gdk_window), gdk_window_get_height(gdk_window)); configureGlobalOffset(gdk_surface_->get_width(), gdk_surface_->get_height());
gdk_surface_->signal_layout().connect(sigc::mem_fun(*this, &Bar::onConfigure));
setPassThrough(passthrough_);
} }
void waybar::Bar::setVisible(bool value) { void waybar::Bar::setVisible(bool value) {
@ -739,6 +458,8 @@ void waybar::Bar::handleSignal(int signal) {
} }
} }
// todo gtkmm4
/*
void waybar::Bar::getModules(const Factory& factory, const std::string& pos, void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
waybar::Group* group = nullptr) { waybar::Group* group = nullptr) {
auto module_list = group ? config[pos]["modules"] : config[pos]; auto module_list = group ? config[pos]["modules"] : config[pos];
@ -754,7 +475,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : ""; auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : "";
auto vertical = (group ? group->getBox().get_orientation() : box_.get_orientation()) == auto vertical = (group ? group->getBox().get_orientation() : box_.get_orientation()) ==
Gtk::ORIENTATION_VERTICAL; Gtk::Orientation::VERTICAL;
auto group_module = new waybar::Group(id_name, class_name, config[ref], vertical); auto group_module = new waybar::Group(id_name, class_name, config[ref], vertical);
getModules(factory, ref, group_module); getModules(factory, ref, group_module);
@ -791,72 +512,95 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
} }
} }
} }
*/
auto waybar::Bar::setupWidgets() -> void { auto waybar::Bar::setupWidgets() -> void {
window.add(box_); box_.set_start_widget(left_);
box_.pack_start(left_, false, false);
if (config["fixed-center"].isBool() ? config["fixed-center"].asBool() : true) { if (config["fixed-center"].isBool() ? config["fixed-center"].asBool() : true) {
box_.set_center_widget(center_); box_.set_center_widget(center_);
} else { } else {
box_.pack_start(center_, true, false); box_.set_start_widget(center_);
} }
box_.pack_end(right_, false, false); box_.set_end_widget(right_);
// Convert to button code for every module that is used. // Convert to button code for every module that is used.
setupAltFormatKeyForModuleList("modules-left"); setupAltFormatKeyForModuleList("modules-left");
setupAltFormatKeyForModuleList("modules-right"); setupAltFormatKeyForModuleList("modules-right");
setupAltFormatKeyForModuleList("modules-center"); setupAltFormatKeyForModuleList("modules-center");
Factory factory(*this, config); // todo gtkmm4
getModules(factory, "modules-left"); // Factory factory(*this, config);
getModules(factory, "modules-center"); // getModules(factory, "modules-left");
getModules(factory, "modules-right"); // getModules(factory, "modules-center");
// getModules(factory, "modules-right");
for (auto const& module : modules_left_) { for (auto const& module : modules_left_) {
left_.pack_start(*module, false, false); left_.prepend(*module);
} }
for (auto const& module : modules_center_) { for (auto const& module : modules_center_) {
center_.pack_start(*module, false, false); center_.prepend(*module);
} }
std::reverse(modules_right_.begin(), modules_right_.end()); std::reverse(modules_right_.begin(), modules_right_.end());
for (auto const& module : modules_right_) { for (auto const& module : modules_right_) {
right_.pack_end(*module, false, false); right_.append(*module);
} }
} }
void waybar::Bar::onConfigure(GdkEventConfigure* ev) { void waybar::Bar::onConfigure(int width, int height) {
configureGlobalOffset(ev->width, ev->height); /*
* GTK wants new size for the window.
* Actual resizing and management of the exclusve zone is handled within the gtk-layer-shell
* code. This event handler only updates stored size of the window and prints some warnings.
*
* Note: forced resizing to a window smaller than required by GTK would not work with
* gtk-layer-shell.
*/
if (orientation == Gtk::Orientation::VERTICAL) {
if (width_ > 1 && width > static_cast<int>(width_)) {
spdlog::warn(MIN_WIDTH_MSG, width_, width);
}
} else {
if (height_ > 1 && height > static_cast<int>(height_)) {
spdlog::warn(MIN_HEIGHT_MSG, height_, height);
}
}
width_ = width;
height_ = height;
configureGlobalOffset(width, height);
spdlog::info(BAR_SIZE_MSG, width, height, output->name);
} }
void waybar::Bar::configureGlobalOffset(int width, int height) { void waybar::Bar::configureGlobalOffset(int width, int height) {
auto monitor_geometry = *output->monitor->property_geometry().get_value().gobj(); auto monitor_geometry = *output->monitor->property_geometry().get_value().gobj();
auto position = config["position"].asString();
int x; int x;
int y; int y;
if (position == "bottom") { switch (position) {
case Gtk::PositionType::BOTTOM:
if (width + margins_.left + margins_.right >= monitor_geometry.width) if (width + margins_.left + margins_.right >= monitor_geometry.width)
x = margins_.left; x = margins_.left;
else else
x = (monitor_geometry.width - width) / 2; x = (monitor_geometry.width - width) / 2;
y = monitor_geometry.height - height - margins_.bottom; y = monitor_geometry.height - height - margins_.bottom;
} else if (position == "left") { break;
case Gtk::PositionType::LEFT:
x = margins_.left; x = margins_.left;
if (height + margins_.top + margins_.bottom >= monitor_geometry.height) if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
y = margins_.top; y = margins_.top;
else else
y = (monitor_geometry.height - height) / 2; y = (monitor_geometry.height - height) / 2;
} else if (position == "right") { break;
case Gtk::PositionType::RIGHT:
x = monitor_geometry.width - width - margins_.right; x = monitor_geometry.width - width - margins_.right;
if (height + margins_.top + margins_.bottom >= monitor_geometry.height) if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
y = margins_.top; y = margins_.top;
else else
y = (monitor_geometry.height - height) / 2; y = (monitor_geometry.height - height) / 2;
} else { break;
// position is top default: /* Gtk::PositionType::TOP */
if (width + margins_.left + margins_.right >= monitor_geometry.width) if (width + margins_.left + margins_.right >= monitor_geometry.width)
x = margins_.left; x = margins_.left;
else else
x = (monitor_geometry.width - width) / 2; x = (monitor_geometry.width - width) / 2;
y = margins_.top; y = margins_.top;
break;
} }
x_global = x + monitor_geometry.x; x_global = x + monitor_geometry.x;

View File

@ -1,14 +1,15 @@
#include "client.hpp" #include "client.hpp"
#include <gtk4-layer-shell.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <iostream> #include <iostream>
#include "gtkmm/icontheme.h" #include "gtkmm/icontheme.h"
#include "gtkmm/application.h"
#include "idle-inhibit-unstable-v1-client-protocol.h" #include "idle-inhibit-unstable-v1-client-protocol.h"
#include "util/clara.hpp" #include "util/clara.hpp"
#include "util/format.hpp" #include "util/format.hpp"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
waybar::Client *waybar::Client::inst() { waybar::Client *waybar::Client::inst() {
static auto c = new Client(); static auto c = new Client();
@ -18,12 +19,7 @@ waybar::Client *waybar::Client::inst() {
void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version) { const char *interface, uint32_t version) {
auto client = static_cast<Client *>(data); auto client = static_cast<Client *>(data);
if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 &&
// limit version to a highest supported by the client protocol file
version = std::min<uint32_t>(version, zwlr_layer_shell_v1_interface.version);
client->layer_shell = static_cast<struct zwlr_layer_shell_v1 *>(
wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, version));
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 &&
version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
client->xdg_output_manager = static_cast<struct zxdg_output_manager_v1 *>(wl_registry_bind( client->xdg_output_manager = static_cast<struct zxdg_output_manager_v1 *>(wl_registry_bind(
registry, name, &zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)); registry, name, &zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION));
@ -181,14 +177,15 @@ const std::string waybar::Client::getStyle(const std::string &style,
auto waybar::Client::setupCss(const std::string &css_file) -> void { auto waybar::Client::setupCss(const std::string &css_file) -> void {
css_provider_ = Gtk::CssProvider::create(); css_provider_ = Gtk::CssProvider::create();
style_context_ = 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(css_file)) { try {
throw std::runtime_error("Can't open style file"); css_provider_->load_from_path(css_file);
} catch (const Glib::Error& e) {
spdlog::error("{}", e.what());
} }
// there's always only one screen // there's always only one screen
style_context_->add_provider_for_screen(Gdk::Screen::get_default(), css_provider_, Gtk::StyleContext::add_provider_for_display(Gdk::Display::get_default(), css_provider_,
GTK_STYLE_PROVIDER_PRIORITY_USER); GTK_STYLE_PROVIDER_PRIORITY_USER);
} }
@ -200,17 +197,29 @@ void waybar::Client::bindInterfaces() {
}; };
wl_registry_add_listener(registry, &registry_listener, this); wl_registry_add_listener(registry, &registry_listener, this);
wl_display_roundtrip(wl_display); wl_display_roundtrip(wl_display);
if (layer_shell == nullptr || xdg_output_manager == nullptr) {
if (!gtk_layer_is_supported()) {
throw std::runtime_error("The Wayland compositor does not support wlr-layer-shell protocol");
}
if (xdg_output_manager == nullptr) {
throw std::runtime_error("Failed to acquire required resources."); throw std::runtime_error("Failed to acquire required resources.");
} }
// add existing outputs and subscribe to updates // add existing outputs and subscribe to updates
for (auto i = 0; i < gdk_display->get_n_monitors(); ++i) { // auto monitors{gdk_display->get_monitors()};
auto monitor = gdk_display->get_monitor(i); for (guint i{0}; i < monitors_->get_n_items(); ++i) {
handleMonitorAdded(monitor); handleMonitorAdded(std::dynamic_pointer_cast<Gdk::Monitor>(monitors_->get_object(i)));
} }
gdk_display->signal_monitor_added().connect(sigc::mem_fun(*this, &Client::handleMonitorAdded));
gdk_display->signal_monitor_removed().connect( monitors_->signal_items_changed().connect([=, this](const guint& position, const guint& removed, const guint& added){
sigc::mem_fun(*this, &Client::handleMonitorRemoved)); for (auto i{removed}; i > 0; --i) {
handleMonitorRemoved(std::dynamic_pointer_cast<Gdk::Monitor>(monitors_->get_object(position + i)));
}
for (auto i{added}; i > 0; --i) {
handleMonitorAdded(std::dynamic_pointer_cast<Gdk::Monitor>(monitors_->get_object(position + i)));
}
});
} }
int waybar::Client::main(int argc, char *argv[]) { int waybar::Client::main(int argc, char *argv[]) {
@ -243,13 +252,8 @@ int waybar::Client::main(int argc, char *argv[]) {
if (!log_level.empty()) { if (!log_level.empty()) {
spdlog::set_level(spdlog::level::from_str(log_level)); spdlog::set_level(spdlog::level::from_str(log_level));
} }
gtk_app = Gtk::Application::create(argc, argv, "fr.arouillard.waybar", gtk_app = Gtk::Application::create("fr.arouillard.waybar",
Gio::APPLICATION_HANDLES_COMMAND_LINE); Gio::Application::Flags::HANDLES_COMMAND_LINE);
// Initialize Waybars GTK resources with our custom icons
auto theme = Gtk::IconTheme::get_default();
theme->add_resource_path("/fr/arouillard/waybar/icons");
gdk_display = Gdk::Display::get_default(); gdk_display = Gdk::Display::get_default();
if (!gdk_display) { if (!gdk_display) {
throw std::runtime_error("Can't find display"); throw std::runtime_error("Can't find display");
@ -257,7 +261,13 @@ int waybar::Client::main(int argc, char *argv[]) {
if (!GDK_IS_WAYLAND_DISPLAY(gdk_display->gobj())) { if (!GDK_IS_WAYLAND_DISPLAY(gdk_display->gobj())) {
throw std::runtime_error("Bar need to run under Wayland"); throw std::runtime_error("Bar need to run under Wayland");
} }
// Initialize Waybars GTK resources with our custom icons
auto theme{Gtk::IconTheme::get_for_display(gdk_display)};
theme->add_resource_path("/fr/arouillard/waybar/icons");
wl_display = gdk_wayland_display_get_wl_display(gdk_display->gobj()); wl_display = gdk_wayland_display_get_wl_display(gdk_display->gobj());
monitors_ = gdk_display->get_monitors();
config.load(config_opt); config.load(config_opt);
if (!portal) { if (!portal) {
portal = std::make_unique<waybar::Portal>(); portal = std::make_unique<waybar::Portal>();
@ -272,6 +282,7 @@ int waybar::Client::main(int argc, char *argv[]) {
gtk_app->hold(); gtk_app->hold();
gtk_app->run(); gtk_app->run();
bars.clear(); bars.clear();
return 0; return 0;
} }

View File

@ -108,11 +108,11 @@ int main(int argc, char* argv[]) {
delete client; delete client;
return ret; return ret;
} catch (const Glib::Error& e) {
spdlog::error("{}", static_cast<std::string>(e.what()));
return 1;
} catch (const std::exception& e) { } catch (const std::exception& e) {
spdlog::error("{}", e.what()); spdlog::error("{}", e.what());
return 1; return 1;
} catch (const Glib::Exception& e) {
spdlog::error("{}", static_cast<std::string>(e.what()));
return 1;
} }
} }

View File

@ -176,16 +176,18 @@ auto waybar::modules::Custom::update() -> void {
} }
} }
} }
auto classes = label_.get_style_context()->list_classes(); auto style = label_.get_style_context();
auto classes = style->list_classes();
for (auto const& c : classes) { for (auto const& c : classes) {
if (c == id_) continue; if (c == id_) continue;
label_.get_style_context()->remove_class(c); style->remove_class(c);
} }
for (auto const& c : class_) { for (auto const& c : class_) {
label_.get_style_context()->add_class(c); style->add_class(c);
} }
label_.get_style_context()->add_class("flat"); style->add_class("flat");
label_.get_style_context()->add_class("text-button"); style->add_class("text-button");
style->add_class(MODULE_CLASS);
event_box_.show(); event_box_.show();
} }
} }

View File

@ -93,7 +93,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
status_manager_{nullptr}, status_manager_{nullptr},
seat_{nullptr}, seat_{nullptr},
bar_(bar), bar_(bar),
box_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, box_{bar.orientation, 0},
output_status_{nullptr} { output_status_{nullptr} {
struct wl_display *display = Client::inst()->wl_display; struct wl_display *display = Client::inst()->wl_display;
struct wl_registry *registry = wl_display_get_registry(display); struct wl_registry *registry = wl_display_get_registry(display);
@ -113,6 +113,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
// Default to 9 tags, cap at 32 // Default to 9 tags, cap at 32

View File

@ -34,9 +34,7 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
} }
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
: AModule(config, "workspaces", id, false, false), : AModule(config, "workspaces", id, false, false), m_bar(bar), m_box(bar.orientation, 0) {
m_bar(bar),
m_box(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
modulesReady = true; modulesReady = true;
parseConfig(config); parseConfig(config);
@ -44,6 +42,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
if (!id.empty()) { if (!id.empty()) {
m_box.get_style_context()->add_class(id); m_box.get_style_context()->add_class(id);
} }
m_box.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(m_box); event_box_.add(m_box);
if (!gIPC) { if (!gIPC) {

View File

@ -7,6 +7,7 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
dp.emit(); dp.emit();

View File

@ -81,7 +81,7 @@ auto supportsLockStates(const libevdev* dev) -> bool {
waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar, waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar,
const Json::Value& config) const Json::Value& config)
: AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()), : AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), box_(bar.orientation, 0),
numlock_label_(""), numlock_label_(""),
capslock_label_(""), capslock_label_(""),
numlock_format_(config_["format"].isString() ? config_["format"].asString() numlock_format_(config_["format"].isString() ? config_["format"].asString()
@ -132,6 +132,7 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
if (config_["device-path"].isString()) { if (config_["device-path"].isString()) {

View File

@ -87,7 +87,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
control_{nullptr}, control_{nullptr},
seat_{nullptr}, seat_{nullptr},
bar_(bar), bar_(bar),
box_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, box_{bar.orientation, 0},
output_status_{nullptr} { output_status_{nullptr} {
struct wl_display *display = Client::inst()->wl_display; struct wl_display *display = Client::inst()->wl_display;
struct wl_registry *registry = wl_display_get_registry(display); struct wl_registry *registry = wl_display_get_registry(display);
@ -111,6 +111,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
// Default to 9 tags, cap at 32 // Default to 9 tags, cap at 32

View File

@ -6,7 +6,7 @@ namespace waybar::modules::SNI {
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
: AModule(config, "tray", id), : AModule(config, "tray", id),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), box_(bar.orientation, 0),
watcher_(SNI::Watcher::getInstance()), watcher_(SNI::Watcher::getInstance()),
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1), host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1)) { std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
@ -15,6 +15,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
if (config_["spacing"].isUInt()) { if (config_["spacing"].isUInt()) {
box_.set_spacing(config_["spacing"].asUInt()); box_.set_spacing(config_["spacing"].asUInt());
} }

View File

@ -27,7 +27,7 @@ int Workspaces::convertWorkspaceNameToNum(std::string name) {
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
: AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()), : AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
bar_(bar), bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) { box_(bar.orientation, 0) {
if (config["format-icons"]["high-priority-named"].isArray()) { if (config["format-icons"]["high-priority-named"].isArray()) {
for (auto &it : config["format-icons"]["high-priority-named"]) { for (auto &it : config["format-icons"]["high-priority-named"]) {
high_priority_named_.push_back(it.asString()); high_priority_named_.push_back(it.asString());
@ -37,6 +37,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
ipc_.subscribe(R"(["workspace"])"); ipc_.subscribe(R"(["workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent)); ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));

View File

@ -277,7 +277,7 @@ Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
handle_{tl_handle}, handle_{tl_handle},
seat_{seat}, seat_{seat},
id_{global_id++}, id_{global_id++},
content_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0} { content_{bar.orientation, 0} {
zwlr_foreign_toplevel_handle_v1_add_listener(handle_, &toplevel_handle_impl, this); zwlr_foreign_toplevel_handle_v1_add_listener(handle_, &toplevel_handle_impl, this);
button.set_relief(Gtk::RELIEF_NONE); button.set_relief(Gtk::RELIEF_NONE);
@ -730,13 +730,14 @@ static const wl_registry_listener registry_listener_impl = {.global = handle_glo
Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Value &config) Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
: waybar::AModule(config, "taskbar", id, false, false), : waybar::AModule(config, "taskbar", id, false, false),
bar_(bar), bar_(bar),
box_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, box_{bar.orientation, 0},
manager_{nullptr}, manager_{nullptr},
seat_{nullptr} { seat_{nullptr} {
box_.set_name("taskbar"); box_.set_name("taskbar");
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
box_.get_style_context()->add_class("empty"); box_.get_style_context()->add_class("empty");
event_box_.add(box_); event_box_.add(box_);

View File

@ -21,9 +21,7 @@ std::map<std::string, std::string> Workspace::icons_map_;
WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar, WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar,
const Json::Value &config) const Json::Value &config)
: waybar::AModule(config, "workspaces", id, false, false), : waybar::AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) {
bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
auto config_sort_by_name = config_["sort-by-name"]; auto config_sort_by_name = config_["sort-by-name"];
if (config_sort_by_name.isBool()) { if (config_sort_by_name.isBool()) {
sort_by_name_ = config_sort_by_name.asBool(); sort_by_name_ = config_sort_by_name.asBool();
@ -54,6 +52,7 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
add_registry_listener(this); add_registry_listener(this);

View File

@ -36,7 +36,7 @@ auto fmt::formatter<waybar::Appearance>::format(waybar::Appearance c, format_con
} }
waybar::Portal::Portal() waybar::Portal::Portal()
: DBus::Proxy(DBus::Connection::get_sync(DBus::BusType::BUS_TYPE_SESSION), PORTAL_BUS_NAME, : DBus::Proxy(DBus::Connection::get_sync(DBus::BusType::SESSION), PORTAL_BUS_NAME,
PORTAL_OBJ_PATH, PORTAL_INTERFACE), PORTAL_OBJ_PATH, PORTAL_INTERFACE),
currentMode(Appearance::UNKNOWN) { currentMode(Appearance::UNKNOWN) {
refreshAppearance(); refreshAppearance();

View File

@ -1,5 +0,0 @@
[wrap-file]
directory = gtk-layer-shell-0.4.0
source_filename = gtk-layer-shell-0.4.0.tar.gz
source_hash = 52fd74d3161fefa5528585ca5a523c3150934961f2284ad010ae54336dad097e
source_url = https://github.com/wmww/gtk-layer-shell/archive/v0.4.0/gtk-layer-shell-0.4.0.tar.gz

View File

@ -0,0 +1,9 @@
[wrap-file]
directory = gtk4-layer-shell-1.0.2
source_filename = gtk4-layer-shell-1.0.2.tar.gz
source_hash = 55fa593241cad200fcb2b647b4dcc0d5d5516792e21a5b65662f010e224d7a73
#source_hash = a3a827845612fa15de30734eb29c01db329c32f8e279d8bc5251facc69220b86
source_url = https://github.com/wmww/gtk4-layer-shell/archive/v1.0.2/gtk4-layer-shell-1.0.2.tar.gz
[provide]
gtk-layer-shell = gtk_layer_shell