Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
lainsce committed Jan 22, 2024
1 parent 57e0419 commit 9612a43
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
21 changes: 14 additions & 7 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ gnome = import('gnome')
xdg_desktop_portal_dep = dependency('xdg-desktop-portal', version: '>= 1.15.0')

# Desktop Portal D-Bus interfaces
desktop_portal_interfaces_dir = xdg_desktop_portal_dep.get_pkgconfig_variable('interfaces_dir')
desktop_portal_dbus_interfaces = [
desktop_portal_interfaces_dir / 'org.freedesktop.impl.portal.Settings.xml',
'org.freedesktop.impl.portal.Settings',
]

desktop_portal_interfaces_dir = xdg_desktop_portal_dep.get_variable(
pkgconfig: 'interfaces_dir')

desktop_portal_dbus_interfaces_files = []
foreach intf: desktop_portal_dbus_interfaces
desktop_portal_dbus_interfaces_files += [desktop_portal_interfaces_dir / '@0@.xml'.format(intf)]
endforeach

built_sources = gnome.gdbus_codegen(
'xdg-desktop-portal-dbus',
sources: desktop_portal_dbus_interfaces,
sources: desktop_portal_dbus_interfaces_files,
interface_prefix: 'org.freedesktop.impl.portal.',
namespace: 'XdpImpl',
)
Expand All @@ -31,9 +38,9 @@ config_h.set_quoted('PACKAGE_STRING', '@0@ @1@'.format(meson.project_name(), mes
built_sources += configure_file(output: 'config.h', configuration: config_h)

# Sources
libhelium_dep = dependency(
'libhelium-1',
fallback: ['libhelium', 'libhelium_dep'],
libadwaita_dep = dependency(
'libadwaita-1',
fallback: ['libadwaita', 'libadwaita_dep'],
default_options: ['examples=false', 'introspection=disabled', 'tests=false', 'vapi=false'],
)
deps = [
Expand All @@ -44,7 +51,7 @@ deps = [
dependency('gio-unix-2.0'),
dependency('gtk4', version: '>= 4.0'),
dependency('gsettings-desktop-schemas'),
libhelium_dep,
libadwaita_dep,
xdg_desktop_portal_dep,
]

Expand Down
54 changes: 37 additions & 17 deletions src/xdg-desktop-portal-tau.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <sys/stat.h>
#include <fcntl.h>

#include <libhelium-1.h>
#include <adwaita.h>

#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
Expand All @@ -51,6 +51,7 @@ static GHashTable *outstanding_handles = NULL;
static gboolean opt_verbose;
static gboolean opt_replace;
static gboolean show_version;
static gboolean settings_only = FALSE;

static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
Expand Down Expand Up @@ -99,6 +100,9 @@ on_bus_acquired (GDBusConnection *connection,
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (settings_only)
return;
}

static void
Expand All @@ -118,6 +122,21 @@ on_name_lost (GDBusConnection *connection,
g_main_loop_quit (loop);
}

static gboolean
init_gtk (GError **error)
{
/* Avoid pointless and confusing recursion */
g_unsetenv ("GTK_USE_PORTAL");

if (G_UNLIKELY (!g_setenv ("ADW_DISABLE_PORTAL", "1", TRUE)))
{
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
"Failed to set ADW_DISABLE_PORTAL: %s", g_strerror (errno));
return FALSE;
}
return TRUE;
}

int
main (int argc, char *argv[])
{
Expand All @@ -131,25 +150,23 @@ main (int argc, char *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);

if (G_UNLIKELY (!g_setenv ("GSK_RENDERER", "cairo", TRUE)))
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (session_bus == NULL)
{
g_printerr ("Failed to set GSK_RENDERER: %s\n", g_strerror (errno));
return 1;
g_printerr ("No session bus: %s\n", error->message);
return 2;
}

gtk_init ();

context = g_option_context_new ("- portal backends");
g_option_context_set_summary (context,
"A backend implementation for xdg-desktop-portal.");
g_option_context_set_description (context,
"xdg-desktop-portal-tau provides D-Bus interfaces that\n"
"xdg-desktop-portal-gnome provides D-Bus interfaces that\n"
"are used by xdg-desktop-portal to implement portals\n"
"\n"
"Documentation for the available D-Bus interfaces can be found at\n"
"https://flatpak.github.io/xdg-desktop-portal/portal-docs.html\n"
"\n"
"Please report issues at https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/issues");
);
g_option_context_add_main_entries (context, entries, NULL);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
Expand All @@ -167,6 +184,15 @@ main (int argc, char *argv[])
return 0;
}

if (!init_gtk (&error))
{
g_debug ("Failed to initialize display server connection: %s",
error->message);
g_clear_error (&error);
g_printerr ("Non-compatible display server, exposing settings only.\n");
settings_only = TRUE;
}

g_set_printerr_handler (printerr_handler);

if (opt_verbose)
Expand All @@ -178,13 +204,6 @@ main (int argc, char *argv[])

outstanding_handles = g_hash_table_new (g_str_hash, g_str_equal);

session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (session_bus == NULL)
{
g_printerr ("No session bus: %s\n", error->message);
return 2;
}

owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
"org.freedesktop.impl.portal.desktop.tau",
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
Expand All @@ -194,7 +213,8 @@ main (int argc, char *argv[])
NULL,
NULL);

he_init ();
if (!settings_only)
adw_init ();

g_main_loop_run (loop);

Expand Down

0 comments on commit 9612a43

Please sign in to comment.