aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-07-01 13:07:25 -0400
committerGitHub <noreply@github.com>2017-07-01 13:07:25 -0400
commitfe763991d4865bffaafcd3ff15ecede6a9daa6ae (patch)
tree33164807e0f99e8718744808514fb0770c9bf5f6 /sway/commands
parent387eca1b29cbc6f497e2cb26a0bff0b06b50b6a1 (diff)
parent60fa626116ac3865ec9034cfa7b33ecad03884a8 (diff)
Merge pull request #1254 from nyorain/master
Fix #926
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/clipboard.c38
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 @@
+#include <wlc/wlc.h>
+#include <unistd.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "stringop.h"
+
+static void send_clipboard(void *data, const char *type, int fd) {
+ if (strcmp(type, "text/plain") != 0
+ && strcmp(type, "text/plain;charset=utf-8") != 0) {
+ close(fd);
+ return;
+ }
+
+ const char *str = data;
+ write(fd, str, strlen(str));
+ close(fd);
+}
+
+struct cmd_results *cmd_clipboard(int argc, char **argv) {
+ static char *current_data = NULL;
+
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "clipboard", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ static const char *types[2] = {
+ "text/plain",
+ "text/plain;charset=utf-8"
+ };
+
+ char *str = join_args(argv, argc);
+ wlc_set_selection(str, types, 2, &send_clipboard);
+
+ free(current_data);
+ current_data = str;
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}