-
Notifications
You must be signed in to change notification settings - Fork 4
/
transparent.c
58 lines (45 loc) · 1.69 KB
/
transparent.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <gtk/gtk.h>
#include <webkit/webkit.h>
static void destroy_cb(GtkWidget* widget, gpointer data) {
gtk_main_quit();
}
int main(int argc, char* argv[]) {
gtk_init(&argc, &argv);
if (argc == 1) {
printf("Usage: URI\n");
return 1;
}
const char *uri = argv[1];
if(!g_thread_supported())
g_thread_init(NULL);
// Create a Window, set colormap to RGBA
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GdkScreen *screen = gtk_widget_get_screen(window);
#if GTK_CHECK_VERSION(3, 0, 0)
GdkVisual *visual = gdk_screen_get_rgba_visual(screen);
if (visual && gdk_screen_is_composited (screen)) {
gtk_widget_set_visual(GTK_WIDGET(window), visual);
}
#else
GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);s
if (rgba && gdk_screen_is_composited (screen)) {
gtk_widget_set_default_colormap(rgba);
gtk_widget_set_default_colormap(rgba);
}
#endif
gtk_window_set_default_size(GTK_WINDOW(window), 600, 400);
g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
// Optional: for dashboard style borderless windows
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
// Create a WebView, set it transparent, add it to the window
WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
webkit_web_view_set_transparent(web_view, TRUE);
gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view));
// Load a default page
webkit_web_view_load_uri(web_view, uri);
// Show it and continue running until the window closes
gtk_widget_grab_focus(GTK_WIDGET(web_view));
gtk_widget_show_all(window);
gtk_main();
return 0;
}