WM-independent fullscreen WebKit launcher


SUBMITTED BY: Guest

DATE: March 22, 2013, 8:15 a.m.

FORMAT: C++

SIZE: 1.8 kB

HITS: 1594

  1. #include <gtk/gtk.h>
  2. #include <gdk/gdk.h>
  3. #include <webkit/webkit.h>
  4. void main(int argc, char *argv[]) {
  5. gtk_init(NULL, NULL);
  6. GtkWindow *main_window = (GtkWindow *)gtk_window_new(GTK_WINDOW_TOPLEVEL);
  7. WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
  8. g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
  9. WebKitWebSettings *settings = webkit_web_settings_new();
  10. gchar *true_settings[] = {"enable-fullscreen", "enable-accelerated-compositing", "enable-spatial-navigation", "enable-page-cache", "enable-html5-local-storage", "enable-html5-database", "enable-file-access-from-file-uris", "javascript-can-access-clipboard", "enable-webaudio", "enable-dom-paste", "enable-webgl", NULL},
  11. *false_settings[] = {"resizable-text-areas", "auto-resize-window", "enable-java-applet","tab-key-cycles-through-elements","enable-default-context-menu", NULL}, **p;
  12. for(p=(gchar **)true_settings;*p;p++) g_object_set(G_OBJECT(settings), *p, TRUE, NULL);
  13. for(p=(gchar **)false_settings;*p;p++) g_object_set(G_OBJECT(settings), *p, FALSE, NULL);
  14. g_object_set(G_OBJECT(settings), "default-encoding", "utf-8", NULL);
  15. webkit_web_view_set_settings (WEBKIT_WEB_VIEW(webView), settings);
  16. gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView));
  17. webkit_web_view_load_uri(webView, argc>1?argv[1]:"about:blank");
  18. gtk_window_fullscreen(main_window);
  19. gint screenw=0, screenh=0;
  20. gdk_window_get_size(gdk_screen_get_root_window(gdk_screen_get_default()), &screenw, &screenh);
  21. gtk_window_set_default_size(main_window, screenw, screenh);
  22. gtk_widget_show_all(GTK_WIDGET(main_window));
  23. gtk_window_set_resizable(main_window, FALSE);
  24. gtk_main();
  25. }

comments powered by Disqus