diff options
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | sway/commands/output.c | 1 | ||||
-rw-r--r-- | sway/commands/output/unplug.c | 54 | ||||
-rw-r--r-- | sway/meson.build | 1 |
4 files changed, 57 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 013a7b82..07941bb4 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -294,6 +294,7 @@ sway_cmd output_cmd_scale_filter; | |||
294 | sway_cmd output_cmd_subpixel; | 294 | sway_cmd output_cmd_subpixel; |
295 | sway_cmd output_cmd_toggle; | 295 | sway_cmd output_cmd_toggle; |
296 | sway_cmd output_cmd_transform; | 296 | sway_cmd output_cmd_transform; |
297 | sway_cmd output_cmd_unplug; | ||
297 | 298 | ||
298 | sway_cmd seat_cmd_attach; | 299 | sway_cmd seat_cmd_attach; |
299 | sway_cmd seat_cmd_cursor; | 300 | sway_cmd seat_cmd_cursor; |
diff --git a/sway/commands/output.c b/sway/commands/output.c index c102344d..df32c673 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -27,6 +27,7 @@ static const struct cmd_handler output_handlers[] = { | |||
27 | { "subpixel", output_cmd_subpixel }, | 27 | { "subpixel", output_cmd_subpixel }, |
28 | { "toggle", output_cmd_toggle }, | 28 | { "toggle", output_cmd_toggle }, |
29 | { "transform", output_cmd_transform }, | 29 | { "transform", output_cmd_transform }, |
30 | { "unplug", output_cmd_unplug }, | ||
30 | }; | 31 | }; |
31 | 32 | ||
32 | struct cmd_results *cmd_output(int argc, char **argv) { | 33 | struct cmd_results *cmd_output(int argc, char **argv) { |
diff --git a/sway/commands/output/unplug.c b/sway/commands/output/unplug.c new file mode 100644 index 00000000..dfef626f --- /dev/null +++ b/sway/commands/output/unplug.c | |||
@@ -0,0 +1,54 @@ | |||
1 | #include <strings.h> | ||
2 | #include <wlr/config.h> | ||
3 | #include <wlr/backend/headless.h> | ||
4 | #include <wlr/backend/wayland.h> | ||
5 | #if WLR_HAS_X11_BACKEND | ||
6 | #include <wlr/backend/x11.h> | ||
7 | #endif | ||
8 | #include "sway/commands.h" | ||
9 | #include "sway/config.h" | ||
10 | #include "sway/output.h" | ||
11 | |||
12 | static bool is_backend_allowed(struct wlr_backend *backend) { | ||
13 | if (wlr_backend_is_headless(backend)) { | ||
14 | return true; | ||
15 | } | ||
16 | if (wlr_backend_is_wl(backend)) { | ||
17 | return true; | ||
18 | } | ||
19 | #if WLR_HAS_X11_BACKEND | ||
20 | if (wlr_backend_is_x11(backend)) { | ||
21 | return true; | ||
22 | } | ||
23 | #endif | ||
24 | return false; | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * This command is intended for developer use only. | ||
29 | */ | ||
30 | struct cmd_results *output_cmd_unplug(int argc, char **argv) { | ||
31 | if (!config->handler_context.output_config) { | ||
32 | return cmd_results_new(CMD_FAILURE, "Missing output config"); | ||
33 | } | ||
34 | |||
35 | const char *oc_name = config->handler_context.output_config->name; | ||
36 | if (strcmp(oc_name, "*") == 0) { | ||
37 | return cmd_results_new(CMD_INVALID, "Won't unplug all outputs"); | ||
38 | } | ||
39 | |||
40 | struct sway_output *sway_output = all_output_by_name_or_id(oc_name); | ||
41 | if (!sway_output) { | ||
42 | return cmd_results_new(CMD_INVALID, | ||
43 | "Cannot unplug unknown output %s", oc_name); | ||
44 | } | ||
45 | |||
46 | if (!is_backend_allowed(sway_output->wlr_output->backend)) { | ||
47 | return cmd_results_new(CMD_INVALID, | ||
48 | "Can only unplug outputs with headless, wayland or x11 backend"); | ||
49 | } | ||
50 | |||
51 | wlr_output_destroy(sway_output->wlr_output); | ||
52 | |||
53 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
54 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index ced7419c..c7b9d6e6 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -198,6 +198,7 @@ sway_sources = files( | |||
198 | 'commands/output/subpixel.c', | 198 | 'commands/output/subpixel.c', |
199 | 'commands/output/toggle.c', | 199 | 'commands/output/toggle.c', |
200 | 'commands/output/transform.c', | 200 | 'commands/output/transform.c', |
201 | 'commands/output/unplug.c', | ||
201 | 202 | ||
202 | 'tree/arrange.c', | 203 | 'tree/arrange.c', |
203 | 'tree/container.c', | 204 | 'tree/container.c', |