From 0cf5be08cdd7b2717b5d40615658e8bf9007c36f Mon Sep 17 00:00:00 2001 From: Faye Date: Mon, 6 Jul 2020 16:45:55 -0500 Subject: [PATCH] Add a snap_to_page command --- doc/man/zathurarc.5.rst | 4 ++++ zathura/config.c | 3 +++ zathura/shortcuts.c | 13 +++++++++++++ zathura/shortcuts.h | 10 ++++++++++ 4 files changed, 30 insertions(+) diff --git a/doc/man/zathurarc.5.rst b/doc/man/zathurarc.5.rst index de5c4a0..d2b2d96 100644 --- a/doc/man/zathurarc.5.rst +++ b/doc/man/zathurarc.5.rst @@ -289,6 +289,10 @@ They can also be combined with modifiers: Set an option. + * ``snap_to_page`` + + Snaps to the current page. Equivalent to ``goto `` + * ``toggle_fullscreen`` Toggle fullscreen. diff --git a/zathura/config.c b/zathura/config.c index 8ab2950..2a5d7b4 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -358,6 +358,8 @@ config_load_default(zathura_t* zathura) \ girara_shortcut_add(gsession, 0, GDK_KEY_n, NULL, sc_search, (mode), FORWARD, NULL); \ girara_shortcut_add(gsession, 0, GDK_KEY_N, NULL, sc_search, (mode), BACKWARD, NULL); \ +\ + girara_shortcut_add(gsession, 0, GDK_KEY_P, NULL, sc_snap_to_page, (mode), 0, NULL); \ \ girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, (mode), 0, NULL); \ girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_n, NULL, girara_sc_toggle_statusbar, (mode), 0, NULL); \ @@ -527,6 +529,7 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "rotate", sc_rotate); girara_shortcut_mapping_add(gsession, "scroll", sc_scroll); girara_shortcut_mapping_add(gsession, "search", sc_search); + girara_shortcut_mapping_add(gsession, "snap_to_page", sc_snap_to_page); girara_shortcut_mapping_add(gsession, "toggle_fullscreen", sc_toggle_fullscreen); girara_shortcut_mapping_add(gsession, "toggle_index", sc_toggle_index); girara_shortcut_mapping_add(gsession, "toggle_page_mode", sc_toggle_page_mode); diff --git a/zathura/shortcuts.c b/zathura/shortcuts.c index eef6b76..d53dacd 100644 --- a/zathura/shortcuts.c +++ b/zathura/shortcuts.c @@ -1469,3 +1469,16 @@ sc_nohlsearch(girara_session_t* session, girara_argument_t* UNUSED(argument), gi return false; } + +bool sc_snap_to_page(girara_session_t *session, + girara_argument_t *UNUSED(argument), + girara_event_t *UNUSED(event), unsigned int UNUSED(t)) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t *zathura = session->global.data; + g_return_val_if_fail(zathura->document != NULL, false); + zathura_document_t *document = zathura->document; + + int page = zathura_document_get_current_page_number(document); + return page_set(zathura, page); +} diff --git a/zathura/shortcuts.h b/zathura/shortcuts.h index 182303f..f198880 100644 --- a/zathura/shortcuts.h +++ b/zathura/shortcuts.h @@ -303,5 +303,15 @@ bool sc_exec(girara_session_t* session, girara_argument_t* argument, girara_even */ bool sc_nohlsearch(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); +/** + * Snaps the current view to the current page + * + * @param session The used girara session + * @param argument The used argument + * @param event Girara event + * @param t Number of executions + * @return true if no error occurred otherwise false + */ +bool sc_snap_to_page(girara_session_t *session, girara_argument_t *argument, girara_event_t *event, unsigned int t); #endif // SHORTCUTS_H