zathura.h 10.6 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>
9
#include "macros.h"
10
#include "types.h"
11

12
13
14
15
#if (GTK_MAJOR_VERSION == 3)
#include <gtk/gtkx.h>
#endif

16
17
#define ZATHURA_PAGE_CACHE_DEFAULT_SIZE		15

Moritz Lipp's avatar
Moritz Lipp committed
18
19
20
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,
Moritz Lipp's avatar
Moritz Lipp committed
21
22
23
24
  BACKWARD, CONTINUOUS, DELETE_LAST, EXPAND, EXPAND_ALL, COLLAPSE_ALL, COLLAPSE,
  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 };
Moritz Lipp's avatar
Moritz Lipp committed
25

26
27
28
29
30
/* unspecified page number */
enum {
  ZATHURA_PAGE_NUMBER_UNSPECIFIED = INT_MIN
};

Marwan Tanager's avatar
Marwan Tanager committed
31
/* forward declaration for types from database.h */
32
typedef struct _ZathuraDatabase zathura_database_t;
33

34
35
36
37
38
39
40
41
42
43
/**
 * Jump
 */
typedef struct zathura_jump_s
{
  unsigned int page;
  double x;
  double y;
} zathura_jump_t;

44
struct zathura_s
Moritz Lipp's avatar
Moritz Lipp committed
45
{
Moritz Lipp's avatar
Moritz Lipp committed
46
  struct
Moritz Lipp's avatar
Moritz Lipp committed
47
  {
Moritz Lipp's avatar
Moritz Lipp committed
48
    girara_session_t* session; /**< girara interface session */
Moritz Lipp's avatar
Moritz Lipp committed
49
50
51

    struct
    {
Moritz Lipp's avatar
Moritz Lipp committed
52
53
54
      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
55
    } statusbar;
Moritz Lipp's avatar
Moritz Lipp committed
56

Moritz Lipp's avatar
Moritz Lipp committed
57
58
    struct
    {
Moritz Lipp's avatar
Moritz Lipp committed
59
      GdkColor highlight_color; /**< Color for highlighting */
60
      GdkColor highlight_color_active; /** Color for highlighting */
61
62
      GdkColor render_loading_bg; /**< Background color for render "Loading..." */
      GdkColor render_loading_fg; /**< Foreground color for render "Loading..." */
Moritz Lipp's avatar
Moritz Lipp committed
63
64
    } colors;

65
66
    GtkWidget *page_widget_alignment;
    GtkWidget *page_widget; /**< Widget that contains all rendered pages */
Moritz Lipp's avatar
Moritz Lipp committed
67
    GtkWidget *index; /**< Widget to show the index of the document */
68
69
70

    GtkAdjustment *hadjustment; /**< Tracking hadjustment */
    GtkAdjustment *vadjustment; /**< Tracking vadjustment */
Moritz Lipp's avatar
Moritz Lipp committed
71
  } ui;
Moritz Lipp's avatar
Moritz Lipp committed
72

Moritz Lipp's avatar
Moritz Lipp committed
73
74
  struct
  {
75
    ZathuraRenderer* render_thread; /**< The thread responsible for rendering the pages */
Moritz Lipp's avatar
Moritz Lipp committed
76
  } sync;
Moritz Lipp's avatar
Moritz Lipp committed
77

Sebastian Ramacher's avatar
Sebastian Ramacher committed
78
79
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
80
    void* manager; /**< Plugin manager */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
81
82
  } plugins;

83
84
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
85
86
    gchar* config_dir; /**< Path to the configuration directory */
    gchar* data_dir; /**< Path to the data directory */
87
88
  } config;

89
90
91
92
93
94
  struct
  {
    bool enabled;
    gchar* editor;
  } synctex;

95
96
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
97
98
    GtkPrintSettings* settings; /**< Print settings */
    GtkPageSetup* page_setup; /**< Saved page setup */
99
100
  } print;

