GTK4 base compilation

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
gtk4
Viktar Lukashonak 2024-01-08 19:03:42 +03:00
parent f5370fcff5
commit 4a88cb693a
No known key found for this signature in database
GPG Key ID: 08A413AA87200A6F
18 changed files with 179 additions and 568 deletions

View File

@ -25,7 +25,7 @@ class ALabel : public AModule {
bool alt_ = false;
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);
};

View File

@ -2,7 +2,7 @@
#include <glibmm/dispatcher.h>
#include <glibmm/markup.h>
#include <gtkmm/eventbox.h>
//#include <gtkmm/eventbox.h>
#include <json/json.h>
#include "IModule.hpp"
@ -28,25 +28,25 @@ class AModule : public IModule {
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
SCROLL_DIR getScrollDir(GdkEventScroll *e);
// SCROLL_DIR getScrollDir(GdkEventScroll *e);
bool tooltipEnabled();
const std::string name_;
const Json::Value &config_;
Gtk::EventBox event_box_;
// Gtk::EventBox event_box_;
virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleScroll(GdkEventScroll *);
virtual bool handleRelease(GdkEventButton *const &ev);
// virtual bool handleToggle(GdkEventButton *const &ev);
// virtual bool handleScroll(GdkEventScroll *);
// virtual bool handleRelease(GdkEventButton *const &ev);
private:
bool handleUserEvent(GdkEventButton *const &ev);
// bool handleUserEvent(GdkEventButton *const &ev);
const bool isTooltip;
std::vector<int> pid_;
gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_;
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_RELEASE), "on-click-release"},
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
@ -66,7 +66,7 @@ class AModule : public IModule {
{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_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

View File

@ -3,8 +3,8 @@
#include <gdkmm/monitor.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.h>
#include <gtkmm/centerbox.h>
#include <gtkmm/cssprovider.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <json/json.h>
@ -91,6 +91,7 @@ class Bar {
bool visible = true;
bool vertical = false;
Gtk::Window window;
Glib::RefPtr<Gdk::Surface> gdk_surface_;
int x_global;
int y_global;
@ -100,13 +101,13 @@ class Bar {
#endif
private:
void onMap(GdkEventAny *);
void onMap();
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 setupAltFormatKeyForModuleList(const char *module_list_name);
void setMode(const bar_mode &);
void onConfigure(GdkEventConfigure *ev);
void onConfigure(int width, int height);
void configureGlobalOffset(int width, int height);
void onOutputGeometryChanged();
@ -120,7 +121,7 @@ class Bar {
Gtk::Box left_;
Gtk::Box center_;
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_center_;
std::vector<std::shared_ptr<waybar::AModule>> modules_right_;

View File

@ -2,7 +2,7 @@
#include <fmt/format.h>
#include <gdk/gdk.h>
#include <gdk/gdkwayland.h>
#include <gdk/wayland/gdkwayland.h>
#include <wayland-client.h>
#include "bar.hpp"
@ -34,6 +34,7 @@ class Client {
private:
Client() = default;
Glib::RefPtr<Gio::ListModel> monitors_;
const std::string getStyle(const std::string &style, std::optional<Appearance> appearance);
void bindInterfaces();
void handleOutput(struct waybar_output &output);
@ -51,7 +52,7 @@ class Client {
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
void handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> monitor);
Glib::RefPtr<Gtk::StyleContext> style_context_;
// Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_;
std::unique_ptr<Portal> portal;
std::list<struct waybar_output> outputs_;

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ class User : public AIconLabel {
virtual ~User() = default;
auto update() -> void override;
bool handleToggle(GdkEventButton* const& e) override;
//todo bool handleToggle(GdkEventButton* const& e) override;
private:
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 arg_tuple_t = std::tuple<std::decay_t<Args>...>;
// ensure that unwrapped methods are not accessible
using signal_t::emit_reverse;
using signal_t::emit;
using signal_t::make_slot;
void handle_event() {

View File

@ -19,7 +19,7 @@ class Portal : private DBus::Proxy {
void refreshAppearance();
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; }
private:

View File

@ -1,10 +1,10 @@
project(
'waybar', 'cpp', 'c',
version: '0.9.24',
version: '4.1.0',
license: 'MIT',
meson_version: '>= 0.50.0',
meson_version: '>= 1.3.0',
default_options : [
'cpp_std=c++20',
'cpp_std=c++23',
'buildtype=release',
'default_library=static'
],
@ -78,78 +78,24 @@ is_freebsd = host_machine.system() == 'freebsd'
is_netbsd = host_machine.system() == 'netbsd'
is_openbsd = host_machine.system() == 'openbsd'
thread_dep = dependency('threads')
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'])
jsoncpp = dependency('jsoncpp', version : ['>=1.9.4'], fallback : ['jsoncpp', 'jsoncpp_dep'])
wayland_client = dependency('wayland-client')
wayland_cursor = dependency('wayland-cursor')
wayland_protos = dependency('wayland-protocols')
gtkmm = dependency('gtkmm-3.0', version : ['>=3.22.0'])
dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4', required: get_option('dbusmenu-gtk'))
giounix = dependency('gio-unix-2.0', required: (get_option('dbusmenu-gtk').enabled() or
get_option('logind').enabled() or
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'))
sigcpp = dependency('sigc++-3.0', version: ['>=3.4.0'])
gtkmm = dependency('gtkmm-4.0', version : ['>=4.12.0'])
gtk = dependency('gtk4', version : ['>=4.10.5'])
giounix = dependency('gio-unix-2.0', version: ['>=2.76.4'])
spdlog = dependency('spdlog', version : ['>=1.10.0'], fallback : ['spdlog', 'spdlog_dep'], default_options : ['external_fmt=enabled'])
libsndio = compiler.find_library('sndio', required: get_option('sndio'))
if libsndio.found()
if not compiler.has_function('sioctl_open', prefix: '#include <sndio.h>', dependencies: libsndio)
if get_option('sndio').enabled()
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('gtk4-layer-shell-0',
version : ['>=1.0.2'],
required: get_option('gtk-layer-shell'),
fallback : ['gtk4-layer-shell', 'gtk_layer_shell'],
default_options : ['vapi=false'])
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' ])
if gtk_layer_shell.found()
add_project_arguments('-DHAVE_GTK_LAYER_SHELL', language: 'cpp')
endif
prefix = get_option('prefix')
@ -159,283 +105,33 @@ conf_data.set('prefix', prefix)
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/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/bar.cpp',
'src/client.cpp',
'src/config.cpp',
'src/group.cpp',
'src/util/portal.cpp',
'src/util/enum.cpp',
'src/util/prepare_for_sleep.cpp',
'src/util/ustring_clen.cpp',
'src/util/sanitize_str.cpp',
'src/util/rewrite_string.cpp',
'src/util/gtk_icon.cpp',
'src/util/regex_collection.cpp'
'src/main.cpp',
'src/client.cpp',
'src/bar.cpp',
'src/config.cpp',
'src/util/portal.cpp',
'src/util/prepare_for_sleep.cpp',
# 'src/AModule.cpp',
)
inc_dirs = ['include']
if is_linux
add_project_arguments('-DHAVE_CPU_LINUX', language: 'cpp')
add_project_arguments('-DHAVE_MEMORY_LINUX', 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',
)
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')
app_resources = []
subdir('resources/icons')
executable(
'waybar',
[src_files, app_resources],
[src_files],
dependencies: [
thread_dep,
client_protos,
wayland_client,
fmt,
spdlog,
gtk,
gtk_layer_shell,
gtkmm,
giounix,
sigcpp,
jsoncpp,
wayland_client,
wayland_cursor,
gtkmm,
dbusmenu_gtk,
giounix,
libinput,
libnl,
libnlgen,
upower_glib,
pipewire,
playerctl,
libpulse,
libjack,
libwireplumber,
libudev,
libinotify,
libepoll,
libmpdclient,
libevdev,
gtk_layer_shell,
libsndio,
tz_dep,
xkbregistry,
cava
client_protos,
spdlog
],
include_directories: inc_dirs,
install: true,
@ -446,112 +142,3 @@ install_data(
'./resources/style.css',
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-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: '>=2.0.0',
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

@ -1,5 +1,5 @@
#ifdef HAVE_GTK_LAYER_SHELL
#include <gtk-layer-shell.h>
#include <gtk4-layer-shell.h>
#endif
#include <spdlog/spdlog.h>
@ -8,7 +8,7 @@
#include "bar.hpp"
#include "client.hpp"
#include "factory.hpp"
//#include "factory.hpp"
#include "group.hpp"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@ -108,17 +108,16 @@ 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} {
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_keyboard_mode(window.gobj(), GTK_LAYER_SHELL_KEYBOARD_MODE_NONE);
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));
window.signal_map().connect(sigc::mem_fun(*this, &GLSSurfaceImpl::onMap));
}
void setExclusiveZone(bool enable) override {
@ -148,13 +147,12 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
void setPassThrough(bool enable) override {
passthrough_ = enable;
auto gdk_window = window_.get_window();
if (gdk_window) {
if (gdk_surface_) {
Cairo::RefPtr<Cairo::Region> region;
if (enable) {
region = Cairo::Region::create();
}
gdk_window->input_shape_combine_region(region, 0, 0);
gdk_surface_->set_input_region(region);
}
}
@ -195,15 +193,19 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
private:
Gtk::Window& window_;
Glib::RefPtr<Gdk::Surface> gdk_surface_;
std::string output_name_;
uint32_t width_;
uint32_t height_;
bool passthrough_ = false;
bool vertical_ = false;
void onMap(GdkEventAny* ev) { setPassThrough(passthrough_); }
void onMap() {
gdk_surface_ = window_.get_surface();
gdk_surface_->signal_layout().connect(sigc::mem_fun(*this, &GLSSurfaceImpl::onConfigure));
setPassThrough(passthrough_); }
void onConfigure(GdkEventConfigure* ev) {
void onConfigure(int width, int height) {
/*
* GTK wants new size for the window.
* Actual resizing and management of the exclusve zone is handled within the gtk-layer-shell
@ -213,30 +215,30 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
* gtk-layer-shell.
*/
if (vertical_) {
if (width_ > 1 && ev->width > static_cast<int>(width_)) {
spdlog::warn(MIN_WIDTH_MSG, width_, ev->width);
if (width_ > 1 && width > static_cast<int>(width_)) {
spdlog::warn(MIN_WIDTH_MSG, width_, width);
}
} else {
if (height_ > 1 && ev->height > static_cast<int>(height_)) {
spdlog::warn(MIN_HEIGHT_MSG, height_, ev->height);
if (height_ > 1 && height > static_cast<int>(height_)) {
spdlog::warn(MIN_HEIGHT_MSG, height_, height);
}
}
width_ = ev->width;
height_ = ev->height;
width_ = width;
height_ = 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} {
RawSurfaceImpl(Gtk::Window& window, struct waybar_output& output)
: window_{window}, gdk_surface_{window_.get_surface()} {
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));
window.signal_realize().connect(sigc::mem_fun(*this, &RawSurfaceImpl::onRealize));
window.signal_map().connect(sigc::mem_fun(*this, &RawSurfaceImpl::onMap));
gdk_surface_->signal_layout().connect(sigc::mem_fun(*this, &RawSurfaceImpl::onConfigure));
if (window.get_realized()) {
onRealize();
@ -294,13 +296,12 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
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) {
if (gdk_surface_) {
Cairo::RefPtr<Cairo::Region> region;
if (enable) {
region = Cairo::Region::create();
}
gdk_window->input_shape_combine_region(region, 0, 0);
gdk_surface_->set_input_region(region);
}
}
@ -345,6 +346,7 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
std::unique_ptr<zwlr_layer_surface_v1, deleter_fn<zwlr_layer_surface_v1_destroy>>;
Gtk::Window& window_;
Glib::RefPtr<Gdk::Surface> gdk_surface_;
std::string output_name_;
uint32_t configured_width_ = 0;
uint32_t configured_height_ = 0;
@ -361,18 +363,16 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
layer_surface_ptr layer_surface_;
void onRealize() {
auto gdk_window = window_.get_window()->gobj();
gdk_wayland_window_set_use_custom_surface(gdk_window);
gtk_layer_init_for_window(window_.gobj());
}
void onMap(GdkEventAny* ev) {
void onMap() {
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);
surface_ = gdk_wayland_surface_get_wl_surface(gdk_surface_->gobj());
layer_surface_.reset(zwlr_layer_shell_v1_get_layer_surface(client->layer_shell, surface_,
output_, layer_, "waybar"));
@ -391,7 +391,7 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
wl_display_roundtrip(client->wl_display);
}
void onConfigure(GdkEventConfigure* ev) {
void onConfigure(int width, int height) {
/*
* GTK wants new size for the window.
*
@ -401,26 +401,26 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
*/
auto tmp_height = height_;
auto tmp_width = width_;
if (ev->height > static_cast<int>(height_)) {
if (height > static_cast<int>(height_)) {
// Default minimal value
if (height_ > 1) {
spdlog::warn(MIN_HEIGHT_MSG, height_, ev->height);
spdlog::warn(MIN_HEIGHT_MSG, height_, height);
}
if (configured_height_ > 1) {
spdlog::info(SIZE_DEFINED, "Height");
} else {
tmp_height = ev->height;
tmp_height = height;
}
}
if (ev->width > static_cast<int>(width_)) {
if (width > static_cast<int>(width_)) {
// Default minimal value
if (width_ > 1) {
spdlog::warn(MIN_WIDTH_MSG, width_, ev->width);
spdlog::warn(MIN_WIDTH_MSG, width_, width);
}
if (configured_width_ > 1) {
spdlog::info(SIZE_DEFINED, "Width");
} else {
tmp_width = ev->width;
tmp_width = width;
}
}
if (tmp_width != width_ || tmp_height != height_) {
@ -460,7 +460,6 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
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_);
@ -480,17 +479,18 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
: output(w_output),
config(w_config),
window{Gtk::WindowType::WINDOW_TOPLEVEL},
window{Gtk::Window()},
x_global(0),
y_global(0),
margins_{.top = 0, .right = 0, .bottom = 0, .left = 0},
left_(Gtk::ORIENTATION_HORIZONTAL, 0),
center_(Gtk::ORIENTATION_HORIZONTAL, 0),
right_(Gtk::ORIENTATION_HORIZONTAL, 0),
box_(Gtk::ORIENTATION_HORIZONTAL, 0) {
left_(Gtk::Orientation::HORIZONTAL, 0),
center_(Gtk::Orientation::HORIZONTAL, 0),
right_(Gtk::Orientation::HORIZONTAL, 0),
box_{} {
window.set_title("waybar");
window.set_name("waybar");
window.set_decorated(false);
window.set_child(box_);
window.get_style_context()->add_class(output->name);
window.get_style_context()->add_class(config["name"].asString());
window.get_style_context()->add_class(config["position"].asString());
@ -498,12 +498,13 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
auto position = config["position"].asString();
if (position == "right" || position == "left") {
left_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
center_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
right_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
box_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
left_.set_orientation(Gtk::Orientation::VERTICAL);
center_.set_orientation(Gtk::Orientation::VERTICAL);
right_.set_orientation(Gtk::Orientation::VERTICAL);
box_.set_orientation(Gtk::Orientation::VERTICAL);
vertical = true;
}
} else
box_.set_orientation(Gtk::Orientation::HORIZONTAL);
left_.get_style_context()->add_class("modules-left");
center_.get_style_context()->add_class("modules-center");
@ -564,7 +565,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
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(
sigc::mem_fun(*this, &Bar::onOutputGeometryChanged));
@ -602,7 +602,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
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 (auto ipc = config["ipc"]; ipc.isBool() && ipc.asBool()) {
@ -622,7 +622,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
#endif
setupWidgets();
window.show_all();
window.show();
if (spdlog::should_log(spdlog::level::debug)) {
// Unfortunately, this function isn't in the C++ bindings, so we have to call the C version.
@ -673,13 +673,18 @@ void waybar::Bar::setMode(const struct bar_mode& mode) {
surface_impl_->commit();
}
void waybar::Bar::onMap(GdkEventAny*) {
void waybar::Bar::onMap() {
/*
* Obtain a pointer to the custom layer surface for modules that require it (idle_inhibitor).
*/
auto gdk_window = window.get_window()->gobj();
surface = gdk_wayland_window_get_wl_surface(gdk_window);
configureGlobalOffset(gdk_window_get_width(gdk_window), gdk_window_get_height(gdk_window));
gdk_surface_ = window.get_surface();
if (gdk_surface_)
spdlog::info("Pointer is defined\n");
else
spdlog::info("Pointer is null\n");
surface = gdk_wayland_surface_get_wl_surface(gdk_surface_->gobj());
configureGlobalOffset(gdk_surface_->get_width(), gdk_surface_->get_height());
gdk_surface_->signal_layout().connect(sigc::mem_fun(*this, &Bar::onConfigure));
}
void waybar::Bar::setVisible(bool value) {
@ -739,6 +744,8 @@ void waybar::Bar::handleSignal(int signal) {
}
}
// todo gtkmm4
/*
void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
waybar::Group* group = nullptr) {
auto module_list = group ? config[pos]["modules"] : config[pos];
@ -754,7 +761,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 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);
getModules(factory, ref, group_module);
@ -791,40 +798,39 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
}
}
}
*/
auto waybar::Bar::setupWidgets() -> void {
window.add(box_);
box_.pack_start(left_, false, false);
box_.set_start_widget(left_);
if (config["fixed-center"].isBool() ? config["fixed-center"].asBool() : true) {
box_.set_center_widget(center_);
} 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.
setupAltFormatKeyForModuleList("modules-left");
setupAltFormatKeyForModuleList("modules-right");
setupAltFormatKeyForModuleList("modules-center");
Factory factory(*this, config);
getModules(factory, "modules-left");
getModules(factory, "modules-center");
getModules(factory, "modules-right");
// todo gtkmm4
// Factory factory(*this, config);
// getModules(factory, "modules-left");
// getModules(factory, "modules-center");
// getModules(factory, "modules-right");
for (auto const& module : modules_left_) {
left_.pack_start(*module, false, false);
left_.prepend(*module);
}
for (auto const& module : modules_center_) {
center_.pack_start(*module, false, false);
center_.prepend(*module);
}
std::reverse(modules_right_.begin(), modules_right_.end());
for (auto const& module : modules_right_) {
right_.pack_end(*module, false, false);
right_.append(*module);
}
}
void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
configureGlobalOffset(ev->width, ev->height);
void waybar::Bar::onConfigure(int width, int height) {
configureGlobalOffset(width, height);
}
void waybar::Bar::configureGlobalOffset(int width, int height) {

View File

@ -5,6 +5,7 @@
#include <iostream>
#include "gtkmm/icontheme.h"
#include "gtkmm/application.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "util/clara.hpp"
#include "util/format.hpp"
@ -181,15 +182,17 @@ const std::string waybar::Client::getStyle(const std::string &style,
auto waybar::Client::setupCss(const std::string &css_file) -> void {
css_provider_ = Gtk::CssProvider::create();
style_context_ = Gtk::StyleContext::create();
//todo gtkmm4 style_context_ = get_style_context();// Gtk::StyleContext::create();
// Load our css file, wherever that may be hiding
if (!css_provider_->load_from_path(css_file)) {
throw std::runtime_error("Can't open style file");
try {
css_provider_->load_from_path(css_file);
} catch (const Glib::Error& e) {
spdlog::error("{}", e.what());
}
// there's always only one screen
style_context_->add_provider_for_screen(Gdk::Screen::get_default(), css_provider_,
GTK_STYLE_PROVIDER_PRIORITY_USER);
//todo gtkmm4 style_context_->add_provider_for_screen(Gdk::Screen::get_default(), css_provider_,
// GTK_STYLE_PROVIDER_PRIORITY_USER);
}
void waybar::Client::bindInterfaces() {
@ -204,13 +207,20 @@ void waybar::Client::bindInterfaces() {
throw std::runtime_error("Failed to acquire required resources.");
}
// add existing outputs and subscribe to updates
for (auto i = 0; i < gdk_display->get_n_monitors(); ++i) {
auto monitor = gdk_display->get_monitor(i);
handleMonitorAdded(monitor);
// auto monitors{gdk_display->get_monitors()};
for (guint i{0}; i < monitors_->get_n_items(); ++i) {
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(
sigc::mem_fun(*this, &Client::handleMonitorRemoved));
monitors_->signal_items_changed().connect([=, this](const guint& position, const guint& removed, const guint& added){
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[]) {
@ -243,13 +253,8 @@ int waybar::Client::main(int argc, char *argv[]) {
if (!log_level.empty()) {
spdlog::set_level(spdlog::level::from_str(log_level));
}
gtk_app = Gtk::Application::create(argc, argv, "fr.arouillard.waybar",
Gio::APPLICATION_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");
gtk_app = Gtk::Application::create("fr.arouillard.waybar",
Gio::Application::Flags::HANDLES_COMMAND_LINE);
gdk_display = Gdk::Display::get_default();
if (!gdk_display) {
throw std::runtime_error("Can't find display");
@ -257,7 +262,13 @@ int waybar::Client::main(int argc, char *argv[]) {
if (!GDK_IS_WAYLAND_DISPLAY(gdk_display->gobj())) {
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());
monitors_ = gdk_display->get_monitors();
config.load(config_opt);
if (!portal) {
portal = std::make_unique<waybar::Portal>();
@ -272,6 +283,7 @@ int waybar::Client::main(int argc, char *argv[]) {
gtk_app->hold();
gtk_app->run();
bars.clear();
return 0;
}

View File

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

View File

@ -36,7 +36,7 @@ auto fmt::formatter<waybar::Appearance>::format(waybar::Appearance c, format_con
}
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),
currentMode(Appearance::UNKNOWN) {
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