From: Daniel Carl Date: Sun, 17 Feb 2013 16:57:02 +0000 (+0100) Subject: Added command and keybinds to zoom the page. X-Git-Url: https://git.owens.tech/about.html/about.html/git?a=commitdiff_plain;h=9fddbf3ab96859b41d69915781f2492b55af0ba0;p=vimb.git Added command and keybinds to zoom the page. --- diff --git a/doc/vimp.1.txt b/doc/vimp.1.txt index 84e3273..9bef515 100644 --- a/doc/vimp.1.txt +++ b/doc/vimp.1.txt @@ -299,10 +299,23 @@ Show the current set value of variable Toggle the value of boolean variable .I VAR and display the new set value. +.SS Zoom +.TP +.BI [ N "]zoom{" "in" ", " "out" "}" +Zoom \fIN\fP steps \fIin\fP or \fIout\fP of the current page \- effects only the text. +.TP +.BI [ N "]zoom{" "in" ", " "out" "}full" +Zoom \fIN\fP steps \fIin\fP or \fIout\fP of the current page \- effecting all elements. +.TP +.B zoomreset +Reset the zoomlevel to the default value. .SS Misc .TP -.BI "[" "N" "]search-{forward, backward}" -Search in current page forward or backward. +.BI "[" "N" "]search-{" forward ", " "backward" "}" +Search in current page +.I forward +or +.IR backward . .TP .B inspect Toggles the webinspector for current page. This is only available if the config diff --git a/src/command.c b/src/command.c index d695de7..8f5d621 100644 --- a/src/command.c +++ b/src/command.c @@ -84,6 +84,11 @@ static CommandInfo cmd_list[] = { {"search-backward", command_search, {VP_SEARCH_BACKWARD}}, {"searchengine-add", command_searchengine,{1}}, {"searchengine-remove", command_searchengine,{0}}, + {"zoomin", command_zoom, {COMMAND_ZOOM_IN}}, + {"zoomout", command_zoom, {COMMAND_ZOOM_OUT}}, + {"zoominfull", command_zoom, {COMMAND_ZOOM_IN | COMMAND_ZOOM_FULL}}, + {"zoomoutfull", command_zoom, {COMMAND_ZOOM_OUT | COMMAND_ZOOM_FULL}}, + {"zoomreset", command_zoom, {COMMAND_ZOOM_RESET}}, }; static void command_write_input(const char* str); @@ -488,6 +493,39 @@ gboolean command_searchengine(const Arg* arg) return result; } +gboolean command_zoom(const Arg* arg) +{ + float step, level; + int count; + + if (arg->i & COMMAND_ZOOM_RESET) { + webkit_web_view_set_zoom_level(vp.gui.webview, 1.0); + vp_set_mode(VP_MODE_NORMAL, FALSE); + + return TRUE; + } + + count = vp.state.count ? vp.state.count : 1; + level = webkit_web_view_get_zoom_level(vp.gui.webview); + + WebKitWebSettings* setting = webkit_web_view_get_settings(vp.gui.webview); + g_object_get(G_OBJECT(setting), "zoom-step", &step, NULL); + + webkit_web_view_set_full_content_zoom( + vp.gui.webview, (arg->i & COMMAND_ZOOM_FULL) > 0 + ); + + webkit_web_view_set_zoom_level( + vp.gui.webview, + level + (float)(count *step) * (arg->i & COMMAND_ZOOM_IN ? 1.0 : -1.0) + ); + + vp_set_mode(VP_MODE_NORMAL, FALSE); + + return TRUE; + +} + static void command_write_input(const char* str) { int pos = 0; diff --git a/src/command.h b/src/command.h index 0492bd6..b09cf88 100644 --- a/src/command.h +++ b/src/command.h @@ -27,6 +27,13 @@ enum { COMMAND_YANK_SELECTION = (COMMAND_YANK_SECONDARY<<2) }; +enum { + COMMAND_ZOOM_OUT, + COMMAND_ZOOM_IN, + COMMAND_ZOOM_FULL = (1<<1), + COMMAND_ZOOM_RESET = (1<<2) +}; + typedef gboolean (*Command)(const Arg* arg); typedef struct { @@ -60,5 +67,6 @@ gboolean command_yank(const Arg* arg); gboolean command_paste(const Arg* arg); gboolean command_search(const Arg* arg); gboolean command_searchengine(const Arg* arg); +gboolean command_zoom(const Arg* arg); #endif /* end of include guard: _COMMAND_H */ diff --git a/src/config.h b/src/config.h index 7f852e7..13e8fec 100644 --- a/src/config.h +++ b/src/config.h @@ -73,6 +73,11 @@ const struct { {"nmap Y=yank-selection"}, {"nmap p=open-clipboard"}, {"nmap P=tabopen-clipboard"}, + {"nmap zi=zoomin"}, + {"nmap zI=zoominfull"}, + {"nmap zo=zoomout"}, + {"nmap zO=zoomoutfull"}, + {"nmap zz=zoomreset"}, {"cmap =complete"}, {"cmap =complete-back"}, {"hmap =hint-focus-next"},