compositor: support loading backend via shortened name

While the --backend parameter looks like it takes a file name, it really
is selected from a list of supported strings that are then funneled
through a translation to enum weston_compositor_backend [1].

Because all backend parameters are of the form "...-backend.so", and
writing "--backend=...-backend.so" is boring, allow the --backend option
to match the backend name without "-backend.so" suffix instead.

For example, this allows to use "--backend=headless" instead of
"--backend=headless-backend.so".

Update help text and documentation. Keep the old way working for
backwards compatibility.

[1] 50dbf38514 ("libweston: use enum to choose the backend")

Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
This commit is contained in:
Philipp Zabel 2022-12-05 17:28:23 +01:00 committed by Philipp Zabel
parent 06eb28ba62
commit 84c10124cd
11 changed files with 64 additions and 57 deletions

View File

@ -645,24 +645,24 @@ usage(int error_code)
"Core options:\n\n" "Core options:\n\n"
" --version\t\tPrint weston version\n" " --version\t\tPrint weston version\n"
" -B, --backend=MODULE\tBackend module, one of\n" " -B, --backend=BACKEND\tBackend module, one of\n"
#if defined(BUILD_DRM_COMPOSITOR) #if defined(BUILD_DRM_COMPOSITOR)
"\t\t\t\tdrm-backend.so\n" "\t\t\t\tdrm\n"
#endif #endif
#if defined(BUILD_HEADLESS_COMPOSITOR) #if defined(BUILD_HEADLESS_COMPOSITOR)
"\t\t\t\theadless-backend.so\n" "\t\t\t\theadless\n"
#endif #endif
#if defined(BUILD_RDP_COMPOSITOR) #if defined(BUILD_RDP_COMPOSITOR)
"\t\t\t\trdp-backend.so\n" "\t\t\t\trdp\n"
#endif #endif
#if defined(BUILD_VNC_COMPOSITOR) #if defined(BUILD_VNC_COMPOSITOR)
"\t\t\t\tvnc-backend.so\n" "\t\t\t\tvnc\n"
#endif #endif
#if defined(BUILD_WAYLAND_COMPOSITOR) #if defined(BUILD_WAYLAND_COMPOSITOR)
"\t\t\t\twayland-backend.so\n" "\t\t\t\twayland\n"
#endif #endif
#if defined(BUILD_X11_COMPOSITOR) #if defined(BUILD_X11_COMPOSITOR)
"\t\t\t\tx11-backend.so\n" "\t\t\t\tx11\n"
#endif #endif
" --shell=MODULE\tShell module, defaults to desktop-shell.so\n" " --shell=MODULE\tShell module, defaults to desktop-shell.so\n"
" -S, --socket=NAME\tName of socket to listen on\n" " -S, --socket=NAME\tName of socket to listen on\n"
@ -686,7 +686,7 @@ usage(int error_code)
#if defined(BUILD_DRM_COMPOSITOR) #if defined(BUILD_DRM_COMPOSITOR)
fprintf(out, fprintf(out,
"Options for drm-backend.so:\n\n" "Options for drm:\n\n"
" --seat=SEAT\t\tThe seat that weston should run on, instead of the seat defined in XDG_SEAT\n" " --seat=SEAT\t\tThe seat that weston should run on, instead of the seat defined in XDG_SEAT\n"
" --drm-device=CARD\tThe DRM device to use, e.g. \"card0\".\n" " --drm-device=CARD\tThe DRM device to use, e.g. \"card0\".\n"
" --use-pixman\t\tUse the pixman (CPU) renderer\n" " --use-pixman\t\tUse the pixman (CPU) renderer\n"
@ -696,7 +696,7 @@ usage(int error_code)
#if defined(BUILD_HEADLESS_COMPOSITOR) #if defined(BUILD_HEADLESS_COMPOSITOR)
fprintf(out, fprintf(out,
"Options for headless-backend.so:\n\n" "Options for headless:\n\n"
" --width=WIDTH\t\tWidth of memory surface\n" " --width=WIDTH\t\tWidth of memory surface\n"
" --height=HEIGHT\tHeight of memory surface\n" " --height=HEIGHT\tHeight of memory surface\n"
" --scale=SCALE\t\tScale factor of output\n" " --scale=SCALE\t\tScale factor of output\n"
@ -710,7 +710,7 @@ usage(int error_code)
#if defined(BUILD_RDP_COMPOSITOR) #if defined(BUILD_RDP_COMPOSITOR)
fprintf(out, fprintf(out,
"Options for rdp-backend.so:\n\n" "Options for rdp:\n\n"
" --width=WIDTH\t\tWidth of desktop\n" " --width=WIDTH\t\tWidth of desktop\n"
" --height=HEIGHT\tHeight of desktop\n" " --height=HEIGHT\tHeight of desktop\n"
" --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n" " --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n"
@ -726,7 +726,7 @@ usage(int error_code)
#if defined(BUILD_VNC_COMPOSITOR) #if defined(BUILD_VNC_COMPOSITOR)
fprintf(out, fprintf(out,
"Options for vnc-backend.so:\n\n" "Options for vnc:\n\n"
" --width=WIDTH\t\tWidth of desktop\n" " --width=WIDTH\t\tWidth of desktop\n"
" --height=HEIGHT\tHeight of desktop\n" " --height=HEIGHT\tHeight of desktop\n"
" --port=PORT\t\tThe port to listen on\n" " --port=PORT\t\tThe port to listen on\n"
@ -737,7 +737,7 @@ usage(int error_code)
#if defined(BUILD_WAYLAND_COMPOSITOR) #if defined(BUILD_WAYLAND_COMPOSITOR)
fprintf(out, fprintf(out,
"Options for wayland-backend.so:\n\n" "Options for wayland:\n\n"
" --width=WIDTH\t\tWidth of Wayland surface\n" " --width=WIDTH\t\tWidth of Wayland surface\n"
" --height=HEIGHT\tHeight of Wayland surface\n" " --height=HEIGHT\tHeight of Wayland surface\n"
" --scale=SCALE\t\tScale factor of output\n" " --scale=SCALE\t\tScale factor of output\n"
@ -750,7 +750,7 @@ usage(int error_code)
#if defined(BUILD_X11_COMPOSITOR) #if defined(BUILD_X11_COMPOSITOR)
fprintf(out, fprintf(out,
"Options for x11-backend.so:\n\n" "Options for x11:\n\n"
" --width=WIDTH\t\tWidth of X window\n" " --width=WIDTH\t\tWidth of X window\n"
" --height=HEIGHT\tHeight of X window\n" " --height=HEIGHT\tHeight of X window\n"
" --scale=SCALE\t\tScale factor of output\n" " --scale=SCALE\t\tScale factor of output\n"
@ -1123,9 +1123,9 @@ weston_choose_default_backend(void)
char *backend = NULL; char *backend = NULL;
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
backend = strdup("wayland-backend.so"); backend = strdup("wayland");
else if (getenv("DISPLAY")) else if (getenv("DISPLAY"))
backend = strdup("x11-backend.so"); backend = strdup("x11");
else else
backend = strdup(WESTON_NATIVE_BACKEND); backend = strdup(WESTON_NATIVE_BACKEND);
@ -3452,17 +3452,23 @@ static int
load_backend(struct weston_compositor *compositor, const char *backend, load_backend(struct weston_compositor *compositor, const char *backend,
int *argc, char **argv, struct weston_config *config) int *argc, char **argv, struct weston_config *config)
{ {
if (strstr(backend, "headless-backend.so")) if (strcmp(backend, "headless") == 0 ||
strstr(backend, "headless-backend.so"))
return load_headless_backend(compositor, argc, argv, config); return load_headless_backend(compositor, argc, argv, config);
else if (strstr(backend, "rdp-backend.so")) else if (strcmp(backend, "rdp") == 0 ||
strstr(backend, "rdp-backend.so"))
return load_rdp_backend(compositor, argc, argv, config); return load_rdp_backend(compositor, argc, argv, config);
else if (strstr(backend, "vnc-backend.so")) else if (strcmp(backend, "vnc") == 0 ||
strstr(backend, "vnc-backend.so"))
return load_vnc_backend(compositor, argc, argv, config); return load_vnc_backend(compositor, argc, argv, config);
else if (strstr(backend, "drm-backend.so")) else if (strcmp(backend, "drm") == 0 ||
strstr(backend, "drm-backend.so"))
return load_drm_backend(compositor, argc, argv, config); return load_drm_backend(compositor, argc, argv, config);
else if (strstr(backend, "x11-backend.so")) else if (strcmp(backend, "x11") == 0 ||
strstr(backend, "x11-backend.so"))
return load_x11_backend(compositor, argc, argv, config); return load_x11_backend(compositor, argc, argv, config);
else if (strstr(backend, "wayland-backend.so")) else if (strcmp(backend, "wayland") == 0 ||
strstr(backend, "wayland-backend.so"))
return load_wayland_backend(compositor, argc, argv, config); return load_wayland_backend(compositor, argc, argv, config);
weston_log("Error: unknown backend \"%s\"\n", backend); weston_log("Error: unknown backend \"%s\"\n", backend);

View File

@ -14,7 +14,7 @@ Weston on a machine that already has another graphical environment running,
being either another wayland compositor (e.g. Weston) or on a X11 server. being either another wayland compositor (e.g. Weston) or on a X11 server.
You should only specify the backend manually if you know that what Weston picks You should only specify the backend manually if you know that what Weston picks
is not the best, or the one you intended to use is different than the one is not the best, or the one you intended to use is different than the one
loaded. In that case, the backend can be selected by using ``-B [backend.so]`` loaded. In that case, the backend can be selected by using ``-B [backend]``
command line option. As each back-end uses a different way to get input and command line option. As each back-end uses a different way to get input and
produce output, it means that the most suitable back-end depends on the produce output, it means that the most suitable back-end depends on the
environment being used. environment being used.
@ -173,7 +173,7 @@ Then, weston can be run by selecting the DRM-backend and the seat ``seat-insecur
:: ::
SEATD_VTBOUND=0 ./weston -Bdrm-backend.so --seat=seat-insecure SEATD_VTBOUND=0 ./weston -Bdrm --seat=seat-insecure
This assumes you are using the libseat launcher of Weston with the "builtin" This assumes you are using the libseat launcher of Weston with the "builtin"
backend of libseat. Libseat automatically falls back to the builtin backend if backend of libseat. Libseat automatically falls back to the builtin backend if

View File

@ -1,5 +1,5 @@
man_conf = configuration_data() man_conf = configuration_data()
man_conf.set('weston_native_backend', opt_backend_native) man_conf.set('weston_native_backend', backend_default)
man_conf.set('weston_modules_dir', dir_module_weston) man_conf.set('weston_modules_dir', dir_module_weston)
man_conf.set('libweston_modules_dir', dir_module_libweston) man_conf.set('libweston_modules_dir', dir_module_libweston)
man_conf.set('weston_shell_client', get_option('desktop-shell-client-default')) man_conf.set('weston_shell_client', get_option('desktop-shell-client-default'))

View File

@ -2,7 +2,7 @@
.SH NAME .SH NAME
weston-drm \- the DRM backend for Weston weston-drm \- the DRM backend for Weston
.SH SYNOPSIS .SH SYNOPSIS
.B weston --backend=drm-backend.so .B weston --backend=drm
. .
.\" *************************************************************** .\" ***************************************************************
.SH DESCRIPTION .SH DESCRIPTION

View File

@ -2,7 +2,7 @@
.SH NAME .SH NAME
weston-rdp \- the RDP backend for Weston weston-rdp \- the RDP backend for Weston
.SH SYNOPSIS .SH SYNOPSIS
.B weston --backend=rdp-backend.so .B weston --backend=rdp
. .
.\" *************************************************************** .\" ***************************************************************
.SH DESCRIPTION .SH DESCRIPTION

View File

@ -2,7 +2,7 @@
.SH NAME .SH NAME
weston-vnc \- the VNC backend for Weston weston-vnc \- the VNC backend for Weston
.SH SYNOPSIS .SH SYNOPSIS
.B weston --backend=vnc-backend.so .B weston --backend=vnc
. .
.\" *************************************************************** .\" ***************************************************************
.SH DESCRIPTION .SH DESCRIPTION

View File

@ -124,18 +124,17 @@ directory are:
.fi .fi
.RE .RE
.TP 7 .TP 7
.BI "backend=" headless-backend.so .BI "backend=" headless
overrides defaults backend. Available backend modules in the overrides defaults backend. Available backends are:
.IR "@libweston_modules_dir@"
directory are:
.PP .PP
.RS 10 .RS 10
.nf .nf
.BR drm-backend.so .BR drm
.BR headless-backend.so .BR headless
.BR rdp-backend.so .BR rdp
.BR wayland-backend.so .BR vnc
.BR x11-backend.so .BR wayland
.BR x11
.fi .fi
.RE .RE
.TP 7 .TP 7
@ -660,7 +659,7 @@ sets the path to the xserver to run (string).
.\"--------------------------------------------------------------------- .\"---------------------------------------------------------------------
.SH "SCREEN-SHARE SECTION" .SH "SCREEN-SHARE SECTION"
.TP 7 .TP 7
.BI "command=" "@weston_bindir@/weston --backend=rdp-backend.so \ .BI "command=" "@weston_bindir@/weston --backend=rdp \
--shell=fullscreen-shell.so --no-clients-resize --no-config" --shell=fullscreen-shell.so --no-clients-resize --no-config"
sets the command to start a fullscreen-shell server for screen sharing (string). sets the command to start a fullscreen-shell server for screen sharing (string).
.TP 7 .TP 7

View File

@ -23,30 +23,30 @@ Weston also supports X clients via
.\" *************************************************************** .\" ***************************************************************
.SH BACKENDS .SH BACKENDS
.TP .TP
.I drm-backend.so .I drm
The DRM backend uses Linux KMS for output and evdev devices for input. The DRM backend uses Linux KMS for output and evdev devices for input.
It supports multiple monitors in a unified desktop with DPMS. See It supports multiple monitors in a unified desktop with DPMS. See
.BR weston-drm (7), .BR weston-drm (7),
if installed. if installed.
.TP .TP
.I wayland-backend.so .I wayland
The Wayland backend runs on another Wayland server, a different Weston The Wayland backend runs on another Wayland server, a different Weston
instance, for example. Weston shows up as a single desktop window on instance, for example. Weston shows up as a single desktop window on
the parent server. the parent server.
.TP .TP
.I x11-backend.so .I x11
The X11 backend runs on an X server. Each Weston output becomes an The X11 backend runs on an X server. Each Weston output becomes an
X window. This is a cheap way to test multi-monitor support of a X window. This is a cheap way to test multi-monitor support of a
Wayland shell, desktop, or applications. Wayland shell, desktop, or applications.
.TP .TP
.I rdp-backend.so .I rdp
The RDP backend runs in memory without the need of graphical hardware. Access The RDP backend runs in memory without the need of graphical hardware. Access
to the desktop is done by using the RDP protocol. Each connecting to the desktop is done by using the RDP protocol. Each connecting
client has its own seat making it a cheap way to test multi-seat support. See client has its own seat making it a cheap way to test multi-seat support. See
.BR weston-rdp (7), .BR weston-rdp (7),
if installed. if installed.
.TP .TP
.I vnc-backend.so .I vnc
The VNC backend runs in memory without the need of graphical hardware. Access The VNC backend runs in memory without the need of graphical hardware. Access
to the desktop is done by using the RFB protocol. Currently only one to the desktop is done by using the RFB protocol. Currently only one
connecting client is supported. See connecting client is supported. See
@ -110,12 +110,14 @@ and
. .
.SS Weston core options: .SS Weston core options:
.TP .TP
\fB\-\^B\fR\fIbackend.so\fR, \fB\-\-backend\fR=\fIbackend.so\fR \fB\-\^B\fR\fIbackend\fR, \fB\-\-backend\fR=\fIbackend\fR
Load Load
.I backend.so .I backend
instead of the default backend. The file is searched for in instead of the default backend, see
.IR "@weston_modules_dir@" , .IR BACKENDS .
or you can pass an absolute path. The default backend is The backend module is searched for in
.IR "@weston_modules_dir@" .
The default backend is
.I @weston_native_backend@ .I @weston_native_backend@
unless the environment suggests otherwise, see unless the environment suggests otherwise, see
.IR DISPLAY " and " WAYLAND_DISPLAY . .IR DISPLAY " and " WAYLAND_DISPLAY .
@ -297,7 +299,7 @@ The X display. If
is set, and is set, and
.B WAYLAND_DISPLAY .B WAYLAND_DISPLAY
is not set, the default backend becomes is not set, the default backend becomes
.IR x11-backend.so . .IR x11 .
.TP .TP
.B WAYLAND_DEBUG .B WAYLAND_DEBUG
If set to any value, causes libwayland to print the live protocol If set to any value, causes libwayland to print the live protocol
@ -314,7 +316,7 @@ is not set, the socket name is "wayland-0".
If If
.B WAYLAND_DISPLAY .B WAYLAND_DISPLAY
is already set, the default backend becomes is already set, the default backend becomes
.IR wayland-backend.so . .IR wayland .
This allows launching Weston as a nested server. This allows launching Weston as a nested server.
.TP .TP
.B WAYLAND_SOCKET .B WAYLAND_SOCKET

View File

@ -124,8 +124,7 @@ if backend_default == 'auto'
endif endif
endforeach endforeach
endif endif
opt_backend_native = backend_default + '-backend.so' config_h.set_quoted('WESTON_NATIVE_BACKEND', backend_default)
config_h.set_quoted('WESTON_NATIVE_BACKEND', opt_backend_native)
message('The default backend is ' + backend_default) message('The default backend is ' + backend_default)
if not get_option('backend-' + backend_default) if not get_option('backend-' + backend_default)
error('Backend @0@ was chosen as native but is not being built.'.format(backend_default)) error('Backend @0@ was chosen as native but is not being built.'.format(backend_default))

View File

@ -206,11 +206,12 @@ static const char *
backend_to_str(enum weston_compositor_backend b) backend_to_str(enum weston_compositor_backend b)
{ {
static const char * const names[] = { static const char * const names[] = {
[WESTON_BACKEND_DRM] = "drm-backend.so", [WESTON_BACKEND_DRM] = "drm",
[WESTON_BACKEND_HEADLESS] = "headless-backend.so", [WESTON_BACKEND_HEADLESS] = "headless",
[WESTON_BACKEND_RDP] = "rdp-backend.so", [WESTON_BACKEND_RDP] = "rdp",
[WESTON_BACKEND_WAYLAND] = "wayland-backend.so", [WESTON_BACKEND_VNC] = "vnc",
[WESTON_BACKEND_X11] = "X11-backend.so", [WESTON_BACKEND_WAYLAND] = "wayland",
[WESTON_BACKEND_X11] = "x11",
}; };
assert(b >= 0 && b < ARRAY_LENGTH(names)); assert(b >= 0 && b < ARRAY_LENGTH(names));
return names[b]; return names[b];

View File

@ -82,7 +82,7 @@ path=@libexecdir@/weston-keyboard
#max_accel_factor = 1.0 #max_accel_factor = 1.0
[screen-share] [screen-share]
command=@bindir@/weston --backend=rdp-backend.so --shell=fullscreen-shell.so --no-clients-resize command=@bindir@/weston --backend=rdp --shell=fullscreen-shell.so --no-clients-resize
#start-on-startup=false #start-on-startup=false
#[xwayland] #[xwayland]