Compare commits

...

5 commits

Author SHA1 Message Date
Daniel Lublin
db5cd26652
Merge 223a7cb209 into 6efb3b5042 2025-04-28 07:30:46 +00:00
Simon Ser
6efb3b5042 cage: remove global server listeners on shutdown 2025-04-15 15:26:03 +02:00
Simon Ser
e21c155bcd seat: destroy keyboard groups on shutdown
These are not destroyed automatically because they are entirely
managed by the compositor.
2025-04-15 15:26:03 +02:00
Daniel Lublin
223a7cb209 fixup! Add -S to set display socket name; avoid auto wayland-0 2025-02-04 19:12:32 +01:00
Daniel Lublin
e22d2e781b Add -S to set display socket name; avoid auto wayland-0
Being able to set the socket name helps with having a predictable name
when for example connecting wayvnc to it.

Not trying the socket name "wayland-0" seems to be best practice:
https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/486
2025-02-04 16:07:26 +01:00
4 changed files with 60 additions and 6 deletions

View file

@ -33,6 +33,9 @@ activities outside the scope of the running application are prevented.
*-s* *-s*
Allow VT switching Allow VT switching
*-S <NAME>*
Use display socket NAME, instead of trying wayland-1, wayland-2, etc
*-v* *-v*
Show the version number and exit. Show the version number and exit.

46
cage.c
View file

