zathura.h 10.3 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1
2
3
4
5
6
/* See LICENSE file for license and copyright information */

#ifndef ZATHURA_H
#define ZATHURA_H

#include <stdbool.h>
7
8
#include <girara/types.h>
#include <gtk/gtk.h>
Sebastian Ramacher's avatar
Sebastian Ramacher committed
9
#include <gtk/gtkx.h>
10
#include "macros.h"
11
#include "types.h"
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
enum {
  NEXT,
  PREVIOUS,
  LEFT,
  RIGHT,
  UP,
  DOWN,
  BOTTOM,
  TOP,
  HIDE,
  HIGHLIGHT,
  DELETE_LAST_WORD,
  DELETE_LAST_CHAR,
  DEFAULT,
  ERROR,
  WARNING,
  NEXT_GROUP,
  PREVIOUS_GROUP,
  ZOOM_IN,
  ZOOM_OUT,
  ZOOM_ORIGINAL,
  ZOOM_SPECIFIC,
  FORWARD,
  BACKWARD,
  CONTINUOUS,
  DELETE_LAST,
  EXPAND,
  EXPAND_ALL,
  COLLAPSE_ALL,
  COLLAPSE,
  TOGGLE,
  SELECT,
  GOTO_DEFAULT,
  GOTO_LABELS,
  GOTO_OFFSET,
  HALF_UP,
  HALF_DOWN,
  FULL_UP,
  FULL_DOWN,
  HALF_LEFT,
  HALF_RIGHT,
  FULL_LEFT,
  FULL_RIGHT,
  NEXT_CHAR,
  PREVIOUS_CHAR,
  DELETE_TO_LINE_START,
  APPEND_FILEPATH,
  ROTATE_CW,
  ROTATE_CCW,
  PAGE_BOTTOM,
63
64
65
  PAGE_TOP,
  BIDIRECTIONAL,
  ZOOM_SMOOTH
66
};
Moritz Lipp's avatar
Moritz Lipp committed
67

68
69
70
71
72
/* unspecified page number */
enum {
  ZATHURA_PAGE_NUMBER_UNSPECIFIED = INT_MIN
};

73
74
75
/* cache constants */
enum {
  ZATHURA_PAGE_CACHE_DEFAULT_SIZE = 15,
76
77
  ZATHURA_PAGE_CACHE_MAX_SIZE = 1024,
  ZATHURA_PAGE_THUMBNAIL_DEFAULT_SIZE = 4*1024*1024
78
79
};

Marwan Tanager's avatar
Marwan Tanager committed
80
/* forward declaration for types from database.h */
81
typedef struct _ZathuraDatabase zathura_database_t;
82

83
84
85
86
87
88
89
90
91
92
/**
 * Jump
 */
typedef struct zathura_jump_s
{
  unsigned int page;
  double x;
  double y;
} zathura_jump_t;

93
struct zathura_s
Moritz Lipp's avatar
Moritz Lipp committed
94
{
Moritz Lipp's avatar
Moritz Lipp committed
95
  struct
Moritz Lipp's avatar
Moritz Lipp committed
96
  {
Moritz Lipp's avatar
Moritz Lipp committed
97
    girara_session_t* session; /**< girara interface session */
Moritz Lipp's avatar
Moritz Lipp committed
98
99
100

    struct
    {
Moritz Lipp's avatar
Moritz Lipp committed
101
102
103
      girara_statusbar_item_t* buffer; /**< buffer statusbar entry */
      girara_statusbar_item_t* file; /**< file statusbar entry */
      girara_statusbar_item_t* page_number; /**< page number statusbar entry */
Moritz Lipp's avatar
Moritz Lipp committed
104
    } statusbar;
Moritz Lipp's avatar
Moritz Lipp committed
105

Moritz Lipp's avatar
Moritz Lipp committed
106
107
    struct
    {
108
109
110
111
      GdkRGBA highlight_color; /**< Color for highlighting */
      GdkRGBA highlight_color_active; /** Color for highlighting */
      GdkRGBA render_loading_bg; /**< Background color for render "Loading..." */
      GdkRGBA render_loading_fg; /**< Foreground color for render "Loading..." */
Moritz Lipp's avatar
Moritz Lipp committed
112
113
    } colors;

114
    GtkWidget *page_widget; /**< Widget that contains all rendered pages */
Moritz Lipp's avatar
Moritz Lipp committed
115
    GtkWidget *index; /**< Widget to show the index of the document */
Moritz Lipp's avatar
Moritz Lipp committed
116
  } ui;
Moritz Lipp's avatar
Moritz Lipp committed
117

Moritz Lipp's avatar
Moritz Lipp committed
118
119
  struct
  {
120
    ZathuraRenderer* render_thread; /**< The thread responsible for rendering the pages */
Moritz Lipp's avatar
Moritz Lipp committed
121
  } sync;
Moritz Lipp's avatar
Moritz Lipp committed
122

Sebastian Ramacher's avatar
Sebastian Ramacher committed
123
124
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
125
    void* manager; /**< Plugin manager */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
126
127
  } plugins;

