static void create_window (GsdLocatePointerData *data, GdkScreen *screen) { GdkColormap *colormap; GdkVisual *visual; GdkWindowAttr attributes; colormap = gdk_screen_get_rgba_colormap (screen); visual = gdk_screen_get_rgba_visual (screen); if (!colormap) { colormap = gdk_screen_get_rgb_colormap (screen); visual = gdk_screen_get_rgb_visual (screen); } attributes.window_type = GDK_WINDOW_TEMP; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = visual; attributes.colormap = colormap; attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK; attributes.width = 1; attributes.height = 1; data->window = gdk_window_new (gdk_screen_get_root_window (screen), &attributes, GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP); gdk_window_set_user_data (data->window, data->widget); }
// Look for an existing Colormap that known to be associated with visual. static Colormap LookupColormapForVisual(const Screen* screen, const Visual* visual) { // common case if (visual == DefaultVisualOfScreen(screen)) return DefaultColormapOfScreen(screen); #ifdef MOZ_WIDGET_GTK2 // I wish there were a gdk_x11_display_lookup_screen. Display* dpy = DisplayOfScreen(screen); GdkDisplay* gdkDpy = gdk_x11_lookup_xdisplay(dpy); if (gdkDpy) { gint screen_num = 0; for (int s = 0; s < ScreenCount(dpy); ++s) { if (ScreenOfDisplay(dpy, s) == screen) { screen_num = s; break; } } GdkScreen* gdkScreen = gdk_display_get_screen(gdkDpy, screen_num); GdkColormap* gdkColormap = NULL; if (visual == GDK_VISUAL_XVISUAL(gdk_screen_get_rgb_visual(gdkScreen))) { // widget/src/gtk2/mozcontainer.c uses gdk_rgb_get_colormap() // which is inherited by child widgets, so this is the visual // expected when drawing directly to widget surfaces or surfaces // created using cairo_surface_create_similar with // CAIRO_CONTENT_COLOR. // gdk_screen_get_rgb_colormap is the generalization of // gdk_rgb_get_colormap for any screen. gdkColormap = gdk_screen_get_rgb_colormap(gdkScreen); } else if (visual == GDK_VISUAL_XVISUAL(gdk_screen_get_rgba_visual(gdkScreen))) { // This is the visual expected on displays with the Composite // extension enabled when the surface has been created using // cairo_surface_create_similar with CAIRO_CONTENT_COLOR_ALPHA, // as happens with non-unit opacity. gdkColormap = gdk_screen_get_rgba_colormap(gdkScreen); } if (gdkColormap != NULL) return GDK_COLORMAP_XCOLORMAP(gdkColormap); } #endif return None; }
GtkWidget * na_tray_child_new (GdkScreen *screen, Window icon_window) { XWindowAttributes window_attributes; Display *xdisplay; NaTrayChild *child; GdkVisual *visual; gboolean visual_has_alpha; GdkColormap *colormap; gboolean new_colormap; int red_prec, green_prec, blue_prec, depth; int result; g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); g_return_val_if_fail (icon_window != None, NULL); xdisplay = GDK_SCREEN_XDISPLAY (screen); /* We need to determine the visual of the window we are embedding and create * the socket in the same visual. */ gdk_error_trap_push (); result = XGetWindowAttributes (xdisplay, icon_window, &window_attributes); gdk_error_trap_pop (); if (!result) /* Window already gone */ return NULL; visual = gdk_x11_screen_lookup_visual (screen, window_attributes.visual->visualid); if (!visual) /* Icon window is on another screen? */ return NULL; new_colormap = FALSE; if (visual == gdk_screen_get_rgb_visual (screen)) colormap = gdk_screen_get_rgb_colormap (screen); else if (visual == gdk_screen_get_rgba_visual (screen)) colormap = gdk_screen_get_rgba_colormap (screen); else if (visual == gdk_screen_get_system_visual (screen)) colormap = gdk_screen_get_system_colormap (screen); else { colormap = gdk_colormap_new (visual, FALSE); new_colormap = TRUE; } child = g_object_new (NA_TYPE_TRAY_CHILD, NULL); child->icon_window = icon_window; gtk_widget_set_colormap (GTK_WIDGET (child), colormap); /* We have alpha if the visual has something other than red, green, * and blue */ gdk_visual_get_red_pixel_details (visual, NULL, NULL, &red_prec); gdk_visual_get_green_pixel_details (visual, NULL, NULL, &green_prec); gdk_visual_get_blue_pixel_details (visual, NULL, NULL, &blue_prec); depth = gdk_visual_get_depth (visual); visual_has_alpha = red_prec + blue_prec + green_prec < depth; child->has_alpha = (visual_has_alpha && gdk_display_supports_composite (gdk_screen_get_display (screen))); child->composited = child->has_alpha; if (new_colormap) g_object_unref (colormap); return GTK_WIDGET (child); }