config.c 35.9 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1
/* See LICENSE file for license and copyright information */
Moritz Lipp's avatar
Moritz Lipp committed
2

3
#include "config.h"
4 5
#include "commands.h"
#include "completion.h"
6
#include "callbacks.h"
Moritz Lipp's avatar
Moritz Lipp committed
7 8
#include "shortcuts.h"
#include "zathura.h"
9
#include "render.h"
Moritz Lipp's avatar
Moritz Lipp committed
10
#include "marks.h"
Moritz Lipp's avatar
Moritz Lipp committed
11
#include "utils.h"
Moritz Lipp's avatar
Moritz Lipp committed
12

13 14 15 16 17
#include <girara/settings.h>
#include <girara/session.h>
#include <girara/shortcuts.h>
#include <girara/config.h>
#include <girara/commands.h>
18
#include <glib/gi18n.h>
19

20 21
static void
cb_jumplist_change(girara_session_t* session, const char* name,
Moritz Lipp's avatar
Moritz Lipp committed
22
                   girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
23 24 25 26 27 28
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  g_return_if_fail(name != NULL);
  zathura_t* zathura = session->global.data;
29 30 31 32 33 34 35 36 37

  if (g_strcmp0(name, "jumplist-size") != 0) {
    return;
  }

  if (*(int *)value < 0) {
    zathura->jumplist.max_size = 0;
  } else {
    zathura->jumplist.max_size = *(int *)value;
38
  }
39 40

  zathura_jumplist_trim(zathura);
41 42
}

43
static void
44
cb_color_change(girara_session_t* session, const char* name,
Moritz Lipp's avatar
Moritz Lipp committed
45
                girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
46 47 48 49 50 51 52
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  g_return_if_fail(name != NULL);
  zathura_t* zathura = session->global.data;

Sebastian Ramacher's avatar
Sebastian Ramacher committed
53
  const char* string_value = (const char*) value;
54
  if (g_strcmp0(name, "highlight-color") == 0) {
55
    gdk_rgba_parse(&(zathura->ui.colors.highlight_color), string_value);
56
  } else if (g_strcmp0(name, "highlight-active-color") == 0) {
57
    gdk_rgba_parse(&(zathura->ui.colors.highlight_color_active), string_value);
58
  } else if (g_strcmp0(name, "recolor-darkcolor") == 0) {
59 60 61
    if (zathura->sync.render_thread != NULL) {
      zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, NULL, string_value);
    }
62
  } else if (g_strcmp0(name, "recolor-lightcolor") == 0) {
63 64 65
    if (zathura->sync.render_thread != NULL) {
      zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, string_value, NULL);
    }
66
  } else if (g_strcmp0(name, "render-loading-bg") == 0) {
67
    gdk_rgba_parse(&(zathura->ui.colors.render_loading_bg), string_value);
68
  } else if (g_strcmp0(name, "render-loading-fg") == 0) {
69
    gdk_rgba_parse(&(zathura->ui.colors.render_loading_fg), string_value);
70 71
  }

72
  render_all(zathura);
73 74
}

Moritz Lipp's avatar
Moritz Lipp committed
75 76
static void
cb_nohlsearch_changed(girara_session_t* session, const char* UNUSED(name),
Moritz Lipp's avatar
Moritz Lipp committed
77
                      girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
Moritz Lipp's avatar
Moritz Lipp committed
78 79 80 81 82 83 84 85 86 87
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  zathura_t* zathura = session->global.data;

  document_draw_search_results(zathura, !(*(bool*) value));
  render_all(zathura);
}

88 89
static void
cb_incsearch_changed(girara_session_t* session, const char* UNUSED(name),
Moritz Lipp's avatar
Moritz Lipp committed
90
                     girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
91 92 93 94 95 96 97 98 99 100 101
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);

  bool inc_search = *(bool*) value;
  girara_special_command_add(session, '/', cmd_search, inc_search, FORWARD,  NULL);
  girara_special_command_add(session, '?', cmd_search, inc_search, BACKWARD, NULL);
}


