@@ -183,67 +183,6 @@ _gtk_get_monitor_num (GdkMonitor *monitor)
183183 return -1 ;
184184}
185185
186- /* the following function is adapted from gtkmenuitem.c */
187- static void
188- position_menu (GtkMenu * menu , gint * x , gint * y ,
189- gboolean * push_in , gpointer user_data )
190- {
191- GtkWidget * widget = GTK_WIDGET (user_data );
192- GdkScreen * screen ;
193- gint twidth , theight , tx , ty ;
194- GtkAllocation allocation ;
195- GtkRequisition requisition ;
196- GtkTextDirection direction ;
197- GdkRectangle monitor ;
198- GdkMonitor * monitor_num ;
199- GdkDisplay * display ;
200-
201- g_return_if_fail (menu != NULL );
202- g_return_if_fail (x != NULL );
203- g_return_if_fail (y != NULL );
204-
205- if (push_in ) * push_in = FALSE;
206-
207- direction = gtk_widget_get_direction (widget );
208-
209- gtk_widget_get_preferred_size (GTK_WIDGET (menu ), & requisition , NULL );
210- twidth = requisition .width ;
211- theight = requisition .height ;
212-
213- screen = gtk_widget_get_screen (GTK_WIDGET (menu ));
214- display = gdk_screen_get_display (screen );
215- monitor_num = gdk_display_get_monitor_at_window (display , gtk_widget_get_window (widget ));
216- if (monitor_num == NULL )
217- monitor_num = gdk_display_get_monitor (display , 0 );
218- gdk_monitor_get_geometry (monitor_num , & monitor );
219-
220- if (!gdk_window_get_origin (gtk_widget_get_window (widget ), & tx , & ty )) {
221- g_warning ("Menu not on screen" );
222- return ;
223- }
224-
225- gtk_widget_get_allocation (widget , & allocation );
226- tx += allocation .x ;
227- ty += allocation .y ;
228-
229- if (direction == GTK_TEXT_DIR_RTL )
230- tx += allocation .width - twidth ;
231-
232- if ((ty + allocation .height + theight ) <= monitor .y + monitor .height )
233- ty += allocation .height ;
234- else if ((ty - theight ) >= monitor .y )
235- ty -= theight ;
236- else if (monitor .y + monitor .height - (ty + allocation .height ) > ty )
237- ty += allocation .height ;
238- else
239- ty -= theight ;
240-
241- * x = CLAMP (tx , monitor .x , MAX (monitor .x , monitor .x + monitor .width - twidth ));
242- * y = ty ;
243-
244- gtk_menu_set_monitor (menu , _gtk_get_monitor_num (monitor_num ));
245- }
246-
247186static gboolean
248187drive_button_button_press (GtkWidget * widget ,
249188 GdkEventButton * event )
@@ -254,9 +193,11 @@ drive_button_button_press (GtkWidget *widget,
254193 if (event -> button == 1 ) {
255194 drive_button_ensure_popup (self );
256195 if (self -> popup_menu ) {
257- gtk_menu_popup (GTK_MENU (self -> popup_menu ), NULL , NULL ,
258- position_menu , self ,
259- event -> button , event -> time );
196+ gtk_menu_popup_at_widget (GTK_MENU (self -> popup_menu ),
197+ widget ,
198+ GDK_GRAVITY_SOUTH_WEST ,
199+ GDK_GRAVITY_NORTH_WEST ,
200+ (const GdkEvent * ) event );
260201 }
261202 return TRUE;
262203 }
@@ -276,9 +217,11 @@ drive_button_key_press (GtkWidget *widget,
276217 case GDK_KEY_Return :
277218 drive_button_ensure_popup (self );
278219 if (self -> popup_menu ) {
279- gtk_menu_popup (GTK_MENU (self -> popup_menu ), NULL , NULL ,
280- position_menu , self ,
281- 0 , event -> time );
220+ gtk_menu_popup_at_widget (GTK_MENU (self -> popup_menu ),
221+ widget ,
222+ GDK_GRAVITY_SOUTH_WEST ,
223+ GDK_GRAVITY_NORTH_WEST ,
224+ (const GdkEvent * ) event );
282225 }
283226 return TRUE;
284227 }
0 commit comments