diff options
author | nyorain <nyorain@gmail.com> | 2017-07-01 18:35:42 +0200 |
---|---|---|
committer | nyorain <nyorain@gmail.com> | 2017-07-01 18:35:42 +0200 |
commit | 60fa626116ac3865ec9034cfa7b33ecad03884a8 (patch) | |
tree | 33164807e0f99e8718744808514fb0770c9bf5f6 | |
parent | Revert "swaybar: Group child processes for signalling" (diff) | |
download | sway-60fa626116ac3865ec9034cfa7b33ecad03884a8.tar.gz sway-60fa626116ac3865ec9034cfa7b33ecad03884a8.tar.zst sway-60fa626116ac3865ec9034cfa7b33ecad03884a8.zip |
Add the 'clipboard' command to set the clipboard
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/clipboard.c | 38 |
3 files changed, 40 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index f67df10f..660da2c2 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -103,6 +103,7 @@ sway_cmd cmd_client_unfocused; | |||
103 | sway_cmd cmd_client_urgent; | 103 | sway_cmd cmd_client_urgent; |
104 | sway_cmd cmd_client_placeholder; | 104 | sway_cmd cmd_client_placeholder; |
105 | sway_cmd cmd_client_background; | 105 | sway_cmd cmd_client_background; |
106 | sway_cmd cmd_clipboard; | ||
106 | sway_cmd cmd_commands; | 107 | sway_cmd cmd_commands; |
107 | sway_cmd cmd_debuglog; | 108 | sway_cmd cmd_debuglog; |
108 | sway_cmd cmd_default_border; | 109 | sway_cmd cmd_default_border; |
diff --git a/sway/commands.c b/sway/commands.c index f83b5287..14be656a 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -165,6 +165,7 @@ static struct cmd_handler handlers[] = { | |||
165 | { "client.placeholder", cmd_client_placeholder }, | 165 | { "client.placeholder", cmd_client_placeholder }, |
166 | { "client.unfocused", cmd_client_unfocused }, | 166 | { "client.unfocused", cmd_client_unfocused }, |
167 | { "client.urgent", cmd_client_urgent }, | 167 | { "client.urgent", cmd_client_urgent }, |
168 | { "clipboard", cmd_clipboard }, | ||
168 | { "commands", cmd_commands }, | 169 | { "commands", cmd_commands }, |
169 | { "debuglog", cmd_debuglog }, | 170 | { "debuglog", cmd_debuglog }, |
170 | { "default_border", cmd_default_border }, | 171 | { "default_border", cmd_default_border }, |
diff --git a/sway/commands/clipboard.c b/sway/commands/clipboard.c new file mode 100644 index 00000000..95514e78 --- /dev/null +++ b/sway/commands/clipboard.c | |||
@@ -0,0 +1,38 @@ | |||
1 | #include <wlc/wlc.h> | ||
2 | #include <unistd.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "stringop.h" | ||
6 | |||
7 | static void send_clipboard(void *data, const char *type, int fd) { | ||
8 | if (strcmp(type, "text/plain") != 0 | ||
9 | && strcmp(type, "text/plain;charset=utf-8") != 0) { | ||
10 | close(fd); | ||
11 | return; | ||
12 | } | ||
13 | |||
14 | const char *str = data; | ||
15 | write(fd, str, strlen(str)); | ||
16 | close(fd); | ||
17 | } | ||
18 | |||
19 | struct cmd_results *cmd_clipboard(int argc, char **argv) { | ||
20 | static char *current_data = NULL; | ||
21 | |||
22 | struct cmd_results *error = NULL; | ||
23 | if ((error = checkarg(argc, "clipboard", EXPECTED_AT_LEAST, 1))) { | ||
24 | return error; | ||
25 | } | ||
26 | |||
27 | static const char *types[2] = { | ||
28 | "text/plain", | ||
29 | "text/plain;charset=utf-8" | ||
30 | }; | ||
31 | |||
32 | char *str = join_args(argv, argc); | ||
33 | wlc_set_selection(str, types, 2, &send_clipboard); | ||
34 | |||
35 | free(current_data); | ||
36 | current_data = str; | ||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | } | ||