From 446bee5f1d27951a54b60062e8e03ce5dea3a0e1 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 26 Jun 2024 14:40:04 +0200 Subject: [PATCH] build: Allow to disable x11 By detecting whether libmutter was built with x11 or xwayland support and disabling relavant code paths Part-of: --- config.h.meson | 6 +++ data/meson.build | 33 ++++++++++---- ...Shell.target => org.gnome.Shell.target.in} | 3 +- meson.build | 14 +++++- src/meson.build | 41 ++++++++++++++---- src/shell-global.c | 43 +++++++++++-------- src/shell-util.c | 6 +++ src/shell-window-tracker.c | 13 +++++- src/st/meson.build | 2 +- 9 files changed, 120 insertions(+), 41 deletions(-) rename data/{org.gnome.Shell.target => org.gnome.Shell.target.in} (71%) diff --git a/config.h.meson b/config.h.meson index 914fc2ebd..a357e1c1f 100644 --- a/config.h.meson +++ b/config.h.meson @@ -39,3 +39,9 @@ /* Define to 1 if the and header file exist. */ #mesondefine HAVE_EXE_INTROSPECTION + +/* Whether GNOME Shell is built with X11 support */ +#mesondefine HAVE_X11 + +/* Whether GNOME Shell is built with X11 clients support */ +#mesondefine HAVE_X11_CLIENT diff --git a/data/meson.build b/data/meson.build index 0307613e7..8654dfeca 100644 --- a/data/meson.build +++ b/data/meson.build @@ -101,13 +101,16 @@ install_data('00_org.gnome.shell.gschema.override', install_dir: schemadir) if have_systemd unitconf = configuration_data() unitconf.set('bindir', bindir) - - configure_file( - input: 'org.gnome.Shell@x11.service.in', - output: 'org.gnome.Shell@x11.service', - configuration: unitconf, - install_dir: systemduserunitdir - ) + supported_sessions = ['wayland'] + if have_x11 + configure_file( + input: 'org.gnome.Shell@x11.service.in', + output: 'org.gnome.Shell@x11.service', + configuration: unitconf, + install_dir: systemduserunitdir + ) + supported_sessions += ['x11'] + endif configure_file( input: 'org.gnome.Shell@wayland.service.in', @@ -116,8 +119,20 @@ if have_systemd install_dir: systemduserunitdir ) - units = files('org.gnome.Shell.target', - 'org.gnome.Shell-disable-extensions.service') + + units = files('org.gnome.Shell-disable-extensions.service') + targetconf = configuration_data() + sessions_wants = [] + foreach session: supported_sessions + sessions_wants += 'org.gnome.Shell@' + session + '.service' + endforeach + targetconf.set('SUPPORTED_SESSIONS', ' '.join(sessions_wants)) + target = configure_file( + input: 'org.gnome.Shell.target.in', + output: 'org.gnome.Shell.target', + configuration: targetconf + ) + units += target install_data(units, install_dir: systemduserunitdir) endif diff --git a/data/org.gnome.Shell.target b/data/org.gnome.Shell.target.in similarity index 71% rename from data/org.gnome.Shell.target rename to data/org.gnome.Shell.target.in index 55f9539e9..bb65fa0e6 100644 --- a/data/org.gnome.Shell.target +++ b/data/org.gnome.Shell.target.in @@ -6,5 +6,4 @@ Requisite=gnome-session-initialized.target PartOf=gnome-session-initialized.target Before=gnome-session-initialized.target -Wants=org.gnome.Shell@wayland.service -Wants=org.gnome.Shell@x11.service +Wants=@SUPPORTED_SESSIONS@ \ No newline at end of file diff --git a/meson.build b/meson.build index d67639f66..b54dd205f 100644 --- a/meson.build +++ b/meson.build @@ -87,10 +87,16 @@ cogl_pango_dep = dependency(cogl_pango_pc, version: mutter_req) mutter_dep = dependency(libmutter_pc, version: mutter_req) polkit_dep = dependency('polkit-agent-1', version: polkit_req) ibus_dep = dependency('ibus-1.0', version: ibus_req) -x11_dep = dependency('x11') schemas_dep = dependency('gsettings-desktop-schemas', version: schemas_req) gnome_desktop_dep = dependency('gnome-desktop-4', version: gnome_desktop_req) +have_x11 = mutter_dep.get_variable('have_x11') == 'true' +have_x11_client = mutter_dep.get_variable('have_x11_client') == 'true' +if have_x11_client or have_x11 + x11_dep = dependency('x11') +endif + + nm_deps = [] if get_option('networkmanager') nm_deps += dependency('libnm', version: nm_req) @@ -145,6 +151,8 @@ cdata.set_quoted('PACKAGE_VERSION', meson.project_version()) cdata.set('HAVE_NETWORKMANAGER', have_networkmanager) cdata.set('HAVE_PIPEWIRE', have_pipewire) cdata.set('HAVE_SYSTEMD', have_systemd) +cdata.set('HAVE_X11', have_x11) +cdata.set('HAVE_X11_CLIENT', have_x11_client) cdata.set('HAVE_FDWALK', cc.has_function('fdwalk')) cdata.set('HAVE_MALLINFO', cc.has_function('mallinfo')) @@ -300,7 +308,7 @@ subdir('src') subdir('po') subdir('data') -if get_option('tests') +if get_option('tests') and have_x11_client subdir('tests') endif @@ -318,6 +326,8 @@ meson.add_dist_script('meson/generate-stylesheets.py') meson.add_dist_script('meson/check-version.py', meson.project_version(), 'NEWS') summary_options = { + 'x11': have_x11, + 'x11_client': have_x11_client, 'camera_monitor': get_option('camera_monitor'), 'networkmanager': get_option('networkmanager'), 'systemd': get_option('systemd'), diff --git a/src/meson.build b/src/meson.build index f99b341b9..752104e12 100644 --- a/src/meson.build +++ b/src/meson.build @@ -13,7 +13,9 @@ introspection_common = { subdir('calendar-server') subdir('hotplug-sniffer') subdir('st') -subdir('tray') +if have_x11_client + subdir('tray') +endif script_data = configuration_data() script_data.set('bindir', bindir) @@ -77,9 +79,12 @@ gnome_shell_deps = [ gcr_dep, libsystemd_dep, libpipewire_dep, - x11_dep, ] +if have_x11_client + gnome_shell_deps += x11_dep +endif + gnome_shell_deps += nm_deps tools_cflags = '-DLOCALEDIR="@0@"'.format(localedir) @@ -121,8 +126,6 @@ libshell_public_headers = [ 'shell-screenshot.h', 'shell-square-bin.h', 'shell-stack.h', - 'shell-tray-icon.h', - 'shell-tray-manager.h', 'shell-util.h', 'shell-window-preview.h', 'shell-window-preview-layout.h', @@ -131,6 +134,13 @@ libshell_public_headers = [ 'shell-workspace-background.h' ] +if have_x11_client + libshell_public_headers += [ + 'shell-tray-icon.h', + 'shell-tray-manager.h', + ] +endif + if have_networkmanager libshell_public_headers += 'shell-network-agent.h' endif @@ -140,11 +150,16 @@ libshell_private_headers = [ 'shell-app-cache-private.h', 'shell-app-system-private.h', 'shell-global-private.h', - 'shell-tray-icon-private.h', 'shell-window-tracker-private.h', 'shell-wm-private.h' ] +if have_x11_client + libshell_private_headers += [ + 'shell-tray-icon-private.h', + ] +endif + libshell_sources = [ 'gnome-shell-plugin.c', 'shell-app.c', @@ -166,8 +181,6 @@ libshell_sources = [ 'shell-secure-text-buffer.h', 'shell-square-bin.c', 'shell-stack.c', - 'shell-tray-icon.c', - 'shell-tray-manager.c', 'shell-util.c', 'shell-window-preview.c', 'shell-window-preview-layout.c', @@ -176,6 +189,13 @@ libshell_sources = [ 'shell-workspace-background.c' ] +if have_x11_client + libshell_sources += [ + 'shell-tray-icon.c', + 'shell-tray-manager.c', + ] +endif + if have_networkmanager libshell_sources += 'shell-network-agent.c' endif @@ -212,12 +232,17 @@ dbus_generated += gnome.gdbus_codegen('switcheroo-control', libshell_no_gir_sources += dbus_generated +libshell_link_with = [] +if have_x11_client + libshell_link_with += [libtray] +endif + libshell = library('shell-' + mutter_api_version, sources: libshell_gir_sources + libshell_no_gir_sources, dependencies: gnome_shell_deps + [libshell_menu_dep, libst_dep, mutter_dep, gnome_desktop_dep, m_dep], include_directories: [conf_inc, st_inc, include_directories('tray')], c_args: gnome_shell_cflags, - link_with: [libtray], + link_with: libshell_link_with, build_rpath: mutter_typelibdir, install_rpath: install_rpath, install_dir: pkglibdir, diff --git a/src/shell-global.c b/src/shell-global.c index c2589fda8..d67a18974 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -15,7 +15,6 @@ #endif #include -#include #include #include #include @@ -26,9 +25,13 @@ #include #include #include -#include #include +#ifdef HAVE_X11 +#include +#include +#endif + #define GNOME_DESKTOP_USE_UNSTABLE_API #include @@ -59,11 +62,14 @@ struct _ShellGlobal { MetaDisplay *meta_display; MetaCompositor *compositor; MetaWorkspaceManager *workspace_manager; +#ifdef HAVE_X11 Display *xdisplay; - char *session_mode; XserverRegion input_region; +#endif + + char *session_mode; GjsContext *js_context; MetaPlugin *plugin; @@ -424,7 +430,7 @@ shell_global_init (ShellGlobal *global) path = g_strdup_printf ("%s/gnome-shell/runtime-state-%s.%s", g_get_user_runtime_dir (), byteorder_string, - XDisplayName (NULL)); + g_getenv ("DISPLAY")); (void) g_mkdir_with_parents (path, 0700); global->runtime_state_path = g_file_new_for_path (path); g_free (path); @@ -766,15 +772,6 @@ _shell_global_destroy_gjs_context (ShellGlobal *self) g_clear_object (&self->js_context); } -static void -sync_input_region (ShellGlobal *global) -{ - MetaDisplay *display = global->meta_display; - MetaX11Display *x11_display = meta_display_get_x11_display (display); - - meta_x11_display_set_stage_input_region (x11_display, global->input_region); -} - /** * shell_global_set_stage_input_region: * @global: the #ShellGlobal @@ -788,16 +785,21 @@ void shell_global_set_stage_input_region (ShellGlobal *global, GSList *rectangles) { +#ifdef HAVE_X11 MtkRectangle *rect; XRectangle *rects; int nrects, i; GSList *r; + MetaDisplay *display; + MetaX11Display *x11_display; g_return_if_fail (SHELL_IS_GLOBAL (global)); if (meta_is_wayland_compositor ()) return; + display = global->meta_display; + x11_display = meta_display_get_x11_display (display); nrects = g_slist_length (rectangles); rects = g_new (XRectangle, nrects); for (r = rectangles, i = 0; r; r = r->next, i++) @@ -815,7 +817,8 @@ shell_global_set_stage_input_region (ShellGlobal *global, global->input_region = XFixesCreateRegion (global->xdisplay, rects, nrects); g_free (rects); - sync_input_region (global); + meta_x11_display_set_stage_input_region (x11_display, global->input_region); +#endif } /** @@ -1009,12 +1012,14 @@ entry_cursor_func (StEntry *entry, use_ibeam ? META_CURSOR_IBEAM : META_CURSOR_DEFAULT); } +#ifdef HAVE_X11 static void on_x11_display_closed (MetaDisplay *display, ShellGlobal *global) { g_signal_handlers_disconnect_by_data (global->stage, global); } +#endif void _shell_global_set_plugin (ShellGlobal *global, @@ -1042,11 +1047,13 @@ _shell_global_set_plugin (ShellGlobal *global, global->stage = CLUTTER_STAGE (meta_get_stage_for_display (display)); +#ifdef HAVE_X11 if (!meta_is_wayland_compositor ()) { MetaX11Display *x11_display = meta_display_get_x11_display (display); global->xdisplay = meta_x11_display_get_xdisplay (x11_display); } +#endif st_entry_set_cursor_func (entry_cursor_func, global); st_clipboard_set_selection (meta_display_get_selection (display)); @@ -1080,9 +1087,11 @@ _shell_global_set_plugin (ShellGlobal *global, "End of frame, possibly including swap time", ""); +#ifdef HAVE_X11 if (global->xdisplay) g_signal_connect_object (global->meta_display, "x11-display-closing", G_CALLBACK (on_x11_display_closed), global, 0); +#endif backend = meta_context_get_backend (shell_global_get_context (global)); settings = meta_backend_get_settings (backend); @@ -1192,10 +1201,10 @@ pre_exec_close_fds(void) /** * shell_global_reexec_self: * @global: A #ShellGlobal - * - * Restart the current process. Only intended for development purposes. + * + * Restart the current process. Only intended for development purposes. */ -void +void shell_global_reexec_self (ShellGlobal *global) { GPtrArray *arr; diff --git a/src/shell-util.c b/src/shell-util.c index 9d1f24018..742aa829a 100644 --- a/src/shell-util.c +++ b/src/shell-util.c @@ -23,7 +23,9 @@ #include #include #include +#ifdef HAVE_X11_CLIENT #include +#endif #include #ifdef HAVE__NL_TIME_FIRST_WEEKDAY @@ -786,6 +788,7 @@ gboolean shell_util_has_x11_display_extension (MetaDisplay *display, const char *extension) { +#ifdef HAVE_X11_CLIENT MetaX11Display *x11_display; Display *xdisplay; int op, event, error; @@ -796,6 +799,9 @@ shell_util_has_x11_display_extension (MetaDisplay *display, xdisplay = meta_x11_display_get_xdisplay (x11_display); return XQueryExtension (xdisplay, extension, &op, &event, &error); +#else + return FALSE; +#endif } /** diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c index 548a3f1ce..d17a9a3fe 100644 --- a/src/shell-window-tracker.c +++ b/src/shell-window-tracker.c @@ -6,11 +6,13 @@ #include #include -#include #include #include #include #include +#ifdef HAVE_X11_CLIENT +#include +#endif #include "shell-window-tracker-private.h" #include "shell-app-private.h" @@ -303,11 +305,15 @@ static ShellApp* get_app_from_window_group (ShellWindowTracker *tracker, MetaWindow *window) { +#ifdef HAVE_X11_CLIENT ShellApp *result; GSList *group_windows; MetaGroup *group; GSList *iter; + if (meta_window_get_client_type (window) != META_WINDOW_CLIENT_TYPE_X11) + return NULL; + group = meta_window_x11_get_group (window); if (group == NULL) return NULL; @@ -335,6 +341,9 @@ get_app_from_window_group (ShellWindowTracker *tracker, g_object_ref (result); return result; +#else + return NULL; +#endif } /* @@ -458,7 +467,7 @@ get_app_for_window (ShellWindowTracker *tracker, /* If we didn't get a startup-notification match, see if we matched * any other windows in the group. */ - if (result == NULL && meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_X11) + if (result == NULL) result = get_app_from_window_group (tracker, window); /* Our last resort - we create a fake app from the window */ diff --git a/src/st/meson.build b/src/st/meson.build index 8161a6b2b..397e41693 100644 --- a/src/st/meson.build +++ b/src/st/meson.build @@ -194,7 +194,7 @@ libst_dep = declare_dependency(link_with: libst, sources: st_enums[1] ) -if get_option('tests') +if get_option('tests') and have_x11_client mutter_test_dep = dependency(libmutter_test_pc, version: mutter_req) test_theme = executable('test-theme', sources: 'test-theme.c',