Moritz Lipp's avatar
Moritz Lipp committed
102
void
103
config_load_default(zathura_t* zathura)
Moritz Lipp's avatar
Moritz Lipp committed
104
{
Moritz Lipp's avatar
CS  
Moritz Lipp committed
105
  if (zathura == NULL || zathura->ui.session == NULL) {
Moritz Lipp's avatar
Moritz Lipp committed
106
    return;
107
  }
Moritz Lipp's avatar
Moritz Lipp committed
108

109
  int int_value              = 0;
110
  float float_value          = 0;
111
  bool bool_value            = false;
112
  bool inc_search            = true;
113
  char* string_value         = NULL;
114
  girara_session_t* gsession = zathura->ui.session;
Moritz Lipp's avatar
Moritz Lipp committed
115

Moritz Lipp's avatar
Moritz Lipp committed
116 117 118 119 120 121 122 123 124 125 126 127
  /* mode settings */
  zathura->modes.normal     = gsession->modes.normal;
  zathura->modes.fullscreen = girara_mode_add(gsession, "fullscreen");
  zathura->modes.index      = girara_mode_add(gsession, "index");
  zathura->modes.insert     = girara_mode_add(gsession, "insert");

#define NORMAL zathura->modes.normal
#define INSERT zathura->modes.insert
#define INDEX zathura->modes.index
#define FULLSCREEN zathura->modes.fullscreen

  girara_mode_set(gsession, zathura->modes.normal);
Moritz Lipp's avatar
Moritz Lipp committed
128

129
  /* zathura settings */
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
130
  girara_setting_add(gsession, "database",              "plain",      STRING, true,  _("Database backend"),         NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
131
  int_value = 10;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
132
  girara_setting_add(gsession, "zoom-step",             &int_value,   INT,    false, _("Zoom step"),                NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
133
  int_value = 1;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
134
  girara_setting_add(gsession, "page-padding",          &int_value,   INT,    false, _("Padding between pages"),    cb_page_layout_value_changed, NULL);
135
  int_value = 1;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
136
  girara_setting_add(gsession, "pages-per-row",         &int_value,   INT,    false, _("Number of pages per row"),  cb_page_layout_value_changed, NULL);
137
  int_value = 1;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
138
  girara_setting_add(gsession, "first-page-column",     &int_value,   INT,    false, _("Column of the first page"), cb_page_layout_value_changed, NULL);
139
  float_value = 40;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
140
  girara_setting_add(gsession, "scroll-step",           &float_value, FLOAT,  false, _("Scroll step"),              NULL, NULL);
141
  float_value = 40;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
142
  girara_setting_add(gsession, "scroll-hstep",          &float_value, FLOAT,  false, _("Horizontal scroll step"),   NULL, NULL);
143
  float_value = 0.0;
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
144
  girara_setting_add(gsession, "scroll-full-overlap",   &float_value, FLOAT,  false, _("Full page scroll overlap"), NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
145
  int_value = 10;
146
  girara_setting_add(gsession, "zoom-min",              &int_value,   INT,    false, _("Zoom minimum"), NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
147
  int_value = 1000;
148
  girara_setting_add(gsession, "zoom-max",              &int_value,   INT,    false, _("Zoom maximum"), NULL, NULL);
149
  int_value = ZATHURA_PAGE_CACHE_DEFAULT_SIZE;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
150
  girara_setting_add(gsession, "page-cache-size",       &int_value,   INT,    true,  _("Maximum number of pages to keep in the cache"), NULL, NULL);
151
  int_value = 2000;
152
  girara_setting_add(gsession, "jumplist-size",         &int_value,   INT,    false, _("Number of positions to remember in the jumplist"), cb_jumplist_change, NULL);
153

154 155
  girara_setting_add(gsession, "recolor-darkcolor",      "#FFFFFF", STRING, false, _("Recoloring (dark color)"),         cb_color_change, NULL);
  girara_setting_add(gsession, "recolor-lightcolor",     "#000000", STRING, false, _("Recoloring (light color)"),        cb_color_change, NULL);
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
156
  girara_setting_add(gsession, "highlight-color",        NULL,      STRING, false, _("Color for highlighting"),          cb_color_change, NULL);
157
  girara_setting_set(gsession, "highlight-color",        "#9FBC00");
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
158
  girara_setting_add(gsession, "highlight-active-color", NULL,      STRING, false, _("Color for highlighting (active)"), cb_color_change, NULL);
159
  girara_setting_set(gsession, "highlight-active-color", "#00BC00");
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
160
  girara_setting_add(gsession, "render-loading-bg",      NULL,      STRING, false, _("'Loading ...' background color"),  cb_color_change, NULL);
161
  girara_setting_set(gsession, "render-loading-bg",      "#FFFFFF");
Sebastian Ramacher's avatar
CS  
Sebastian Ramacher committed
162
  girara_setting_add(gsession, "render-loading-fg",      NULL,      STRING, false, _("'Loading ...' foreground color"),  cb_color_change, NULL);
163
  girara_setting_set(gsession, "render-loading-fg",      "#000000");
164

Moritz Lipp's avatar
Moritz Lipp committed
165 166
  bool_value = false;
  girara_setting_add(gsession, "recolor",                &bool_value,  BOOLEAN, false, _("Recolor pages"), cb_setting_recolor_change, NULL);
167
  bool_value = false;
168 169
  girara_setting_add(gsession, "recolor-keephue",        &bool_value,  BOOLEAN, false, _("When recoloring keep original hue and adjust lightness only"), cb_setting_recolor_keep_hue_change, NULL);
  bool_value = false;
170
  girara_setting_add(gsession, "scroll-wrap",            &bool_value,  BOOLEAN, false, _("Wrap scrolling"), NULL, NULL);
171
  bool_value = false;
172 173
  girara_setting_add(gsession, "scroll-page-aware",      &bool_value,  BOOLEAN, false, _("Page aware scrolling"), NULL, NULL);
  bool_value = false;
174
  girara_setting_add(gsession, "advance-pages-per-row",  &bool_value,  BOOLEAN, false, _("Advance number of pages per row"), NULL, NULL);
Julian Orth's avatar
Julian Orth committed
175 176 177
  bool_value = false;
  girara_setting_add(gsession, "zoom-center",            &bool_value,  BOOLEAN, false, _("Horizontally centered zoom"), NULL, NULL);
  bool_value = true;
178 179
  girara_setting_add(gsession, "link-hadjust",           &bool_value,  BOOLEAN, false, _("Align link target to the left"), NULL, NULL);
  bool_value = true;
180 181
  girara_setting_add(gsession, "link-zoom",              &bool_value,  BOOLEAN, false, _("Let zoom be changed when following links"), NULL, NULL);
  bool_value = true;
Julian Orth's avatar
Julian Orth committed
182
  girara_setting_add(gsession, "search-hadjust",         &bool_value,  BOOLEAN, false, _("Center result horizontally"), NULL, NULL);
183
  float_value = 0.5;
184
  girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT,   false, _("Transparency for highlighting"), NULL, NULL);
185
  bool_value = true;
186
  girara_setting_add(gsession, "render-loading",         &bool_value,  BOOLEAN, false, _("Render 'Loading ...'"), NULL, NULL);
187
  girara_setting_add(gsession, "adjust-open",            "best-fit",   STRING,  false, _("Adjust to when opening file"), NULL, NULL);
188
  bool_value = false;
189
  girara_setting_add(gsession, "show-hidden",            &bool_value,  BOOLEAN, false, _("Show hidden files and directories"), NULL, NULL);
190
  bool_value = true;
191
  girara_setting_add(gsession, "show-directories",       &bool_value,  BOOLEAN, false, _("Show directories"), NULL, NULL);
192 193
  bool_value = false;
  girara_setting_add(gsession, "open-first-page",        &bool_value,  BOOLEAN, false, _("Always open on first page"), NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
194 195
  bool_value = false;
  girara_setting_add(gsession, "nohlsearch",             &bool_value,  BOOLEAN, false, _("Highlight search results"), cb_nohlsearch_changed, NULL);
196 197
  inc_search = false;
  girara_setting_add(gsession, "incremental-search",     &inc_search,  BOOLEAN, false, _("Enable incremental search"), cb_incsearch_changed, NULL);
198 199
  bool_value = true;
  girara_setting_add(gsession, "abort-clear-search",     &bool_value,  BOOLEAN, false, _("Clear search results on abort"), NULL, NULL);
200 201
  bool_value = false;
  girara_setting_add(gsession, "window-title-basename",  &bool_value,  BOOLEAN, false, _("Use basename of the file in the window title"), NULL, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
202
  bool_value = false;
203 204
  girara_setting_add(gsession, "window-title-page",      &bool_value,  BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL);
  bool_value = false;
205 206
  girara_setting_add(gsession, "statusbar-basename",     &bool_value,  BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL);
  bool_value = false;
Sebastian Ramacher's avatar
Sebastian Ramacher committed
207
  girara_setting_add(gsession, "synctex",                &bool_value,  BOOLEAN, false, _("Enable synctex support"), NULL, NULL);
208
  string_value = "primary";
209
  girara_setting_add(gsession, "selection-clipboard",    string_value, STRING,  false, _("The clipboard into which mouse-selected data will be written"), NULL, NULL);
210

Moritz Lipp's avatar
Moritz Lipp committed
211
  /* define default shortcuts */
212 213
  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);
Moritz Lipp's avatar
Moritz Lipp committed
214

215 216
  girara_shortcut_add(gsession, 0,                GDK_KEY_a,          NULL, sc_adjust_window,            NORMAL,     ZATHURA_ADJUST_BESTFIT,  NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_s,          NULL, sc_adjust_window,            NORMAL,     ZATHURA_ADJUST_WIDTH,    NULL);
Moritz Lipp's avatar
Moritz Lipp committed
217

218 219
  girara_shortcut_add(gsession, 0,                GDK_KEY_F,          NULL, sc_display_link,             NORMAL,     0,               NULL);

220 221 222 223 224 225
  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 "));
Moritz Lipp's avatar
Moritz Lipp committed
226

227
  girara_shortcut_add(gsession, 0,                GDK_KEY_f,          NULL, sc_follow,                   NORMAL,     0,               NULL);
Moritz Lipp's avatar
Moritz Lipp committed
228

229 230 231 232
  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);
Moritz Lipp's avatar
Moritz Lipp committed
233

Moritz Lipp's avatar
Moritz Lipp committed
234 235 236
  girara_shortcut_add(gsession, 0,                GDK_KEY_m,          NULL, sc_mark_add,                 NORMAL,     0,               NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_apostrophe, NULL, sc_mark_evaluate,            NORMAL,     0,               NULL);

237 238 239 240
  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);
Moritz Lipp's avatar
Moritz Lipp committed
241 242
  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);
243
  girara_shortcut_add(gsession, 0,                GDK_KEY_J,          NULL, sc_navigate,                 FULLSCREEN, NEXT,            NULL);
244 245
  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);
246
  girara_shortcut_add(gsession, 0,                GDK_KEY_Page_Down,  NULL, sc_navigate,                 FULLSCREEN, NEXT,            NULL);
Moritz Lipp's avatar
Moritz Lipp committed
247 248 249 250
  girara_shortcut_add(gsession, 0,                GDK_KEY_space,      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);
251
  girara_shortcut_add(gsession, 0,                GDK_KEY_Page_Up,    NULL, sc_navigate,                 FULLSCREEN, PREVIOUS,        NULL);
Moritz Lipp's avatar
Moritz Lipp committed
252
  girara_shortcut_add(gsession, GDK_SHIFT_MASK,   GDK_KEY_space,      NULL, sc_navigate,                 FULLSCREEN, PREVIOUS,        NULL);
253
  girara_shortcut_add(gsession, 0,                GDK_KEY_BackSpace,  NULL, sc_navigate,                 FULLSCREEN, PREVIOUS,        NULL);
Moritz Lipp's avatar
Moritz Lipp committed
254

255 256 257 258
  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);
