Skip to content

Commit

Permalink
SWAPPY_PAINT_MODE_TEXT support C-v paste
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiuf committed Aug 27, 2024
1 parent fc0c6d9 commit 9ac76f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,24 @@ static void im_context_commit(GtkIMContext *imc, gchar *str,
}
}

static void clipboard_paste_selection(struct swappy_state *state) {
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gchar *text = gtk_clipboard_wait_for_text(clipboard);
if (text) {
paint_update_temporary_str(state, text);
g_free(text);
}
}

void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
struct swappy_state *state) {
if (state->temp_paint && state->mode == SWAPPY_PAINT_MODE_TEXT) {
paint_update_temporary_text(state, event);
/* ctrl-v: paste */
if (event->state & GDK_CONTROL_MASK && event->keyval == GDK_KEY_v) {
clipboard_paste_selection(state);
} else {
paint_update_temporary_text(state, event);
}
render_state(state);
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ void paint_update_temporary_text(struct swappy_state *state,
case GDK_KEY_Right:
cursor_move_forward(text);
break;
case GDK_KEY_V:
cursor_move_forward(text);
break;
default:
unicode = gdk_keyval_to_unicode(event->keyval);
if (unicode != 0) {
Expand Down

0 comments on commit 9ac76f4

Please sign in to comment.