aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar nyorain <nyorain@gmail.com>2017-07-01 18:35:42 +0200
committerLibravatar nyorain <nyorain@gmail.com>2017-07-01 18:35:42 +0200
commit60fa626116ac3865ec9034cfa7b33ecad03884a8 (patch)
tree33164807e0f99e8718744808514fb0770c9bf5f6 /sway
parentRevert "swaybar: Group child processes for signalling" (diff)
downloadsway-60fa626116ac3865ec9034cfa7b33ecad03884a8.tar.gz
sway-60fa626116ac3865ec9034cfa7b33ecad03884a8.tar.zst
sway-60fa626116ac3865ec9034cfa7b33ecad03884a8.zip
Add the 'clipboard' command to set the clipboard
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/clipboard.c38
2 files changed, 39 insertions, 0 deletions
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
7static 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
19struct 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}