Allow using glib instead of sd-bus to get the pretty hostname
This commit is contained in:
+13
-1
@@ -26,7 +26,8 @@ include("cmake/AutoOption.cmake")
|
||||
option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
|
||||
auto_option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" AUTO)
|
||||
auto_option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" AUTO)
|
||||
auto_option(WIVRN_USE_SYSTEMD "Use libsystemd, required to show pretty hostname" AUTO)
|
||||
auto_option(WIVRN_USE_SYSTEMD "Use libsystemd, either libsystemd or glib is required to show pretty hostname" AUTO)
|
||||
auto_option(WIVRN_USE_GLIB "Use glib, required to show pretty hostname inside a flatpak container" OFF)
|
||||
option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
|
||||
option(WIVRN_BUILD_CLIENT "Build WiVRn client" OFF)
|
||||
option(WIVRN_BUILD_SERVER "Build WiVRn server" ON)
|
||||
@@ -140,6 +141,17 @@ if (WIVRN_BUILD_SERVER)
|
||||
find_package(Eigen3 REQUIRED)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
find_package(CLI11 REQUIRED)
|
||||
|
||||
if (WIVRN_USE_GLIB STREQUAL "AUTO")
|
||||
pkg_check_modules(glib2 IMPORTED_TARGET glib-2.0 gio-2.0)
|
||||
if(glib2_FOUND)
|
||||
set(WIVRN_USE_GLIB ON)
|
||||
else()
|
||||
set(WIVRN_USE_GLIB OFF)
|
||||
endif()
|
||||
elseif (WIVRN_USE_GLIB)
|
||||
pkg_check_modules(glib2 REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#cmakedefine WIVRN_USE_X264
|
||||
|
||||
#cmakedefine WIVRN_USE_SYSTEMD
|
||||
#cmakedefine WIVRN_USE_GLIB
|
||||
|
||||
#cmakedefine WIVRN_USE_PIPEWIRE
|
||||
#cmakedefine WIVRN_USE_PULSEAUDIO
|
||||
|
||||
@@ -122,6 +122,7 @@ modules:
|
||||
- -DWIVRN_USE_X264=ON
|
||||
- -DWIVRN_USE_NVENC=ON
|
||||
- -DWIVRN_USE_PULSEAUDIO=OFF
|
||||
- -DWIVRN_USE_GLIB=ON
|
||||
- -DFETCHCONTENT_FULLY_DISCONNECTED=ON
|
||||
- -DFETCHCONTENT_BASE_DIR=deps
|
||||
- -DXRT_IPC_MSG_SOCK_FILENAME=wivrn/comp_ipc
|
||||
@@ -194,10 +195,10 @@ finish-args:
|
||||
# Needs to talk to the network
|
||||
- --share=network
|
||||
# Announce WiVRn via avahi
|
||||
# - --system-talk-name=org.freedesktop.Avahi
|
||||
- --system-talk-name=org.freedesktop.Avahi
|
||||
# Allow getting the pretty hostname
|
||||
# - --system-talk-name=org.freedesktop.hostname1
|
||||
- --socket=system-bus # workaround bug between sd-bus (https://github.com/systemd/systemd/issues/16610) and xdg-dbus-proxy (https://github.com/flatpak/xdg-dbus-proxy/issues/21)
|
||||
- --system-talk-name=org.freedesktop.hostname1
|
||||
# - --socket=system-bus # workaround bug between sd-bus (https://github.com/systemd/systemd/issues/16610) and xdg-dbus-proxy (https://github.com/flatpak/xdg-dbus-proxy/issues/21)
|
||||
# Pipewire
|
||||
- --filesystem=xdg-run/pipewire-0
|
||||
# Set the active OpenXR / OpenVR runtime
|
||||
|
||||
@@ -159,6 +159,10 @@ target_link_libraries(
|
||||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
|
||||
if(WIVRN_USE_GLIB)
|
||||
target_link_libraries( wivrn-server PRIVATE PkgConfig::glib2)
|
||||
endif()
|
||||
|
||||
configure_file(dist/wivrn.service.in wivrn.service)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/wivrn.service
|
||||
DESTINATION lib/systemd/user/)
|
||||
|
||||
+50
-2
@@ -5,13 +5,61 @@
|
||||
#include "util/u_logging.h"
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
#ifdef WIVRN_USE_GLIB
|
||||
#include <gio/gio.h>
|
||||
#elif defined(WIVRN_USE_SYSTEMD)
|
||||
#include <systemd/sd-bus.h>
|
||||
#endif
|
||||
|
||||
std::string hostname()
|
||||
{
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
#ifdef WIVRN_USE_GLIB
|
||||
GError * error = NULL;
|
||||
GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
|
||||
if (!con)
|
||||
{
|
||||
U_LOG_W("Failed to connect to system bus: %s", error->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto property: {"PrettyHostname", "StaticHostname", "Hostname"})
|
||||
{
|
||||
GVariant * result = g_dbus_connection_call_sync(con,
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
g_variant_new("(ss)", "org.freedesktop.hostname1", property),
|
||||
G_VARIANT_TYPE("(v)"),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
continue;
|
||||
|
||||
GVariant * property_value;
|
||||
g_variant_get(result, "(v)", &property_value);
|
||||
const char * hostname = g_variant_get_string(property_value, NULL);
|
||||
|
||||
if (hostname && strcmp(hostname, ""))
|
||||
{
|
||||
std::string s = hostname;
|
||||
g_variant_unref(property_value);
|
||||
g_variant_unref(result);
|
||||
g_object_unref(con);
|
||||
return s;
|
||||
}
|
||||
|
||||
g_variant_unref(property_value);
|
||||
g_variant_unref(result);
|
||||
}
|
||||
|
||||
g_object_unref(con);
|
||||
}
|
||||
#elif defined(WIVRN_USE_SYSTEMD)
|
||||
sd_bus * bus;
|
||||
if (sd_bus_default_system(&bus) < 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user