259 260
  girara_shortcut_add(gsession, 0,                GDK_KEY_L,          NULL, sc_navigate_index,           INDEX,      EXPAND_ALL,      NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_H,          NULL, sc_navigate_index,           INDEX,      COLLAPSE_ALL,    NULL);
Moritz Lipp's avatar
Moritz Lipp committed
261 262 263 264
  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);
265 266
  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);
Moritz Lipp's avatar
Moritz Lipp committed
267

Moritz Lipp's avatar
Moritz Lipp committed
268 269
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_p,          NULL, sc_print,                    NORMAL,     0,               NULL);

270
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_r,          NULL, sc_recolor,                  NORMAL,     0,               NULL);
Moritz Lipp's avatar
Moritz Lipp committed
271

272
  girara_shortcut_add(gsession, 0,                GDK_KEY_R,          NULL, sc_reload,                   NORMAL,     0,               NULL);
Moritz Lipp's avatar
Moritz Lipp committed
273

274
  girara_shortcut_add(gsession, 0,                GDK_KEY_r,          NULL, sc_rotate,                   NORMAL,     ROTATE_CW,       NULL);
Moritz Lipp's avatar
Moritz Lipp committed
275

276 277 278 279 280 281 282 283
  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);
  girara_shortcut_add(gsession, 0,                GDK_KEY_l,          NULL, sc_scroll,                   NORMAL,     RIGHT,           NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_Left,       NULL, sc_scroll,                   NORMAL,     LEFT,            NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_Up,         NULL, sc_scroll,                   NORMAL,     UP,              NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_Down,       NULL, sc_scroll,                   NORMAL,     DOWN,            NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_Right,      NULL, sc_scroll,                   NORMAL,     RIGHT,           NULL);
