diff --git a/unix/gtkapp.c b/unix/gtkapp.c index 4a4af5a0..27468f2c 100644 --- a/unix/gtkapp.c +++ b/unix/gtkapp.c @@ -135,23 +135,21 @@ static void startup(GApplication *app, gpointer user_data) G_MENU_MODEL(menubar)); } -static void copy_cb(GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - copy_menu_action(user_data); -} +#define WIN_ACTION_LIST(X) \ + X("copy", MA_COPY) \ + X("paste", MA_PASTE) \ + /* end of list */ -static void paste_cb(GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - paste_menu_action(user_data); -} +#define WIN_ACTION_CALLBACK(name, id) \ +static void win_action_cb_ ## id(GSimpleAction *a, GVariant *p, gpointer d) \ +{ app_menu_action(d, id); } +WIN_ACTION_LIST(WIN_ACTION_CALLBACK) +#undef WIN_ACTION_CALLBACK static const GActionEntry win_actions[] = { - { "copy", copy_cb }, - { "paste", paste_cb }, +#define WIN_ACTION_ENTRY(name, id) { name, win_action_cb_ ## id }, +WIN_ACTION_LIST(WIN_ACTION_ENTRY) +#undef WIN_ACTION_ENTRY }; static GtkApplication *app; diff --git a/unix/gtkwin.c b/unix/gtkwin.c index feaa2e18..634f772d 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -3252,17 +3252,20 @@ void init_clipboard(struct gui_data *inst) #endif /* JUST_USE_GTK_CLIPBOARD_UTF8 */ -void copy_menu_action(void *frontend) +void app_menu_action(void *frontend, enum MenuAction action) { struct gui_data *inst = (struct gui_data *)frontend; - static const int clips[] = { MENU_CLIPBOARD }; - term_request_copy(inst->term, clips, lenof(clips)); -} - -void paste_menu_action(void *frontend) -{ - struct gui_data *inst = (struct gui_data *)frontend; - term_request_paste(inst->term, MENU_CLIPBOARD); + switch (action) { + case MA_COPY: + { + static const int clips[] = { MENU_CLIPBOARD }; + term_request_copy(inst->term, clips, lenof(clips)); + } + break; + case MA_PASTE: + term_request_paste(inst->term, MENU_CLIPBOARD); + break; + } } static void set_window_titles(struct gui_data *inst) diff --git a/unix/unix.h b/unix/unix.h index b2271cd3..20986ef7 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -184,9 +184,11 @@ GtkWidget *make_gtk_toplevel_window(void *frontend); /* Defined in gtkcomm.c */ void gtkcomm_setup(void); -/* Defined in gtkwin.c */ -void copy_menu_action(void *frontend); -void paste_menu_action(void *frontend); +/* Used to pass application-menu operations from gtkapp.c to gtkwin.c */ +enum MenuAction { + MA_COPY, MA_PASTE, +}; +void app_menu_action(void *frontend, enum MenuAction); /* Things pty.c needs from pterm.c */ const char *get_x_display(void *frontend);