From fe0864120520db9357b92489255d495cb61eba4f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 3 Nov 2016 23:40:54 +0100 Subject: [PATCH] x11: Maointin window visuals without GdkVisual That way, we don't need a GdkScreen to create a GdkWindow anymore. --- gdk/x11/gdkdisplay-x11.c | 43 +++++++++--------- gdk/x11/gdkdisplay-x11.h | 5 +++ gdk/x11/gdkprivate-x11.h | 10 +++-- gdk/x11/gdkscreen-x11.c | 5 ++- gdk/x11/gdkscreen-x11.h | 3 +- gdk/x11/gdkvisual-x11.c | 97 +++++++++++++--------------------------- 6 files changed, 68 insertions(+), 95 deletions(-) diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index c944a664b4..7884570128 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -1334,6 +1334,22 @@ set_sm_client_id (GdkDisplay *display, gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID")); } +void +gdk_display_setup_window_visual (GdkDisplay *display, + gint depth, + Visual *visual, + Colormap colormap, + gboolean rgba) +{ + GdkX11Display *display_x11 = GDK_X11_DISPLAY (display); + + display_x11->window_depth = depth; + display_x11->window_visual = visual; + display_x11->window_colormap = colormap; + + gdk_display_set_rgba (display, rgba); +} + GdkDisplay * _gdk_x11_display_open (const gchar *display_name) { @@ -1390,9 +1406,7 @@ _gdk_x11_display_open (const gchar *display_name) #endif /* initialize the display's screens */ - display_x11->screen = _gdk_x11_screen_new (display, DefaultScreen (display_x11->xdisplay)); - if (gdk_screen_get_rgba_visual (display_x11->screen) == NULL) - gdk_display_set_rgba (display, FALSE); + display_x11->screen = _gdk_x11_screen_new (display, DefaultScreen (display_x11->xdisplay), TRUE); /* We need to initialize events after we have the screen * structures in places @@ -1993,7 +2007,7 @@ _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display, if (gdk_x11_display_error_trap_pop (display) || !result) return NULL; - screen = _gdk_x11_screen_new (display, XScreenNumberOfScreen (attrs.screen)); + screen = _gdk_x11_screen_new (display, XScreenNumberOfScreen (attrs.screen), FALSE); display_x11->screens = g_list_prepend (display_x11->screens, screen); @@ -2919,37 +2933,22 @@ gdk_x11_display_get_primary_monitor (GdkDisplay *display) return NULL; } -static GdkVisual * -gdk_x11_display_get_window_gdk_visual (GdkX11Display *display) -{ - GdkScreen *screen; - GdkVisual *visual; - - screen = gdk_display_get_default_screen (GDK_DISPLAY (display)); - - visual = gdk_screen_get_rgba_visual (screen); - if (visual == NULL) - visual = gdk_screen_get_system_visual (screen); - - return visual; -} - int gdk_x11_display_get_window_depth (GdkX11Display *display) { - return gdk_visual_get_depth (gdk_x11_display_get_window_gdk_visual (display)); + return display->window_depth; } Visual * gdk_x11_display_get_window_visual (GdkX11Display *display) { - return gdk_x11_visual_get_xvisual (gdk_x11_display_get_window_gdk_visual (display)); + return display->window_visual; } Colormap gdk_x11_display_get_window_colormap (GdkX11Display *display) { - return _gdk_visual_get_x11_colormap (gdk_x11_display_get_window_gdk_visual (display)); + return display->window_colormap; } static void diff --git a/gdk/x11/gdkdisplay-x11.h b/gdk/x11/gdkdisplay-x11.h index f53db8ceb3..9f7491f36f 100644 --- a/gdk/x11/gdkdisplay-x11.h +++ b/gdk/x11/gdkdisplay-x11.h @@ -45,6 +45,11 @@ struct _GdkX11Display gint grab_count; + /* Visual infos for creating Windows */ + int window_depth; + Visual *window_visual; + Colormap window_colormap; + /* Keyboard related information */ gint xkb_event_type; gboolean use_xkb; diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h index b96f1a0d7a..3353f74c7e 100644 --- a/gdk/x11/gdkprivate-x11.h +++ b/gdk/x11/gdkprivate-x11.h @@ -48,12 +48,15 @@ void _gdk_x11_error_handler_push (void); void _gdk_x11_error_handler_pop (void); -Colormap _gdk_visual_get_x11_colormap (GdkVisual *visual); - GdkVisual * _gdk_x11_screen_get_system_visual (GdkScreen *screen); GList * _gdk_x11_screen_list_visuals (GdkScreen *screen); +void gdk_display_setup_window_visual (GdkDisplay *display, + gint depth, + Visual *visual, + Colormap colormap, + gboolean rgba); int gdk_x11_display_get_window_depth (GdkX11Display *display); Visual * gdk_x11_display_get_window_visual (GdkX11Display *display); Colormap gdk_x11_display_get_window_colormap (GdkX11Display *display); @@ -290,7 +293,8 @@ _gdk_x11_dnd_filter (GdkXEvent *xev, gpointer data); void _gdk_x11_screen_init_root_window (GdkScreen *screen); -void _gdk_x11_screen_init_visuals (GdkScreen *screen); +void _gdk_x11_screen_init_visuals (GdkScreen *screen, + gboolean setup_display); void _gdk_x11_cursor_update_theme (GdkCursor *cursor); void _gdk_x11_cursor_display_finalize (GdkDisplay *display); diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c index 59d4a27b50..905368d35f 100644 --- a/gdk/x11/gdkscreen-x11.c +++ b/gdk/x11/gdkscreen-x11.c @@ -794,7 +794,8 @@ init_multihead (GdkScreen *screen) GdkScreen * _gdk_x11_screen_new (GdkDisplay *display, - gint screen_number) + gint screen_number, + gboolean setup_display) { GdkScreen *screen; GdkX11Screen *x11_screen; @@ -827,7 +828,7 @@ _gdk_x11_screen_new (GdkDisplay *display, init_randr_support (screen); init_multihead (screen); - _gdk_x11_screen_init_visuals (screen); + _gdk_x11_screen_init_visuals (screen, setup_display); _gdk_x11_screen_init_root_window (screen); return screen; diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h index ee099b54f4..f26e13f744 100644 --- a/gdk/x11/gdkscreen-x11.h +++ b/gdk/x11/gdkscreen-x11.h @@ -98,7 +98,8 @@ struct _GdkX11ScreenClass GType _gdk_x11_screen_get_type (void); GdkScreen * _gdk_x11_screen_new (GdkDisplay *display, - gint screen_number); + gint screen_number, + gboolean setup_display); void _gdk_x11_screen_update_visuals_for_gl (GdkScreen *screen); void _gdk_x11_screen_window_manager_changed (GdkScreen *screen); diff --git a/gdk/x11/gdkvisual-x11.c b/gdk/x11/gdkvisual-x11.c index b9486132e9..366193336b 100644 --- a/gdk/x11/gdkvisual-x11.c +++ b/gdk/x11/gdkvisual-x11.c @@ -36,7 +36,6 @@ struct _GdkX11Visual GdkVisual visual; Visual *xvisual; - Colormap colormap; }; struct _GdkX11VisualClass @@ -49,47 +48,16 @@ G_DEFINE_TYPE (GdkX11Visual, gdk_x11_visual, GDK_TYPE_VISUAL) static void gdk_x11_visual_init (GdkX11Visual *x11_visual) { - x11_visual->colormap = None; -} - -static void -gdk_x11_visual_finalize (GObject *object) -{ - GdkVisual *visual = (GdkVisual *)object; - GdkX11Visual *x11_visual = (GdkX11Visual *)object; - - if (x11_visual->colormap != None) - XFreeColormap (GDK_SCREEN_XDISPLAY (visual->screen), x11_visual->colormap); - - G_OBJECT_CLASS (gdk_x11_visual_parent_class)->finalize (object); -} - -static void -gdk_x11_visual_dispose (GObject *object) -{ - GdkVisual *visual = (GdkVisual *)object; - GdkX11Visual *x11_visual = (GdkX11Visual *)object; - - if (x11_visual->colormap != None) - { - XFreeColormap (GDK_SCREEN_XDISPLAY (visual->screen), x11_visual->colormap); - x11_visual->colormap = None; - } - - G_OBJECT_CLASS (gdk_x11_visual_parent_class)->dispose (object); } static void gdk_x11_visual_class_init (GdkX11VisualClass *class) { - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->finalize = gdk_x11_visual_finalize; - object_class->dispose = gdk_x11_visual_dispose; } void -_gdk_x11_screen_init_visuals (GdkScreen *screen) +_gdk_x11_screen_init_visuals (GdkScreen *screen, + gboolean setup_display) { static const gint possible_depths[8] = { 32, 30, 24, 16, 15, 8, 4, 1 }; static const GdkVisualType possible_types[6] = @@ -221,11 +189,7 @@ _gdk_x11_screen_init_visuals (GdkScreen *screen) for (i = 0; i < nvisuals; i++) { if (default_xvisual->visualid == GDK_X11_VISUAL (visuals[i])->xvisual->visualid) - { - x11_screen->system_visual = visuals[i]; - GDK_X11_VISUAL (visuals[i])->colormap = - DefaultColormap (x11_screen->xdisplay, x11_screen->screen_num); - } + x11_screen->system_visual = visuals[i]; /* For now, we only support 8888 ARGB for the "rgba visual". * Additional formats (like ABGR) could be added later if they @@ -298,6 +262,33 @@ _gdk_x11_screen_init_visuals (GdkScreen *screen) as we care about glx details such as alpha/depth/stencil depth, stereo and double buffering */ _gdk_x11_screen_update_visuals_for_gl (screen); + + if (setup_display) + { + if (x11_screen->rgba_visual) + { + Visual *xvisual = GDK_X11_VISUAL (x11_screen->rgba_visual)->xvisual; + Colormap colormap; + + colormap = XCreateColormap (x11_screen->xdisplay, + RootWindow (x11_screen->xdisplay, x11_screen->screen_num), + xvisual, + AllocNone); + gdk_display_setup_window_visual (gdk_screen_get_display (screen), + x11_screen->rgba_visual->depth, + GDK_X11_VISUAL (x11_screen->rgba_visual)->xvisual, + colormap, + TRUE); + } + else + { + gdk_display_setup_window_visual (gdk_screen_get_display (screen), + DefaultDepth (x11_screen->xdisplay, x11_screen->screen_num), + DefaultVisual (x11_screen->xdisplay, x11_screen->screen_num), + DefaultColormap (x11_screen->xdisplay, x11_screen->screen_num), + FALSE); + } + } } GdkVisual * @@ -354,34 +345,6 @@ gdk_x11_screen_lookup_visual (GdkScreen *screen, return NULL; } -/** - * _gdk_visual_get_x11_colormap: - * @visual: the visual to get the colormap from - * - * Gets the colormap to use - * - * Returns: the X Colormap to use for new windows using @visual - **/ -Colormap -_gdk_visual_get_x11_colormap (GdkVisual *visual) -{ - GdkX11Visual *x11_visual; - - g_return_val_if_fail (GDK_IS_VISUAL (visual), None); - - x11_visual = GDK_X11_VISUAL (visual); - - if (x11_visual->colormap == None) - { - x11_visual->colormap = XCreateColormap (GDK_SCREEN_XDISPLAY (visual->screen), - GDK_SCREEN_XROOTWIN (visual->screen), - x11_visual->xvisual, - AllocNone); - } - - return x11_visual->colormap; -} - /** * gdk_x11_visual_get_xvisual: * @visual: (type GdkX11Visual): a #GdkVisual.