Moritz Lipp's avatar
Moritz Lipp committed
101
102
  struct
  {
103
    bool update_page_number; /**< Update current page number */
104
    int search_direction; /**< Current search direction (FORWARD or BACKWARD) */
Moritz Lipp's avatar
Moritz Lipp committed
105
    girara_list_t* marks; /**< Marker */
106
    char** arguments; /**> Arguments that were passed at startup */
Moritz Lipp's avatar
Moritz Lipp committed
107
108
  } global;

Pavel Borzenkov's avatar
Pavel Borzenkov committed
109
110
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
111
112
113
114
    girara_mode_t normal; /**< Normal mode */
    girara_mode_t fullscreen; /**< Fullscreen mode */
    girara_mode_t index; /**< Index mode */
    girara_mode_t insert; /**< Insert mode */
Pavel Borzenkov's avatar
Pavel Borzenkov committed
115
  } modes;
Moritz Lipp's avatar
Moritz Lipp committed
116

117
118
  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
119
120
    gchar* file; /**< bookmarks file */
    girara_list_t* bookmarks; /**< bookmarks */
121
122
  } bookmarks;

123
124
125
126
127
128
129
130
  struct
  {
    girara_list_t* list;
    girara_list_iterator_t *cur;
    unsigned int size;
    unsigned int max_size;
  } jumplist;

131
132
133
134
135
  struct
  {
    gchar* file;
  } stdin_support;

Moritz Lipp's avatar
Moritz Lipp committed
136
  zathura_document_t* document; /**< The current document */
137
  GtkWidget** pages; /**< The page widgets */
Moritz Lipp's avatar
Moritz Lipp committed
138
  zathura_database_t* database; /**< The database */
Moritz Lipp's avatar
Moritz Lipp committed
139
140
141
142
143
144
145
146
147
148

  /**
   * 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;
149
150
151
152
153
154
155
156
157

  /**
   * The page cache
   */
  struct {
    int* cache;
    unsigned int size;
    unsigned int num_cached_pages;
  } page_cache;
158
159
160
161
162
163
164
165
166

  /**
   * 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;
167
};
Moritz Lipp's avatar
Moritz Lipp committed
168

169
170
171
172
173
174
175
/**
 * 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
176
177
178
/**
 * Initializes zathura
 *
179
180
 * @param zathura The zathura session
 * @return true if initialization has been successful
Moritz Lipp's avatar
Moritz Lipp committed
181
 */
182
bool zathura_init(zathura_t* zathura);
Moritz Lipp's avatar
Moritz Lipp committed
183
184

/**
185
 * Free zathura session
Moritz Lipp's avatar
Moritz Lipp committed
186
 *
187
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
188
 */
Moritz Lipp's avatar
Moritz Lipp committed
189
void zathura_free(zathura_t* zathura);
Moritz Lipp's avatar
Moritz Lipp committed
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
 * Set parent window id
 *
 * @param zathura The zathura session
 * @param xid The window id
 */
#if (GTK_MAJOR_VERSION == 2)
void zathura_set_xid(zathura_t* zathura, GdkNativeWindow xid);
#else
void zathura_set_xid(zathura_t* zathura, Window xid);
#endif

/**
 * 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);

/**
 * 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);

/**
 * Enables synctex support and sets the synctex editor command
 *
 * @param zathura The zathura session
 * @param command Synctex editor command
 */
void zathura_set_synctex_editor_command(zathura_t* zathura, const char* command);

Moritz Lipp's avatar
Moritz Lipp committed
235
/**
236
 * En/Disable zathuras synctex support
Moritz Lipp's avatar
Moritz Lipp committed
237
238
239
240
 *
 * @param zathura The zathura session
 * @param value The value
 */
241
void zathura_set_synctex(zathura_t* zathura, bool value);
Moritz Lipp's avatar
Moritz Lipp committed
242

