From bb4ccb5d424656eafaf92668d55d6a9a7c1640e8 Mon Sep 17 00:00:00 2001 From: pupbrained Date: Sat, 10 May 2025 16:35:23 -0400 Subject: [PATCH] linux optionality stuff --- meson.build | 29 ++++++++++++++++++++++------- src/os/linux.cpp | 22 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 64dc827..de36128 100644 --- a/meson.build +++ b/meson.build @@ -134,16 +134,31 @@ elif host_system == 'windows' cpp.find_library('dwmapi'), cpp.find_library('windowsapp'), ] -elif host_system != 'serenity' +elif host_system != 'serenity' and host_system != 'haiku' + # Make dbus, x11, and wayland dependencies optional + dbus_dep = dependency('dbus-1', required: false) + xcb_dep = dependency('xcb', required: false) + xau_dep = dependency('xau', required: false) + xdmcp_dep = dependency('xdmcp', required: false) + wayland_dep = dependency('wayland-client', required: false) + platform_deps += [ dependency('SQLiteCpp'), dependency('pugixml'), - dependency('xcb'), - dependency('xau'), - dependency('xdmcp'), - dependency('wayland-client'), - dependency('dbus-1'), ] + + if dbus_dep.found() + platform_deps += dbus_dep + add_project_arguments('-DHAVE_DBUS', language: 'cpp') + endif + if xcb_dep.found() and xau_dep.found() and xdmcp_dep.found() + platform_deps += [xcb_dep, xau_dep, xdmcp_dep] + add_project_arguments('-DHAVE_XCB', language: 'cpp') + endif + if wayland_dep.found() + platform_deps += wayland_dep + add_project_arguments('-DHAVE_WAYLAND', language: 'cpp') + endif endif # FTXUI configuration @@ -201,4 +216,4 @@ executable( link_args: link_args, dependencies: deps, install: true, -) +) \ No newline at end of file diff --git a/src/os/linux.cpp b/src/os/linux.cpp index 627aae3..aa11e98 100644 --- a/src/os/linux.cpp +++ b/src/os/linux.cpp @@ -6,8 +6,6 @@ #include // SQLite::Statement #include // PATH_MAX #include // std::strlen -#include // DBUS_TYPE_* -#include // DBUS_BUS_SESSION #include // std::{unexpected, expected} #include // std::filesystem::{current_path, directory_entry, directory_iterator, etc.} #include // std::{format, format_to_n} @@ -45,6 +43,7 @@ using util::error::DracError, util::error::DracErrorCode; using util::types::String, util::types::Result, util::types::Err, util::types::usize; namespace { + #ifdef HAVE_XCB fn GetX11WindowManager() -> Result { using namespace xcb; using namespace matchit; @@ -123,7 +122,13 @@ namespace { return String(nameData, length); } + #else + fn GetX11WindowManager() -> Result { + return Err(DracError(DracErrorCode::NotSupported, "XCB (X11) support not available")); + } + #endif + #ifdef HAVE_WAYLAND fn GetWaylandCompositor() -> Result { using util::types::i32, util::types::Array, util::types::isize, util::types::StringView; @@ -196,6 +201,11 @@ namespace { return String(compositorNameView); } + #else + fn GetWaylandCompositor() -> Result { + return Err(DracError(DracErrorCode::NotSupported, "Wayland support not available")); + } + #endif } // namespace namespace os { @@ -251,6 +261,7 @@ namespace os { } fn GetNowPlaying() -> Result { + #ifdef HAVE_DBUS using namespace dbus; Result connectionResult = Connection::busGet(DBUS_BUS_SESSION); @@ -385,9 +396,15 @@ namespace os { } return MediaInfo(std::move(title), std::move(artist)); + #else + return Err(DracError(DracErrorCode::NotSupported, "DBus support not available")); + #endif } fn GetWindowManager() -> Result { + #if !defined(HAVE_WAYLAND) && !defined(HAVE_XCB) + return Err(DracError(DracErrorCode::NotSupported, "Wayland or XCB support not available")); + #else if (Result waylandResult = GetWaylandCompositor()) return *waylandResult; @@ -395,6 +412,7 @@ namespace os { return *x11Result; return Err(DracError(DracErrorCode::NotFound, "Could not detect window manager (Wayland/X11) or both failed")); + #endif } fn GetDesktopEnvironment() -> Result {