284 285
  girara_shortcut_add(gsession, 0,                GDK_KEY_H,          NULL, sc_scroll,                   NORMAL,     PAGE_TOP,        NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_L,          NULL, sc_scroll,                   NORMAL,     PAGE_BOTTOM,     NULL);
286
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_t,          NULL, sc_scroll,                   NORMAL,     HALF_LEFT,       NULL);
287 288
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_d,          NULL, sc_scroll,                   NORMAL,     HALF_DOWN,       NULL);
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_u,          NULL, sc_scroll,                   NORMAL,     HALF_UP,         NULL);
289 290
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_y,          NULL, sc_scroll,                   NORMAL,     HALF_RIGHT,      NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_t,          NULL, sc_scroll,                   NORMAL,     FULL_LEFT,       NULL);
291 292
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_f,          NULL, sc_scroll,                   NORMAL,     FULL_DOWN,       NULL);
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_b,          NULL, sc_scroll,                   NORMAL,     FULL_UP,         NULL);
293
  girara_shortcut_add(gsession, 0,                GDK_KEY_y,          NULL, sc_scroll,                   NORMAL,     FULL_RIGHT,      NULL);
294 295
  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);
296 297
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_o,          NULL, sc_jumplist,                 NORMAL,     BACKWARD,        NULL);
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_i,          NULL, sc_jumplist,                 NORMAL,     FORWARD,         NULL);
298 299
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_j,          NULL, sc_bisect,                   NORMAL,     FORWARD,         NULL);
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_k,          NULL, sc_bisect,                   NORMAL,     BACKWARD,        NULL);
300 301
  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);
