forked from phillipberndt/pqiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pqiv.h
309 lines (256 loc) · 10.2 KB
/
pqiv.h
1
2
3
4
5
6
7
8
9
10
11
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/**
* pqiv
*
* Copyright (c) 2013-2017, Phillip Berndt
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// This file contains the definition of files, image types and
// the plugin infrastructure. It should be included in file type
// handlers.
#ifndef _PQIV_H_INCLUDED
#define _PQIV_H_INCLUDED
#include <glib.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include "lib/bostree.h"
#ifndef PQIV_VERSION
#define PQIV_VERSION "2.13.1"
#endif
#define FILE_FLAGS_ANIMATION (guint)(1)
#define FILE_FLAGS_MEMORY_IMAGE (guint)(1<<1)
#define FALSE_POINTER ((void*)-1)
// The structure for images {{{
typedef struct _file file_t;
typedef GBytes *(*file_data_loader_fn_t)(file_t *file, GError **error_pointer);
typedef struct file_type_handler_struct_t file_type_handler_t;
struct _file {
// File type
const file_type_handler_t *file_type;
// Special flags
// FILE_FLAGS_ANIMATION -> Animation functions are invoked
// Set by file type handlers
// FILE_FLAGS_MEMORY_IMAGE -> File lives in memory
guint file_flags;
// The file name to display
// Must be different from file_name, because it is free()d seperately
gchar *display_name;
// The name to sort by
// Must be set if option_sort is set; in backends the simplest approach
// is to only touch this if it is not NULL
gchar *sort_name;
// The URI or file name of the file
gchar *file_name;
// If the file is a memory image, the actual image data _or_ data for the
// file_data_loader callback to use to construct the _actual_ bytes object
// to use.
GBytes *file_data;
// If the image is a memory image that can be generated at load time,
// store a pointer to the generator.
file_data_loader_fn_t file_data_loader;
// The file monitor structure is used for inotify-watching of
// the files
GFileMonitor *file_monitor;
// This flag stores whether this image is currently loaded
// and valid. i.e. if it is set, you can assume that
// private_data contains a representation of the image;
// if not, you can NOT assume that it does not.
gboolean is_loaded;
// This flag determines whether this file should be reloaded
// despite is_loaded being set
gboolean force_reload;
// Cached image size
guint width;
guint height;
#ifndef CONFIGURED_WITHOUT_MONTAGE_MODE
// Cached thumbnail
cairo_surface_t *thumbnail;
#endif
// Lock to prevent multiple threads from accessing the backend at the same
// time
GMutex lock;
// Default render, automatically unloaded with the image, not guaranteed to
// be present, not guaranteed to have the correct scale level.
cairo_surface_t *prerendered_view;
// File-type specific data, allocated and freed by the file type handlers
void *private;
// TRUE if file is marked
#ifndef CONFIGURED_WITHOUT_EXTERNAL_COMMANDS
gboolean marked;
#endif
};
// }}}
// Definition of the built-in file types {{{
// If you want to implement your own file type, you'll have to implement the
// following functions and a non-static initialization function named
// file_type_NAME_initializer that fills a file_type_handler_t with pointers to
// the functions. Store the file in backends/NAME.c and adjust the Makefile to
// add the required libraries if your backend is listed in the $(BACKENDS)
// variable.
typedef enum { PARAMETER, RECURSION, INOTIFY, BROWSE_ORIGINAL_PARAMETER, FILTER_OUTPUT } load_images_state_t;
// Allocation function: Allocate the ->private structure within a file and add the
// image(s) to the list of available images via load_images_handle_parameter_add_file()
// If an image is not to be loaded for any reason, the file structure should be
// deallocated using file_free()
// Returns a pointer to the first added image
// Optional, you can also set the pointer to this function to NULL.
// If new file_t structures are needed, use image_loader_duplicate_file
typedef BOSNode *(*file_type_alloc_fn_t)(load_images_state_t state, file_t *file);
// Deallocation, if a file is removed from the images list. Free the ->private structure.
// Only called if ->private is non-NULL.
typedef void (*file_type_free_fn_t)(file_t *file);
// Actually load a file into memory
typedef void (*file_type_load_fn_t)(file_t *file, GInputStream *data, GError **error_pointer);
// Unload a file
typedef void (*file_type_unload_fn_t)(file_t *file);
// Animation support: Initialize memory for animations, return ms until first frame
// Optional, you can also set the pointer to this function to NULL.
typedef double (*file_type_animation_initialize_fn_t)(file_t *file);
// Animation support: Advance to the next frame, return ms until next frame
// Optional, you can also set the pointer to this function to NULL.
typedef double (*file_type_animation_next_frame_fn_t)(file_t *file);
// Draw the current view to a cairo context
typedef void (*file_type_draw_fn_t)(file_t *file, cairo_t *cr);
struct file_type_handler_struct_t {
// All files will be filtered with this filter. If it lets it pass,
// a handler is assigned to a file. If none do, the file is
// discarded if it was found during directory traversal or
// loaded using the first image backend if it was an explicit
// parameter.
GtkFileFilter *file_types_handled;
// Pointers to the functions defined above
file_type_alloc_fn_t alloc_fn;
file_type_free_fn_t free_fn;
file_type_load_fn_t load_fn;
file_type_unload_fn_t unload_fn;
file_type_animation_initialize_fn_t animation_initialize_fn;
file_type_animation_next_frame_fn_t animation_next_frame_fn;
file_type_draw_fn_t draw_fn;
};
// Initialization function: Tell pqiv about a backend
typedef void (*file_type_initializer_fn_t)(file_type_handler_t *info);
// pqiv symbols available to plugins {{{
// Global cancellable that should be used for every i/o operation
extern GCancellable *image_loader_cancellable;
// Current scale level. For backends that don't support cairo natively.
extern gdouble current_scale_level;
// Load a file from disc/memory/network
GInputStream *image_loader_stream_file(file_t *file, GError **error_pointer);
// Create a GFile for a file's name (We have a wrapper to support names with colons)
GFile *gfile_for_commandline_arg(const char *parameter);
// Duplicate a file_t; the private section does not get duplicated, only the pointer gets copied
file_t *image_loader_duplicate_file(file_t *file, gchar *custom_file_name, gchar *custom_display_name, gchar *custom_sort_name);
// Add a file to the list of loaded files
// Should be called at least once in a file_type_alloc_fn_t, with the state being
// forwarded unaltered.
BOSNode *load_images_handle_parameter_add_file(load_images_state_t state, file_t *file);
// Find a handler for a given file; useful for handler redirection, see archive
// file type
BOSNode *load_images_handle_parameter_find_handler(const char *param, load_images_state_t state, file_t *file, GtkFileFilterInfo *file_filter_info);
// Load all data from an input stream into memory, conveinience function
GBytes *g_input_stream_read_completely(GInputStream *input_stream, GCancellable *cancellable, GError **error_pointer);
// Free a file
void file_free(file_t *file);
// Set the interpolation filter in a cairo context for the current file based on the user settings
void apply_interpolation_quality(cairo_t *cr);
// Wrapper for string vector contains function
gboolean strv_contains(const gchar * const *strv, const gchar *str);
// }}}
// File type handlers, used in the initializer and file type guessing
extern file_type_handler_t file_type_handlers[];
/* }}} */
// The means to control pqiv remotely {{{
typedef enum {
ACTION_NOP,
ACTION_SHIFT_Y,
ACTION_SHIFT_X,
ACTION_SET_SLIDESHOW_INTERVAL_RELATIVE,
ACTION_SET_SLIDESHOW_INTERVAL_ABSOLUTE,
ACTION_SET_SCALE_LEVEL_RELATIVE,
ACTION_SET_SCALE_LEVEL_ABSOLUTE,
ACTION_TOGGLE_SCALE_MODE,
ACTION_SET_SCALE_MODE_SCREEN_FRACTION,
ACTION_TOGGLE_SHUFFLE_MODE,
ACTION_RELOAD,
ACTION_RESET_SCALE_LEVEL,
ACTION_TOGGLE_FULLSCREEN,
ACTION_FLIP_HORIZONTALLY,
ACTION_FLIP_VERTICALLY,
ACTION_ROTATE_LEFT,
ACTION_ROTATE_RIGHT,
ACTION_TOGGLE_INFO_BOX,
ACTION_JUMP_DIALOG,
ACTION_TOGGLE_SLIDESHOW,
ACTION_HARDLINK_CURRENT_IMAGE,
ACTION_GOTO_DIRECTORY_RELATIVE,
ACTION_GOTO_LOGICAL_DIRECTORY_RELATIVE,
ACTION_GOTO_FILE_RELATIVE,
ACTION_QUIT,
ACTION_NUMERIC_COMMAND,
ACTION_COMMAND,
ACTION_ADD_FILE,
ACTION_GOTO_FILE_BYINDEX,
ACTION_GOTO_FILE_BYNAME,
ACTION_REMOVE_FILE_BYINDEX,
ACTION_REMOVE_FILE_BYNAME,
ACTION_OUTPUT_FILE_LIST,
ACTION_SET_CURSOR_VISIBILITY,
ACTION_SET_STATUS_OUTPUT,
ACTION_SET_SCALE_MODE_FIT_PX,
ACTION_SET_SHIFT_X,
ACTION_SET_SHIFT_Y,
ACTION_BIND_KEY,
ACTION_SEND_KEYS,
ACTION_SET_SHIFT_ALIGN_CORNER,
ACTION_SET_INTERPOLATION_QUALITY,
ACTION_ANIMATION_STEP,
ACTION_ANIMATION_CONTINUE,
ACTION_ANIMATION_SET_SPEED_ABSOLUTE,
ACTION_ANIMATION_SET_SPEED_RELATIVE,
ACTION_GOTO_EARLIER_FILE,
ACTION_SET_CURSOR_AUTO_HIDE,
ACTION_SET_FADE_DURATION,
ACTION_SET_KEYBOARD_TIMEOUT,
ACTION_SET_THUMBNAIL_SIZE,
ACTION_SET_THUMBNAIL_PRELOAD,
ACTION_MONTAGE_MODE_ENTER,
ACTION_MONTAGE_MODE_SHIFT_X,
ACTION_MONTAGE_MODE_SHIFT_Y,
ACTION_MONTAGE_MODE_SET_SHIFT_X,
ACTION_MONTAGE_MODE_SET_SHIFT_Y,
ACTION_MONTAGE_MODE_SET_WRAP_MODE,
ACTION_MONTAGE_MODE_SHIFT_Y_PG,
ACTION_MONTAGE_MODE_SHIFT_Y_ROWS,
ACTION_MONTAGE_MODE_SHOW_BINDING_OVERLAYS,
ACTION_MONTAGE_MODE_FOLLOW,
ACTION_MONTAGE_MODE_FOLLOW_PROCEED,
ACTION_MONTAGE_MODE_RETURN_PROCEED,
ACTION_MONTAGE_MODE_RETURN_CANCEL,
ACTION_MOVE_WINDOW,
ACTION_TOGGLE_BACKGROUND_PATTERN,
ACTION_TOGGLE_NEGATE_MODE,
ACTION_TOGGLE_MARK,
ACTION_CLEAR_MARKS,
} pqiv_action_t;
typedef union {
int pint;
double pdouble;
char *pcharptr;
struct {
short p1;
short p2;
} p2short;
} pqiv_action_parameter_t;
void action(pqiv_action_t action, pqiv_action_parameter_t parameter);
// }}}
#endif