Merge pull request #2926 from alebastr/meson-cleanup

build: refactorings and deprecation fixes
This commit is contained in:
Alexis Rouillard 2024-02-19 23:44:52 +01:00 committed by GitHub
commit 6048e23e09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 195 additions and 169 deletions

View File

@ -13,8 +13,10 @@
#include "modules/sway/window.hpp"
#include "modules/sway/workspaces.hpp"
#endif
#ifdef HAVE_WLR
#ifdef HAVE_WLR_TASKBAR
#include "modules/wlr/taskbar.hpp"
#endif
#ifdef HAVE_WLR_WORKSPACES
#include "modules/wlr/workspace_manager.hpp"
#endif
#ifdef HAVE_RIVER
@ -33,7 +35,7 @@
#include "modules/hyprland/window.hpp"
#include "modules/hyprland/workspaces.hpp"
#endif
#if defined(__FreeBSD__) || (defined(__linux__) && !defined(NO_FILESYSTEM))
#if defined(__FreeBSD__) || defined(__linux__)
#include "modules/battery.hpp"
#endif
#if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD)
@ -80,8 +82,10 @@
#ifdef HAVE_LIBSNDIO
#include "modules/sndio.hpp"
#endif
#ifdef HAVE_GIO_UNIX
#if defined(__linux__)
#include "modules/bluetooth.hpp"
#endif
#ifdef HAVE_LOGIND_INHIBITOR
#include "modules/inhibitor.hpp"
#endif
#ifdef HAVE_LIBJACK

View File

