aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/input/events.c1
-rw-r--r--sway/commands/input/xkb_switch_layout.c1
-rw-r--r--sway/commands/move.c1
-rw-r--r--sway/commands/output.c1
-rw-r--r--sway/commands/output/color_profile.c101
-rw-r--r--sway/commands/seat/cursor.c1
-rw-r--r--sway/commands/seat/pointer_constraint.c1
-rw-r--r--sway/commands/seat/shortcuts_inhibitor.c1
-rw-r--r--sway/commands/shortcuts_inhibitor.c1
-rw-r--r--sway/commands/swap.c4
-rw-r--r--sway/commands/workspace.c4
-rw-r--r--sway/commands/xwayland.c2
12 files changed, 116 insertions, 3 deletions
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c
index 08d99bf0..3cea026e 100644
--- a/sway/commands/input/events.c
+++ b/sway/commands/input/events.c
@@ -5,6 +5,7 @@
5#include "sway/config.h" 5#include "sway/config.h"
6#include "sway/commands.h" 6#include "sway/commands.h"
7#include "sway/input/input-manager.h" 7#include "sway/input/input-manager.h"
8#include "sway/server.h"
8#include "log.h" 9#include "log.h"
9 10
10#if WLR_HAS_LIBINPUT_BACKEND 11#if WLR_HAS_LIBINPUT_BACKEND
diff --git a/sway/commands/input/xkb_switch_layout.c b/sway/commands/input/xkb_switch_layout.c
index ecac8e6c..8d600fca 100644
--- a/sway/commands/input/xkb_switch_layout.c
+++ b/sway/commands/input/xkb_switch_layout.c
@@ -3,6 +3,7 @@
3#include "sway/config.h" 3#include "sway/config.h"
4#include "sway/commands.h" 4#include "sway/commands.h"
5#include "sway/input/input-manager.h" 5#include "sway/input/input-manager.h"
6#include "sway/server.h"
6#include "log.h" 7#include "log.h"
7 8
8struct xkb_switch_layout_action { 9struct xkb_switch_layout_action {
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 8addf26e..ff656cfb 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -11,6 +11,7 @@
11#include "sway/input/seat.h" 11#include "sway/input/seat.h"
12#include "sway/ipc-server.h" 12#include "sway/ipc-server.h"
13#include "sway/output.h" 13#include "sway/output.h"
14#include "sway/server.h"
14#include "sway/tree/arrange.h" 15#include "sway/tree/arrange.h"
15#include "sway/tree/container.h" 16#include "sway/tree/container.h"
16#include "sway/tree/root.h" 17#include "sway/tree/root.h"
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 5e5d31b3..b822e770 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -10,6 +10,7 @@ static const struct cmd_handler output_handlers[] = {
10 { "adaptive_sync", output_cmd_adaptive_sync }, 10 { "adaptive_sync", output_cmd_adaptive_sync },
11 { "background", output_cmd_background }, 11 { "background", output_cmd_background },
12 { "bg", output_cmd_background }, 12 { "bg", output_cmd_background },
13 { "color_profile", output_cmd_color_profile },
13 { "disable", output_cmd_disable }, 14 { "disable", output_cmd_disable },
14 { "dpms", output_cmd_dpms }, 15 { "dpms", output_cmd_dpms },
15 { "enable", output_cmd_enable }, 16 { "enable", output_cmd_enable },
diff --git a/sway/commands/output/color_profile.c b/sway/commands/output/color_profile.c
new file mode 100644
index 00000000..792bd55f
--- /dev/null
+++ b/sway/commands/output/color_profile.c
@@ -0,0 +1,101 @@
1#include <fcntl.h>
2#include <strings.h>
3#include <sys/stat.h>
4#include <unistd.h>
5#include <wlr/render/color.h>
6#include "sway/commands.h"
7#include "sway/config.h"
8
9static bool read_file_into_buf(const char *path, void **buf, size_t *size) {
10 /* Why not use fopen/fread directly? glibc will succesfully open directories,
11 * not just files, and supports seeking on them. Instead, we directly
12 * work with file descriptors and use the more consistent open/fstat/read. */
13 int fd = open(path, O_RDONLY | O_NOCTTY | O_CLOEXEC);
14 if (fd == -1) {
15 return false;
16 }
17 char *b = NULL;
18 struct stat info;
19 if (fstat(fd, &info) == -1) {
20 goto fail;
21 }
22 // only regular files, to avoid issues with e.g. opening pipes
23 if (!S_ISREG(info.st_mode)) {
24 goto fail;
25 }
26 off_t s = info.st_size;
27 if (s <= 0) {
28 goto fail;
29 }
30 b = calloc(1, s);
31 if (!b) {
32 goto fail;
33 }
34 size_t nread = 0;
35 while (nread < (size_t)s) {
36 size_t to_read = (size_t)s - nread;
37 ssize_t r = read(fd, b + nread, to_read);
38 if ((r == -1 && errno != EINTR) || r == 0) {
39 goto fail;
40 }
41 nread += (size_t)r;
42 }
43 close(fd);
44 *buf = b;
45 *size = (size_t)s;
46 return true; // success
47fail:
48 free(b);
49 close(fd);
50 return false;
51}
52
53struct cmd_results *output_cmd_color_profile(int argc, char **argv) {
54 if (!config->handler_context.output_config) {
55 return cmd_results_new(CMD_FAILURE, "Missing output config");
56 }
57 if (!argc) {
58 return cmd_results_new(CMD_INVALID, "Missing color_profile first argument.");
59 }
60
61 if (strcmp(*argv, "srgb") == 0) {
62 wlr_color_transform_unref(config->handler_context.output_config->color_transform);
63 config->handler_context.output_config->color_transform = NULL;
64 config->handler_context.output_config->set_color_transform = true;
65
66 config->handler_context.leftovers.argc = argc - 1;
67 config->handler_context.leftovers.argv = argv + 1;
68 } else if (strcmp(*argv, "icc") == 0) {
69 if (argc < 2) {
70 return cmd_results_new(CMD_INVALID,
71 "Invalid color profile specification: icc type requires a file");
72 }
73 void *data = NULL;
74 size_t size = 0;
75 if (!read_file_into_buf(argv[1], &data, &size)) {
76 return cmd_results_new(CMD_FAILURE,
77 "Failed to load color profile: could not read ICC file");
78 }
79
80 struct wlr_color_transform *tmp =
81 wlr_color_transform_init_linear_to_icc(data, size);
82 if (!tmp) {
83 free(data);
84 return cmd_results_new(CMD_FAILURE,
85 "Failed to load color profile: failed to initialize transform from ICC");
86 }
87 free(data);
88
89 wlr_color_transform_unref(config->handler_context.output_config->color_transform);
90 config->handler_context.output_config->color_transform = tmp;
91 config->handler_context.output_config->set_color_transform = true;
92
93 config->handler_context.leftovers.argc = argc - 2;
94 config->handler_context.leftovers.argv = argv + 2;
95 } else {
96 return cmd_results_new(CMD_INVALID,
97 "Invalid color profile specification: first argument should be icc|srgb");
98 }
99
100 return NULL;
101}
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c
index df7c379d..434e6bbb 100644
--- a/sway/commands/seat/cursor.c
+++ b/sway/commands/seat/cursor.c
@@ -5,6 +5,7 @@
5#include <wlr/types/wlr_pointer.h> 5#include <wlr/types/wlr_pointer.h>
6#include "sway/commands.h" 6#include "sway/commands.h"
7#include "sway/input/cursor.h" 7#include "sway/input/cursor.h"
8#include "sway/server.h"
8 9
9static struct cmd_results *press_or_release(struct sway_cursor *cursor, 10static struct cmd_results *press_or_release(struct sway_cursor *cursor,
10 char *action, char *button_str); 11 char *action, char *button_str);
diff --git a/sway/commands/seat/pointer_constraint.c b/sway/commands/seat/pointer_constraint.c
index 3890ebde..38f85bcd 100644
--- a/sway/commands/seat/pointer_constraint.c
+++ b/sway/commands/seat/pointer_constraint.c
@@ -4,6 +4,7 @@
4#include "sway/config.h" 4#include "sway/config.h"
5#include "sway/input/cursor.h" 5#include "sway/input/cursor.h"
6#include "sway/input/seat.h" 6#include "sway/input/seat.h"
7#include "sway/server.h"
7 8
8enum operation { 9enum operation {
9 OP_ENABLE, 10 OP_ENABLE,
diff --git a/sway/commands/seat/shortcuts_inhibitor.c b/sway/commands/seat/shortcuts_inhibitor.c
index 7c7f99cf..df68618d 100644
--- a/sway/commands/seat/shortcuts_inhibitor.c
+++ b/sway/commands/seat/shortcuts_inhibitor.c
@@ -2,6 +2,7 @@
2#include "sway/commands.h" 2#include "sway/commands.h"
3#include "sway/input/seat.h" 3#include "sway/input/seat.h"
4#include "sway/input/input-manager.h" 4#include "sway/input/input-manager.h"
5#include "sway/server.h"
5#include "util.h" 6#include "util.h"
6 7
7static struct cmd_results *handle_action(struct seat_config *sc, 8static struct cmd_results *handle_action(struct seat_config *sc,
diff --git a/sway/commands/shortcuts_inhibitor.c b/sway/commands/shortcuts_inhibitor.c
index ffa1a5c9..2dfd1b9f 100644
--- a/sway/commands/shortcuts_inhibitor.c
+++ b/sway/commands/shortcuts_inhibitor.c
@@ -3,6 +3,7 @@
3#include "sway/commands.h" 3#include "sway/commands.h"
4#include "sway/config.h" 4#include "sway/config.h"
5#include "sway/input/seat.h" 5#include "sway/input/seat.h"
6#include "sway/server.h"
6#include "sway/tree/container.h" 7#include "sway/tree/container.h"
7#include "sway/tree/view.h" 8#include "sway/tree/view.h"
8 9
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index e142eede..c0b0d0b9 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -18,7 +18,7 @@ static bool test_con_id(struct sway_container *container, void *data) {
18 return container->node.id == *con_id; 18 return container->node.id == *con_id;
19} 19}
20 20
21#if HAVE_XWAYLAND 21#if WLR_HAS_XWAYLAND
22static bool test_id(struct sway_container *container, void *data) { 22static bool test_id(struct sway_container *container, void *data) {
23 xcb_window_t *wid = data; 23 xcb_window_t *wid = data;
24 return (container->view && container->view->type == SWAY_VIEW_XWAYLAND 24 return (container->view && container->view->type == SWAY_VIEW_XWAYLAND
@@ -53,7 +53,7 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
53 53
54 char *value = join_args(argv + 3, argc - 3); 54 char *value = join_args(argv + 3, argc - 3);
55 if (strcasecmp(argv[2], "id") == 0) { 55 if (strcasecmp(argv[2], "id") == 0) {
56#if HAVE_XWAYLAND 56#if WLR_HAS_XWAYLAND
57 xcb_window_t id = strtol(value, NULL, 0); 57 xcb_window_t id = strtol(value, NULL, 0);
58 other = root_find_container(test_id, &id); 58 other = root_find_container(test_id, &id);
59#endif 59#endif
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index a14ebb20..37a201b4 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -157,6 +157,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
157 return cmd_results_new(CMD_FAILURE, 157 return cmd_results_new(CMD_FAILURE,
158 "Unable to allocate workspace output"); 158 "Unable to allocate workspace output");
159 } 159 }
160 if (output_location + 1 < argc) {
161 list_free_items_and_destroy(wsc->outputs);
162 wsc->outputs = create_list();
163 }
160 for (int i = output_location + 1; i < argc; ++i) { 164 for (int i = output_location + 1; i < argc; ++i) {
161 list_add(wsc->outputs, strdup(argv[i])); 165 list_add(wsc->outputs, strdup(argv[i]));
162 } 166 }
diff --git a/sway/commands/xwayland.c b/sway/commands/xwayland.c
index 584a8e3a..c0b175fc 100644
--- a/sway/commands/xwayland.c
+++ b/sway/commands/xwayland.c
@@ -10,7 +10,7 @@ struct cmd_results *cmd_xwayland(int argc, char **argv) {
10 return error; 10 return error;
11 } 11 }
12 12
13#ifdef HAVE_XWAYLAND 13#ifdef WLR_HAS_XWAYLAND
14 enum xwayland_mode xwayland; 14 enum xwayland_mode xwayland;
15 if (strcmp(argv[0], "force") == 0) { 15 if (strcmp(argv[0], "force") == 0) {
16 xwayland = XWAYLAND_MODE_IMMEDIATE; 16 xwayland = XWAYLAND_MODE_IMMEDIATE;