logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: 47c494da006c5a034f2cf3b26299c0edf46a840b
parent: 8806bcb782b2e3e415007441ee37858791dd2ad1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 26 Apr 2019 21:09:23 +0200

Add window-wide keybinds

Diffstat:

Mbadwolf.12+-
Mbadwolf.c67+++++++++++++++++++++++++++++++++++++++++++++----------------------
2 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/badwolf.1 b/badwolf.1 @@ -32,7 +32,7 @@ Reloads the current tab (with/without clearing cache) Focuses on the search entry .It webview C-l Focuses on the location(URL) entry -.It webview C-t +.It window C-t, webview C-t Creates a new tab (unrelated, similar as pressing the button) .It webview C-[ / C-] Go back/forward in current tab’s history diff --git a/badwolf.c b/badwolf.c @@ -34,9 +34,12 @@ struct Client }; static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); -static gboolean commonCb_key_press_event(struct Client *browser, GdkEvent *event); +static gboolean +commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser); static gboolean WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data); +static gboolean +main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, gpointer user_data); @@ -90,31 +93,38 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data) } static gboolean -commonCb_key_press_event(struct Client *browser, GdkEvent *event) +commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser) { - GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook); + GtkNotebook *notebook = GTK_NOTEBOOK(window->notebook); if(((GdkEventKey *)event)->state & GDK_CONTROL_MASK) { - switch(((GdkEventKey *)event)->keyval) + if(browser != NULL) + { + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_F4: webkit_web_view_try_close(browser->webView); return TRUE; + case GDK_KEY_r: + if(((GdkEventKey *)event)->state & GDK_SHIFT_MASK) + webkit_web_view_reload_bypass_cache(browser->webView); + else + webkit_web_view_reload(browser->webView); + + return TRUE; + case GDK_KEY_f: gtk_widget_grab_focus(browser->search); return TRUE; + 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; + } + } + else { - case GDK_KEY_F4: webkit_web_view_try_close(browser->webView); return TRUE; - case GDK_KEY_r: - if(((GdkEventKey *)event)->state & GDK_SHIFT_MASK) - webkit_web_view_reload_bypass_cache(browser->webView); - else - webkit_web_view_reload(browser->webView); - - return TRUE; - case GDK_KEY_f: gtk_widget_grab_focus(browser->search); return TRUE; - case GDK_KEY_l: gtk_widget_grab_focus(browser->location); return TRUE; - case GDK_KEY_Page_Down: gtk_notebook_next_page(notebook); return TRUE; - case GDK_KEY_Page_Up: gtk_notebook_prev_page(notebook); return TRUE; - case GDK_KEY_t: - badwolf_new_tab(notebook, new_browser(browser->window, NULL, NULL)); - 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; + switch(((GdkEventKey *)event)->keyval) + { + case GDK_KEY_Page_Down: gtk_notebook_next_page(notebook); return TRUE; + case GDK_KEY_Page_Up: gtk_notebook_prev_page(notebook); return TRUE; + case GDK_KEY_t: badwolf_new_tab(notebook, new_browser(window, NULL, NULL)); return TRUE; + } } } @@ -127,12 +137,22 @@ WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user (void)webView; struct Client *browser = (struct Client *)user_data; - if(commonCb_key_press_event(browser, event)) return TRUE; + if(commonCb_key_press_event(browser->window, event, browser)) return TRUE; return FALSE; } static gboolean +main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + (void)widget; + struct Window *window = (struct Window *)user_data; + + if(commonCb_key_press_event(window, event, NULL)) return TRUE; + + return FALSE; +} +static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, gpointer user_data) @@ -605,6 +625,9 @@ main(int argc, char *argv[]) badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url, NULL)); + g_signal_connect( + window->main_window, "key-press-event", G_CALLBACK(main_windowCb_key_press_event), window); + g_signal_connect(window->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(window->new_tab, "clicked", G_CALLBACK(new_tabCb_clicked), window); g_signal_connect(window->notebook, "switch-page", G_CALLBACK(notebookCb_switch__page), window);