forked from RepoMirrors/bemenu
Add paste functionality
This commit is contained in:
parent
cd41b1b52c
commit
00efc974d7
@ -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,
|
||||
|
19
lib/menu.c
19
lib/menu.c
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user