128
129
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
130
131
    gchar* config_dir; /**< Path to the configuration directory */
    gchar* data_dir; /**< Path to the data directory */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
132
    gchar* cache_dir; /**< Path to the cache directory */
133
134
  } config;

135
136
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
137
138
    GtkPrintSettings* settings; /**< Print settings */
    GtkPageSetup* page_setup; /**< Saved page setup */
139
140
  } print;

Moritz Lipp's avatar
Moritz Lipp committed
141
142
  struct
  {
143
    int search_direction; /**< Current search direction (FORWARD or BACKWARD) */
Moritz Lipp's avatar
Moritz Lipp committed
144
    girara_list_t* marks; /**< Marker */
145
    char** arguments; /**> Arguments that were passed at startup */
Moritz Lipp's avatar
Moritz Lipp committed
146
147
  } global;

Pavel Borzenkov's avatar
Pavel Borzenkov committed
148
149
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
150
151
152
153
    girara_mode_t normal; /**< Normal mode */
    girara_mode_t fullscreen; /**< Fullscreen mode */
    girara_mode_t index; /**< Index mode */
    girara_mode_t insert; /**< Insert mode */
154
    girara_mode_t presentation; /**< Presentation mode */
Pavel Borzenkov's avatar
Pavel Borzenkov committed
155
  } modes;
Moritz Lipp's avatar
Moritz Lipp committed
156

157
158
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
159
160
    gchar* file; /**< bookmarks file */
    girara_list_t* bookmarks; /**< bookmarks */
161
162
  } bookmarks;

163
164
165
166
167
168
169
170
  struct
  {
    girara_list_t* list;
    girara_list_iterator_t *cur;
    unsigned int size;
    unsigned int max_size;
  } jumplist;

171
172
173
  struct
  {
    guint refresh_view;
Moritz Lipp's avatar
Moritz Lipp committed
174
175
176
#ifdef G_OS_UNIX
    guint sigterm;
#endif
177
178
  } signals;

179
180
181
182
183
  struct
  {
    gchar* file;
  } stdin_support;

Moritz Lipp's avatar
Moritz Lipp committed
184
  zathura_document_t* document; /**< The current document */
185
  GtkWidget** pages; /**< The page widgets */
Moritz Lipp's avatar
Moritz Lipp committed
186
  zathura_database_t* database; /**< The database */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
187
  ZathuraDbus* dbus; /**< D-Bus service */
Moritz Lipp's avatar
Moritz Lipp committed
188
189
190
191
192
193
194
195
196
197

  /**
   * File monitor
   */
  struct {
    GFileMonitor* monitor; /**< File monitor */
    GFile* file; /**< File for file monitor */
    gchar* file_path; /**< Save file path */
    gchar* password; /**< Save password */
  } file_monitor;
198

199
200
201
202
203
204
205
206
  /**
   * Bisect stage
   */
  struct {
    unsigned int last_jump; /**< Page jumped to by bisect */
    unsigned int start; /**< Bisection range - start */
    unsigned int end; /**< Bisection range - end */
  } bisect;
