Add clipboard support for Wayland
This commit adds clipboard support for Wayland. The implementation is quite ugly though, as it requires the use of an external program and shell (wl-clipboard). It doesn't add a hard dependency though, as if the user doesn't want pasting the dependency is not required.
This commit is contained in:
parent
5129856857
commit
dd44bc56ab
4
PKGBUILD
4
PKGBUILD
|
@ -27,6 +27,10 @@ makedepends=(
|
|||
ninja
|
||||
)
|
||||
|
||||
optdepends=(
|
||||
'wl-clipboard: Clipboard support on Wayland'
|
||||
)
|
||||
|
||||
provides=($pkgname)
|
||||
conflicts=($pkgname)
|
||||
source=(
|
||||
|
|
|
@ -34,6 +34,9 @@ can be themed to look identical to dmenu.
|
|||
- For Wayland support, which is optional.
|
||||
- wayland-protocols
|
||||
- For Wayland support, which is optional.
|
||||
- wl-clipboard
|
||||
- For Wayland support, which is optional.
|
||||
- Only required at runtime, and only if pasting is desired.
|
||||
- xkbcommon
|
||||
- For Wayland support, which is optional.
|
||||
- libX11
|
||||
|
|
|
@ -188,10 +188,16 @@ void moveend(Arg *arg) {
|
|||
}
|
||||
|
||||
void paste(Arg *arg) {
|
||||
#if USEWAYLAND
|
||||
if (protocol) {
|
||||
paste_wl();
|
||||
} else {
|
||||
#if USEX
|
||||
if (!protocol) {
|
||||
paste_x11(arg->i);
|
||||
#endif
|
||||
}
|
||||
#elif USEX
|
||||
paste_x11(arg->i);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,44 @@ int is_correct_modifier(struct state *state, char *modifier) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* This function is pretty garbage. However I don't feel like implementing all the garbage necessary to paste properly.
|
||||
* If anyone wants to do it, feel free to pull request.
|
||||
*/
|
||||
char *wl_clipboard(void) {
|
||||
FILE *fp;
|
||||
char output_text[1024];
|
||||
char *clipboard = malloc(sizeof(output_text));
|
||||
clipboard[0] = '\0';
|
||||
|
||||
fp = popen("which wl-paste > /dev/null && wl-paste -t text/plain", "r");
|
||||
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "spmenu: Failed to open command\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(output_text, sizeof(output_text), fp) != NULL) {
|
||||
strcat(clipboard, output_text);
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
void paste_wl(void) {
|
||||
char *p, *q;
|
||||
|
||||
fprintf(stderr, "gentoo");
|
||||
|
||||
p = wl_clipboard();
|
||||
|
||||
insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t)strlen(p)); // insert selection
|
||||
|
||||
// draw the menu
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
void keypress_wl(struct state *state, enum wl_keyboard_key_state key_state, xkb_keysym_t sym) {
|
||||
int i = 0;
|
||||
char buf[8];
|
||||
|
|
|
@ -149,6 +149,8 @@ static int set_exclusive_zone(struct state *state, unsigned int val);
|
|||
static int set_keyboard(struct state *state, int interactivity);
|
||||
static int add_layer_listener(struct state *state);
|
||||
static int set_visible_layer(struct state *state);
|
||||
static char *wl_clipboard(void);
|
||||
static void paste_wl(void);
|
||||
struct wl_buffer *create_buffer(struct state *state);
|
||||
|
||||
/* Set to 0 if the connection was successful
|
||||
|
|
2
spmenu.c
2
spmenu.c
|
@ -257,7 +257,7 @@ static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
|
|||
static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
||||
|
||||
#if USEX
|
||||
static void pastesel(void); // TODO: wayland clipboard
|
||||
static void pastesel(void);
|
||||
static void grabfocus(void); // focus doesn't need to be grabbed on wayland
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue