summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h1
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/clipboard.c38
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;
103sway_cmd cmd_client_urgent; 103sway_cmd cmd_client_urgent;
104sway_cmd cmd_client_placeholder; 104sway_cmd cmd_client_placeholder;
105sway_cmd cmd_client_background; 105sway_cmd cmd_client_background;
106sway_cmd cmd_clipboard;
106sway_cmd cmd_commands; 107sway_cmd cmd_commands;
107sway_cmd cmd_debuglog; 108sway_cmd cmd_debuglog;
108sway_cmd cmd_default_border; 109sway_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
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}