207
};
Moritz Lipp's avatar
Moritz Lipp committed
208

209
210
211
212
213
214
215
/**
 * Creates a zathura session
 *
 * @return zathura session object or NULL if zathura could not be creeated
 */
zathura_t* zathura_create(void);

Moritz Lipp's avatar
Moritz Lipp committed
216
217
218
/**
 * Initializes zathura
 *
219
220
 * @param zathura The zathura session
 * @return true if initialization has been successful
Moritz Lipp's avatar
Moritz Lipp committed
221
 */
222
bool zathura_init(zathura_t* zathura);
Moritz Lipp's avatar
Moritz Lipp committed
223
224

/**
225
 * Free zathura session
Moritz Lipp's avatar
Moritz Lipp committed
226
 *
227
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
228
 */
Moritz Lipp's avatar
Moritz Lipp committed
229
void zathura_free(zathura_t* zathura);
Moritz Lipp's avatar
Moritz Lipp committed
230

231
#ifdef GDK_WINDOWING_X11
232
233
234
235
236
237
238
/**
 * Set parent window id
 *
 * @param zathura The zathura session
 * @param xid The window id
 */
void zathura_set_xid(zathura_t* zathura, Window xid);
239
#endif
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

/**
 * Set the path to the configuration directory
 *
 * @param zathura The zathura session
 * @param dir Directory path
 */
void zathura_set_config_dir(zathura_t* zathura, const char* dir);

/**
 * Set the path to the data directory
 *
 * @param zathura The zathura session
 * @param dir Directory path
 */
void zathura_set_data_dir(zathura_t* zathura, const char* dir);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
257
258
259
260
261
262
263
264
/**
 * Set the path to the cache directory.
 *
 * @param zathura The Zathura session
 * @param dir Directory path
 */
void zathura_set_cache_dir(zathura_t* zathura, const char* dir);

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
 * Set the path to the plugin directory
 *
 * @param zathura The zathura session
 * @param dir Directory path
 */
void zathura_set_plugin_dir(zathura_t* zathura, const char* dir);

/**
 * Sets the program parameters
 *
 * @param zathura The zathura session
 * @param argv List of arguments
 */
void zathura_set_argv(zathura_t* zathura, char** argv);

281
282
283
284
285
286
287
288
/**
 * Returns the filename formatted according to the user config.
 * Takes into account the basename setting and the home-tilde setting.
 *
 * @param zatura The zathura session
 * @param file_path The filename to be formatted
 * @param statusbar True if for statusbar, false if for window title
 */
289
char* get_formatted_filename(zathura_t* zathura, const char* file_path, bool statusbar);
290

Moritz Lipp's avatar
Moritz Lipp committed
291
292
293
/**
 * Opens a file
 *
294
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
295
296
 * @param path The path to the file
 * @param password The password of the file
Moritz Lipp's avatar
Moritz Lipp committed
297
 * @param page_number Open given page number
Moritz Lipp's avatar
Moritz Lipp committed
298
299
300
 *
 * @return If no error occured true, otherwise false, is returned.
 */
301
302
bool document_open(zathura_t* zathura, const char* path, const char* password,
                   int page_number);
Moritz Lipp's avatar
Moritz Lipp committed
303

304
305
306
307
308
309
/**
 * Opens a file (idle)
 *
 * @param zathura The zathura session
 * @param path The path to the file
 * @param password The password of the file
Moritz Lipp's avatar
Moritz Lipp committed
310
311
 * @param page_number Open given page number
 * @param mode Open in given page mode
312
 */
313
void document_open_idle(zathura_t* zathura, const char* path,
Sebastian Ramacher's avatar
Sebastian Ramacher committed
314
315
                        const char* password, int page_number,
                        const char* mode);
316

317
318
319
320
321
322
323
324
325
326
327
/**
 * Save a open file
 *
 * @param zathura The zathura session
 * @param path The path
 * @param overwrite Overwrite existing file
 *
 * @return If no error occured true, otherwise false, is returned.
 */
