int screenDepth(Widget* widget) { GdkVisual* visual = getVisual(widget); if (!visual) return 24; return gdk_visual_get_depth(visual); }
NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display, uint64_t windowID) : m_plugin(plugin) , m_pluginDisplay(display) , m_windowID(windowID) { // It seems flash needs the socket to be in the same process, // I guess it uses gdk_window_lookup(), so we create a new socket here // containing a plug with the UI process socket embedded. m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID)); // Hide the GtkPlug on delete-event since we assume the widget is valid while the plugin is active. // platformDestroy() will be called anyway right after the delete-event. g_signal_connect(m_platformPluginWidget, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), nullptr); GtkWidget* socket = gtk_socket_new(); // Do not show the plug widget until the socket is connected. g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget); g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr); gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket); gtk_widget_show(socket); Display* hostDisplay = x11HostDisplay(); m_npWindowID = gtk_socket_get_id(GTK_SOCKET(socket)); GdkWindow* window = gtk_widget_get_window(socket); m_setWindowCallbackStruct.display = GDK_WINDOW_XDISPLAY(window); m_setWindowCallbackStruct.visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window)); m_setWindowCallbackStruct.depth = gdk_visual_get_depth(gdk_window_get_visual(window)); m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, GDK_ROOT_WINDOW(), m_setWindowCallbackStruct.visual, AllocNone); XFlush(hostDisplay); }
GdkWindow* create_wrapper(GdkWindow* parent, Window tray_icon) { gdk_flush(); GdkWindow* icon = gdk_x11_window_foreign_new_for_display(gdk_display_get_default(), tray_icon); if (icon == NULL) return NULL; GdkVisual* visual = gdk_window_get_visual(icon); GdkWindow* wrapper = NULL; if (gdk_visual_get_depth(visual) == 24) { GdkWindowAttr attributes; attributes.width = DEFAULT_HEIGHT; attributes.height = DEFAULT_HEIGHT; attributes.window_type = GDK_WINDOW_CHILD; attributes.wclass = GDK_INPUT_OUTPUT; attributes.event_mask = GDK_ALL_EVENTS_MASK; attributes.visual = visual; wrapper = gdk_window_new(parent, &attributes, GDK_WA_VISUAL); //TODO: there should set color correspond by dock background color /*GdkColor color = {1, 0, 0, 1};*/ /*gdk_window_set_background_rgba(wrapper, &color);*/ XReparentWindow(gdk_x11_get_default_xdisplay(), tray_icon, GDK_WINDOW_XID(wrapper), 0, 0); gdk_window_show(icon); g_object_set_data(G_OBJECT(wrapper), "wrapper_child", icon); g_object_set_data(G_OBJECT(icon), "wrapper_parent", wrapper); } else { wrapper = icon; } return wrapper; }
std::unique_ptr<BackingStoreBackendCairo> BackingStore::createBackend() { #if PLATFORM(GTK) && PLATFORM(X11) const auto& sharedDisplay = PlatformDisplay::sharedDisplay(); if (is<PlatformDisplayX11>(sharedDisplay)) { GdkVisual* visual = gtk_widget_get_visual(m_webPageProxy.viewWidget()); GdkScreen* screen = gdk_visual_get_screen(visual); ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen)); return std::make_unique<BackingStoreBackendCairoX11>(downcast<PlatformDisplayX11>(sharedDisplay).native(), GDK_WINDOW_XID(gdk_screen_get_root_window(screen)), GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor); } #endif IntSize scaledSize = m_size; scaledSize.scale(m_deviceScaleFactor); #if PLATFORM(GTK) RefPtr<cairo_surface_t> surface = adoptRef(gdk_window_create_similar_surface(gtk_widget_get_window(m_webPageProxy.viewWidget()), CAIRO_CONTENT_COLOR_ALPHA, scaledSize.width(), scaledSize.height())); #else RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, scaledSize.width(), scaledSize.height())); #endif cairoSurfaceSetDeviceScale(surface.get(), m_deviceScaleFactor, m_deviceScaleFactor); return std::make_unique<BackingStoreBackendCairoImpl>(surface.get(), m_size); }
int wxDisplayDepth() { #ifdef __WXGTK4__ return 24; #else return gdk_visual_get_depth(gdk_window_get_visual(wxGetTopLevelGDK())); #endif }
NS_IMETHODIMP nsScreenGtk :: GetPixelDepth(int32_t *aPixelDepth) { GdkVisual * visual = gdk_screen_get_system_visual(gdk_screen_get_default()); *aPixelDepth = gdk_visual_get_depth(visual); return NS_OK; } // GetPixelDepth
static inline int displayDepth() { #if PLATFORM(GTK) return gdk_visual_get_depth(gdk_screen_get_system_visual(gdk_screen_get_default())); #elif PLATFORM(EFL) && defined(HAVE_ECORE_X) return ecore_x_default_depth_get(x11HostDisplay(), ecore_x_default_screen_get()); #else return 0; #endif }
static inline int displayDepth() { #if PLATFORM(QT) return XDefaultDepth(NetscapePlugin::x11HostDisplay(), x11Screen()); #elif PLATFORM(GTK) return gdk_visual_get_depth(gdk_screen_get_system_visual(gdk_screen_get_default())); #else return 0; #endif }
GtkWidget * na_tray_child_new (GdkScreen *screen, Window icon_window) { XWindowAttributes window_attributes; Display *xdisplay; NaTrayChild *child; GdkVisual *visual; gboolean visual_has_alpha; 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_ignored (); 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; child = g_object_new (NA_TYPE_TRAY_CHILD, NULL); child->icon_window = icon_window; gtk_widget_set_visual (GTK_WIDGET (child), visual); /* 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; return GTK_WIDGET (child); }
WidgetBackingStoreGtkX11::WidgetBackingStoreGtkX11(GtkWidget* widget, const IntSize& size) : WidgetBackingStore(size) { GdkVisual* visual = gtk_widget_get_visual(widget); GdkScreen* screen = gdk_visual_get_screen(visual); m_display = GDK_SCREEN_XDISPLAY(screen); m_pixmap = XCreatePixmap(m_display, GDK_WINDOW_XID(gdk_screen_get_root_window(screen)), size.width(), size.height(), gdk_visual_get_depth(visual)); m_gc = XCreateGC(m_display, m_pixmap, 0, 0); m_surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap, GDK_VISUAL_XVISUAL(visual), size.width(), size.height())); }
static GdkColormap* get_cmap (GdkPixmap *pixmap) { GdkColormap *cmap; cmap = gdk_drawable_get_colormap (pixmap); if (cmap) g_object_ref (G_OBJECT (cmap)); if (cmap == NULL) { if (gdk_drawable_get_depth (pixmap) == 1) { /* try null cmap */ cmap = NULL; } else { /* Try system cmap */ GdkScreen *screen = gdk_drawable_get_screen (GDK_DRAWABLE (pixmap)); cmap = gdk_screen_get_system_colormap (screen); g_object_ref (G_OBJECT (cmap)); } } /* Be sure we aren't going to blow up due to visual mismatch */ if (cmap && #if GTK_CHECK_VERSION(2,21,0) (gdk_visual_get_depth (gdk_colormap_get_visual (cmap)) != gdk_drawable_get_depth (pixmap)) #else (gdk_colormap_get_visual (cmap)->depth != gdk_drawable_get_depth (pixmap)) #endif ) { g_object_unref (G_OBJECT (cmap)); cmap = NULL; } return cmap; }
cairo_surface_t * create_native_surface_and_wrap (int w, int h, GtkWidget *parent_style_window) { GdkWindow *window; GdkVisual *visual; cairo_surface_t *surface; Display *display; Pixmap pixmap; if (w <= 0 || h <= 0) abort (); display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); window = gtk_widget_get_window (parent_style_window); visual = gdk_window_get_visual (window); pixmap = XCreatePixmap (display, GDK_WINDOW_XID (window), w, h, gdk_visual_get_depth (visual)); surface = cairo_xlib_surface_create (display, pixmap, GDK_VISUAL_XVISUAL (visual), w, h); return surface; }
bool NetscapePlugin::platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID) { m_npWindow.type = NPWindowTypeWindow; if (!needsXEmbed) { notImplemented(); return false; } Display* display = x11HostDisplay(); #if PLATFORM(GTK) // It seems flash needs the socket to be in the same process, // I guess it uses gdk_window_lookup(), so we create a new socket here // containing a plug with the UI process socket embedded. m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID)); GtkWidget* socket = gtk_socket_new(); // Do not show the plug widget until the socket is connected. g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget); g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr); gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket); gtk_widget_show(socket); m_npWindow.window = GINT_TO_POINTER(gtk_socket_get_id(GTK_SOCKET(socket))); GdkWindow* window = gtk_widget_get_window(socket); NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info); callbackStruct->display = GDK_WINDOW_XDISPLAY(window); callbackStruct->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window)); callbackStruct->depth = gdk_visual_get_depth(gdk_window_get_visual(window)); callbackStruct->colormap = XCreateColormap(display, GDK_ROOT_WINDOW(), callbackStruct->visual, AllocNone); #else UNUSED_PARAM(windowID); #endif XFlush(display); callSetWindow(); return true; }
GtkWidget* gtk_xtbin_new (GtkWidget *parent_widget, String *f) { GtkXtBin *xtbin; gpointer user_data; GdkScreen *screen; GdkVisual* visual; Colormap colormap; GdkWindow* parent_window = gtk_widget_get_window(parent_widget); assert(parent_window != NULL); xtbin = g_object_new (GTK_TYPE_XTBIN, NULL); if (!xtbin) return (GtkWidget*)NULL; if (f) fallback = f; /* Initialize the Xt toolkit */ xtbin->parent_window = parent_window; screen = gtk_widget_get_screen(parent_widget); visual = gdk_screen_get_system_visual(screen); colormap = XCreateColormap(GDK_DISPLAY_XDISPLAY(gdk_screen_get_display(screen)), GDK_WINDOW_XWINDOW(gdk_screen_get_root_window(screen)), GDK_VISUAL_XVISUAL(visual), AllocNone); xt_client_init(&(xtbin->xtclient), GDK_VISUAL_XVISUAL(visual), colormap, gdk_visual_get_depth(visual)); if (!xtbin->xtclient.xtdisplay) { /* If XtOpenDisplay failed, we can't go any further. * Bail out. */ #ifdef DEBUG_XTBIN printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n"); #endif g_free (xtbin); return (GtkWidget *)NULL; } /* If this is the first running widget, hook this display into the mainloop */ if (0 == num_widgets) { int cnumber; /* * hook Xt event loop into the glib event loop. */ /* the assumption is that gtk_init has already been called */ GSource* gs = g_source_new(&xt_event_funcs, sizeof(GSource)); if (!gs) { return NULL; } g_source_set_priority(gs, GDK_PRIORITY_EVENTS); g_source_set_can_recurse(gs, TRUE); tag = g_source_attach(gs, (GMainContext*)NULL); #ifdef VMS cnumber = XConnectionNumber(xtdisplay); #else cnumber = ConnectionNumber(xtdisplay); #endif xt_event_poll_fd.fd = cnumber; xt_event_poll_fd.events = G_IO_IN; xt_event_poll_fd.revents = 0; /* hmm... is this correct? */ g_main_context_add_poll ((GMainContext*)NULL, &xt_event_poll_fd, G_PRIORITY_LOW); /* add a timer so that we can poll and process Xt timers */ xt_polling_timer_id = g_timeout_add(25, (GSourceFunc)xt_event_polling_timer_callback, xtdisplay); } /* Bump up our usage count */ num_widgets++; /* Build the hierachy */ xtbin->xtdisplay = xtbin->xtclient.xtdisplay; gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window); gdk_window_get_user_data(xtbin->parent_window, &user_data); if (user_data) gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin)); return GTK_WIDGET (xtbin); }
nsresult nsPluginNativeWindowGtk::CreateXEmbedWindow(bool aEnableXtFocus) { NS_ASSERTION(!mSocketWidget,"Already created a socket widget!"); GdkDisplay *display = gdk_display_get_default(); GdkWindow *parent_win = gdk_x11_window_lookup_for_display(display, GetWindow()); mSocketWidget = gtk_socket_new(); //attach the socket to the container widget gtk_widget_set_parent_window(mSocketWidget, parent_win); // enable/disable focus event handlers, // see plugin_window_filter_func() for details g_object_set_data(G_OBJECT(mSocketWidget), "enable-xt-focus", (void *)aEnableXtFocus); // Make sure to handle the plug_removed signal. If we don't the // socket will automatically be destroyed when the plug is // removed, which means we're destroying it more than once. // SYNTAX ERROR. g_signal_connect(mSocketWidget, "plug_removed", G_CALLBACK(plug_removed_cb), nullptr); g_signal_connect(mSocketWidget, "unrealize", G_CALLBACK(socket_unrealize_cb), nullptr); g_signal_connect(mSocketWidget, "destroy", G_CALLBACK(gtk_widget_destroyed), &mSocketWidget); gpointer user_data = nullptr; gdk_window_get_user_data(parent_win, &user_data); GtkContainer *container = GTK_CONTAINER(user_data); gtk_container_add(container, mSocketWidget); gtk_widget_realize(mSocketWidget); // The GtkSocket has a visible window, but the plugin's XEmbed plug will // cover this window. Normally GtkSockets let the X server paint their // background and this would happen immediately (before the plug is // created). Setting the background to None prevents the server from // painting this window, avoiding flicker. // TODO GTK3 #if (MOZ_WIDGET_GTK == 2) gdk_window_set_back_pixmap(gtk_widget_get_window(mSocketWidget), nullptr, FALSE); #endif // Resize before we show SetAllocation(); gtk_widget_show(mSocketWidget); gdk_flush(); SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget))); // Fill out the ws_info structure. // (The windowless case is done in nsPluginFrame.cpp.) GdkWindow *gdkWindow = gdk_x11_window_lookup_for_display(display, GetWindow()); if(!gdkWindow) return NS_ERROR_FAILURE; mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow); #if (MOZ_WIDGET_GTK == 2) mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow)); GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow); mWsInfo.depth = gdkVisual->depth; #else mWsInfo.colormap = None; GdkVisual* gdkVisual = gdk_window_get_visual(gdkWindow); mWsInfo.depth = gdk_visual_get_depth(gdkVisual); #endif mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual); return NS_OK; }
RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify) : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow))) , m_window(0) , m_parentWindow(0) , m_pixmap(0) , m_damage(0) , m_needsNewPixmapAfterResize(false) { Screen* screen = DefaultScreenOfDisplay(m_display); GdkVisual* visual = gdk_window_get_visual(parentWindow); Colormap colormap = XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone); // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc XSetWindowAttributes windowAttributes; windowAttributes.override_redirect = True; windowAttributes.colormap = colormap; // CWBorderPixel must be present when the depth doesn't match the parent's one. // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703. windowAttributes.border_pixel = 0; m_parentWindow = XCreateWindow(m_display, RootWindowOfScreen(screen), WidthOfScreen(screen) + 1, 0, 1, 1, 0, gdk_visual_get_depth(visual), InputOutput, GDK_VISUAL_XVISUAL(visual), CWOverrideRedirect | CWColormap | CWBorderPixel, &windowAttributes); XMapWindow(m_display, m_parentWindow); windowAttributes.event_mask = StructureNotifyMask; windowAttributes.override_redirect = False; // Create the window of at last 1x1 since X doesn't allow to create empty windows. m_window = XCreateWindow(m_display, m_parentWindow, 0, 0, std::max(1, m_size.width()), std::max(1, m_size.height()), 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &windowAttributes); XMapWindow(m_display, m_window); XFreeColormap(m_display, colormap); xDamageNotifier().add(m_window, WTF::move(damageNotify)); while (1) { XEvent event; XWindowEvent(m_display, m_window, StructureNotifyMask, &event); if (event.type == MapNotify && event.xmap.window == m_window) break; } XSelectInput(m_display, m_window, NoEventMask); XCompositeRedirectWindow(m_display, m_window, CompositeRedirectManual); m_damage = XDamageCreate(m_display, m_window, XDamageReportNonEmpty); }
RedirectedXCompositeWindow::RedirectedXCompositeWindow(WebPageProxy& webPage, const IntSize& initialSize, std::function<void()>&& damageNotify) : m_webPage(webPage) , m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(gtk_widget_get_parent_window(webPage.viewWidget())))) , m_size(initialSize) { m_size.scale(m_webPage.deviceScaleFactor()); ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display); Screen* screen = DefaultScreenOfDisplay(m_display); GdkVisual* visual = gdk_window_get_visual(gtk_widget_get_parent_window(webPage.viewWidget())); XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone)); // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc XSetWindowAttributes windowAttributes; windowAttributes.override_redirect = True; windowAttributes.colormap = colormap.get(); // CWBorderPixel must be present when the depth doesn't match the parent's one. // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703. windowAttributes.border_pixel = 0; m_parentWindow = XCreateWindow(m_display, RootWindowOfScreen(screen), WidthOfScreen(screen) + 1, 0, 1, 1, 0, gdk_visual_get_depth(visual), InputOutput, GDK_VISUAL_XVISUAL(visual), CWOverrideRedirect | CWColormap | CWBorderPixel, &windowAttributes); XMapWindow(m_display, m_parentWindow.get()); windowAttributes.event_mask = StructureNotifyMask; windowAttributes.override_redirect = False; // Create the window of at last 1x1 since X doesn't allow to create empty windows. m_window = XCreateWindow(m_display, m_parentWindow.get(), 0, 0, std::max(1, m_size.width()), std::max(1, m_size.height()), 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &windowAttributes); XMapWindow(m_display, m_window.get()); xDamageNotifier().add(m_window.get(), WTFMove(damageNotify)); while (1) { XEvent event; XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event); if (event.type == MapNotify && event.xmap.window == m_window.get()) break; } XSelectInput(m_display, m_window.get(), NoEventMask); XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual); if (!m_size.isEmpty()) createNewPixampAndPixampSurface(); m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty); }
int wxDisplayDepth() { return gdk_visual_get_depth(gtk_widget_get_visual(wxGetRootWindow())); }