API: gdk: Add gdk_window_new_toplevel()

... and use it in GTK.
This commit is contained in:
Benjamin Otte 2016-11-06 17:40:59 +01:00
parent 7a6cab14eb
commit 87f07bac6b
4 changed files with 64 additions and 26 deletions

View File

@ -278,6 +278,7 @@ GdkWindowTypeHint
GdkWindowAttr
GdkWindowAttributesType
gdk_window_new
gdk_window_new_toplevel
gdk_window_new_child
gdk_window_new_input
gdk_window_destroy

View File

@ -1295,6 +1295,41 @@ gdk_window_new (GdkWindow *parent,
return window;
}
/**
* gdk_window_new_toplevel: (constructor)
* @display: the display to create the window on
* @event_mask: event mask (see gdk_window_set_events())
* @width: width of new window
* @height: height of new window
*
* Creates a new toplevel window. The window will be managed by the window
* manager.
*
* Returns: (transfer full): the new #GdkWindow
*
* Since: 3.90
**/
GdkWindow *
gdk_window_new_toplevel (GdkDisplay *display,
gint event_mask,
gint width,
gint height)
{
GdkWindowAttr attr;
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
attr.event_mask = event_mask;
attr.wclass = GDK_INPUT_OUTPUT;
attr.width = width;
attr.height = height;
attr.window_type = GDK_WINDOW_TOPLEVEL;
return gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (display)),
&attr,
0);
}
/**
* gdk_window_new_child: (constructor)
* @parent: the parent window

View File

@ -466,6 +466,11 @@ GdkWindow* gdk_window_new (GdkWindow *parent,
GdkWindowAttr *attributes,
gint attributes_mask);
GDK_AVAILABLE_IN_3_90
GdkWindow * gdk_window_new_toplevel (GdkDisplay *display,
gint event_mask,
int width,
int height);
GDK_AVAILABLE_IN_3_90
GdkWindow * gdk_window_new_child (GdkWindow *parent,
gint event_mask,
const GdkRectangle *position);

View File

@ -6868,11 +6868,9 @@ gtk_window_realize (GtkWidget *widget)
GtkAllocation allocation;
GtkAllocation child_allocation;
GtkWindow *window;
GdkWindow *parent_window;
GdkWindow *gdk_window;
GdkWindowAttr attributes;
GtkBorder window_border;
gint attributes_mask;
GtkWindowPrivate *priv;
gint i;
GList *link;
@ -6944,30 +6942,8 @@ gtk_window_realize (GtkWidget *widget)
}
else
{
switch (priv->type)
{
case GTK_WINDOW_TOPLEVEL:
attributes.window_type = GDK_WINDOW_TOPLEVEL;
break;
case GTK_WINDOW_POPUP:
attributes.window_type = GDK_WINDOW_TEMP;
break;
default:
g_warning (G_STRLOC": Unknown window type %d!", priv->type);
break;
}
#ifdef GDK_WINDOWING_WAYLAND
if (priv->use_subsurface &&
GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
attributes.window_type = GDK_WINDOW_SUBSURFACE;
#endif
attributes.wclass = GDK_INPUT_OUTPUT;
attributes_mask = 0;
parent_window = gdk_screen_get_root_window (_gtk_window_get_screen (window));
_gtk_widget_get_allocation (widget, &allocation);
attributes.width = allocation.width;
attributes.height = allocation.height;
@ -6982,11 +6958,32 @@ gtk_window_realize (GtkWidget *widget)
GDK_LEAVE_NOTIFY_MASK |
GDK_FOCUS_CHANGE_MASK |
GDK_STRUCTURE_MASK);
if (priv->decorated && priv->client_decorated)
attributes.event_mask |= GDK_POINTER_MOTION_MASK;
gdk_window = gdk_window_new (parent_window, &attributes, attributes_mask);
switch (priv->type)
{
case GTK_WINDOW_TOPLEVEL:
gdk_window = gdk_window_new_toplevel (gtk_widget_get_display (widget),
attributes.event_mask,
allocation.width,
allocation.height);
break;
case GTK_WINDOW_POPUP:
#ifdef GDK_WINDOWING_WAYLAND
if (priv->use_subsurface &&
GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
attributes.window_type = GDK_WINDOW_SUBSURFACE;
else
#endif
attributes.window_type = GDK_WINDOW_TEMP;
gdk_window = gdk_window_new (gdk_screen_get_root_window (_gtk_window_get_screen (window)),
&attributes, 0);
break;
default:
g_warning (G_STRLOC": Unknown window type %d!", priv->type);
break;
}
}
gtk_widget_set_window (widget, gdk_window);