bool document_save(zathura_t* zathura, const char* path, bool overwrite);

Moritz Lipp's avatar
Moritz Lipp committed
328
329
330
/**
 * Closes the current opened document
 *
331
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
332
 * @param keep_monitor Set to true if monitor should be kept (sc_reload)
Moritz Lipp's avatar
Moritz Lipp committed
333
334
 * @return If no error occured true, otherwise false, is returned.
 */
Moritz Lipp's avatar
Moritz Lipp committed
335
bool document_close(zathura_t* zathura, bool keep_monitor);
Moritz Lipp's avatar
Moritz Lipp committed
336
337
338
339

/**
 * Opens the page with the given number
 *
340
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
341
 * @param page_id The id of the page that should be set
Moritz Lipp's avatar
Moritz Lipp committed
342
343
 * @return If no error occured true, otherwise false, is returned.
 */
Moritz Lipp's avatar
Moritz Lipp committed
344
bool page_set(zathura_t* zathura, unsigned int page_id);
Moritz Lipp's avatar
Moritz Lipp committed
345

346
347
348
349
350
351
/**
 * Moves to the given position
 *
 * @param zathura Zathura session
 * @param position_x X coordinate
 * @param position_y Y coordinate
352
 * @return If no error occured true, otherwise false, is returned.
353
 */
354
bool position_set(zathura_t* zathura, double position_x, double position_y);
Moritz Lipp's avatar
Moritz Lipp committed
355

356
357
358
359
360
361
362
/**
 * Refresh the page view
 *
 * @param zathura Zathura session
 */
void refresh_view(zathura_t* zathura);

363
364
365
366
367
368
369
/**
 * Recompute the scale according to settings
 *
 * @param zathura Zathura session
 */
bool adjust_view(zathura_t* zathura);

370
371
372
/**
 * Builds the box structure to show the rendered pages
 *
373
 * @param zathura The zathura session
374
 * @param page_padding padding in pixels between pages
375
 * @param pages_per_row Number of shown pages per row
376
 * @param first_page_column Column on which first page start
377
 */
378
379
void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
                          unsigned int pages_per_row, unsigned int first_page_column);
380

381
382
383
384
385
386
387
388
/**
 * Updates the page number in the statusbar. Note that 1 will be added to the
 * displayed number
 *
 * @param zathura The zathura session
 */
void statusbar_page_number_update(zathura_t* zathura);

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/**
 * Checks whether current jump has a previous jump
 *
 * @param zathura The zathura session
 * @return true if current jump has a previous jump
 */
bool zathura_jumplist_has_previous(zathura_t* zathura);

/**
 * Checks whether current jump has a next jump
 *
 * @param zathura The zathura session
 * @return true if current jump has a next jump
 */
bool zathura_jumplist_has_next(zathura_t* zathura);

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/**
 * Return current jump in the jumplist
 *
 * @param zathura The zathura session
 * @return current jump
 */
zathura_jump_t* zathura_jumplist_current(zathura_t* zathura);

/**
 * Move forward in the jumplist
 *
 * @param zathura The zathura session
 */
void zathura_jumplist_forward(zathura_t* zathura);

/**
 * Move backward in the jumplist
 *
 * @param zathura The zathura session
 */
void zathura_jumplist_backward(zathura_t* zathura);

/**
 * Add current page as a new item to the jumplist after current position
 *
 * @param zathura The zathura session
 */
void zathura_jumplist_add(zathura_t* zathura);

434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/**
 * Trim entries from the beginning of the jumplist to maintain it's maximum size constraint.
 *
 * @param zathura The zathura session
 */
void zathura_jumplist_trim(zathura_t* zathura);

/**
 * Load the jumplist of the specified file
 *
 * @param zathura The zathura session
 * @param file The file whose jumplist is to be loaded
 *
 * return A linked list of zathura_jump_t structures constituting the jumplist of the specified file, or NULL.
 */
bool zathura_jumplist_load(zathura_t* zathura, const char* file);

Moritz Lipp's avatar
Moritz Lipp committed
451
#endif // ZATHURA_H