Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: GitHub noreply@github.com Date: Sun, 15 Oct 2023 20:14:41 UTC Commit: 5a5b85d6c3886c54e18853f3c6df8f48148b9ac5 https://github.com/geany/geany/commit/5a5b85d6c3886c54e18853f3c6df8f48148b9a...
Log Message: ----------- Merge pull request #3316 from dolik-rce/fix-goto-popup-location
Fix goto popup location
Modified Paths: -------------- plugins/filebrowser.c src/callbacks.c src/editor.c src/msgwindow.c src/notebook.c src/plugins.c src/prefs.c src/sidebar.c src/symbols.c src/ui_utils.c src/ui_utils.h src/vte.c
Modified: plugins/filebrowser.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -743,7 +743,7 @@ static gboolean on_button_press(GtkWidget *widget, GdkEventButton *event, gpoint
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(popup_items.show_hidden_files), show_hidden_files); - gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL, event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(popup_menu), (GdkEvent *) event); /* don't return TRUE here, unless the selection won't be changed */ } return FALSE;
Modified: src/callbacks.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -634,7 +634,7 @@ gboolean toolbar_popup_menu(GtkWidget *widget, GdkEventButton *event, gpointer u { if (event->button == 3) { - ui_menu_popup(GTK_MENU(ui_widgets.toolbar_menu), NULL, NULL, event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(ui_widgets.toolbar_menu), (GdkEvent *) event); return TRUE; } return FALSE;
Modified: src/editor.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -346,7 +346,7 @@ static gboolean on_editor_button_press_event(GtkWidget *widget, GdkEventButton * g_signal_emit_by_name(geany_object, "update-editor-menu", current_word, editor_info.click_pos, doc);
- ui_menu_popup(GTK_MENU(main_widgets.editor_menu), NULL, NULL, event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(main_widgets.editor_menu), (GdkEvent *) event); return TRUE; } return FALSE;
Modified: src/msgwindow.c 9 lines changed, 3 insertions(+), 6 deletions(-) =================================================================== @@ -1236,20 +1236,17 @@ static gboolean on_msgwin_button_press_event(GtkWidget *widget, GdkEventButton * { case MSG_STATUS: { - ui_menu_popup(GTK_MENU(msgwindow.popup_status_menu), NULL, NULL, - event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(msgwindow.popup_status_menu), (GdkEvent *) event); break; } case MSG_MESSAGE: { - ui_menu_popup(GTK_MENU(msgwindow.popup_msg_menu), NULL, NULL, - event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(msgwindow.popup_msg_menu), (GdkEvent *) event); break; } case MSG_COMPILER: { - ui_menu_popup(GTK_MENU(msgwindow.popup_compiler_menu), NULL, NULL, - event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(msgwindow.popup_compiler_menu), (GdkEvent *) event); break; } }
Modified: src/notebook.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -512,7 +512,7 @@ static void show_tab_bar_popup_menu(GdkEventButton *event, GeanyDocument *doc) gtk_container_add(GTK_CONTAINER(menu), menu_item); g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_all1_activate), NULL);
- ui_menu_popup(GTK_MENU(menu), NULL, NULL, event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *) event); }
Modified: src/plugins.c 3 lines changed, 1 insertions(+), 2 deletions(-) =================================================================== @@ -1642,8 +1642,7 @@ static gboolean pm_treeview_button_press_cb(GtkWidget *widget, GdkEventButton *e { if (event->button == 3) { - ui_menu_popup(GTK_MENU(pm_widgets.popup_menu), NULL, NULL, - event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(pm_widgets.popup_menu), (GdkEvent *) event); } return FALSE; }
Modified: src/prefs.c 15 lines changed, 1 insertions(+), 14 deletions(-) =================================================================== @@ -214,8 +214,6 @@ static void kb_tree_view_change_button_clicked_cb(GtkWidget *button, KbData *kbd static void kb_show_popup_menu(KbData *kbdata, GtkWidget *widget, GdkEventButton *event) { static GtkWidget *menu = NULL; - guint button; - guint32 event_time;
if (menu == NULL) { @@ -236,18 +234,7 @@ static void kb_show_popup_menu(KbData *kbdata, GtkWidget *widget, GdkEventButton gtk_menu_attach_to_widget(GTK_MENU(menu), widget, NULL); }
- if (event != NULL) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time(); - } - - ui_menu_popup(GTK_MENU(menu), NULL, NULL, button, event_time); + gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *) event); }
Modified: src/sidebar.c 8 lines changed, 3 insertions(+), 5 deletions(-) =================================================================== @@ -145,7 +145,7 @@ on_default_tag_tree_button_press_event(GtkWidget *widget, GdkEventButton *event, { if (event->button == 3) { - ui_menu_popup(GTK_MENU(tv.popup_taglist), NULL, NULL, event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(tv.popup_taglist), (GdkEvent *) event); return TRUE; } return FALSE; @@ -1513,13 +1513,11 @@ static gboolean sidebar_button_press_cb(GtkWidget *widget, GdkEventButton *event
/* update menu item sensitivity */ documents_menu_update(selection); - ui_menu_popup(GTK_MENU(openfiles_popup_menu), NULL, NULL, - event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(openfiles_popup_menu), (GdkEvent *) event); } else { - ui_menu_popup(GTK_MENU(tv.popup_taglist), NULL, NULL, - event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(tv.popup_taglist), (GdkEvent *) event); } handled = TRUE; }
Modified: src/symbols.c 99 lines changed, 18 insertions(+), 81 deletions(-) =================================================================== @@ -1408,81 +1408,22 @@ static guint get_tag_class(const TMTag *tag) }
-/* positions a popup at the caret from the ScintillaObject in @p data */ -static void goto_popup_position_func(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) +/* opens menu at caret position */ +static void show_menu_at_caret(GtkMenu* menu, ScintillaObject *sci) { - gint line_height; - GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(menu)); - gint monitor_num; - GdkRectangle monitor; - GtkRequisition req; - GdkEventButton *event_button = g_object_get_data(G_OBJECT(menu), "geany-button-event"); - - if (event_button) - { - /* if we got a mouse click, popup at that position */ - *x = (gint) event_button->x_root; - *y = (gint) event_button->y_root; - line_height = 0; /* we don't want to offset below the line or anything */ - } - else /* keyboard positioning */ - { - ScintillaObject *sci = data; - GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(sci)); - gint pos = sci_get_current_position(sci); - gint line = sci_get_line_from_position(sci, pos); - gint pos_x = SSM(sci, SCI_POINTXFROMPOSITION, 0, pos); - gint pos_y = SSM(sci, SCI_POINTYFROMPOSITION, 0, pos); - - line_height = SSM(sci, SCI_TEXTHEIGHT, line, 0); - - gdk_window_get_origin(window, x, y); - *x += pos_x; - *y += pos_y; - } - - monitor_num = gdk_screen_get_monitor_at_point(screen, *x, *y); - - gtk_widget_get_preferred_size(GTK_WIDGET(menu), NULL, &req); - -#if GTK_CHECK_VERSION(3, 4, 0) - gdk_screen_get_monitor_workarea(screen, monitor_num, &monitor); -#else - gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor); -#endif - - /* put on one size of the X position, but within the monitor */ - if (gtk_widget_get_direction(GTK_WIDGET(menu)) == GTK_TEXT_DIR_RTL) - { - if (*x - req.width - 1 >= monitor.x) - *x -= req.width + 1; - else if (*x + req.width > monitor.x + monitor.width) - *x = monitor.x; - else - *x += 1; - } - else - { - if (*x + req.width + 1 <= monitor.x + monitor.width) - *x = MAX(monitor.x, *x + 1); - else if (*x - req.width - 1 >= monitor.x) - *x -= req.width + 1; - else - *x = monitor.x + MAX(0, monitor.width - req.width); - } - - /* try to put, in order: - * 1. below the Y position, under the line - * 2. above the Y position - * 3. within the monitor */ - if (*y + line_height + req.height <= monitor.y + monitor.height) - *y = MAX(monitor.y, *y + line_height); - else if (*y - req.height >= monitor.y) - *y = *y - req.height; - else - *y = monitor.y + MAX(0, monitor.height - req.height); - - *push_in = FALSE; + GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(sci)); + gint pos = sci_get_current_position(sci); + gint line = sci_get_line_from_position(sci, pos); + gint line_height = SSM(sci, SCI_TEXTHEIGHT, line, 0); + gint x = SSM(sci, SCI_POINTXFROMPOSITION, 0, pos); + gint y = SSM(sci, SCI_POINTYFROMPOSITION, 0, pos); + gint pos_next = sci_get_position_after(sci, pos); + gint char_width = 0; + /* if next pos is on the same Y (same line and not after wrapping), diff the X */ + if (pos_next > pos && SSM(sci, SCI_POINTYFROMPOSITION, 0, pos_next) == y) + char_width = SSM(sci, SCI_POINTXFROMPOSITION, 0, pos_next) - x; + GdkRectangle rect = {x, y, char_width, line_height}; + gtk_menu_popup_at_rect(GTK_MENU(menu), window, &rect, GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL); }
@@ -1492,7 +1433,6 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b GtkWidget *menu; GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); GdkEvent *event; - GdkEventButton *button_event = NULL; TMTag *tmtag; guint i; gchar **short_names, **file_names; @@ -1560,15 +1500,12 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b
event = gtk_get_current_event(); if (event && event->type == GDK_BUTTON_PRESS) - button_event = (GdkEventButton *) event; + gtk_menu_popup_at_pointer(GTK_MENU(menu), event); else + show_menu_at_caret(GTK_MENU(menu), doc->editor->sci); + if (event) gdk_event_free(event);
- g_object_set_data_full(G_OBJECT(menu), "geany-button-event", button_event, - button_event ? (GDestroyNotify) gdk_event_free : NULL); - ui_menu_popup(GTK_MENU(menu), goto_popup_position_func, doc->editor->sci, - button_event ? button_event->button : 0, gtk_get_current_event_time ()); - g_object_unref(group); }
Modified: src/ui_utils.c 12 lines changed, 0 insertions(+), 12 deletions(-) =================================================================== @@ -3257,15 +3257,3 @@ gboolean ui_encodings_combo_box_set_active_encoding(GtkComboBox *combo, gint enc } return FALSE; } - -void ui_menu_popup(GtkMenu* menu, GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time) -{ - /* Use appropriate function for menu popup: - - gtk_menu_popup_at_pointer is not available on GTK older than 3.22 - - gtk_menu_popup is deprecated and causes issues on multimonitor wayland setups */ -#if GTK_CHECK_VERSION(3,22,0) - gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL); -#else - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, func, data, button, activate_time); -#endif -}
Modified: src/ui_utils.h 2 lines changed, 0 insertions(+), 2 deletions(-) =================================================================== @@ -373,8 +373,6 @@ gchar *ui_get_project_directory(const gchar *path);
void ui_menu_sort_by_label(GtkMenu *menu);
-void ui_menu_popup(GtkMenu* menu, GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time); - #endif /* GEANY_PRIVATE */
G_END_DECLS
Modified: src/vte.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -526,7 +526,7 @@ static gboolean vte_button_pressed(GtkWidget *widget, GdkEventButton *event, gpo if (event->button == 3) { gtk_widget_grab_focus(vte_config.vte); - ui_menu_popup(GTK_MENU(vte_config.menu), NULL, NULL, event->button, event->time); + gtk_menu_popup_at_pointer(GTK_MENU(vte_config.menu), (GdkEvent *) event); return TRUE; } else if (event->button == 2)
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).