Index: windowlist.c =================================================================== --- windowlist.c (revision 26113) +++ windowlist.c (working copy) @@ -53,9 +53,13 @@ static gboolean windowlist_blink (gpointer data); -static GtkArrowType -windowlist_arrow_type (XfcePanelPlugin * plugin); +static void +windowlist_arrow_type_update (Windowlist * wl); +static void +windowlist_arrow_type_set (Windowlist * wl, + GtkArrowType arrow_type); + static gboolean windowlist_set_size (XfcePanelPlugin *plugin, int size, @@ -338,67 +342,6 @@ } /** - * Menu position function - **/ -static void -windowlist_position_menu (GtkMenu *menu, - int *x, - int *y, - gboolean * push_in, - Windowlist *wl) -{ - GtkWidget *widget; - GtkRequisition req; - GdkScreen *screen; - GdkRectangle geom; - int num; - - widget = GTK_WIDGET (wl->plugin); - - if (!GTK_WIDGET_REALIZED (GTK_WIDGET (menu))) - gtk_widget_realize (GTK_WIDGET (menu)); - - gtk_widget_size_request (GTK_WIDGET (menu), &req); - gdk_window_get_origin (widget->window, x, y); - - switch (wl->arrowtype) - { - case GTK_ARROW_UP: - *y += widget->allocation.y - req.height; - break; - case GTK_ARROW_DOWN: - *y += widget->allocation.y + widget->allocation.height; - break; - case GTK_ARROW_LEFT: - *x += widget->allocation.x - req.width; - *y += - req.height + widget->allocation.height; - break; - case GTK_ARROW_RIGHT: - *x += widget->allocation.x + widget->allocation.width; - *y += - req.height + widget->allocation.height; - break; - default: - break; - } - - screen = gtk_widget_get_screen (widget); - num = gdk_screen_get_monitor_at_window (screen, widget->window); - gdk_screen_get_monitor_geometry (screen, num, &geom); - - gtk_menu_set_screen (menu, screen); - - if (*x > geom.x + geom.width - req.width) - *x = geom.x + geom.width - req.width; - if (*x < geom.x) - *x = geom.x; - - if (*y > geom.y + geom.height - req.height) - *y = geom.y + geom.height - req.height; - if (*y < geom.y) - *y = geom.y; -} - -/** * Window List Menu functions **/ static GtkWidget * @@ -478,14 +421,13 @@ gint size, i, wscount; GList *windows, *li; PangoFontDescription *italic, *bold; + GtkArrowType arrow_type; /* Menu item styles */ italic = pango_font_description_from_string ("italic"); bold = pango_font_description_from_string ("bold"); menu = gtk_menu_new (); - xfce_panel_plugin_register_menu (XFCE_PANEL_PLUGIN (wl->plugin), - GTK_MENU (menu)); gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &size, NULL); @@ -687,11 +629,16 @@ gtk_widget_show_all (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, - at_pointer ? NULL - : (GtkMenuPositionFunc)windowlist_position_menu, - wl, 0, ev ? ev->time : GDK_CURRENT_TIME); - + if (!at_pointer) + { + gtk_menu_attach_to_widget (GTK_MENU (menu), + wl->button, NULL); + } + + arrow_type = xfce_panel_plugin_menu_popup (XFCE_PANEL_PLUGIN (wl->plugin), + GTK_MENU (menu)); + windowlist_arrow_type_set(wl, arrow_type); + return TRUE; } @@ -956,6 +903,20 @@ } /** + * When the arrow is about to be drawn, set its orientation + **/ +static void +windowlist_init_arrow (GtkWidget * button, + GdkEventExpose * event, + Windowlist * wl) +{ + windowlist_arrow_type_update (wl); + g_signal_handlers_disconnect_by_func (G_OBJECT (button), + G_CALLBACK (windowlist_init_arrow), + wl); +} + +/** * Build the panel button and connect signals and styles **/ void @@ -997,15 +958,16 @@ case ARROW_BUTTON: DBG ("Create Arrow Button"); - - wl->button = xfce_arrow_button_new (GTK_ARROW_UP); - xfce_arrow_button_set_arrow_type ( - XFCE_ARROW_BUTTON (wl->button), wl->arrowtype); + wl->arrowtype = GTK_ARROW_NONE; + wl->button = xfce_arrow_button_new (GTK_ARROW_NONE); break; } + g_signal_connect (G_OBJECT (wl->button), "expose-event", + G_CALLBACK (windowlist_init_arrow), wl); + /* Button layout */ GTK_WIDGET_UNSET_FLAGS (wl->button, GTK_CAN_DEFAULT|GTK_CAN_FOCUS); gtk_button_set_relief (GTK_BUTTON (wl->button), GTK_RELIEF_NONE); @@ -1035,72 +997,41 @@ /** * Arrow type functions **/ -static GtkArrowType -calculate_floating_arrow_type (XfcePanelPlugin * plugin, - XfceScreenPosition position) +static void +windowlist_arrow_type_update (Windowlist * wl) { - GtkWidget *widget = GTK_WIDGET (plugin); - GtkArrowType type = GTK_ARROW_UP; - int mon, x, y; - GdkScreen *screen; - GdkRectangle geom; + GtkArrowType type = GTK_ARROW_NONE; + + if (!GTK_IS_WIDGET (wl->button)) + return; - if (!GTK_WIDGET_REALIZED (widget)) - { - if (xfce_screen_position_is_horizontal (position)) - return GTK_ARROW_UP; - else - return GTK_ARROW_LEFT; - } + type = xfce_panel_plugin_popup_direction (XFCE_PANEL_PLUGIN (wl->plugin), + GTK_WIDGET (wl->button)); + if (type != GTK_ARROW_NONE) + windowlist_arrow_type_set (wl, type); +} - screen = gtk_widget_get_screen (widget); - mon = gdk_screen_get_monitor_at_window (screen, - widget->window); - gdk_screen_get_monitor_geometry (screen, mon, &geom); - gdk_window_get_root_origin (widget->window, &x, &y); - - if (xfce_screen_position_is_horizontal (position)) +static void +windowlist_arrow_type_set (Windowlist *wl, GtkArrowType new_arrow_type) +{ + g_return_if_fail (wl->button != NULL); + + if (new_arrow_type == GTK_ARROW_NONE || new_arrow_type == wl->arrowtype) + return; + + wl->arrowtype = new_arrow_type; + + if (wl->layout == ARROW_BUTTON) { - if (y > geom.y + geom.height / 2) - type = GTK_ARROW_UP; - else - type = GTK_ARROW_DOWN; - } - else - { - if (x > geom.x + geom.width / 2) - type = GTK_ARROW_LEFT; - else - type = GTK_ARROW_RIGHT; - } + xfce_arrow_button_set_arrow_type (XFCE_ARROW_BUTTON (wl->button), + wl->arrowtype); - return type; + windowlist_set_size (wl->plugin, + xfce_panel_plugin_get_size (wl->plugin), + wl); + } } -static GtkArrowType -windowlist_arrow_type (XfcePanelPlugin * plugin) -{ - GtkArrowType type = GTK_ARROW_UP; - XfceScreenPosition position = xfce_panel_plugin_get_screen_position (plugin); - - if (xfce_screen_position_is_floating (position)) - type = calculate_floating_arrow_type (plugin, position); - - else if (xfce_screen_position_is_top (position)) - type = GTK_ARROW_DOWN; - - else if (xfce_screen_position_is_left (position)) - type = GTK_ARROW_RIGHT; - - else if (xfce_screen_position_is_right (position)) - type = GTK_ARROW_LEFT; - - else if (xfce_screen_position_is_bottom (position)) - type = GTK_ARROW_UP; - - return type; -} - /** * Read and write user settings **/ @@ -1256,15 +1187,14 @@ /* Read user settings */ windowlist_read (wl); - /* Read arrow type, this is also used for the popup function */ - wl->arrowtype = windowlist_arrow_type (wl->plugin); - /* Build the panel button */ + windowlist_create_button (wl); return wl; } + /** * Common plugin functions **/ @@ -1283,16 +1213,14 @@ break; case ARROW_BUTTON: - switch (wl->arrowtype) + switch (xfce_panel_plugin_get_orientation (wl->plugin)) { - case GTK_ARROW_LEFT: - case GTK_ARROW_RIGHT: + case GTK_ORIENTATION_VERTICAL: gtk_widget_set_size_request (GTK_WIDGET (wl->button), size, ARROW_WIDTH); break; - case GTK_ARROW_UP: - case GTK_ARROW_DOWN: + case GTK_ORIENTATION_HORIZONTAL: gtk_widget_set_size_request (GTK_WIDGET (wl->button), ARROW_WIDTH, size); break; @@ -1300,6 +1228,7 @@ break; } break; + } return TRUE; @@ -1344,11 +1273,8 @@ { DBG ("..."); - wl->arrowtype = windowlist_arrow_type (plugin); - - if (wl->layout == ARROW_BUTTON) - xfce_arrow_button_set_arrow_type ( - XFCE_ARROW_BUTTON (wl->button), wl->arrowtype); + windowlist_arrow_type_update (wl); + } static void @@ -1358,11 +1284,7 @@ { DBG ("..."); - wl->arrowtype = windowlist_arrow_type (plugin); - - if (wl->layout == ARROW_BUTTON) - xfce_arrow_button_set_arrow_type ( - XFCE_ARROW_BUTTON (wl->button), wl->arrowtype); + windowlist_arrow_type_update (wl); } /**