[gnome-settings-daemon/wip/carlosg/xwayland-startup-side-channel: 5/6] xsettings: Add support for launching Xwayland session scripts



commit 7b00240a88a70bfd28b36cfb74b7d5c0c9223fbe
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Nov 15 11:37:06 2019 +0100

    xsettings: Add support for launching Xwayland session scripts
    
    We now look for scripts to launch at $XDG_CONFIG_DIRS/Xwayland-session.d.
    This will let users/x11 services/distributors to hook other miscellaneous
    X11 services that should be there before a client is able to launch.
    Real life examples are:
    
    - Xresources files should be loaded with xrdb before any client uses them
    - Pulseaudio might want to export its configuration to root window
      properties before SSH forwarded X11 clients may use them.
    - Ibus may want to set up its XIM implementation

 plugins/xsettings/gsd-xsettings-manager.c | 99 +++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
---
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index 75744b20..aff0c60d 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -1166,6 +1166,101 @@ on_shell_introspect_name_appeared_handler (GDBusConnection *connection,
         animations_enabled_changed (manager);
 }
 
+static void
+launch_xwayland_services_on_dir (const gchar *path)
+{
+        GFileEnumerator *enumerator;
+        GError *error = NULL;
+        GList *l, *scripts = NULL;
+        GFile *dir;
+
+        g_debug ("launch_xwayland_services_on_dir: %s", path);
+
+        dir = g_file_new_for_path (path);
+        enumerator = g_file_enumerate_children (dir,
+                                                G_FILE_ATTRIBUTE_STANDARD_NAME ","
+                                                G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE ","
+                                                G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                                G_FILE_QUERY_INFO_NONE,
+                                                NULL, &error);
+        g_object_unref (dir);
+
+        if (!enumerator) {
+                if (!g_error_matches (error,
+                                      G_IO_ERROR,
+                                      G_IO_ERROR_NOT_FOUND)) {
+                        g_warning ("Error opening '%s': %s",
+                                   path, error->message);
+                }
+
+                g_error_free (error);
+                return;
+        }
+
+        while (TRUE) {
+                GFileInfo *info;
+                GFile *child;
+
+                if (!g_file_enumerator_iterate (enumerator,
+                                                &info, &child,
+                                                NULL, &error)) {
+                        g_warning ("Error iterating on '%s': %s",
+                                   path, error->message);
+                        g_error_free (error);
+                        break;
+                }
+
+                if (!info)
+                        break;
+
+                if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR ||
+                    !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
+                        continue;
+
+                scripts = g_list_prepend (scripts, g_file_get_path (child));
+        }
+
+        scripts = g_list_sort (scripts, (GCompareFunc) strcmp);
+
+        for (l = scripts; l; l = l->next) {
+                gchar *args[2] = { l->data, NULL };
+
+                g_debug ("launch_xwayland_services_on_dir: Spawning '%s'", args[0]);
+                if (!g_spawn_sync (NULL, args, NULL,
+                                   G_SPAWN_DEFAULT,
+                                   NULL, NULL,
+                                   NULL, NULL, NULL,
+                                   &error)) {
+                        g_warning ("Error when spawning '%s': %s",
+                                   args[0], error->message);
+                        g_clear_error (&error);
+                }
+        }
+
+        g_object_unref (enumerator);
+        g_list_free_full (scripts, g_free);
+}
+
+static void
+launch_xwayland_services (void)
+{
+        const gchar * const * config_dirs;
+        gint i;
+
+        config_dirs = g_get_system_config_dirs ();
+
+        for (i = 0; config_dirs[i] != NULL; i++) {
+                gchar *config_dir;
+
+                config_dir = g_build_filename (config_dirs[i],
+                                               "Xwayland-session.d",
+                                               NULL);
+
+                launch_xwayland_services_on_dir (config_dir);
+                g_free (config_dir);
+        }
+}
+
 gboolean
 gsd_xsettings_manager_start (GsdXSettingsManager *manager,
                              GError             **error)
@@ -1297,6 +1392,10 @@ gsd_xsettings_manager_start (GsdXSettingsManager *manager,
         /* Xft settings */
         update_xft_settings (manager);
 
+        /* Launch Xwayland services */
+        if (gnome_settings_is_wayland ())
+                launch_xwayland_services ();
+
         register_manager_dbus (manager);
 
         start_fontconfig_monitor (manager);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]