Moritz Lipp's avatar
Moritz Lipp committed
302

303 304 305 306 307
  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, 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);
Moritz Lipp's avatar
Moritz Lipp committed
308
  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_m,          NULL, girara_sc_toggle_inputbar,   NORMAL,     0,               NULL);
Moritz Lipp's avatar
Moritz Lipp committed
309
  girara_shortcut_add(gsession, 0,                GDK_KEY_d,          NULL, sc_toggle_page_mode,         NORMAL,     0,               NULL);
Moritz Lipp's avatar
Moritz Lipp committed
310

311
  girara_shortcut_add(gsession, 0,                GDK_KEY_q,          NULL, sc_quit,                     NORMAL,     0,               NULL);
312
  girara_shortcut_add(gsession, 0,                GDK_KEY_q,          NULL, sc_quit,                     FULLSCREEN, 0,               NULL);
Moritz Lipp's avatar
Moritz Lipp committed
313

314
  girara_shortcut_add(gsession, 0,                GDK_KEY_plus,       NULL, sc_zoom,                     NORMAL,     ZOOM_IN,         NULL);
315
  girara_shortcut_add(gsession, 0,                GDK_KEY_KP_Add,     NULL, sc_zoom,                     NORMAL,     ZOOM_IN,         NULL);
316
  girara_shortcut_add(gsession, 0,                GDK_KEY_plus,       NULL, sc_zoom,                     FULLSCREEN, ZOOM_IN,         NULL);
317
  girara_shortcut_add(gsession, 0,                GDK_KEY_KP_Add,     NULL, sc_zoom,                     FULLSCREEN, ZOOM_IN,         NULL);
318
  girara_shortcut_add(gsession, 0,                GDK_KEY_minus,      NULL, sc_zoom,                     NORMAL,     ZOOM_OUT,        NULL);
319
  girara_shortcut_add(gsession, 0,                GDK_KEY_KP_Subtract,NULL, sc_zoom,                     NORMAL,     ZOOM_OUT,        NULL);
320
  girara_shortcut_add(gsession, 0,                GDK_KEY_minus,      NULL, sc_zoom,                     FULLSCREEN, ZOOM_OUT,        NULL);
321
  girara_shortcut_add(gsession, 0,                GDK_KEY_KP_Subtract,NULL, sc_zoom,                     FULLSCREEN, ZOOM_OUT,        NULL);
322 323
  girara_shortcut_add(gsession, 0,                GDK_KEY_equal,      NULL, sc_zoom,                     NORMAL,     ZOOM_SPECIFIC,   NULL);
  girara_shortcut_add(gsession, 0,                GDK_KEY_equal,      NULL, sc_zoom,                     FULLSCREEN, ZOOM_SPECIFIC,   NULL);
