mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-25 21:26:02 +01:00
input: Add shortcut to cycle first page column
Add mapping cycle_first_column (default 'D') to cycle the column in which to display the first page.
This commit is contained in:
parent
5447de8a47
commit
d5cb3777c1
7 changed files with 107 additions and 0 deletions
|
@ -127,6 +127,8 @@ General
|
|||
Show index and switch to **Index mode**
|
||||
d
|
||||
Toggle dual page view
|
||||
D
|
||||
Cycle opening column in dual page view
|
||||
F5
|
||||
Switch to presentation mode
|
||||
F11
|
||||
|
|
|
@ -225,6 +225,10 @@ They can also be combined with modifiers:
|
|||
|
||||
Change current mode. Pass the desired mode as argument.
|
||||
|
||||
* ``cycle_first_page``
|
||||
|
||||
In multiple page layout, cycle the column in which the first page is displayed.
|
||||
|
||||
* ``display_link``:
|
||||
|
||||
Display link target.
|
||||
|
|
|
@ -443,6 +443,7 @@ void config_load_default(zathura_t* zathura) {
|
|||
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_n, NULL, girara_sc_toggle_statusbar, (mode), 0, NULL); \
|
||||
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_m, NULL, girara_sc_toggle_inputbar, (mode), 0, NULL); \
|
||||
girara_shortcut_add(gsession, 0, GDK_KEY_d, NULL, sc_toggle_page_mode, (mode), 0, NULL); \
|
||||
girara_shortcut_add(gsession, 0, GDK_KEY_D, NULL, sc_cycle_first_column, (mode), 0, NULL); \
|
||||
\
|
||||
girara_shortcut_add(gsession, 0, GDK_KEY_q, NULL, sc_quit, (mode), 0, NULL); \
|
||||
\
|
||||
|
@ -596,6 +597,7 @@ void config_load_default(zathura_t* zathura) {
|
|||
girara_shortcut_mapping_add(gsession, "adjust_window", sc_adjust_window);
|
||||
girara_shortcut_mapping_add(gsession, "bisect", sc_bisect);
|
||||
girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode);
|
||||
girara_shortcut_mapping_add(gsession, "cycle_first_column", sc_cycle_first_column);
|
||||
girara_shortcut_mapping_add(gsession, "display_link", sc_display_link);
|
||||
girara_shortcut_mapping_add(gsession, "copy_link", sc_copy_link);
|
||||
girara_shortcut_mapping_add(gsession, "copy_filepath", sc_copy_filepath);
|
||||
|
|
|
@ -150,6 +150,34 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_cycle_first_column(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||
girara_event_t* UNUSED(event), unsigned int 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;
|
||||
|
||||
if (zathura->document == NULL) {
|
||||
girara_notify(session, GIRARA_WARNING, _("No document opened."));
|
||||
return false;
|
||||
}
|
||||
|
||||
int pages_per_row = 1;
|
||||
girara_setting_get(session, "pages-per-row", &pages_per_row);
|
||||
char* first_page_column_list = NULL;
|
||||
girara_setting_get(session, "first-page-column", &first_page_column_list);
|
||||
|
||||
if (t == 0) t = 1;
|
||||
char* new_column_list = increment_first_page_column(first_page_column_list, pages_per_row, t);
|
||||
g_free(first_page_column_list);
|
||||
|
||||
girara_setting_set(session, "first-page-column", new_column_list);
|
||||
g_free(new_column_list);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_display_link(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
||||
|
|
|
@ -38,6 +38,17 @@ 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);
|
||||
|
||||
/**
|
||||
* Cycle the column the first page is displayed in
|
||||
*
|
||||
* @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_cycle_first_column(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t);
|
||||
|
||||
/**
|
||||
* Display a link
|
||||
*
|
||||
|
|
|
@ -313,6 +313,54 @@ find_first_page_column(const char* first_page_column_list,
|
|||
return first_page_column;
|
||||
}
|
||||
|
||||
char*
|
||||
increment_first_page_column(const char* first_page_column_list,
|
||||
const unsigned int pages_per_row, int incr)
|
||||
{
|
||||
/* sanity checks */
|
||||
if (first_page_column_list == NULL)
|
||||
first_page_column_list = "";
|
||||
/* This function is a no-op for 1 column layout */
|
||||
if (pages_per_row <= 1)
|
||||
return g_strdup(first_page_column_list);
|
||||
|
||||
unsigned int size = 0;
|
||||
unsigned int* settings = parse_first_page_column_list(first_page_column_list, &size);
|
||||
|
||||
/* Lookup current setting. Signed value to avoid negative overflow when modifying it later. */
|
||||
int column = 1;
|
||||
if (pages_per_row <= size) {
|
||||
column = settings[pages_per_row - 1];
|
||||
} else if (size > 0) {
|
||||
column = settings[size - 1];
|
||||
}
|
||||
|
||||
/* increment and normalise to [1,pages_per_row]. */
|
||||
column += incr;
|
||||
column %= pages_per_row; /* range [-pages_per_row+1, pages_per_row-1] */
|
||||
if (column <= 0)
|
||||
column += pages_per_row; /* range [1, pages_per_row] */
|
||||
|
||||
/* Write back, creating the new cell if necessary. */
|
||||
if (pages_per_row <= size) {
|
||||
settings[pages_per_row - 1] = column;
|
||||
} else {
|
||||
/* extend settings array */
|
||||
settings = g_realloc_n(settings, pages_per_row, sizeof(*settings));
|
||||
for (unsigned int i=size; i<pages_per_row-1; i++) {
|
||||
/* The value of the last set cell is normally used for all largers pages_per_row,
|
||||
* so duplicate it to the newly created cells. */
|
||||
settings[i] = settings[size - 1];
|
||||
}
|
||||
settings[pages_per_row-1] = column;
|
||||
size = pages_per_row;
|
||||
}
|
||||
|
||||
char* new_column_list = write_first_page_column_list(settings, size);
|
||||
g_free(settings);
|
||||
return new_column_list;
|
||||
}
|
||||
|
||||
bool
|
||||
parse_color(GdkRGBA* color, const char* str)
|
||||
{
|
||||
|
|
|
@ -143,6 +143,18 @@ unsigned int* parse_first_page_column(const char* first_page_column_list, unsign
|
|||
unsigned int find_first_page_column(const char* first_page_column_list,
|
||||
const unsigned int pages_per_row);
|
||||
|
||||
/**
|
||||
* Cycle the column the first page should be rendered in.
|
||||
*
|
||||
* @param[in] first_page_column_list The settings list
|
||||
* @param[in] pages_per_row The current pages per row
|
||||
* @param[in] incr The value added to the current first page column setting
|
||||
*
|
||||
* @return The new modified settings list
|
||||
*/
|
||||
char* increment_first_page_column(const char* first_page_column_list,
|
||||
const unsigned int pages_per_row, int incr);
|
||||
|
||||
/**
|
||||
* Parse color string and print warning if color cannot be parsed.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue