1 /* SPDX-License-Identifier: Zlib */ 2 3 #ifndef ZATHURA_H 4 #define ZATHURA_H 5 6 #include <stdbool.h> 7 #include <girara/types.h> 8 #include <girara/session.h> 9 #include <gtk/gtk.h> 10 #ifdef GDK_WINDOWING_X11 11 #include <gtk/gtkx.h> 12 #endif 13 #include "macros.h" 14 #include "types.h" 15 #include "jumplist.h" 16 #include "file-monitor.h" 17 18 enum { 19 NEXT, 20 PREVIOUS, 21 LEFT, 22 RIGHT, 23 UP, 24 DOWN, 25 BOTTOM, 26 TOP, 27 HIDE, 28 HIGHLIGHT, 29 DELETE_LAST_WORD, 30 DELETE_LAST_CHAR, 31 DEFAULT, 32 ERROR, 33 WARNING, 34 NEXT_GROUP, 35 PREVIOUS_GROUP, 36 ZOOM_IN, 37 ZOOM_OUT, 38 ZOOM_ORIGINAL, 39 ZOOM_SPECIFIC, 40 FORWARD, 41 BACKWARD, 42 CONTINUOUS, 43 DELETE_LAST, 44 EXPAND, 45 EXPAND_ALL, 46 COLLAPSE_ALL, 47 COLLAPSE, 48 TOGGLE, 49 SELECT, 50 GOTO_DEFAULT, 51 GOTO_LABELS, 52 GOTO_OFFSET, 53 HALF_UP, 54 HALF_DOWN, 55 FULL_UP, 56 FULL_DOWN, 57 HALF_LEFT, 58 HALF_RIGHT, 59 FULL_LEFT, 60 FULL_RIGHT, 61 NEXT_CHAR, 62 PREVIOUS_CHAR, 63 DELETE_TO_LINE_START, 64 APPEND_FILEPATH, 65 ROTATE_CW, 66 ROTATE_CCW, 67 PAGE_BOTTOM, 68 PAGE_TOP, 69 BIDIRECTIONAL, 70 ZOOM_SMOOTH 71 }; 72 73 /* unspecified page number */ 74 enum { 75 ZATHURA_PAGE_NUMBER_UNSPECIFIED = INT_MIN 76 }; 77 78 /* cache constants */ 79 enum { 80 ZATHURA_PAGE_CACHE_DEFAULT_SIZE = 15, 81 ZATHURA_PAGE_CACHE_MAX_SIZE = 1024, 82 ZATHURA_PAGE_THUMBNAIL_DEFAULT_SIZE = 4*1024*1024 83 }; 84 85 typedef enum { 86 ZATHURA_SANDBOX_NONE, 87 ZATHURA_SANDBOX_NORMAL, 88 ZATHURA_SANDBOX_STRICT 89 } zathura_sandbox_t; 90 91 /* forward declaration for types from database.h */ 92 typedef struct _ZathuraDatabase zathura_database_t; 93 94 struct zathura_s 95 { 96 struct 97 { 98 girara_session_t* session; /**< girara interface session */ 99 100 struct 101 { 102 girara_statusbar_item_t* buffer; /**< buffer statusbar entry */ 103 girara_statusbar_item_t* file; /**< file statusbar entry */ 104 girara_statusbar_item_t* page_number; /**< page number statusbar entry */ 105 } statusbar; 106 107 struct 108 { 109 GdkRGBA highlight_color; /**< Color for highlighting */ 110 GdkRGBA highlight_color_active; /** Color for highlighting */ 111 GdkRGBA render_loading_bg; /**< Background color for render "Loading..." */ 112 GdkRGBA render_loading_fg; /**< Foreground color for render "Loading..." */ 113 } colors; 114 115 GtkWidget *page_widget; /**< Widget that contains all rendered pages */ 116 GtkWidget *index; /**< Widget to show the index of the document */ 117 } ui; 118 119 struct 120 { 121 ZathuraRenderer* render_thread; /**< The thread responsible for rendering the pages */ 122 } sync; 123 124 struct 125 { 126 void* manager; /**< Plugin manager */ 127 } plugins; 128 129 struct 130 { 131 gchar* config_dir; /**< Path to the configuration directory */ 132 gchar* data_dir; /**< Path to the data directory */ 133 gchar* cache_dir; /**< Path to the cache directory */ 134 } config; 135 136 struct 137 { 138 GtkPrintSettings* settings; /**< Print settings */ 139 GtkPageSetup* page_setup; /**< Saved page setup */ 140 } print; 141 142 struct 143 { 144 int search_direction; /**< Current search direction (FORWARD or BACKWARD) */ 145 girara_list_t* marks; /**< Marker */ 146 char** arguments; /**> Arguments that were passed at startup */ 147 zathura_sandbox_t sandbox; /**< Sandbox mode */ 148 } global; 149 150 struct 151 { 152 girara_mode_t normal; /**< Normal mode */ 153 girara_mode_t fullscreen; /**< Fullscreen mode */ 154 girara_mode_t index; /**< Index mode */ 155 girara_mode_t insert; /**< Insert mode */ 156 girara_mode_t presentation; /**< Presentation mode */ 157 } modes; 158 159 struct 160 { 161 gchar* file; /**< bookmarks file */ 162 girara_list_t* bookmarks; /**< bookmarks */ 163 } bookmarks; 164 165 zathura_jumplist_t jumplist; 166 167 struct 168 { 169 guint refresh_view; 170 #ifdef G_OS_UNIX 171 guint sigterm; 172 #endif 173 174 gulong monitors_changed_handler; /**< Signal handler for monitors-changed */ 175 } signals; 176 177 struct 178 { 179 gchar* file; 180 } stdin_support; 181 182 zathura_document_t* document; /**< The current document */ 183 GtkWidget** pages; /**< The page widgets */ 184 zathura_database_t* database; /**< The database */ 185 ZathuraDbus* dbus; /**< D-Bus service */ 186 ZathuraRenderRequest* window_icon_render_request; /**< Render request for window icon */ 187 188 /** 189 * File monitor 190 */ 191 struct { 192 ZathuraFileMonitor* monitor; /**< File monitor */ 193 gchar* password; /**< Save password */ 194 } file_monitor; 195 196 /** 197 * Bisect stage 198 */ 199 struct { 200 unsigned int last_jump; /**< Page jumped to by bisect */ 201 unsigned int start; /**< Bisection range - start */ 202 unsigned int end; /**< Bisection range - end */ 203 } bisect; 204 205 /** 206 * Storage for shortcuts. 207 */ 208 struct { 209 struct { 210 int x; 211 int y; 212 } mouse; 213 struct { 214 int pages; 215 } toggle_page_mode; 216 struct { 217 int pages; 218 char* first_page_column_list; 219 double zoom; 220 } toggle_presentation_mode; 221 } shortcut; 222 223 /** 224 * Context for MIME type detection 225 */ 226 zathura_content_type_context_t* content_type_context; 227 }; 228 229 /** 230 * Creates a zathura session 231 * 232 * @return zathura session object or NULL if zathura could not be creeated 233 */ 234 zathura_t* zathura_create(void); 235 236 /** 237 * Initializes zathura 238 * 239 * @param zathura The zathura session 240 * @return true if initialization has been successful 241 */ 242 bool zathura_init(zathura_t* zathura); 243 244 /** 245 * Free zathura session 246 * 247 * @param zathura The zathura session 248 */ 249 void zathura_free(zathura_t* zathura); 250 251 /** 252 * Set parent window id. This does not have an effect if the underlying Gtk 253 * backend is not X11. 254 * 255 * @param zathura The zathura session 256 * @param xid The window id 257 */ 258 void zathura_set_xid(zathura_t* zathura, Window xid); 259 260 /** 261 * Set the path to the configuration directory 262 * 263 * @param zathura The zathura session 264 * @param dir Directory path 265 */ 266 void zathura_set_config_dir(zathura_t* zathura, const char* dir); 267 268 /** 269 * Set the path to the data directory 270 * 271 * @param zathura The zathura session 272 * @param dir Directory path 273 */ 274 void zathura_set_data_dir(zathura_t* zathura, const char* dir); 275 276 /** 277 * Set the path to the cache directory. 278 * 279 * @param zathura The Zathura session 280 * @param dir Directory path 281 */ 282 void zathura_set_cache_dir(zathura_t* zathura, const char* dir); 283 284 /** 285 * Set the path to the plugin directory 286 * 287 * @param zathura The zathura session 288 * @param dir Directory path 289 */ 290 void zathura_set_plugin_dir(zathura_t* zathura, const char* dir); 291 292 /** 293 * Sets the program parameters 294 * 295 * @param zathura The zathura session 296 * @param argv List of arguments 297 */ 298 void zathura_set_argv(zathura_t* zathura, char** argv); 299 300 /** 301 * Calculate and store the monitor PPI for the view widget 302 * 303 * @param zathura The zathura session 304 */ 305 void zathura_update_view_ppi(zathura_t* zathura); 306 307 /** 308 * Opens a file 309 * 310 * @param zathura The zathura session 311 * @param path The path to the file 312 * @param password The password of the file 313 * @param page_number Open given page number 314 * 315 * @return If no error occurred true, otherwise false, is returned. 316 */ 317 bool document_open(zathura_t* zathura, const char* path, const char* uri, const char* password, 318 int page_number); 319 320 /** 321 * Opens a file 322 * 323 * @param zathura The zathura session 324 * @param path The path to the file 325 * @param password The password of the file 326 * @param synctex Open at the given SyncTeX string 327 * 328 * @return If no error occurred true, otherwise false, is returned. 329 */ 330 bool document_open_synctex(zathura_t* zathura, const char* path, const char* uri, 331 const char* password, const char* synctex); 332 333 /** 334 * Opens a file (idle) 335 * 336 * @param zathura The zathura session 337 * @param path The path to the file 338 * @param password The password of the file 339 * @param page_number Open given page number 340 * @param mode Open in given page mode 341 * @param synctex SyncTeX string 342 */ 343 void document_open_idle(zathura_t* zathura, const char* path, 344 const char* password, int page_number, 345 const char* mode, const char* synctex); 346 347 /** 348 * Save a open file 349 * 350 * @param zathura The zathura session 351 * @param path The path 352 * @param overwrite Overwrite existing file 353 * 354 * @return If no error occurred true, otherwise false, is returned. 355 */ 356 bool document_save(zathura_t* zathura, const char* path, bool overwrite); 357 358 /** 359 * Closes the current opened document 360 * 361 * @param zathura The zathura session 362 * @param keep_monitor Set to true if monitor should be kept (sc_reload) 363 * @return If no error occurred true, otherwise false, is returned. 364 */ 365 bool document_close(zathura_t* zathura, bool keep_monitor); 366 367 /** 368 * Opens the page with the given number 369 * 370 * @param zathura The zathura session 371 * @param page_id The id of the page that should be set 372 * @return If no error occurred true, otherwise false, is returned. 373 */ 374 bool page_set(zathura_t* zathura, unsigned int page_id); 375 376 /** 377 * Moves to the given position 378 * 379 * @param zathura Zathura session 380 * @param position_x X coordinate 381 * @param position_y Y coordinate 382 * @return If no error occurred true, otherwise false, is returned. 383 */ 384 bool position_set(zathura_t* zathura, double position_x, double position_y); 385 386 /** 387 * Refresh the page view 388 * 389 * @param zathura Zathura session 390 */ 391 void refresh_view(zathura_t* zathura); 392 393 /** 394 * Recompute the scale according to settings 395 * 396 * @param zathura Zathura session 397 */ 398 bool adjust_view(zathura_t* zathura); 399 400 /** 401 * Builds the box structure to show the rendered pages 402 * 403 * @param zathura The zathura session 404 * @param page_padding padding in pixels between pages 405 * @param pages_per_row Number of shown pages per row 406 * @param first_page_column Column on which first page start 407 * @param page_right_to_left Render pages right to left 408 */ 409 void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, 410 unsigned int pages_per_row, unsigned int first_page_column, 411 bool page_right_to_left); 412 413 /** 414 * Updates the page number in the statusbar. Note that 1 will be added to the 415 * displayed number 416 * 417 * @param zathura The zathura session 418 */ 419 void statusbar_page_number_update(zathura_t* zathura); 420 421 /** 422 * Gets the nicely formatted filename of the loaded document according to settings 423 * 424 * @param zathura The zathura session 425 * @param statusbar Whether return value will be dispalyed in status bar 426 * 427 * return Printable filename. Free with g_free. 428 */ 429 char* get_formatted_filename(zathura_t* zathura, bool statusbar); 430 431 #endif // ZATHURA_H 432