Merge pull request #3144 from emersion/cmd-xwayland

Add xwayland command
This commit is contained in:
Drew DeVault 2019-01-13 20:42:39 -05:00 committed by GitHub
commit 4879d40695
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 71 additions and 38 deletions

View file

@ -101,6 +101,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 */

21
sway/commands/xwayland.c Normal file
View file

@ -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);
}

View file

@ -204,6 +204,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;
config->titlebar_border_thickness = 1;
config->titlebar_h_padding = 5;

View file

@ -369,7 +369,7 @@ int main(int argc, char **argv) {
}
if (!terminate_request) {
if (!server_start_backend(&server)) {
if (!server_start(&server)) {
sway_terminate(EXIT_FAILURE);
}
}

View file

@ -104,6 +104,7 @@ sway_sources = files(
'commands/workspace.c',
'commands/workspace_layout.c',
'commands/ws_auto_back_and_forth.c',
'commands/xwayland.c',
'commands/bar/bind.c',
'commands/bar/binding_mode_indicator.c',

View file

@ -84,40 +84,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(
@ -175,7 +141,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)) {

View file

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