diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 65d7e138f4..0d88611f55 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -279,6 +279,7 @@ GdkWindowAttr GdkWindowAttributesType gdk_window_new gdk_window_new_toplevel +gdk_window_new_popup gdk_window_new_child gdk_window_new_input gdk_window_destroy diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 846174c991..0d7a6d6f85 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -1330,6 +1330,41 @@ gdk_window_new_toplevel (GdkDisplay *display, 0); } +/** + * gdk_window_new_popup: (constructor) + * @display: the display to create the window on + * @event_mask: event mask (see gdk_window_set_events()) + * @position: position of the window on screen + * + * Creates a new toplevel popup window. The window will bypass window + * management. + * + * Returns: (transfer full): the new #GdkWindow + * + * Since: 3.90 + **/ +GdkWindow * +gdk_window_new_popup (GdkDisplay *display, + gint event_mask, + const GdkRectangle *position) +{ + GdkWindowAttr attr; + + g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); + g_return_val_if_fail (position != NULL, NULL); + + attr.event_mask = event_mask; + attr.wclass = GDK_INPUT_OUTPUT; + attr.x = position->x; + attr.y = position->y; + attr.width = position->width; + attr.height = position->height; + attr.window_type = GDK_WINDOW_TEMP; + + return gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (display)), + &attr, + GDK_WA_X | GDK_WA_Y); +} /** * gdk_window_new_child: (constructor) * @parent: the parent window diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h index 960c16dd77..33c3d52408 100644 --- a/gdk/gdkwindow.h +++ b/gdk/gdkwindow.h @@ -471,6 +471,10 @@ GdkWindow * gdk_window_new_toplevel (GdkDisplay *display, int width, int height); GDK_AVAILABLE_IN_3_90 +GdkWindow * gdk_window_new_popup (GdkDisplay *display, + gint event_mask, + const GdkRectangle *position); +GDK_AVAILABLE_IN_3_90 GdkWindow * gdk_window_new_child (GdkWindow *parent, gint event_mask, const GdkRectangle *position); diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index ce4915bea1..45483af705 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -4511,20 +4511,7 @@ static const struct wl_surface_listener pointer_surface_listener = { static GdkWindow * create_foreign_dnd_window (GdkDisplay *display) { - GdkWindowAttr attrs; - GdkScreen *screen; - guint mask; - - screen = gdk_display_get_default_screen (display); - - attrs.x = attrs.y = 0; - attrs.width = attrs.height = 1; - attrs.wclass = GDK_INPUT_OUTPUT; - attrs.window_type = GDK_WINDOW_TEMP; - - mask = GDK_WA_X | GDK_WA_Y; - - return gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask); + return gdk_window_new_popup (display, 0, &(GdkRectangle) { 0, 0, 1, 1 }); } static void diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c index ca5ec779fa..184c6a0b69 100644 --- a/gdk/wayland/gdkdnd-wayland.c +++ b/gdk/wayland/gdkdnd-wayland.c @@ -498,20 +498,11 @@ _gdk_wayland_window_register_dnd (GdkWindow *window) } static GdkWindow * -create_dnd_window (GdkScreen *screen) +create_dnd_window (GdkDisplay *display) { - GdkWindowAttr attrs; GdkWindow *window; - guint mask; - attrs.x = attrs.y = 0; - attrs.width = attrs.height = 100; - attrs.wclass = GDK_INPUT_OUTPUT; - attrs.window_type = GDK_WINDOW_TEMP; - - mask = GDK_WA_X | GDK_WA_Y; - - window = gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask); + window = gdk_window_new_popup (display, 0, &(GdkRectangle) { 0, 0, 100, 100 }); gdk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DND); @@ -538,7 +529,7 @@ _gdk_wayland_window_drag_begin (GdkWindow *window, gdk_drag_context_set_device (context, device); - context_wayland->dnd_window = create_dnd_window (gdk_window_get_screen (window)); + context_wayland->dnd_window = create_dnd_window (gdk_window_get_display (window)); context_wayland->dnd_surface = gdk_wayland_window_get_wl_surface (context_wayland->dnd_window); context_wayland->data_source = gdk_wayland_selection_get_data_source (window, diff --git a/gdk/win32/gdkdevicemanager-win32.c b/gdk/win32/gdkdevicemanager-win32.c index 62c164d355..7c8794ff59 100644 --- a/gdk/win32/gdkdevicemanager-win32.c +++ b/gdk/win32/gdkdevicemanager-win32.c @@ -354,7 +354,6 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager) GdkWindow *root = gdk_screen_get_root_window (gdk_display_get_default_screen (display)); static gboolean wintab_initialized = FALSE; GdkDeviceWintab *device; - GdkWindowAttr wa; WORD specversion; HCTX *hctx; UINT ndevices, ncursors, ncsrtypes, firstcsr, hardware; @@ -434,18 +433,7 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager) ndevices, ncursors)); #endif /* Create a dummy window to receive wintab events */ - wa.wclass = GDK_INPUT_OUTPUT; - wa.event_mask = GDK_ALL_EVENTS_MASK; - wa.width = 2; - wa.height = 2; - wa.x = -100; - wa.y = -100; - wa.window_type = GDK_WINDOW_TOPLEVEL; - if ((wintab_window = gdk_window_new (root, &wa, GDK_WA_X | GDK_WA_Y)) == NULL) - { - g_warning ("gdk_input_wintab_init: gdk_window_new failed"); - return; - } + wintab_window = gdk_window_new_popup (display, GDK_ALL_EVENTS_MASK, &(GdkRectangle) { -100, -100, 2, 2 }); g_object_ref (wintab_window); for (devix = 0; devix < ndevices; devix++) diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c index f4cdcc33c3..ac5e51e8e5 100644 --- a/gdk/x11/gdkdnd-x11.c +++ b/gdk/x11/gdkdnd-x11.c @@ -1991,20 +1991,11 @@ gdk_drag_do_leave (GdkX11DragContext *context_x11, } static GdkWindow * -create_drag_window (GdkScreen *screen) +create_drag_window (GdkDisplay *display) { - GdkWindowAttr attrs = { 0 }; GdkWindow *window; - guint mask; - attrs.x = attrs.y = 0; - attrs.width = attrs.height = 100; - attrs.wclass = GDK_INPUT_OUTPUT; - attrs.window_type = GDK_WINDOW_TEMP; - - mask = GDK_WA_X | GDK_WA_Y; - - window = gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask); + window = gdk_window_new_popup (display, 0, &(GdkRectangle) { 0, 0, 100, 100 }); gdk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DND); @@ -2037,7 +2028,7 @@ _gdk_x11_window_drag_begin (GdkWindow *window, GDK_X11_DRAG_CONTEXT (context)->start_x = x_root; GDK_X11_DRAG_CONTEXT (context)->start_y = y_root; - GDK_X11_DRAG_CONTEXT (context)->drag_window = create_drag_window (gdk_window_get_screen (window)); + GDK_X11_DRAG_CONTEXT (context)->drag_window = create_drag_window (gdk_window_get_display(window)); return context; } diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 9747b63d19..595d5720b4 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -3938,25 +3938,15 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view) /* Create the new window */ if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW) { - GdkWindowAttr attributes; - gint attributes_mask; - if (tree_view->priv->drag_highlight_window) { gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window); gdk_window_destroy (tree_view->priv->drag_highlight_window); } - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y; - attributes.x = x; - attributes.y = y; - attributes.width = width; - attributes.height = height; - tree_view->priv->drag_highlight_window = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)), - &attributes, attributes_mask); + tree_view->priv->drag_highlight_window = gdk_window_new_popup (gtk_widget_get_display (widget), + GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK, + &(GdkRectangle) { x, y, width, height }); gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window); mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height); @@ -4017,24 +4007,15 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view) if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT && tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT) { - GdkWindowAttr attributes; - gint attributes_mask; - if (tree_view->priv->drag_highlight_window) { gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window); gdk_window_destroy (tree_view->priv->drag_highlight_window); } - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y; - attributes.x = x; - attributes.y = y; - attributes.width = width; - attributes.height = height; - tree_view->priv->drag_highlight_window = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)), &attributes, attributes_mask); + tree_view->priv->drag_highlight_window = gdk_window_new_popup (gtk_widget_get_display (widget), + GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK, + &(GdkRectangle) { x, y, width, height }); gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window); mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 764cbf5ff7..28b68af933 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -6858,9 +6858,9 @@ gtk_window_realize (GtkWidget *widget) GtkAllocation child_allocation; GtkWindow *window; GdkWindow *gdk_window; - GdkWindowAttr attributes; GtkBorder window_border; GtkWindowPrivate *priv; + gint event_mask; gint i; GList *link; @@ -6931,30 +6931,26 @@ gtk_window_realize (GtkWidget *widget) } else { - attributes.wclass = GDK_INPUT_OUTPUT; - _gtk_widget_get_allocation (widget, &allocation); - attributes.width = allocation.width; - attributes.height = allocation.height; - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON_MOTION_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK | - GDK_FOCUS_CHANGE_MASK | - GDK_STRUCTURE_MASK); + event_mask = gtk_widget_get_events (widget); + event_mask |= (GDK_EXPOSURE_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_BUTTON_MOTION_MASK | + GDK_KEY_PRESS_MASK | + GDK_KEY_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK | + GDK_FOCUS_CHANGE_MASK | + GDK_STRUCTURE_MASK); if (priv->decorated && priv->client_decorated) - attributes.event_mask |= GDK_POINTER_MOTION_MASK; + event_mask |= GDK_POINTER_MOTION_MASK; switch (priv->type) { case GTK_WINDOW_TOPLEVEL: gdk_window = gdk_window_new_toplevel (gtk_widget_get_display (widget), - attributes.event_mask, + event_mask, allocation.width, allocation.height); break; @@ -6964,15 +6960,15 @@ gtk_window_realize (GtkWidget *widget) GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget))) { gdk_window = gdk_wayland_window_new_subsurface (gtk_widget_get_display (widget), - attributes.event_mask, + event_mask, &allocation); } 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); + gdk_window = gdk_window_new_popup (gtk_widget_get_display (widget), + event_mask, + &allocation); } break; default: diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c index 1c5cecbb7d..8af8f4f0d2 100644 --- a/testsuite/gtk/defaultvalue.c +++ b/testsuite/gtk/defaultvalue.c @@ -107,13 +107,9 @@ test_type (gconstpointer data) instance = g_object_ref (gtk_settings_get_default ()); else if (g_type_is_a (type, GDK_TYPE_WINDOW)) { - GdkWindowAttr attributes; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_TEMP; - attributes.event_mask = 0; - attributes.width = 100; - attributes.height = 100; - instance = g_object_ref (gdk_window_new (NULL, &attributes, 0)); + instance = g_object_ref (gdk_window_new_popup (gdk_display_get_default (), + 0, + &(GdkRectangle) { 0, 0, 100, 100 })); } else if (g_str_equal (g_type_name (type), "GdkX11Cursor")) instance = g_object_new (type, "display", display, NULL); diff --git a/testsuite/gtk/notify.c b/testsuite/gtk/notify.c index 65aba315b8..3f369136a6 100644 --- a/testsuite/gtk/notify.c +++ b/testsuite/gtk/notify.c @@ -403,13 +403,9 @@ test_type (gconstpointer data) instance = g_object_ref (gtk_settings_get_default ()); else if (g_type_is_a (type, GDK_TYPE_WINDOW)) { - GdkWindowAttr attributes; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_TEMP; - attributes.event_mask = 0; - attributes.width = 100; - attributes.height = 100; - instance = g_object_ref (gdk_window_new (NULL, &attributes, 0)); + instance = g_object_ref (gdk_window_new_popup (gdk_display_get_default (), + 0, + &(GdkRectangle) { 0, 0, 100, 100 })); } else if (g_str_equal (g_type_name (type), "GdkX11Cursor")) instance = g_object_new (type, "display", display, NULL);