[PATCH gtk-3-16] GtkComboBox wrong menu_ypos
- From: Leslie Zhai <xiang zhai i-soft com cn>
- To: gtk-devel-list gnome org
- Subject: [PATCH gtk-3-16] GtkComboBox wrong menu_ypos
- Date: Wed, 03 Jun 2015 09:52:11 +0800
Hi Gtk developers,
I pay more attention to the gtk_combo_box_menu_position, the user
supplied function used to position the menu, when pressed the combobox
button
https://git.gnome.org/browse/gtk+/tree/gtk/gtkcombobox.c?h=gtk-3-16#n2268
I argue that it ignore the relationship between DisplayHeight (use X11
style), GdkEventButton`s y_root and popup menu`s allocation height
https://twitter.com/xiangzhai/status/605902462189314048
If DisplayHeight minus y_root is smaller than menu_alloc_height, the
menu_ypos should be minus menu_alloc_height, then my workaround patch
shown as below, not a monkey patch any more ;)
https://mail.gnome.org/archives/gtk-devel-list/2015-June/msg00000.html
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index ccda6ad..ce60473 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -159,6 +159,7 @@ struct _GtkComboBoxPrivate
GdkDevice *grab_keyboard;
gchar *tearoff_title;
+ guint y_root;
};
/* While debugging this evil code, I have learned that
@@ -1125,6 +1126,8 @@ gtk_combo_box_init (GtkComboBox *combo_box)
priv->text_column = -1;
priv->text_renderer = NULL;
priv->id_column = -1;
+
+ priv->y_root = 0;
}
static void
@@ -1898,6 +1901,18 @@ gtk_combo_box_menu_position_below (GtkMenu *menu,
*push_in = FALSE;
}
+static GdkRectangle m_get_monitor_geo()
+{
+ GdkRectangle r;
+ GdkDisplay *display = gdk_display_get_default();
+ GdkScreen *screen = gdk_display_get_default_screen(display);
+ gint mon_id = gdk_screen_get_primary_monitor(screen);
+
+ gdk_screen_get_monitor_geometry(screen, mon_id, &r);
+
+ return r;
+}
+
static void
gtk_combo_box_menu_position_over (GtkMenu *menu,
gint *x,
@@ -1938,6 +1953,13 @@ gtk_combo_box_menu_position_over (GtkMenu *menu,
menu_ypos -= child_allocation.height / 2;
}
+ gtk_widget_get_allocation(GTK_WIDGET(menu), &allocation);
+ GdkRectangle display_rect = m_get_monitor_geo();
+ if (display_rect.height - combo_box->priv->y_root < allocation.height) {
+ menu_ypos -= allocation.height;
+ }
+
children = GTK_MENU_SHELL
(combo_box->priv->popup_widget)->priv->children;
while (children)
{
@@ -3237,6 +3261,7 @@ gtk_combo_box_menu_button_press (GtkWidget
*widget,
!gtk_widget_has_focus (priv->button))
gtk_widget_grab_focus (priv->button);
+ priv->y_root = event->y_root;
gtk_combo_box_menu_popup (combo_box, event->button, event->time);
return TRUE;
What about ***unimplented*** part? menu_ypos minus popup menu`s
allocation height is not enough when popup menu ***active*** item is,
for example, last one not the first, then menu_ypos should be plus the
height of active item to the first one, sorry for my poor English ;P
--
Regards,
Leslie Zhai
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]