From 311c7db7e300bc9e749a582a56805150180138e0 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 17 Nov 2018 12:29:59 +0100 Subject: [PATCH] Add xwayland command --- include/sway/commands.h | 3 +- include/sway/config.h | 1 + include/sway/server.h | 2 +- sway/commands.c | 1 + sway/commands/xwayland.c | 21 ++++++++++++ sway/config.c | 1 + sway/main.c | 2 +- sway/meson.build | 1 + sway/server.c | 73 +++++++++++++++++++++------------------- sway/sway.5.scd | 6 +++- 10 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 sway/commands/xwayland.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 2fe8a631..32925369 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -176,8 +176,9 @@ sway_cmd cmd_title_format; sway_cmd cmd_unmark; sway_cmd cmd_urgent; sway_cmd cmd_workspace; -sway_cmd cmd_ws_auto_back_and_forth; sway_cmd cmd_workspace_layout; +sway_cmd cmd_ws_auto_back_and_forth; +sway_cmd cmd_xwayland; sway_cmd bar_cmd_activate_button; sway_cmd bar_cmd_binding_mode_indicator; diff --git a/include/sway/config.h b/include/sway/config.h index 658b4a01..c44533ee 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -393,6 +393,7 @@ struct sway_config { size_t urgent_timeout; enum sway_fowa focus_on_window_activation; enum sway_popup_during_fullscreen popup_during_fullscreen; + bool xwayland; // Flags enum focus_follows_mouse_mode focus_follows_mouse; diff --git a/include/sway/server.h b/include/sway/server.h index a3233d66..0f30653f 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -71,7 +71,7 @@ struct sway_server server; bool server_privileged_prepare(struct sway_server *server); bool server_init(struct sway_server *server); void server_fini(struct sway_server *server); -bool server_start_backend(struct sway_server *server); +bool server_start(struct sway_server *server); void server_run(struct sway_server *server); void handle_new_output(struct wl_listener *listener, void *data); diff --git a/sway/commands.c b/sway/commands.c index 4b86c2fa..a68c724a 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -113,6 +113,7 @@ static struct cmd_handler config_handlers[] = { { "swaybg_command", cmd_swaybg_command }, { "swaynag_command", cmd_swaynag_command }, { "workspace_layout", cmd_workspace_layout }, + { "xwayland", cmd_xwayland }, }; /* Runtime-only commands. Keep alphabetized */ diff --git a/sway/commands/xwayland.c b/sway/commands/xwayland.c new file mode 100644 index 00000000..03a0121b --- /dev/null +++ b/sway/commands/xwayland.c @@ -0,0 +1,21 @@ +#include "sway/config.h" +#include "log.h" +#include "sway/commands.h" +#include "sway/server.h" +#include "util.h" + +struct cmd_results *cmd_xwayland(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "xwayland", EXPECTED_EQUAL_TO, 1))) { + return error; + } + +#ifdef HAVE_XWAYLAND + config->xwayland = parse_boolean(argv[0], config->xwayland); +#else + wlr_log(WLR_INFO, "Ignoring `xwayland` command, " + "sway hasn't been built with Xwayland support"); +#endif + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config.c b/sway/config.c index c1320acf..6f65d0c2 100644 --- a/sway/config.c +++ b/sway/config.c @@ -212,6 +212,7 @@ static void config_defaults(struct sway_config *config) { config->font_height = 17; // height of monospace 10 config->urgent_timeout = 500; config->popup_during_fullscreen = POPUP_SMART; + config->xwayland = true; // floating view config->floating_maximum_width = 0; diff --git a/sway/main.c b/sway/main.c index 920cea11..86374163 100644 --- a/sway/main.c +++ b/sway/main.c @@ -382,7 +382,7 @@ int main(int argc, char **argv) { } if (!terminate_request) { - if (!server_start_backend(&server)) { + if (!server_start(&server)) { sway_terminate(EXIT_FAILURE); } } diff --git a/sway/meson.build b/sway/meson.build index d9bc08f3..4524bac9 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -94,6 +94,7 @@ sway_sources = files( 'commands/workspace.c', 'commands/workspace_layout.c', 'commands/ws_auto_back_and_forth.c', + 'commands/xwayland.c', 'commands/bar/activate_button.c', 'commands/bar/binding_mode_indicator.c', diff --git a/sway/server.c b/sway/server.c index cd3fcdf6..68142e87 100644 --- a/sway/server.c +++ b/sway/server.c @@ -83,40 +83,6 @@ bool server_init(struct sway_server *server) { &server->xdg_shell_surface); server->xdg_shell_surface.notify = handle_xdg_shell_surface; - // TODO: configurable cursor theme and size - int cursor_size = 24; - const char *cursor_theme = NULL; - - char cursor_size_fmt[16]; - snprintf(cursor_size_fmt, sizeof(cursor_size_fmt), "%d", cursor_size); - setenv("XCURSOR_SIZE", cursor_size_fmt, 1); - if (cursor_theme != NULL) { - setenv("XCURSOR_THEME", cursor_theme, 1); - } - -#if HAVE_XWAYLAND - server->xwayland.wlr_xwayland = - wlr_xwayland_create(server->wl_display, server->compositor, true); - wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface, - &server->xwayland_surface); - server->xwayland_surface.notify = handle_xwayland_surface; - wl_signal_add(&server->xwayland.wlr_xwayland->events.ready, - &server->xwayland_ready); - server->xwayland_ready.notify = handle_xwayland_ready; - - server->xwayland.xcursor_manager = - wlr_xcursor_manager_create(cursor_theme, cursor_size); - wlr_xcursor_manager_load(server->xwayland.xcursor_manager, 1); - struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( - server->xwayland.xcursor_manager, "left_ptr", 1); - if (xcursor != NULL) { - struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_xwayland_set_cursor(server->xwayland.wlr_xwayland, image->buffer, - image->width * 4, image->width, image->height, image->hotspot_x, - image->hotspot_y); - } -#endif - server->server_decoration_manager = wlr_server_decoration_manager_create(server->wl_display); wlr_server_decoration_manager_set_default_mode( @@ -173,7 +139,44 @@ void server_fini(struct sway_server *server) { list_free(server->transactions); } -bool server_start_backend(struct sway_server *server) { +bool server_start(struct sway_server *server) { + // TODO: configurable cursor theme and size + int cursor_size = 24; + const char *cursor_theme = NULL; + + char cursor_size_fmt[16]; + snprintf(cursor_size_fmt, sizeof(cursor_size_fmt), "%d", cursor_size); + setenv("XCURSOR_SIZE", cursor_size_fmt, 1); + if (cursor_theme != NULL) { + setenv("XCURSOR_THEME", cursor_theme, 1); + } + +#if HAVE_XWAYLAND + if (config->xwayland) { + wlr_log(WLR_DEBUG, "Initializing Xwayland"); + server->xwayland.wlr_xwayland = + wlr_xwayland_create(server->wl_display, server->compositor, true); + wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface, + &server->xwayland_surface); + server->xwayland_surface.notify = handle_xwayland_surface; + wl_signal_add(&server->xwayland.wlr_xwayland->events.ready, + &server->xwayland_ready); + server->xwayland_ready.notify = handle_xwayland_ready; + + server->xwayland.xcursor_manager = + wlr_xcursor_manager_create(cursor_theme, cursor_size); + wlr_xcursor_manager_load(server->xwayland.xcursor_manager, 1); + struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( + server->xwayland.xcursor_manager, "left_ptr", 1); + if (xcursor != NULL) { + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_xwayland_set_cursor(server->xwayland.wlr_xwayland, image->buffer, + image->width * 4, image->width, image->height, image->hotspot_x, + image->hotspot_y); + } + } +#endif + wlr_log(WLR_INFO, "Starting backend on wayland display '%s'", server->socket); if (!wlr_backend_start(server->backend)) { diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 1a11015f..95376ccc 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -84,6 +84,10 @@ The following commands may only be used in the configuration file. It can be disabled by setting the command to a single dash: _swaynag\_command -_ +*xwayland* enable|disable + Enables or disables Xwayland support, which allows X11 applications to be + used. + The following commands cannot be used directly in the configuration file. They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). @@ -421,7 +425,7 @@ The default colors are: *focus\_follows\_mouse* yes|no|always If set to _yes_, moving your mouse over a window will focus that window. If - set to _always_, the window under the cursor will always be focused, even + set to _always_, the window under the cursor will always be focused, even after switching between workspaces. *focus\_wrapping* yes|no|force