diff options
author | Peter Hofmann <scm@uninformativ.de> | 2014-06-19 07:48:38 +0200 |
---|---|---|
committer | Peter Hofmann <scm@uninformativ.de> | 2014-06-19 08:42:26 +0200 |
commit | 65d6f54d22a37a686b10afc4f6b2af48c9f98195 (patch) | |
tree | 273b7042a76ad5fe971c2ea9474c7300050432a5 | |
parent | 2909ad56b93d262c08b25dee25918b079adce657 (diff) | |
download | lariza-65d6f54d22a37a686b10afc4f6b2af48c9f98195.tar.gz |
Rework and extend hotkeys
hjkl is nice in a terminal, but it poses a problem in GUI programs: If
your program is not ENTIRELY controlled via keyboard, your right hand
has to reach from the mouse to the keyboard to the mouse to the
keyboard... That's nasty.
Now, all hotkeys can be hit using your left hand.
I also think that using Control as a modifier is uncomfortable. Your
pinkie has to do a lot of work and stays in an uncomfortable position.
Using Alt/Mod1 feels better.
Secondly, there's no need for scrolling hotkeys. This only makes sense
if your program has keyboard-only usage. I can scroll using the mouse
(plus, I have screen barriers to support this).
Furthermore, there's a hotkey now that enters search mode and hotkeys to
create or destroy windows/tabs.
I also differentiate between single-handed hotkeys and dual-handed
hotkeys. When you enter the location bar or search mode, you are going
to begin typing -- thus, your right hand MUST move from the mouse to the
keyboard. As a result, it doesn't make sense to make these hotkeys
reachable using only your left hand. Mod1+l to enter the location bar is
totally fine and so is Mod1+k for searching.
Of course, it's more comfortable if you can also close the download
manager using Mod1+q. Reloading is useful as well and I NEVER want to
have "reload WITH using the cache" (major annoyance of other browsers).
To sum it up, your left hand can stay relaxed over q, w, e, d.
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | browser.c | 181 |
2 files changed, 101 insertions, 82 deletions
@@ -13,7 +13,7 @@ Features: - Global content zoom - Pluggability into suckless' tabbed - Built-in downloads - - vi-like scrolling (modified by CTRL) + - Optimized hotkeys: Left hand on keyboard, right hand on mouse - Searching the current page for a word - Adblock - Support for Flash and Java @@ -37,11 +37,11 @@ static void downloadmanager_setup(void); static gchar *ensure_url_scheme(const gchar *); static void grab_environment_configuration(void); static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer); +static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer); static gboolean key_location(GtkWidget *, GdkEvent *, gpointer); static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer); static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer); static void search(gpointer, gint); -static void scroll(GtkAdjustment *, gint, gdouble); static Window tabbed_launch(void); static void usage(void); @@ -517,6 +517,8 @@ downloadmanager_setup(void) gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager"); g_signal_connect(G_OBJECT(dm.win), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL); + g_signal_connect(G_OBJECT(dm.win), "key-press-event", + G_CALLBACK(key_downloadmanager), NULL); dm.toolbar = gtk_toolbar_new(); gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar), @@ -589,6 +591,28 @@ hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri, gpointer data) } gboolean +key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + (void)widget; + (void)data; + + if (event->type == GDK_KEY_PRESS) + { + if (((GdkEventKey *)event)->state & GDK_MOD1_MASK) + { + switch (((GdkEventKey *)event)->keyval) + { + case GDK_KEY_q: /* close window (left hand) */ + gtk_widget_hide(dm.win); + return TRUE; + } + } + } + + return FALSE; +} + +gboolean key_location(GtkWidget *widget, GdkEvent *event, gpointer data) { struct Client *c = (struct Client *)data; @@ -599,40 +623,55 @@ key_location(GtkWidget *widget, GdkEvent *event, gpointer data) if (event->type == GDK_KEY_PRESS) { - switch (((GdkEventKey *)event)->keyval) + if (((GdkEventKey *)event)->state & GDK_MOD1_MASK) { - case GDK_KEY_Return: - gtk_widget_grab_focus(c->web_view); - t = gtk_entry_get_text(GTK_ENTRY(c->location)); - if (t != NULL && t[0] == '/') - { - if (search_text != NULL) - g_free(search_text); - search_text = g_strdup(t + 1); /* XXX whacky */ - search(c, 1); - } - else - { - f = ensure_url_scheme(t); - if (show_all_requests) - fprintf(stderr, "====> %s\n", f); - webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f); - g_free(f); - } - return TRUE; - case GDK_KEY_Escape: - t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)); - gtk_entry_set_text(GTK_ENTRY(c->location), - (t == NULL ? __NAME__ : t)); - return TRUE; - case GDK_KEY_d: - if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) - { + switch (((GdkEventKey *)event)->keyval) + { + case GDK_KEY_q: /* close window (left hand) */ + gtk_widget_destroy(c->win); + return TRUE; + case GDK_KEY_d: /* download manager (left hand) */ gtk_widget_show_all(dm.win); return TRUE; - } - else - return FALSE; + case GDK_KEY_r: /* reload (left hand) */ + webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW( + c->web_view)); + return TRUE; + case GDK_KEY_k: /* initiate search (BOTH hands) */ + gtk_entry_set_text(GTK_ENTRY(c->location), "/"); + gtk_editable_set_position(GTK_EDITABLE(c->location), -1); + return TRUE; + } + } + else + { + switch (((GdkEventKey *)event)->keyval) + { + case GDK_KEY_Return: + gtk_widget_grab_focus(c->web_view); + t = gtk_entry_get_text(GTK_ENTRY(c->location)); + if (t != NULL && t[0] == '/') + { + if (search_text != NULL) + g_free(search_text); + search_text = g_strdup(t + 1); /* XXX whacky */ + search(c, 1); + } + else + { + f = ensure_url_scheme(t); + if (show_all_requests) + fprintf(stderr, "====> %s\n", f); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f); + g_free(f); + } + return TRUE; + case GDK_KEY_Escape: + t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)); + gtk_entry_set_text(GTK_ENTRY(c->location), + (t == NULL ? __NAME__ : t)); + return TRUE; + } } } @@ -651,52 +690,48 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data) if (event->type == GDK_KEY_PRESS) { - if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) + if (((GdkEventKey *)event)->state & GDK_MOD1_MASK) { switch (((GdkEventKey *)event)->keyval) { - case GDK_KEY_o: - gtk_widget_grab_focus(c->location); - return TRUE; - case GDK_KEY_h: - scroll(gtk_scrolled_window_get_hadjustment( - GTK_SCROLLED_WINDOW(c->scroll)), 0, -1); - return TRUE; - case GDK_KEY_j: - scroll(gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(c->scroll)), 0, 1); + case GDK_KEY_q: /* close window (left hand) */ + gtk_widget_destroy(c->win); return TRUE; - case GDK_KEY_k: - scroll(gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(c->scroll)), 0, -1); + case GDK_KEY_w: /* home (left hand) */ + f = ensure_url_scheme(first_uri); + if (show_all_requests) + fprintf(stderr, "====> %s\n", f); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f); + g_free(f); return TRUE; - case GDK_KEY_l: - scroll(gtk_scrolled_window_get_hadjustment( - GTK_SCROLLED_WINDOW(c->scroll)), 0, 1); + case GDK_KEY_e: /* new tab (left hand) */ + f = ensure_url_scheme(first_uri); + if (show_all_requests) + fprintf(stderr, "====> %s\n", f); + client_new(f); + g_free(f); return TRUE; - case GDK_KEY_f: - scroll(gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(c->scroll)), 1, 0.5); + case GDK_KEY_r: /* reload (left hand) */ + webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW( + c->web_view)); return TRUE; - case GDK_KEY_b: - scroll(gtk_scrolled_window_get_vadjustment( - GTK_SCROLLED_WINDOW(c->scroll)), 1, -0.5); + case GDK_KEY_d: /* download manager (left hand) */ + gtk_widget_show_all(dm.win); return TRUE; - case GDK_KEY_n: + case GDK_KEY_2: /* search forward (left hand) */ + case GDK_KEY_n: /* search forward (maybe both hands) */ search(c, 1); return TRUE; - case GDK_KEY_p: + case GDK_KEY_3: /* search backward (left hand) */ search(c, -1); return TRUE; - case GDK_KEY_g: - f = ensure_url_scheme(first_uri); - if (show_all_requests) - fprintf(stderr, "====> %s\n", f); - webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f); - g_free(f); + case GDK_KEY_l: /* location (BOTH hands) */ + gtk_widget_grab_focus(c->location); return TRUE; - case GDK_KEY_d: - gtk_widget_show_all(dm.win); + case GDK_KEY_k: /* initiate search (BOTH hands) */ + gtk_widget_grab_focus(c->location); + gtk_entry_set_text(GTK_ENTRY(c->location), "/"); + gtk_editable_set_position(GTK_EDITABLE(c->location), -1); return TRUE; } } @@ -766,22 +801,6 @@ search(gpointer data, gint direction) FALSE, direction == 1, TRUE); } -void -scroll(GtkAdjustment *a, gint step_type, gdouble factor) -{ - gdouble new, lower, upper, step; - lower = gtk_adjustment_get_lower(a); - upper = gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a) + lower; - if (step_type == 0) - step = gtk_adjustment_get_step_increment(a); - else - step = gtk_adjustment_get_page_increment(a); - new = gtk_adjustment_get_value(a) + factor * step; - new = new < lower ? lower : new; - new = new > upper ? upper : new; - gtk_adjustment_set_value(a, new); -} - Window tabbed_launch(void) { |