diff options
author | emersion <contact@emersion.fr> | 2018-11-17 12:29:59 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-11-19 17:38:37 +0100 |
commit | 311c7db7e300bc9e749a582a56805150180138e0 (patch) | |
tree | a695f7af6143e47c8b7bb8afe32e2e8f59c39958 | |
parent | Merge pull request #3152 from camoz/master (diff) | |
download | sway-311c7db7e300bc9e749a582a56805150180138e0.tar.gz sway-311c7db7e300bc9e749a582a56805150180138e0.tar.zst sway-311c7db7e300bc9e749a582a56805150180138e0.zip |
Add xwayland command
-rw-r--r-- | include/sway/commands.h | 3 | ||||
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/sway/server.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/xwayland.c | 21 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/main.c | 2 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/server.c | 73 | ||||
-rw-r--r-- | sway/sway.5.scd | 6 |
10 files changed, 72 insertions, 39 deletions
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; | |||
176 | sway_cmd cmd_unmark; | 176 | sway_cmd cmd_unmark; |
177 | sway_cmd cmd_urgent; | 177 | sway_cmd cmd_urgent; |
178 | sway_cmd cmd_workspace; | 178 | sway_cmd cmd_workspace; |
179 | sway_cmd cmd_ws_auto_back_and_forth; | ||
180 | sway_cmd cmd_workspace_layout; | 179 | sway_cmd cmd_workspace_layout; |
180 | sway_cmd cmd_ws_auto_back_and_forth; | ||
181 | sway_cmd cmd_xwayland; | ||
181 | 182 | ||
182 | sway_cmd bar_cmd_activate_button; | 183 | sway_cmd bar_cmd_activate_button; |
183 | sway_cmd bar_cmd_binding_mode_indicator; | 184 | 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 { | |||
393 | size_t urgent_timeout; | 393 | size_t urgent_timeout; |
394 | enum sway_fowa focus_on_window_activation; | 394 | enum sway_fowa focus_on_window_activation; |
395 | enum sway_popup_during_fullscreen popup_during_fullscreen; | 395 | enum sway_popup_during_fullscreen popup_during_fullscreen; |
396 | bool xwayland; | ||
396 | 397 | ||
397 | // Flags | 398 | // Flags |
398 | enum focus_follows_mouse_mode focus_follows_mouse; | 399 | 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; | |||
71 | bool server_privileged_prepare(struct sway_server *server); | 71 | bool server_privileged_prepare(struct sway_server *server); |
72 | bool server_init(struct sway_server *server); | 72 | bool server_init(struct sway_server *server); |
73 | void server_fini(struct sway_server *server); | 73 | void server_fini(struct sway_server *server); |
74 | bool server_start_backend(struct sway_server *server); | 74 | bool server_start(struct sway_server *server); |
75 | void server_run(struct sway_server *server); | 75 | void server_run(struct sway_server *server); |
76 | 76 | ||
77 | void handle_new_output(struct wl_listener *listener, void *data); | 77 | 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[] = { | |||
113 | { "swaybg_command", cmd_swaybg_command }, | 113 | { "swaybg_command", cmd_swaybg_command }, |
114 | { "swaynag_command", cmd_swaynag_command }, | 114 | { "swaynag_command", cmd_swaynag_command }, |
115 | { "workspace_layout", cmd_workspace_layout }, | 115 | { "workspace_layout", cmd_workspace_layout }, |
116 | { "xwayland", cmd_xwayland }, | ||
116 | }; | 117 | }; |
117 | 118 | ||
118 | /* Runtime-only commands. Keep alphabetized */ | 119 | /* 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 @@ | |||
1 | #include "sway/config.h" | ||
2 | #include "log.h" | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/server.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | struct cmd_results *cmd_xwayland(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "xwayland", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | #ifdef HAVE_XWAYLAND | ||
14 | config->xwayland = parse_boolean(argv[0], config->xwayland); | ||
15 | #else | ||
16 | wlr_log(WLR_INFO, "Ignoring `xwayland` command, " | ||
17 | "sway hasn't been built with Xwayland support"); | ||
18 | #endif | ||
19 | |||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
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) { | |||
212 | config->font_height = 17; // height of monospace 10 | 212 | config->font_height = 17; // height of monospace 10 |
213 | config->urgent_timeout = 500; | 213 | config->urgent_timeout = 500; |
214 | config->popup_during_fullscreen = POPUP_SMART; | 214 | config->popup_during_fullscreen = POPUP_SMART; |
215 | config->xwayland = true; | ||
215 | 216 | ||
216 | // floating view | 217 | // floating view |
217 | config->floating_maximum_width = 0; | 218 | 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) { | |||
382 | } | 382 | } |
383 | 383 | ||
384 | if (!terminate_request) { | 384 | if (!terminate_request) { |
385 | if (!server_start_backend(&server)) { | 385 | if (!server_start(&server)) { |
386 | sway_terminate(EXIT_FAILURE); | 386 | sway_terminate(EXIT_FAILURE); |
387 | } | 387 | } |
388 | } | 388 | } |
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( | |||
94 | 'commands/workspace.c', | 94 | 'commands/workspace.c', |
95 | 'commands/workspace_layout.c', | 95 | 'commands/workspace_layout.c', |
96 | 'commands/ws_auto_back_and_forth.c', | 96 | 'commands/ws_auto_back_and_forth.c', |
97 | 'commands/xwayland.c', | ||
97 | 98 | ||
98 | 'commands/bar/activate_button.c', | 99 | 'commands/bar/activate_button.c', |
99 | 'commands/bar/binding_mode_indicator.c', | 100 | '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) { | |||
83 | &server->xdg_shell_surface); | 83 | &server->xdg_shell_surface); |
84 | server->xdg_shell_surface.notify = handle_xdg_shell_surface; | 84 | server->xdg_shell_surface.notify = handle_xdg_shell_surface; |
85 | 85 | ||
86 | // TODO: configurable cursor theme and size | ||
87 | int cursor_size = 24; | ||
88 | const char *cursor_theme = NULL; | ||
89 | |||
90 | char cursor_size_fmt[16]; | ||
91 | snprintf(cursor_size_fmt, sizeof(cursor_size_fmt), "%d", cursor_size); | ||
92 | setenv("XCURSOR_SIZE", cursor_size_fmt, 1); | ||
93 | if (cursor_theme != NULL) { | ||
94 | setenv("XCURSOR_THEME", cursor_theme, 1); | ||
95 | } | ||
96 | |||
97 | #if HAVE_XWAYLAND | ||
98 | server->xwayland.wlr_xwayland = | ||
99 | wlr_xwayland_create(server->wl_display, server->compositor, true); | ||
100 | wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface, | ||
101 | &server->xwayland_surface); | ||
102 | server->xwayland_surface.notify = handle_xwayland_surface; | ||
103 | wl_signal_add(&server->xwayland.wlr_xwayland->events.ready, | ||
104 | &server->xwayland_ready); | ||
105 | server->xwayland_ready.notify = handle_xwayland_ready; | ||
106 | |||
107 | server->xwayland.xcursor_manager = | ||
108 | wlr_xcursor_manager_create(cursor_theme, cursor_size); | ||
109 | wlr_xcursor_manager_load(server->xwayland.xcursor_manager, 1); | ||
110 | struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( | ||
111 | server->xwayland.xcursor_manager, "left_ptr", 1); | ||
112 | if (xcursor != NULL) { | ||
113 | struct wlr_xcursor_image *image = xcursor->images[0]; | ||
114 | wlr_xwayland_set_cursor(server->xwayland.wlr_xwayland, image->buffer, | ||
115 | image->width * 4, image->width, image->height, image->hotspot_x, | ||
116 | image->hotspot_y); | ||
117 | } | ||
118 | #endif | ||
119 | |||
120 | server->server_decoration_manager = | 86 | server->server_decoration_manager = |
121 | wlr_server_decoration_manager_create(server->wl_display); | 87 | wlr_server_decoration_manager_create(server->wl_display); |
122 | wlr_server_decoration_manager_set_default_mode( | 88 | wlr_server_decoration_manager_set_default_mode( |
@@ -173,7 +139,44 @@ void server_fini(struct sway_server *server) { | |||
173 | list_free(server->transactions); | 139 | list_free(server->transactions); |
174 | } | 140 | } |
175 | 141 | ||
176 | bool server_start_backend(struct sway_server *server) { | 142 | bool server_start(struct sway_server *server) { |
143 | // TODO: configurable cursor theme and size | ||
144 | int cursor_size = 24; | ||
145 | const char *cursor_theme = NULL; | ||
146 | |||
147 | char cursor_size_fmt[16]; | ||
148 | snprintf(cursor_size_fmt, sizeof(cursor_size_fmt), "%d", cursor_size); | ||
149 | setenv("XCURSOR_SIZE", cursor_size_fmt, 1); | ||
150 | if (cursor_theme != NULL) { | ||
151 | setenv("XCURSOR_THEME", cursor_theme, 1); | ||
152 | } | ||
153 | |||
154 | #if HAVE_XWAYLAND | ||
155 | if (config->xwayland) { | ||
156 | wlr_log(WLR_DEBUG, "Initializing Xwayland"); | ||
157 | server->xwayland.wlr_xwayland = | ||
158 | wlr_xwayland_create(server->wl_display, server->compositor, true); | ||
159 | wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface, | ||
160 | &server->xwayland_surface); | ||
161 | server->xwayland_surface.notify = handle_xwayland_surface; | ||
162 | wl_signal_add(&server->xwayland.wlr_xwayland->events.ready, | ||
163 | &server->xwayland_ready); | ||
164 | server->xwayland_ready.notify = handle_xwayland_ready; | ||
165 | |||
166 | server->xwayland.xcursor_manager = | ||
167 | wlr_xcursor_manager_create(cursor_theme, cursor_size); | ||
168 | wlr_xcursor_manager_load(server->xwayland.xcursor_manager, 1); | ||
169 | struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( | ||
170 | server->xwayland.xcursor_manager, "left_ptr", 1); | ||
171 | if (xcursor != NULL) { | ||
172 | struct wlr_xcursor_image *image = xcursor->images[0]; | ||
173 | wlr_xwayland_set_cursor(server->xwayland.wlr_xwayland, image->buffer, | ||
174 | image->width * 4, image->width, image->height, image->hotspot_x, | ||
175 | image->hotspot_y); | ||
176 | } | ||
177 | } | ||
178 | #endif | ||
179 | |||
177 | wlr_log(WLR_INFO, "Starting backend on wayland display '%s'", | 180 | wlr_log(WLR_INFO, "Starting backend on wayland display '%s'", |
178 | server->socket); | 181 | server->socket); |
179 | if (!wlr_backend_start(server->backend)) { | 182 | 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. | |||
84 | It can be disabled by setting the command to a single dash: | 84 | It can be disabled by setting the command to a single dash: |
85 | _swaynag\_command -_ | 85 | _swaynag\_command -_ |
86 | 86 | ||
87 | *xwayland* enable|disable | ||
88 | Enables or disables Xwayland support, which allows X11 applications to be | ||
89 | used. | ||
90 | |||
87 | The following commands cannot be used directly in the configuration file. | 91 | The following commands cannot be used directly in the configuration file. |
88 | They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). | 92 | They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). |
89 | 93 | ||
@@ -421,7 +425,7 @@ The default colors are: | |||
421 | 425 | ||
422 | *focus\_follows\_mouse* yes|no|always | 426 | *focus\_follows\_mouse* yes|no|always |
423 | If set to _yes_, moving your mouse over a window will focus that window. If | 427 | If set to _yes_, moving your mouse over a window will focus that window. If |
424 | set to _always_, the window under the cursor will always be focused, even | 428 | set to _always_, the window under the cursor will always be focused, even |
425 | after switching between workspaces. | 429 | after switching between workspaces. |
426 | 430 | ||
427 | *focus\_wrapping* yes|no|force | 431 | *focus\_wrapping* yes|no|force |