@@ -835,90 +835,9 @@ container_has_focusable_child (GtkContainer *container)
835835 return retval ;
836836}
837837
838- static void
839- mate_panel_applet_position_menu (GtkMenu * menu ,
840- int * x ,
841- int * y ,
842- gboolean * push_in ,
843- GtkWidget * widget )
844- {
845- MatePanelApplet * applet ;
846- GtkAllocation allocation ;
847- GtkRequisition requisition ;
848- GdkDevice * device ;
849- GdkMonitor * monitor ;
850- GdkScreen * screen ;
851- int menu_x = 0 ;
852- int menu_y = 0 ;
853- int pointer_x ;
854- int pointer_y ;
855- GdkRectangle screen_geom ;
856-
857- g_return_if_fail (PANEL_IS_APPLET (widget ));
858-
859- applet = MATE_PANEL_APPLET (widget );
860-
861- monitor = gdk_display_get_monitor_at_window (gtk_widget_get_display (widget ), gtk_widget_get_window (widget ));
862- gdk_monitor_get_geometry (monitor , & screen_geom );
863-
864- screen = gtk_widget_get_screen (widget );
865- gtk_menu_set_screen (menu , screen );
866-
867- gtk_widget_get_preferred_size (GTK_WIDGET (menu ), & requisition , NULL );
868- gdk_window_get_origin (gtk_widget_get_window (widget ),
869- & menu_x , & menu_y );
870-
871- device = gdk_seat_get_pointer (gdk_display_get_default_seat (gtk_widget_get_display (widget )));
872- gdk_window_get_device_position (gtk_widget_get_window (widget ), device , & pointer_x , & pointer_y , NULL );
873-
874- gtk_widget_get_allocation (widget , & allocation );
875-
876- menu_x += allocation .x ;
877- menu_y += allocation .y ;
878-
879- if (applet -> priv -> orient == MATE_PANEL_APPLET_ORIENT_UP ||
880- applet -> priv -> orient == MATE_PANEL_APPLET_ORIENT_DOWN ) {
881- if (gtk_widget_get_direction (GTK_WIDGET (menu )) != GTK_TEXT_DIR_RTL ) {
882- if (pointer_x < allocation .width &&
883- requisition .width < pointer_x )
884- menu_x += MIN (pointer_x ,
885- allocation .width - requisition .width );
886- } else {
887- menu_x += allocation .width - requisition .width ;
888- if (pointer_x > 0 && pointer_x < allocation .width &&
889- pointer_x < allocation .width - requisition .width ) {
890- menu_x -= MIN (allocation .width - pointer_x ,
891- allocation .width - requisition .width );
892- }
893- }
894- menu_x = MIN (menu_x , screen_geom .width - requisition .width );
895-
896- if (menu_y > screen_geom .height / 2 )
897- menu_y -= requisition .height ;
898- else
899- menu_y += allocation .height ;
900- } else {
901- if (pointer_y < allocation .height &&
902- requisition .height < pointer_y )
903- menu_y += MIN (pointer_y , allocation .height - requisition .height );
904- menu_y = MIN (menu_y , screen_geom .height - requisition .height );
905-
906- if (menu_x > screen_geom .width / 2 )
907- menu_x -= requisition .width ;
908- else
909- menu_x += allocation .width ;
910-
911- }
912-
913- * x = menu_x ;
914- * y = menu_y ;
915- * push_in = FALSE;
916- }
917-
918838static void
919839mate_panel_applet_menu_popup (MatePanelApplet * applet ,
920- guint button ,
921- guint32 time )
840+ GdkEvent * event )
922841{
923842 GtkWidget * menu ;
924843
@@ -936,11 +855,11 @@ mate_panel_applet_menu_popup (MatePanelApplet *applet,
936855 context = gtk_widget_get_style_context (GTK_WIDGET (toplevel ));
937856 gtk_style_context_add_class (context ,"gnome-panel-menu-bar" );
938857 gtk_style_context_add_class (context ,"mate-panel-menu-bar" );
939- gtk_menu_popup (GTK_MENU (menu ),
940- NULL , NULL ,
941- ( GtkMenuPositionFunc ) mate_panel_applet_position_menu ,
942- applet ,
943- button , time );
858+ gtk_menu_popup_at_widget (GTK_MENU (menu ),
859+ GTK_WIDGET ( applet ) ,
860+ GDK_GRAVITY_NORTH_WEST ,
861+ GDK_GRAVITY_NORTH_WEST ,
862+ event );
944863}
945864
946865static gboolean
@@ -1049,7 +968,7 @@ mate_panel_applet_button_press (GtkWidget *widget,
1049968 }
1050969
1051970 if (event -> button == 3 ) {
1052- mate_panel_applet_menu_popup (applet , event -> button , event -> time );
971+ mate_panel_applet_menu_popup (applet , ( GdkEvent * ) event );
1053972
1054973 return TRUE;
1055974 }
@@ -1067,9 +986,10 @@ mate_panel_applet_button_release (GtkWidget *widget,
1067986}
1068987
1069988static gboolean
1070- mate_panel_applet_popup_menu (GtkWidget * widget )
989+ mate_panel_applet_key_press_event (GtkWidget * widget ,
990+ GdkEventKey * event )
1071991{
1072- mate_panel_applet_menu_popup (MATE_PANEL_APPLET (widget ), 3 , GDK_CURRENT_TIME );
992+ mate_panel_applet_menu_popup (MATE_PANEL_APPLET (widget ), ( GdkEvent * ) event );
1073993
1074994 return TRUE;
1075995}
@@ -1949,7 +1869,8 @@ mate_panel_applet_class_init (MatePanelAppletClass *klass)
19491869 widget_class -> size_allocate = mate_panel_applet_size_allocate ;
19501870 widget_class -> focus = mate_panel_applet_focus ;
19511871 widget_class -> realize = mate_panel_applet_realize ;
1952- widget_class -> popup_menu = mate_panel_applet_popup_menu ;
1872+ widget_class -> key_press_event = mate_panel_applet_key_press_event ;
1873+
19531874
19541875 gobject_class -> finalize = mate_panel_applet_finalize ;
19551876
@@ -2113,6 +2034,30 @@ GtkWidget* mate_panel_applet_new(void)
21132034 return GTK_WIDGET (applet );
21142035}
21152036
2037+ static GdkEvent *
2038+ button_press_event_new (MatePanelApplet * applet ,
2039+ guint button ,
2040+ guint time )
2041+ {
2042+ GdkDisplay * display ;
2043+ GdkSeat * seat ;
2044+ GdkDevice * device ;
2045+ GdkEvent * event ;
2046+
2047+ display = gdk_display_get_default ();
2048+ seat = gdk_display_get_default_seat (display );
2049+ device = gdk_seat_get_pointer (seat );
2050+
2051+ event = gdk_event_new (GDK_BUTTON_PRESS );
2052+
2053+ event -> button .time = time ;
2054+ event -> button .button = button ;
2055+
2056+ gdk_event_set_device (event , device );
2057+
2058+ return event ;
2059+ }
2060+
21162061static void
21172062method_call_cb (GDBusConnection * connection ,
21182063 const gchar * sender ,
@@ -2124,13 +2069,17 @@ method_call_cb (GDBusConnection *connection,
21242069 gpointer user_data )
21252070{
21262071 MatePanelApplet * applet = MATE_PANEL_APPLET (user_data );
2072+ GdkEvent * event ;
21272073
21282074 if (g_strcmp0 (method_name , "PopupMenu" ) == 0 ) {
21292075 guint button ;
21302076 guint time ;
21312077
21322078 g_variant_get (parameters , "(uu)" , & button , & time );
2133- mate_panel_applet_menu_popup (applet , button , time );
2079+
2080+ event = button_press_event_new (applet , button , time );
2081+ mate_panel_applet_menu_popup (applet , event );
2082+ gdk_event_free (event );
21342083
21352084 g_dbus_method_invocation_return_value (invocation , NULL );
21362085 }
0 commit comments