[webkit-gtk] Fwd: webview failed to be transparent

Jianhua Shao alex.sjh at gmail.com
Wed Apr 24 00:35:20 PDT 2013

I build webkitgtk 1.9.92 by below configuration
./configure --prefix=/usr --enable-accelerated-compositing
--enable-fast-mobile-scrolling --enable-jit --disable-webkit2
--disable-plugin-process --disable-gtk-doc-html --with-gtk=2.0

After that, I write a simple app to make the content of webview transparent
by calling webkit_web_view_set_transparent(). But it failed.
I tryied version 1.11.5, it also does not work.
The same app source code works in a old version of gtk-webkit, AFAIK, it
was about gtk-webkit 1.3.

Why I want to a build a new version of gtk-webkit, is to use the
compositing accelerating feature.

Anyone know something about this problem?

The test code is here:
-----------app code---------
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <webkit/webkit.h>
#include <stdlib.h>
#include <string.h>
static void destroy_cb(GtkWidget* widget, gpointer data) {

bool transparent = true;
bool decorate = false;
int width = 800;
int height = 480;
gchar * url = "/home/meego/httproot/htdocs/hmi/hmi/index.html";
char *window_name = "HMI";
WebKitWebView* view;
GdkColormap* rgba;
GdkScreen* screen;

gint key_press_cb(GtkWidget *widget, GdkEventKey *kevent, gpointer data)  {
    GtkWidget *btn = (GtkWidget *)data;

    if(kevent->type == GDK_KEY_PRESS && kevent->keyval == 'p')  {

        GdkPixbuf * pixbuf;
        pixbuf = gdk_pixbuf_get_from_drawable( NULL,
GTK_WIDGET(view)->window, rgba, 0, 0, 0, 0, 600, 400 );
        gdk_pixbuf_save(pixbuf, "/home/meego/dump.png", "png", NULL, NULL);
        printf("colormap is %s\n", rgba ? "not NULL" : "NULL");
        printf("screen %s compoisted\n", gdk_screen_is_composited(screen)?
"is" : "is not");
        printf("webview %s transparent\n",
webkit_web_view_get_transparent(view) ? "is" : "is not");
    return TRUE;

static gboolean window_delete_event(GtkWidget *widget, GdkEvent  *event,
gpointer user_data)
    return TRUE;

int main(int argc, char* argv[]) {
    int ret;

    if(argc >= 2) {
        url = argv[1];
    gtk_init(&argc, &argv);

    // Create a Window, set colormap to RGBA
    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    screen = gtk_widget_get_screen(window);
    rgba = gdk_screen_get_rgba_colormap (screen);

    gtk_window_set_title(GTK_WINDOW(window), (const gchar*)window_name);
    if (rgba && gdk_screen_is_composited (screen)) {
        gtk_widget_set_colormap(GTK_WIDGET(window), rgba);

    gtk_widget_set_size_request(window, width, height);

        gtk_window_set_decorated(GTK_WINDOW(window), FALSE);

    view = WEBKIT_WEB_VIEW(webkit_web_view_new());
    gtk_widget_set_colormap(GTK_WIDGET(view), rgba);
    if(transparent) {
        if(gdk_screen_is_composited(screen)) {
            printf("set transparent\n");
            webkit_web_view_set_transparent(view, TRUE);

    WebKitWebSettings *settings = webkit_web_settings_new();

    if(NULL == settings) {
        return -1;
    } else {
        g_object_set (G_OBJECT(settings),
"enable-file-access-from-file-uris", TRUE, NULL);
        g_object_set (G_OBJECT(settings), "enable-default-context-menu",
        webkit_web_view_set_settings (WEBKIT_WEB_VIEW(view), settings);
    gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(view));

    g_signal_connect(window, "delete-event",
G_CALLBACK(window_delete_event), NULL);
    g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);

    g_signal_connect(G_OBJECT(window), "key_press_event",
G_CALLBACK(key_press_cb), window);
    //g_signal_emit_by_name(G_OBJECT(window), "activate", NULL);

    // Load a default page
    if (g_str_has_prefix(url, "http://")
            || g_str_has_prefix(url, "https://")
            || g_str_has_prefix(url, "file://"))
        webkit_web_view_open(WEBKIT_WEB_VIEW(view), url);
    } else {
        gchar *t_url = NULL;
        if (g_path_is_absolute(url)) {
            t_url = g_strjoin("", "file://", url, NULL);
        } else {
            gchar *pwd = g_get_current_dir();
            t_url = g_strjoin("/", "file://", pwd, url, NULL);
        webkit_web_view_open(WEBKIT_WEB_VIEW(view), t_url);

    return 0;

-----------html code-----------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Transparency Test</title>
  <style type="text/css">
    body { background: rgba(220, 220, 0, .5); }
    Text on a yellowish, semi-transparent background.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-gtk/attachments/20130424/c56eeda3/attachment-0001.html>

More information about the webkit-gtk mailing list