Fixed Snapcraft

This commit is contained in:
brunoherbelin
2025-11-18 19:41:21 +01:00
parent 03a3113d34
commit 316e80d7e5
2 changed files with 33 additions and 51 deletions

View File

@@ -8,10 +8,7 @@
"rename-icon": "vimix", "rename-icon": "vimix",
"finish-args": [ "finish-args": [
"--socket=x11", "--socket=x11",
"--socket=wayland",
"--socket=fallback-x11",
"--socket=pulseaudio", "--socket=pulseaudio",
"--socket=session-bus",
"--share=ipc", "--share=ipc",
"--share=network", "--share=network",
"--device=dri", "--device=dri",
@@ -20,6 +17,7 @@
"--filesystem=host", "--filesystem=host",
"--filesystem=/tmp", "--filesystem=/tmp",
"--talk-name=org.gtk.vfs.*", "--talk-name=org.gtk.vfs.*",
"--talk-name=org.freedesktop.portal.Desktop",
"--env=FREI0R_PATH=/app/lib/frei0r-1" "--env=FREI0R_PATH=/app/lib/frei0r-1"
], ],
"cleanup": [ "cleanup": [

View File

@@ -81,27 +81,24 @@ void inhibitScreensaver (bool on)
{ {
/* /*
* Inhibit or un-inhibit the desktop screensaver via the * Inhibit or un-inhibit the desktop screensaver via the
* org.freedesktop.ScreenSaver D-Bus API. * XDG Desktop Portal org.freedesktop.portal.Inhibit API.
* *
* When 'on' is true: * When 'on' is true:
* - Obtain a connection to the session bus (cached in session_dbus_). * - Obtain a connection to the session bus (cached in session_dbus_).
* - Call the Inhibit method with two strings: the application name * - Call the Inhibit method with: window identifier (empty string for whole app),
* ("vimix") and a human-readable reason. * flags (8 = inhibit idle/screensaver), and options (reason string).
* - The call returns a uint 'cookie' which must be kept and later * - The call returns an object path handle which identifies the inhibit request.
* passed to UnInhibit to release the inhibition.
* *
* When 'on' is false: * When 'on' is false:
* - If we previously inhibited the screensaver (screensaver_inhibit_cookie_ != 0) * - The inhibition is automatically released when the handle is removed or app exits.
* call UnInhibit with that cookie. * - We explicitly close the session bus connection to clean up.
* - Release the cached D-Bus connection (session_dbus_) and reset the cookie.
* *
* Notes: * Notes:
* - This uses the XDG Desktop Portal which works in Flatpak sandboxes.
* - Requires --talk-name=org.freedesktop.portal.Desktop permission.
* - This function uses synchronous D-Bus calls. They may block briefly. * - This function uses synchronous D-Bus calls. They may block briefly.
* - Errors from g_dbus_connection_call_sync are reported to the log and freed. * - Errors from g_dbus_connection_call_sync are reported to the log and freed.
* - The code is guarded by an #ifdef so it only compiles for platforms * - Works on both X11 and Wayland.
* where GLFW_EXPOSE_NATIVE_GLX is defined (historically used for X11/GLX),
* but the org.freedesktop.ScreenSaver D-Bus interface works on both
* X11 and Wayland session daemons that implement the spec.
*/ */
if (on ) { if (on ) {
GError *error = NULL; GError *error = NULL;
@@ -111,15 +108,24 @@ void inhibitScreensaver (bool on)
/* Only inhibit once: do nothing if we already have a cookie. */ /* Only inhibit once: do nothing if we already have a cookie. */
if (session_dbus_ != NULL && screensaver_inhibit_cookie_ == 0) { if (session_dbus_ != NULL && screensaver_inhibit_cookie_ == 0) {
/* Call org.freedesktop.ScreenSaver.Inhibit(application_name, reason) */ /* Build options dictionary with reason */
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add(&builder, "{sv}", "reason",
g_variant_new_string("Video mixing in progress"));
/* Call org.freedesktop.portal.Inhibit.Inhibit(window, flags, options) */
GVariant *result = g_dbus_connection_call_sync( GVariant *result = g_dbus_connection_call_sync(
session_dbus_, session_dbus_,
"org.freedesktop.ScreenSaver", "org.freedesktop.portal.Desktop",
"/org/freedesktop/ScreenSaver", "/org/freedesktop/portal/desktop",
"org.freedesktop.ScreenSaver", "org.freedesktop.portal.Inhibit",
"Inhibit", "Inhibit",
g_variant_new("(ss)", "vimix", "Video mixing in progress"), g_variant_new("(su@a{sv})",
G_VARIANT_TYPE("(u)"), "", // window identifier (empty for whole app)
8, // flags: 8 = inhibit idle/screensaver
g_variant_builder_end(&builder)),
G_VARIANT_TYPE("(o)"), // returns object path handle
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
NULL, NULL,
@@ -127,10 +133,11 @@ void inhibitScreensaver (bool on)
); );
if (result != NULL) { if (result != NULL) {
/* The returned variant contains a single unsigned integer cookie. */ /* The returned variant contains an object path handle.
g_variant_get(result, "(u)", &screensaver_inhibit_cookie_); * We store a dummy cookie value to indicate inhibition is active. */
screensaver_inhibit_cookie_ = 1;
g_variant_unref(result); g_variant_unref(result);
Log::Info("Screensaver inhibited for vimix (cookie: %u)", screensaver_inhibit_cookie_); Log::Info("Screensaver inhibited for vimix via XDG Desktop Portal");
} else { } else {
/* If the call failed, log the error and ensure cookie is zero. */ /* If the call failed, log the error and ensure cookie is zero. */
if (error != NULL) { if (error != NULL) {
@@ -142,37 +149,14 @@ void inhibitScreensaver (bool on)
} }
} }
else { else {
/* Un-inhibit only if we have a valid cookie recorded. */ /* Un-inhibit: the portal automatically releases when we close the session */
if (screensaver_inhibit_cookie_ != 0) { if (screensaver_inhibit_cookie_ != 0) {
GError *error = NULL;
if (session_dbus_ != NULL) { if (session_dbus_ != NULL) {
/* Call org.freedesktop.ScreenSaver.UnInhibit(cookie) */
g_dbus_connection_call_sync(
session_dbus_,
"org.freedesktop.ScreenSaver",
"/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver",
"UnInhibit",
g_variant_new("(u)", screensaver_inhibit_cookie_),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error
);
if (error != NULL) {
/* Report failure to release inhibition but continue cleanup. */
g_printerr("Could not un-inhibit screensaver: %s\n", error->message);
g_error_free(error);
} else {
g_printerr("Screensaver inhibition disabled\n");
Log::Info("Screensaver inhibition disabled\n");
}
/* Close and drop our cached session bus connection. */ /* Close and drop our cached session bus connection. */
/* The portal will automatically release the inhibition. */
g_object_unref(session_dbus_); g_object_unref(session_dbus_);
session_dbus_ = NULL; session_dbus_ = NULL;
Log::Info("Screensaver inhibition disabled");
} }
/* Reset cookie so subsequent calls can re-inhibit if needed. */ /* Reset cookie so subsequent calls can re-inhibit if needed. */
screensaver_inhibit_cookie_ = 0; screensaver_inhibit_cookie_ = 0;