Skip to content

Commit

Permalink
Merge branch 'develop' into 'develop'
Browse files Browse the repository at this point in the history
Add the ability to scroll half page up or down in index

See merge request pwmt/zathura!95
  • Loading branch information
sebastinas committed Apr 30, 2024
2 parents f98f8ee + 9cbc60c commit d2156cd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ libm = cc.find_library('m', required: false)
girara = dependency('girara-gtk3', version: '>=0.4.3', fallback: ['girara', 'girara_dependency'])
glib = dependency('glib-2.0', version: '>=2.72')
gio = dependency('gio-unix-2.0', required: host_machine.system() != 'windows')
gthread = dependency('gthread-2.0', version: '>=2.74')
gmodule = dependency('gmodule-no-export-2.0', version: '>=2.74')
gthread = dependency('gthread-2.0', version: '>=2.72')
gmodule = dependency('gmodule-no-export-2.0', version: '>=2.72')
gtk3 = dependency('gtk+-3.0', version: '>=3.24')
json_glib = dependency('json-glib-1.0')
cairo = dependency('cairo')
Expand Down
3 changes: 3 additions & 0 deletions zathura/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ void config_load_default(zathura_t* zathura) {
girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, INDEX, 0, 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, GDK_CONTROL_MASK, GDK_KEY_d, NULL, sc_navigate_index, INDEX, HALF_DOWN, NULL);
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_u, NULL, sc_navigate_index, INDEX, HALF_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_L, NULL, sc_navigate_index, INDEX, EXPAND_ALL, NULL);
Expand Down
27 changes: 27 additions & 0 deletions zathura/shortcuts.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: Zlib */

#include <girara/log.h>
#include <girara/session.h>
#include <girara/settings.h>
#include <girara/datastructures.h>
Expand Down Expand Up @@ -1063,17 +1064,28 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,

GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreePath *path;
GtkTreePath *start_path;
GtkTreePath *end_path;

gtk_tree_view_get_cursor(tree_view, &path, NULL);
if (path == NULL) {
return false;
}

if (gtk_tree_view_get_visible_range(tree_view, &start_path, &end_path) != TRUE)
{
girara_error("Cannot get visible range for index");
gtk_tree_path_free(start_path);
gtk_tree_path_free(end_path);
return false;
}

GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
GtkTreeIter iter;
GtkTreeIter child_iter;

gboolean is_valid_path = TRUE;
gboolean need_to_scroll = FALSE;

switch(argument->n) {
case TOP:
Expand Down Expand Up @@ -1129,6 +1141,18 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
&& gtk_tree_path_up(path));
}
break;
case HALF_UP:
gtk_tree_path_free(path);
gtk_tree_path_free(end_path);
path = start_path;
need_to_scroll = TRUE;
break;
case HALF_DOWN:
gtk_tree_path_free(path);
gtk_tree_path_free(start_path);
path = end_path;
need_to_scroll = TRUE;
break;
case EXPAND:
if (gtk_tree_view_expand_row(tree_view, path, FALSE)) {
gtk_tree_path_down(path);
Expand Down Expand Up @@ -1161,6 +1185,9 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,

if (is_valid_path == TRUE) {
gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
if (need_to_scroll == TRUE) {
gtk_tree_view_scroll_to_cell(tree_view, path, NULL, TRUE, 0.5, 0.0);
}
}

gtk_tree_path_free(path);
Expand Down

0 comments on commit d2156cd

Please sign in to comment.