From 60fa626116ac3865ec9034cfa7b33ecad03884a8 Mon Sep 17 00:00:00 2001 From: nyorain Date: Sat, 1 Jul 2017 18:35:42 +0200 Subject: Add the 'clipboard' command to set the clipboard --- sway/commands/clipboard.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sway/commands/clipboard.c (limited to 'sway/commands') 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 +#include +#include +#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); +} -- cgit v1.2.3