commit: edf9a89dad1649771779759d23ea5baa0924f601
parent: a33ff308ee2e28c8240a54384eb32e3dc1d11690
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 11 May 2019 04:17:13 +0200
Merge branch 'features/zoom_ctrl+scroll' into develop
Diffstat:
M | badwolf.1 | 12 | +++++++++++- |
M | badwolf.c | 59 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
2 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/badwolf.1 b/badwolf.1
@@ -18,7 +18,15 @@ Runtime configuration specific to
.Nm
will probably get added at a later release.
.Sh KEYBINDINGS
-For now it only has the default Webkit/GTK keybindings, which notably are (C for Control, S for Shift):
+The following section lists the keybinding by their action, each item is described by the widget the focus is on or
+.Aq any
+if it works for the whole window, followed by the keybind it grabs. C is short for Control, S is short for Shift.
+.Bl -width Ds -tag
+.It webview C-Scroll
+Zooms the webpage in/out.
+.El
+.Ss DEFAULT ONES
+Here is a incomplete list of the default Webkit/GTK keybindings:
.Bl -width Ds -tag
.It any C-PageUp / C-PageDown
Go to the previous/next tab
@@ -36,6 +44,8 @@ Reloads the current tab (with/without clearing cache)
Go back/forward in current tab’s history
.It search C-g / C-S-g
When the search box is focused it goes to the Next/Previous search term.
+.It search Escape
+Cancels current search
.El
.Sh BUGS
You can submit contributions or tickets to
diff --git a/badwolf.c b/badwolf.c
@@ -11,7 +11,7 @@
#include <webkit2/webkit2.h>
const gchar *homepage = "https://hacktivis.me/projects/badwolf";
-const gchar *version = "0.1.1";
+const gchar *version = "0.1.1";
struct Window
{
@@ -113,6 +113,15 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data)
return TRUE;
}
+/* commonCb_key_press_event: Global callback for keybindings
+ *
+ * Theses shortcuts should be avoided as much as possible:
+ * - Single key shortcuts (ie. backspace and space)
+ * - Triple key shortcuts (except for Ctrl+Shift)
+ * - Unix Terminal shortcuts (specially Ctrl-W)
+ *
+ * loosely follows https://developer.gnome.org/hig/stable/keyboard-input.html
+ */
static gboolean
commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser)
{
@@ -136,6 +145,9 @@ commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *
case GDK_KEY_l: gtk_widget_grab_focus(browser->location); return TRUE;
case GDK_KEY_bracketleft: webkit_web_view_go_back(browser->webView); return TRUE;
case GDK_KEY_bracketright: webkit_web_view_go_forward(browser->webView); return TRUE;
+ case GDK_KEY_0:
+ webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(browser->webView), 1);
+ return TRUE;
}
}
else
@@ -148,9 +160,29 @@ commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *
}
}
}
- else if(((GdkEventKey *)event)->keyval == GDK_KEY_F1)
+
+ if((((GdkEventKey *)event)->state & GDK_MOD1_MASK) && brower != NULL)
+ {
+ switch(((GdkEventKey *)event)->keyval)
+ {
+ case GDK_KEY_Left: gtk_notebook_prev_page(notebook); return TRUE;
+ case GDK_KEY_Right: gtk_notebook_next_page(notebook); return TRUE;
+ }
+ }
+
+ if(browser != NULL)
+ {
+ switch(((GdkEventKey *)event)->keyval)
+ {
+ case GDK_KEY_F5: webkit_web_view_reload(browser->webView); return TRUE;
+ }
+ }
+ else
{
- badwolf_about_dialog(GTK_WINDOW(window->main_window));
+ switch(((GdkEventKey *)event)->keyval)
+ {
+ case GDK_KEY_F1: badwolf_about_dialog(GTK_WINDOW(window->main_window)); return TRUE;
+ }
}
return FALSE;
@@ -351,6 +383,26 @@ WebViewCb_mouse_target_changed(WebKitWebView *webView,
return TRUE;
}
+static gboolean
+WebViewCb_scroll_event(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ (void)widget;
+ struct Client *browser = (struct Client *)data;
+ gdouble delta_x, delta_y;
+ gfloat zoom;
+
+ if(((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
+ {
+ gdk_event_get_scroll_deltas(event, &delta_x, &delta_y);
+ zoom = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(browser->webView));
+ zoom -= delta_y * 0.1;
+ webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(browser->webView), zoom);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static WebKitWebView *
WebViewCb_create(WebKitWebView *related_web_view,
WebKitNavigationAction *navigation_action,
@@ -546,6 +598,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web
g_signal_connect(browser->webView, "close", G_CALLBACK(WebViewCb_close), browser);
g_signal_connect(
browser->webView, "key-press-event", G_CALLBACK(WebViewCb_key_press_event), browser);
+ g_signal_connect(browser->webView, "scroll-event", G_CALLBACK(WebViewCb_scroll_event), browser);
g_signal_connect(browser->search, "next-match", G_CALLBACK(SearchEntryCb_next__match), browser);
g_signal_connect(