243
244
245
246
247
248
249
250
/**
 * Sets the program parameters
 *
 * @param zathura The zathura session
 * @param argv List of arguments
 */
void zathura_set_argv(zathura_t* zathura, char** argv);

Moritz Lipp's avatar
Moritz Lipp committed
251
252
253
/**
 * Opens a file
 *
254
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
255
256
257
258
259
 * @param path The path to the file
 * @param password The password of the file
 *
 * @return If no error occured true, otherwise false, is returned.
 */
260
261
bool document_open(zathura_t* zathura, const char* path, const char* password,
                   int page_number);
Moritz Lipp's avatar
Moritz Lipp committed
262

263
264
265
266
267
268
269
/**
 * Opens a file (idle)
 *
 * @param zathura The zathura session
 * @param path The path to the file
 * @param password The password of the file
 */
270
271
void document_open_idle(zathura_t* zathura, const char* path,
                        const char* password, int page_number);
272

273
274
275
276
277
278
279
280
281
282
283
/**
 * 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
284
285
286
/**
 * Closes the current opened document
 *
287
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
288
 * @param keep_monitor Set to true if monitor should be kept (sc_reload)
Moritz Lipp's avatar
Moritz Lipp committed
289
290
 * @return If no error occured true, otherwise false, is returned.
 */
Moritz Lipp's avatar
Moritz Lipp committed
291
bool document_close(zathura_t* zathura, bool keep_monitor);
Moritz Lipp's avatar
Moritz Lipp committed
292
293
294
295

/**
 * Opens the page with the given number
 *
296
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
297
 * @param page_id The id of the page that should be set
Moritz Lipp's avatar
Moritz Lipp committed
298
299
 * @return If no error occured true, otherwise false, is returned.
 */
Moritz Lipp's avatar
Moritz Lipp committed
300
bool page_set(zathura_t* zathura, unsigned int page_id);
Moritz Lipp's avatar
Moritz Lipp committed
301

302
303
304
305
/**
 * Opens the page with the given number (delayed)
 *
 * @param zathura The zathura session
Moritz Lipp's avatar
Moritz Lipp committed
306
 * @param page_id The id of the page that should be set
307
308
309
310
 * @return If no error occured true, otherwise false, is returned.
 */
bool page_set_delayed(zathura_t* zathura, unsigned int page_id);

Moritz Lipp's avatar
Moritz Lipp committed
311
312
313
314
315
316
317
/**
 * Moves to the given position
 *
 * @param zathura Zathura session
 * @param position_x X coordinate
 * @param position_y Y coordinate
 */
318
319
320
321
322
323
324
325
326
327
void position_set_delayed(zathura_t* zathura, double position_x, double position_y);

/**
 * Moves to the given position
 *
 * @param zathura Zathura session
 * @param position_x X coordinate
 * @param position_y Y coordinate
 */
void position_set(zathura_t* zathura, double position_x, double position_y);
Moritz Lipp's avatar
Moritz Lipp committed
328

329
330
331
/**
 * Builds the box structure to show the rendered pages
 *
332
 * @param zathura The zathura session
333
 * @param pages_per_row Number of shown pages per row
334
 * @param first_page_column Column on which first page start
335
 */
336
void page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row, unsigned int first_page_column);
337

338
339
340
341
342
343
344
345
/**
 * 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);

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/**
 * 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);

362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/**
 * 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);

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/**
 * 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);

408
409
410
411
412
413
414
/**
 * Add a page to the page cache
 *
 * @param zathura The zathura session
 * @param page_index The index of the page to be cached
 */
void zathura_page_cache_add(zathura_t* zathura, unsigned int page_index);
415

416
417
418
419
420
421
422
423
424
425
/**
 * Checks if the given page is cached
 *
 * @param zathura The zathura session
 * @param page_index The index of the page that may be cached
 *
 * @return true if page is cached otherwise false
 */
bool zathura_page_cache_is_cached(zathura_t* zathura, unsigned int page_index);

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