@ -1,11 +1,8 @@
#pragma once
#ifdef FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
#else
#include <filesystem>
#endif
#include <fmt/format.h>
#include <filesystem>
#if defined(__linux__)
#include <sys/inotify.h>
#endif
@ -21,11 +18,7 @@
namespace waybar::modules {
#ifdef FILESYSTEM_EXPERIMENTAL
namespace fs = std::experimental::filesystem;
#else
namespace fs = std::filesystem;
#endif
class Battery : public ALabel {
public:

View File

@ -16,6 +16,8 @@ class CssReloadHelper {
public:
CssReloadHelper(std::string cssFile, std::function<void()> callback);
virtual ~CssReloadHelper() = default;
virtual void monitorChanges();
protected:

View File

@ -139,6 +139,7 @@ Additional to workspace name matching, the following *format-icons* can be set.
}
```
```
"hyprland/workspaces": {
// Formatting omitted for brevity
"ignore-workspaces": [

View File

@ -2,7 +2,7 @@ project(
'waybar', 'cpp', 'c',
version: '0.9.24',
license: 'MIT',
meson_version: '>= 0.50.0',
meson_version: '>= 0.59.0',
default_options : [
'cpp_std=c++20',
'buildtype=release',
@ -22,8 +22,6 @@ endif
if compiler.has_link_argument('-lc++fs')
cpp_link_args += ['-lc++fs']
elif compiler.has_link_argument('-lc++experimental')
cpp_link_args += ['-lc++experimental']
elif compiler.has_link_argument('-lstdc++fs')
cpp_link_args += ['-lstdc++fs']
endif
@ -33,10 +31,10 @@ git = find_program('git', native: true, required: false)
if not git.found()
add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp')
else
git_path = run_command([git.path(), 'rev-parse', '--show-toplevel']).stdout().strip()
if meson.source_root() == git_path
git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']).stdout().strip()
git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip()
git_path = run_command(git, 'rev-parse', '--show-toplevel', check: false).stdout().strip()
if meson.project_source_root() == git_path
git_commit_hash = run_command(git, 'describe', '--always', '--tags', check: false).stdout().strip()
git_branch = run_command(git, 'rev-parse', '--abbrev-ref', 'HEAD', check: false).stdout().strip()
version = '"@0@ (branch \'@1@\')"'.format(git_commit_hash, git_branch)
add_project_arguments('-DVERSION=@0@'.format(version), language: 'cpp')
else
@ -44,15 +42,6 @@ else
endif
endif
if not compiler.has_header('filesystem')
if compiler.has_header('experimental/filesystem')
add_project_arguments('-DFILESYSTEM_EXPERIMENTAL', language: 'cpp')
else
add_project_arguments('-DNO_FILESYSTEM', language: 'cpp')
warning('No filesystem header found, some modules may not work')
endif
endif
code = '''
#include <langinfo.h>
#include <locale.h>
@ -86,10 +75,7 @@ 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()))
giounix = dependency('gio-unix-2.0')
jsoncpp = dependency('jsoncpp', version : ['>=1.9.2'], fallback : ['jsoncpp', 'jsoncpp_dep'])
sigcpp = dependency('sigc++-2.0')
libinotify = dependency('libinotify', required: false)
@ -157,10 +143,10 @@ sysconfdir = get_option('sysconfdir')
conf_data = configuration_data()
conf_data.set('prefix', prefix)
add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'cpp')
add_project_arguments('-DSYSCONFDIR="@0@"'.format(prefix / sysconfdir), language : 'cpp')
if systemd.found()
user_units_dir = systemd.get_pkgconfig_variable('systemduserunitdir')
user_units_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir')
configure_file(
configuration: conf_data,
@ -200,6 +186,15 @@ src_files = files(
'src/util/css_reload_helper.cpp'
)
man_files = files(
'man/waybar-custom.5.scd',
'man/waybar-disk.5.scd',
'man/waybar-idle-inhibitor.5.scd',
'man/waybar-image.5.scd',
'man/waybar-states.5.scd',
'man/waybar-temperature.5.scd',
)
inc_dirs = ['include']
if is_linux
@ -208,6 +203,7 @@ if is_linux
add_project_arguments('-DHAVE_SYSTEMD_MONITOR', language: 'cpp')
src_files += files(
'src/modules/battery.cpp',
'src/modules/bluetooth.cpp',
'src/modules/cffi.cpp',
'src/modules/cpu.cpp',
'src/modules/cpu_frequency/common.cpp',
@ -218,6 +214,14 @@ if is_linux
'src/modules/memory/linux.cpp',
'src/modules/systemd_failed_units.cpp',
)
man_files += files(
'man/waybar-battery.5.scd',
'man/waybar-bluetooth.5.scd',
'man/waybar-cffi.5.scd',
'man/waybar-cpu.5.scd',
'man/waybar-memory.5.scd',
'man/waybar-systemd-failed-units.5.scd',
)
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')
@ -231,15 +235,20 @@ elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
'src/modules/memory/bsd.cpp',
'src/modules/memory/common.cpp',
)
if is_freebsd
src_files += files(
'src/modules/battery.cpp',
man_files += files(
'man/waybar-cffi.5.scd',
'man/waybar-cpu.5.scd',
'man/waybar-memory.5.scd',
)
if is_freebsd
src_files += files('src/modules/battery.cpp')
man_files += files('man/waybar-battery.5.scd')
endif
endif
add_project_arguments('-DHAVE_SWAY', language: 'cpp')
src_files += [
if true
add_project_arguments('-DHAVE_SWAY', language: 'cpp')
src_files += files(
'src/modules/sway/ipc/client.cpp',
'src/modules/sway/bar.cpp',
'src/modules/sway/mode.cpp',
@ -247,81 +256,128 @@ src_files += [
'src/modules/sway/window.cpp',
'src/modules/sway/workspaces.cpp',
'src/modules/sway/scratchpad.cpp'
]
)
man_files += files(
'man/waybar-sway-language.5.scd',
'man/waybar-sway-mode.5.scd',
'man/waybar-sway-scratchpad.5.scd',
'man/waybar-sway-window.5.scd',
'man/waybar-sway-workspaces.5.scd',
)
endif
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'
add_project_arguments('-DHAVE_WLR_TASKBAR', language: 'cpp')
src_files += files('src/modules/wlr/taskbar.cpp')
man_files += files('man/waybar-wlr-taskbar.5.scd')
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'
src_files += files(
'src/modules/river/layout.cpp',
'src/modules/river/mode.cpp',
'src/modules/river/tags.cpp',
'src/modules/river/window.cpp',
)
man_files += files(
'man/waybar-river-layout.5.scd',
'man/waybar-river-mode.5.scd',
'man/waybar-river-tags.5.scd',
'man/waybar-river-window.5.scd',
)
endif
if true
add_project_arguments('-DHAVE_DWL', language: 'cpp')
src_files += 'src/modules/dwl/tags.cpp'
src_files += files('src/modules/dwl/tags.cpp')
man_files += files('man/waybar-dwl-tags.5.scd')
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'
src_files += files(
'src/modules/hyprland/backend.cpp',
'src/modules/hyprland/language.cpp',
'src/modules/hyprland/submap.cpp',
'src/modules/hyprland/window.cpp',
'src/modules/hyprland/workspaces.cpp',
)
man_files += files(
'man/waybar-hyprland-language.5.scd',
'man/waybar-hyprland-submap.5.scd',
'man/waybar-hyprland-window.5.scd',
'man/waybar-hyprland-workspaces.5.scd',
)
endif
if libnl.found() and libnlgen.found()
add_project_arguments('-DHAVE_LIBNL', language: 'cpp')
src_files += 'src/modules/network.cpp'
src_files += files('src/modules/network.cpp')
man_files += files('man/waybar-network.5.scd')
endif
if (giounix.found() and not get_option('logind').disabled())
add_project_arguments('-DHAVE_GAMEMODE', language: 'cpp')
src_files += 'src/modules/gamemode.cpp'
if not get_option('logind').disabled()
add_project_arguments('-DHAVE_GAMEMODE', '-DHAVE_LOGIND_INHIBITOR', language: 'cpp')
src_files += files(
'src/modules/gamemode.cpp',
'src/modules/inhibitor.cpp',
)
man_files += files(
'man/waybar-gamemode.5.scd',
'man/waybar-inhibitor.5.scd',
)
endif
if (upower_glib.found() and giounix.found() and not get_option('logind').disabled())
if (upower_glib.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'
src_files += files(
'src/modules/upower/upower.cpp',
'src/modules/upower/upower_tooltip.cpp',
)
man_files += files('man/waybar-upower.5.scd')
endif
if (pipewire.found())
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'
src_files += files(
'src/modules/privacy/privacy.cpp',
'src/modules/privacy/privacy_item.cpp',
'src/util/pipewire_backend.cpp',
)
man_files += files('man/waybar-privacy.5.scd')
endif
if (playerctl.found() and giounix.found() and not get_option('logind').disabled())
if playerctl.found()
add_project_arguments('-DHAVE_MPRIS', language: 'cpp')
src_files += 'src/modules/mpris/mpris.cpp'
src_files += files('src/modules/mpris/mpris.cpp')
man_files += files('man/waybar-mpris.5.scd')
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'
src_files += files(
'src/modules/pulseaudio.cpp',
'src/modules/pulseaudio_slider.cpp',
'src/util/audio_backend.cpp',
)
man_files += files(
'man/waybar-pulseaudio.5.scd',
'man/waybar-pulseaudio-slider.5.scd',
)
endif
if libjack.found()
add_project_arguments('-DHAVE_LIBJACK', language: 'cpp')
src_files += 'src/modules/jack.cpp'
src_files += files('src/modules/jack.cpp')
man_files += files('man/waybar-jack.5.scd')
endif
if libwireplumber.found()
add_project_arguments('-DHAVE_LIBWIREPLUMBER', language: 'cpp')
src_files += 'src/modules/wireplumber.cpp'
src_files += files('src/modules/wireplumber.cpp')
man_files += files('man/waybar-wireplumber.5.scd')
endif
if dbusmenu_gtk.found()
@ -332,36 +388,46 @@ if dbusmenu_gtk.found()
'src/modules/sni/host.cpp',
'src/modules/sni/item.cpp'
)
man_files += files(
'man/waybar-tray.5.scd',
)
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'
src_files += files(
'src/modules/backlight.cpp',
'src/modules/backlight_slider.cpp',
'src/util/backlight_backend.cpp',
)
man_files += files(
'man/waybar-backlight.5.scd',
'man/waybar-backlight-slider.5.scd',
)
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'
src_files += files('src/modules/keyboard_state.cpp')
man_files += files('man/waybar-keyboard-state.5.scd')
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'
src_files += files(
'src/modules/mpd/mpd.cpp',
'src/modules/mpd/state.cpp',
)
man_files += files(
'man/waybar-mpd.5.scd',
)
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'
src_files += files('src/modules/sndio.cpp')
man_files += files('man/waybar-sndio.5.scd')
endif
if get_option('rfkill').enabled() and is_linux
@ -373,16 +439,26 @@ endif
if have_chrono_timezones
add_project_arguments('-DHAVE_CHRONO_TIMEZONES', language: 'cpp')
src_files += 'src/modules/clock.cpp'
src_files += files('src/modules/clock.cpp')
man_files += files('man/waybar-clock.5.scd')
elif tz_dep.found()
add_project_arguments('-DHAVE_LIBDATE', language: 'cpp')
src_files += 'src/modules/clock.cpp'
src_files += files('src/modules/clock.cpp')
man_files += files('man/waybar-clock.5.scd')
else
src_files += 'src/modules/simpleclock.cpp'
src_files += files('src/modules/simpleclock.cpp')
man_files += files('man/waybar-clock.5.scd')
endif
if get_option('experimental')
add_project_arguments('-DUSE_EXPERIMENTAL', language: 'cpp')
add_project_arguments('-DHAVE_WLR_WORKSPACES', language: 'cpp')
src_files += files(
'src/modules/wlr/workspace_manager.cpp',
'src/modules/wlr/workspace_manager_binding.cpp',
)
man_files += files(
'man/waybar-wlr-workspaces.5.scd',
)
endif
cava = dependency('cava',
@ -393,7 +469,8 @@ cava = dependency('cava',
if cava.found()
add_project_arguments('-DHAVE_LIBCAVA', language: 'cpp')
src_files += 'src/modules/cava.cpp'
src_files += files('src/modules/cava.cpp')
man_files += files('man/waybar-cava.5.scd')
endif
subdir('protocol')
@ -443,77 +520,24 @@ executable(
install_data(
'./resources/config',
'./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(
man_files += configure_file(
input: 'man/waybar.5.scd.in',
output: 'waybar.5.scd',
configuration: {
'sysconfdir': join_paths(prefix, sysconfdir)
'sysconfdir': prefix / sysconfdir
}
)
main_manpage_path = join_paths(meson.build_root(), '@0@'.format(main_manpage))
fs = import('fs')
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]
basename = fs.name(file)
topic = basename.split('.')[-3]
section = basename.split('.')[-2]
@ -521,12 +545,11 @@ if scdoc.found()
custom_target(
output,
# drops the 'man' if `path` is an absolute path
input: join_paths('man', path),
input: file,
output: output,
command: [
sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc_prog.path(), output)
],
command: scdoc.get_variable('scdoc'),
feed: true,
capture: true,
install: true,
install_dir: '@0@/man@1@'.format(mandir, section)
)
@ -536,6 +559,7 @@ endif
catch2 = dependency(
'catch2',
version: '>=3.5.1',
default_options: [ 'tests=false' ],
fallback: ['catch2', 'catch2_dep'],
required: get_option('tests'),
)
@ -551,7 +575,7 @@ if clangtidy.found()
command: [
clangtidy,
'-checks=*,-fuchsia-default-arguments',
'-p', meson.build_root()
'-p', meson.project_build_root()
] + src_files)
endif

View File

@ -1,4 +1,4 @@
wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir')
wl_protocol_dir = wayland_protos.get_variable(pkgconfig: 'pkgdatadir')
wayland_scanner = find_program('wayland-scanner')
@ -43,7 +43,7 @@ endforeach
gdbus_codegen = find_program('gdbus-codegen')
r = run_command(gdbus_codegen, '--body', '--output', '/dev/null')
r = run_command(gdbus_codegen, '--body', '--output', '/dev/null', check: false)
if r.returncode() != 0
gdbus_code_dsnw = custom_target(
'dbus-status-notifier-watcher.[ch]',

View File

@ -16,7 +16,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
auto hash_pos = name.find('#');
auto ref = name.substr(0, hash_pos);
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
#if defined(__FreeBSD__) || (defined(__linux__) && !defined(NO_FILESYSTEM))
#if defined(__FreeBSD__) || defined(__linux__)
if (ref == "battery") {
return new waybar::modules::Battery(id, bar_, config_[name]);
}
@ -58,16 +58,16 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
return new waybar::modules::sway::Scratchpad(id, config_[name]);
}
#endif
#ifdef HAVE_WLR
#ifdef HAVE_WLR_TASKBAR
if (ref == "wlr/taskbar") {
return new waybar::modules::wlr::Taskbar(id, bar_, config_[name]);
}
#ifdef USE_EXPERIMENTAL
#endif
#ifdef HAVE_WLR_WORKSPACES
if (ref == "wlr/workspaces") {
return new waybar::modules::wlr::WorkspaceManager(id, bar_, config_[name]);
}
#endif
#endif
#ifdef HAVE_RIVER
if (ref == "river/mode") {
return new waybar::modules::river::Mode(id, bar_, config_[name]);
@ -178,10 +178,12 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
return new waybar::modules::Sndio(id, config_[name]);
}
#endif
#ifdef HAVE_GIO_UNIX
#if defined(__linux__)
if (ref == "bluetooth") {
return new waybar::modules::Bluetooth(id, config_[name]);
}
#endif
#ifdef HAVE_LOGIND_INHIBITOR
if (ref == "inhibitor") {
return new waybar::modules::Inhibitor(id, bar_, config_[name]);
}

View File

@ -31,5 +31,5 @@ waybar_test = executable(
test(
'waybar',
waybar_test,
workdir: meson.source_root(),
workdir: meson.project_source_root(),
)