Add paste functionality

This commit is contained in:
Andrei E 2021-11-01 18:52:03 +00:00 committed by Jari Vetoniemi
parent cd41b1b52c
commit 00efc974d7
4 changed files with 26 additions and 0 deletions

View File

@ -232,6 +232,7 @@ enum bm_key {
BM_KEY_LINE_DELETE_LEFT,
BM_KEY_LINE_DELETE_RIGHT,
BM_KEY_WORD_DELETE,
BM_KEY_PASTE,
BM_KEY_TAB,
BM_KEY_SHIFT_TAB,
BM_KEY_ESCAPE,

View File

@ -835,6 +835,25 @@ bm_menu_run_with_key(struct bm_menu *menu, enum bm_key key, uint32_t unicode)
}
break;
case BM_KEY_PASTE:
{
FILE *clipboard;
clipboard = popen("wl-paste -t text/plain", "r");
if (clipboard == NULL) {
clipboard = popen("xclip -t text/plain -out", "r");
}
if (clipboard == NULL) {
break;
}
int c;
while ((c = fgetc(clipboard)) != EOF) {
size_t width;
menu->cursor += bm_unicode_insert(&menu->filter, &menu->filter_size, menu->cursor, c, &width);
menu->curses_cursor += width;
}
}
break;
case BM_KEY_UNICODE:
{
size_t width;

View File

@ -177,6 +177,9 @@ poll_key(const struct bm_menu *menu, unsigned int *unicode)
case XKB_KEY_m:
return (mods & MOD_CTRL ? BM_KEY_RETURN : BM_KEY_UNICODE);
case XKB_KEY_y:
return (mods & MOD_CTRL ? BM_KEY_PASTE : BM_KEY_UNICODE);
case XKB_KEY_1:
if ((mods & MOD_ALT)) return BM_KEY_CUSTOM_1;
break;

View File

@ -144,6 +144,9 @@ poll_key(const struct bm_menu *menu, unsigned int *unicode)
case XK_w:
return (mods & MOD_CTRL ? BM_KEY_WORD_DELETE : BM_KEY_UNICODE);
case XK_y:
return (mods & MOD_CTRL ? BM_KEY_PASTE : BM_KEY_UNICODE);
case XK_j:
return (mods & MOD_ALT ? BM_KEY_DOWN : BM_KEY_UNICODE);