mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 13:05:59 +01:00
Merge branch 'master' of pwmt.org:zathura
This commit is contained in:
commit
da61a695bd
1 changed files with 55 additions and 39 deletions
94
zathura.c
94
zathura.c
|
@ -1,6 +1,7 @@
|
||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#define _BSD_SOURCE || _XOPEN_SOURCE >= 500
|
#define _BSD_SOURCE
|
||||||
|
#define _XOPEN_SOURCE 500
|
||||||
|
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -18,8 +19,14 @@
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
|
||||||
/* macros */
|
/* macros */
|
||||||
#define LENGTH(x) sizeof(x)/sizeof((x)[0])
|
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
#define CLEAN(m) (m & ~(GDK_MOD2_MASK) & ~(GDK_BUTTON1_MASK) & ~(GDK_BUTTON2_MASK) & ~(GDK_BUTTON3_MASK) & ~(GDK_BUTTON4_MASK) & ~(GDK_BUTTON5_MASK) & ~(GDK_LEAVE_NOTIFY_MASK))
|
#define CLEAN(m) (m & ~(GDK_MOD2_MASK) & ~(GDK_BUTTON1_MASK) & ~(GDK_BUTTON2_MASK) & ~(GDK_BUTTON3_MASK) & ~(GDK_BUTTON4_MASK) & ~(GDK_BUTTON5_MASK) & ~(GDK_LEAVE_NOTIFY_MASK))
|
||||||
|
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) || defined(__clang__)
|
||||||
|
/* only gcc, clang and Intel's cc seem support this */
|
||||||
|
#define NORETURN __attribute__((noreturn))
|
||||||
|
#else
|
||||||
|
#define NORETURN
|
||||||
|
#endif
|
||||||
|
|
||||||
/* enums */
|
/* enums */
|
||||||
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
|
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
|
||||||
|
@ -343,18 +350,18 @@ struct
|
||||||
|
|
||||||
|
|
||||||
/* function declarations */
|
/* function declarations */
|
||||||
void init_look();
|
void init_look(void);
|
||||||
void init_directories();
|
void init_directories(void);
|
||||||
void init_bookmarks();
|
void init_bookmarks(void);
|
||||||
void init_keylist();
|
void init_keylist(void);
|
||||||
void init_settings();
|
void init_settings(void);
|
||||||
void init_zathura();
|
void init_zathura(void);
|
||||||
void add_marker(int);
|
void add_marker(int);
|
||||||
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
|
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
|
||||||
void change_mode(int);
|
void change_mode(int);
|
||||||
void calculate_offset(GtkWidget*, double*, double*);
|
void calculate_offset(GtkWidget*, double*, double*);
|
||||||
void close_file(gboolean);
|
void close_file(gboolean);
|
||||||
void enter_password();
|
void enter_password(void);
|
||||||
void highlight_result(int, PopplerRectangle*);
|
void highlight_result(int, PopplerRectangle*);
|
||||||
void draw(int);
|
void draw(int);
|
||||||
void eval_marker(int);
|
void eval_marker(int);
|
||||||
|
@ -362,10 +369,10 @@ void notify(int, const char*);
|
||||||
gboolean open_file(char*, char*);
|
gboolean open_file(char*, char*);
|
||||||
gboolean open_stdin(gchar*);
|
gboolean open_stdin(gchar*);
|
||||||
void open_uri(char*);
|
void open_uri(char*);
|
||||||
void out_of_memory();
|
void out_of_memory(void) NORETURN;
|
||||||
void update_status();
|
void update_status(void);
|
||||||
void read_configuration_file(const char*);
|
void read_configuration_file(const char*);
|
||||||
void read_configuration();
|
void read_configuration(void);
|
||||||
void recalcRectangle(int, PopplerRectangle*);
|
void recalcRectangle(int, PopplerRectangle*);
|
||||||
void setCompletionRowColor(GtkBox*, int, int);
|
void setCompletionRowColor(GtkBox*, int, int);
|
||||||
void set_page(int);
|
void set_page(int);
|
||||||
|
@ -373,9 +380,9 @@ void switch_view(GtkWidget*);
|
||||||
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
|
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
|
||||||
gchar* fix_path(const gchar*);
|
gchar* fix_path(const gchar*);
|
||||||
gchar* path_from_env(const gchar*);
|
gchar* path_from_env(const gchar*);
|
||||||
gchar* get_home_dir();
|
gchar* get_home_dir(void);
|
||||||
|
|
||||||
Completion* completion_init();
|
Completion* completion_init(void);
|
||||||
CompletionGroup* completion_group_create(char*);
|
CompletionGroup* completion_group_create(char*);
|
||||||
void completion_add_group(Completion*, CompletionGroup*);
|
void completion_add_group(Completion*, CompletionGroup*);
|
||||||
void completion_free(Completion*);
|
void completion_free(Completion*);
|
||||||
|
@ -466,7 +473,7 @@ gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointe
|
||||||
|
|
||||||
/* function implementation */
|
/* function implementation */
|
||||||
void
|
void
|
||||||
init_look()
|
init_look(void)
|
||||||
{
|
{
|
||||||
/* parse */
|
/* parse */
|
||||||
gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg));
|
gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg));
|
||||||
|
@ -557,14 +564,14 @@ gchar* path_from_env(const gchar* var)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar* get_home_dir()
|
gchar* get_home_dir(void)
|
||||||
{
|
{
|
||||||
const gchar* homedir = g_getenv("HOME");
|
const gchar* homedir = g_getenv("HOME");
|
||||||
return g_strdup(homedir ? homedir : g_get_home_dir());
|
return g_strdup(homedir ? homedir : g_get_home_dir());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_directories()
|
init_directories(void)
|
||||||
{
|
{
|
||||||
/* setup directories */
|
/* setup directories */
|
||||||
if (!Zathura.Config.config_dir)
|
if (!Zathura.Config.config_dir)
|
||||||
|
@ -594,7 +601,7 @@ init_directories()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_bookmarks()
|
init_bookmarks(void)
|
||||||
{
|
{
|
||||||
/* create or open existing bookmark file */
|
/* create or open existing bookmark file */
|
||||||
Zathura.Bookmarks.data = g_key_file_new();
|
Zathura.Bookmarks.data = g_key_file_new();
|
||||||
|
@ -619,7 +626,7 @@ init_bookmarks()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_keylist()
|
init_keylist(void)
|
||||||
{
|
{
|
||||||
ShortcutList* e = NULL;
|
ShortcutList* e = NULL;
|
||||||
ShortcutList* p = NULL;
|
ShortcutList* p = NULL;
|
||||||
|
@ -644,7 +651,7 @@ init_keylist()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_settings()
|
init_settings(void)
|
||||||
{
|
{
|
||||||
Zathura.State.filename = g_strdup((char*) default_text);
|
Zathura.State.filename = g_strdup((char*) default_text);
|
||||||
Zathura.Global.adjust_mode = adjust_open;
|
Zathura.Global.adjust_mode = adjust_open;
|
||||||
|
@ -653,7 +660,7 @@ init_settings()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_zathura()
|
init_zathura(void)
|
||||||
{
|
{
|
||||||
/* init mutexes */
|
/* init mutexes */
|
||||||
g_static_mutex_init(&(Zathura.Lock.pdflib_lock));
|
g_static_mutex_init(&(Zathura.Lock.pdflib_lock));
|
||||||
|
@ -1126,7 +1133,7 @@ close_file(gboolean keep_monitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
enter_password()
|
enter_password(void)
|
||||||
{
|
{
|
||||||
/* replace default inputbar handler */
|
/* replace default inputbar handler */
|
||||||
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
|
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
|
||||||
|
@ -1418,30 +1425,43 @@ open_stdin(gchar* password)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read from stdin and dump to temporary file
|
// read from stdin and dump to temporary file
|
||||||
|
int stdinfno = fileno(stdin);
|
||||||
|
if (stdinfno == -1)
|
||||||
|
{
|
||||||
|
gchar* message = g_strdup_printf("Can not read from stdin.");
|
||||||
|
notify(ERROR, message);
|
||||||
|
g_free(message);
|
||||||
|
close(handle);
|
||||||
|
g_unlink(file);
|
||||||
|
g_free(file);
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
ssize_t count = 0;
|
ssize_t count = 0;
|
||||||
while ((count = read(0, buffer, BUFSIZ)) > 0)
|
while ((count = read(stdinfno, buffer, BUFSIZ)) > 0)
|
||||||
{
|
{
|
||||||
if (write(handle, buffer, count) != count)
|
if (write(handle, buffer, count) != count)
|
||||||
{
|
{
|
||||||
gchar* message = g_strdup_printf("Can not write to temporary file: %s", file);
|
gchar* message = g_strdup_printf("Can not write to temporary file: %s", file);
|
||||||
notify(ERROR, message);
|
notify(ERROR, message);
|
||||||
g_free(message);
|
g_free(message);
|
||||||
|
close(handle);
|
||||||
g_unlink(file);
|
g_unlink(file);
|
||||||
g_free(file);
|
g_free(file);
|
||||||
close(handle);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
{
|
{
|
||||||
gchar* message = g_strdup_printf("Can not read from stdin");
|
gchar* message = g_strdup_printf("Can not read from stdin.");
|
||||||
notify(ERROR, message);
|
notify(ERROR, message);
|
||||||
g_free(message);
|
g_free(message);
|
||||||
|
close(handle);
|
||||||
g_unlink(file);
|
g_unlink(file);
|
||||||
g_free(file);
|
g_free(file);
|
||||||
close(handle);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1463,14 +1483,14 @@ void open_uri(char* uri)
|
||||||
g_free(escaped_uri);
|
g_free(escaped_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_of_memory()
|
void out_of_memory(void)
|
||||||
{
|
{
|
||||||
printf("error: out of memory\n");
|
printf("error: out of memory\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
update_status()
|
update_status(void)
|
||||||
{
|
{
|
||||||
/* update text */
|
/* update text */
|
||||||
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename);
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename);
|
||||||
|
@ -1530,7 +1550,7 @@ read_configuration_file(const char* rcfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
read_configuration()
|
read_configuration(void)
|
||||||
{
|
{
|
||||||
char* zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL);
|
char* zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL);
|
||||||
read_configuration_file(GLOBAL_RC);
|
read_configuration_file(GLOBAL_RC);
|
||||||
|
@ -1702,7 +1722,7 @@ switch_view(GtkWidget* widget)
|
||||||
}
|
}
|
||||||
|
|
||||||
Completion*
|
Completion*
|
||||||
completion_init()
|
completion_init(void)
|
||||||
{
|
{
|
||||||
Completion *completion = malloc(sizeof(Completion));
|
Completion *completion = malloc(sizeof(Completion));
|
||||||
if(!completion)
|
if(!completion)
|
||||||
|
@ -2010,14 +2030,14 @@ sc_follow(Argument* argument)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number];
|
Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number];
|
||||||
int number_of_links = 0, link_id = 1;
|
int link_id = 1;
|
||||||
|
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
||||||
GList *link_list = poppler_page_get_link_mapping(current_page->page);
|
GList *link_list = poppler_page_get_link_mapping(current_page->page);
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
||||||
link_list = g_list_reverse(link_list);
|
link_list = g_list_reverse(link_list);
|
||||||
|
|
||||||
if((number_of_links = g_list_length(link_list)) <= 0)
|
if(g_list_length(link_list) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GList *links;
|
GList *links;
|
||||||
|
@ -2142,7 +2162,6 @@ sc_scroll(Argument* argument)
|
||||||
gdouble view_size = gtk_adjustment_get_page_size(adjustment);
|
gdouble view_size = gtk_adjustment_get_page_size(adjustment);
|
||||||
gdouble value = gtk_adjustment_get_value(adjustment);
|
gdouble value = gtk_adjustment_get_value(adjustment);
|
||||||
gdouble max = gtk_adjustment_get_upper(adjustment) - view_size;
|
gdouble max = gtk_adjustment_get_upper(adjustment) - view_size;
|
||||||
gdouble new_value = value;
|
|
||||||
gboolean static ss = FALSE;
|
gboolean static ss = FALSE;
|
||||||
|
|
||||||
if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0)
|
if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0)
|
||||||
|
@ -2163,7 +2182,9 @@ sc_scroll(Argument* argument)
|
||||||
sc_navigate(&arg);
|
sc_navigate(&arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(argument->n == FULL_UP)
|
|
||||||
|
gdouble new_value;
|
||||||
|
if(argument->n == FULL_UP)
|
||||||
new_value = (value - view_size) < 0 ? 0 : (value - view_size);
|
new_value = (value - view_size) < 0 ? 0 : (value - view_size);
|
||||||
else if(argument->n == FULL_DOWN)
|
else if(argument->n == FULL_DOWN)
|
||||||
new_value = (value + view_size) > max ? max : (value + view_size);
|
new_value = (value + view_size) > max ? max : (value + view_size);
|
||||||
|
@ -2544,14 +2565,12 @@ isc_completion(Argument* argument)
|
||||||
char* current_command;
|
char* current_command;
|
||||||
char* current_parameter;
|
char* current_parameter;
|
||||||
int current_command_length;
|
int current_command_length;
|
||||||
int current_parameter_length;
|
|
||||||
|
|
||||||
if(!first_space)
|
if(!first_space)
|
||||||
{
|
{
|
||||||
current_command = g_strdup(input);
|
current_command = g_strdup(input);
|
||||||
current_command_length = length;
|
current_command_length = length;
|
||||||
current_parameter = NULL;
|
current_parameter = NULL;
|
||||||
current_parameter_length = 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2559,7 +2578,6 @@ isc_completion(Argument* argument)
|
||||||
current_command = g_strndup(input, offset);
|
current_command = g_strndup(input, offset);
|
||||||
current_command_length = strlen(current_command);
|
current_command_length = strlen(current_command);
|
||||||
current_parameter = input + offset + 1;
|
current_parameter = input + offset + 1;
|
||||||
current_parameter_length = strlen(current_parameter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the identifier does not match the command sign and
|
/* if the identifier does not match the command sign and
|
||||||
|
@ -3074,13 +3092,11 @@ cmd_export(int argc, char** argv)
|
||||||
for(images = image_list; images; images = g_list_next(images))
|
for(images = image_list; images; images = g_list_next(images))
|
||||||
{
|
{
|
||||||
PopplerImageMapping *image_mapping;
|
PopplerImageMapping *image_mapping;
|
||||||
PopplerRectangle image_field;
|
|
||||||
gint image_id;
|
gint image_id;
|
||||||
char* file;
|
char* file;
|
||||||
char* filename;
|
char* filename;
|
||||||
|
|
||||||
image_mapping = (PopplerImageMapping*) images->data;
|
image_mapping = (PopplerImageMapping*) images->data;
|
||||||
image_field = image_mapping->area;
|
|
||||||
image_id = image_mapping->image_id;
|
image_id = image_mapping->image_id;
|
||||||
|
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
||||||
|
|
Loading…
Reference in a new issue