diff options
Diffstat (limited to 'sway/commands/clipboard.c')
-rw-r--r-- | sway/commands/clipboard.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 | } | ||