From 3b93773add0bd3bc17b55a2ce458667693eb285e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 7 Nov 2016 01:03:17 +0100 Subject: [PATCH] API: gdk: Add gdk_window_new_temp() Your one stop shop for all those nasty hidden input-only windows. --- gdk/broadway/gdkwindow-broadway.c | 17 +--------------- gdk/gdkwindow.c | 34 +++++++++++++++++++++++++++++++ gdk/gdkwindow.h | 2 ++ gdk/x11/gdkdisplay-x11.c | 12 +---------- gdk/x11/gdkwindow-x11.c | 18 +--------------- gtk/gtkinvisible.c | 19 +---------------- gtk/gtkmenu.c | 18 +--------------- 7 files changed, 41 insertions(+), 79 deletions(-) diff --git a/gdk/broadway/gdkwindow-broadway.c b/gdk/broadway/gdkwindow-broadway.c index 596ed6d4df..c3c9adfa64 100644 --- a/gdk/broadway/gdkwindow-broadway.c +++ b/gdk/broadway/gdkwindow-broadway.c @@ -1290,28 +1290,13 @@ static void create_moveresize_window (MoveResizeData *mv_resize, guint32 timestamp) { - GdkWindowAttr attributes; - gint attributes_mask; GdkGrabStatus status; GdkSeat *seat; GdkDevice *pointer; g_assert (mv_resize->moveresize_emulation_window == NULL); - attributes.x = -100; - attributes.y = -100; - attributes.width = 10; - attributes.height = 10; - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = 0; - - attributes_mask = GDK_WA_X | GDK_WA_Y; - - mv_resize->moveresize_emulation_window = - gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)), - &attributes, - attributes_mask); + mv_resize->moveresize_emulation_window = gdk_window_new_temp (mv_resize->display); gdk_window_show (mv_resize->moveresize_emulation_window); diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 0d7a6d6f85..0db6270f1f 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -1365,6 +1365,40 @@ gdk_window_new_popup (GdkDisplay *display, &attr, GDK_WA_X | GDK_WA_Y); } + +/** + * gdk_window_new_temp: (constructor) + * @display: the display to create the window on + * + * Creates a new toplevel temporary window. The window will be + * situated off-screen and not handle output. + * + * You most likely do not want to use this function. + * + * Returns: (transfer full): the new #GdkWindow + * + * Since: 3.90 + **/ +GdkWindow * +gdk_window_new_temp (GdkDisplay *display) +{ + GdkWindowAttr attr; + + g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); + + attr.event_mask = 0; + attr.wclass = GDK_INPUT_ONLY; + attr.x = -100; + attr.y = -100; + attr.width = 10; + attr.height = 10; + 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 33c3d52408..83030a86a0 100644 --- a/gdk/gdkwindow.h +++ b/gdk/gdkwindow.h @@ -475,6 +475,8 @@ GdkWindow * gdk_window_new_popup (GdkDisplay *display, gint event_mask, const GdkRectangle *position); GDK_AVAILABLE_IN_3_90 +GdkWindow * gdk_window_new_temp (GdkDisplay *display); +GDK_AVAILABLE_IN_3_90 GdkWindow * gdk_window_new_child (GdkWindow *parent, gint event_mask, const GdkRectangle *position); diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index 7884570128..cca0b651be 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -1356,7 +1356,6 @@ _gdk_x11_display_open (const gchar *display_name) Display *xdisplay; GdkDisplay *display; GdkX11Display *display_x11; - GdkWindowAttr attr; gint argc; gchar *argv[1]; @@ -1417,16 +1416,7 @@ _gdk_x11_display_open (const gchar *display_name) gdk_event_init (display); - attr.window_type = GDK_WINDOW_TOPLEVEL; - attr.wclass = GDK_INPUT_ONLY; - attr.x = 10; - attr.y = 10; - attr.width = 10; - attr.height = 10; - attr.event_mask = 0; - - display_x11->leader_gdk_window = gdk_window_new (GDK_X11_SCREEN (display_x11->screen)->root_window, - &attr, GDK_WA_X | GDK_WA_Y); + display_x11->leader_gdk_window = gdk_window_new_temp (display); (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE; display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window); diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 8d226dca74..371ba9e246 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -4815,27 +4815,11 @@ static void create_moveresize_window (MoveResizeData *mv_resize, guint32 timestamp) { - GdkWindowAttr attributes; - gint attributes_mask; GdkGrabStatus status; g_assert (mv_resize->moveresize_emulation_window == NULL); - attributes.x = -100; - attributes.y = -100; - attributes.width = 10; - attributes.height = 10; - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = 0; - - attributes_mask = GDK_WA_X | GDK_WA_Y; - - mv_resize->moveresize_emulation_window = - gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)), - &attributes, - attributes_mask); - + mv_resize->moveresize_emulation_window = gdk_window_new_temp (mv_resize->display); gdk_window_show (mv_resize->moveresize_emulation_window); status = gdk_seat_grab (gdk_device_get_seat (mv_resize->device), diff --git a/gtk/gtkinvisible.c b/gtk/gtkinvisible.c index ebea8b9d9b..16f5ef695e 100644 --- a/gtk/gtkinvisible.c +++ b/gtk/gtkinvisible.c @@ -229,28 +229,11 @@ gtk_invisible_get_screen (GtkInvisible *invisible) static void gtk_invisible_realize (GtkWidget *widget) { - GdkWindow *parent; GdkWindow *window; - GdkWindowAttr attributes; - gint attributes_mask; gtk_widget_set_realized (widget, TRUE); - parent = gtk_widget_get_parent_window (widget); - if (parent == NULL) - parent = gdk_screen_get_root_window (gtk_widget_get_screen (widget)); - - attributes.x = -100; - attributes.y = -100; - attributes.width = 10; - attributes.height = 10; - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = gtk_widget_get_events (widget); - - attributes_mask = GDK_WA_X | GDK_WA_Y; - - window = gdk_window_new (parent, &attributes, attributes_mask); + window = gdk_window_new_temp (gtk_widget_get_display (widget)); gtk_widget_set_window (widget, window); gtk_widget_register_window (widget, window); } diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index f7ac5b294b..e345779ff7 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -2667,23 +2667,7 @@ menu_grab_transfer_window_get (GtkMenu *menu) GdkWindow *window = g_object_get_data (G_OBJECT (menu), "gtk-menu-transfer-window"); if (!window) { - GdkWindowAttr attributes; - gint attributes_mask; - GdkWindow *parent; - - attributes.x = -100; - attributes.y = -100; - attributes.width = 10; - attributes.height = 10; - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = 0; - - attributes_mask = GDK_WA_X | GDK_WA_Y; - - parent = gdk_screen_get_root_window (gtk_widget_get_screen (GTK_WIDGET (menu))); - window = gdk_window_new (parent, - &attributes, attributes_mask); + window = gdk_window_new_temp (gtk_widget_get_display (GTK_WIDGET (menu))); gtk_widget_register_window (GTK_WIDGET (menu), window); gdk_window_show (window);