@ -6,7 +6,7 @@
* See the LICENSE file accompanying this file. * See the LICENSE file accompanying this file.
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200809L
#include "config.h" #include "config.h"
@ -15,6 +15,7 @@
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
@ -232,6 +233,7 @@ usage(FILE *file, const char *cage)
" -m extend Extend the display across all connected outputs (default)\n" " -m extend Extend the display across all connected outputs (default)\n"
" -m last Use only the last connected output\n" " -m last Use only the last connected output\n"
" -s\t Allow VT switching\n" " -s\t Allow VT switching\n"
" -S NAME Use display socket NAME, instead of trying wayland-1, wayland-2, etc\n"
" -v\t Show the version number and exit\n" " -v\t Show the version number and exit\n"
"\n" "\n"
" Use -- when you want to pass arguments to APPLICATION\n", " Use -- when you want to pass arguments to APPLICATION\n",
@ -242,7 +244,7 @@ static bool
parse_args(struct cg_server *server, int argc, char *argv[]) parse_args(struct cg_server *server, int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "dDhm:sv")) != -1) { while ((c = getopt(argc, argv, "dDhm:sS:v")) != -1) {
switch (c) { switch (c) {
case 'd': case 'd':
server->xdg_decoration = true; server->xdg_decoration = true;
@ -263,6 +265,9 @@ parse_args(struct cg_server *server, int argc, char *argv[])
case 's': case 's':
server->allow_vt_switch = true; server->allow_vt_switch = true;
break; break;
case 'S':
server->socket = strdup(optarg);
break;
case 'v': case 'v':
fprintf(stdout, "Cage version " CAGE_VERSION "\n"); fprintf(stdout, "Cage version " CAGE_VERSION "\n");
exit(0); exit(0);
@ -562,8 +567,23 @@ main(int argc, char *argv[])
} }
#endif #endif
const char *socket = wl_display_add_socket_auto(server.wl_display); if (server.socket) {
if (!socket) { if (wl_display_add_socket(server.wl_display, server.socket) < 0) {
server.socket = NULL;
}
} else {
// Try display socket "wayland-1" and upwards, no "wayland-0"
char name_candidate[16];
for (unsigned int i = 1; i <= 32; ++i) {
snprintf(name_candidate, sizeof(name_candidate), "wayland-%u", i);
if (wl_display_add_socket(server.wl_display, name_candidate) >= 0) {
server.socket = strdup(name_candidate);
break;
}
}
}
if (!server.socket) {
wlr_log_errno(WLR_ERROR, "Unable to open Wayland socket"); wlr_log_errno(WLR_ERROR, "Unable to open Wayland socket");
ret = 1; ret = 1;
goto end; goto end;
@ -575,10 +595,10 @@ main(int argc, char *argv[])
goto end; goto end;
} }
if (setenv("WAYLAND_DISPLAY", socket, true) < 0) { if (setenv("WAYLAND_DISPLAY", server.socket, true) < 0) {
wlr_log_errno(WLR_ERROR, "Unable to set WAYLAND_DISPLAY. Clients may not be able to connect"); wlr_log_errno(WLR_ERROR, "Unable to set WAYLAND_DISPLAY. Clients may not be able to connect");
} else { } else {
wlr_log(WLR_DEBUG, "Cage " CAGE_VERSION " is running on Wayland display %s", socket); wlr_log(WLR_DEBUG, "Cage " CAGE_VERSION " is running on Wayland display %s", server.socket);
} }
#if CAGE_HAS_XWAYLAND #if CAGE_HAS_XWAYLAND
@ -596,11 +616,25 @@ main(int argc, char *argv[])
wl_display_run(server.wl_display); wl_display_run(server.wl_display);
#if CAGE_HAS_XWAYLAND #if CAGE_HAS_XWAYLAND
if (xwayland) {
wl_list_remove(&server.new_xwayland_surface.link);
}
wlr_xwayland_destroy(xwayland); wlr_xwayland_destroy(xwayland);
wlr_xcursor_manager_destroy(xcursor_manager); wlr_xcursor_manager_destroy(xcursor_manager);
#endif #endif
wl_display_destroy_clients(server.wl_display); wl_display_destroy_clients(server.wl_display);
wl_list_remove(&server.new_virtual_pointer.link);
wl_list_remove(&server.new_virtual_keyboard.link);
wl_list_remove(&server.output_manager_apply.link);
wl_list_remove(&server.output_manager_test.link);
wl_list_remove(&server.xdg_toplevel_decoration.link);
wl_list_remove(&server.new_xdg_toplevel.link);
wl_list_remove(&server.new_xdg_popup.link);
wl_list_remove(&server.new_idle_inhibitor_v1.link);
wl_list_remove(&server.new_output.link);
wl_list_remove(&server.output_layout_change.link);
end: end:
if (pid != 0) if (pid != 0)
app_ret = cleanup_primary_client(pid); app_ret = cleanup_primary_client(pid);

15
seat.c
View file

@ -380,6 +380,16 @@ cleanup:
free(cg_group); free(cg_group);
} }
static void
keyboard_group_destroy(struct cg_keyboard_group *keyboard_group)
{
wl_list_remove(&keyboard_group->key.link);
wl_list_remove(&keyboard_group->modifiers.link);
wlr_keyboard_group_destroy(keyboard_group->wlr_group);
wl_list_remove(&keyboard_group->link);
free(keyboard_group);
}
static void static void
handle_new_keyboard(struct cg_seat *seat, struct wlr_keyboard *keyboard, bool virtual) handle_new_keyboard(struct cg_seat *seat, struct wlr_keyboard *keyboard, bool virtual)
{ {
@ -893,6 +903,11 @@ seat_destroy(struct cg_seat *seat)
wl_list_remove(&seat->request_start_drag.link); wl_list_remove(&seat->request_start_drag.link);
wl_list_remove(&seat->start_drag.link); wl_list_remove(&seat->start_drag.link);
struct cg_keyboard_group *keyboard_group, *keyboard_group_tmp;
wl_list_for_each_safe (keyboard_group, keyboard_group_tmp, &seat->keyboard_groups, link) {
keyboard_group_destroy(keyboard_group);
}
// Destroying the wlr seat will trigger the destroy handler on our seat, // Destroying the wlr seat will trigger the destroy handler on our seat,
// which will in turn free it. // which will in turn free it.
wlr_seat_destroy(seat->seat); wlr_seat_destroy(seat->seat);

View file

@ -66,6 +66,8 @@ struct cg_server {
bool return_app_code; bool return_app_code;
bool terminated; bool terminated;
enum wlr_log_importance log_level; enum wlr_log_importance log_level;
char *socket;
}; };
void server_terminate(struct cg_server *server); void server_terminate(struct cg_server *server);