Added command and keybinds to zoom the page.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 17 Feb 2013 16:57:02 +0000 (17:57 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 17 Feb 2013 16:57:02 +0000 (17:57 +0100)
doc/vimp.1.txt
src/command.c
src/command.h
src/config.h

index 84e3273..9bef515 100644 (file)
@@ -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
index d695de7..8f5d621 100644 (file)
@@ -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;
index 0492bd6..b09cf88 100644 (file)
@@ -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 */
index 7f852e7..13e8fec 100644 (file)
@@ -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 <tab>=complete"},
     {"cmap <shift-tab>=complete-back"},
     {"hmap <tab>=hint-focus-next"},