build: Allow to disable x11

By detecting whether libmutter was built with x11 or xwayland support
and disabling relavant code paths

Part-of:
<https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3362>
This commit is contained in:
Bilal Elmoussaoui 2024-06-26 14:40:04 +02:00
parent 19a37ed02a
commit 446bee5f1d
9 changed files with 120 additions and 41 deletions

View File

@ -39,3 +39,9 @@
/* Define to 1 if the <elf.h> and <link.h> 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

View File

@ -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

View File

@ -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@

View File

@ -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'),

View File

@ -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,

View File

@ -15,7 +15,6 @@
#endif
#include <locale.h>
#include <X11/extensions/Xfixes.h>
#include <gio/gio.h>
#include <girepository.h>
#include <meta/meta-backend.h>
@ -26,9 +25,13 @@
#include <meta/meta-cursor-tracker.h>
#include <meta/meta-settings.h>
#include <meta/meta-workspace-manager.h>
#include <meta/meta-x11-display.h>
#include <mtk/mtk.h>
#ifdef HAVE_X11
#include <meta/meta-x11-display.h>
#include <X11/extensions/Xfixes.h>
#endif
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-systemd.h>
@ -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;

View File

@ -23,7 +23,9 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <meta/meta-context.h>
#include <meta/display.h>
#ifdef HAVE_X11_CLIENT
#include <meta/meta-x11-display.h>
#endif
#include <locale.h>
#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
}
/**

View File

@ -6,11 +6,13 @@
#include <stdlib.h>
#include <meta/display.h>
#include <meta/group.h>
#include <meta/util.h>
#include <meta/window.h>
#include <meta/meta-workspace-manager.h>
#include <meta/meta-startup-notification.h>
#ifdef HAVE_X11_CLIENT
#include <meta/meta-x11-group.h>
#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 */

View File

@ -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',