Commit b5fb9ae3 authored by Matthias Clasen's avatar Matthias Clasen

gtk: Port to new monitor api

Use the GdkDisplay monitor api instead of the GdkScreen one.
parent 1b7d7c85
......@@ -1934,9 +1934,9 @@ gtk_combo_box_menu_position_below (GtkMenu *menu,
gint sx, sy;
GtkWidget *child;
GtkRequisition req;
GdkScreen *screen;
gint monitor_num;
GdkRectangle monitor;
GdkDisplay *display;
GdkMonitor *monitor;
GdkRectangle area;
/* FIXME: is using the size request here broken? */
child = gtk_bin_get_child (GTK_BIN (combo_box));
......@@ -1953,8 +1953,7 @@ gtk_combo_box_menu_position_below (GtkMenu *menu,
sy += child_allocation.y;
}
gdk_window_get_root_coords (gtk_widget_get_window (child),
sx, sy, &sx, &sy);
gdk_window_get_root_coords (gtk_widget_get_window (child), sx, sy, &sx, &sy);
if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_RTL)
sx += (content_allocation.x - border_allocation.x);
......@@ -1972,21 +1971,20 @@ gtk_combo_box_menu_position_below (GtkMenu *menu,
*x = sx + child_allocation.width - req.width;
*y = sy;
screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
monitor_num = gdk_screen_get_monitor_at_window (screen,
gtk_widget_get_window (GTK_WIDGET (combo_box)));
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (GTK_WIDGET (combo_box));
monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (GTK_WIDGET (combo_box)));
gdk_monitor_get_workarea (monitor, &area);
if (*x < monitor.x)
*x = monitor.x;
else if (*x + req.width > monitor.x + monitor.width)
*x = monitor.x + monitor.width - req.width;
if (*x < area.x)
*x = area.x;
else if (*x + req.width > area.x + area.width)
*x = area.x + area.width - req.width;
if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
if (area.y + area.height - *y - child_allocation.height >= req.height)
*y += child_allocation.height;
else if (*y - monitor.y >= req.height)
else if (*y - area.y >= req.height)
*y -= req.height;
else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
else if (area.y + area.height - *y - child_allocation.height > *y - area.y)
*y += child_allocation.height;
else
*y -= req.height;
......@@ -2109,9 +2107,9 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
{
GtkComboBoxPrivate *priv = combo_box->priv;
GtkAllocation content_allocation;
GdkScreen *screen;
gint monitor_num;
GdkRectangle monitor;
GdkDisplay *display;
GdkMonitor *monitor;
GdkRectangle area;
GtkRequisition popup_req;
GtkPolicyType hpolicy, vpolicy;
GdkWindow *window;
......@@ -2162,31 +2160,31 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
*height = popup_req.height;
screen = gtk_widget_get_screen (widget);
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (widget);
monitor = gdk_display_get_monitor_at_window (display, window);
gdk_monitor_get_workarea (monitor, &area);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
*x = *x + content_allocation.width - *width;
if (*x < monitor.x)
*x = monitor.x;
else if (*x + *width > monitor.x + monitor.width)
*x = monitor.x + monitor.width - *width;
if (*x < area.x)
*x = area.x;
else if (*x + *width > area.x + area.width)
*x = area.x + area.width - *width;
if (*y + content_allocation.height + *height <= monitor.y + monitor.height)
if (*y + content_allocation.height + *height <= area.y + area.height)
*y += content_allocation.height;
else if (*y - *height >= monitor.y)
else if (*y - *height >= area.y)
*y -= *height;
else if (monitor.y + monitor.height - (*y + content_allocation.height) > *y - monitor.y)
else if (area.y + area.height - (*y + content_allocation.height) > *y - area.y)
{
*y += content_allocation.height;
*height = monitor.y + monitor.height - *y;
*height = area.y + area.height - *y;
}
else
{
*height = *y - monitor.y;
*y = monitor.y;
*height = *y - area.y;
*y = area.y;
}
if (popup_req.height > *height)
......
......@@ -9417,24 +9417,21 @@ popup_position_func (GtkMenu *menu,
GtkEntry *entry = GTK_ENTRY (user_data);
GtkEntryPrivate *priv = entry->priv;
GtkWidget *widget = GTK_WIDGET (entry);
GdkScreen *screen;
GdkDisplay *display;
GtkRequisition menu_req;
GdkRectangle monitor;
gint monitor_num, strong_x, height;
GdkMonitor *monitor;
GdkRectangle area;
gint strong_x, height;
g_return_if_fail (gtk_widget_get_realized (widget));
gdk_window_get_origin (priv->text_area, x, y);
screen = gtk_widget_get_screen (widget);
monitor_num = gdk_screen_get_monitor_at_window (screen, priv->text_area);
if (monitor_num < 0)
monitor_num = 0;
gtk_menu_set_monitor (menu, monitor_num);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
gtk_widget_get_preferred_size (priv->popup_menu,
&menu_req, NULL);
display = gtk_widget_get_display (widget);
monitor = gdk_display_get_monitor_at_window (display, priv->text_area);
gtk_menu_place_on_monitor (menu, monitor);
gdk_monitor_get_workarea (monitor, &area);
gtk_widget_get_preferred_size (priv->popup_menu, &menu_req, NULL);
height = gdk_window_get_height (priv->text_area);
gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
......@@ -9442,11 +9439,11 @@ popup_position_func (GtkMenu *menu,
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
*x -= menu_req.width;
if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
if ((*y + height + menu_req.height) <= area.y + area.height)
*y += height;
else if ((*y - menu_req.height) >= monitor.y)
else if ((*y - menu_req.height) >= area.y)
*y -= menu_req.height;
else if (monitor.y + monitor.height - (*y + height) > *y)
else if (area.y + area.height - (*y + height) > *y)
*y += height;
else
*y -= menu_req.height;
......
......@@ -1494,10 +1494,10 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
GtkAllocation allocation;
gint x, y;
gint matches, actions, items, height;
GdkScreen *screen;
gint monitor_num;
GdkDisplay *display;
GdkMonitor *monitor;
gint vertical_separator;
GdkRectangle monitor;
GdkRectangle area;
GdkWindow *window;
GtkRequisition popup_req;
GtkRequisition entry_req;
......@@ -1546,16 +1546,16 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
gtk_widget_realize (completion->priv->tree_view);
screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (GTK_WIDGET (completion->priv->entry));
monitor = gdk_display_get_monitor_at_window (display, window);
gdk_monitor_get_workarea (monitor, &area);
if (height == 0)
items = 0;
else if (y > monitor.height / 2)
items = MIN (matches, (((monitor.y + y) - (actions * action_height)) / height) - 1);
else if (y > area.height / 2)
items = MIN (matches, (((area.y + y) - (actions * action_height)) / height) - 1);
else
items = MIN (matches, (((monitor.height - y) - (actions * action_height)) / height) - 1);
items = MIN (matches, (((area.height - y) - (actions * action_height)) / height) - 1);
if (items <= 0)
gtk_widget_hide (completion->priv->scrolled_window);
......@@ -1563,7 +1563,7 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
gtk_widget_show (completion->priv->scrolled_window);
if (completion->priv->popup_set_width)
width = MIN (allocation.width, monitor.width);
width = MIN (allocation.width, area.width);
else
width = -1;
......@@ -1580,13 +1580,13 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
gtk_widget_get_preferred_size (completion->priv->popup_window,
&popup_req, NULL);
if (x < monitor.x)
x = monitor.x;
else if (x + popup_req.width > monitor.x + monitor.width)
x = monitor.x + monitor.width - popup_req.width;
if (x < area.x)
x = area.x;
else if (x + popup_req.width > area.x + area.width)
x = area.x + area.width - popup_req.width;
if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
if (y + entry_req.height + popup_req.height <= area.y + area.height ||
y - area.y < (area.y + area.height) - (y + entry_req.height))
{
y += entry_req.height;
above = FALSE;
......
......@@ -346,11 +346,11 @@ popup_position_func (GtkMenu *menu,
GtkLinkButtonPrivate *priv = link_button->priv;
GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (link_button);
GdkScreen *screen = gtk_widget_get_screen (widget);
GdkDisplay *display;
GdkMonitor *monitor;
GtkRequisition req;
gint monitor_num;
GdkRectangle monitor;
GdkRectangle area;
g_return_if_fail (gtk_widget_get_realized (widget));
gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
......@@ -361,12 +361,13 @@ popup_position_func (GtkMenu *menu,
*x += allocation.width / 2;
*y += allocation.height;
monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
gtk_menu_set_monitor (menu, monitor_num);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (widget);
monitor = gdk_display_get_monitor_at_point (display, *x, *y);
gtk_menu_place_on_monitor (menu, monitor);
gdk_monitor_get_workarea (monitor, &area);
*x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
*y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
*x = CLAMP (*x, area.x, area.x + MAX (0, area.width - req.width));
*y = CLAMP (*y, area.y, area.y + MAX (0, area.height - req.height));
*push_in = FALSE;
}
......
......@@ -251,9 +251,9 @@ menu_position_up_down_func (GtkMenu *menu,
GtkWidget *widget = GTK_WIDGET (menu_button);
GtkWidget *toplevel;
GtkTextDirection direction;
GdkRectangle monitor;
gint monitor_num;
GdkScreen *screen;
GdkRectangle workarea;
GdkDisplay *display;
GdkMonitor *monitor;
GdkWindow *window;
GtkAllocation menu_allocation, allocation, arrow_allocation;
GtkAlign align;
......@@ -272,11 +272,9 @@ menu_position_up_down_func (GtkMenu *menu,
direction = gtk_widget_get_direction (widget);
window = gtk_widget_get_window (priv->align_widget ? priv->align_widget : widget);
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (GTK_WIDGET (menu));
monitor = gdk_display_get_monitor_at_window (display, window);
gdk_monitor_get_workarea (monitor, &workarea);
gtk_widget_get_allocation (priv->align_widget ? priv->align_widget : widget, &allocation);
gtk_widget_get_allocation (widget, &arrow_allocation);
......@@ -298,17 +296,17 @@ menu_position_up_down_func (GtkMenu *menu,
else if (menu_allocation.width > allocation.width)
*x -= menu_allocation.width - allocation.width;
if (priv->arrow_type == GTK_ARROW_UP && *y - menu_allocation.height >= monitor.y)
if (priv->arrow_type == GTK_ARROW_UP && *y - menu_allocation.height >= workarea.y)
{
*y -= menu_allocation.height;
}
else
{
if ((*y + arrow_allocation.height + menu_allocation.height) <= monitor.y + monitor.height)
if ((*y + arrow_allocation.height + menu_allocation.height) <= workarea.y + workarea.height)
*y += arrow_allocation.height;
else if ((*y - menu_allocation.height) >= monitor.y)
else if ((*y - menu_allocation.height) >= workarea.y)
*y -= menu_allocation.height;
else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
else if (workarea.y + workarea.height - (*y + arrow_allocation.height) > *y)
*y += arrow_allocation.height;
else
*y -= menu_allocation.height;
......@@ -328,9 +326,9 @@ menu_position_side_func (GtkMenu *menu,
GtkAllocation allocation;
GtkAllocation menu_allocation;
GtkWidget *widget = GTK_WIDGET (menu_button);
GdkRectangle monitor;
gint monitor_num;
GdkScreen *screen;
GdkDisplay *display;
GdkMonitor *monitor;
GdkRectangle workarea;
GdkWindow *window;
GtkAlign align;
GtkTextDirection direction;
......@@ -339,11 +337,9 @@ menu_position_side_func (GtkMenu *menu,
direction = gtk_widget_get_direction (widget);
align = gtk_widget_get_valign (GTK_WIDGET (menu));
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (GTK_WIDGET (menu));
monitor = gdk_display_get_monitor_at_window (display, window);
gdk_monitor_get_workarea (monitor, &workarea);
gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (menu_button)), x, y);
......@@ -354,14 +350,14 @@ menu_position_side_func (GtkMenu *menu,
(priv->arrow_type == GTK_ARROW_LEFT && direction == GTK_TEXT_DIR_RTL))
{
if (*x + allocation.width + menu_allocation.width <= monitor.x + monitor.width)
if (*x + allocation.width + menu_allocation.width <= workarea.x + workarea.width)
*x += allocation.width;
else
*x -= menu_allocation.width;
}
else
{
if (*x - menu_allocation.width >= monitor.x)
if (*x - menu_allocation.width >= workarea.x)
*x -= menu_allocation.width;
else
*x += allocation.width;
......
......@@ -2102,12 +2102,12 @@ gtk_menu_item_position_menu (GtkMenu *menu,
GtkWidget *widget;
GtkMenuItem *parent_menu_item;
GtkWidget *parent;
GdkScreen *screen;
GdkDisplay *display;
gint twidth, theight;
gint tx, ty;
GtkTextDirection direction;
GdkRectangle monitor;
gint monitor_num;
GdkMonitor *monitor;
GdkRectangle workarea;
gint horizontal_offset;
gint vertical_offset;
gint available_left, available_right;
......@@ -2128,11 +2128,9 @@ gtk_menu_item_position_menu (GtkMenu *menu,
twidth = gtk_widget_get_allocated_width (GTK_WIDGET (menu));
theight = gtk_widget_get_allocated_height (GTK_WIDGET (menu));
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
monitor_num = gdk_screen_get_monitor_at_window (screen, priv->event_window);
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (GTK_WIDGET (menu));
monitor = gdk_display_get_monitor_at_window (display, priv->event_window);
gdk_monitor_get_workarea (monitor, &workarea);
if (!gdk_window_get_origin (gtk_widget_get_window (widget), &tx, &ty))
{
......@@ -2147,8 +2145,8 @@ gtk_menu_item_position_menu (GtkMenu *menu,
get_offsets (menu, &horizontal_offset, &vertical_offset);
available_left = tx - monitor.x;
available_right = monitor.x + monitor.width - (tx + allocation.width);
available_left = tx - workarea.x;
available_right = workarea.x + workarea.width - (tx + allocation.width);
parent = gtk_widget_get_parent (widget);
priv->from_menubar = GTK_IS_MENU_BAR (parent);
......@@ -2163,11 +2161,11 @@ gtk_menu_item_position_menu (GtkMenu *menu,
priv->submenu_direction = GTK_DIRECTION_LEFT;
tx += allocation.width - twidth;
}
if ((ty + allocation.height + theight) <= monitor.y + monitor.height)
if ((ty + allocation.height + theight) <= workarea.y + workarea.height)
ty += allocation.height;
else if ((ty - theight) >= monitor.y)
else if ((ty - theight) >= workarea.y)
ty -= theight;
else if (monitor.y + monitor.height - (ty + allocation.height) > ty)
else if (workarea.y + workarea.height - (ty + allocation.height) > ty)
ty += allocation.height;
else
ty -= theight;
......@@ -2197,7 +2195,7 @@ gtk_menu_item_position_menu (GtkMenu *menu,
switch (priv->submenu_direction)
{
case GTK_DIRECTION_LEFT:
if (tx - twidth - parent_padding.left - horizontal_offset >= monitor.x ||
if (tx - twidth - parent_padding.left - horizontal_offset >= workarea.x ||
available_left >= available_right)
tx -= twidth + parent_padding.left + horizontal_offset;
else
......@@ -2208,7 +2206,7 @@ gtk_menu_item_position_menu (GtkMenu *menu,
break;
case GTK_DIRECTION_RIGHT:
if (tx + allocation.width + parent_padding.right + horizontal_offset + twidth <= monitor.x + monitor.width ||
if (tx + allocation.width + parent_padding.right + horizontal_offset + twidth <= workarea.x + workarea.width ||
available_right >= available_left)
tx += allocation.width + parent_padding.right + horizontal_offset;
else
......@@ -2222,17 +2220,17 @@ gtk_menu_item_position_menu (GtkMenu *menu,
ty += vertical_offset;
/* If the height of the menu doesn't fit we move it upward. */
ty = CLAMP (ty, monitor.y, MAX (monitor.y, monitor.y + monitor.height - theight));
ty = CLAMP (ty, workarea.y, MAX (workarea.y, workarea.y + workarea.height - theight));
break;
}
/* If we have negative, tx, here it is because we can't get
* the menu all the way on screen. Favor the left portion.
*/
*x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth));
*x = CLAMP (tx, workarea.x, MAX (workarea.x, workarea.x + workarea.width - twidth));
*y = ty;
gtk_menu_set_monitor (menu, monitor_num);
gtk_menu_place_on_monitor (menu, monitor);
if (!gtk_widget_get_visible (menu->priv->toplevel))
{
......
......@@ -873,10 +873,10 @@ set_default_size (GtkRecentChooserDefault *impl)
GtkWidget *widget;
gint width, height;
double font_size;
GdkScreen *screen;
gint monitor_num;
GdkDisplay *display;
GdkMonitor *monitor;
GtkRequisition req;
GdkRectangle monitor;
GdkRectangle workarea;
GtkStyleContext *context;
widget = GTK_WIDGET (impl);
......@@ -894,14 +894,12 @@ set_default_size (GtkRecentChooserDefault *impl)
height = MAX (height, req.height);
/* ... but no larger than the monitor */
screen = gtk_widget_get_screen (widget);
monitor_num = gdk_screen_get_monitor_at_window (screen,
gtk_widget_get_window (widget));
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (widget);
monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (widget));
gdk_monitor_get_workarea (monitor, &workarea);
width = MIN (width, monitor.width * 3 / 4);
height = MIN (height, monitor.height * 3 / 4);
width = MIN (width, workarea.width * 3 / 4);
height = MIN (height, workarea.height * 3 / 4);
/* Set size */
scrollw = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (impl->priv->recent_view));
......@@ -1739,30 +1737,29 @@ popup_position_func (GtkMenu *menu,
{
GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (user_data);
GdkScreen *screen = gtk_widget_get_screen (widget);
GtkRequisition req;
gint monitor_num;
GdkRectangle monitor;
GdkDisplay *display;
GdkMonitor *monitor;
GdkRectangle workarea;
if (G_UNLIKELY (!gtk_widget_get_realized (widget)))
return;
gdk_window_get_origin (gtk_widget_get_window (widget),
x, y);
gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
gtk_widget_get_preferred_size (GTK_WIDGET (menu),
&req, NULL);
gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
gtk_widget_get_allocation (widget, &allocation);
*x += (allocation.width - req.width) / 2;
*y += (allocation.height - req.height) / 2;
monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
gtk_menu_set_monitor (menu, monitor_num);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (widget);
monitor = gdk_display_get_monitor_at_point (display, *x, *y);
gtk_menu_place_on_monitor (menu, monitor);
gdk_monitor_get_workarea (monitor, &workarea);
*x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
*y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
*x = CLAMP (*x, workarea.x, workarea.x + MAX (0, workarea.width - req.width));
*y = CLAMP (*y, workarea.y, workarea.y + MAX (0, workarea.height - req.height));
*push_in = FALSE;
}
......
......@@ -9356,17 +9356,17 @@ popup_position_func (GtkMenu *menu,
GdkRectangle onscreen_rect;
gint root_x, root_y;
GtkTextIter iter;
GtkRequisition req;
GdkScreen *screen;
gint monitor_num;
GdkRectangle monitor;
GtkRequisition req;
GdkDisplay *display;
GdkMonitor *monitor;
GdkRectangle workarea;
text_view = GTK_TEXT_VIEW (user_data);
widget = GTK_WIDGET (text_view);
g_return_if_fail (gtk_widget_get_realized (widget));
screen = gtk_widget_get_screen (widget);
display = gtk_widget_get_display (widget);
gdk_window_get_origin (gtk_widget_get_window (widget),
&root_x, &root_y);
......@@ -9391,7 +9391,7 @@ popup_position_func (GtkMenu *menu,
cursor_rect.x < onscreen_rect.x + onscreen_rect.width &&
cursor_rect.y >= onscreen_rect.y &&
cursor_rect.y < onscreen_rect.y + onscreen_rect.height)
{
{
gtk_text_view_buffer_to_window_coords (text_view,
GTK_TEXT_WINDOW_WIDGET,
cursor_rect.x, cursor_rect.y,
......@@ -9411,12 +9411,12 @@ popup_position_func (GtkMenu *menu,
*x = CLAMP (*x, root_x, (root_x + allocation.width));
*y = CLAMP (*y, root_y, (root_y + allocation.height));
monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
gtk_menu_set_monitor (menu, monitor_num);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
monitor = gdk_display_get_monitor_at_point (display, *x, *y);
gtk_menu_place_on_monitor (menu, monitor);
gdk_monitor_get_workarea (monitor, &workarea);
*x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
*y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
*x = CLAMP (*x, workarea.x, workarea.x + MAX (0, workarea.width - req.width));
*y = CLAMP (*y, workarea.y, workarea.y + MAX (0, workarea.height - req.height));
*push_in = FALSE;
}
......
......@@ -2629,50 +2629,48 @@ menu_position_func (GtkMenu *menu,
GtkToolbarPrivate *priv = toolbar->priv;
GtkRequisition req;
GtkRequisition menu_req;
GdkRectangle monitor;
gint monitor_num;
GdkScreen *screen;
GdkRectangle workarea;
GdkMonitor *monitor;
GdkDisplay *display;
gtk_widget_get_preferred_size (priv->arrow_button,
&req, NULL);
gtk_widget_get_preferred_size (GTK_WIDGET (menu),
&menu_req, NULL);
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
monitor_num = gdk_screen_get_monitor_at_window (screen,
gtk_widget_get_window (priv->arrow_button));
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
display = gtk_widget_get_display (GTK_WIDGET (menu));
monitor = gdk_display_get_monitor_at_window (display,
gtk_widget_get_window (priv->arrow_button));
gdk_monitor_get_workarea (monitor, &workarea);
gtk_widget_get_allocation (priv->arrow_button, &allocation);
gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (priv->arrow_button)), x, y);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
*x += allocation.width - req.width;
else
else
*x += req.width - menu_req.width;
if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
if ((*y + allocation.height + menu_req.height) <= workarea.y + workarea.height)
*y += allocation.height;
else if ((*y - menu_req.height) >= monitor.y)
else if ((*y - menu_req.height) >= workarea.y)
*y -= menu_req.height;
else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
else if (workarea.y + workarea.height - (*y + allocation.height) > *y)
*y += allocation.height;
else
*y -= menu_req.height;
}
else
else
{
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
*x += allocation.width;
else
else
*x -= menu_req.width;
if (*y + menu_req.height > monitor.y + monitor.height &&
*y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
if (*y + menu_req.height > workarea.y + workarea.height &&
*y + allocation.height - workarea.y > workarea.y + workarea.height - *y)
*y += allocation.height - menu_req.height;
}
......
......@@ -895,9 +895,8 @@ gtk_tooltip_position (GtkTooltip *tooltip,
GtkWidget *new_tooltip_widget)
{
gint x, y, width, height;
GdkScreen *screen;
gint monitor_num;
GdkRectangle monitor;
GdkMonitor *monitor;
GdkRectangle workarea;
guint cursor_size;
GdkRectangle bounds;
GtkBorder border;
......@@ -909,17 +908,13 @@ gtk_tooltip_position (GtkTooltip *tooltip,
tooltip->tooltip_widget = new_tooltip_widget;
screen = gtk_widget_get_screen (new_tooltip_widget);
_gtk_window_get_shadow_width (GTK_WINDOW (tooltip->current_window), &border);
width = gtk_widget_get_allocated_width (GTK_WIDGET (tooltip->current_window)) - border.left - border.right;
height = gtk_widget_get_allocated_height (GTK_WIDGET (tooltip->current_window)) - border.top - border.bottom;
monitor_num = gdk_screen_get_monitor_at_point (screen,
tooltip->last_x,
tooltip->last_y);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
monitor = gdk_display_get_monitor_at_point (display, tooltip->last_x, tooltip->last_y);
gdk_monitor_get_workarea (monitor, &workarea);
get_bounding_box (new_tooltip_widget, &bounds);
......@@ -931,7 +926,7 @@ gtk_tooltip_position (GtkTooltip *tooltip,
x = bounds.x + bounds.width / 2 - width / 2;
y = bounds.y + bounds.height + 4;
if (y + height <= monitor.y + monitor.height)
if (y + height <= workarea<