324 325
  girara_shortcut_add(gsession, 0,                0,                  "zi", sc_zoom,                     NORMAL,     ZOOM_IN,         NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zi", sc_zoom,                     FULLSCREEN, ZOOM_IN,         NULL);
326 327
  girara_shortcut_add(gsession, 0,                0,                  "zI", sc_zoom,                     NORMAL,     ZOOM_IN,         NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zI", sc_zoom,                     FULLSCREEN, ZOOM_IN,         NULL);
328 329
  girara_shortcut_add(gsession, 0,                0,                  "zo", sc_zoom,                     NORMAL,     ZOOM_OUT,        NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zo", sc_zoom,                     FULLSCREEN, ZOOM_OUT,        NULL);
330 331 332 333
  girara_shortcut_add(gsession, 0,                0,                  "zO", sc_zoom,                     NORMAL,     ZOOM_OUT,        NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zO", sc_zoom,                     FULLSCREEN, ZOOM_OUT,        NULL);
  girara_shortcut_add(gsession, 0,                0,                  "z0", sc_zoom,                     NORMAL,     ZOOM_ORIGINAL,   NULL);
  girara_shortcut_add(gsession, 0,                0,                  "z0", sc_zoom,                     FULLSCREEN, ZOOM_ORIGINAL,   NULL);
334 335 336 337
  girara_shortcut_add(gsession, 0,                0,                  "zz", sc_zoom,                     NORMAL,     ZOOM_SPECIFIC,   NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zz", sc_zoom,                     FULLSCREEN, ZOOM_SPECIFIC,   NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zZ", sc_zoom,                     NORMAL,     ZOOM_SPECIFIC,   NULL);
  girara_shortcut_add(gsession, 0,                0,                  "zZ", sc_zoom,                     FULLSCREEN, ZOOM_SPECIFIC,   NULL);
338

339 340 341 342
  /* inputbar shortcuts */
  girara_inputbar_shortcut_add(gsession, 0,                GDK_KEY_Escape, sc_abort, 0, NULL);
  girara_inputbar_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c,      sc_abort, 0, NULL);

Moritz Lipp's avatar
Moritz Lipp committed
343
  /* mouse events */
344 345 346 347
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, NORMAL,     GIRARA_EVENT_SCROLL_UP,      UP,    NULL);
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_UP,      UP,    NULL);
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, NORMAL,     GIRARA_EVENT_SCROLL_DOWN,    DOWN,  NULL);
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN,    DOWN,  NULL);
348 349 350 351
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, NORMAL,     GIRARA_EVENT_SCROLL_LEFT,    LEFT,  NULL);
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_LEFT,    LEFT,  NULL);
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, NORMAL,     GIRARA_EVENT_SCROLL_RIGHT,   RIGHT, NULL);
  girara_mouse_event_add(gsession, 0, 0,                                   sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_RIGHT,   RIGHT, NULL);
352 353 354 355

  girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON1,                sc_navigate,     FULLSCREEN, GIRARA_EVENT_BUTTON_PRESS,   NEXT,     NULL);
  girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON3,                sc_navigate,     FULLSCREEN, GIRARA_EVENT_BUTTON_PRESS,   PREVIOUS, NULL);

356 357 358 359 360
  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0,                      sc_mouse_scroll, NORMAL,     GIRARA_EVENT_SCROLL_UP,      LEFT,  NULL);
  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0,                      sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_UP,      LEFT,  NULL);
  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0,                      sc_mouse_scroll, NORMAL,     GIRARA_EVENT_SCROLL_DOWN,    RIGHT, NULL);
  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0,                      sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN,    RIGHT, NULL);

Moritz Lipp's avatar
Moritz Lipp committed
361 362 363 364 365 366 367
  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0,                    sc_mouse_zoom,   NORMAL,     GIRARA_EVENT_SCROLL_UP,      UP,   NULL);
  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0,                    sc_mouse_zoom,   FULLSCREEN, GIRARA_EVENT_SCROLL_UP,      UP,   NULL);
  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0,                    sc_mouse_zoom,   NORMAL,     GIRARA_EVENT_SCROLL_DOWN,    DOWN, NULL);
  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0,                    sc_mouse_zoom,   FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN,    DOWN, NULL);
  girara_mouse_event_add(gsession, 0,                GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL,     GIRARA_EVENT_BUTTON_PRESS,   0,    NULL);
  girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL,     GIRARA_EVENT_BUTTON_RELEASE, 0,    NULL);
  girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, 0,                    sc_mouse_scroll, NORMAL,     GIRARA_EVENT_MOTION_NOTIFY,  0,    NULL);
Moritz Lipp's avatar
Moritz Lipp committed
368

369
  /* define default inputbar commands */
