From 2cdf2bd2ba9b27866dd5561ba6a1250d2da68d46 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 20 Feb 2012 12:30:43 +0100 Subject: [PATCH 1/5] Update key bindings --- config.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index a766258..7872b3d 100644 --- a/config.c +++ b/config.c @@ -97,38 +97,57 @@ config_load_default(zathura_t* zathura) /* define default shortcuts */ girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, NULL, sc_abort, 0, 0, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Escape, NULL, sc_abort, 0, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_slash, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("/")); girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_slash, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("/")); girara_shortcut_add(gsession, 0, GDK_KEY_question, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("?")); girara_shortcut_add(gsession, 0, GDK_KEY_colon, NULL, girara_sc_focus_inputbar, NORMAL, 0, &(":")); girara_shortcut_add(gsession, 0, GDK_KEY_o, NULL, girara_sc_focus_inputbar, NORMAL, 0, &(":open ")); girara_shortcut_add(gsession, 0, GDK_KEY_O, NULL, girara_sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_KEY_f, NULL, sc_follow, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, NORMAL, TOP, NULL); girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, FULLSCREEN, TOP, NULL); girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL, BOTTOM, NULL); girara_shortcut_add(gsession, 0, 0, "G", sc_goto, FULLSCREEN, BOTTOM, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_J, NULL, sc_navigate, NORMAL, NEXT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_navigate_index, INDEX, UP, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate_index, INDEX, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate_index, INDEX, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate_index, INDEX, EXPAND, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_i, NULL, sc_recolor, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_R, NULL, sc_reload, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_r, NULL, sc_rotate, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_scroll, NORMAL, LEFT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_scroll, NORMAL, DOWN, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_scroll, NORMAL, UP, NULL); @@ -143,15 +162,19 @@ config_load_default(zathura_t* zathura) girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_space, NULL, sc_scroll, NORMAL, FULL_UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_n, NULL, sc_search, NORMAL, FORWARD, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_N, NULL, sc_search, NORMAL, BACKWARD, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, NORMAL, 0, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, INDEX, 0, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_m, NULL, girara_sc_toggle_inputbar, NORMAL, 0, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_F5, NULL, sc_toggle_fullscreen, NORMAL, 0, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_F5, NULL, sc_toggle_fullscreen, FULLSCREEN, 0, NULL); girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_n, NULL, girara_sc_toggle_statusbar, NORMAL, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_m, NULL, girara_sc_toggle_inputbar, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_q, NULL, sc_quit, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_plus, NULL, sc_zoom, NORMAL, ZOOM_IN, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_plus, NULL, sc_zoom, FULLSCREEN, ZOOM_IN, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_minus, NULL, sc_zoom, NORMAL, ZOOM_OUT, NULL); From b8470a5317bf01e73f3c387c0aaa58c295f526e3 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 20 Feb 2012 12:40:25 +0100 Subject: [PATCH 2/5] Set current page number in page_set --- config.c | 6 ++++-- zathura.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 7872b3d..6d28781 100644 --- a/config.c +++ b/config.c @@ -124,12 +124,14 @@ config_load_default(zathura_t* zathura) girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, NORMAL, NEXT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_J, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_K, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_navigate_index, INDEX, UP, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); diff --git a/zathura.c b/zathura.c index ee0fa24..76d4653 100644 --- a/zathura.c +++ b/zathura.c @@ -557,6 +557,8 @@ page_set(zathura_t* zathura, unsigned int page_id) goto error_out; } + zathura->document->current_page_number = page_id; + page_offset_t offset; page_calculate_offset(page, &offset); From eeee28b0cb23f9049773cb83cc751c44a007a66f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 20 Feb 2012 12:53:21 +0100 Subject: [PATCH 3/5] Fix leading slash in cc_open --- completion.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/completion.c b/completion.c index cfcbd92..7ab595b 100644 --- a/completion.c +++ b/completion.c @@ -53,7 +53,13 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil continue; } - char* full_path = g_strdup_printf("%s%s%s", current_path, is_dir ? "" : "/", e_name); + + char* tmp = "/"; + if (is_dir == true || g_strcmp0(current_path, "/") == 0) { + tmp = ""; + }; + + char* full_path = g_strdup_printf("%s%s%s", current_path, tmp, e_name); if (full_path == NULL) { g_free(e_name); goto error_free; From f4d6c6993b396fa217e51ecd616f996fd75188d4 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 20 Feb 2012 13:02:24 +0100 Subject: [PATCH 4/5] Hide hidden files/directories by default and make it configurable --- completion.c | 18 +++++++++++++++--- config.c | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/completion.c b/completion.c index 7ab595b..59fd2cd 100644 --- a/completion.c +++ b/completion.c @@ -11,6 +11,7 @@ #include "utils.h" #include +#include #include #include #include @@ -29,6 +30,10 @@ compare_case_insensitive(const char* str1, const char* str2) static girara_list_t* list_files(zathura_t* zathura, const char* current_path, const char* current_file, int current_file_length, bool is_dir) { + if (zathura == NULL || zathura->ui.session == NULL || current_path == NULL) { + return NULL; + } + /* read directory */ GDir* dir = g_dir_open(current_path, 0, NULL); if (dir == NULL) { @@ -38,6 +43,9 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil girara_list_t* res = girara_sorted_list_new2((girara_compare_function_t)compare_case_insensitive, (girara_free_function_t)g_free); + bool show_hidden = false; + girara_setting_get(zathura->ui.session, "show-hidden", &show_hidden); + /* read files */ char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { @@ -45,14 +53,18 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil if (e_name == NULL) { goto error_free; } - int e_length = strlen(e_name); - if ((current_file_length > e_length) || strncmp(current_file, e_name, - current_file_length)) { + int e_length = strlen(e_name); + + if (show_hidden == false && e_name[0] == '.') { g_free(e_name); continue; } + if ((current_file_length > e_length) || strncmp(current_file, e_name, current_file_length)) { + g_free(e_name); + continue; + } char* tmp = "/"; if (is_dir == true || g_strcmp0(current_path, "/") == 0) { diff --git a/config.c b/config.c index 6d28781..40efd9a 100644 --- a/config.c +++ b/config.c @@ -93,6 +93,8 @@ config_load_default(zathura_t* zathura) girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, "Render 'Loading ...'", NULL, NULL); string_value = "best-fit"; girara_setting_add(gsession, "adjust-open", string_value, STRING, false, "Adjust to when opening file", NULL, NULL); + bool_value = false; + girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, "Show hidden files and directories", NULL, NULL); /* define default shortcuts */ girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, NULL, sc_abort, 0, 0, NULL); From d8bc9fefac92b1d0b493031844dff199a2323403 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 20 Feb 2012 16:33:59 +0100 Subject: [PATCH 5/5] Implement sc_focus_inputbar with possible APPEND_FILEPATH parameter --- config.c | 12 +++++------ shortcuts.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ shortcuts.h | 12 +++++++++++ 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/config.c b/config.c index 40efd9a..5db01c3 100644 --- a/config.c +++ b/config.c @@ -106,12 +106,12 @@ config_load_default(zathura_t* zathura) girara_shortcut_add(gsession, 0, GDK_KEY_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); - girara_shortcut_add(gsession, 0, GDK_KEY_slash, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_slash, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, 0, GDK_KEY_question, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("?")); - girara_shortcut_add(gsession, 0, GDK_KEY_colon, NULL, girara_sc_focus_inputbar, NORMAL, 0, &(":")); - girara_shortcut_add(gsession, 0, GDK_KEY_o, NULL, girara_sc_focus_inputbar, NORMAL, 0, &(":open ")); - girara_shortcut_add(gsession, 0, GDK_KEY_O, NULL, girara_sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_KEY_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, 0, GDK_KEY_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); + girara_shortcut_add(gsession, 0, GDK_KEY_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); + girara_shortcut_add(gsession, 0, GDK_KEY_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_KEY_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); girara_shortcut_add(gsession, 0, GDK_KEY_f, NULL, sc_follow, NORMAL, 0, NULL); diff --git a/shortcuts.c b/shortcuts.c index 3fb4df0..d71b3de 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "callbacks.h" #include "shortcuts.h" @@ -116,6 +117,63 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument, return false; } +bool +sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) +{ + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->gtk.inputbar_entry != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == false) { + gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + } + + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.notification_area)) == true) { + gtk_widget_hide(GTK_WIDGET(session->gtk.notification_area)); + } + + gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar_entry)); + + if (argument->data != NULL) { + gtk_entry_set_text(session->gtk.inputbar_entry, (char*) argument->data); + + /* append filepath */ + if (argument->n == APPEND_FILEPATH && zathura->document != NULL) { + char* file_path = g_strdup(zathura->document->file_path); + if (file_path == NULL) { + return false; + } + + char* path = dirname(file_path); + char* tmp = g_strdup_printf("%s%s/", (char*) argument->data, (g_strcmp0(path, "/") == 0) ? "" : path); + + if (tmp == NULL) { + g_free(file_path); + return false; + } + + gtk_entry_set_text(session->gtk.inputbar_entry, tmp); + g_free(tmp); + g_free(file_path); + } + + /* we save the X clipboard that will be clear by "grab_focus" */ + gchar* x_clipboard_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); + + gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar_entry), -1); + + if (x_clipboard_text != NULL) { + /* we reset the X clipboard with saved text */ + gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), x_clipboard_text, -1); + g_free(x_clipboard_text); + } + } + + return true; +} + bool sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) diff --git a/shortcuts.h b/shortcuts.h index 1629d74..56bed86 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -38,6 +38,18 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, gi */ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); +/** + * Shortcut function to focus the inputbar + * + * @param session The used girara session + * @param argument The argument + * @param event Girara event + * @param t Number of executions + * @return true No error occured + * @return false An error occured (abort execution) + */ +bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); + /** * Follow a link *