xiterm

simple vte terminal emulator
git clone https://git.ce9e.org/xiterm.git

commit
c754f18f827dae999087f0414bbb53cbc5e4d5a7
parent
27a1f753035ec6cf3247ce6765782dbe543a14df
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-10-31 22:04
portal: async initialization

Diffstat

M portal.h 48 ++++++++++++++++++++++++++++++------------------

1 files changed, 30 insertions, 18 deletions


diff --git a/portal.h b/portal.h

@@ -8,10 +8,9 @@
    8     8 static GDBusProxy *openuri_portal;
    9     9 static GDBusProxy *settings_portal;
   10    10 
   11    -1 static GDBusProxy *get_portal(const char *iface) {
   12    -1 	GError *error = NULL;
   13    -1 
   14    -1 	GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(
   -1    11 static void portal_new(const char *iface, GAsyncReadyCallback callback) {
   -1    12 	g_printerr("Connecting to %s\n", iface);
   -1    13 	g_dbus_proxy_new_for_bus(
   15    14 		G_BUS_TYPE_SESSION,
   16    15 		G_DBUS_PROXY_FLAGS_NONE,
   17    16 		NULL,
@@ -19,16 +18,9 @@ static GDBusProxy *get_portal(const char *iface) {
   19    18 		"/org/freedesktop/portal/desktop",
   20    19 		iface,
   21    20 		NULL,
   22    -1 		&error
   -1    21 		callback,
   -1    22 		NULL
   23    23 	);
   24    -1 
   25    -1 	if (error) {
   26    -1 		g_printerr("Failed connect to portal %s: %s\n", iface, error->message);
   27    -1 		g_clear_error(&error);
   28    -1 		return NULL;
   29    -1 	}
   30    -1 
   31    -1 	return proxy;
   32    24 }
   33    25 
   34    26 static void set_color_scheme(GVariant *scheme) {
@@ -43,7 +35,7 @@ static void set_color_scheme(GVariant *scheme) {
   43    35 	);
   44    36 }
   45    37 
   46    -1 static void on_settings_portal(
   -1    38 static void on_settings_signal(
   47    39 	GDBusProxy *proxy,
   48    40 	const char *sender_name,
   49    41 	const char *signal_name,
@@ -70,7 +62,7 @@ static void setup_color_scheme(void) {
   70    62 		g_signal_connect(
   71    63 			settings_portal,
   72    64 			"g-signal",
   73    -1 			G_CALLBACK(on_settings_portal),
   -1    65 			G_CALLBACK(on_settings_signal),
   74    66 			NULL
   75    67 		);
   76    68 
@@ -94,12 +86,32 @@ static void setup_color_scheme(void) {
   94    86 	}
   95    87 }
   96    88 
   97    -1 void portal_setup(void) {
   98    -1 	openuri_portal = get_portal("org.freedesktop.portal.OpenURI");
   99    -1 	settings_portal = get_portal("org.freedesktop.portal.Settings");
   -1    89 static void on_openuri_portal(GObject* source_object, GAsyncResult* res, gpointer data) {
   -1    90 	GError *error = NULL;
   -1    91 	openuri_portal = g_dbus_proxy_new_for_bus_finish(res, &error);
   -1    92 	if (error) {
   -1    93 		g_printerr("Failed connect to OpenURI portal: %s\n", error->message);
   -1    94 		g_clear_error(&error);
   -1    95 		openuri_portal = NULL;
   -1    96 	}
   -1    97 }
   -1    98 
   -1    99 static void on_settings_portal(GObject* source_object, GAsyncResult* res, gpointer data) {
   -1   100 	GError *error = NULL;
   -1   101 	settings_portal = g_dbus_proxy_new_for_bus_finish(res, &error);
   -1   102 	if (error) {
   -1   103 		g_printerr("Failed connect to Settings portal: %s\n", error->message);
   -1   104 		g_clear_error(&error);
   -1   105 		settings_portal = NULL;
   -1   106 	}
  100   107 	setup_color_scheme();
  101   108 }
  102   109 
   -1   110 void portal_setup(void) {
   -1   111 	portal_new("org.freedesktop.portal.OpenURI", on_openuri_portal);
   -1   112 	portal_new("org.freedesktop.portal.Settings", on_settings_portal);
   -1   113 }
   -1   114 
  103   115 void portal_finalize(void) {
  104   116 	if (openuri_portal) {
  105   117 		g_clear_object(&openuri_portal);