zathura
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
config.c
Go to the documentation of this file.
1 /* See LICENSE file for license and copyright information */
2 
3 #include "config.h"
4 #include "commands.h"
5 #include "completion.h"
6 #include "callbacks.h"
7 #include "shortcuts.h"
8 #include "zathura.h"
9 #include "render.h"
10 #include "marks.h"
11 #include "utils.h"
12 
13 #include <girara/settings.h>
14 #include <girara/session.h>
15 #include <girara/shortcuts.h>
16 #include <girara/config.h>
17 #include <girara/commands.h>
18 #include <girara/utils.h>
19 #include <glib/gi18n.h>
20 
21 #define GLOBAL_RC "/etc/zathurarc"
22 #define ZATHURA_RC "zathurarc"
23 
24 static void
25 cb_jumplist_change(girara_session_t* session, const char* name,
26  girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
27 {
28  g_return_if_fail(value != NULL);
29  g_return_if_fail(session != NULL);
30  g_return_if_fail(session->global.data != NULL);
31  g_return_if_fail(name != NULL);
32  zathura_t* zathura = session->global.data;
33 
34  if (g_strcmp0(name, "jumplist-size") != 0) {
35  return;
36  }
37 
38  if (*(int *)value < 0) {
39  zathura->jumplist.max_size = 0;
40  } else {
41  zathura->jumplist.max_size = *(int *)value;
42  }
43 
44  zathura_jumplist_trim(zathura);
45 }
46 
47 static void
48 cb_color_change(girara_session_t* session, const char* name,
49  girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
50 {
51  g_return_if_fail(value != NULL);
52  g_return_if_fail(session != NULL);
53  g_return_if_fail(session->global.data != NULL);
54  g_return_if_fail(name != NULL);
55  zathura_t* zathura = session->global.data;
56 
57  const char* string_value = (const char*) value;
58  if (g_strcmp0(name, "highlight-color") == 0) {
59  gdk_rgba_parse(&(zathura->ui.colors.highlight_color), string_value);
60  } else if (g_strcmp0(name, "highlight-active-color") == 0) {
61  gdk_rgba_parse(&(zathura->ui.colors.highlight_color_active), string_value);
62  } else if (g_strcmp0(name, "recolor-darkcolor") == 0) {
63  if (zathura->sync.render_thread != NULL) {
64  zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, NULL, string_value);
65  }
66  } else if (g_strcmp0(name, "recolor-lightcolor") == 0) {
67  if (zathura->sync.render_thread != NULL) {
68  zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, string_value, NULL);
69  }
70  } else if (g_strcmp0(name, "render-loading-bg") == 0) {
71  gdk_rgba_parse(&(zathura->ui.colors.render_loading_bg), string_value);
72  } else if (g_strcmp0(name, "render-loading-fg") == 0) {
73  gdk_rgba_parse(&(zathura->ui.colors.render_loading_fg), string_value);
74  }
75 
76  render_all(zathura);
77 }
78 
79 static void
80 cb_nohlsearch_changed(girara_session_t* session, const char* UNUSED(name),
81  girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
82 {
83  g_return_if_fail(value != NULL);
84  g_return_if_fail(session != NULL);
85  g_return_if_fail(session->global.data != NULL);
86  zathura_t* zathura = session->global.data;
87 
88  document_draw_search_results(zathura, !(*(bool*) value));
89  render_all(zathura);
90 }
91 
92 static void
93 cb_incsearch_changed(girara_session_t* session, const char* UNUSED(name),
94  girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
95 {
96  g_return_if_fail(value != NULL);
97  g_return_if_fail(session != NULL);
98  g_return_if_fail(session->global.data != NULL);
99 
100  bool inc_search = *(bool*) value;
101  girara_special_command_add(session, '/', cmd_search, inc_search, FORWARD, NULL);
102  girara_special_command_add(session, '?', cmd_search, inc_search, BACKWARD, NULL);
103 }
104 
105 
106 void
107 config_load_default(zathura_t* zathura)
108 {
109  if (zathura == NULL || zathura->ui.session == NULL) {
110  return;
111  }
112 
113  int int_value = 0;
114  float float_value = 0;
115  bool bool_value = false;
116  char* string_value = NULL;
117  girara_session_t* gsession = zathura->ui.session;
118 
119  /* mode settings */
120  zathura->modes.normal = gsession->modes.normal;
121  zathura->modes.fullscreen = girara_mode_add(gsession, "fullscreen");
122  zathura->modes.index = girara_mode_add(gsession, "index");
123  zathura->modes.insert = girara_mode_add(gsession, "insert");
124  zathura->modes.presentation = girara_mode_add(gsession, "presentation");
125 
126 #define NORMAL zathura->modes.normal
127 #define INSERT zathura->modes.insert
128 #define INDEX zathura->modes.index
129 #define FULLSCREEN zathura->modes.fullscreen
130 #define PRESENTATION zathura->modes.presentation
131 
132  const girara_mode_t all_modes[] = {
133  NORMAL,
134  INSERT,
135  INDEX,
136  FULLSCREEN,
138  };
139 
140  /* Set default mode */
141  girara_mode_set(gsession, zathura->modes.normal);
142 
143  /* zathura settings */
144  girara_setting_add(gsession, "database", "plain", STRING, true, _("Database backend"), NULL, NULL);
145  int_value = 10;
146  girara_setting_add(gsession, "zoom-step", &int_value, INT, false, _("Zoom step"), NULL, NULL);
147  int_value = 1;
148  girara_setting_add(gsession, "page-padding", &int_value, INT, false, _("Padding between pages"), cb_page_layout_value_changed, NULL);
149  int_value = 1;
150  girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, _("Number of pages per row"), cb_page_layout_value_changed, NULL);
151  int_value = 1;
152  girara_setting_add(gsession, "first-page-column", &int_value, INT, false, _("Column of the first page"), cb_page_layout_value_changed, NULL);
153  float_value = 40;
154  girara_setting_add(gsession, "scroll-step", &float_value, FLOAT, false, _("Scroll step"), NULL, NULL);
155  float_value = 40;
156  girara_setting_add(gsession, "scroll-hstep", &float_value, FLOAT, false, _("Horizontal scroll step"), NULL, NULL);
157  float_value = 0.0;
158  girara_setting_add(gsession, "scroll-full-overlap", &float_value, FLOAT, false, _("Full page scroll overlap"), NULL, NULL);
159  int_value = 10;
160  girara_setting_add(gsession, "zoom-min", &int_value, INT, false, _("Zoom minimum"), NULL, NULL);
161  int_value = 1000;
162  girara_setting_add(gsession, "zoom-max", &int_value, INT, false, _("Zoom maximum"), NULL, NULL);
164  girara_setting_add(gsession, "page-cache-size", &int_value, INT, true, _("Maximum number of pages to keep in the cache"), NULL, NULL);
165  int_value = 2000;
166  girara_setting_add(gsession, "jumplist-size", &int_value, INT, false, _("Number of positions to remember in the jumplist"), cb_jumplist_change, NULL);
167 
168  girara_setting_add(gsession, "recolor-darkcolor", "#FFFFFF", STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL);
169  girara_setting_add(gsession, "recolor-lightcolor", "#000000", STRING, false, _("Recoloring (light color)"), cb_color_change, NULL);
170  girara_setting_add(gsession, "highlight-color", NULL, STRING, false, _("Color for highlighting"), cb_color_change, NULL);
171  girara_setting_set(gsession, "highlight-color", "#9FBC00");
172  girara_setting_add(gsession, "highlight-active-color", NULL, STRING, false, _("Color for highlighting (active)"), cb_color_change, NULL);
173  girara_setting_set(gsession, "highlight-active-color", "#00BC00");
174  girara_setting_add(gsession, "render-loading-bg", NULL, STRING, false, _("'Loading ...' background color"), cb_color_change, NULL);
175  girara_setting_set(gsession, "render-loading-bg", "#FFFFFF");
176  girara_setting_add(gsession, "render-loading-fg", NULL, STRING, false, _("'Loading ...' foreground color"), cb_color_change, NULL);
177  girara_setting_set(gsession, "render-loading-fg", "#000000");
178 
179  bool_value = false;
180  girara_setting_add(gsession, "recolor", &bool_value, BOOLEAN, false, _("Recolor pages"), cb_setting_recolor_change, NULL);
181  bool_value = false;
182  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);
183  bool_value = false;
184  girara_setting_add(gsession, "scroll-wrap", &bool_value, BOOLEAN, false, _("Wrap scrolling"), NULL, NULL);
185  bool_value = false;
186  girara_setting_add(gsession, "scroll-page-aware", &bool_value, BOOLEAN, false, _("Page aware scrolling"), NULL, NULL);
187  bool_value = false;
188  girara_setting_add(gsession, "advance-pages-per-row", &bool_value, BOOLEAN, false, _("Advance number of pages per row"), NULL, NULL);
189  bool_value = false;
190  girara_setting_add(gsession, "zoom-center", &bool_value, BOOLEAN, false, _("Horizontally centered zoom"), NULL, NULL);
191  bool_value = true;
192  girara_setting_add(gsession, "link-hadjust", &bool_value, BOOLEAN, false, _("Align link target to the left"), NULL, NULL);
193  bool_value = true;
194  girara_setting_add(gsession, "link-zoom", &bool_value, BOOLEAN, false, _("Let zoom be changed when following links"), NULL, NULL);
195  bool_value = true;
196  girara_setting_add(gsession, "search-hadjust", &bool_value, BOOLEAN, false, _("Center result horizontally"), NULL, NULL);
197  float_value = 0.5;
198  girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, _("Transparency for highlighting"), NULL, NULL);
199  bool_value = true;
200  girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, _("Render 'Loading ...'"), NULL, NULL);
201  girara_setting_add(gsession, "adjust-open", "best-fit", STRING, false, _("Adjust to when opening file"), NULL, NULL);
202  bool_value = false;
203  girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, _("Show hidden files and directories"), NULL, NULL);
204  bool_value = true;
205  girara_setting_add(gsession, "show-directories", &bool_value, BOOLEAN, false, _("Show directories"), NULL, NULL);
206  bool_value = false;
207  girara_setting_add(gsession, "open-first-page", &bool_value, BOOLEAN, false, _("Always open on first page"), NULL, NULL);
208  bool_value = false;
209  girara_setting_add(gsession, "nohlsearch", &bool_value, BOOLEAN, false, _("Highlight search results"), cb_nohlsearch_changed, NULL);
210 #define INCREMENTAL_SEARCH false
211  bool_value = INCREMENTAL_SEARCH;
212  girara_setting_add(gsession, "incremental-search", &bool_value, BOOLEAN, false, _("Enable incremental search"), cb_incsearch_changed, NULL);
213  bool_value = true;
214  girara_setting_add(gsession, "abort-clear-search", &bool_value, BOOLEAN, false, _("Clear search results on abort"), NULL, NULL);
215  bool_value = false;
216  girara_setting_add(gsession, "window-title-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the window title"), NULL, NULL);
217  bool_value = false;
218  girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL);
219  bool_value = false;
220  girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL);
221  bool_value = false;
222  girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL);
223  bool_value = true;
224  girara_setting_add(gsession, "dbus-service", &bool_value, BOOLEAN, false, _("Enable D-Bus service"), NULL, NULL);
225  string_value = "primary";
226  girara_setting_add(gsession, "selection-clipboard", string_value, STRING, false, _("The clipboard into which mouse-selected data will be written"), NULL, NULL);
227 
228 #define DEFAULT_SHORTCUTS(mode) \
229  girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, (mode), ZATHURA_ADJUST_BESTFIT, NULL); \
230  girara_shortcut_add(gsession, 0, GDK_KEY_s, NULL, sc_adjust_window, (mode), ZATHURA_ADJUST_WIDTH, NULL); \
231 \
232  girara_shortcut_add(gsession, 0, GDK_KEY_F, NULL, sc_display_link, (mode), 0, NULL); \
233 \
234  girara_shortcut_add(gsession, 0, GDK_KEY_slash, NULL, sc_focus_inputbar, (mode), 0, &("/")); \
235  girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_slash, NULL, sc_focus_inputbar, (mode), 0, &("/")); \
236  girara_shortcut_add(gsession, 0, GDK_KEY_question, NULL, sc_focus_inputbar, (mode), 0, &("?")); \
237  girara_shortcut_add(gsession, 0, GDK_KEY_colon, NULL, sc_focus_inputbar, (mode), 0, &(":")); \
238  girara_shortcut_add(gsession, 0, GDK_KEY_o, NULL, sc_focus_inputbar, (mode), 0, &(":open ")); \
239  girara_shortcut_add(gsession, 0, GDK_KEY_O, NULL, sc_focus_inputbar, (mode), APPEND_FILEPATH, &(":open ")); \
240 \
241  girara_shortcut_add(gsession, 0, GDK_KEY_f, NULL, sc_follow, (mode), 0, NULL); \
242 \
243  girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, (mode), TOP, NULL); \
244  girara_shortcut_add(gsession, 0, 0, "G", sc_goto, (mode), BOTTOM, NULL); \
245 \
246  girara_shortcut_add(gsession, 0, GDK_KEY_m, NULL, sc_mark_add, (mode), 0, NULL); \
247  girara_shortcut_add(gsession, 0, GDK_KEY_apostrophe, NULL, sc_mark_evaluate, (mode), 0, NULL); \
248 \
249  girara_shortcut_add(gsession, 0, GDK_KEY_J, NULL, sc_navigate, (mode), NEXT, NULL); \
250  girara_shortcut_add(gsession, 0, GDK_KEY_K, NULL, sc_navigate, (mode), PREVIOUS, NULL); \
251  girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Right, NULL, sc_navigate, (mode), NEXT, NULL); \
252  girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Left, NULL, sc_navigate, (mode), PREVIOUS, NULL); \
253  girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, (mode), NEXT, NULL); \
254  girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, (mode), PREVIOUS, NULL); \
255 \
256  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_p, NULL, sc_print, (mode), 0, NULL); \
257 \
258  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_r, NULL, sc_recolor, (mode), 0, NULL); \
259 \
260  girara_shortcut_add(gsession, 0, GDK_KEY_R, NULL, sc_reload, (mode), 0, NULL); \
261 \
262  girara_shortcut_add(gsession, 0, GDK_KEY_r, NULL, sc_rotate, (mode), ROTATE_CW, NULL); \
263 \
264  girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_scroll, (mode), LEFT, NULL); \
265  girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_scroll, (mode), DOWN, NULL); \
266  girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_scroll, (mode), UP, NULL); \
267  girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_scroll, (mode), RIGHT, NULL); \
268  girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_scroll, (mode), LEFT, NULL); \
269  girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_scroll, (mode), UP, NULL); \
270  girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_scroll, (mode), DOWN, NULL); \
271  girara_shortcut_add(gsession, 0, GDK_KEY_H, NULL, sc_scroll, (mode), PAGE_TOP, NULL); \
272  girara_shortcut_add(gsession, 0, GDK_KEY_L, NULL, sc_scroll, (mode), PAGE_BOTTOM, NULL); \
273  girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_scroll, (mode), RIGHT, NULL); \
274  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_t, NULL, sc_scroll, (mode), HALF_LEFT, NULL); \
275  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_d, NULL, sc_scroll, (mode), HALF_DOWN, NULL); \
276  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_u, NULL, sc_scroll, (mode), HALF_UP, NULL); \
277  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_y, NULL, sc_scroll, (mode), HALF_RIGHT, NULL); \
278  girara_shortcut_add(gsession, 0, GDK_KEY_t, NULL, sc_scroll, (mode), FULL_LEFT, NULL); \
279  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_f, NULL, sc_scroll, (mode), FULL_DOWN, NULL); \
280  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_b, NULL, sc_scroll, (mode), FULL_UP, NULL); \
281  girara_shortcut_add(gsession, 0, GDK_KEY_y, NULL, sc_scroll, (mode), FULL_RIGHT, NULL); \
282  girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_scroll, (mode), FULL_DOWN, NULL); \
283  girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_space, NULL, sc_scroll, (mode), FULL_UP, NULL); \
284 \
285  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_o, NULL, sc_jumplist, (mode), BACKWARD, NULL); \
286  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_i, NULL, sc_jumplist, (mode), FORWARD, NULL); \
287 \
288  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_j, NULL, sc_bisect, (mode), FORWARD, NULL); \
289  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_k, NULL, sc_bisect, (mode), BACKWARD, NULL); \
290 \
291  girara_shortcut_add(gsession, 0, GDK_KEY_n, NULL, sc_search, (mode), FORWARD, NULL); \
292  girara_shortcut_add(gsession, 0, GDK_KEY_N, NULL, sc_search, (mode), BACKWARD, NULL); \
293 \
294  girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, (mode), 0, NULL); \
295  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_n, NULL, girara_sc_toggle_statusbar, (mode), 0, NULL); \
296  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_m, NULL, girara_sc_toggle_inputbar, (mode), 0, NULL); \
297  girara_shortcut_add(gsession, 0, GDK_KEY_d, NULL, sc_toggle_page_mode, (mode), 0, NULL); \
298 \
299  girara_shortcut_add(gsession, 0, GDK_KEY_q, NULL, sc_quit, (mode), 0, NULL); \
300 \
301  girara_shortcut_add(gsession, 0, GDK_KEY_plus, NULL, sc_zoom, (mode), ZOOM_IN, NULL); \
302  girara_shortcut_add(gsession, 0, GDK_KEY_KP_Add, NULL, sc_zoom, (mode), ZOOM_IN, NULL); \
303  girara_shortcut_add(gsession, 0, GDK_KEY_minus, NULL, sc_zoom, (mode), ZOOM_OUT, NULL); \
304  girara_shortcut_add(gsession, 0, GDK_KEY_KP_Subtract,NULL, sc_zoom, (mode), ZOOM_OUT, NULL); \
305  girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, (mode), ZOOM_SPECIFIC, NULL); \
306  girara_shortcut_add(gsession, 0, 0, "zi", sc_zoom, (mode), ZOOM_IN, NULL); \
307  girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, (mode), ZOOM_IN, NULL); \
308  girara_shortcut_add(gsession, 0, 0, "zo", sc_zoom, (mode), ZOOM_OUT, NULL); \
309  girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, (mode), ZOOM_OUT, NULL); \
310  girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, (mode), ZOOM_ORIGINAL, NULL); \
311  girara_shortcut_add(gsession, 0, 0, "zz", sc_zoom, (mode), ZOOM_SPECIFIC, NULL); \
312  girara_shortcut_add(gsession, 0, 0, "zZ", sc_zoom, (mode), ZOOM_SPECIFIC, NULL);
313 
314 #define DEFAULT_MOUSE_EVENTS(mode) \
315  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_SCROLL_UP, UP, NULL); \
316  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL); \
317  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_SCROLL_LEFT, LEFT, NULL); \
318  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_SCROLL_RIGHT, RIGHT, NULL); \
319 \
320  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_SCROLL_UP, LEFT, NULL); \
321  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_SCROLL_DOWN, RIGHT, NULL); \
322 \
323  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, (mode), GIRARA_EVENT_SCROLL_UP, UP, NULL); \
324  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, (mode), GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL); \
325  girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, (mode), GIRARA_EVENT_BUTTON_PRESS, 0, NULL); \
326  girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, (mode), GIRARA_EVENT_BUTTON_RELEASE, 0, NULL); \
327  girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, 0, sc_mouse_scroll, (mode), GIRARA_EVENT_MOTION_NOTIFY, 0, NULL); \
328 
329  /* Define mode-less shortcuts
330  * girara adds them only for normal mode, so passing 0 as mode is currently
331  * not enough. We need to add/override for every mode. */
332  for (size_t idx = 0; idx != LENGTH(all_modes); ++idx) {
333  girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, NULL, sc_abort, all_modes[idx], 0, NULL);
334  girara_shortcut_add(gsession, 0, GDK_KEY_Escape, NULL, sc_abort, all_modes[idx], 0, NULL);
335  }
336 
337  /* Normal mode */
338  girara_shortcut_add(gsession, 0, GDK_KEY_F5, NULL, sc_toggle_presentation, NORMAL, 0, NULL);
339  girara_shortcut_add(gsession, 0, GDK_KEY_F11, NULL, sc_toggle_fullscreen, NORMAL, 0, NULL);
340 
342 
343  /* Normal mode - Mouse events */
345 
346  /* Fullscreen mode */
347  girara_shortcut_add(gsession, 0, GDK_KEY_F11, NULL, sc_toggle_fullscreen, FULLSCREEN, 0, NULL);
348 
350 
351  /* Fullscreen mode - Mouse events */
353 
354  /* Index mode */
355  girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, INDEX, 0, NULL);
356 
357  girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_navigate_index, INDEX, UP, NULL);
358  girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL);
359  girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL);
360  girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL);
361  girara_shortcut_add(gsession, 0, GDK_KEY_L, NULL, sc_navigate_index, INDEX, EXPAND_ALL, NULL);
362  girara_shortcut_add(gsession, 0, GDK_KEY_H, NULL, sc_navigate_index, INDEX, COLLAPSE_ALL, NULL);
363  girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate_index, INDEX, UP, NULL);
364  girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate_index, INDEX, DOWN, NULL);
365  girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL);
366  girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate_index, INDEX, EXPAND, NULL);
367  girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_navigate_index, INDEX, SELECT, NULL);
368  girara_shortcut_add(gsession, 0, GDK_KEY_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL);
369  girara_shortcut_add(gsession, 0, 0, "gg", sc_navigate_index, INDEX, TOP, NULL);
370  girara_shortcut_add(gsession, 0, 0, "G", sc_navigate_index, INDEX, BOTTOM, NULL);
371 
372 
373  /* Presentation mode */
374  girara_shortcut_add(gsession, 0, GDK_KEY_J, NULL, sc_navigate, PRESENTATION, NEXT, NULL);
375  girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate, PRESENTATION, NEXT, NULL);
376  girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate, PRESENTATION, NEXT, NULL);
377  girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, PRESENTATION, NEXT, NULL);
378  girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_navigate, PRESENTATION, NEXT, NULL);
379  girara_shortcut_add(gsession, 0, GDK_KEY_K, NULL, sc_navigate, PRESENTATION, PREVIOUS, NULL);
380  girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate, PRESENTATION, PREVIOUS, NULL);
381  girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate, PRESENTATION, PREVIOUS, NULL);
382  girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, PRESENTATION, PREVIOUS, NULL);
383  girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_space, NULL, sc_navigate, PRESENTATION, PREVIOUS, NULL);
384  girara_shortcut_add(gsession, 0, GDK_KEY_BackSpace, NULL, sc_navigate, PRESENTATION, PREVIOUS, NULL);
385 
386  girara_shortcut_add(gsession, 0, GDK_KEY_F5, NULL, sc_toggle_presentation, PRESENTATION, 0, NULL);
387 
388  girara_shortcut_add(gsession, 0, GDK_KEY_q, NULL, sc_quit, PRESENTATION, 0, NULL);
389 
390  /* Presentation mode - Mouse events */
391  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, PRESENTATION, GIRARA_EVENT_SCROLL_UP, UP, NULL);
392  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, PRESENTATION, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL);
393  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, PRESENTATION, GIRARA_EVENT_SCROLL_LEFT, LEFT, NULL);
394  girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, PRESENTATION, GIRARA_EVENT_SCROLL_RIGHT, RIGHT, NULL);
395 
396  girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON1, sc_navigate, PRESENTATION, GIRARA_EVENT_BUTTON_PRESS, NEXT, NULL);
397  girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON3, sc_navigate, PRESENTATION, GIRARA_EVENT_BUTTON_PRESS, PREVIOUS, NULL);
398 
399  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0, sc_mouse_scroll, PRESENTATION, GIRARA_EVENT_SCROLL_UP, LEFT, NULL);
400  girara_mouse_event_add(gsession, GDK_SHIFT_MASK, 0, sc_mouse_scroll, PRESENTATION, GIRARA_EVENT_SCROLL_DOWN, RIGHT, NULL);
401 
402  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, PRESENTATION, GIRARA_EVENT_SCROLL_UP, UP, NULL);
403  girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, PRESENTATION, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL);
404 
405  /* inputbar shortcuts */
406  girara_inputbar_shortcut_add(gsession, 0, GDK_KEY_Escape, sc_abort, 0, NULL);
407  girara_inputbar_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, sc_abort, 0, NULL);
408 
409  /* define default inputbar commands */
410  girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, _("Add a bookmark"));
411  girara_inputbar_command_add(gsession, "bdelete", NULL, cmd_bookmark_delete, cc_bookmarks, _("Delete a bookmark"));
412  girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, cc_bookmarks, _("List all bookmarks"));
413  girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, _("Close current file"));
414  girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, _("Show file information"));
415  girara_inputbar_command_add(gsession, "exec", NULL, cmd_exec, NULL, _("Execute a command"));
416  girara_inputbar_command_add(gsession, "help", NULL, cmd_help, NULL, _("Show help"));
417  girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, _("Open document"));
418  girara_inputbar_command_add(gsession, "quit", "q", cmd_quit, NULL, _("Close zathura"));
419  girara_inputbar_command_add(gsession, "print", NULL, cmd_print, NULL, _("Print document"));
420  girara_inputbar_command_add(gsession, "write", NULL, cmd_save, cc_write, _("Save document"));
421  girara_inputbar_command_add(gsession, "write!", NULL, cmd_savef, cc_write, _("Save document (and force overwriting)"));
422  girara_inputbar_command_add(gsession, "export", NULL, cmd_export, cc_export, _("Save attachments"));
423  girara_inputbar_command_add(gsession, "offset", NULL, cmd_offset, NULL, _("Set page offset"));
424  girara_inputbar_command_add(gsession, "mark", NULL, cmd_marks_add, NULL, _("Mark current location within the document"));
425  girara_inputbar_command_add(gsession, "delmarks", "delm", cmd_marks_delete, NULL, _("Delete the specified marks"));
426  girara_inputbar_command_add(gsession, "nohlsearch", "nohl", cmd_nohlsearch, NULL, _("Don't highlight current search results"));
427  girara_inputbar_command_add(gsession, "hlsearch", NULL, cmd_hlsearch, NULL, _("Highlight current search results"));
428  girara_inputbar_command_add(gsession, "version", NULL, cmd_version, NULL, _("Show version information"));
429 
430  girara_special_command_add(gsession, '/', cmd_search, INCREMENTAL_SEARCH, FORWARD, NULL);
431  girara_special_command_add(gsession, '?', cmd_search, INCREMENTAL_SEARCH, BACKWARD, NULL);
432 
433  /* add shortcut mappings */
434  girara_shortcut_mapping_add(gsession, "abort", sc_abort);
435  girara_shortcut_mapping_add(gsession, "adjust_window", sc_adjust_window);
436  girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode);
437  girara_shortcut_mapping_add(gsession, "display_link", sc_display_link);
438  girara_shortcut_mapping_add(gsession, "focus_inputbar", sc_focus_inputbar);
439  girara_shortcut_mapping_add(gsession, "follow", sc_follow);
440  girara_shortcut_mapping_add(gsession, "goto", sc_goto);
441  girara_shortcut_mapping_add(gsession, "jumplist", sc_jumplist);
442  girara_shortcut_mapping_add(gsession, "bisect", sc_bisect);
443  girara_shortcut_mapping_add(gsession, "navigate", sc_navigate);
444  girara_shortcut_mapping_add(gsession, "navigate_index", sc_navigate_index);
445  girara_shortcut_mapping_add(gsession, "print", sc_print);
446  girara_shortcut_mapping_add(gsession, "quit", sc_quit);
447  girara_shortcut_mapping_add(gsession, "recolor", sc_recolor);
448  girara_shortcut_mapping_add(gsession, "reload", sc_reload);
449  girara_shortcut_mapping_add(gsession, "rotate", sc_rotate);
450  girara_shortcut_mapping_add(gsession, "scroll", sc_scroll);
451  girara_shortcut_mapping_add(gsession, "search", sc_search);
452  girara_shortcut_mapping_add(gsession, "toggle_fullscreen", sc_toggle_fullscreen);
453  girara_shortcut_mapping_add(gsession, "toggle_presentation", sc_toggle_presentation);
454  girara_shortcut_mapping_add(gsession, "toggle_index", sc_toggle_index);
455  girara_shortcut_mapping_add(gsession, "toggle_inputbar", girara_sc_toggle_inputbar);
456  girara_shortcut_mapping_add(gsession, "toggle_page_mode", sc_toggle_page_mode);
457  girara_shortcut_mapping_add(gsession, "toggle_statusbar", girara_sc_toggle_statusbar);
458  girara_shortcut_mapping_add(gsession, "zoom", sc_zoom);
459 
460  /* add argument mappings */
461  girara_argument_mapping_add(gsession, "backward", BACKWARD);
462  girara_argument_mapping_add(gsession, "bottom", BOTTOM);
463  girara_argument_mapping_add(gsession, "default", DEFAULT);
464  girara_argument_mapping_add(gsession, "collapse", COLLAPSE);
465  girara_argument_mapping_add(gsession, "collapse-all", COLLAPSE_ALL);
466  girara_argument_mapping_add(gsession, "down", DOWN);
467  girara_argument_mapping_add(gsession, "expand", EXPAND);
468  girara_argument_mapping_add(gsession, "expand-all", EXPAND_ALL);
469  girara_argument_mapping_add(gsession, "select", SELECT);
470  girara_argument_mapping_add(gsession, "toggle", TOGGLE);
471  girara_argument_mapping_add(gsession, "forward", FORWARD);
472  girara_argument_mapping_add(gsession, "full-down", FULL_DOWN);
473  girara_argument_mapping_add(gsession, "full-up", FULL_UP);
474  girara_argument_mapping_add(gsession, "half-down", HALF_DOWN);
475  girara_argument_mapping_add(gsession, "half-up", HALF_UP);
476  girara_argument_mapping_add(gsession, "full-right", FULL_RIGHT);
477  girara_argument_mapping_add(gsession, "full-left", FULL_LEFT);
478  girara_argument_mapping_add(gsession, "half-right", HALF_RIGHT);
479  girara_argument_mapping_add(gsession, "half-left", HALF_LEFT);
480  girara_argument_mapping_add(gsession, "in", ZOOM_IN);
481  girara_argument_mapping_add(gsession, "left", LEFT);
482  girara_argument_mapping_add(gsession, "next", NEXT);
483  girara_argument_mapping_add(gsession, "out", ZOOM_OUT);
484  girara_argument_mapping_add(gsession, "page-top", PAGE_TOP);
485  girara_argument_mapping_add(gsession, "page-bottom", PAGE_BOTTOM);
486  girara_argument_mapping_add(gsession, "previous", PREVIOUS);
487  girara_argument_mapping_add(gsession, "right", RIGHT);
488  girara_argument_mapping_add(gsession, "specific", ZOOM_SPECIFIC);
489  girara_argument_mapping_add(gsession, "top", TOP);
490  girara_argument_mapping_add(gsession, "up", UP);
491  girara_argument_mapping_add(gsession, "best-fit", ZATHURA_ADJUST_BESTFIT);
492  girara_argument_mapping_add(gsession, "width", ZATHURA_ADJUST_WIDTH);
493  girara_argument_mapping_add(gsession, "rotate-cw", ROTATE_CW);
494  girara_argument_mapping_add(gsession, "rotate-ccw", ROTATE_CCW);
495 }
496 
497 void
498 config_load_files(zathura_t* zathura)
499 {
500  /* load global configuration files */
501  char* config_path = girara_get_xdg_path(XDG_CONFIG_DIRS);
502  girara_list_t* config_dirs = girara_split_path_array(config_path);
503  ssize_t size = girara_list_size(config_dirs) - 1;
504  for (; size >= 0; --size) {
505  const char* dir = girara_list_nth(config_dirs, size);
506  char* file = g_build_filename(dir, ZATHURA_RC, NULL);
507  girara_config_parse(zathura->ui.session, file);
508  g_free(file);
509  }
510  girara_list_free(config_dirs);
511  g_free(config_path);
512 
513  girara_config_parse(zathura->ui.session, GLOBAL_RC);
514 
515  /* load local configuration files */
516  char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL);
517  girara_config_parse(zathura->ui.session, configuration_file);
518  g_free(configuration_file);
519 }