Moritz Lipp's avatar
Moritz Lipp committed
370 371 372 373 374
  girara_inputbar_command_add(gsession, "bmark",      NULL,   cmd_bookmark_create, NULL,         _("Add a bookmark"));
  girara_inputbar_command_add(gsession, "bdelete",    NULL,   cmd_bookmark_delete, cc_bookmarks, _("Delete a bookmark"));
  girara_inputbar_command_add(gsession, "blist",      NULL,   cmd_bookmark_open,   cc_bookmarks, _("List all bookmarks"));
  girara_inputbar_command_add(gsession, "close",      NULL,   cmd_close,           NULL,         _("Close current file"));
  girara_inputbar_command_add(gsession, "info",       NULL,   cmd_info,            NULL,         _("Show file information"));
Moritz Lipp's avatar
Moritz Lipp committed
375
  girara_inputbar_command_add(gsession, "exec",       NULL,   cmd_exec,            NULL,         _("Execute a command"));
Moritz Lipp's avatar
Moritz Lipp committed
376 377 378 379 380 381 382 383 384 385 386 387
  girara_inputbar_command_add(gsession, "help",       NULL,   cmd_help,            NULL,         _("Show help"));
  girara_inputbar_command_add(gsession, "open",       "o",    cmd_open,            cc_open,      _("Open document"));
  girara_inputbar_command_add(gsession, "quit",       "q",    cmd_quit,            NULL,         _("Close zathura"));
  girara_inputbar_command_add(gsession, "print",      NULL,   cmd_print,           NULL,         _("Print document"));
  girara_inputbar_command_add(gsession, "write",      NULL,   cmd_save,            cc_write,     _("Save document"));
  girara_inputbar_command_add(gsession, "write!",     NULL,   cmd_savef,           cc_write,     _("Save document (and force overwriting)"));
  girara_inputbar_command_add(gsession, "export",     NULL,   cmd_export,          cc_export,    _("Save attachments"));
  girara_inputbar_command_add(gsession, "offset",     NULL,   cmd_offset,          NULL,         _("Set page offset"));
  girara_inputbar_command_add(gsession, "mark",       NULL,   cmd_marks_add,       NULL,         _("Mark current location within the document"));
  girara_inputbar_command_add(gsession, "delmarks",   "delm", cmd_marks_delete,    NULL,         _("Delete the specified marks"));
  girara_inputbar_command_add(gsession, "nohlsearch", "nohl", cmd_nohlsearch,      NULL,         _("Don't highlight current search results"));
  girara_inputbar_command_add(gsession, "hlsearch",   NULL,   cmd_hlsearch,        NULL,         _("Highlight current search results"));
Moritz Lipp's avatar
Moritz Lipp committed
388
  girara_inputbar_command_add(gsession, "version",    NULL,   cmd_version,         NULL,         _("Show version information"));
Sebastian Ramacher's avatar
Sebastian Ramacher committed
389

390 391
  girara_special_command_add(gsession, '/', cmd_search, inc_search, FORWARD,  NULL);
  girara_special_command_add(gsession, '?', cmd_search, inc_search, BACKWARD, NULL);
Moritz Lipp's avatar
Moritz Lipp committed
392

Moritz Lipp's avatar
Moritz Lipp committed
393 394 395 396
  /* add shortcut mappings */
  girara_shortcut_mapping_add(gsession, "abort",             sc_abort);
  girara_shortcut_mapping_add(gsession, "adjust_window",     sc_adjust_window);
  girara_shortcut_mapping_add(gsession, "change_mode",       sc_change_mode);
397
  girara_shortcut_mapping_add(gsession, "display_link",      sc_display_link);
398
  girara_shortcut_mapping_add(gsession, "focus_inputbar",    sc_focus_inputbar);
Moritz Lipp's avatar
Moritz Lipp committed
399 400
  girara_shortcut_mapping_add(gsession, "follow",            sc_follow);
  girara_shortcut_mapping_add(gsession, "goto",              sc_goto);
401
  girara_shortcut_mapping_add(gsession, "jumplist",          sc_jumplist);
402
  girara_shortcut_mapping_add(gsession, "bisect",            sc_bisect);
Moritz Lipp's avatar
Moritz Lipp committed
403
  girara_shortcut_mapping_add(gsession, "navigate",          sc_navigate);
404
  girara_shortcut_mapping_add(gsession, "navigate_index",    sc_navigate_index);
Moritz Lipp's avatar
Moritz Lipp committed
405
  girara_shortcut_mapping_add(gsession, "print",             sc_print);
