X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=b69c615b4f377c054420e6f78e3ba0243fdbb7d5;hb=0dfdb75804315678fb22e9703b3e48f5c2b8e1cd;hp=a090dc879b2e43dc7d539134d331ae9e4934cacd;hpb=5501d75d2c97398d3ffddb200061cb93cc90bac3;p=surf.git diff --git a/surf.c b/surf.c index a090dc8..b69c615 100644 --- a/surf.c +++ b/surf.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ typedef struct Client { gint progress; gboolean sslfailed; struct Client *next; - gboolean zoomed; + gboolean zoomed, fullscreen; } Client; typedef struct { @@ -100,6 +101,7 @@ static void die(char *str); static void drawindicator(Client *c); static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c); static void find(Client *c, const Arg *arg); +static void fullscreen(Client *c, const Arg *arg); static const char *getatom(Client *c, int a); static char *geturi(Client *c); static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c); @@ -398,6 +400,16 @@ find(Client *c, const Arg *arg) { webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE); } +void +fullscreen(Client *c, const Arg *arg) { + if(c->fullscreen) { + gtk_window_unfullscreen(GTK_WINDOW(c->win)); + } else { + gtk_window_fullscreen(GTK_WINDOW(c->win)); + } + c->fullscreen = !c->fullscreen; +} + const char * getatom(Client *c, int a) { static char buf[BUFSIZ]; @@ -497,14 +509,23 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { void loaduri(Client *c, const Arg *arg) { - char *u; + char *u, *rp; const char *uri = (char *)arg->v; Arg a = { .b = FALSE }; if(strcmp(uri, "") == 0) return; - u = g_strrstr(uri, "://") ? g_strdup(uri) - : g_strdup_printf("http://%s", uri); + + /* In case it's a file path. */ + if(uri[0] == '/') { + rp = realpath(uri, NULL); + u = g_strdup_printf("file://%s", rp); + free(rp); + } else { + u = g_strrstr(uri, "://") ? g_strdup(uri) + : g_strdup_printf("http://%s", uri); + } + /* prevents endless loop */ if(c->uri && strcmp(u, c->uri) == 0) { reload(c, &a); @@ -976,11 +997,14 @@ windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObje void zoom(Client *c, const Arg *arg) { c->zoomed = TRUE; - if(arg->i < 0) /* zoom out */ + if(arg->i < 0) { + /* zoom out */ webkit_web_view_zoom_out(c->view); - else if(arg->i > 0) /* zoom in */ + } else if(arg->i > 0) { + /* zoom in */ webkit_web_view_zoom_in(c->view); - else { /* reset */ + } else { + /* reset */ c->zoomed = FALSE; webkit_web_view_set_zoom_level(c->view, 1.0); }