gtk: Port to new monitor api

Use the GdkDisplay monitor api instead of the GdkScreen one.
This commit is contained in:
Matthias Clasen 2016-04-10 23:01:10 -04:00
parent 1b7d7c857f
commit b5fb9ae3b7
13 changed files with 223 additions and 275 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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))
{

View File

@ -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));
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);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.y + workarea.height)
{
if (tooltip->keyboard_mode_enabled)
goto found;
@ -951,7 +946,7 @@ gtk_tooltip_position (GtkTooltip *tooltip,
x = bounds.x + bounds.width / 2 - width / 2;
y = bounds.y - height - 4;
if (y >= monitor.y)
if (y >= workarea.y)
{
if (tooltip->keyboard_mode_enabled)
goto found;
@ -971,7 +966,7 @@ gtk_tooltip_position (GtkTooltip *tooltip,
x = bounds.x + bounds.width + 4;
y = bounds.y + bounds.height / 2 - height / 2;
if (x + width <= monitor.x + monitor.width)
if (x + width <= workarea.x + workarea.width)
{
if (tooltip->keyboard_mode_enabled)
goto found;
@ -991,7 +986,7 @@ gtk_tooltip_position (GtkTooltip *tooltip,
x = bounds.x - width - 4;
y = bounds.y + bounds.height / 2 - height / 2;
if (x >= monitor.x)
if (x >= workarea.x)
{
if (tooltip->keyboard_mode_enabled)
goto found;
@ -1022,15 +1017,15 @@ gtk_tooltip_position (GtkTooltip *tooltip,
found:
/* Show it */
if (x + width > monitor.x + monitor.width)
x -= x - (monitor.x + monitor.width) + width;
else if (x < monitor.x)
x = monitor.x;
if (x + width > workarea.x + workarea.width)
x -= x - (workarea.x + workarea.width) + width;
else if (x < workarea.x)
x = workarea.x;
if (y + height > monitor.y + monitor.height)
y -= y - (monitor.y + monitor.height) + height;
else if (y < monitor.y)
y = monitor.y;
if (y + height > workarea.y + workarea.height)
y -= y - (workarea.y + workarea.height) + height;
else if (y < workarea.y)
y = workarea.y;
if (!tooltip->keyboard_mode_enabled)
{

View File

@ -15066,14 +15066,9 @@ gtk_tree_view_search_position_func (GtkTreeView *tree_view,
gint x, y;
gint tree_x, tree_y;
gint tree_width, tree_height;
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
GdkScreen *screen = gdk_window_get_screen (tree_window);
GtkRequisition requisition;
gint monitor_num;
GdkRectangle monitor;
monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
gtk_widget_realize (search_window);

View File

@ -10826,7 +10826,8 @@ gint
gtk_widget_get_scale_factor (GtkWidget *widget)
{
GtkWidget *toplevel;
GdkScreen *screen;
GdkDisplay *display;
GdkMonitor *monitor;
g_return_val_if_fail (GTK_IS_WIDGET (widget), 1);
@ -10840,11 +10841,10 @@ gtk_widget_get_scale_factor (GtkWidget *widget)
/* else fall back to something that is more likely to be right than
* just returning 1:
*/
screen = gtk_widget_get_screen (widget);
if (screen)
return gdk_screen_get_monitor_scale_factor (screen, 0);
display = gtk_widget_get_display (widget);
monitor = gdk_display_get_monitor (display, 0);
return 1;
return gdk_monitor_get_scale_factor (monitor);
}
/**

View File

@ -183,6 +183,7 @@ struct _GtkWindowPrivate
GtkWindowGeometryInfo *geometry_info;
GtkWindowGroup *group;
GdkScreen *screen;
GdkDisplay *display;
GtkApplication *application;
GList *popovers;
@ -6402,28 +6403,22 @@ gtk_window_guess_default_size (GtkWindow *window,
gint *height)
{
GtkWidget *widget;
GdkScreen *screen;
GdkDisplay *display;
GdkWindow *gdkwindow;
GdkMonitor *monitor;
GdkRectangle workarea;
int minimum, natural;
widget = GTK_WIDGET (window);
screen = _gtk_window_get_screen (window);
display = gdk_screen_get_display (_gtk_window_get_screen (window));
gdkwindow = _gtk_widget_get_window (widget);
if (gdkwindow)
{
gdk_screen_get_monitor_workarea (screen,
gdk_screen_get_monitor_at_window (screen, gdkwindow),
&workarea);
}
monitor = gdk_display_get_monitor_at_window (display, gdkwindow);
else
{
/* XXX: Figure out what screen we appear on */
gdk_screen_get_monitor_workarea (screen,
0,
&workarea);
}
monitor = gdk_display_get_monitor (display, 0);
gdk_monitor_get_workarea (monitor, &workarea);
*width = workarea.width;
*height = workarea.height;
@ -9200,40 +9195,31 @@ get_effective_position (GtkWindow *window)
return pos;
}
static int
static GdkMonitor *
get_center_monitor_of_window (GtkWindow *window)
{
GdkDisplay *display;
/* We could try to sort out the relative positions of the monitors and
* stuff, or we could just be losers and assume you have a row
* or column of monitors.
*/
return gdk_screen_get_n_monitors (gtk_window_check_screen (window)) / 2;
display = gdk_screen_get_display (gtk_window_check_screen (window));
return gdk_display_get_monitor (display, gdk_display_get_n_monitors (display) / 2);
}
static int
static GdkMonitor *
get_monitor_containing_pointer (GtkWindow *window)
{
gint px, py;
gint monitor_num;
GdkScreen *window_screen;
GdkScreen *pointer_screen;
GdkDisplay *display;
GdkDevice *pointer;
window_screen = gtk_window_check_screen (window);
display = gdk_screen_get_display (window_screen);
display = gdk_screen_get_display (gtk_window_check_screen (window));
pointer = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
gdk_device_get_position (pointer, NULL, &px, &py);
gdk_device_get_position (pointer,
&pointer_screen,
&px, &py);
if (pointer_screen == window_screen)
monitor_num = gdk_screen_get_monitor_at_point (pointer_screen, px, py);
else
monitor_num = -1;
return monitor_num;
return gdk_display_get_monitor_at_point (display, px, py);
}
static void
@ -9243,27 +9229,26 @@ center_window_on_monitor (GtkWindow *window,
gint *x,
gint *y)
{
GdkRectangle monitor;
int monitor_num;
GdkRectangle area;
GdkMonitor *monitor;
monitor_num = get_monitor_containing_pointer (window);
monitor = get_monitor_containing_pointer (window);
if (monitor_num == -1)
monitor_num = get_center_monitor_of_window (window);
if (monitor == NULL)
monitor = get_center_monitor_of_window (window);
gdk_screen_get_monitor_workarea (gtk_window_check_screen (window),
monitor_num, &monitor);
gdk_monitor_get_workarea (monitor, &area);
*x = (monitor.width - w) / 2 + monitor.x;
*y = (monitor.height - h) / 2 + monitor.y;
*x = (area.width - w) / 2 + area.x;
*y = (area.height - h) / 2 + area.y;
/* Be sure we aren't off the monitor, ignoring _NET_WM_STRUT
* and WM decorations.
*/
if (*x < monitor.x)
*x = monitor.x;
if (*y < monitor.y)
*y = monitor.y;
if (*x < area.x)
*x = area.x;
if (*y < area.y)
*y = area.y;
}
static void
@ -9364,24 +9349,20 @@ gtk_window_compute_configure_request (GtkWindow *window,
case GTK_WIN_POS_CENTER_ON_PARENT:
{
GdkDisplay *display;
GtkAllocation allocation;
GdkWindow *gdk_window;
gint monitor_num;
GdkRectangle monitor;
GdkMonitor *monitor;
GdkRectangle area;
gint ox, oy;
g_assert (_gtk_widget_get_mapped (parent_widget)); /* established earlier */
display = gdk_screen_get_display (screen);
gdk_window = _gtk_widget_get_window (parent_widget);
monitor = gdk_display_get_monitor_at_window (display, gdk_window);
if (gdk_window != NULL)
monitor_num = gdk_screen_get_monitor_at_window (screen,
gdk_window);
else
monitor_num = -1;
gdk_window_get_origin (gdk_window,
&ox, &oy);
gdk_window_get_origin (gdk_window, &ox, &oy);
_gtk_widget_get_allocation (parent_widget, &allocation);
x = ox + (allocation.width - w) / 2;
@ -9391,10 +9372,10 @@ gtk_window_compute_configure_request (GtkWindow *window,
* WM decorations. If parent wasn't on a monitor, just
* give up.
*/
if (monitor_num >= 0)
if (monitor != NULL)
{
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
clamp_window_to_rectangle (&x, &y, w, h, &monitor);
gdk_monitor_get_geometry (monitor, &area);
clamp_window_to_rectangle (&x, &y, w, h, &area);
}
}
break;
@ -9403,24 +9384,17 @@ gtk_window_compute_configure_request (GtkWindow *window,
{
gint screen_width = gdk_screen_get_width (screen);
gint screen_height = gdk_screen_get_height (screen);
gint monitor_num;
GdkRectangle monitor;
GdkRectangle area;
GdkDisplay *display;
GdkDevice *pointer;
GdkScreen *pointer_screen;
GdkMonitor *monitor;
gint px, py;
display = gdk_screen_get_display (screen);
pointer = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
gdk_device_get_position (pointer,
&pointer_screen,
&px, &py);
if (pointer_screen == screen)
monitor_num = gdk_screen_get_monitor_at_point (screen, px, py);
else
monitor_num = -1;
gdk_device_get_position (pointer, NULL, &px, &py);
monitor = gdk_display_get_monitor_at_point (display, px, py);
x = px - w / 2;
y = py - h / 2;
@ -9431,10 +9405,10 @@ gtk_window_compute_configure_request (GtkWindow *window,
* WM decorations. Don't try to figure out what's going
* on if the mouse wasn't inside a monitor.
*/
if (monitor_num >= 0)
if (monitor != NULL)
{
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
clamp_window_to_rectangle (&x, &y, w, h, &monitor);
gdk_monitor_get_geometry (monitor, &area);
clamp_window_to_rectangle (&x, &y, w, h, &area);
}
}
break;
@ -10538,12 +10512,11 @@ gtk_window_fullscreen_on_monitor (GtkWindow *window,
GtkWindowPrivate *priv;
GtkWidget *widget;
GdkWindow *toplevel;
g_return_if_fail (GTK_IS_WINDOW (window));
g_return_if_fail (GDK_IS_SCREEN (screen));
g_return_if_fail (monitor >= 0);
g_return_if_fail (monitor < gdk_screen_get_n_monitors (screen));
g_return_if_fail (gdk_display_get_monitor (gdk_screen_get_display (screen), monitor) != NULL);
priv = window->priv;
widget = GTK_WIDGET (window);