Moritz Lipp's avatar
Moritz Lipp committed
406 407 408 409 410 411 412 413
  girara_shortcut_mapping_add(gsession, "quit",              sc_quit);
  girara_shortcut_mapping_add(gsession, "recolor",           sc_recolor);
  girara_shortcut_mapping_add(gsession, "reload",            sc_reload);
  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, "toggle_fullscreen", sc_toggle_fullscreen);
  girara_shortcut_mapping_add(gsession, "toggle_index",      sc_toggle_index);
Moritz Lipp's avatar
Moritz Lipp committed
414
  girara_shortcut_mapping_add(gsession, "toggle_inputbar",   girara_sc_toggle_inputbar);
415
  girara_shortcut_mapping_add(gsession, "toggle_page_mode",  sc_toggle_page_mode);
Moritz Lipp's avatar
Moritz Lipp committed
416
  girara_shortcut_mapping_add(gsession, "toggle_statusbar",  girara_sc_toggle_statusbar);
Moritz Lipp's avatar
Moritz Lipp committed
417
  girara_shortcut_mapping_add(gsession, "zoom",              sc_zoom);
Moritz Lipp's avatar
Moritz Lipp committed
418 419

  /* add argument mappings */
420
  girara_argument_mapping_add(gsession, "backward",     BACKWARD);
421 422 423 424 425 426 427
  girara_argument_mapping_add(gsession, "bottom",       BOTTOM);
  girara_argument_mapping_add(gsession, "default",      DEFAULT);
  girara_argument_mapping_add(gsession, "collapse",     COLLAPSE);
  girara_argument_mapping_add(gsession, "collapse-all", COLLAPSE_ALL);
  girara_argument_mapping_add(gsession, "down",         DOWN);
  girara_argument_mapping_add(gsession, "expand",       EXPAND);
  girara_argument_mapping_add(gsession, "expand-all",   EXPAND_ALL);
428
  girara_argument_mapping_add(gsession, "forward",      FORWARD);
429 430 431 432
  girara_argument_mapping_add(gsession, "full-down",    FULL_DOWN);
  girara_argument_mapping_add(gsession, "full-up",      FULL_UP);
  girara_argument_mapping_add(gsession, "half-down",    HALF_DOWN);
  girara_argument_mapping_add(gsession, "half-up",      HALF_UP);
433 434 435 436
  girara_argument_mapping_add(gsession, "full-right",   FULL_RIGHT);
  girara_argument_mapping_add(gsession, "full-left",    FULL_LEFT);
  girara_argument_mapping_add(gsession, "half-right",   HALF_RIGHT);
  girara_argument_mapping_add(gsession, "half-left",    HALF_LEFT);
437 438 439 440
  girara_argument_mapping_add(gsession, "in",           ZOOM_IN);
  girara_argument_mapping_add(gsession, "left",         LEFT);
  girara_argument_mapping_add(gsession, "next",         NEXT);
  girara_argument_mapping_add(gsession, "out",          ZOOM_OUT);
441 442
  girara_argument_mapping_add(gsession, "page-top",     PAGE_TOP);
  girara_argument_mapping_add(gsession, "page-bottom",  PAGE_BOTTOM);
443 444 445 446 447
  girara_argument_mapping_add(gsession, "previous",     PREVIOUS);
  girara_argument_mapping_add(gsession, "right",        RIGHT);
  girara_argument_mapping_add(gsession, "specific",     ZOOM_SPECIFIC);
  girara_argument_mapping_add(gsession, "top",          TOP);
  girara_argument_mapping_add(gsession, "up",           UP);
448 449
  girara_argument_mapping_add(gsession, "best-fit",     ZATHURA_ADJUST_BESTFIT);
  girara_argument_mapping_add(gsession, "width",        ZATHURA_ADJUST_WIDTH);
450 451
  girara_argument_mapping_add(gsession, "rotate-cw",    ROTATE_CW);
  girara_argument_mapping_add(gsession, "rotate-ccw",   ROTATE_CCW);
Moritz Lipp's avatar
Moritz Lipp committed
452
}
Moritz Lipp's avatar
Moritz Lipp committed
453 454

void
455
config_load_file(zathura_t* zathura, char* path)
Moritz Lipp's avatar
Moritz Lipp committed
456
{
Moritz Lipp's avatar
Moritz Lipp committed
457
  if (zathura == NULL || path == NULL) {
Moritz Lipp's avatar
Moritz Lipp committed
458 459 460
    return;
  }

461
  girara_config_parse(zathura->ui.session, path);
Moritz Lipp's avatar
Moritz Lipp committed
462
}