forked from pschultz/kiosk-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.c
83 lines (64 loc) · 1.93 KB
/
browser.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <signal.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <webkit/webkit.h>
gboolean on_key_press(GtkWidget*, GdkEventKey*, gpointer);
void reload_browser(int);
void toggle_fullscreen(int);
void maximize();
void unmaximize();
static WebKitWebView* web_view;
static GtkWidget *window;
gchar* default_url = "https://github.com/pschultz/kiosk-browser/blob/master/README.md";
int main(int argc, char** argv) {
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
signal(SIGHUP, reload_browser);
signal(SIGUSR1, toggle_fullscreen);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(web_view));
if(argc > 1) {
webkit_web_view_load_uri(web_view, argv[1]);
}
else {
webkit_web_view_load_uri(web_view, default_url);
}
maximize();
gtk_widget_show_all(window);
gtk_main();
return 0;
}
gboolean on_key_press(GtkWidget* window, GdkEventKey* key, gpointer userdata) {
if(key->type == GDK_KEY_PRESS && key->keyval == GDK_F5) {
reload_browser(0);
}
else if(key->type == GDK_KEY_PRESS && key->keyval == GDK_F11) {
toggle_fullscreen(0);
}
return FALSE;
}
void reload_browser(int signum) {
webkit_web_view_reload_bypass_cache(web_view);
}
void toggle_fullscreen(int signum) {
if(gtk_window_get_decorated(GTK_WINDOW(window))) {
maximize();
}
else {
unmaximize();
}
}
void maximize() {
gtk_window_maximize(GTK_WINDOW(window));
gtk_window_fullscreen(GTK_WINDOW(window));
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
}
void unmaximize() {
gtk_window_unmaximize(GTK_WINDOW(window));
gtk_window_unfullscreen(GTK_WINDOW(window));
gtk_window_set_decorated(GTK_WINDOW(window), TRUE);
gtk_window_resize(GTK_WINDOW(window), 1280, 768);
}