2009-12-26 14:30:50 +01:00
|
|
|
/* See LICENSE file for license and copyright information */
|
|
|
|
|
2009-12-26 17:57:46 +01:00
|
|
|
#define _BSD_SOURCE || _XOPEN_SOURCE >= 500
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
#include <regex.h>
|
2009-12-26 17:18:45 +01:00
|
|
|
#include <limits.h>
|
2009-08-11 23:18:50 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-12-26 17:18:45 +01:00
|
|
|
#include <unistd.h>
|
2009-12-28 00:44:35 +01:00
|
|
|
#include <libgen.h>
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 16:08:33 +01:00
|
|
|
#include <poppler/glib/poppler.h>
|
|
|
|
#include <cairo.h>
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
/* macros */
|
|
|
|
#define LENGTH(x) sizeof(x)/sizeof((x)[0])
|
2010-06-19 16:10:41 +02:00
|
|
|
#define CLEAN(m) (m & ~(GDK_MOD2_MASK) & ~(GDK_BUTTON1_MASK) & ~(GDK_BUTTON2_MASK) & ~(GDK_BUTTON3_MASK) & ~(GDK_BUTTON4_MASK) & ~(GDK_BUTTON5_MASK))
|
2009-08-11 23:18:50 +02:00
|
|
|
|
|
|
|
/* enums */
|
2010-06-19 10:33:36 +02:00
|
|
|
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
|
|
|
|
DELETE_LAST_WORD, DEFAULT, ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP,
|
|
|
|
ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD, BACKWARD,
|
|
|
|
ADJUST_BESTFIT, ADJUST_WIDTH, ADJUST_NONE, CONTINUOUS, DELETE_LAST,
|
|
|
|
ADD_MARKER, EVAL_MARKER, EXPAND, COLLAPSE, SELECT, GOTO_DEFAULT, GOTO_LABELS,
|
|
|
|
GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, FULL_DOWN };
|
|
|
|
|
|
|
|
/* define modes */
|
|
|
|
#define ALL (1 << 0)
|
|
|
|
#define FULLSCREEN (1 << 1)
|
|
|
|
#define INDEX (1 << 2)
|
|
|
|
#define INSERT (1 << 3)
|
|
|
|
#define NORMAL (1 << 4)
|
|
|
|
#define VISUAL (1 << 5)
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* typedefs */
|
|
|
|
struct CElement
|
|
|
|
{
|
|
|
|
char *value;
|
|
|
|
char *description;
|
|
|
|
struct CElement *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CElement CompletionElement;
|
|
|
|
|
|
|
|
struct CGroup
|
|
|
|
{
|
|
|
|
char *value;
|
|
|
|
CompletionElement *elements;
|
|
|
|
struct CGroup *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CGroup CompletionGroup;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CompletionGroup* groups;
|
|
|
|
} Completion;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* command;
|
|
|
|
char* description;
|
|
|
|
int command_id;
|
|
|
|
gboolean is_group;
|
|
|
|
GtkWidget* row;
|
|
|
|
} CompletionRow;
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
void *data;
|
|
|
|
} Argument;
|
|
|
|
|
2010-06-17 00:12:21 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
int argument;
|
|
|
|
} ArgumentName;
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int mask;
|
|
|
|
int key;
|
|
|
|
void (*function)(Argument*);
|
2009-12-26 14:30:50 +01:00
|
|
|
int mode;
|
2009-08-11 23:18:50 +02:00
|
|
|
Argument argument;
|
|
|
|
} Shortcut;
|
|
|
|
|
2010-06-17 00:12:21 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
int mode;
|
|
|
|
} ModeName;
|
|
|
|
|
2010-06-16 22:42:45 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
void (*function)(Argument*);
|
|
|
|
} ShortcutName;
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
int mask;
|
|
|
|
int key;
|
|
|
|
void (*function)(Argument*);
|
|
|
|
Argument argument;
|
|
|
|
} InputbarShortcut;
|
|
|
|
|
2010-04-12 19:38:07 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int direction;
|
|
|
|
void (*function)(Argument*);
|
|
|
|
Argument argument;
|
|
|
|
} MouseScrollEvent;
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* command;
|
|
|
|
char* abbr;
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean (*function)(int, char**);
|
2009-12-26 14:30:50 +01:00
|
|
|
Completion* (*completion)(char*);
|
|
|
|
char* description;
|
2009-08-11 23:18:50 +02:00
|
|
|
} Command;
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* regex;
|
|
|
|
void (*function)(char*, Argument*);
|
|
|
|
Argument argument;
|
|
|
|
} BufferCommand;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char identifier;
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean (*function)(char*, Argument*);
|
2009-12-26 14:30:50 +01:00
|
|
|
int always;
|
|
|
|
Argument argument;
|
|
|
|
} SpecialCommand;
|
|
|
|
|
2010-06-16 22:42:45 +02:00
|
|
|
struct SCList
|
|
|
|
{
|
|
|
|
Shortcut element;
|
|
|
|
struct SCList *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct SCList ShortcutList;
|
|
|
|
|
2010-06-18 12:58:20 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* identifier;
|
|
|
|
int key;
|
|
|
|
} GDKKey;
|
|
|
|
|
2009-12-26 16:08:33 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-05-05 12:36:04 +02:00
|
|
|
PopplerPage *page;
|
|
|
|
int id;
|
|
|
|
char *label;
|
2009-12-26 16:08:33 +01:00
|
|
|
} Page;
|
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
void* variable;
|
|
|
|
char type;
|
|
|
|
gboolean render;
|
2010-06-14 21:06:26 +02:00
|
|
|
gboolean reinit;
|
2010-01-01 19:52:20 +01:00
|
|
|
char* description;
|
|
|
|
} Setting;
|
|
|
|
|
2010-01-30 23:48:36 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
int page;
|
|
|
|
} Marker;
|
|
|
|
|
2010-01-31 21:07:27 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* id;
|
|
|
|
int page;
|
|
|
|
} Bookmark;
|
|
|
|
|
2009-12-26 16:08:33 +01:00
|
|
|
/* zathura */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2010-06-16 20:24:31 +02:00
|
|
|
GtkWidget *window;
|
2009-12-26 16:08:33 +01:00
|
|
|
GtkBox *box;
|
2010-01-01 13:54:21 +01:00
|
|
|
GtkBox *continuous;
|
2009-12-26 16:08:33 +01:00
|
|
|
GtkScrolledWindow *view;
|
2009-12-29 22:33:40 +01:00
|
|
|
GtkViewport *viewport;
|
2009-12-26 16:08:33 +01:00
|
|
|
GtkWidget *statusbar;
|
|
|
|
GtkBox *statusbar_entries;
|
|
|
|
GtkEntry *inputbar;
|
2010-01-01 22:52:45 +01:00
|
|
|
GtkWidget *index;
|
2010-01-02 02:04:43 +01:00
|
|
|
GtkWidget *information;
|
2010-01-20 23:46:13 +01:00
|
|
|
GtkWidget *drawing_area;
|
2010-04-12 23:55:14 +02:00
|
|
|
GtkWidget *document;
|
2010-06-16 20:24:31 +02:00
|
|
|
GdkNativeWindow embed;
|
2009-12-26 16:08:33 +01:00
|
|
|
} UI;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
GdkColor default_fg;
|
|
|
|
GdkColor default_bg;
|
|
|
|
GdkColor inputbar_fg;
|
|
|
|
GdkColor inputbar_bg;
|
|
|
|
GdkColor statusbar_fg;
|
|
|
|
GdkColor statusbar_bg;
|
|
|
|
GdkColor completion_fg;
|
|
|
|
GdkColor completion_bg;
|
|
|
|
GdkColor completion_g_bg;
|
|
|
|
GdkColor completion_g_fg;
|
|
|
|
GdkColor completion_hl_fg;
|
|
|
|
GdkColor completion_hl_bg;
|
|
|
|
GdkColor notification_e_fg;
|
|
|
|
GdkColor notification_e_bg;
|
|
|
|
GdkColor notification_w_fg;
|
|
|
|
GdkColor notification_w_bg;
|
2010-04-11 10:47:09 +02:00
|
|
|
GdkColor recolor_darkcolor;
|
|
|
|
GdkColor recolor_lightcolor;
|
2010-01-02 14:23:49 +01:00
|
|
|
GdkColor search_highlight;
|
2010-04-13 00:22:56 +02:00
|
|
|
GdkColor select_text;
|
2009-12-26 16:08:33 +01:00
|
|
|
PangoFontDescription *font;
|
|
|
|
} Style;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
GtkLabel *status_text;
|
|
|
|
GtkLabel *status_buffer;
|
|
|
|
GtkLabel *status_state;
|
2010-06-03 17:11:33 +02:00
|
|
|
GString *buffer;
|
|
|
|
GList *history;
|
|
|
|
int mode;
|
|
|
|
int viewing_mode;
|
|
|
|
gboolean recolor;
|
|
|
|
gboolean enable_labelmode;
|
|
|
|
int goto_mode;
|
2010-04-12 09:31:56 +02:00
|
|
|
int adjust_mode;
|
2010-06-03 17:11:33 +02:00
|
|
|
gboolean show_index;
|
2009-12-26 16:08:33 +01:00
|
|
|
} Global;
|
|
|
|
|
2010-06-16 22:42:45 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
ShortcutList *sclist;
|
|
|
|
} Bindings;
|
|
|
|
|
2010-04-13 00:22:56 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
gdouble x;
|
|
|
|
gdouble y;
|
|
|
|
} SelectPoint;
|
|
|
|
|
2009-12-26 17:44:13 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
char* filename;
|
|
|
|
char* pages;
|
2010-01-29 13:18:25 +01:00
|
|
|
int scroll_percentage;
|
2009-12-26 17:44:13 +01:00
|
|
|
} State;
|
|
|
|
|
2010-01-30 23:48:36 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
Marker* markers;
|
|
|
|
int number_of_markers;
|
|
|
|
int last;
|
|
|
|
} Marker;
|
|
|
|
|
2010-03-08 20:08:59 +01:00
|
|
|
struct
|
|
|
|
{
|
2010-06-03 18:05:34 +02:00
|
|
|
GFileMonitor* monitor;
|
|
|
|
} FileMonitor;
|
2010-03-08 20:08:59 +01:00
|
|
|
|
2010-01-31 11:44:33 +01:00
|
|
|
struct
|
|
|
|
{
|
2010-01-31 12:35:49 +01:00
|
|
|
GKeyFile *data;
|
|
|
|
char *file;
|
2010-01-31 21:07:27 +01:00
|
|
|
Bookmark *bookmarks;
|
|
|
|
int number_of_bookmarks;
|
2010-01-31 11:44:33 +01:00
|
|
|
} Bookmarks;
|
|
|
|
|
2009-12-26 16:08:33 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
PopplerDocument *document;
|
|
|
|
char *file;
|
2010-02-02 15:27:37 +01:00
|
|
|
char *password;
|
2009-12-28 19:50:30 +01:00
|
|
|
Page **pages;
|
2009-12-26 16:08:33 +01:00
|
|
|
int page_number;
|
2010-05-05 20:05:06 +02:00
|
|
|
int page_offset;
|
2009-12-26 16:08:33 +01:00
|
|
|
int number_of_pages;
|
2009-12-28 19:24:15 +01:00
|
|
|
int scale;
|
2009-12-28 18:34:00 +01:00
|
|
|
int rotate;
|
2010-01-20 23:46:13 +01:00
|
|
|
cairo_surface_t *surface;
|
2009-12-26 16:08:33 +01:00
|
|
|
} PDF;
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
GStaticMutex pdflib_lock;
|
2010-05-12 12:27:15 +02:00
|
|
|
GStaticMutex pdf_obj_lock;
|
2010-04-10 14:33:23 +02:00
|
|
|
GStaticMutex search_lock;
|
2010-04-13 00:22:56 +02:00
|
|
|
GStaticMutex select_lock;
|
2010-04-10 14:33:23 +02:00
|
|
|
} Lock;
|
|
|
|
|
2010-05-11 20:45:47 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
GList* results;
|
|
|
|
int page;
|
2010-05-13 11:39:20 +02:00
|
|
|
gboolean draw;
|
2010-05-11 20:45:47 +02:00
|
|
|
} Search;
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
GThread* search_thread;
|
|
|
|
gboolean search_thread_running;
|
|
|
|
GThread* inotify_thread;
|
|
|
|
} Thread;
|
|
|
|
|
2010-04-11 12:31:18 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
guint inputbar_activate;
|
|
|
|
guint inputbar_key_press_event;
|
|
|
|
} Handler;
|
|
|
|
|
2009-12-26 16:08:33 +01:00
|
|
|
} Zathura;
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
/* function declarations */
|
2010-06-15 12:50:43 +02:00
|
|
|
void init_look();
|
2010-01-31 02:03:28 +01:00
|
|
|
void init_directories();
|
2010-06-16 22:42:45 +02:00
|
|
|
void init_keylist();
|
2010-06-15 12:50:43 +02:00
|
|
|
void init_settings();
|
2009-12-26 14:30:50 +01:00
|
|
|
void init_zathura();
|
2010-01-30 23:48:36 +01:00
|
|
|
void add_marker(int);
|
2010-01-01 22:52:45 +01:00
|
|
|
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
|
2009-12-26 14:30:50 +01:00
|
|
|
void change_mode(int);
|
2010-04-13 09:47:47 +02:00
|
|
|
void calculate_offset(GtkWidget*, double*, double*);
|
2010-06-15 10:17:38 +02:00
|
|
|
void close_file(gboolean);
|
2010-05-24 21:26:40 +02:00
|
|
|
void enter_password();
|
2010-01-02 14:23:49 +01:00
|
|
|
void highlight_result(int, PopplerRectangle*);
|
2009-12-28 19:50:30 +01:00
|
|
|
void draw(int);
|
2010-01-30 23:48:36 +01:00
|
|
|
void eval_marker(int);
|
2009-12-26 14:30:50 +01:00
|
|
|
void notify(int, char*);
|
2010-02-02 15:27:37 +01:00
|
|
|
gboolean open_file(char*, char*);
|
2010-04-11 14:18:49 +02:00
|
|
|
void open_uri(char*);
|
2010-06-16 22:42:45 +02:00
|
|
|
void out_of_memory();
|
2009-12-26 17:44:13 +01:00
|
|
|
void update_status();
|
2010-06-14 21:52:19 +02:00
|
|
|
void read_configuration();
|
2010-01-02 14:23:49 +01:00
|
|
|
void recalcRectangle(int, PopplerRectangle*);
|
2009-12-26 14:30:50 +01:00
|
|
|
void setCompletionRowColor(GtkBox*, int, int);
|
2009-12-26 17:44:13 +01:00
|
|
|
void set_page(int);
|
2009-12-28 21:42:55 +01:00
|
|
|
void switch_view(GtkWidget*);
|
2009-12-26 14:30:50 +01:00
|
|
|
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-28 19:50:30 +01:00
|
|
|
/* thread declaration */
|
2010-01-02 16:31:25 +01:00
|
|
|
void* search(void*);
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
/* shortcut declarations */
|
2009-12-26 14:30:50 +01:00
|
|
|
void sc_abort(Argument*);
|
2009-12-26 15:55:32 +01:00
|
|
|
void sc_adjust_window(Argument*);
|
2010-01-29 13:42:24 +01:00
|
|
|
void sc_change_buffer(Argument*);
|
2009-12-26 14:30:50 +01:00
|
|
|
void sc_change_mode(Argument*);
|
2009-08-11 23:18:50 +02:00
|
|
|
void sc_focus_inputbar(Argument*);
|
2010-04-11 12:00:27 +02:00
|
|
|
void sc_follow(Argument*);
|
2009-12-26 15:55:32 +01:00
|
|
|
void sc_navigate(Argument*);
|
2010-04-11 10:47:09 +02:00
|
|
|
void sc_recolor(Argument*);
|
2010-06-03 18:12:45 +02:00
|
|
|
void sc_reload(Argument*);
|
2009-12-26 15:55:32 +01:00
|
|
|
void sc_rotate(Argument*);
|
|
|
|
void sc_scroll(Argument*);
|
|
|
|
void sc_search(Argument*);
|
2010-05-05 20:05:06 +02:00
|
|
|
void sc_switch_goto_mode(Argument*);
|
2010-04-27 16:07:49 +02:00
|
|
|
void sc_navigate_index(Argument*);
|
2010-01-01 22:52:45 +01:00
|
|
|
void sc_toggle_index(Argument*);
|
2009-12-26 15:55:32 +01:00
|
|
|
void sc_toggle_inputbar(Argument*);
|
2010-05-24 09:38:54 +02:00
|
|
|
void sc_toggle_fullscreen(Argument*);
|
2009-12-26 15:55:32 +01:00
|
|
|
void sc_toggle_statusbar(Argument*);
|
2009-08-11 23:18:50 +02:00
|
|
|
void sc_quit(Argument*);
|
2010-06-18 11:03:11 +02:00
|
|
|
void sc_zoom(Argument*);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* inputbar shortcut declarations */
|
|
|
|
void isc_abort(Argument*);
|
|
|
|
void isc_command_history(Argument*);
|
|
|
|
void isc_completion(Argument*);
|
|
|
|
void isc_string_manipulation(Argument*);
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
/* command declarations */
|
2010-01-31 21:07:27 +01:00
|
|
|
gboolean cmd_bookmark(int, char**);
|
|
|
|
gboolean cmd_open_bookmark(int, char**);
|
2010-01-01 20:46:07 +01:00
|
|
|
gboolean cmd_close(int, char**);
|
2010-05-05 20:05:06 +02:00
|
|
|
gboolean cmd_correct_offset(int, char**);
|
2010-01-31 21:24:33 +01:00
|
|
|
gboolean cmd_delete_bookmark(int, char**);
|
2010-01-03 16:25:51 +01:00
|
|
|
gboolean cmd_export(int, char**);
|
2010-01-02 02:04:43 +01:00
|
|
|
gboolean cmd_info(int, char**);
|
2010-06-16 21:50:28 +02:00
|
|
|
gboolean cmd_map(int, char**);
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean cmd_open(int, char**);
|
|
|
|
gboolean cmd_print(int, char**);
|
|
|
|
gboolean cmd_rotate(int, char**);
|
2010-01-01 19:52:20 +01:00
|
|
|
gboolean cmd_set(int, char**);
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean cmd_quit(int, char**);
|
|
|
|
gboolean cmd_save(int, char**);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* completion commands */
|
2010-01-31 21:07:27 +01:00
|
|
|
Completion* cc_bookmark(char*);
|
2010-01-03 16:25:51 +01:00
|
|
|
Completion* cc_export(char*);
|
2009-12-26 14:30:50 +01:00
|
|
|
Completion* cc_open(char*);
|
2010-01-02 00:25:18 +01:00
|
|
|
Completion* cc_print(char*);
|
2010-01-01 19:52:20 +01:00
|
|
|
Completion* cc_set(char*);
|
2009-12-26 14:30:50 +01:00
|
|
|
|
|
|
|
/* buffer command declarations */
|
2010-01-30 23:48:36 +01:00
|
|
|
void bcmd_evalmarker(char*, Argument*);
|
2009-12-26 14:30:50 +01:00
|
|
|
void bcmd_goto(char*, Argument*);
|
2010-01-29 13:18:25 +01:00
|
|
|
void bcmd_scroll(char*, Argument*);
|
2010-01-30 23:48:36 +01:00
|
|
|
void bcmd_setmarker(char*, Argument*);
|
2009-12-26 15:55:32 +01:00
|
|
|
void bcmd_zoom(char*, Argument*);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* special command delcarations */
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean scmd_search(char*, Argument*);
|
2009-12-26 14:30:50 +01:00
|
|
|
|
|
|
|
/* callback declarations */
|
|
|
|
gboolean cb_destroy(GtkWidget*, gpointer);
|
2009-12-30 00:44:14 +01:00
|
|
|
gboolean cb_draw(GtkWidget*, GdkEventExpose*, gpointer);
|
2010-04-27 16:07:49 +02:00
|
|
|
gboolean cb_index_row_activated(GtkTreeView*, GtkTreePath*, GtkTreeViewColumn*, gpointer);
|
2009-12-26 14:30:50 +01:00
|
|
|
gboolean cb_inputbar_kb_pressed(GtkWidget*, GdkEventKey*, gpointer);
|
|
|
|
gboolean cb_inputbar_activate(GtkEntry*, gpointer);
|
2010-04-11 12:31:18 +02:00
|
|
|
gboolean cb_inputbar_form_activate(GtkEntry*, gpointer);
|
2010-05-24 21:26:40 +02:00
|
|
|
gboolean cb_inputbar_password_activate(GtkEntry*, gpointer);
|
2010-04-12 09:31:56 +02:00
|
|
|
gboolean cb_view_kb_pressed(GtkWidget*, GdkEventKey*, gpointer);
|
|
|
|
gboolean cb_view_resized(GtkWidget*, GtkAllocation*, gpointer);
|
2010-04-12 19:22:47 +02:00
|
|
|
gboolean cb_view_button_pressed(GtkWidget*, GdkEventButton*, gpointer);
|
2010-04-12 23:55:14 +02:00
|
|
|
gboolean cb_view_button_release(GtkWidget*, GdkEventButton*, gpointer);
|
|
|
|
gboolean cb_view_motion_notify(GtkWidget*, GdkEventMotion*, gpointer);
|
2010-04-12 19:22:47 +02:00
|
|
|
gboolean cb_view_scrolled(GtkWidget*, GdkEventScroll*, gpointer);
|
2010-06-03 18:05:34 +02:00
|
|
|
gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointer);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
#include "config.h"
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* function implementation */
|
2010-06-14 21:06:26 +02:00
|
|
|
void
|
2010-06-15 12:50:43 +02:00
|
|
|
init_look()
|
2010-06-14 21:06:26 +02:00
|
|
|
{
|
|
|
|
/* parse */
|
|
|
|
gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg));
|
|
|
|
gdk_color_parse(default_bgcolor, &(Zathura.Style.default_bg));
|
|
|
|
gdk_color_parse(inputbar_fgcolor, &(Zathura.Style.inputbar_fg));
|
|
|
|
gdk_color_parse(inputbar_bgcolor, &(Zathura.Style.inputbar_bg));
|
|
|
|
gdk_color_parse(statusbar_fgcolor, &(Zathura.Style.statusbar_fg));
|
|
|
|
gdk_color_parse(statusbar_bgcolor, &(Zathura.Style.statusbar_bg));
|
|
|
|
gdk_color_parse(completion_fgcolor, &(Zathura.Style.completion_fg));
|
|
|
|
gdk_color_parse(completion_bgcolor, &(Zathura.Style.completion_bg));
|
|
|
|
gdk_color_parse(completion_g_fgcolor, &(Zathura.Style.completion_g_fg));
|
|
|
|
gdk_color_parse(completion_g_fgcolor, &(Zathura.Style.completion_g_fg));
|
|
|
|
gdk_color_parse(completion_hl_fgcolor, &(Zathura.Style.completion_hl_fg));
|
|
|
|
gdk_color_parse(completion_hl_bgcolor, &(Zathura.Style.completion_hl_bg));
|
|
|
|
gdk_color_parse(notification_e_fgcolor, &(Zathura.Style.notification_e_fg));
|
|
|
|
gdk_color_parse(notification_e_bgcolor, &(Zathura.Style.notification_e_bg));
|
|
|
|
gdk_color_parse(notification_w_fgcolor, &(Zathura.Style.notification_w_fg));
|
|
|
|
gdk_color_parse(notification_w_bgcolor, &(Zathura.Style.notification_w_bg));
|
|
|
|
gdk_color_parse(recolor_darkcolor, &(Zathura.Style.recolor_darkcolor));
|
|
|
|
gdk_color_parse(recolor_lightcolor, &(Zathura.Style.recolor_lightcolor));
|
|
|
|
gdk_color_parse(search_highlight, &(Zathura.Style.search_highlight));
|
|
|
|
gdk_color_parse(select_text, &(Zathura.Style.select_text));
|
|
|
|
Zathura.Style.font = pango_font_description_from_string(font);
|
|
|
|
|
|
|
|
/* drawing area */
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(Zathura.UI.drawing_area), GTK_STATE_NORMAL, &(Zathura.Style.default_bg));
|
|
|
|
|
|
|
|
/* statusbar */
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(Zathura.UI.statusbar), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_bg));
|
|
|
|
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(Zathura.Global.status_text), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_fg));
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(Zathura.Global.status_state), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_fg));
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(Zathura.Global.status_buffer), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_fg));
|
|
|
|
|
|
|
|
gtk_widget_modify_font(GTK_WIDGET(Zathura.Global.status_text), Zathura.Style.font);
|
|
|
|
gtk_widget_modify_font(GTK_WIDGET(Zathura.Global.status_state), Zathura.Style.font);
|
|
|
|
gtk_widget_modify_font(GTK_WIDGET(Zathura.Global.status_buffer), Zathura.Style.font);
|
|
|
|
|
|
|
|
/* inputbar */
|
|
|
|
gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_bg));
|
|
|
|
gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_fg));
|
|
|
|
gtk_widget_modify_font(GTK_WIDGET(Zathura.UI.inputbar), Zathura.Style.font);
|
|
|
|
|
2010-06-15 12:50:43 +02:00
|
|
|
/* scrollbars */
|
|
|
|
if(show_scrollbars)
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
else
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
2010-06-14 21:06:26 +02:00
|
|
|
}
|
|
|
|
|
2010-01-31 02:03:28 +01:00
|
|
|
void
|
|
|
|
init_directories()
|
|
|
|
{
|
2010-01-31 11:44:33 +01:00
|
|
|
/* create zathura directory */
|
2010-01-31 02:03:28 +01:00
|
|
|
gchar *base_directory = g_build_filename(g_get_home_dir(), ZATHURA_DIR, NULL);
|
|
|
|
g_mkdir_with_parents(base_directory, 0771);
|
|
|
|
g_free(base_directory);
|
2010-01-31 11:44:33 +01:00
|
|
|
|
|
|
|
/* create or open existing bookmark file */
|
2010-01-31 12:35:49 +01:00
|
|
|
Zathura.Bookmarks.data = g_key_file_new();
|
2010-01-31 11:44:33 +01:00
|
|
|
char* bookmarks = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, BOOKMARK_FILE);
|
|
|
|
|
|
|
|
if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
|
|
|
|
{
|
|
|
|
/* file does not exist */
|
2010-01-31 12:35:49 +01:00
|
|
|
g_file_set_contents(bookmarks, "# Zathura bookmarks\n", -1, NULL);
|
2010-01-31 11:44:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GError* error = NULL;
|
2010-05-18 00:19:09 +02:00
|
|
|
if(!g_key_file_load_from_file(Zathura.Bookmarks.data, bookmarks,
|
2010-01-31 12:35:49 +01:00
|
|
|
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error))
|
2010-01-31 11:44:33 +01:00
|
|
|
{
|
2010-05-25 20:16:12 +02:00
|
|
|
gchar* message = g_strdup_printf("Could not load bookmark file: %s", error->message);
|
|
|
|
notify(ERROR, message);
|
|
|
|
g_free(message);
|
2010-01-31 11:44:33 +01:00
|
|
|
}
|
|
|
|
|
2010-01-31 12:35:49 +01:00
|
|
|
Zathura.Bookmarks.file = g_strdup(bookmarks);
|
2010-01-31 11:44:33 +01:00
|
|
|
g_free(bookmarks);
|
2010-01-31 02:03:28 +01:00
|
|
|
}
|
|
|
|
|
2010-06-16 22:42:45 +02:00
|
|
|
void
|
|
|
|
init_keylist()
|
|
|
|
{
|
|
|
|
ShortcutList* e = NULL;
|
|
|
|
ShortcutList* p = NULL;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < LENGTH(shortcuts); i++)
|
|
|
|
{
|
|
|
|
e = malloc(sizeof(ShortcutList));
|
|
|
|
if(!e)
|
|
|
|
out_of_memory();
|
|
|
|
|
|
|
|
e->element = shortcuts[i];
|
|
|
|
e->next = NULL;
|
|
|
|
|
|
|
|
if(!Zathura.Bindings.sclist)
|
|
|
|
Zathura.Bindings.sclist = e;
|
|
|
|
if(p)
|
|
|
|
p->next = e;
|
|
|
|
|
|
|
|
p = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 12:50:43 +02:00
|
|
|
void
|
|
|
|
init_settings()
|
|
|
|
{
|
2010-06-18 11:03:11 +02:00
|
|
|
Zathura.State.filename = (char*) default_text;
|
|
|
|
Zathura.Global.adjust_mode = adjust_open;
|
2010-06-15 12:50:43 +02:00
|
|
|
|
2010-06-17 00:53:41 +02:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(Zathura.UI.window), default_width, default_height);
|
2010-06-15 12:50:43 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
init_zathura()
|
|
|
|
{
|
2010-04-10 14:33:23 +02:00
|
|
|
/* init mutexes */
|
|
|
|
g_static_mutex_init(&(Zathura.Lock.pdflib_lock));
|
|
|
|
g_static_mutex_init(&(Zathura.Lock.search_lock));
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_init(&(Zathura.Lock.pdf_obj_lock));
|
2010-04-13 00:22:56 +02:00
|
|
|
g_static_mutex_init(&(Zathura.Lock.select_lock));
|
2010-04-13 00:22:56 +02:00
|
|
|
g_static_mutex_init(&(Zathura.Lock.select_lock));
|
2010-01-01 14:18:09 +01:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* other */
|
2010-01-01 19:52:20 +01:00
|
|
|
Zathura.Global.mode = NORMAL;
|
|
|
|
Zathura.Global.viewing_mode = NORMAL;
|
2010-06-15 12:50:43 +02:00
|
|
|
Zathura.Global.recolor = 0;
|
2010-05-05 20:05:06 +02:00
|
|
|
Zathura.Global.goto_mode = GOTO_MODE;
|
2010-06-03 17:11:33 +02:00
|
|
|
Zathura.Global.show_index = FALSE;
|
2009-12-26 14:30:50 +01:00
|
|
|
|
2010-05-14 11:30:00 +02:00
|
|
|
Zathura.State.pages = g_strdup_printf("");
|
2010-01-29 13:18:25 +01:00
|
|
|
Zathura.State.scroll_percentage = 0;
|
2009-12-26 17:44:13 +01:00
|
|
|
|
2010-01-30 23:48:36 +01:00
|
|
|
Zathura.Marker.markers = NULL;
|
|
|
|
Zathura.Marker.number_of_markers = 0;
|
|
|
|
Zathura.Marker.last = -1;
|
|
|
|
|
2010-05-11 20:45:47 +02:00
|
|
|
Zathura.Search.results = NULL;
|
|
|
|
Zathura.Search.page = 0;
|
2010-05-18 22:24:15 +02:00
|
|
|
Zathura.Search.draw = FALSE;
|
2010-05-11 20:45:47 +02:00
|
|
|
|
2010-06-03 18:05:34 +02:00
|
|
|
Zathura.FileMonitor.monitor = NULL;
|
2010-03-08 20:08:59 +01:00
|
|
|
|
2010-06-16 20:24:31 +02:00
|
|
|
/* window */
|
|
|
|
if(Zathura.UI.embed)
|
|
|
|
Zathura.UI.window = gtk_plug_new(Zathura.UI.embed);
|
|
|
|
else
|
|
|
|
Zathura.UI.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* UI */
|
|
|
|
Zathura.UI.box = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
2010-01-01 13:54:21 +01:00
|
|
|
Zathura.UI.continuous = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
2009-12-26 14:30:50 +01:00
|
|
|
Zathura.UI.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
|
2009-12-29 22:33:40 +01:00
|
|
|
Zathura.UI.viewport = GTK_VIEWPORT(gtk_viewport_new(NULL, NULL));
|
2010-01-20 23:46:13 +01:00
|
|
|
Zathura.UI.drawing_area = gtk_drawing_area_new();
|
2009-12-26 14:30:50 +01:00
|
|
|
Zathura.UI.statusbar = gtk_event_box_new();
|
|
|
|
Zathura.UI.statusbar_entries = GTK_BOX(gtk_hbox_new(FALSE, 0));
|
|
|
|
Zathura.UI.inputbar = GTK_ENTRY(gtk_entry_new());
|
2010-04-12 23:55:14 +02:00
|
|
|
Zathura.UI.document = gtk_event_box_new();
|
2009-08-11 23:18:50 +02:00
|
|
|
|
|
|
|
/* window */
|
2010-06-16 20:24:31 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura");
|
2009-12-26 14:30:50 +01:00
|
|
|
GdkGeometry hints = { 1, 1 };
|
2010-06-16 20:24:31 +02:00
|
|
|
gtk_window_set_geometry_hints(GTK_WINDOW(Zathura.UI.window), NULL, &hints, GDK_HINT_MIN_SIZE);
|
2009-12-26 14:30:50 +01:00
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.window), "destroy", G_CALLBACK(cb_destroy), NULL);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* box */
|
|
|
|
gtk_box_set_spacing(Zathura.UI.box, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(Zathura.UI.window), GTK_WIDGET(Zathura.UI.box));
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2010-01-01 13:54:21 +01:00
|
|
|
/* continuous */
|
|
|
|
gtk_box_set_spacing(Zathura.UI.continuous, 5);
|
|
|
|
|
2010-04-12 23:55:14 +02:00
|
|
|
/* events */
|
|
|
|
gtk_container_add(GTK_CONTAINER(Zathura.UI.document), GTK_WIDGET(Zathura.UI.drawing_area));
|
|
|
|
gtk_widget_add_events(GTK_WIDGET(Zathura.UI.document), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.document), "button-press-event", G_CALLBACK(cb_view_button_pressed), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.document), "button-release-event", G_CALLBACK(cb_view_button_release), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.document), "motion-notify-event", G_CALLBACK(cb_view_motion_notify), NULL);
|
2010-05-24 17:25:12 +02:00
|
|
|
gtk_widget_show(Zathura.UI.document);
|
2010-04-12 23:55:14 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* view */
|
2010-04-12 23:55:14 +02:00
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.view), "key-press-event", G_CALLBACK(cb_view_kb_pressed), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.view), "size-allocate", G_CALLBACK(cb_view_resized), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.view), "scroll-event", G_CALLBACK(cb_view_scrolled), NULL);
|
2009-12-29 22:33:40 +01:00
|
|
|
gtk_container_add(GTK_CONTAINER(Zathura.UI.view), GTK_WIDGET(Zathura.UI.viewport));
|
2009-12-30 00:47:29 +01:00
|
|
|
gtk_viewport_set_shadow_type(Zathura.UI.viewport, GTK_SHADOW_NONE);
|
2010-05-18 00:19:09 +02:00
|
|
|
|
2010-01-20 23:46:13 +01:00
|
|
|
/* drawing area */
|
|
|
|
gtk_widget_show(Zathura.UI.drawing_area);
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL);
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* statusbar */
|
|
|
|
Zathura.Global.status_text = GTK_LABEL(gtk_label_new(NULL));
|
|
|
|
Zathura.Global.status_state = GTK_LABEL(gtk_label_new(NULL));
|
|
|
|
Zathura.Global.status_buffer = GTK_LABEL(gtk_label_new(NULL));
|
2009-09-19 15:53:35 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_text), 0.0, 0.0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_state), 1.0, 0.0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_buffer), 1.0, 0.0);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_misc_set_padding(GTK_MISC(Zathura.Global.status_text), 2.0, 4.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(Zathura.Global.status_state), 2.0, 4.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(Zathura.Global.status_buffer), 2.0, 4.0);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_label_set_use_markup(Zathura.Global.status_text, TRUE);
|
|
|
|
gtk_label_set_use_markup(Zathura.Global.status_state, TRUE);
|
|
|
|
gtk_label_set_use_markup(Zathura.Global.status_buffer, TRUE);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_box_pack_start(Zathura.UI.statusbar_entries, GTK_WIDGET(Zathura.Global.status_text), TRUE, TRUE, 2);
|
|
|
|
gtk_box_pack_start(Zathura.UI.statusbar_entries, GTK_WIDGET(Zathura.Global.status_buffer), FALSE, FALSE, 2);
|
|
|
|
gtk_box_pack_start(Zathura.UI.statusbar_entries, GTK_WIDGET(Zathura.Global.status_state), FALSE, FALSE, 2);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_container_add(GTK_CONTAINER(Zathura.UI.statusbar), GTK_WIDGET(Zathura.UI.statusbar_entries));
|
2009-08-13 22:55:36 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* inputbar */
|
|
|
|
gtk_entry_set_inner_border(Zathura.UI.inputbar, NULL);
|
|
|
|
gtk_entry_set_has_frame( Zathura.UI.inputbar, FALSE);
|
|
|
|
gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), TRUE);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2010-04-11 12:31:18 +02:00
|
|
|
Zathura.Handler.inputbar_key_press_event =
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "key-press-event", G_CALLBACK(cb_inputbar_kb_pressed), NULL);
|
|
|
|
Zathura.Handler.inputbar_activate =
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_activate), NULL);
|
2009-08-13 22:55:36 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* packing */
|
|
|
|
gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(Zathura.UI.view), TRUE, TRUE, 0);
|
|
|
|
gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(Zathura.UI.statusbar), FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_end( Zathura.UI.box, GTK_WIDGET(Zathura.UI.inputbar), FALSE, FALSE, 0);
|
2009-08-13 22:55:36 +02:00
|
|
|
}
|
|
|
|
|
2010-01-30 23:48:36 +01:00
|
|
|
void
|
|
|
|
add_marker(int id)
|
|
|
|
{
|
|
|
|
if( (id < 0x30) || (id > 0x7A))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* current information */
|
|
|
|
int page_number = Zathura.PDF.page_number;
|
|
|
|
|
|
|
|
/* search if entry already exists */
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < Zathura.Marker.number_of_markers; i++)
|
|
|
|
{
|
|
|
|
if(Zathura.Marker.markers[i].id == id)
|
|
|
|
{
|
|
|
|
Zathura.Marker.markers[i].page = page_number;
|
|
|
|
Zathura.Marker.last = page_number;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new marker */
|
|
|
|
int marker_index = Zathura.Marker.number_of_markers++;
|
|
|
|
Zathura.Marker.markers = realloc(Zathura.Marker.markers, sizeof(Marker) *
|
|
|
|
(Zathura.Marker.number_of_markers));
|
|
|
|
|
|
|
|
Zathura.Marker.markers[marker_index].id = id;
|
|
|
|
Zathura.Marker.markers[marker_index].page = page_number;
|
|
|
|
Zathura.Marker.last = page_number;
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:52:45 +01:00
|
|
|
void
|
|
|
|
build_index(GtkTreeModel* model, GtkTreeIter* parent, PopplerIndexIter* index_iter)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
GtkTreeIter tree_iter;
|
|
|
|
PopplerIndexIter *child;
|
|
|
|
PopplerAction *action;
|
|
|
|
gchar *markup;
|
|
|
|
|
|
|
|
action = poppler_index_iter_get_action(index_iter);
|
|
|
|
if(!action)
|
|
|
|
continue;
|
|
|
|
|
2010-04-11 20:56:16 +02:00
|
|
|
markup = g_markup_escape_text (action->any.title, -1);
|
2010-01-01 22:52:45 +01:00
|
|
|
|
|
|
|
gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent);
|
2010-04-11 20:56:16 +02:00
|
|
|
gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, markup, 1, action, -1);
|
2010-01-01 22:52:45 +01:00
|
|
|
g_object_weak_ref(G_OBJECT(model), (GWeakNotify) poppler_action_free, action);
|
|
|
|
g_free(markup);
|
|
|
|
|
|
|
|
child = poppler_index_iter_get_child(index_iter);
|
|
|
|
if(child)
|
|
|
|
build_index(model, &tree_iter, child);
|
|
|
|
poppler_index_iter_free(child);
|
2010-04-11 20:56:16 +02:00
|
|
|
} while(poppler_index_iter_next(index_iter));
|
2010-01-01 22:52:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
draw(int page_id)
|
2009-12-28 19:50:30 +01:00
|
|
|
{
|
2010-05-25 09:03:02 +02:00
|
|
|
if(!Zathura.PDF.document || page_id < 0 || page_id >= Zathura.PDF.number_of_pages)
|
2009-12-28 19:50:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
double page_width, page_height;
|
|
|
|
double width, height;
|
2010-01-01 14:18:09 +01:00
|
|
|
|
2009-12-28 20:02:07 +01:00
|
|
|
double scale = ((double) Zathura.PDF.scale / 100.0);
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-01-01 17:18:48 +01:00
|
|
|
int rotate = Zathura.PDF.rotate;
|
|
|
|
|
2009-12-28 19:50:30 +01:00
|
|
|
Page *current_page = Zathura.PDF.pages[page_id];
|
|
|
|
|
2010-01-20 23:46:13 +01:00
|
|
|
if(Zathura.PDF.surface)
|
|
|
|
cairo_surface_destroy(Zathura.PDF.surface);
|
|
|
|
Zathura.PDF.surface = NULL;
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2009-12-28 19:50:30 +01:00
|
|
|
poppler_page_get_size(current_page->page, &page_width, &page_height);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-01-01 17:18:48 +01:00
|
|
|
if(rotate == 0 || rotate == 180)
|
2009-12-28 19:50:30 +01:00
|
|
|
{
|
2009-12-28 20:02:07 +01:00
|
|
|
width = page_width * scale;
|
|
|
|
height = page_height * scale;
|
2009-12-28 19:50:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-28 20:02:07 +01:00
|
|
|
width = page_height * scale;
|
|
|
|
height = page_width * scale;
|
2009-12-28 19:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_t *cairo;
|
2010-01-20 23:46:13 +01:00
|
|
|
Zathura.PDF.surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
|
|
|
|
cairo = cairo_create(Zathura.PDF.surface);
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-01-02 16:31:25 +01:00
|
|
|
cairo_save(cairo);
|
2009-12-28 19:50:30 +01:00
|
|
|
cairo_set_source_rgb(cairo, 1, 1, 1);
|
|
|
|
cairo_rectangle(cairo, 0, 0, width, height);
|
|
|
|
cairo_fill(cairo);
|
2010-01-02 16:31:25 +01:00
|
|
|
cairo_restore(cairo);
|
|
|
|
cairo_save(cairo);
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-01-01 17:18:48 +01:00
|
|
|
switch(rotate)
|
2009-12-28 19:50:30 +01:00
|
|
|
{
|
|
|
|
case 90:
|
|
|
|
cairo_translate(cairo, width, 0);
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
cairo_translate(cairo, width, height);
|
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
cairo_translate(cairo, 0, height);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cairo_translate(cairo, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-12-28 20:02:07 +01:00
|
|
|
if(scale != 1.0)
|
|
|
|
cairo_scale(cairo, scale, scale);
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-01-01 17:18:48 +01:00
|
|
|
if(rotate != 0)
|
|
|
|
cairo_rotate(cairo, rotate * G_PI / 180.0);
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2009-12-28 19:50:30 +01:00
|
|
|
poppler_page_render(current_page->page, cairo);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2009-12-28 19:50:30 +01:00
|
|
|
|
2010-01-02 16:31:25 +01:00
|
|
|
cairo_restore(cairo);
|
|
|
|
cairo_destroy(cairo);
|
|
|
|
|
2010-04-11 10:47:09 +02:00
|
|
|
if(Zathura.Global.recolor)
|
2010-01-01 15:34:01 +01:00
|
|
|
{
|
2010-01-20 23:46:13 +01:00
|
|
|
unsigned char* image = cairo_image_surface_get_data(Zathura.PDF.surface);
|
2010-04-11 10:47:09 +02:00
|
|
|
int x, y;
|
2010-01-20 23:46:13 +01:00
|
|
|
|
2010-04-11 10:47:09 +02:00
|
|
|
int width = cairo_image_surface_get_width(Zathura.PDF.surface);
|
|
|
|
int height = cairo_image_surface_get_height(Zathura.PDF.surface);
|
|
|
|
int rowstride = cairo_image_surface_get_stride(Zathura.PDF.surface);
|
|
|
|
|
|
|
|
/* recolor code based on qimageblitz library flatten() function
|
|
|
|
(http://sourceforge.net/projects/qimageblitz/) */
|
|
|
|
|
|
|
|
int r1 = Zathura.Style.recolor_darkcolor.red / 257;
|
|
|
|
int g1 = Zathura.Style.recolor_darkcolor.green / 257;
|
|
|
|
int b1 = Zathura.Style.recolor_darkcolor.blue / 257;
|
|
|
|
int r2 = Zathura.Style.recolor_lightcolor.red / 257;
|
|
|
|
int g2 = Zathura.Style.recolor_lightcolor.green / 257;
|
|
|
|
int b2 = Zathura.Style.recolor_lightcolor.blue / 257;
|
|
|
|
|
|
|
|
int min = 0x00;
|
|
|
|
int max = 0xFF;
|
|
|
|
int mean;
|
|
|
|
|
|
|
|
float sr = ((float) r2 - r1) / (max - min);
|
|
|
|
float sg = ((float) g2 - g1) / (max - min);
|
|
|
|
float sb = ((float) b2 - b1) / (max - min);
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
for (y = 0; y < height; y++)
|
2010-04-11 10:47:09 +02:00
|
|
|
{
|
|
|
|
unsigned char* data = image + y * rowstride;
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
for (x = 0; x < width; x++)
|
2010-04-11 10:47:09 +02:00
|
|
|
{
|
|
|
|
mean = (data[0] + data[1] + data[2]) / 3;
|
|
|
|
data[2] = sr * (mean - min) + r1 + 0.5;
|
|
|
|
data[1] = sg * (mean - min) + g1 + 0.5;
|
|
|
|
data[0] = sb * (mean - min) + b1 + 0.5;
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2010-01-01 15:34:01 +01:00
|
|
|
}
|
2009-12-28 21:18:54 +01:00
|
|
|
|
2010-01-20 23:46:13 +01:00
|
|
|
gtk_widget_set_size_request(Zathura.UI.drawing_area, width, height);
|
|
|
|
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
2009-12-28 19:50:30 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
void
|
|
|
|
change_mode(int mode)
|
2009-08-29 16:07:58 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
char* mode_text;
|
|
|
|
|
|
|
|
switch(mode)
|
2009-08-29 16:07:58 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
case INSERT:
|
|
|
|
mode_text = "-- INSERT --";
|
2009-08-29 16:07:58 +02:00
|
|
|
break;
|
2009-12-26 14:30:50 +01:00
|
|
|
case VISUAL:
|
|
|
|
mode_text = "-- VISUAL --";
|
2009-08-29 16:07:58 +02:00
|
|
|
break;
|
2010-01-30 23:48:36 +01:00
|
|
|
case ADD_MARKER:
|
|
|
|
mode_text = "";
|
|
|
|
break;
|
|
|
|
case EVAL_MARKER:
|
|
|
|
mode_text = "";
|
|
|
|
break;
|
2009-08-29 16:07:58 +02:00
|
|
|
default:
|
2009-12-26 14:30:50 +01:00
|
|
|
mode_text = "";
|
|
|
|
mode = NORMAL;
|
|
|
|
break;
|
2009-08-29 16:07:58 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
Zathura.Global.mode = mode;
|
|
|
|
notify(DEFAULT, mode_text);
|
2009-08-29 16:07:58 +02:00
|
|
|
}
|
|
|
|
|
2010-04-13 09:47:47 +02:00
|
|
|
void
|
|
|
|
calculate_offset(GtkWidget* widget, double* offset_x, double* offset_y)
|
|
|
|
{
|
|
|
|
double page_width, page_height, width, height;
|
|
|
|
double scale = ((double) Zathura.PDF.scale / 100.0);
|
|
|
|
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
|
|
|
|
if(Zathura.PDF.rotate == 0 || Zathura.PDF.rotate == 180)
|
|
|
|
{
|
|
|
|
width = page_width * scale;
|
|
|
|
height = page_height * scale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = page_height * scale;
|
|
|
|
height = page_width * scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
int window_x, window_y;
|
|
|
|
gdk_drawable_get_size(widget->window, &window_x, &window_y);
|
|
|
|
|
|
|
|
if (window_x > width)
|
|
|
|
*offset_x = (window_x - width) / 2;
|
|
|
|
else
|
|
|
|
*offset_x = 0;
|
|
|
|
|
|
|
|
if (window_y > height)
|
|
|
|
*offset_y = (window_y - height) / 2;
|
|
|
|
else
|
|
|
|
*offset_y = 0;
|
2010-05-24 21:26:40 +02:00
|
|
|
}
|
|
|
|
|
2010-06-15 10:17:38 +02:00
|
|
|
void
|
|
|
|
close_file(gboolean keep_monitor)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* clean up pages */
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < Zathura.PDF.number_of_pages; i++)
|
|
|
|
{
|
|
|
|
Page* current_page = Zathura.PDF.pages[i];
|
|
|
|
g_object_unref(current_page->page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save bookmarks */
|
|
|
|
if(Zathura.Bookmarks.data)
|
|
|
|
{
|
|
|
|
/* set current page */
|
|
|
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
|
|
|
BM_PAGE_ENTRY, Zathura.PDF.page_number);
|
|
|
|
|
|
|
|
/* set page offset */
|
|
|
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
|
|
|
BM_PAGE_OFFSET, Zathura.PDF.page_offset);
|
|
|
|
|
|
|
|
/* save bookmarks */
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
|
|
|
g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file,
|
|
|
|
Zathura.Bookmarks.bookmarks[i].id, Zathura.Bookmarks.bookmarks[i].page);
|
|
|
|
|
|
|
|
/* convert file and save it */
|
|
|
|
gchar* bookmarks = g_key_file_to_data(Zathura.Bookmarks.data, NULL, NULL);
|
|
|
|
g_file_set_contents(Zathura.Bookmarks.file, bookmarks, -1, NULL);
|
|
|
|
g_free(bookmarks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inotify */
|
|
|
|
if(!keep_monitor)
|
|
|
|
{
|
|
|
|
g_object_unref(Zathura.FileMonitor.monitor);
|
|
|
|
Zathura.FileMonitor.monitor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset values */
|
|
|
|
free(Zathura.PDF.pages);
|
|
|
|
g_object_unref(Zathura.PDF.document);
|
|
|
|
g_free(Zathura.State.pages);
|
2010-06-16 20:24:31 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura");
|
2010-06-15 10:17:38 +02:00
|
|
|
|
|
|
|
Zathura.State.pages = g_strdup_printf("");
|
2010-06-17 00:53:41 +02:00
|
|
|
Zathura.State.filename = (char*) default_text;;
|
2010-06-15 10:17:38 +02:00
|
|
|
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
Zathura.PDF.document = NULL;
|
|
|
|
if(!keep_monitor)
|
|
|
|
{
|
|
|
|
Zathura.PDF.file = NULL;
|
|
|
|
Zathura.PDF.password = NULL;
|
|
|
|
Zathura.PDF.page_number = 0;
|
|
|
|
Zathura.PDF.scale = 0;
|
|
|
|
Zathura.PDF.rotate = 0;
|
|
|
|
}
|
|
|
|
Zathura.PDF.number_of_pages = 0;
|
|
|
|
Zathura.PDF.page_offset = 0;
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
|
|
|
|
/* destroy index */
|
|
|
|
if(Zathura.UI.index)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(Zathura.UI.index);
|
|
|
|
Zathura.UI.index = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destroy information */
|
|
|
|
if(Zathura.UI.information)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(Zathura.UI.information);
|
|
|
|
Zathura.UI.information = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free markers */
|
|
|
|
if(Zathura.Marker.markers)
|
|
|
|
free(Zathura.Marker.markers);
|
|
|
|
Zathura.Marker.number_of_markers = 0;
|
|
|
|
Zathura.Marker.last = -1;
|
|
|
|
|
|
|
|
update_status();
|
|
|
|
}
|
|
|
|
|
2010-05-24 21:26:40 +02:00
|
|
|
void
|
|
|
|
enter_password()
|
|
|
|
{
|
|
|
|
/* replace default inputbar handler */
|
|
|
|
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
|
|
|
|
Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_password_activate), NULL);
|
2010-04-13 09:47:47 +02:00
|
|
|
|
2010-05-24 21:26:40 +02:00
|
|
|
Argument argument;
|
|
|
|
argument.data = "Enter password: ";
|
|
|
|
sc_focus_inputbar(&argument);
|
2010-04-13 09:47:47 +02:00
|
|
|
}
|
|
|
|
|
2010-01-30 23:48:36 +01:00
|
|
|
void
|
|
|
|
eval_marker(int id)
|
|
|
|
{
|
|
|
|
/* go to last marker */
|
|
|
|
if(id == 0x27)
|
|
|
|
{
|
|
|
|
int current_page = Zathura.PDF.page_number;
|
|
|
|
set_page(Zathura.Marker.last);
|
|
|
|
Zathura.Marker.last = current_page;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search markers */
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < Zathura.Marker.number_of_markers; i++)
|
|
|
|
{
|
|
|
|
if(Zathura.Marker.markers[i].id == id)
|
|
|
|
{
|
|
|
|
set_page(Zathura.Marker.markers[i].page);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-02 14:23:49 +01:00
|
|
|
void
|
|
|
|
highlight_result(int page_id, PopplerRectangle* rectangle)
|
|
|
|
{
|
2010-05-13 11:31:02 +02:00
|
|
|
PopplerRectangle* trect = poppler_rectangle_copy(rectangle);
|
2010-01-20 23:46:13 +01:00
|
|
|
cairo_t *cairo = cairo_create(Zathura.PDF.surface);
|
2010-01-02 14:23:49 +01:00
|
|
|
cairo_set_source_rgba(cairo, Zathura.Style.search_highlight.red, Zathura.Style.search_highlight.green,
|
2010-06-15 12:50:43 +02:00
|
|
|
Zathura.Style.search_highlight.blue, transparency);
|
2010-01-02 14:23:49 +01:00
|
|
|
|
2010-05-13 11:31:02 +02:00
|
|
|
recalcRectangle(page_id, trect);
|
|
|
|
cairo_rectangle(cairo, trect->x1, trect->y1, (trect->x2 - trect->x1), (trect->y2 - trect->y1));
|
|
|
|
poppler_rectangle_free(trect);
|
2010-01-02 14:23:49 +01:00
|
|
|
cairo_fill(cairo);
|
2010-01-02 14:24:44 +01:00
|
|
|
}
|
2010-01-02 14:23:49 +01:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
void notify(int level, char* message)
|
2009-08-13 22:55:36 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
switch(level)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
case ERROR:
|
|
|
|
gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_e_bg));
|
|
|
|
gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_e_fg));
|
2009-08-12 21:45:49 +02:00
|
|
|
break;
|
2009-12-26 14:30:50 +01:00
|
|
|
case WARNING:
|
|
|
|
gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_w_bg));
|
|
|
|
gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_w_fg));
|
2009-08-12 21:45:49 +02:00
|
|
|
break;
|
|
|
|
default:
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_bg));
|
|
|
|
gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_fg));
|
|
|
|
break;
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
2010-05-18 00:19:09 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(message)
|
|
|
|
gtk_entry_set_text(Zathura.UI.inputbar, message);
|
2009-08-15 12:35:07 +02:00
|
|
|
}
|
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
gboolean
|
|
|
|
open_file(char* path, char* password)
|
|
|
|
{
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
2010-05-24 21:26:40 +02:00
|
|
|
|
2010-06-06 19:27:10 +02:00
|
|
|
/* specify path max */
|
|
|
|
size_t pm;
|
|
|
|
#ifdef PATH_MAX
|
|
|
|
pm = PATH_MAX;
|
|
|
|
#else
|
|
|
|
pm = pathconf(path,_PC_PATH_MAX);
|
|
|
|
if(pm <= 0)
|
|
|
|
pm = 4096;
|
|
|
|
#endif
|
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
/* get filename */
|
2010-06-06 19:27:10 +02:00
|
|
|
char* file = (char*) calloc(sizeof(char), pm);
|
|
|
|
if(!file || !realpath(path, file))
|
|
|
|
{
|
2010-06-16 22:52:28 +02:00
|
|
|
notify(ERROR, "File does not exist");
|
2010-06-06 19:27:10 +02:00
|
|
|
if(file)
|
|
|
|
free(file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-02-02 15:27:37 +01:00
|
|
|
|
|
|
|
if(path[0] == '~')
|
2010-04-10 14:33:23 +02:00
|
|
|
{
|
|
|
|
char* home_path = getenv("HOME");
|
|
|
|
int file_len = strlen(home_path) + strlen(path) - 1;
|
|
|
|
file = malloc(file_len);
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!file)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
snprintf(file, file_len, "%s%s", getenv("HOME"), path + 1);
|
|
|
|
}
|
2010-02-02 15:27:37 +01:00
|
|
|
|
|
|
|
/* check if file exists */
|
|
|
|
if(!g_file_test(file, G_FILE_TEST_IS_REGULAR))
|
|
|
|
{
|
|
|
|
notify(ERROR, "File does not exist");
|
2010-04-10 14:33:23 +02:00
|
|
|
free(file);
|
2010-05-24 21:26:40 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
2010-02-02 15:27:37 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close old file */
|
2010-05-24 21:26:40 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
2010-06-15 10:17:38 +02:00
|
|
|
close_file(FALSE);
|
2010-05-24 21:26:40 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
2010-02-02 15:27:37 +01:00
|
|
|
|
2010-05-11 20:09:20 +02:00
|
|
|
/* format path */
|
2010-02-02 15:27:37 +01:00
|
|
|
GError* error = NULL;
|
2010-05-11 20:09:20 +02:00
|
|
|
char* file_uri = g_filename_to_uri(file, NULL, &error);
|
|
|
|
if (!file_uri)
|
|
|
|
{
|
|
|
|
char* message = g_strdup_printf("Can not open file: %s", error->message);
|
|
|
|
notify(ERROR, message);
|
|
|
|
g_free(message);
|
|
|
|
g_error_free(error);
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
2010-05-11 20:09:20 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open file */
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-05-24 21:26:40 +02:00
|
|
|
Zathura.PDF.document = poppler_document_new_from_file(file_uri, password, &error);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-02-02 15:27:37 +01:00
|
|
|
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
{
|
2010-05-24 21:26:40 +02:00
|
|
|
if(error->code == 1)
|
|
|
|
{
|
2010-06-03 18:05:34 +02:00
|
|
|
g_free(file_uri);
|
2010-05-24 21:26:40 +02:00
|
|
|
g_error_free(error);
|
|
|
|
Zathura.PDF.file = file;
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
enter_password();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char* message = g_strdup_printf("Can not open file: %s", error->message);
|
|
|
|
notify(ERROR, message);
|
2010-06-03 18:05:34 +02:00
|
|
|
g_free(file_uri);
|
2010-05-24 21:26:40 +02:00
|
|
|
g_free(message);
|
|
|
|
g_error_free(error);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-02-02 15:27:37 +01:00
|
|
|
}
|
|
|
|
|
2010-05-24 21:26:40 +02:00
|
|
|
/* save password */
|
|
|
|
Zathura.PDF.password = password;
|
|
|
|
|
2010-03-08 20:08:59 +01:00
|
|
|
/* inotify */
|
2010-06-15 10:17:38 +02:00
|
|
|
if(!Zathura.FileMonitor.monitor)
|
2010-03-08 20:08:59 +01:00
|
|
|
{
|
2010-06-03 18:05:34 +02:00
|
|
|
GFile* file = g_file_new_for_uri(file_uri);
|
|
|
|
|
|
|
|
if(file)
|
|
|
|
{
|
|
|
|
Zathura.FileMonitor.monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, NULL, NULL);
|
|
|
|
if(Zathura.FileMonitor.monitor)
|
|
|
|
g_signal_connect(G_OBJECT(Zathura.FileMonitor.monitor), "changed", G_CALLBACK(cb_watch_file), NULL);
|
|
|
|
}
|
2010-03-08 20:08:59 +01:00
|
|
|
}
|
|
|
|
|
2010-06-03 18:05:34 +02:00
|
|
|
g_free(file_uri);
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-02-02 15:27:37 +01:00
|
|
|
Zathura.PDF.number_of_pages = poppler_document_get_n_pages(Zathura.PDF.document);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-02-02 15:27:37 +01:00
|
|
|
Zathura.PDF.file = file;
|
|
|
|
Zathura.PDF.scale = 100;
|
|
|
|
Zathura.PDF.rotate = 0;
|
2010-04-10 14:33:23 +02:00
|
|
|
Zathura.State.filename = g_markup_escape_text(file, -1);
|
2010-06-16 22:42:45 +02:00
|
|
|
Zathura.PDF.pages = malloc(Zathura.PDF.number_of_pages * sizeof(Page*));
|
|
|
|
|
|
|
|
if(!Zathura.PDF.pages)
|
|
|
|
out_of_memory();
|
2010-02-02 15:27:37 +01:00
|
|
|
|
2010-05-06 20:31:53 +02:00
|
|
|
/* get pages and check label mode */
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-05-06 20:31:53 +02:00
|
|
|
Zathura.Global.enable_labelmode = FALSE;
|
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < Zathura.PDF.number_of_pages; i++)
|
|
|
|
{
|
|
|
|
Zathura.PDF.pages[i] = malloc(sizeof(Page));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!Zathura.PDF.pages[i])
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-05-05 12:36:04 +02:00
|
|
|
Zathura.PDF.pages[i]->id = i + 1;
|
2010-02-02 15:27:37 +01:00
|
|
|
Zathura.PDF.pages[i]->page = poppler_document_get_page(Zathura.PDF.document, i);
|
2010-05-05 12:36:04 +02:00
|
|
|
g_object_get(G_OBJECT(Zathura.PDF.pages[i]->page), "label", &(Zathura.PDF.pages[i]->label), NULL);
|
2010-05-06 20:31:53 +02:00
|
|
|
|
|
|
|
/* check if it is necessary to use the label mode */
|
|
|
|
int label_int = atoi(Zathura.PDF.pages[i]->label);
|
|
|
|
if(label_int == 0 || label_int != (i+1))
|
|
|
|
Zathura.Global.enable_labelmode = TRUE;
|
2010-02-02 15:27:37 +01:00
|
|
|
}
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-02-02 15:27:37 +01:00
|
|
|
|
2010-05-06 20:31:53 +02:00
|
|
|
/* set correct goto mode */
|
|
|
|
if(!Zathura.Global.enable_labelmode && GOTO_MODE == GOTO_LABELS)
|
|
|
|
Zathura.Global.goto_mode = GOTO_DEFAULT;
|
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
/* start page */
|
2010-05-05 20:05:06 +02:00
|
|
|
int start_page = 0;
|
|
|
|
Zathura.PDF.page_offset = 0;
|
2010-02-02 15:27:37 +01:00
|
|
|
|
|
|
|
/* bookmarks */
|
2010-05-05 20:05:06 +02:00
|
|
|
if(Zathura.Bookmarks.data && g_key_file_has_group(Zathura.Bookmarks.data, file))
|
2010-02-02 15:27:37 +01:00
|
|
|
{
|
|
|
|
/* get last opened page */
|
2010-05-05 20:05:06 +02:00
|
|
|
if(g_key_file_has_key(Zathura.Bookmarks.data, file, BM_PAGE_ENTRY, NULL))
|
|
|
|
start_page = g_key_file_get_integer(Zathura.Bookmarks.data, file, BM_PAGE_ENTRY, NULL);
|
|
|
|
|
|
|
|
/* get page offset */
|
|
|
|
if(g_key_file_has_key(Zathura.Bookmarks.data, file, BM_PAGE_OFFSET, NULL))
|
|
|
|
Zathura.PDF.page_offset = g_key_file_get_integer(Zathura.Bookmarks.data, file, BM_PAGE_OFFSET, NULL);
|
|
|
|
if((Zathura.PDF.page_offset != 0) && (Zathura.PDF.page_offset != GOTO_OFFSET))
|
|
|
|
Zathura.PDF.page_offset = GOTO_OFFSET;
|
2010-02-02 15:27:37 +01:00
|
|
|
|
|
|
|
/* open and read bookmark file */
|
|
|
|
gsize i = 0;
|
|
|
|
gsize number_of_keys = 0;
|
|
|
|
char** keys = g_key_file_get_keys(Zathura.Bookmarks.data, file, &number_of_keys, NULL);
|
|
|
|
|
|
|
|
for(i = 0; i < number_of_keys; i++)
|
|
|
|
{
|
2010-05-05 20:05:06 +02:00
|
|
|
if(strcmp(keys[i], BM_PAGE_ENTRY) && strcmp(keys[i], BM_PAGE_OFFSET))
|
2010-02-02 15:27:37 +01:00
|
|
|
{
|
2010-05-18 00:19:09 +02:00
|
|
|
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
|
|
|
|
(Zathura.Bookmarks.number_of_bookmarks + 1) * sizeof(Bookmark));
|
2010-02-02 15:27:37 +01:00
|
|
|
|
|
|
|
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].id = keys[i];
|
2010-05-18 00:19:09 +02:00
|
|
|
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].page =
|
2010-02-02 15:27:37 +01:00
|
|
|
g_key_file_get_integer(Zathura.Bookmarks.data, file, keys[i], NULL);
|
|
|
|
|
|
|
|
Zathura.Bookmarks.number_of_bookmarks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-12 09:47:07 +02:00
|
|
|
/* set window title */
|
2010-06-16 20:24:31 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), basename(file));
|
2010-06-12 09:47:07 +02:00
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
/* show document */
|
|
|
|
set_page(start_page);
|
|
|
|
update_status();
|
|
|
|
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
2010-06-15 10:17:38 +02:00
|
|
|
isc_abort(NULL);
|
2010-02-02 15:27:37 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-11 14:18:49 +02:00
|
|
|
void open_uri(char* uri)
|
|
|
|
{
|
2010-06-15 12:50:43 +02:00
|
|
|
char* uri_cmd = g_strdup_printf(uri_command, uri);
|
2010-04-11 14:18:49 +02:00
|
|
|
system(uri_cmd);
|
|
|
|
g_free(uri_cmd);
|
|
|
|
}
|
|
|
|
|
2010-06-16 22:42:45 +02:00
|
|
|
void out_of_memory()
|
|
|
|
{
|
|
|
|
printf("error: out of memory\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2009-08-15 12:35:07 +02:00
|
|
|
void
|
2009-12-26 17:44:13 +01:00
|
|
|
update_status()
|
2009-08-15 12:35:07 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
/* update text */
|
2009-12-26 17:44:13 +01:00
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename);
|
2009-12-26 14:30:50 +01:00
|
|
|
|
2010-05-05 12:36:04 +02:00
|
|
|
/* update pages */
|
|
|
|
if( Zathura.PDF.document && Zathura.PDF.pages )
|
|
|
|
{
|
|
|
|
int page = Zathura.PDF.page_number;
|
2010-05-14 11:30:00 +02:00
|
|
|
g_free(Zathura.State.pages);
|
2010-05-25 20:16:12 +02:00
|
|
|
|
|
|
|
Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages);
|
2010-05-05 12:36:04 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* update state */
|
2010-05-25 20:16:12 +02:00
|
|
|
char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : g_strdup("");
|
2010-06-17 00:12:21 +02:00
|
|
|
char* goto_mode = (Zathura.Global.goto_mode == GOTO_LABELS) ? "L" :
|
2010-05-05 20:05:06 +02:00
|
|
|
(Zathura.Global.goto_mode == GOTO_OFFSET) ? "O" : "D";
|
|
|
|
char* status_text = g_strdup_printf("%s [%s] %s", zoom_level, goto_mode, Zathura.State.pages);
|
2009-12-28 19:03:26 +01:00
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text);
|
2010-05-25 20:16:12 +02:00
|
|
|
g_free(status_text);
|
|
|
|
g_free(zoom_level);
|
2009-08-13 22:55:36 +02:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:52:19 +02:00
|
|
|
void
|
|
|
|
read_configuration()
|
|
|
|
{
|
|
|
|
char* zathurarc = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, ZATHURA_RC);
|
|
|
|
|
|
|
|
if(!zathurarc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(g_file_test(zathurarc, G_FILE_TEST_IS_REGULAR))
|
|
|
|
{
|
|
|
|
char* content = NULL;
|
|
|
|
|
|
|
|
if(g_file_get_contents(zathurarc, &content, NULL, NULL))
|
|
|
|
{
|
|
|
|
gchar **lines = g_strsplit(content, "\n", -1);
|
|
|
|
int n = g_strv_length(lines) - 1;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
{
|
2010-06-18 10:35:12 +02:00
|
|
|
if(!strlen(lines[i]))
|
|
|
|
continue;
|
|
|
|
|
2010-06-14 21:52:19 +02:00
|
|
|
gchar **tokens = g_strsplit(lines[i], " ", -1);
|
|
|
|
int length = g_strv_length(tokens);
|
|
|
|
|
|
|
|
if(!strcmp(tokens[0], "set"))
|
|
|
|
cmd_set(length - 1, tokens + 1);
|
2010-06-17 00:12:21 +02:00
|
|
|
else if(!strcmp(tokens[0], "map"))
|
|
|
|
cmd_map(length - 1, tokens + 1);
|
2010-06-14 21:52:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(zathurarc);
|
|
|
|
}
|
|
|
|
|
2010-01-02 14:23:49 +01:00
|
|
|
void
|
|
|
|
recalcRectangle(int page_id, PopplerRectangle* rectangle)
|
|
|
|
{
|
|
|
|
double page_width, page_height;
|
|
|
|
double x1 = rectangle->x1;
|
|
|
|
double x2 = rectangle->x2;
|
|
|
|
double y1 = rectangle->y1;
|
|
|
|
double y2 = rectangle->y2;
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-02 14:23:49 +01:00
|
|
|
poppler_page_get_size(Zathura.PDF.pages[page_id]->page, &page_width, &page_height);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-02 14:23:49 +01:00
|
|
|
|
|
|
|
double scale = ((double) Zathura.PDF.scale / 100.0);
|
|
|
|
|
|
|
|
int rotate = Zathura.PDF.rotate;
|
|
|
|
|
|
|
|
switch(rotate)
|
|
|
|
{
|
|
|
|
case 90:
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->x1 = y2 * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
rectangle->y1 = x1 * scale;
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->x2 = y1 * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
rectangle->y2 = x2 * scale;
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
rectangle->x1 = (page_width - x2) * scale;
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->y1 = y2 * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
rectangle->x2 = (page_width - x1) * scale;
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->y2 = y1 * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
break;
|
|
|
|
case 270:
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->x1 = (page_height - y1) * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
rectangle->y1 = (page_width - x2) * scale;
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->x2 = (page_height - y2) * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
rectangle->y2 = (page_width - x1) * scale;
|
|
|
|
break;
|
|
|
|
default:
|
2010-01-02 23:34:34 +01:00
|
|
|
rectangle->x1 = x1 * scale;
|
|
|
|
rectangle->y1 = (page_height - y1) * scale;
|
|
|
|
rectangle->x2 = x2 * scale;
|
|
|
|
rectangle->y2 = (page_height - y2) * scale;
|
2010-01-02 14:23:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
GtkEventBox*
|
|
|
|
createCompletionRow(GtkBox* results, char* command, char* description, gboolean group)
|
2009-08-29 16:07:58 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
GtkBox *col = GTK_BOX(gtk_hbox_new(FALSE, 0));
|
|
|
|
GtkEventBox *row = GTK_EVENT_BOX(gtk_event_box_new());
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
GtkLabel *show_command = GTK_LABEL(gtk_label_new(NULL));
|
|
|
|
GtkLabel *show_description = GTK_LABEL(gtk_label_new(NULL));
|
2009-09-19 10:43:41 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(show_command), 0.0, 0.0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(show_description), 0.0, 0.0);
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(group)
|
|
|
|
{
|
|
|
|
gtk_misc_set_padding(GTK_MISC(show_command), 2.0, 4.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(show_description), 2.0, 4.0);
|
2009-08-29 16:07:58 +02:00
|
|
|
}
|
2009-12-26 14:30:50 +01:00
|
|
|
else
|
2009-08-29 16:07:58 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_misc_set_padding(GTK_MISC(show_command), 1.0, 1.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(show_description), 1.0, 1.0);
|
2009-08-29 16:07:58 +02:00
|
|
|
}
|
|
|
|
|
2009-12-28 00:44:35 +01:00
|
|
|
gtk_label_set_use_markup(show_command, TRUE);
|
|
|
|
gtk_label_set_use_markup(show_description, TRUE);
|
2009-08-13 22:55:36 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_label_set_markup(show_command, g_markup_printf_escaped(FORMAT_COMMAND, command ? command : ""));
|
|
|
|
gtk_label_set_markup(show_description, g_markup_printf_escaped(FORMAT_DESCRIPTION, description ? description : ""));
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(group)
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg));
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(show_description), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg));
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_bg));
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg));
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(show_description), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg));
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg));
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_widget_modify_font(GTK_WIDGET(show_command), Zathura.Style.font);
|
|
|
|
gtk_widget_modify_font(GTK_WIDGET(show_description), Zathura.Style.font);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_command), TRUE, TRUE, 2);
|
|
|
|
gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_description), FALSE, FALSE, 2);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_container_add(GTK_CONTAINER(row), GTK_WIDGET(col));
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_box_pack_start(results, GTK_WIDGET(row), FALSE, FALSE, 0);
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
return row;
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
setCompletionRowColor(GtkBox* results, int mode, int id)
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
GtkEventBox *row = (GtkEventBox*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(results)), id);
|
2010-05-18 00:19:09 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(row)
|
2009-09-19 15:53:35 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
GtkBox *col = (GtkBox*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(row)), 0);
|
|
|
|
GtkLabel *cmd = (GtkLabel*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 0);
|
|
|
|
GtkLabel *cdesc = (GtkLabel*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 1);
|
|
|
|
|
|
|
|
if(mode == NORMAL)
|
|
|
|
{
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg));
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(cdesc), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg));
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg));
|
|
|
|
gtk_widget_modify_fg(GTK_WIDGET(cdesc), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg));
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_bg));
|
|
|
|
}
|
2009-09-19 15:53:35 +02:00
|
|
|
}
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 17:44:13 +01:00
|
|
|
void
|
|
|
|
set_page(int page)
|
|
|
|
{
|
2010-05-25 09:03:02 +02:00
|
|
|
if(page >= Zathura.PDF.number_of_pages || page < 0)
|
2009-12-26 17:44:13 +01:00
|
|
|
{
|
|
|
|
notify(WARNING, "Could not open page");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Zathura.PDF.page_number = page;
|
2010-05-18 22:24:15 +02:00
|
|
|
Zathura.Search.draw = FALSE;
|
2010-01-29 13:18:25 +01:00
|
|
|
|
|
|
|
Argument argument;
|
|
|
|
argument.n = TOP;
|
|
|
|
|
2010-04-12 23:55:14 +02:00
|
|
|
switch_view(Zathura.UI.document);
|
2010-01-20 23:46:13 +01:00
|
|
|
draw(page);
|
2010-05-18 23:11:38 +02:00
|
|
|
sc_scroll(&argument);
|
2009-12-26 17:44:13 +01:00
|
|
|
}
|
|
|
|
|
2009-12-28 21:42:55 +01:00
|
|
|
void
|
|
|
|
switch_view(GtkWidget* widget)
|
|
|
|
{
|
2010-01-02 16:31:25 +01:00
|
|
|
GtkWidget* child = gtk_bin_get_child(GTK_BIN(Zathura.UI.viewport));
|
|
|
|
if(child)
|
2009-12-29 22:33:40 +01:00
|
|
|
{
|
2010-01-02 16:31:25 +01:00
|
|
|
g_object_ref(child);
|
|
|
|
gtk_container_remove(GTK_CONTAINER(Zathura.UI.viewport), child);
|
2009-12-29 22:33:40 +01:00
|
|
|
}
|
2009-12-28 21:42:55 +01:00
|
|
|
|
2009-12-29 22:33:40 +01:00
|
|
|
gtk_container_add(GTK_CONTAINER(Zathura.UI.viewport), GTK_WIDGET(widget));
|
2009-12-28 21:42:55 +01:00
|
|
|
}
|
|
|
|
|
2009-12-28 19:50:30 +01:00
|
|
|
/* thread implementation */
|
2010-01-21 01:46:53 +01:00
|
|
|
void*
|
|
|
|
search(void* parameter)
|
2010-01-02 16:31:25 +01:00
|
|
|
{
|
|
|
|
Argument* argument = (Argument*) parameter;
|
|
|
|
|
|
|
|
static char* search_item;
|
|
|
|
static int direction;
|
2010-01-21 01:46:53 +01:00
|
|
|
static int next_page = 0;
|
2010-01-02 16:31:25 +01:00
|
|
|
int page_counter;
|
2010-04-10 14:33:23 +02:00
|
|
|
GList* results = NULL;
|
2010-01-21 01:46:53 +01:00
|
|
|
|
2010-01-02 16:31:25 +01:00
|
|
|
if(argument->data)
|
2010-05-25 20:16:12 +02:00
|
|
|
{
|
|
|
|
if(search_item)
|
|
|
|
g_free(search_item);
|
|
|
|
|
2010-01-02 16:31:25 +01:00
|
|
|
search_item = g_strdup((char*) argument->data);
|
2010-05-25 20:16:12 +02:00
|
|
|
}
|
2010-01-02 16:31:25 +01:00
|
|
|
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
2010-01-02 16:31:25 +01:00
|
|
|
if(!Zathura.PDF.document || !search_item || !strlen(search_item))
|
2010-01-21 01:46:53 +01:00
|
|
|
{
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.search_lock));
|
2010-01-21 01:46:53 +01:00
|
|
|
Zathura.Thread.search_thread_running = FALSE;
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.search_lock));
|
|
|
|
g_thread_exit(NULL);
|
2010-01-21 01:46:53 +01:00
|
|
|
}
|
2010-01-02 16:31:25 +01:00
|
|
|
|
2010-05-11 20:45:47 +02:00
|
|
|
/* delete old results */
|
|
|
|
if(Zathura.Search.results)
|
|
|
|
{
|
|
|
|
g_list_free(Zathura.Search.results);
|
|
|
|
Zathura.Search.results = NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-02 16:31:25 +01:00
|
|
|
/* search document */
|
|
|
|
if(argument->n)
|
|
|
|
direction = (argument->n == BACKWARD) ? -1 : 1;
|
|
|
|
|
2010-04-27 16:07:49 +02:00
|
|
|
int number_of_pages = Zathura.PDF.number_of_pages;
|
|
|
|
int page_number = Zathura.PDF.page_number;
|
|
|
|
|
2010-05-12 12:27:15 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
|
|
|
|
for(page_counter = 1; page_counter <= number_of_pages; page_counter++)
|
2010-01-02 16:31:25 +01:00
|
|
|
{
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.search_lock));
|
2010-03-08 21:10:39 +01:00
|
|
|
if(Zathura.Thread.search_thread_running == FALSE)
|
|
|
|
{
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.search_lock));
|
|
|
|
g_thread_exit(NULL);
|
2010-03-08 21:10:39 +01:00
|
|
|
}
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.search_lock));
|
2010-03-08 21:10:39 +01:00
|
|
|
|
2010-04-27 16:07:49 +02:00
|
|
|
next_page = (number_of_pages + page_number +
|
|
|
|
page_counter * direction) % number_of_pages;
|
2010-01-02 16:31:25 +01:00
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-21 11:36:13 +01:00
|
|
|
PopplerPage* page = poppler_document_get_page(Zathura.PDF.document, next_page);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-03-08 21:49:41 +01:00
|
|
|
|
2010-01-21 11:36:13 +01:00
|
|
|
if(!page)
|
2010-04-10 14:33:23 +02:00
|
|
|
g_thread_exit(NULL);
|
2010-03-08 21:49:41 +01:00
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-21 11:36:13 +01:00
|
|
|
results = poppler_page_find_text(page, search_item);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-02 16:31:25 +01:00
|
|
|
|
|
|
|
if(results)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw results */
|
|
|
|
if(results)
|
|
|
|
{
|
2010-04-10 14:33:23 +02:00
|
|
|
gdk_threads_enter();
|
|
|
|
|
2010-03-28 20:59:25 +02:00
|
|
|
set_page(next_page);
|
|
|
|
|
2010-05-11 20:45:47 +02:00
|
|
|
Zathura.Search.results = results;
|
|
|
|
Zathura.Search.page = next_page;
|
2010-05-18 22:24:15 +02:00
|
|
|
Zathura.Search.draw = TRUE;
|
2010-04-10 14:33:23 +02:00
|
|
|
|
|
|
|
gdk_threads_leave();
|
2010-01-02 16:31:25 +01:00
|
|
|
}
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.search_lock));
|
2010-01-21 01:46:53 +01:00
|
|
|
Zathura.Thread.search_thread_running = FALSE;
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.search_lock));
|
|
|
|
|
|
|
|
g_thread_exit(NULL);
|
2010-04-27 16:07:49 +02:00
|
|
|
return NULL;
|
2010-01-02 16:31:25 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* shortcut implementation */
|
2009-08-12 21:45:49 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
sc_abort(Argument* argument)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
/* Clear buffer */
|
|
|
|
if(Zathura.Global.buffer)
|
2009-10-30 00:16:43 +01:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
g_string_free(Zathura.Global.buffer, TRUE);
|
|
|
|
Zathura.Global.buffer = NULL;
|
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, "");
|
2009-10-30 00:16:43 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* Set back to normal mode */
|
|
|
|
change_mode(NORMAL);
|
2010-04-12 23:55:14 +02:00
|
|
|
switch_view(Zathura.UI.document);
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 15:55:32 +01:00
|
|
|
void
|
|
|
|
sc_adjust_window(Argument* argument)
|
|
|
|
{
|
2010-01-29 13:18:25 +01:00
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return;
|
|
|
|
|
2010-04-12 09:31:56 +02:00
|
|
|
Zathura.Global.adjust_mode = argument->n;
|
|
|
|
|
2010-01-28 14:06:27 +01:00
|
|
|
GtkAdjustment* adjustment;
|
|
|
|
double view_size;
|
|
|
|
double page_width;
|
|
|
|
double page_height;
|
2009-12-26 15:55:32 +01:00
|
|
|
|
2010-04-12 09:36:14 +02:00
|
|
|
if(argument->n == ADJUST_BESTFIT)
|
2010-01-28 14:06:27 +01:00
|
|
|
adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view);
|
2010-04-12 09:36:14 +02:00
|
|
|
else if(argument->n == ADJUST_WIDTH)
|
2010-01-28 14:06:27 +01:00
|
|
|
adjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view);
|
2010-04-12 09:31:56 +02:00
|
|
|
else
|
|
|
|
return;
|
2010-01-28 14:06:27 +01:00
|
|
|
|
|
|
|
view_size = gtk_adjustment_get_page_size(adjustment);
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-28 14:06:27 +01:00
|
|
|
poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-28 14:06:27 +01:00
|
|
|
|
|
|
|
if ((Zathura.PDF.rotate == 90) || (Zathura.PDF.rotate == 270))
|
|
|
|
{
|
|
|
|
double swap = page_width;
|
|
|
|
page_width = page_height;
|
|
|
|
page_height = swap;
|
|
|
|
}
|
|
|
|
|
2010-04-12 09:36:14 +02:00
|
|
|
if(argument->n == ADJUST_BESTFIT)
|
2010-01-28 14:06:27 +01:00
|
|
|
Zathura.PDF.scale = (view_size / page_height) * 100;
|
|
|
|
else
|
|
|
|
Zathura.PDF.scale = (view_size / page_width) * 100;
|
|
|
|
|
|
|
|
draw(Zathura.PDF.page_number);
|
2010-04-12 19:38:07 +02:00
|
|
|
update_status();
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2010-01-29 13:42:24 +01:00
|
|
|
void
|
|
|
|
sc_change_buffer(Argument* argument)
|
|
|
|
{
|
|
|
|
if(!Zathura.Global.buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int buffer_length = Zathura.Global.buffer->len;
|
|
|
|
|
|
|
|
if(argument->n == DELETE_LAST)
|
|
|
|
{
|
|
|
|
if((buffer_length - 1) == 0)
|
|
|
|
{
|
|
|
|
g_string_free(Zathura.Global.buffer, TRUE);
|
|
|
|
Zathura.Global.buffer = NULL;
|
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GString* temp = g_string_new_len(Zathura.Global.buffer->str, buffer_length - 1);
|
|
|
|
g_string_free(Zathura.Global.buffer, TRUE);
|
|
|
|
Zathura.Global.buffer = temp;
|
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, Zathura.Global.buffer->str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-12 21:45:49 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
sc_change_mode(Argument* argument)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(argument)
|
|
|
|
change_mode(argument->n);
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
sc_focus_inputbar(Argument* argument)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(argument->data)
|
|
|
|
{
|
|
|
|
notify(DEFAULT, argument->data);
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar));
|
|
|
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1);
|
|
|
|
}
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
|
2010-04-11 12:00:27 +02:00
|
|
|
void
|
|
|
|
sc_follow(Argument* argument)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number];
|
2010-04-11 12:53:45 +02:00
|
|
|
int number_of_links = 0, link_id = 1;
|
2010-04-11 12:00:27 +02:00
|
|
|
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
GList *link_list = poppler_page_get_link_mapping(current_page->page);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
link_list = g_list_reverse(link_list);
|
|
|
|
|
|
|
|
if((number_of_links = g_list_length(link_list)) <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GList *links;
|
|
|
|
for(links = link_list; links; links = g_list_next(links))
|
|
|
|
{
|
|
|
|
PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data;
|
|
|
|
PopplerRectangle* link_rectangle = &link_mapping->area;
|
2010-04-11 12:53:45 +02:00
|
|
|
PopplerAction *action = link_mapping->action;
|
2010-04-11 12:31:18 +02:00
|
|
|
|
2010-04-11 12:53:45 +02:00
|
|
|
/* only handle URI and internal links */
|
|
|
|
if(action->type == POPPLER_ACTION_URI || action->type == POPPLER_ACTION_GOTO_DEST)
|
|
|
|
{
|
|
|
|
highlight_result(Zathura.PDF.page_number, link_rectangle);
|
|
|
|
|
|
|
|
/* draw text */
|
2010-05-13 11:36:05 +02:00
|
|
|
recalcRectangle(Zathura.PDF.page_number, link_rectangle);
|
2010-04-11 12:53:45 +02:00
|
|
|
cairo_t *cairo = cairo_create(Zathura.PDF.surface);
|
|
|
|
cairo_select_font_face(cairo, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
|
|
|
|
cairo_set_font_size(cairo, 10);
|
|
|
|
cairo_move_to(cairo, link_rectangle->x1 + 1, link_rectangle->y1 - 1);
|
2010-05-25 20:16:12 +02:00
|
|
|
char* link_number = g_strdup_printf("%i", link_id++);
|
|
|
|
cairo_show_text(cairo, link_number);
|
|
|
|
g_free(link_number);
|
2010-04-11 12:53:45 +02:00
|
|
|
}
|
2010-04-11 12:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
|
|
|
poppler_page_free_link_mapping(link_list);
|
2010-04-11 12:31:18 +02:00
|
|
|
|
|
|
|
/* replace default inputbar handler */
|
|
|
|
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
|
|
|
|
Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_form_activate), NULL);
|
|
|
|
|
|
|
|
argument->data = "Follow hint: ";
|
|
|
|
sc_focus_inputbar(argument);
|
2010-04-11 12:00:27 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 15:55:32 +01:00
|
|
|
void
|
|
|
|
sc_navigate(Argument* argument)
|
|
|
|
{
|
2009-12-26 18:16:51 +01:00
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int number_of_pages = Zathura.PDF.number_of_pages;
|
|
|
|
int new_page = Zathura.PDF.page_number;
|
2009-12-26 15:55:32 +01:00
|
|
|
|
2009-12-26 18:16:51 +01:00
|
|
|
if(argument->n == NEXT)
|
|
|
|
new_page = (new_page + number_of_pages + 1) % number_of_pages;
|
2010-05-18 00:19:09 +02:00
|
|
|
else if(argument->n == PREVIOUS)
|
2009-12-26 18:16:51 +01:00
|
|
|
new_page = (new_page + number_of_pages - 1) % number_of_pages;
|
|
|
|
|
|
|
|
set_page(new_page);
|
|
|
|
update_status();
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2010-01-01 15:34:01 +01:00
|
|
|
void
|
2010-04-11 10:47:09 +02:00
|
|
|
sc_recolor(Argument* argument)
|
2010-01-01 15:34:01 +01:00
|
|
|
{
|
2010-04-11 10:47:09 +02:00
|
|
|
Zathura.Global.recolor = !Zathura.Global.recolor;
|
2010-01-20 23:46:13 +01:00
|
|
|
draw(Zathura.PDF.page_number);
|
2010-01-01 15:34:01 +01:00
|
|
|
}
|
|
|
|
|
2010-06-03 18:12:45 +02:00
|
|
|
void
|
|
|
|
sc_reload(Argument* argument)
|
|
|
|
{
|
2010-06-15 10:17:38 +02:00
|
|
|
draw(Zathura.PDF.page_number);
|
2010-06-15 09:39:22 +02:00
|
|
|
|
2010-06-21 16:27:38 +02:00
|
|
|
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view);
|
|
|
|
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view);
|
|
|
|
|
2010-06-03 18:12:45 +02:00
|
|
|
/* save old information */
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
char* path = Zathura.PDF.file ? strdup(Zathura.PDF.file) : NULL;
|
|
|
|
char* password = Zathura.PDF.password ? strdup(Zathura.PDF.password) : NULL;
|
|
|
|
int scale = Zathura.PDF.scale;
|
|
|
|
int page = Zathura.PDF.page_number;
|
|
|
|
int rotate = Zathura.PDF.rotate;
|
2010-06-21 16:27:38 +02:00
|
|
|
gdouble va = gtk_adjustment_get_value(vadjustment);
|
|
|
|
gdouble ha = gtk_adjustment_get_value(hadjustment);
|
2010-06-03 18:12:45 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
|
|
|
|
|
|
|
/* reopen and restore settings */
|
2010-06-15 10:17:38 +02:00
|
|
|
close_file(TRUE);
|
2010-06-03 18:12:45 +02:00
|
|
|
open_file(path, password);
|
|
|
|
|
2010-06-21 16:27:38 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
2010-06-03 18:12:45 +02:00
|
|
|
Zathura.PDF.scale = scale;
|
|
|
|
Zathura.PDF.rotate = rotate;
|
2010-06-21 16:27:38 +02:00
|
|
|
gtk_adjustment_set_value(vadjustment, va);
|
|
|
|
gtk_adjustment_set_value(hadjustment, ha);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
|
2010-06-03 18:12:45 +02:00
|
|
|
|
|
|
|
draw(page);
|
|
|
|
|
|
|
|
if(path)
|
|
|
|
free(path);
|
|
|
|
if(password)
|
|
|
|
free(password);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-26 15:55:32 +01:00
|
|
|
void
|
|
|
|
sc_rotate(Argument* argument)
|
|
|
|
{
|
2010-05-19 12:13:28 +02:00
|
|
|
Zathura.PDF.rotate = (Zathura.PDF.rotate + 90) % 360;
|
|
|
|
Zathura.Search.draw = TRUE;
|
2010-01-01 17:18:48 +01:00
|
|
|
|
2010-01-20 23:46:13 +01:00
|
|
|
draw(Zathura.PDF.page_number);
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_scroll(Argument* argument)
|
|
|
|
{
|
2009-12-30 00:21:29 +01:00
|
|
|
GtkAdjustment* adjustment;
|
2009-12-26 15:55:32 +01:00
|
|
|
|
2009-12-30 00:21:29 +01:00
|
|
|
if( (argument->n == LEFT) || (argument->n == RIGHT) )
|
|
|
|
adjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view);
|
|
|
|
else
|
|
|
|
adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view);
|
|
|
|
|
|
|
|
gdouble view_size = gtk_adjustment_get_page_size(adjustment);
|
|
|
|
gdouble value = gtk_adjustment_get_value(adjustment);
|
|
|
|
gdouble max = gtk_adjustment_get_upper(adjustment) - view_size;
|
|
|
|
|
2010-06-14 17:22:06 +02:00
|
|
|
if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0)
|
2010-06-13 16:39:46 +02:00
|
|
|
{
|
|
|
|
Argument arg;
|
|
|
|
arg.n = PREVIOUS;
|
|
|
|
sc_navigate(&arg);
|
|
|
|
arg.n = BOTTOM;
|
|
|
|
sc_scroll(&arg);
|
|
|
|
}
|
2010-06-14 17:22:06 +02:00
|
|
|
else if((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max)
|
2010-06-13 16:39:46 +02:00
|
|
|
{
|
|
|
|
Argument arg;
|
|
|
|
arg.n = NEXT;
|
|
|
|
sc_navigate(&arg);
|
|
|
|
}
|
2010-06-14 17:13:18 +02:00
|
|
|
else if(argument->n == FULL_UP)
|
|
|
|
gtk_adjustment_set_value(adjustment, (value - view_size) < 0 ? 0 : (value - view_size));
|
|
|
|
else if(argument->n == FULL_DOWN)
|
|
|
|
gtk_adjustment_set_value(adjustment, (value + view_size) > max ? max : (value + view_size));
|
|
|
|
else if(argument->n == HALF_UP)
|
|
|
|
gtk_adjustment_set_value(adjustment, (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)));
|
|
|
|
else if(argument->n == HALF_DOWN)
|
|
|
|
gtk_adjustment_set_value(adjustment, (value + (view_size / 2)) > max ? max : (value + (view_size / 2)));
|
2010-06-13 16:39:46 +02:00
|
|
|
else if((argument->n == LEFT) || (argument->n == UP))
|
2010-06-15 12:50:43 +02:00
|
|
|
gtk_adjustment_set_value(adjustment, (value - scroll_step) < 0 ? 0 : (value - scroll_step));
|
2010-06-13 16:39:46 +02:00
|
|
|
else if(argument->n == TOP)
|
2009-12-30 00:21:29 +01:00
|
|
|
gtk_adjustment_set_value(adjustment, 0);
|
|
|
|
else if(argument->n == BOTTOM)
|
|
|
|
gtk_adjustment_set_value(adjustment, max);
|
|
|
|
else
|
2010-06-15 12:50:43 +02:00
|
|
|
gtk_adjustment_set_value(adjustment, (value + scroll_step) > max ? max : (value + scroll_step));
|
2010-01-29 13:18:25 +01:00
|
|
|
|
|
|
|
update_status();
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_search(Argument* argument)
|
|
|
|
{
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.search_lock));
|
2010-01-21 01:46:53 +01:00
|
|
|
if(Zathura.Thread.search_thread_running)
|
|
|
|
{
|
|
|
|
Zathura.Thread.search_thread_running = FALSE;
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.search_lock));
|
|
|
|
gdk_threads_leave();
|
|
|
|
g_thread_join(Zathura.Thread.search_thread);
|
|
|
|
gdk_threads_enter();
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.search_lock));
|
2010-01-21 01:46:53 +01:00
|
|
|
}
|
2010-01-02 14:23:49 +01:00
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
Zathura.Thread.search_thread_running = TRUE;
|
|
|
|
Zathura.Thread.search_thread = g_thread_create(search, (gpointer) argument, TRUE, NULL);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.search_lock));
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2010-05-05 20:05:06 +02:00
|
|
|
void
|
|
|
|
sc_switch_goto_mode(Argument* argument)
|
|
|
|
{
|
|
|
|
switch(Zathura.Global.goto_mode)
|
|
|
|
{
|
|
|
|
case GOTO_LABELS:
|
|
|
|
Zathura.Global.goto_mode = GOTO_OFFSET;
|
|
|
|
break;
|
|
|
|
case GOTO_OFFSET:
|
|
|
|
Zathura.Global.goto_mode = GOTO_DEFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
2010-05-06 20:31:53 +02:00
|
|
|
if(Zathura.Global.enable_labelmode)
|
|
|
|
Zathura.Global.goto_mode = GOTO_LABELS;
|
|
|
|
else
|
|
|
|
Zathura.Global.goto_mode = GOTO_OFFSET;
|
2010-05-05 20:05:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_status();
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:07:49 +02:00
|
|
|
gboolean cb_index_row_activated(GtkTreeView* treeview, GtkTreePath* path,
|
|
|
|
GtkTreeViewColumn* column, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_object_get(treeview, "model", &model, NULL);
|
|
|
|
|
|
|
|
if(gtk_tree_model_get_iter(model, &iter, path))
|
|
|
|
{
|
|
|
|
PopplerAction* action;
|
|
|
|
PopplerDest* destination;
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, &iter, 1, &action, -1);
|
|
|
|
if(!action)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if(action->type == POPPLER_ACTION_GOTO_DEST)
|
|
|
|
{
|
|
|
|
destination = action->goto_dest.dest;
|
|
|
|
int page_number = destination->page_num;
|
|
|
|
|
|
|
|
if(action->goto_dest.dest->type == POPPLER_DEST_NAMED)
|
|
|
|
{
|
|
|
|
PopplerDest* d = poppler_document_find_dest(Zathura.PDF.document, action->goto_dest.dest->named_dest);
|
|
|
|
if(d)
|
|
|
|
{
|
|
|
|
page_number = d->page_num;
|
|
|
|
poppler_dest_free(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_page(page_number - 1);
|
|
|
|
update_status();
|
2010-06-03 17:11:33 +02:00
|
|
|
Zathura.Global.show_index = FALSE;
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.document));
|
2010-04-27 16:07:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Zathura.Global.mode = NORMAL;
|
|
|
|
g_object_unref(model);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_navigate_index(Argument* argument)
|
|
|
|
{
|
|
|
|
GtkTreeView *treeview = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.index))->data;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
gtk_tree_view_get_cursor(treeview, &path, NULL);
|
|
|
|
if(!path)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
gboolean is_valid_path = TRUE;
|
|
|
|
|
|
|
|
switch(argument->n)
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
if(!gtk_tree_path_prev(path))
|
|
|
|
is_valid_path = gtk_tree_path_up(path);
|
|
|
|
else /* row above */
|
|
|
|
{
|
|
|
|
while(gtk_tree_view_row_expanded(treeview, path)) {
|
|
|
|
gtk_tree_model_get_iter(model, &iter, path);
|
|
|
|
/* select last child */
|
|
|
|
gtk_tree_model_iter_nth_child(model, &child_iter, &iter,
|
|
|
|
gtk_tree_model_iter_n_children(model, &iter)-1);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
path = gtk_tree_model_get_path(model, &child_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case COLLAPSE:
|
|
|
|
if(!gtk_tree_view_collapse_row(treeview, path)
|
|
|
|
&& gtk_tree_path_get_depth(path) > 1)
|
|
|
|
{
|
|
|
|
gtk_tree_path_up(path);
|
|
|
|
gtk_tree_view_collapse_row(treeview, path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DOWN:
|
|
|
|
if(gtk_tree_view_row_expanded(treeview, path))
|
|
|
|
gtk_tree_path_down(path);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_tree_model_get_iter(model, &iter, path);
|
|
|
|
if (gtk_tree_model_iter_next(model, &iter))
|
|
|
|
{
|
|
|
|
path = gtk_tree_model_get_path(model, &iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while((is_valid_path = (gtk_tree_path_get_depth(path) > 1))
|
|
|
|
&& gtk_tree_path_up(path));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPAND:
|
|
|
|
if(gtk_tree_view_expand_row(treeview, path, FALSE))
|
|
|
|
gtk_tree_path_down(path);
|
|
|
|
break;
|
|
|
|
case SELECT:
|
|
|
|
cb_index_row_activated(treeview, path, NULL, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_valid_path)
|
|
|
|
gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
|
|
|
|
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:52:45 +01:00
|
|
|
void
|
|
|
|
sc_toggle_index(Argument* argument)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return;
|
|
|
|
|
2010-04-11 20:56:16 +02:00
|
|
|
GtkWidget *treeview;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
PopplerIndexIter *iter;
|
|
|
|
|
2010-01-01 22:52:45 +01:00
|
|
|
if(!Zathura.UI.index)
|
|
|
|
{
|
2010-04-11 20:56:16 +02:00
|
|
|
Zathura.UI.index = gtk_scrolled_window_new (NULL, NULL);
|
2010-01-01 22:52:45 +01:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index),
|
2010-04-11 20:56:16 +02:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2010-01-01 22:52:45 +01:00
|
|
|
|
2010-04-11 20:56:16 +02:00
|
|
|
if((iter = poppler_index_iter_new(Zathura.PDF.document)))
|
2010-01-01 22:52:45 +01:00
|
|
|
{
|
|
|
|
model = GTK_TREE_MODEL(gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER));
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-04-11 20:56:16 +02:00
|
|
|
build_index(model, NULL, iter);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-04-11 20:56:16 +02:00
|
|
|
poppler_index_iter_free(iter);
|
2010-01-01 22:52:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARNING, "This document does not contain any index");
|
|
|
|
Zathura.UI.index = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-11 20:56:16 +02:00
|
|
|
treeview = gtk_tree_view_new_with_model (model);
|
|
|
|
g_object_unref(model);
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title",
|
|
|
|
renderer, "markup", 0, NULL);
|
|
|
|
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
|
|
|
|
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
|
|
|
|
|
2010-04-27 16:07:49 +02:00
|
|
|
gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE);
|
|
|
|
g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL);
|
2010-04-11 20:56:16 +02:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (Zathura.UI.index), treeview);
|
|
|
|
gtk_widget_show (treeview);
|
2010-01-01 22:52:45 +01:00
|
|
|
gtk_widget_show(Zathura.UI.index);
|
|
|
|
}
|
2010-04-11 20:56:16 +02:00
|
|
|
|
2010-06-03 17:11:33 +02:00
|
|
|
if(!Zathura.Global.show_index)
|
2010-04-27 16:07:49 +02:00
|
|
|
{
|
2010-04-11 20:56:16 +02:00
|
|
|
switch_view(Zathura.UI.index);
|
2010-04-27 16:07:49 +02:00
|
|
|
Zathura.Global.mode = INDEX;
|
|
|
|
}
|
2010-01-01 22:52:45 +01:00
|
|
|
else
|
2010-04-27 16:07:49 +02:00
|
|
|
{
|
2010-06-03 17:11:33 +02:00
|
|
|
switch_view(Zathura.UI.document);
|
2010-04-27 16:07:49 +02:00
|
|
|
Zathura.Global.mode = NORMAL;
|
|
|
|
}
|
2010-01-01 22:52:45 +01:00
|
|
|
|
2010-06-03 17:11:33 +02:00
|
|
|
Zathura.Global.show_index = !Zathura.Global.show_index;
|
2010-01-01 22:52:45 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 15:55:32 +01:00
|
|
|
void
|
|
|
|
sc_toggle_inputbar(Argument* argument)
|
|
|
|
{
|
2009-12-26 16:05:03 +01:00
|
|
|
if(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.inputbar)))
|
|
|
|
gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar));
|
|
|
|
else
|
|
|
|
gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar));
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2010-05-24 09:38:54 +02:00
|
|
|
void
|
|
|
|
sc_toggle_fullscreen(Argument* argument)
|
|
|
|
{
|
|
|
|
static gboolean fs = TRUE;
|
|
|
|
|
|
|
|
if(fs)
|
|
|
|
{
|
|
|
|
gtk_window_fullscreen(GTK_WINDOW(Zathura.UI.window));
|
|
|
|
gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar));
|
|
|
|
gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar));
|
|
|
|
|
2010-05-24 11:41:08 +02:00
|
|
|
Argument arg;
|
|
|
|
arg.n = ADJUST_BESTFIT;
|
|
|
|
sc_adjust_window(&arg);
|
|
|
|
|
|
|
|
Zathura.Global.mode = FULLSCREEN;
|
2010-05-24 09:38:54 +02:00
|
|
|
fs = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(Zathura.UI.window));
|
|
|
|
gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar));
|
|
|
|
gtk_widget_show(GTK_WIDGET(Zathura.UI.statusbar));
|
|
|
|
|
2010-05-24 11:41:08 +02:00
|
|
|
Zathura.Global.mode = NORMAL;
|
2010-05-24 09:38:54 +02:00
|
|
|
fs = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-26 15:55:32 +01:00
|
|
|
void
|
|
|
|
sc_toggle_statusbar(Argument* argument)
|
|
|
|
{
|
2009-12-26 16:05:03 +01:00
|
|
|
if(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.statusbar)))
|
|
|
|
gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar));
|
|
|
|
else
|
|
|
|
gtk_widget_show(GTK_WIDGET(Zathura.UI.statusbar));
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2009-08-12 21:45:49 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
sc_quit(Argument* argument)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
cb_destroy(NULL, NULL);
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
|
2010-06-18 11:03:11 +02:00
|
|
|
void
|
|
|
|
sc_zoom(Argument* argument)
|
|
|
|
{
|
|
|
|
bcmd_zoom(NULL, argument);
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* inputbar shortcut declarations */
|
2009-08-12 21:45:49 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
isc_abort(Argument* argument)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
Argument arg = { HIDE };
|
|
|
|
isc_completion(&arg);
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
notify(DEFAULT, "");
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view));
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
|
2009-08-13 22:55:36 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
isc_command_history(Argument* argument)
|
2009-08-13 22:55:36 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
static int current = 0;
|
|
|
|
int length = g_list_length(Zathura.Global.history);
|
2009-08-13 22:55:36 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(length > 0)
|
2009-08-13 22:55:36 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(argument->n == NEXT)
|
|
|
|
current = (length + current + 1) % length;
|
|
|
|
else
|
|
|
|
current = (length + current - 1) % length;
|
2009-09-12 11:19:51 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gchar* command = (gchar*) g_list_nth_data(Zathura.Global.history, current);
|
|
|
|
notify(DEFAULT, command);
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar));
|
|
|
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1);
|
2009-08-13 22:55:36 +02:00
|
|
|
}
|
2009-09-19 10:43:41 +02:00
|
|
|
}
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
isc_completion(Argument* argument)
|
2009-09-20 16:25:56 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 1, -1);
|
|
|
|
gchar identifier = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, 1)[0];
|
|
|
|
int length = strlen(input);
|
2010-05-18 00:19:09 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(!length && !identifier)
|
2009-09-20 16:25:56 +02:00
|
|
|
return;
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* get current information*/
|
|
|
|
char* first_space = strstr(input, " ");
|
|
|
|
char* current_command;
|
|
|
|
char* current_parameter;
|
|
|
|
int current_command_length;
|
|
|
|
int current_parameter_length;
|
2009-09-20 16:25:56 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(!first_space)
|
2009-09-20 16:25:56 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
current_command = input;
|
|
|
|
current_command_length = length;
|
|
|
|
current_parameter = NULL;
|
|
|
|
current_parameter_length = 0;
|
2009-09-20 16:25:56 +02:00
|
|
|
}
|
|
|
|
else
|
2009-09-19 10:43:41 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
int offset = abs(input - first_space);
|
|
|
|
current_command = g_strndup(input, offset);
|
|
|
|
current_command_length = strlen(current_command);
|
|
|
|
current_parameter = input + offset + 1;
|
|
|
|
current_parameter_length = strlen(current_parameter);
|
2009-09-19 10:43:41 +02:00
|
|
|
}
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* if the identifier does not match the command sign and
|
|
|
|
* the completion should not be hidden, leave this function */
|
|
|
|
if((identifier != ':') && (argument->n != HIDE))
|
2009-08-13 22:55:36 +02:00
|
|
|
return;
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* static elements */
|
|
|
|
static GtkBox *results = NULL;
|
|
|
|
static CompletionRow *rows = NULL;
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
static int current_item = 0;
|
|
|
|
static int n_items = 0;
|
2009-09-20 16:25:56 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
static char *previous_command = NULL;
|
|
|
|
static char *previous_parameter = NULL;
|
|
|
|
static int previous_id = 0;
|
|
|
|
static int previous_length = 0;
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
static gboolean command_mode = TRUE;
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* delete old list iff
|
|
|
|
* the completion should be hidden
|
|
|
|
* the current command differs from the previous one
|
|
|
|
* the current parameter differs from the previous one
|
|
|
|
*/
|
|
|
|
if( (argument->n == HIDE) ||
|
|
|
|
(current_parameter && previous_parameter && strcmp(current_parameter, previous_parameter)) ||
|
|
|
|
(current_command && previous_command && strcmp(current_command, previous_command)) ||
|
|
|
|
(previous_length != length)
|
|
|
|
)
|
2009-09-19 10:43:41 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(results)
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(results));
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
results = NULL;
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(rows)
|
|
|
|
free(rows);
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
rows = NULL;
|
|
|
|
current_item = 0;
|
|
|
|
n_items = 0;
|
|
|
|
command_mode = TRUE;
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(argument->n == HIDE)
|
2009-08-29 16:07:58 +02:00
|
|
|
return;
|
2009-08-15 12:35:07 +02:00
|
|
|
}
|
2009-08-29 16:07:58 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* create new list iff
|
|
|
|
* there is no current list
|
|
|
|
* the current command differs from the previous one
|
|
|
|
* the current parameter differs from the previous one
|
|
|
|
*/
|
|
|
|
if( (!results) )
|
2009-08-15 12:35:07 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
results = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* create list based on parameters iff
|
|
|
|
* there is a current parameter given
|
|
|
|
* there is an old list with commands
|
|
|
|
* the current command does not differ from the previous one
|
|
|
|
* the current command has an completion function
|
|
|
|
*/
|
|
|
|
if( (previous_command) && (current_parameter) && !strcmp(current_command, previous_command) )
|
|
|
|
{
|
|
|
|
if(previous_id < 0 || !commands[previous_id].completion)
|
|
|
|
return;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
Completion *result = commands[previous_id].completion(current_parameter);
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-28 00:44:35 +01:00
|
|
|
if(!result || !result->groups)
|
2009-12-26 14:30:50 +01:00
|
|
|
return;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-28 00:44:35 +01:00
|
|
|
command_mode = FALSE;
|
|
|
|
CompletionGroup* group = NULL;
|
|
|
|
CompletionElement* element = NULL;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
rows = malloc(sizeof(CompletionRow));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!rows)
|
|
|
|
out_of_memory();
|
2009-12-26 14:30:50 +01:00
|
|
|
|
|
|
|
for(group = result->groups; group != NULL; group = group->next)
|
2009-09-10 23:46:40 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
int group_elements = 0;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
for(element = group->elements; element != NULL; element = element->next)
|
|
|
|
{
|
|
|
|
if( (element->value) &&
|
|
|
|
(current_parameter_length <= strlen(element->value)) && !strncmp(current_parameter, element->value, current_parameter_length)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
rows = realloc(rows, (n_items + 1) * sizeof(CompletionRow));
|
|
|
|
rows[n_items].command = element->value;
|
|
|
|
rows[n_items].description = element->description;
|
|
|
|
rows[n_items].command_id = previous_id;
|
|
|
|
rows[n_items].is_group = FALSE;
|
|
|
|
rows[n_items++].row = GTK_WIDGET(createCompletionRow(results, element->value, element->description, FALSE));
|
|
|
|
group_elements++;
|
|
|
|
}
|
|
|
|
}
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(group->value && group_elements > 0)
|
|
|
|
{
|
|
|
|
rows = realloc(rows, (n_items + 1) * sizeof(CompletionRow));
|
|
|
|
rows[n_items].command = group->value;
|
|
|
|
rows[n_items].description = NULL;
|
|
|
|
rows[n_items].command_id = -1;
|
|
|
|
rows[n_items].is_group = TRUE;
|
|
|
|
rows[n_items].row = GTK_WIDGET(createCompletionRow(results, group->value, NULL, TRUE));
|
|
|
|
|
|
|
|
/* Swap group element with first element of the list */
|
|
|
|
CompletionRow temp = rows[n_items - group_elements];
|
|
|
|
gtk_box_reorder_child(results, rows[n_items].row, n_items - group_elements);
|
|
|
|
rows[n_items - group_elements] = rows[n_items];
|
|
|
|
rows[n_items] = temp;
|
|
|
|
|
|
|
|
n_items++;
|
|
|
|
}
|
2009-09-10 23:46:40 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* clean up */
|
|
|
|
group = result->groups;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
while(group)
|
|
|
|
{
|
|
|
|
element = group->elements;
|
|
|
|
while(element)
|
|
|
|
{
|
|
|
|
CompletionElement* ne = element->next;
|
|
|
|
free(element);
|
|
|
|
element = ne;
|
|
|
|
}
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
CompletionGroup *ng = group->next;
|
|
|
|
free(group);
|
|
|
|
group = ng;
|
|
|
|
}
|
2009-09-10 23:46:40 +02:00
|
|
|
}
|
2009-12-26 14:30:50 +01:00
|
|
|
/* create list based on commands */
|
|
|
|
else
|
2009-09-10 23:46:40 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
int i = 0;
|
|
|
|
command_mode = TRUE;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
rows = malloc(LENGTH(commands) * sizeof(CompletionRow));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!rows)
|
|
|
|
out_of_memory();
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
for(i = 0; i < LENGTH(commands); i++)
|
|
|
|
{
|
2010-01-31 21:07:27 +01:00
|
|
|
int abbr_length = commands[i].abbr ? strlen(commands[i].abbr) : 0;
|
|
|
|
int cmd_length = commands[i].command ? strlen(commands[i].command) : 0;
|
2009-12-26 14:30:50 +01:00
|
|
|
|
|
|
|
/* add command to list iff
|
|
|
|
* the current command would match the command
|
|
|
|
* the current command would match the abbreviation
|
|
|
|
*/
|
|
|
|
if( ((current_command_length <= cmd_length) && !strncmp(current_command, commands[i].command, current_command_length)) ||
|
|
|
|
((current_command_length <= abbr_length) && !strncmp(current_command, commands[i].abbr, current_command_length))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
rows[n_items].command = commands[i].command;
|
|
|
|
rows[n_items].description = commands[i].description;
|
|
|
|
rows[n_items].command_id = i;
|
|
|
|
rows[n_items].is_group = FALSE;
|
|
|
|
rows[n_items++].row = GTK_WIDGET(createCompletionRow(results, commands[i].command, commands[i].description, FALSE));
|
|
|
|
}
|
|
|
|
}
|
2009-08-13 22:55:36 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
rows = realloc(rows, n_items * sizeof(CompletionRow));
|
|
|
|
}
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(results), FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window));
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
current_item = (argument->n == NEXT) ? -1 : 0;
|
|
|
|
}
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* update coloring iff
|
|
|
|
* there is a list with items
|
|
|
|
*/
|
|
|
|
if( (results) && (n_items > 0) )
|
|
|
|
{
|
|
|
|
setCompletionRowColor(results, NORMAL, current_item);
|
|
|
|
char* temp;
|
|
|
|
int i = 0, next_group = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < n_items; i++)
|
|
|
|
{
|
|
|
|
if(argument->n == NEXT || argument->n == NEXT_GROUP)
|
|
|
|
current_item = (current_item + n_items + 1) % n_items;
|
|
|
|
else if(argument->n == PREVIOUS || argument->n == PREVIOUS_GROUP)
|
|
|
|
current_item = (current_item + n_items - 1) % n_items;
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(rows[current_item].is_group)
|
|
|
|
{
|
|
|
|
if(!command_mode && (argument->n == NEXT_GROUP || argument->n == PREVIOUS_GROUP))
|
|
|
|
next_group = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!command_mode && (next_group == 0) && (argument->n == NEXT_GROUP || argument->n == PREVIOUS_GROUP))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
setCompletionRowColor(results, HIGHLIGHT, current_item);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
if(command_mode)
|
2009-08-15 12:35:07 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
char* cp = (current_parameter) ? g_strconcat(" ", current_parameter, NULL) : 0;
|
|
|
|
temp = g_strconcat(":", rows[current_item].command, cp, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp = g_strconcat(":", previous_command, " ", rows[current_item].command, NULL);
|
2009-08-15 12:35:07 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_entry_set_text(Zathura.UI.inputbar, temp);
|
|
|
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1);
|
|
|
|
g_free(temp);
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
previous_command = (command_mode) ? rows[current_item].command : current_command;
|
|
|
|
previous_parameter = (command_mode) ? current_parameter : rows[current_item].command;
|
|
|
|
previous_length = strlen(previous_command) + ((command_mode) ? (length - current_command_length) : (strlen(previous_parameter) + 1));
|
|
|
|
previous_id = rows[current_item].command_id;
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-10 23:46:40 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
isc_string_manipulation(Argument* argument)
|
2009-09-10 23:46:40 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(argument->n == DELETE_LAST_WORD)
|
|
|
|
{
|
|
|
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, -1);
|
|
|
|
int length = strlen(input);
|
|
|
|
int i = 0;
|
2009-09-10 23:46:40 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
for(i = length; i > 0; i--)
|
|
|
|
{
|
|
|
|
if( (input[i] == ' ') ||
|
|
|
|
(input[i] == '/') )
|
|
|
|
{
|
|
|
|
if(i == (length - 1))
|
|
|
|
continue;
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
i = (input[i] == ' ') ? (i - 1) : i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-12 21:45:49 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
notify(DEFAULT, g_strndup(input, i + 1));
|
|
|
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1);
|
|
|
|
}
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* command implementation */
|
2010-01-31 21:07:27 +01:00
|
|
|
gboolean
|
|
|
|
cmd_bookmark(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document || argc < 1)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* get id */
|
|
|
|
int i;
|
|
|
|
GString *id = g_string_new("");
|
|
|
|
|
|
|
|
for(i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if(i != 0)
|
|
|
|
id = g_string_append_c(id, ' ');
|
|
|
|
|
|
|
|
id = g_string_append(id, argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for existing bookmark to overwrite */
|
|
|
|
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
|
|
|
{
|
|
|
|
if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id))
|
|
|
|
{
|
|
|
|
Zathura.Bookmarks.bookmarks[i].page = Zathura.PDF.page_number;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new bookmark */
|
2010-05-18 00:19:09 +02:00
|
|
|
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
|
|
|
|
(Zathura.Bookmarks.number_of_bookmarks + 1) * sizeof(Bookmark));
|
2010-01-31 21:07:27 +01:00
|
|
|
|
|
|
|
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].id = id->str;
|
|
|
|
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].page = Zathura.PDF.page_number;
|
|
|
|
Zathura.Bookmarks.number_of_bookmarks++;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cmd_open_bookmark(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document || argc < 1)
|
|
|
|
return TRUE;
|
2010-05-18 00:19:09 +02:00
|
|
|
|
2010-01-31 21:07:27 +01:00
|
|
|
/* get id */
|
|
|
|
int i;
|
|
|
|
GString *id = g_string_new("");
|
|
|
|
|
|
|
|
for(i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if(i != 0)
|
|
|
|
id = g_string_append_c(id, ' ');
|
|
|
|
|
|
|
|
id = g_string_append(id, argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find bookmark */
|
|
|
|
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
|
|
|
{
|
|
|
|
if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id))
|
|
|
|
{
|
|
|
|
set_page(Zathura.Bookmarks.bookmarks[i].page);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notify(WARNING, "No matching bookmark found");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-01 20:46:07 +01:00
|
|
|
gboolean
|
|
|
|
cmd_close(int argc, char** argv)
|
|
|
|
{
|
2010-06-15 10:17:38 +02:00
|
|
|
close_file(FALSE);
|
2010-01-01 20:46:07 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-05 20:05:06 +02:00
|
|
|
gboolean
|
|
|
|
cmd_correct_offset(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document || argc == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
Zathura.PDF.page_offset = (Zathura.PDF.page_number + 1) - atoi(argv[0]);
|
|
|
|
|
|
|
|
if(Zathura.PDF.page_offset != 0)
|
|
|
|
Zathura.Global.goto_mode = GOTO_OFFSET;
|
|
|
|
else
|
|
|
|
Zathura.Global.goto_mode = GOTO_MODE;
|
|
|
|
|
|
|
|
update_status();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-31 21:24:33 +01:00
|
|
|
gboolean
|
|
|
|
cmd_delete_bookmark(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document || argc < 1)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* get id */
|
|
|
|
int i;
|
|
|
|
GString *id = g_string_new("");
|
|
|
|
|
|
|
|
for(i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if(i != 0)
|
|
|
|
id = g_string_append_c(id, ' ');
|
|
|
|
|
|
|
|
id = g_string_append(id, argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for bookmark to delete */
|
|
|
|
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
|
|
|
{
|
|
|
|
if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id))
|
|
|
|
{
|
|
|
|
/* update key file */
|
|
|
|
g_key_file_remove_key(Zathura.Bookmarks.data, Zathura.PDF.file, Zathura.Bookmarks.bookmarks[i].id, NULL);
|
|
|
|
|
|
|
|
/* update bookmarks */
|
|
|
|
Zathura.Bookmarks.bookmarks[i].id = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].id;
|
|
|
|
Zathura.Bookmarks.bookmarks[i].page = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].page;
|
|
|
|
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
|
|
|
|
Zathura.Bookmarks.number_of_bookmarks * sizeof(Bookmark));
|
|
|
|
|
|
|
|
Zathura.Bookmarks.number_of_bookmarks--;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-03 16:25:51 +01:00
|
|
|
gboolean
|
|
|
|
cmd_export(int argc, char** argv)
|
|
|
|
{
|
2010-01-03 16:49:50 +01:00
|
|
|
if(argc == 0 || !Zathura.PDF.document)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if(argc < 2)
|
|
|
|
{
|
|
|
|
notify(WARNING, "No export path specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* export images */
|
|
|
|
if(!strcmp(argv[0], "images"))
|
|
|
|
{
|
|
|
|
int page_number;
|
|
|
|
for(page_number = 0; page_number < Zathura.PDF.number_of_pages; page_number++)
|
|
|
|
{
|
|
|
|
GList *image_list;
|
|
|
|
GList *images;
|
|
|
|
cairo_surface_t *image;
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
image_list = poppler_page_get_image_mapping(Zathura.PDF.pages[page_number]->page);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
|
|
|
|
if(!g_list_length(image_list))
|
|
|
|
{
|
|
|
|
notify(WARNING, "This document does not contain any images");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(images = image_list; images; images = g_list_next(images))
|
|
|
|
{
|
|
|
|
PopplerImageMapping *image_mapping;
|
|
|
|
PopplerRectangle image_field;
|
|
|
|
gint image_id;
|
|
|
|
char* file;
|
|
|
|
char* filename;
|
|
|
|
|
|
|
|
image_mapping = (PopplerImageMapping*) images->data;
|
|
|
|
image_field = image_mapping->area;
|
|
|
|
image_id = image_mapping->image_id;
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
image = poppler_page_get_image(Zathura.PDF.pages[page_number]->page, image_id);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
|
|
|
|
if(!image)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
filename = g_strdup_printf("%s_p%i_i%i.png", Zathura.PDF.file, page_number + 1, image_id);
|
|
|
|
|
|
|
|
if(argv[1][0] == '~')
|
|
|
|
{
|
2010-05-18 00:19:09 +02:00
|
|
|
file = malloc(((int) strlen(filename) + (int) strlen(argv[1])
|
2010-01-03 16:49:50 +01:00
|
|
|
+ (int) strlen(getenv("HOME")) - 1) * sizeof(char));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!file)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-03 16:49:50 +01:00
|
|
|
file = g_strdup_printf("%s%s%s", getenv("HOME"), argv[1] + 1, filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file = g_strdup_printf("%s%s", argv[1], filename);
|
|
|
|
|
|
|
|
cairo_surface_write_to_png(image, file);
|
|
|
|
|
|
|
|
g_free(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!strcmp(argv[0], "attachments"))
|
|
|
|
{
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
if(!poppler_document_has_attachments(Zathura.PDF.document))
|
|
|
|
{
|
|
|
|
notify(WARNING, "PDF file has no attachments");
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *attachment_list = poppler_document_get_attachments(Zathura.PDF.document);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
|
2010-01-03 16:49:50 +01:00
|
|
|
GList *attachments;
|
|
|
|
char *file;
|
|
|
|
|
|
|
|
for(attachments = attachment_list; attachments; attachments = g_list_next(attachments))
|
|
|
|
{
|
|
|
|
PopplerAttachment *attachment = (PopplerAttachment*) attachments->data;
|
|
|
|
|
|
|
|
if(argv[1][0] == '~')
|
|
|
|
{
|
|
|
|
file = malloc(((int) strlen(attachment->name) + (int) strlen(argv[1])
|
|
|
|
+ (int) strlen(getenv("HOME")) - 1) * sizeof(char));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!file)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-03 16:49:50 +01:00
|
|
|
file = g_strdup_printf("%s%s%s", getenv("HOME"), argv[1] + 1, attachment->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file = g_strdup_printf("%s%s", argv[1], attachment->name);
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
poppler_attachment_save(attachment, file, NULL);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-01-03 16:49:50 +01:00
|
|
|
|
|
|
|
g_free(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-03 16:25:51 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-02 02:04:43 +01:00
|
|
|
gboolean
|
|
|
|
cmd_info(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return TRUE;
|
|
|
|
|
2010-04-11 11:18:33 +02:00
|
|
|
static gboolean visible = FALSE;
|
|
|
|
|
2010-01-02 02:04:43 +01:00
|
|
|
if(!Zathura.UI.information)
|
|
|
|
{
|
|
|
|
GtkListStore *list;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
|
|
|
|
|
|
|
|
/* read document information */
|
|
|
|
gchar *title, *author;
|
|
|
|
gchar *subject, *keywords;
|
|
|
|
gchar *creator, *producer;
|
|
|
|
GTime creation_date, modification_date;
|
|
|
|
|
|
|
|
g_object_get(Zathura.PDF.document,
|
|
|
|
"title", &title,
|
|
|
|
"author", &author,
|
|
|
|
"subject", &subject,
|
|
|
|
"keywords", &keywords,
|
|
|
|
"creator", &creator,
|
|
|
|
"producer", &producer,
|
|
|
|
"creation-date", &creation_date,
|
|
|
|
"mod-date", &modification_date,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* append information to list */
|
|
|
|
gtk_list_store_append(list, &iter);
|
|
|
|
gtk_list_store_set(list, &iter, 0, "Author", 1, author ? author : "", -1);
|
|
|
|
gtk_list_store_append(list, &iter);
|
|
|
|
gtk_list_store_set(list, &iter, 0, "Title", 1, title ? title : "", -1);
|
|
|
|
gtk_list_store_append(list, &iter);
|
|
|
|
gtk_list_store_set(list, &iter, 0, "Subject", 1, subject ? subject : "", -1);
|
|
|
|
gtk_list_store_append(list, &iter);
|
|
|
|
gtk_list_store_set(list, &iter, 0, "Keywords", 1, keywords ? keywords : "", -1);
|
|
|
|
gtk_list_store_append(list, &iter);
|
|
|
|
gtk_list_store_set(list, &iter, 0, "Creator", 1, creator ? creator : "", -1);
|
|
|
|
gtk_list_store_append(list, &iter);
|
|
|
|
gtk_list_store_set(list, &iter, 0, "Producer", 1, producer ? producer : "", -1);
|
|
|
|
|
|
|
|
Zathura.UI.information = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list));
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(Zathura.UI.information), -1,
|
|
|
|
"Name", renderer, "text", 0, NULL);
|
|
|
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(Zathura.UI.information), -1,
|
|
|
|
"Value", renderer, "text", 1, NULL);
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(Zathura.UI.information));
|
|
|
|
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
|
|
|
|
|
|
|
|
gtk_widget_show_all(Zathura.UI.information);
|
|
|
|
}
|
|
|
|
|
2010-04-11 11:18:33 +02:00
|
|
|
if(!visible)
|
2010-01-02 02:04:43 +01:00
|
|
|
switch_view(Zathura.UI.information);
|
|
|
|
else
|
2010-04-12 23:55:14 +02:00
|
|
|
switch_view(Zathura.UI.document);
|
2010-04-11 11:18:33 +02:00
|
|
|
|
|
|
|
visible = !visible;
|
2010-01-02 02:04:43 +01:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-16 21:50:28 +02:00
|
|
|
gboolean
|
|
|
|
cmd_map(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if(argc < 2)
|
2010-06-16 23:13:25 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2010-06-17 00:12:21 +02:00
|
|
|
char* ks = argv[0];
|
|
|
|
|
2010-06-16 23:13:25 +02:00
|
|
|
/* search for the right shortcut function */
|
|
|
|
int sc_id = -1;
|
|
|
|
|
|
|
|
int sc_c;
|
|
|
|
for(sc_c = 0; sc_c < LENGTH(shortcut_names); sc_c++)
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[1], shortcut_names[sc_c].name))
|
|
|
|
{
|
|
|
|
sc_id = sc_c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sc_id == -1)
|
|
|
|
{
|
|
|
|
notify(WARNING, "No such shortcut function exists");
|
2010-06-16 21:50:28 +02:00
|
|
|
return FALSE;
|
2010-06-16 23:13:25 +02:00
|
|
|
}
|
|
|
|
|
2010-06-17 00:12:21 +02:00
|
|
|
/* parse modifier and key */
|
|
|
|
int mask = 0;
|
|
|
|
int key = 0;
|
2010-06-18 12:58:20 +02:00
|
|
|
int keyl = strlen(ks);
|
2010-06-17 00:12:21 +02:00
|
|
|
int mode = NORMAL;
|
|
|
|
|
|
|
|
// single key (e.g.: g)
|
2010-06-18 12:58:20 +02:00
|
|
|
if(keyl == 1)
|
2010-06-17 00:12:21 +02:00
|
|
|
key = ks[0];
|
|
|
|
|
|
|
|
// modifier and key (e.g.: <S-g>
|
2010-06-18 12:58:20 +02:00
|
|
|
// special key or modifier and key/special key (e.g.: <S-g>, <Space>)
|
|
|
|
|
|
|
|
else if(keyl >= 3 && ks[0] == '<' && ks[keyl-1] == '>')
|
2010-06-17 00:12:21 +02:00
|
|
|
{
|
2010-06-18 12:58:20 +02:00
|
|
|
char* specialkey = NULL;
|
|
|
|
|
|
|
|
/* check for modifier */
|
|
|
|
if(keyl >= 5 && ks[2] == '-')
|
2010-06-17 00:12:21 +02:00
|
|
|
{
|
2010-06-18 12:58:20 +02:00
|
|
|
/* evaluate modifier */
|
|
|
|
switch(ks[1])
|
|
|
|
{
|
|
|
|
case 'S':
|
|
|
|
mask = GDK_SHIFT_MASK;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
mask = GDK_CONTROL_MASK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no valid modifier */
|
|
|
|
if(!mask)
|
|
|
|
{
|
|
|
|
notify(WARNING, "No valid modifier given.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-17 00:12:21 +02:00
|
|
|
|
2010-06-18 12:58:20 +02:00
|
|
|
/* modifier and special key */
|
|
|
|
if(keyl > 5)
|
|
|
|
specialkey = g_strndup(ks + 3, keyl - 4);
|
|
|
|
else
|
|
|
|
key = ks[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
specialkey = ks;
|
2010-06-17 00:12:21 +02:00
|
|
|
|
2010-06-18 12:58:20 +02:00
|
|
|
/* search special key */
|
|
|
|
int g_c;
|
|
|
|
for(g_c = 0; specialkey && g_c < LENGTH(gdk_keys); g_c++)
|
2010-06-17 00:12:21 +02:00
|
|
|
{
|
2010-06-18 12:58:20 +02:00
|
|
|
if(!strcmp(specialkey, gdk_keys[g_c].identifier))
|
|
|
|
{
|
|
|
|
key = gdk_keys[g_c].key;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-17 00:12:21 +02:00
|
|
|
}
|
2010-06-18 12:58:20 +02:00
|
|
|
|
|
|
|
if(specialkey)
|
|
|
|
g_free(specialkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!key)
|
|
|
|
{
|
|
|
|
notify(WARNING, "No valid key binding given.");
|
|
|
|
return FALSE;
|
2010-06-17 00:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* parse argument */
|
|
|
|
Argument arg = {0, 0};
|
|
|
|
|
|
|
|
if(argc >= 3)
|
|
|
|
{
|
|
|
|
int arg_id = -1;
|
|
|
|
|
|
|
|
/* compare argument with given argument names... */
|
|
|
|
int arg_c;
|
|
|
|
for(arg_c = 0; arg_c < LENGTH(argument_names); arg_c++)
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[2], argument_names[arg_c].name))
|
|
|
|
{
|
|
|
|
arg_id = argument_names[arg_c].argument;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if not, save it do .data */
|
|
|
|
if(arg_id == -1)
|
|
|
|
arg.data = argv[2];
|
|
|
|
else
|
|
|
|
arg.n = arg_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse mode */
|
|
|
|
if(argc >= 4)
|
|
|
|
{
|
|
|
|
int mode_c;
|
|
|
|
for(mode_c = 0; mode_c < LENGTH(mode_names); mode_c++)
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[3], mode_names[mode_c].name))
|
|
|
|
{
|
|
|
|
mode = mode_names[mode_c].mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search for existing binding to overwrite it */
|
2010-06-16 23:13:25 +02:00
|
|
|
ShortcutList* sc = Zathura.Bindings.sclist;
|
|
|
|
while(sc && sc->next != NULL)
|
|
|
|
{
|
2010-06-17 00:12:21 +02:00
|
|
|
if(sc->element.key == key && sc->element.mask == mask
|
|
|
|
&& sc->element.mode == mode)
|
|
|
|
{
|
|
|
|
sc->element.function = shortcut_names[sc_id].function;
|
|
|
|
sc->element.argument = arg;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-16 23:13:25 +02:00
|
|
|
sc = sc->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create new entry */
|
|
|
|
ShortcutList* entry = malloc(sizeof(ShortcutList));
|
|
|
|
if(!entry)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-06-17 00:12:21 +02:00
|
|
|
entry->element.mask = mask;
|
|
|
|
entry->element.key = key;
|
2010-06-16 23:13:25 +02:00
|
|
|
entry->element.function = shortcut_names[sc_id].function;
|
2010-06-17 00:12:21 +02:00
|
|
|
entry->element.mode = mode;
|
2010-06-16 23:13:25 +02:00
|
|
|
entry->element.argument = arg;
|
2010-06-17 00:12:21 +02:00
|
|
|
entry->next = NULL;
|
2010-06-16 23:13:25 +02:00
|
|
|
|
|
|
|
/* append to list */
|
|
|
|
if(!Zathura.Bindings.sclist)
|
|
|
|
Zathura.Bindings.sclist = entry;
|
|
|
|
|
|
|
|
if(sc)
|
|
|
|
sc->next = entry;
|
2010-06-16 21:50:28 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean
|
2009-12-26 15:55:32 +01:00
|
|
|
cmd_open(int argc, char** argv)
|
|
|
|
{
|
2009-12-26 17:18:45 +01:00
|
|
|
if(argc == 0 || strlen(argv[0]) == 0)
|
|
|
|
return FALSE;
|
2009-12-28 20:10:47 +01:00
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
/* assembly the arguments back to one string */
|
|
|
|
int i = 0;
|
|
|
|
GString *filepath = g_string_new("");
|
|
|
|
for(i = 0; i < argc; i++)
|
2010-01-31 12:35:49 +01:00
|
|
|
{
|
2010-02-02 15:27:37 +01:00
|
|
|
if(i != 0)
|
|
|
|
filepath = g_string_append_c(filepath, ' ');
|
2010-01-31 21:07:27 +01:00
|
|
|
|
2010-02-02 15:27:37 +01:00
|
|
|
filepath = g_string_append(filepath, argv[i]);
|
2010-01-31 12:35:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-24 21:26:40 +02:00
|
|
|
return open_file(filepath->str, NULL);
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean
|
2009-12-26 15:55:32 +01:00
|
|
|
cmd_print(int argc, char** argv)
|
|
|
|
{
|
2010-01-02 00:36:32 +01:00
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if(argc == 0)
|
|
|
|
{
|
|
|
|
notify(WARNING, "No printer specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* printer = argv[0];
|
2010-06-03 20:05:17 +02:00
|
|
|
char* sites = (argc == 2) ? g_strdup(argv[1]) : g_strdup_printf("1-%i", Zathura.PDF.number_of_pages);
|
2010-06-15 12:50:43 +02:00
|
|
|
char* command = g_strdup_printf(print_command, printer, sites, Zathura.PDF.file);
|
|
|
|
system(command);
|
2010-01-02 00:36:32 +01:00
|
|
|
|
2010-05-25 20:16:12 +02:00
|
|
|
g_free(sites);
|
2010-06-15 12:50:43 +02:00
|
|
|
g_free(command);
|
2010-05-25 20:16:12 +02:00
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
return TRUE;
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean
|
2009-12-26 15:55:32 +01:00
|
|
|
cmd_rotate(int argc, char** argv)
|
|
|
|
{
|
2009-12-26 17:18:45 +01:00
|
|
|
return TRUE;
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
gboolean
|
|
|
|
cmd_set(int argc, char** argv)
|
|
|
|
{
|
2010-06-14 21:06:26 +02:00
|
|
|
if(argc <= 0)
|
2010-01-01 19:52:20 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < LENGTH(settings); i++)
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[0], settings[i].name))
|
|
|
|
{
|
|
|
|
/* check var type */
|
|
|
|
if(settings[i].type == 'b')
|
|
|
|
{
|
|
|
|
gboolean *x = (gboolean*) (settings[i].variable);
|
2010-01-29 11:10:49 +01:00
|
|
|
*x = !(*x);
|
2010-01-01 19:52:20 +01:00
|
|
|
|
2010-01-29 11:10:49 +01:00
|
|
|
if(argv[1])
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[1], "false") || !strcmp(argv[1], "0"))
|
|
|
|
*x = FALSE;
|
2010-05-05 12:36:04 +02:00
|
|
|
else
|
|
|
|
*x = TRUE;
|
2010-01-29 11:10:49 +01:00
|
|
|
}
|
2010-01-01 19:52:20 +01:00
|
|
|
}
|
|
|
|
else if(settings[i].type == 'i')
|
|
|
|
{
|
|
|
|
if(argc != 2)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
int *x = (int*) (settings[i].variable);
|
2010-06-18 11:03:11 +02:00
|
|
|
|
|
|
|
int id = -1;
|
|
|
|
int arg_c;
|
|
|
|
for(arg_c = 0; arg_c < LENGTH(argument_names); arg_c++)
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[1], argument_names[arg_c].name))
|
|
|
|
{
|
|
|
|
id = argument_names[arg_c].argument;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(id == -1)
|
|
|
|
id = atoi(argv[1]);
|
|
|
|
|
|
|
|
*x = id;
|
2010-01-01 19:52:20 +01:00
|
|
|
}
|
2010-06-15 12:50:43 +02:00
|
|
|
else if(settings[i].type == 'f')
|
2010-01-01 19:52:20 +01:00
|
|
|
{
|
|
|
|
if(argc != 2)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-06-15 12:50:43 +02:00
|
|
|
float *x = (float*) (settings[i].variable);
|
2010-01-29 11:10:49 +01:00
|
|
|
if(argv[1])
|
2010-06-15 12:50:43 +02:00
|
|
|
*x = atof(argv[1]);
|
|
|
|
}
|
2010-01-01 19:52:20 +01:00
|
|
|
else if(settings[i].type == 's')
|
|
|
|
{
|
2010-06-14 21:06:26 +02:00
|
|
|
if(argc < 2)
|
2010-01-01 19:52:20 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2010-06-14 21:06:26 +02:00
|
|
|
/* assembly the arguments back to one string */
|
2010-06-14 21:52:19 +02:00
|
|
|
int j;
|
2010-06-14 21:06:26 +02:00
|
|
|
GString *s = g_string_new("");
|
2010-06-14 21:52:19 +02:00
|
|
|
for(j = 1; j < argc; j++)
|
2010-06-14 21:06:26 +02:00
|
|
|
{
|
2010-06-14 21:52:19 +02:00
|
|
|
if(j != 1)
|
2010-06-14 21:06:26 +02:00
|
|
|
s = g_string_append_c(s, ' ');
|
|
|
|
|
2010-06-14 21:52:19 +02:00
|
|
|
s = g_string_append(s, argv[j]);
|
2010-06-14 21:06:26 +02:00
|
|
|
}
|
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
char **x = (char**) settings[i].variable;
|
2010-06-14 21:06:26 +02:00
|
|
|
*x = s->str;
|
2010-01-01 19:52:20 +01:00
|
|
|
}
|
|
|
|
else if(settings[i].type == 'c')
|
|
|
|
{
|
|
|
|
if(argc != 2)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
char *x = (char*) (settings[i].variable);
|
2010-01-29 11:10:49 +01:00
|
|
|
if(argv[1])
|
|
|
|
*x = argv[1][0];
|
2010-01-01 19:52:20 +01:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:06:26 +02:00
|
|
|
/* re-init */
|
|
|
|
if(settings[i].reinit)
|
2010-06-15 12:50:43 +02:00
|
|
|
init_look();
|
2010-06-14 21:06:26 +02:00
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
/* render */
|
|
|
|
if(settings[i].render)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-01-20 23:46:13 +01:00
|
|
|
draw(Zathura.PDF.page_number);
|
2010-01-01 19:52:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 12:36:04 +02:00
|
|
|
update_status();
|
2010-01-01 19:52:20 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean
|
2009-08-11 23:18:50 +02:00
|
|
|
cmd_quit(int argc, char** argv)
|
|
|
|
{
|
|
|
|
cb_destroy(NULL, NULL);
|
2009-12-26 17:18:45 +01:00
|
|
|
return TRUE;
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean
|
2009-12-26 15:55:32 +01:00
|
|
|
cmd_save(int argc, char** argv)
|
|
|
|
{
|
2010-04-11 21:12:30 +02:00
|
|
|
if(argc == 0 || !Zathura.PDF.document)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
char* path = g_strdup_printf("file://%s", argv[0]);
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
poppler_document_save(Zathura.PDF.document, path, NULL);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
g_free(path);
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
return TRUE;
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* completion command implementation */
|
2010-01-31 21:07:27 +01:00
|
|
|
Completion*
|
|
|
|
cc_bookmark(char* input)
|
|
|
|
{
|
|
|
|
/* init completion group */
|
|
|
|
Completion *completion = malloc(sizeof(Completion));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!completion)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-31 21:07:27 +01:00
|
|
|
CompletionGroup* group = malloc(sizeof(CompletionGroup));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!group)
|
|
|
|
out_of_memory();
|
2010-01-31 21:07:27 +01:00
|
|
|
|
|
|
|
group->value = NULL;
|
|
|
|
group->next = NULL;
|
|
|
|
group->elements = NULL;
|
|
|
|
|
|
|
|
completion->groups = group;
|
|
|
|
CompletionElement *last_element = NULL;
|
|
|
|
int element_counter = 0;
|
|
|
|
int i = 0;
|
|
|
|
int input_length = input ? strlen(input) : 0;
|
|
|
|
|
|
|
|
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
|
|
|
|
{
|
|
|
|
if( (input_length <= strlen(Zathura.Bookmarks.bookmarks[i].id)) &&
|
|
|
|
!strncmp(input, Zathura.Bookmarks.bookmarks[i].id, input_length) )
|
|
|
|
{
|
|
|
|
CompletionElement* el = malloc(sizeof(CompletionElement));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!el)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-31 21:07:27 +01:00
|
|
|
el->value = Zathura.Bookmarks.bookmarks[i].id;
|
|
|
|
el->description = g_strdup_printf("Page: %d", Zathura.Bookmarks.bookmarks[i].page);
|
|
|
|
el->next = NULL;
|
|
|
|
|
|
|
|
if(element_counter++ != 0)
|
|
|
|
last_element->next = el;
|
|
|
|
else
|
|
|
|
group->elements = el;
|
|
|
|
|
|
|
|
last_element = el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
2010-01-03 16:25:51 +01:00
|
|
|
Completion*
|
|
|
|
cc_export(char* input)
|
|
|
|
{
|
|
|
|
/* init completion group */
|
|
|
|
Completion *completion = malloc(sizeof(Completion));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!completion)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-03 16:25:51 +01:00
|
|
|
CompletionGroup* group = malloc(sizeof(CompletionGroup));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!group)
|
|
|
|
out_of_memory();
|
2010-01-03 16:25:51 +01:00
|
|
|
|
|
|
|
group->value = NULL;
|
|
|
|
group->next = NULL;
|
|
|
|
group->elements = NULL;
|
|
|
|
|
|
|
|
completion->groups = group;
|
|
|
|
|
|
|
|
/* export images */
|
|
|
|
CompletionElement *export_images = malloc(sizeof(CompletionElement));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!export_images)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-03 16:25:51 +01:00
|
|
|
export_images->value = "images";
|
|
|
|
export_images->description = "Export images";
|
|
|
|
export_images->next = NULL;
|
|
|
|
|
|
|
|
/* export attachmants */
|
|
|
|
CompletionElement *export_attachments = malloc(sizeof(CompletionElement));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!export_attachments)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-03 16:25:51 +01:00
|
|
|
export_attachments->value = "attachments";
|
|
|
|
export_attachments->description = "Export attachments";
|
|
|
|
export_attachments->next = NULL;
|
|
|
|
|
|
|
|
/* connect */
|
|
|
|
group->elements = export_attachments;
|
|
|
|
export_attachments->next = export_images;
|
|
|
|
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
Completion*
|
|
|
|
cc_open(char* input)
|
2009-12-26 14:30:50 +01:00
|
|
|
{
|
2009-12-28 00:44:35 +01:00
|
|
|
/* init completion group */
|
2009-12-28 17:14:23 +01:00
|
|
|
Completion *completion = malloc(sizeof(Completion));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!completion)
|
|
|
|
out_of_memory();
|
|
|
|
|
2009-12-28 17:14:23 +01:00
|
|
|
CompletionGroup* group = malloc(sizeof(CompletionGroup));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!group)
|
|
|
|
out_of_memory();
|
2009-12-28 00:44:35 +01:00
|
|
|
|
|
|
|
group->value = NULL;
|
|
|
|
group->next = NULL;
|
|
|
|
group->elements = NULL;
|
2009-12-26 14:30:50 +01:00
|
|
|
|
|
|
|
completion->groups = group;
|
|
|
|
|
2009-12-28 00:44:35 +01:00
|
|
|
/* read dir */
|
2009-12-28 17:14:23 +01:00
|
|
|
char* path = "/";
|
|
|
|
char* file = "";
|
|
|
|
int file_length = 0;
|
2009-12-28 00:44:35 +01:00
|
|
|
|
2010-01-01 20:55:12 +01:00
|
|
|
/* ~ */
|
|
|
|
if(input[0] == '~')
|
|
|
|
{
|
|
|
|
char *file = g_strdup_printf(":open %s/%s", getenv("HOME"), input + 1);
|
|
|
|
gtk_entry_set_text(Zathura.UI.inputbar, file);
|
|
|
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-28 17:14:23 +01:00
|
|
|
/* parse input string */
|
|
|
|
if(input && strlen(input) > 0)
|
2009-12-28 00:44:35 +01:00
|
|
|
{
|
2009-12-28 17:14:23 +01:00
|
|
|
char* path_temp = dirname(strdup(input));
|
|
|
|
char* file_temp = basename(strdup(input));
|
|
|
|
char last_char = input[strlen(input) - 1];
|
2009-12-28 00:44:35 +01:00
|
|
|
|
2009-12-28 17:14:23 +01:00
|
|
|
if( !strcmp(path_temp, "/") && !strcmp(file_temp, "/") )
|
2009-12-28 00:44:35 +01:00
|
|
|
file = "";
|
2009-12-28 17:14:23 +01:00
|
|
|
else if( !strcmp(path_temp, "/") && strcmp(file_temp, "/") && last_char != '/')
|
|
|
|
file = file_temp;
|
|
|
|
else if( !strcmp(path_temp, "/") && strcmp(file_temp, "/") && last_char == '/')
|
|
|
|
path = g_strdup_printf("/%s/", file_temp);
|
|
|
|
else if(last_char == '/')
|
|
|
|
path = input;
|
|
|
|
else
|
2009-12-28 00:44:35 +01:00
|
|
|
{
|
2009-12-28 17:14:23 +01:00
|
|
|
path = g_strdup_printf("%s/", path_temp);
|
|
|
|
file = file_temp;
|
2009-12-28 00:44:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_length = strlen(file);
|
|
|
|
|
2009-12-28 17:14:23 +01:00
|
|
|
/* open directory */
|
2009-12-28 00:44:35 +01:00
|
|
|
GDir* dir = g_dir_open(path, 0, NULL);
|
|
|
|
if(!dir)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-28 17:14:23 +01:00
|
|
|
/* create element list */
|
2009-12-28 00:44:35 +01:00
|
|
|
CompletionElement *last_element = NULL;
|
2009-12-28 17:14:23 +01:00
|
|
|
char* name = NULL;
|
|
|
|
int element_counter = 0;
|
2009-12-28 00:44:35 +01:00
|
|
|
|
|
|
|
while((name = (char*) g_dir_read_name(dir)) != NULL)
|
|
|
|
{
|
|
|
|
char* d_name = g_filename_display_name(name);
|
2010-01-01 19:52:20 +01:00
|
|
|
int d_length = strlen(d_name);
|
2009-12-28 17:14:23 +01:00
|
|
|
|
|
|
|
if( ((file_length <= d_length) && !strncmp(file, d_name, file_length)) ||
|
|
|
|
(file_length == 0) )
|
2009-12-28 00:44:35 +01:00
|
|
|
{
|
|
|
|
CompletionElement* el = malloc(sizeof(CompletionElement));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!el)
|
|
|
|
out_of_memory();
|
|
|
|
|
2009-12-28 00:44:35 +01:00
|
|
|
el->value = g_strdup_printf("%s%s", path, d_name);
|
|
|
|
el->description = NULL;
|
|
|
|
el->next = NULL;
|
|
|
|
|
|
|
|
if(element_counter++ != 0)
|
|
|
|
last_element->next = el;
|
|
|
|
else
|
|
|
|
group->elements = el;
|
|
|
|
|
|
|
|
last_element = el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dir_close(dir);
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
2010-01-02 00:25:18 +01:00
|
|
|
Completion*
|
|
|
|
cc_print(char* input)
|
|
|
|
{
|
|
|
|
/* init completion group */
|
|
|
|
Completion *completion = malloc(sizeof(Completion));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!completion)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-02 00:25:18 +01:00
|
|
|
CompletionGroup* group = malloc(sizeof(CompletionGroup));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!group)
|
|
|
|
out_of_memory();
|
2010-01-02 00:25:18 +01:00
|
|
|
|
|
|
|
group->value = NULL;
|
|
|
|
group->next = NULL;
|
|
|
|
group->elements = NULL;
|
|
|
|
|
|
|
|
completion->groups = group;
|
|
|
|
CompletionElement *last_element = NULL;
|
|
|
|
int element_counter = 0;
|
|
|
|
int input_length = input ? strlen(input) : 0;
|
|
|
|
|
|
|
|
/* read printers */
|
|
|
|
char *current_line = NULL, current_char;
|
|
|
|
int count = 0;
|
|
|
|
FILE *fp;
|
|
|
|
|
2010-06-15 12:50:43 +02:00
|
|
|
fp = popen(list_printer_command, "r");
|
2010-01-02 00:25:18 +01:00
|
|
|
|
|
|
|
if(!fp)
|
2010-04-10 14:33:23 +02:00
|
|
|
{
|
|
|
|
free(completion);
|
|
|
|
free(group);
|
2010-01-02 00:25:18 +01:00
|
|
|
return NULL;
|
2010-04-10 14:33:23 +02:00
|
|
|
}
|
2010-01-02 00:25:18 +01:00
|
|
|
|
|
|
|
while((current_char = fgetc(fp)) != EOF)
|
|
|
|
{
|
|
|
|
if(!current_line)
|
2010-01-02 00:36:32 +01:00
|
|
|
current_line = malloc(sizeof(char));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!current_line)
|
|
|
|
out_of_memory();
|
2010-01-02 00:25:18 +01:00
|
|
|
|
|
|
|
current_line = realloc(current_line, (count + 1) * sizeof(char));
|
|
|
|
|
|
|
|
if(current_char != '\n')
|
|
|
|
current_line[count++] = current_char;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current_line[count] = '\0';
|
|
|
|
int line_length = strlen(current_line);
|
|
|
|
|
|
|
|
if( (input_length <= line_length) ||
|
|
|
|
(!strncmp(input, current_line, input_length)) )
|
|
|
|
{
|
|
|
|
CompletionElement* el = malloc(sizeof(CompletionElement));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!el)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-02 00:25:18 +01:00
|
|
|
el->value = g_strdup(current_line);
|
|
|
|
el->description = NULL;
|
|
|
|
el->next = NULL;
|
|
|
|
|
|
|
|
if(element_counter++ != 0)
|
|
|
|
last_element->next = el;
|
|
|
|
else
|
|
|
|
group->elements = el;
|
|
|
|
|
|
|
|
last_element = el;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(current_line);
|
|
|
|
current_line = NULL;
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
|
|
|
|
return completion;
|
|
|
|
}
|
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
Completion*
|
|
|
|
cc_set(char* input)
|
|
|
|
{
|
|
|
|
/* init completion group */
|
|
|
|
Completion *completion = malloc(sizeof(Completion));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!completion)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-01 19:52:20 +01:00
|
|
|
CompletionGroup* group = malloc(sizeof(CompletionGroup));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!group)
|
|
|
|
out_of_memory();
|
2010-01-01 19:52:20 +01:00
|
|
|
|
|
|
|
group->value = NULL;
|
|
|
|
group->next = NULL;
|
|
|
|
group->elements = NULL;
|
|
|
|
|
|
|
|
completion->groups = group;
|
|
|
|
CompletionElement *last_element = NULL;
|
|
|
|
int element_counter = 0;
|
2010-01-01 20:00:56 +01:00
|
|
|
int i = 0;
|
2010-01-01 19:52:20 +01:00
|
|
|
int input_length = input ? strlen(input) : 0;
|
|
|
|
|
2010-01-01 20:00:56 +01:00
|
|
|
for(i = 0; i < LENGTH(settings); i++)
|
2010-01-01 19:52:20 +01:00
|
|
|
{
|
2010-01-01 20:00:56 +01:00
|
|
|
if( (input_length <= strlen(settings[i].name)) &&
|
|
|
|
!strncmp(input, settings[i].name, input_length) )
|
2010-01-01 19:52:20 +01:00
|
|
|
{
|
|
|
|
CompletionElement* el = malloc(sizeof(CompletionElement));
|
2010-06-16 22:42:45 +02:00
|
|
|
if(!el)
|
|
|
|
out_of_memory();
|
|
|
|
|
2010-01-01 20:00:56 +01:00
|
|
|
el->value = settings[i].name;
|
|
|
|
el->description = settings[i].description;
|
2010-01-01 19:52:20 +01:00
|
|
|
el->next = NULL;
|
|
|
|
|
2010-01-01 20:00:56 +01:00
|
|
|
if(element_counter++ != 0)
|
2010-01-01 19:52:20 +01:00
|
|
|
last_element->next = el;
|
|
|
|
else
|
|
|
|
group->elements = el;
|
|
|
|
|
|
|
|
last_element = el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return completion;
|
|
|
|
}
|
2009-12-28 17:14:23 +01:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* buffer command implementation */
|
2010-05-18 00:19:09 +02:00
|
|
|
void
|
2009-12-26 14:30:50 +01:00
|
|
|
bcmd_goto(char* buffer, Argument* argument)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2010-06-19 09:58:40 +02:00
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return;
|
|
|
|
|
2009-12-28 18:34:00 +01:00
|
|
|
int b_length = strlen(buffer);
|
|
|
|
if(b_length < 1)
|
|
|
|
return;
|
|
|
|
|
2009-12-30 00:55:03 +01:00
|
|
|
if(!strcmp(buffer, "gg"))
|
|
|
|
set_page(0);
|
|
|
|
else if(!strcmp(buffer, "G"))
|
|
|
|
set_page(Zathura.PDF.number_of_pages - 1);
|
|
|
|
else
|
2010-05-05 12:51:18 +02:00
|
|
|
{
|
|
|
|
char* id = g_strndup(buffer, b_length - 1);
|
|
|
|
int pid = atoi(id);
|
|
|
|
|
2010-05-05 20:05:06 +02:00
|
|
|
if(Zathura.Global.goto_mode == GOTO_LABELS)
|
2010-05-05 12:51:18 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < Zathura.PDF.number_of_pages; i++)
|
|
|
|
if(!strcmp(id, Zathura.PDF.pages[i]->label))
|
|
|
|
pid = Zathura.PDF.pages[i]->id;
|
|
|
|
}
|
2010-05-05 20:05:06 +02:00
|
|
|
else if(Zathura.Global.goto_mode == GOTO_OFFSET)
|
|
|
|
pid += Zathura.PDF.page_offset;
|
2010-05-05 12:51:18 +02:00
|
|
|
|
|
|
|
set_page(pid - 1);
|
|
|
|
g_free(id);
|
|
|
|
}
|
2009-10-30 00:16:43 +01:00
|
|
|
|
2009-12-28 18:34:00 +01:00
|
|
|
update_status();
|
2009-12-26 14:30:50 +01:00
|
|
|
}
|
2009-10-30 00:16:43 +01:00
|
|
|
|
2010-01-29 13:18:25 +01:00
|
|
|
void
|
|
|
|
bcmd_scroll(char* buffer, Argument* argument)
|
|
|
|
{
|
|
|
|
int b_length = strlen(buffer);
|
|
|
|
if(b_length < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int percentage = atoi(g_strndup(buffer, b_length - 1));
|
|
|
|
percentage = (percentage < 0) ? 0 : ((percentage > 100) ? 100 : percentage);
|
|
|
|
|
|
|
|
GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view);
|
|
|
|
|
|
|
|
gdouble view_size = gtk_adjustment_get_page_size(adjustment);
|
|
|
|
gdouble max = gtk_adjustment_get_upper(adjustment) - view_size;
|
|
|
|
gdouble nvalue = (percentage * max) / 100;
|
|
|
|
|
|
|
|
Zathura.State.scroll_percentage = percentage;
|
|
|
|
gtk_adjustment_set_value(adjustment, nvalue);
|
|
|
|
update_status();
|
|
|
|
}
|
|
|
|
|
2009-12-26 15:55:32 +01:00
|
|
|
void
|
|
|
|
bcmd_zoom(char* buffer, Argument* argument)
|
|
|
|
{
|
2010-04-12 19:30:48 +02:00
|
|
|
Zathura.Global.adjust_mode = ADJUST_NONE;
|
|
|
|
|
2009-12-28 18:34:00 +01:00
|
|
|
if(argument->n == ZOOM_IN)
|
2009-12-28 19:03:26 +01:00
|
|
|
{
|
2010-06-15 12:50:43 +02:00
|
|
|
if((Zathura.PDF.scale + zoom_step) <= zoom_max)
|
|
|
|
Zathura.PDF.scale += zoom_step;
|
2010-01-28 13:57:54 +01:00
|
|
|
else
|
2010-06-15 12:50:43 +02:00
|
|
|
Zathura.PDF.scale = zoom_max;
|
2009-12-28 19:03:26 +01:00
|
|
|
}
|
2009-12-28 18:34:00 +01:00
|
|
|
else if(argument->n == ZOOM_OUT)
|
2009-12-28 19:03:26 +01:00
|
|
|
{
|
2010-06-15 12:50:43 +02:00
|
|
|
if((Zathura.PDF.scale - zoom_step) >= zoom_min)
|
|
|
|
Zathura.PDF.scale -= zoom_step;
|
2010-01-28 13:57:54 +01:00
|
|
|
else
|
2010-06-15 12:50:43 +02:00
|
|
|
Zathura.PDF.scale = zoom_min;
|
2010-01-28 13:57:54 +01:00
|
|
|
}
|
|
|
|
else if(argument->n == ZOOM_SPECIFIC)
|
|
|
|
{
|
|
|
|
int b_length = strlen(buffer);
|
|
|
|
if(b_length < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int value = atoi(g_strndup(buffer, b_length - 1));
|
2010-06-15 12:50:43 +02:00
|
|
|
if(value <= zoom_min)
|
|
|
|
Zathura.PDF.scale = zoom_min;
|
|
|
|
else if(value >= zoom_max)
|
|
|
|
Zathura.PDF.scale = zoom_max;
|
2010-01-28 13:57:54 +01:00
|
|
|
else
|
|
|
|
Zathura.PDF.scale = value;
|
2009-12-28 19:03:26 +01:00
|
|
|
}
|
2009-12-28 18:34:00 +01:00
|
|
|
else
|
2009-12-28 19:24:15 +01:00
|
|
|
Zathura.PDF.scale = 100;
|
2009-12-28 19:03:26 +01:00
|
|
|
|
2010-05-19 12:13:28 +02:00
|
|
|
Zathura.Search.draw = TRUE;
|
2010-01-20 23:46:13 +01:00
|
|
|
draw(Zathura.PDF.page_number);
|
2009-12-28 19:03:26 +01:00
|
|
|
update_status();
|
2009-12-26 15:55:32 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* special command implementation */
|
2009-12-26 17:18:45 +01:00
|
|
|
gboolean
|
2009-12-26 14:30:50 +01:00
|
|
|
scmd_search(char* input, Argument* argument)
|
|
|
|
{
|
2010-01-03 16:18:36 +01:00
|
|
|
if(!strlen(input))
|
|
|
|
return TRUE;
|
|
|
|
|
2010-01-02 14:23:49 +01:00
|
|
|
argument->data = input;
|
|
|
|
sc_search(argument);
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
return TRUE;
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* callback implementation */
|
|
|
|
gboolean
|
|
|
|
cb_destroy(GtkWidget* widget, gpointer data)
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
pango_font_description_free(Zathura.Style.font);
|
2009-12-28 19:24:15 +01:00
|
|
|
|
|
|
|
if(Zathura.PDF.document)
|
2010-06-15 10:17:38 +02:00
|
|
|
close_file(FALSE);
|
2009-12-28 19:24:15 +01:00
|
|
|
|
2010-01-31 12:35:49 +01:00
|
|
|
/* clean up other variables */
|
|
|
|
g_free(Zathura.Bookmarks.file);
|
|
|
|
|
2010-03-08 20:08:59 +01:00
|
|
|
/* inotify */
|
2010-06-03 18:05:34 +02:00
|
|
|
if(Zathura.FileMonitor.monitor)
|
|
|
|
g_object_unref(Zathura.FileMonitor.monitor);
|
2010-03-08 20:08:59 +01:00
|
|
|
|
2010-05-25 20:16:12 +02:00
|
|
|
g_list_free(Zathura.Global.history);
|
|
|
|
|
2010-06-16 22:42:45 +02:00
|
|
|
/* clean shortcut list */
|
|
|
|
ShortcutList* sc = Zathura.Bindings.sclist;
|
|
|
|
|
|
|
|
while(sc)
|
|
|
|
{
|
|
|
|
ShortcutList* ne = sc->next;
|
|
|
|
free(sc);
|
|
|
|
sc = ne;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
gtk_main_quit();
|
2009-12-26 14:30:50 +01:00
|
|
|
|
2009-12-28 21:18:54 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-30 00:44:14 +01:00
|
|
|
gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data)
|
2009-12-28 21:18:54 +01:00
|
|
|
{
|
2010-04-12 17:36:58 +02:00
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-08 20:08:59 +01:00
|
|
|
int page_id = Zathura.PDF.page_number;
|
2009-12-29 23:48:28 +01:00
|
|
|
if(page_id < 0 || page_id > Zathura.PDF.number_of_pages)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-12-28 21:18:54 +01:00
|
|
|
gdk_window_clear(widget->window);
|
|
|
|
cairo_t *cairo = gdk_cairo_create(widget->window);
|
|
|
|
|
|
|
|
double page_width, page_height, width, height;
|
|
|
|
double scale = ((double) Zathura.PDF.scale / 100.0);
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2009-12-28 21:18:54 +01:00
|
|
|
poppler_page_get_size(Zathura.PDF.pages[page_id]->page, &page_width, &page_height);
|
2010-04-10 14:33:23 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2009-12-28 21:18:54 +01:00
|
|
|
|
|
|
|
if(Zathura.PDF.rotate == 0 || Zathura.PDF.rotate == 180)
|
|
|
|
{
|
|
|
|
width = page_width * scale;
|
|
|
|
height = page_height * scale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = page_height * scale;
|
|
|
|
height = page_width * scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
int window_x, window_y;
|
|
|
|
gdk_drawable_get_size(widget->window, &window_x, &window_y);
|
|
|
|
|
|
|
|
int offset_x, offset_y;
|
|
|
|
|
|
|
|
if (window_x > width)
|
|
|
|
offset_x = (window_x - width) / 2;
|
|
|
|
else
|
|
|
|
offset_x = 0;
|
|
|
|
|
|
|
|
if (window_y > height)
|
|
|
|
offset_y = (window_y - height) / 2;
|
|
|
|
else
|
|
|
|
offset_y = 0;
|
|
|
|
|
2010-05-13 11:39:20 +02:00
|
|
|
if(Zathura.Search.draw)
|
|
|
|
{
|
|
|
|
GList* list;
|
|
|
|
for(list = Zathura.Search.results; list && list->data; list = g_list_next(list))
|
|
|
|
highlight_result(Zathura.Search.page, (PopplerRectangle*) list->data);
|
2010-05-19 12:13:28 +02:00
|
|
|
Zathura.Search.draw = FALSE;
|
2010-05-13 11:39:20 +02:00
|
|
|
}
|
2010-01-02 00:45:16 +01:00
|
|
|
|
2010-01-20 23:46:13 +01:00
|
|
|
cairo_set_source_surface(cairo, Zathura.PDF.surface, offset_x, offset_y);
|
2009-12-28 21:18:54 +01:00
|
|
|
cairo_paint(cairo);
|
|
|
|
cairo_destroy(cairo);
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
return TRUE;
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gboolean
|
|
|
|
cb_inputbar_kb_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
2009-08-15 12:35:07 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
int i;
|
2009-08-15 12:35:07 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* inputbar shortcuts */
|
|
|
|
for(i = 0; i < LENGTH(inputbar_shortcuts); i++)
|
2009-08-15 12:35:07 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(event->keyval == inputbar_shortcuts[i].key &&
|
|
|
|
(((event->state & inputbar_shortcuts[i].mask) == inputbar_shortcuts[i].mask)
|
|
|
|
|| inputbar_shortcuts[i].mask == 0))
|
2009-08-15 12:35:07 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
inputbar_shortcuts[i].function(&(inputbar_shortcuts[i].argument));
|
|
|
|
return TRUE;
|
2009-08-15 12:35:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* special commands */
|
|
|
|
char identifier = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, 1)[0];
|
|
|
|
for(i = 0; i < LENGTH(special_commands); i++)
|
2009-09-20 16:25:56 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if((identifier == special_commands[i].identifier) &&
|
|
|
|
(special_commands[i].always == 1))
|
2009-09-20 16:25:56 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 1, -1);
|
|
|
|
special_commands[i].function(input, &(special_commands[i].argument));
|
|
|
|
return FALSE;
|
2009-09-20 16:25:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
return FALSE;
|
2009-08-15 12:35:07 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
gboolean
|
2009-12-26 14:30:50 +01:00
|
|
|
cb_inputbar_activate(GtkEntry* entry, gpointer data)
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2009-12-28 19:03:26 +01:00
|
|
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1);
|
|
|
|
gchar **tokens = g_strsplit(input, " ", -1);
|
|
|
|
gchar *command = tokens[0];
|
|
|
|
int length = g_strv_length(tokens);
|
|
|
|
int i = 0;
|
|
|
|
gboolean retv = FALSE;
|
|
|
|
gboolean succ = FALSE;
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* no input */
|
|
|
|
if(length < 1)
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
isc_abort(NULL);
|
|
|
|
return FALSE;
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
2009-12-28 19:03:26 +01:00
|
|
|
/* append input to the command history */
|
|
|
|
Zathura.Global.history = g_list_append(Zathura.Global.history, g_strdup(gtk_entry_get_text(entry)));
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* special commands */
|
|
|
|
char identifier = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, 1)[0];
|
|
|
|
for(i = 0; i < LENGTH(special_commands); i++)
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if(identifier == special_commands[i].identifier)
|
|
|
|
{
|
2010-04-12 19:57:53 +02:00
|
|
|
/* special commands that are evaluated every key change are not
|
|
|
|
* called here */
|
|
|
|
if(special_commands[i].always == 1)
|
|
|
|
{
|
|
|
|
isc_abort(NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-26 17:18:45 +01:00
|
|
|
retv = special_commands[i].function(input, &(special_commands[i].argument));
|
|
|
|
if(retv) isc_abort(NULL);
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view));
|
2009-12-26 14:30:50 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
2009-09-12 11:19:51 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
/* search commands */
|
|
|
|
for(i = 0; i < LENGTH(commands); i++)
|
2009-08-12 21:45:49 +02:00
|
|
|
{
|
2009-12-26 14:30:50 +01:00
|
|
|
if((g_strcmp0(command, commands[i].command) == 0) ||
|
|
|
|
(g_strcmp0(command, commands[i].abbr) == 0))
|
|
|
|
{
|
2009-12-26 17:18:45 +01:00
|
|
|
retv = commands[i].function(length - 1, tokens + 1);
|
2009-12-28 19:03:26 +01:00
|
|
|
succ = TRUE;
|
2009-12-26 14:30:50 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-08-12 21:45:49 +02:00
|
|
|
}
|
2009-08-11 23:18:50 +02:00
|
|
|
|
2009-12-28 19:03:26 +01:00
|
|
|
if(retv)
|
|
|
|
isc_abort(NULL);
|
|
|
|
|
|
|
|
if(!succ)
|
|
|
|
notify(ERROR, "Unknown command.");
|
2009-12-26 14:30:50 +01:00
|
|
|
|
2010-01-01 20:46:07 +01:00
|
|
|
Argument arg = { HIDE };
|
|
|
|
isc_completion(&arg);
|
2009-12-26 17:18:45 +01:00
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view));
|
2009-12-26 14:30:50 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2009-08-11 23:18:50 +02:00
|
|
|
}
|
|
|
|
|
2010-04-11 12:31:18 +02:00
|
|
|
gboolean
|
|
|
|
cb_inputbar_form_activate(GtkEntry* entry, gpointer data)
|
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number];
|
2010-04-11 14:18:49 +02:00
|
|
|
int number_of_links = 0, link_id = 1, new_page_id = Zathura.PDF.page_number;
|
2010-04-11 12:31:18 +02:00
|
|
|
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
GList *link_list = poppler_page_get_link_mapping(current_page->page);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
link_list = g_list_reverse(link_list);
|
|
|
|
|
|
|
|
if((number_of_links = g_list_length(link_list)) <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-04-11 12:53:45 +02:00
|
|
|
/* parse entry */
|
|
|
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1);
|
|
|
|
gchar *token = input + strlen("Follow hint: ") - 1;
|
|
|
|
if(!token)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
int li = atoi(token);
|
|
|
|
if(li <= 0 || li > number_of_links)
|
|
|
|
{
|
|
|
|
set_page(Zathura.PDF.page_number);
|
|
|
|
isc_abort(NULL);
|
|
|
|
notify(WARNING, "Invalid hint");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compare entry */
|
2010-04-11 12:31:18 +02:00
|
|
|
GList *links;
|
|
|
|
for(links = link_list; links; links = g_list_next(links))
|
|
|
|
{
|
|
|
|
PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data;
|
2010-04-11 12:53:45 +02:00
|
|
|
PopplerAction *action = link_mapping->action;
|
|
|
|
|
|
|
|
/* only handle URI and internal links */
|
|
|
|
if(action->type == POPPLER_ACTION_URI)
|
|
|
|
{
|
2010-04-11 14:18:49 +02:00
|
|
|
if(li == link_id)
|
|
|
|
open_uri(action->uri.uri);
|
2010-04-11 12:53:45 +02:00
|
|
|
}
|
|
|
|
else if(action->type == POPPLER_ACTION_GOTO_DEST)
|
|
|
|
{
|
2010-04-11 14:18:49 +02:00
|
|
|
if(li == link_id)
|
|
|
|
{
|
|
|
|
if(action->goto_dest.dest->type == POPPLER_DEST_NAMED)
|
|
|
|
{
|
|
|
|
PopplerDest* destination = poppler_document_find_dest(Zathura.PDF.document, action->goto_dest.dest->named_dest);
|
|
|
|
if(destination)
|
|
|
|
{
|
|
|
|
new_page_id = destination->page_num - 1;
|
|
|
|
poppler_dest_free(destination);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new_page_id = action->goto_dest.dest->page_num - 1;
|
|
|
|
}
|
2010-04-11 12:53:45 +02:00
|
|
|
}
|
2010-04-11 14:18:49 +02:00
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
link_id++;
|
2010-04-11 12:31:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
poppler_page_free_link_mapping(link_list);
|
|
|
|
|
|
|
|
/* replace default inputbar handler */
|
|
|
|
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
|
|
|
|
Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_activate), NULL);
|
|
|
|
|
|
|
|
/* reset all */
|
2010-04-11 14:18:49 +02:00
|
|
|
set_page(new_page_id);
|
2010-04-11 12:31:18 +02:00
|
|
|
isc_abort(NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-24 21:26:40 +02:00
|
|
|
gboolean
|
|
|
|
cb_inputbar_password_activate(GtkEntry* entry, gpointer data)
|
|
|
|
{
|
|
|
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1);
|
|
|
|
gchar *token = input + strlen("Enter password: ") - 1;
|
|
|
|
if(!token)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if(!open_file(Zathura.PDF.file, token))
|
|
|
|
{
|
|
|
|
enter_password();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replace default inputbar handler */
|
|
|
|
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
|
|
|
|
Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_activate), NULL);
|
|
|
|
|
|
|
|
isc_abort(NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-12 09:31:56 +02:00
|
|
|
gboolean
|
|
|
|
cb_view_kb_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|
|
|
{
|
2010-06-16 22:42:45 +02:00
|
|
|
ShortcutList* sc = Zathura.Bindings.sclist;
|
|
|
|
while(sc)
|
2010-04-12 09:31:56 +02:00
|
|
|
{
|
2010-06-21 16:19:06 +02:00
|
|
|
if(
|
|
|
|
event->keyval == sc->element.key
|
|
|
|
&& (CLEAN(event->state) == sc->element.mask || (sc->element.key >= 0x21
|
2010-06-21 18:27:44 +02:00
|
|
|
&& sc->element.key <= 0x7E && CLEAN(event->state) == GDK_SHIFT_MASK))
|
2010-06-21 16:19:06 +02:00
|
|
|
&& (Zathura.Global.mode & sc->element.mode || sc->element.mode == ALL)
|
|
|
|
&& sc->element.function
|
2010-06-18 12:58:20 +02:00
|
|
|
)
|
2010-04-12 09:31:56 +02:00
|
|
|
{
|
2010-06-21 16:19:06 +02:00
|
|
|
if(!(Zathura.Global.buffer && strlen(Zathura.Global.buffer->str)) || (sc->element.mask == GDK_CONTROL_MASK) ||
|
|
|
|
(sc->element.key <= 0x21 || sc->element.key >= 0x7E)
|
|
|
|
)
|
2010-06-19 16:38:57 +02:00
|
|
|
{
|
|
|
|
sc->element.function(&(sc->element.argument));
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-04-12 09:31:56 +02:00
|
|
|
}
|
2010-06-16 22:42:45 +02:00
|
|
|
|
|
|
|
sc = sc->next;
|
2010-04-12 09:31:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(Zathura.Global.mode == ADD_MARKER)
|
|
|
|
{
|
|
|
|
add_marker(event->keyval);
|
|
|
|
change_mode(NORMAL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if(Zathura.Global.mode == EVAL_MARKER)
|
|
|
|
{
|
|
|
|
eval_marker(event->keyval);
|
|
|
|
change_mode(NORMAL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append only numbers and characters to buffer */
|
2010-06-19 16:38:57 +02:00
|
|
|
if( (event->keyval >= 0x21) && (event->keyval <= 0x7E))
|
2010-04-12 09:31:56 +02:00
|
|
|
{
|
|
|
|
if(!Zathura.Global.buffer)
|
|
|
|
Zathura.Global.buffer = g_string_new("");
|
|
|
|
|
|
|
|
Zathura.Global.buffer = g_string_append_c(Zathura.Global.buffer, event->keyval);
|
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, Zathura.Global.buffer->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search buffer commands */
|
|
|
|
if(Zathura.Global.buffer)
|
|
|
|
{
|
2010-06-16 22:42:45 +02:00
|
|
|
int i;
|
2010-04-12 09:31:56 +02:00
|
|
|
for(i = 0; i < LENGTH(buffer_commands); i++)
|
|
|
|
{
|
|
|
|
regex_t regex;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
regcomp(®ex, buffer_commands[i].regex, REG_EXTENDED);
|
|
|
|
status = regexec(®ex, Zathura.Global.buffer->str, (size_t) 0, NULL, 0);
|
|
|
|
regfree(®ex);
|
|
|
|
|
|
|
|
if(status == 0)
|
|
|
|
{
|
|
|
|
buffer_commands[i].function(Zathura.Global.buffer->str, &(buffer_commands[i].argument));
|
|
|
|
g_string_free(Zathura.Global.buffer, TRUE);
|
|
|
|
Zathura.Global.buffer = NULL;
|
|
|
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, "");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cb_view_resized(GtkWidget* widget, GtkAllocation* allocation, gpointer data)
|
|
|
|
{
|
|
|
|
Argument arg;
|
|
|
|
arg.n = Zathura.Global.adjust_mode;
|
|
|
|
sc_adjust_window(&arg);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-12 19:22:47 +02:00
|
|
|
gboolean
|
|
|
|
cb_view_button_pressed(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
2010-04-12 23:55:14 +02:00
|
|
|
{
|
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-04-13 00:22:56 +02:00
|
|
|
/* clean page */
|
|
|
|
draw(Zathura.PDF.page_number);
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.select_lock));
|
|
|
|
Zathura.SelectPoint.x = event->x;
|
|
|
|
Zathura.SelectPoint.y = event->y;
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.select_lock));
|
|
|
|
|
2010-04-12 23:55:14 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
|
|
|
{
|
2010-04-13 00:22:56 +02:00
|
|
|
if(!Zathura.PDF.document)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
double scale, offset_x, offset_y, page_width, page_height;
|
2010-04-13 09:47:47 +02:00
|
|
|
PopplerRectangle rectangle;
|
|
|
|
cairo_t* cairo;
|
|
|
|
|
|
|
|
/* build selection rectangle */
|
|
|
|
rectangle.x1 = event->x;
|
|
|
|
rectangle.y1 = event->y;
|
|
|
|
|
2010-04-13 00:22:56 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.select_lock));
|
2010-04-13 09:47:47 +02:00
|
|
|
rectangle.x2 = Zathura.SelectPoint.x;
|
|
|
|
rectangle.y2 = Zathura.SelectPoint.y;
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.select_lock));
|
|
|
|
|
|
|
|
/* calculate offset */
|
|
|
|
calculate_offset(widget, &offset_x, &offset_y);
|
|
|
|
|
|
|
|
/* draw selection rectangle */
|
|
|
|
cairo = cairo_create(Zathura.PDF.surface);
|
2010-04-13 00:22:56 +02:00
|
|
|
cairo_set_source_rgba(cairo, Zathura.Style.select_text.red, Zathura.Style.select_text.green,
|
2010-06-15 12:50:43 +02:00
|
|
|
Zathura.Style.select_text.blue, transparency);
|
2010-04-13 09:47:47 +02:00
|
|
|
cairo_rectangle(cairo, rectangle.x1 - offset_x, rectangle.y1 - offset_y,
|
|
|
|
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
2010-04-13 00:22:56 +02:00
|
|
|
cairo_fill(cairo);
|
|
|
|
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
/* resize selection rectangle to document page */
|
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height);
|
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
|
|
|
|
|
|
|
scale = ((double) Zathura.PDF.scale / 100.0);
|
|
|
|
rectangle.x1 = (rectangle.x1 - offset_x) / scale;
|
|
|
|
rectangle.y1 = (rectangle.y1 - offset_y) / scale;
|
|
|
|
rectangle.x2 = (rectangle.x2 - offset_x) / scale;
|
|
|
|
rectangle.y2 = (rectangle.y2 - offset_y) / scale;
|
|
|
|
|
|
|
|
/* rotation */
|
|
|
|
int rotate = Zathura.PDF.rotate;
|
|
|
|
double x1 = rectangle.x1;
|
|
|
|
double x2 = rectangle.x2;
|
|
|
|
double y1 = rectangle.y1;
|
|
|
|
double y2 = rectangle.y2;
|
|
|
|
|
|
|
|
switch(rotate)
|
|
|
|
{
|
|
|
|
case 90:
|
|
|
|
rectangle.x1 = y1;
|
|
|
|
rectangle.y1 = page_height - x2;
|
|
|
|
rectangle.x2 = y2;
|
|
|
|
rectangle.y2 = page_height - x1;
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
rectangle.x1 = (page_height - y1);
|
|
|
|
rectangle.y1 = (page_width - x2);
|
|
|
|
rectangle.x2 = (page_height - y2);
|
|
|
|
rectangle.y2 = (page_width - x1);
|
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
rectangle.x1 = page_width - y2;
|
|
|
|
rectangle.y1 = x1;
|
|
|
|
rectangle.x2 = page_width - y1;
|
|
|
|
rectangle.y2 = x2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-13 09:47:47 +02:00
|
|
|
/* reset points of the rectangle so that p1 is in the top-left corner
|
|
|
|
* and p2 is in the bottom right corner */
|
|
|
|
if(rectangle.x1 > rectangle.x2)
|
|
|
|
{
|
2010-05-18 00:19:09 +02:00
|
|
|
double d = rectangle.x1;
|
|
|
|
rectangle.x1 = rectangle.x2;
|
|
|
|
rectangle.x2 = d;
|
2010-04-13 09:47:47 +02:00
|
|
|
}
|
|
|
|
if(rectangle.y2 > rectangle.y1)
|
|
|
|
{
|
2010-05-18 00:19:09 +02:00
|
|
|
double d = rectangle.y1;
|
|
|
|
rectangle.y1 = rectangle.y2;
|
|
|
|
rectangle.y2 = d;
|
2010-04-13 09:47:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
/* adapt y coordinates */
|
|
|
|
rectangle.y1 = page_height - rectangle.y1;
|
|
|
|
rectangle.y2 = page_height - rectangle.y2;
|
2010-04-13 09:47:47 +02:00
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
/* get selected text */
|
2010-04-13 09:47:47 +02:00
|
|
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
2010-05-18 00:19:09 +02:00
|
|
|
char* selected_text = poppler_page_get_text(
|
2010-05-18 00:48:46 +02:00
|
|
|
Zathura.PDF.pages[Zathura.PDF.page_number]->page,SELECTION_STYLE,
|
2010-05-18 00:19:09 +02:00
|
|
|
&rectangle);
|
2010-04-13 09:47:47 +02:00
|
|
|
|
|
|
|
if(selected_text)
|
2010-05-18 00:19:09 +02:00
|
|
|
{
|
2010-04-13 09:47:47 +02:00
|
|
|
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), selected_text, -1);
|
2010-05-18 00:19:09 +02:00
|
|
|
g_free(selected_text);
|
|
|
|
}
|
2010-04-13 09:47:47 +02:00
|
|
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
2010-04-13 00:22:56 +02:00
|
|
|
|
2010-05-18 00:19:09 +02:00
|
|
|
|
2010-04-12 23:55:14 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cb_view_motion_notify(GtkWidget* widget, GdkEventMotion* event, gpointer data)
|
2010-04-12 19:22:47 +02:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cb_view_scrolled(GtkWidget* widget, GdkEventScroll* event, gpointer data)
|
|
|
|
{
|
2010-04-12 19:38:07 +02:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < LENGTH(mouse_scroll_events); i++)
|
|
|
|
{
|
|
|
|
if(event->direction == mouse_scroll_events[i].direction)
|
|
|
|
{
|
|
|
|
mouse_scroll_events[i].function(&(mouse_scroll_events[i].argument));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2010-04-12 19:22:47 +02:00
|
|
|
}
|
2010-04-12 09:31:56 +02:00
|
|
|
|
2010-06-03 18:05:34 +02:00
|
|
|
gboolean
|
|
|
|
cb_watch_file(GFileMonitor* monitor, GFile* file, GFile* other_file, GFileMonitorEvent event, gpointer data)
|
|
|
|
{
|
|
|
|
if(event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-06-03 18:12:45 +02:00
|
|
|
sc_reload(NULL);
|
2010-06-03 18:05:34 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
/* main function */
|
2009-12-26 14:30:50 +01:00
|
|
|
int main(int argc, char* argv[])
|
2009-08-11 23:18:50 +02:00
|
|
|
{
|
2010-06-16 20:24:31 +02:00
|
|
|
/* embed */
|
|
|
|
Zathura.UI.embed = 0;
|
|
|
|
|
|
|
|
/* parse arguments */
|
|
|
|
int i;
|
|
|
|
for(i = 1; i < argc && argv[i][0] == '-' && argv[i][1] != '\0'; i++)
|
|
|
|
{
|
|
|
|
switch(argv[i][1])
|
|
|
|
{
|
|
|
|
case 'e':
|
|
|
|
if(++i < argc)
|
|
|
|
Zathura.UI.embed = atoi(argv[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
g_thread_init(NULL);
|
|
|
|
gdk_threads_init();
|
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
|
2010-06-16 20:24:31 +02:00
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
init_zathura();
|
2010-06-17 00:12:21 +02:00
|
|
|
init_keylist();
|
2010-06-14 21:52:19 +02:00
|
|
|
read_configuration();
|
2010-06-15 12:50:43 +02:00
|
|
|
init_settings();
|
|
|
|
init_look();
|
2010-01-31 02:03:28 +01:00
|
|
|
init_directories();
|
|
|
|
|
2010-06-16 20:24:31 +02:00
|
|
|
if(argc >= i+1)
|
|
|
|
open_file(argv[i], (argc == i+2) ? argv[i+1] : NULL);
|
2010-01-01 13:54:21 +01:00
|
|
|
|
2010-05-24 21:26:40 +02:00
|
|
|
switch_view(Zathura.UI.document);
|
2010-05-05 12:36:04 +02:00
|
|
|
update_status();
|
|
|
|
|
2009-12-26 14:30:50 +01:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window));
|
2010-06-16 20:24:31 +02:00
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view));
|
2010-01-28 14:14:01 +01:00
|
|
|
|
2010-04-10 14:33:23 +02:00
|
|
|
gdk_threads_enter();
|
2009-08-11 23:18:50 +02:00
|
|
|
gtk_main();
|
2010-04-10 14:33:23 +02:00
|
|
|
gdk_threads_leave();
|
2009-09-19 10:43:41 +02:00
|
|
|
|
2009-08-11 23:18:50 +02:00
|
|
|
return 0;
|
|
|
|
}
|