mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-31 09:04:57 +01:00
Advanced notification - Basic search function
Added following functionality: * Notification via vanishing pop-ups, different notification levels and changeable text2 * Basic search function * Check file existence * Scroll to begin or bottom of a page Fixes and other changes: * Fixed unnecessary high processor load * Fixed update status * Added variable for number of pages
This commit is contained in:
parent
00e5216940
commit
9134c458aa
2 changed files with 215 additions and 88 deletions
19
config.h
19
config.h
|
@ -1,20 +1,29 @@
|
||||||
|
/* settings */
|
||||||
|
static const int SHOW_NOTIFICATION = 5;
|
||||||
static const float ZOOM_STEP = 0.1;
|
static const float ZOOM_STEP = 0.1;
|
||||||
static const float SCROLL_STEP = 40;
|
static const float SCROLL_STEP = 40;
|
||||||
|
|
||||||
|
/* look */
|
||||||
static const char font[] = "monospace normal 9";
|
static const char font[] = "monospace normal 9";
|
||||||
static const char default_bgcolor[] = "#141414";
|
static const char default_bgcolor[] = "#141414";
|
||||||
static const char default_fgcolor[] = "#CCCCCC";
|
static const char default_fgcolor[] = "#CCCCCC";
|
||||||
|
|
||||||
|
static const char notification_fgcolor[] = "#0F0F0F";
|
||||||
|
static const char notification_bgcolor[] = "#F9F9F9";
|
||||||
|
static const char notification_warning_fgcolor[] = "2222222";
|
||||||
|
static const char notification_warning_bgcolor[] = "#E8E62E";
|
||||||
|
static const char notification_error_fgcolor[] = "#CCCCCC";
|
||||||
|
static const char notification_error_bgcolor[] = "#B82121";
|
||||||
|
|
||||||
static const char inputbar_bgcolor[] = "#141414";
|
static const char inputbar_bgcolor[] = "#141414";
|
||||||
static const char inputbar_fgcolor[] = "#9FBC00";
|
static const char inputbar_fgcolor[] = "#9FBC00";
|
||||||
static const char inputbar_wn_fgcolor[] = "#CCCCCC";
|
|
||||||
static const char inputbar_wn_bgcolor[] = "#B82121";
|
|
||||||
|
|
||||||
static const char completion_fgcolor[] = "#CCCCCC";
|
static const char completion_fgcolor[] = "#CCCCCC";
|
||||||
static const char completion_bgcolor[] = "#232323";
|
static const char completion_bgcolor[] = "#232323";
|
||||||
static const char completion_hl_fgcolor[] = "#232323";
|
static const char completion_hl_fgcolor[] = "#232323";
|
||||||
static const char completion_hl_bgcolor[] = "#9FBC00";
|
static const char completion_hl_bgcolor[] = "#9FBC00";
|
||||||
|
|
||||||
|
/* shortcuts */
|
||||||
Shortcut shortcuts[] = {
|
Shortcut shortcuts[] = {
|
||||||
// mask, key, function, argument
|
// mask, key, function, argument
|
||||||
{GDK_CONTROL_MASK, GDK_f, sc_navigate, { NEXT } },
|
{GDK_CONTROL_MASK, GDK_f, sc_navigate, { NEXT } },
|
||||||
|
@ -24,11 +33,16 @@ Shortcut shortcuts[] = {
|
||||||
{GDK_CONTROL_MASK, GDK_0, sc_zoom, { ZOOM_ORIGINAL } },
|
{GDK_CONTROL_MASK, GDK_0, sc_zoom, { ZOOM_ORIGINAL } },
|
||||||
{GDK_CONTROL_MASK, GDK_r, sc_rotate, { RIGHT } },
|
{GDK_CONTROL_MASK, GDK_r, sc_rotate, { RIGHT } },
|
||||||
{GDK_CONTROL_MASK, GDK_e, sc_rotate, { LEFT } },
|
{GDK_CONTROL_MASK, GDK_e, sc_rotate, { LEFT } },
|
||||||
|
{GDK_CONTROL_MASK, GDK_p, sc_print, {0} },
|
||||||
{GDK_CONTROL_MASK, GDK_q, sc_quit, {0} },
|
{GDK_CONTROL_MASK, GDK_q, sc_quit, {0} },
|
||||||
|
{0, GDK_n, sc_search, { FORWARD } },
|
||||||
|
{0, GDK_N, sc_search, { BACKWARD } },
|
||||||
{0, GDK_h, sc_scroll, { LEFT } },
|
{0, GDK_h, sc_scroll, { LEFT } },
|
||||||
{0, GDK_j, sc_scroll, { DOWN } },
|
{0, GDK_j, sc_scroll, { DOWN } },
|
||||||
{0, GDK_k, sc_scroll, { UP } },
|
{0, GDK_k, sc_scroll, { UP } },
|
||||||
{0, GDK_l, sc_scroll, { RIGHT } },
|
{0, GDK_l, sc_scroll, { RIGHT } },
|
||||||
|
{0, GDK_Page_Up, sc_scroll, { TOP } },
|
||||||
|
{0, GDK_Page_Down, sc_scroll, { BOTTOM } },
|
||||||
{0, GDK_i, sc_adjust_window, { ADJUST_BESTFIT } },
|
{0, GDK_i, sc_adjust_window, { ADJUST_BESTFIT } },
|
||||||
{0, GDK_u, sc_adjust_window, { ADJUST_WIDTH } },
|
{0, GDK_u, sc_adjust_window, { ADJUST_WIDTH } },
|
||||||
{0, GDK_colon, sc_focus_inputbar, { .data = ":" } },
|
{0, GDK_colon, sc_focus_inputbar, { .data = ":" } },
|
||||||
|
@ -39,6 +53,7 @@ Shortcut shortcuts[] = {
|
||||||
{0, GDK_slash, sc_focus_inputbar, { .data = "/" } },
|
{0, GDK_slash, sc_focus_inputbar, { .data = "/" } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* commands */
|
||||||
Command commands[] = {
|
Command commands[] = {
|
||||||
// command, function
|
// command, function
|
||||||
{"g", cmd_goto},
|
{"g", cmd_goto},
|
||||||
|
|
244
zathura.c
244
zathura.c
|
@ -1,5 +1,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <poppler/glib/poppler.h>
|
#include <poppler/glib/poppler.h>
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
@ -12,8 +13,8 @@
|
||||||
|
|
||||||
/* enums */
|
/* enums */
|
||||||
enum { UP, DOWN, LEFT, RIGHT, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL,
|
enum { UP, DOWN, LEFT, RIGHT, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL,
|
||||||
NEXT, PREVIOUS, HIDE, ERROR, WARNING, DEFAULT,
|
NEXT, PREVIOUS, HIDE, ERROR, WARNING, DEFAULT, TOP, BOTTOM,
|
||||||
ADJUST_BESTFIT, ADJUST_WIDTH };
|
ADJUST_BESTFIT, ADJUST_WIDTH, FORWARD, BACKWARD };
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -21,6 +22,7 @@ struct
|
||||||
GtkBox *box;
|
GtkBox *box;
|
||||||
GtkScrolledWindow *view;
|
GtkScrolledWindow *view;
|
||||||
GtkWidget *drawing_area;
|
GtkWidget *drawing_area;
|
||||||
|
GtkBox *notification;
|
||||||
GtkEntry *inputbar;
|
GtkEntry *inputbar;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -29,8 +31,12 @@ struct
|
||||||
GdkColor default_bg;
|
GdkColor default_bg;
|
||||||
GdkColor inputbar_fg;
|
GdkColor inputbar_fg;
|
||||||
GdkColor inputbar_bg;
|
GdkColor inputbar_bg;
|
||||||
GdkColor inputbar_wn_fg;
|
GdkColor notification_fg;
|
||||||
GdkColor inputbar_wn_bg;
|
GdkColor notification_bg;
|
||||||
|
GdkColor notification_wn_fg;
|
||||||
|
GdkColor notification_wn_bg;
|
||||||
|
GdkColor notification_er_fg;
|
||||||
|
GdkColor notification_er_bg;
|
||||||
GdkColor completion_fg;
|
GdkColor completion_fg;
|
||||||
GdkColor completion_bg;
|
GdkColor completion_bg;
|
||||||
GdkColor completion_hl_fg;
|
GdkColor completion_hl_fg;
|
||||||
|
@ -42,11 +48,12 @@ struct
|
||||||
{
|
{
|
||||||
PopplerDocument *document;
|
PopplerDocument *document;
|
||||||
PopplerPage *page;
|
PopplerPage *page;
|
||||||
|
char *file;
|
||||||
|
cairo_surface_t *surface;
|
||||||
int page_number;
|
int page_number;
|
||||||
|
int number_of_pages;
|
||||||
double scale;
|
double scale;
|
||||||
int rotate;
|
int rotate;
|
||||||
cairo_surface_t *surface;
|
|
||||||
char *file;
|
|
||||||
} PDF;
|
} PDF;
|
||||||
|
|
||||||
} Zathura;
|
} Zathura;
|
||||||
|
@ -74,11 +81,14 @@ typedef struct
|
||||||
/* function declarations */
|
/* function declarations */
|
||||||
void init();
|
void init();
|
||||||
void update_title();
|
void update_title();
|
||||||
void update_status(int, char*);
|
void update_status();
|
||||||
void set_page(int);
|
void set_page(int);
|
||||||
void draw();
|
void draw();
|
||||||
|
void hilight_result(PopplerRectangle*);
|
||||||
|
|
||||||
gboolean complete(Argument*);
|
gboolean complete(Argument*);
|
||||||
|
gboolean delete_widget(gpointer);
|
||||||
|
GtkLabel* notify(int, char*);
|
||||||
|
|
||||||
/* shortcut declarations */
|
/* shortcut declarations */
|
||||||
void sc_focus_inputbar(Argument*);
|
void sc_focus_inputbar(Argument*);
|
||||||
|
@ -87,13 +97,14 @@ void sc_navigate(Argument*);
|
||||||
void sc_zoom(Argument*);
|
void sc_zoom(Argument*);
|
||||||
void sc_adjust_window(Argument*);
|
void sc_adjust_window(Argument*);
|
||||||
void sc_rotate(Argument*);
|
void sc_rotate(Argument*);
|
||||||
|
void sc_search(Argument*);
|
||||||
|
void sc_print(Argument*);
|
||||||
void sc_quit(Argument*);
|
void sc_quit(Argument*);
|
||||||
|
|
||||||
/* command declarations */
|
/* command declarations */
|
||||||
void cmd_goto(int, char**);
|
void cmd_goto(int, char**);
|
||||||
void cmd_open(int, char**);
|
void cmd_open(int, char**);
|
||||||
void cmd_rotate(int, char**);
|
void cmd_rotate(int, char**);
|
||||||
void cmd_search(int, char**);
|
|
||||||
void cmd_quit(int, char**);
|
void cmd_quit(int, char**);
|
||||||
void cmd_zoom(int, char**);
|
void cmd_zoom(int, char**);
|
||||||
|
|
||||||
|
@ -119,8 +130,12 @@ init()
|
||||||
gdk_color_parse(default_bgcolor, &(Zathura.Settings.default_bg));
|
gdk_color_parse(default_bgcolor, &(Zathura.Settings.default_bg));
|
||||||
gdk_color_parse(inputbar_fgcolor, &(Zathura.Settings.inputbar_fg));
|
gdk_color_parse(inputbar_fgcolor, &(Zathura.Settings.inputbar_fg));
|
||||||
gdk_color_parse(inputbar_bgcolor, &(Zathura.Settings.inputbar_bg));
|
gdk_color_parse(inputbar_bgcolor, &(Zathura.Settings.inputbar_bg));
|
||||||
gdk_color_parse(inputbar_wn_fgcolor, &(Zathura.Settings.inputbar_wn_fg));
|
gdk_color_parse(notification_fgcolor, &(Zathura.Settings.notification_fg));
|
||||||
gdk_color_parse(inputbar_wn_bgcolor, &(Zathura.Settings.inputbar_wn_bg));
|
gdk_color_parse(notification_bgcolor, &(Zathura.Settings.notification_bg));
|
||||||
|
gdk_color_parse(notification_warning_fgcolor, &(Zathura.Settings.notification_wn_fg));
|
||||||
|
gdk_color_parse(notification_warning_bgcolor, &(Zathura.Settings.notification_wn_bg));
|
||||||
|
gdk_color_parse(notification_error_fgcolor, &(Zathura.Settings.notification_er_fg));
|
||||||
|
gdk_color_parse(notification_error_bgcolor, &(Zathura.Settings.notification_er_bg));
|
||||||
gdk_color_parse(completion_fgcolor, &(Zathura.Settings.completion_fg));
|
gdk_color_parse(completion_fgcolor, &(Zathura.Settings.completion_fg));
|
||||||
gdk_color_parse(completion_bgcolor, &(Zathura.Settings.completion_bg));
|
gdk_color_parse(completion_bgcolor, &(Zathura.Settings.completion_bg));
|
||||||
gdk_color_parse(completion_hl_fgcolor, &(Zathura.Settings.completion_hl_fg));
|
gdk_color_parse(completion_hl_fgcolor, &(Zathura.Settings.completion_hl_fg));
|
||||||
|
@ -132,6 +147,7 @@ init()
|
||||||
Zathura.box = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
Zathura.box = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
||||||
Zathura.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
|
Zathura.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
|
||||||
Zathura.drawing_area = gtk_drawing_area_new();
|
Zathura.drawing_area = gtk_drawing_area_new();
|
||||||
|
Zathura.notification = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
||||||
Zathura.inputbar = GTK_ENTRY(gtk_entry_new());
|
Zathura.inputbar = GTK_ENTRY(gtk_entry_new());
|
||||||
Zathura.PDF.scale = 1.0;
|
Zathura.PDF.scale = 1.0;
|
||||||
Zathura.PDF.rotate = 0;
|
Zathura.PDF.rotate = 0;
|
||||||
|
@ -149,15 +165,15 @@ init()
|
||||||
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(Zathura.view), Zathura.drawing_area);
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(Zathura.view), Zathura.drawing_area);
|
||||||
g_signal_connect(G_OBJECT(Zathura.view), "key-press-event", G_CALLBACK(cb_view_key_pressed), NULL);
|
g_signal_connect(G_OBJECT(Zathura.view), "key-press-event", G_CALLBACK(cb_view_key_pressed), NULL);
|
||||||
|
|
||||||
/* drawing area */
|
|
||||||
g_signal_connect(G_OBJECT(Zathura.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL);
|
|
||||||
|
|
||||||
#ifdef SHOW_SCROLLBARS
|
#ifdef SHOW_SCROLLBARS
|
||||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||||
#else
|
#else
|
||||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.view), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.view), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* drawing area */
|
||||||
|
g_signal_connect(G_OBJECT(Zathura.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL);
|
||||||
|
|
||||||
/* inputbar */
|
/* inputbar */
|
||||||
gtk_entry_set_inner_border(Zathura.inputbar, NULL);
|
gtk_entry_set_inner_border(Zathura.inputbar, NULL);
|
||||||
gtk_entry_set_has_frame(Zathura.inputbar, FALSE);
|
gtk_entry_set_has_frame(Zathura.inputbar, FALSE);
|
||||||
|
@ -169,6 +185,7 @@ init()
|
||||||
|
|
||||||
/* packing */
|
/* packing */
|
||||||
gtk_box_pack_start(Zathura.box, GTK_WIDGET(Zathura.view), TRUE, TRUE, 0);
|
gtk_box_pack_start(Zathura.box, GTK_WIDGET(Zathura.view), TRUE, TRUE, 0);
|
||||||
|
gtk_box_pack_start(Zathura.box, GTK_WIDGET(Zathura.notification), FALSE, FALSE, 0);
|
||||||
gtk_box_pack_end(Zathura.box, GTK_WIDGET(Zathura.inputbar), FALSE, FALSE, 0);
|
gtk_box_pack_end(Zathura.box, GTK_WIDGET(Zathura.inputbar), FALSE, FALSE, 0);
|
||||||
|
|
||||||
/* visuals */
|
/* visuals */
|
||||||
|
@ -181,34 +198,56 @@ void
|
||||||
update_title()
|
update_title()
|
||||||
{
|
{
|
||||||
if(Zathura.PDF.file != NULL)
|
if(Zathura.PDF.file != NULL)
|
||||||
gtk_window_set_title(GTK_WINDOW(Zathura.window), Zathura.PDF.file + strlen("file://"));
|
gtk_window_set_title(GTK_WINDOW(Zathura.window), Zathura.PDF.file);
|
||||||
else
|
else
|
||||||
gtk_window_set_title(GTK_WINDOW(Zathura.window), "zathura");
|
gtk_window_set_title(GTK_WINDOW(Zathura.window), "zathura");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
GtkLabel*
|
||||||
update_status(int level, char* text)
|
notify(int level, char* text)
|
||||||
{
|
{
|
||||||
|
GtkLabel *message = GTK_LABEL(gtk_label_new(text));
|
||||||
|
GtkEventBox *view = GTK_EVENT_BOX(gtk_event_box_new());
|
||||||
|
|
||||||
|
gtk_misc_set_alignment(GTK_MISC(message), 0, 0);
|
||||||
|
gtk_widget_modify_font(GTK_WIDGET(message), Zathura.Settings.font);
|
||||||
|
|
||||||
if(level == WARNING)
|
if(level == WARNING)
|
||||||
{
|
{
|
||||||
gtk_widget_modify_text(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_wn_fg));
|
gtk_widget_modify_fg(GTK_WIDGET(message), GTK_STATE_NORMAL, &(Zathura.Settings.notification_wn_fg));
|
||||||
gtk_widget_modify_base(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_wn_bg));
|
gtk_widget_modify_bg(GTK_WIDGET(view), GTK_STATE_NORMAL, &(Zathura.Settings.notification_wn_bg));
|
||||||
}
|
}
|
||||||
else if(level == DEFAULT)
|
else if(level == ERROR)
|
||||||
{
|
{
|
||||||
gtk_widget_modify_text(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_fg));
|
gtk_widget_modify_fg(GTK_WIDGET(message), GTK_STATE_NORMAL, &(Zathura.Settings.notification_er_fg));
|
||||||
gtk_widget_modify_base(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_bg));
|
gtk_widget_modify_bg(GTK_WIDGET(view), GTK_STATE_NORMAL, &(Zathura.Settings.notification_er_bg));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_widget_modify_fg(GTK_WIDGET(message), GTK_STATE_NORMAL, &(Zathura.Settings.notification_fg));
|
||||||
|
gtk_widget_modify_bg(GTK_WIDGET(view), GTK_STATE_NORMAL, &(Zathura.Settings.notification_bg));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(text == (char*) "")
|
gtk_container_add(GTK_CONTAINER(view), GTK_WIDGET(message));
|
||||||
|
gtk_container_add(GTK_CONTAINER(Zathura.notification), GTK_WIDGET(view));
|
||||||
|
|
||||||
|
gtk_widget_show_all(GTK_WIDGET(Zathura.window));
|
||||||
|
g_timeout_add_seconds(SHOW_NOTIFICATION, delete_widget, GTK_WIDGET(GTK_WIDGET(view)));
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
update_status()
|
||||||
{
|
{
|
||||||
|
char* text = "";
|
||||||
|
|
||||||
if(Zathura.PDF.document && Zathura.PDF.page)
|
if(Zathura.PDF.document && Zathura.PDF.page)
|
||||||
{
|
{
|
||||||
char* show_page = g_strdup_printf("[%i/%i]", Zathura.PDF.page_number + 1,
|
char* show_page = g_strdup_printf("[%i/%i]", Zathura.PDF.page_number + 1,
|
||||||
poppler_document_get_n_pages(Zathura.PDF.document));
|
Zathura.PDF.number_of_pages);
|
||||||
char* filename = Zathura.PDF.file + strlen("file://");
|
text = g_strdup_printf("%s %s", show_page, Zathura.PDF.file);
|
||||||
text = g_strdup_printf("%s %s", show_page, filename);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_entry_set_text(Zathura.inputbar, text);
|
gtk_entry_set_text(Zathura.inputbar, text);
|
||||||
|
@ -216,9 +255,9 @@ update_status(int level, char* text)
|
||||||
|
|
||||||
void set_page(int page_number)
|
void set_page(int page_number)
|
||||||
{
|
{
|
||||||
if(page_number > poppler_document_get_n_pages(Zathura.PDF.document))
|
if(page_number > Zathura.PDF.number_of_pages)
|
||||||
{
|
{
|
||||||
update_status(WARNING, "Error: Could not open page");
|
notify(WARNING, "Could not open page");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,10 +331,23 @@ draw()
|
||||||
gtk_widget_queue_draw(Zathura.drawing_area);
|
gtk_widget_queue_draw(Zathura.drawing_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hilight_result(PopplerRectangle* rectangle)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
delete_widget(gpointer data)
|
||||||
|
{
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(data));
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
complete(Argument* argument)
|
complete(Argument* argument)
|
||||||
{
|
{
|
||||||
|
|
||||||
static GtkBox *results;
|
static GtkBox *results;
|
||||||
static GtkWidget **result_rows;
|
static GtkWidget **result_rows;
|
||||||
static char **command_names;
|
static char **command_names;
|
||||||
|
@ -434,6 +486,10 @@ sc_scroll(Argument *argument)
|
||||||
|
|
||||||
if( (argument->n == LEFT) || (argument->n == DOWN))
|
if( (argument->n == LEFT) || (argument->n == DOWN))
|
||||||
gtk_adjustment_set_value(adjustment, (value - SCROLL_STEP) < 0 ? 0 : (value - SCROLL_STEP));
|
gtk_adjustment_set_value(adjustment, (value - SCROLL_STEP) < 0 ? 0 : (value - SCROLL_STEP));
|
||||||
|
else if (argument->n == TOP)
|
||||||
|
gtk_adjustment_set_value(adjustment, 0);
|
||||||
|
else if(argument->n == BOTTOM)
|
||||||
|
gtk_adjustment_set_value(adjustment, max);
|
||||||
else
|
else
|
||||||
gtk_adjustment_set_value(adjustment, (value + SCROLL_STEP) > max ? max : (value + SCROLL_STEP));
|
gtk_adjustment_set_value(adjustment, (value + SCROLL_STEP) > max ? max : (value + SCROLL_STEP));
|
||||||
}
|
}
|
||||||
|
@ -449,11 +505,15 @@ sc_navigate(Argument *argument)
|
||||||
else if(argument->n == PREVIOUS)
|
else if(argument->n == PREVIOUS)
|
||||||
new_page = abs( (new_page + number_of_pages - 1) % number_of_pages);
|
new_page = abs( (new_page + number_of_pages - 1) % number_of_pages);
|
||||||
|
|
||||||
Zathura.PDF.page = poppler_document_get_page(Zathura.PDF.document, new_page);
|
set_page(new_page);
|
||||||
Zathura.PDF.page_number = new_page;
|
|
||||||
|
Argument reset;
|
||||||
|
reset.n = TOP;
|
||||||
|
sc_scroll(&reset);
|
||||||
|
|
||||||
update_status(DEFAULT, "");
|
|
||||||
draw();
|
draw();
|
||||||
|
|
||||||
|
update_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -504,6 +564,60 @@ sc_rotate(Argument *argument)
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_search(Argument *argument)
|
||||||
|
{
|
||||||
|
static char* search_item;
|
||||||
|
static int direction;
|
||||||
|
int page_counter;
|
||||||
|
GList* results;
|
||||||
|
GList* list;
|
||||||
|
|
||||||
|
if(argument->data)
|
||||||
|
search_item = (char*) argument->data;
|
||||||
|
|
||||||
|
if(!Zathura.PDF.document || !Zathura.PDF.page || !search_item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* search document */
|
||||||
|
GtkLabel* search_status = notify(DEFAULT, "Searching...");
|
||||||
|
if(argument->n)
|
||||||
|
direction = (argument->n == BACKWARD) ? -1 : 1;
|
||||||
|
|
||||||
|
for(page_counter = 0; page_counter < Zathura.PDF.number_of_pages; page_counter++)
|
||||||
|
{
|
||||||
|
int next_page = (Zathura.PDF.page_number + page_counter * direction) % Zathura.PDF.number_of_pages;
|
||||||
|
set_page(next_page);
|
||||||
|
|
||||||
|
results = poppler_page_find_text(Zathura.PDF.page, search_item);
|
||||||
|
if(results)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw results */
|
||||||
|
if(results)
|
||||||
|
{
|
||||||
|
draw();
|
||||||
|
|
||||||
|
gtk_label_set_text(search_status, g_strdup_printf("%s found on page %i for %i time(s)",
|
||||||
|
search_item, Zathura.PDF.page_number, g_list_length(results)));
|
||||||
|
|
||||||
|
for(list = results; list && list->data; list = g_list_next(list))
|
||||||
|
{
|
||||||
|
hilight_result((PopplerRectangle*) list->data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gtk_label_set_text(search_status, g_strdup_printf("No match for %s", search_item));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_print(Argument *argument)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_quit(Argument *argument)
|
sc_quit(Argument *argument)
|
||||||
{
|
{
|
||||||
|
@ -519,6 +633,12 @@ cmd_open(int argc, char** argv)
|
||||||
|
|
||||||
gchar* file;
|
gchar* file;
|
||||||
|
|
||||||
|
if(!g_file_test(argv[0], G_FILE_TEST_EXISTS))
|
||||||
|
{
|
||||||
|
notify(ERROR, "File does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(g_ascii_strncasecmp(argv[0], "file://", strlen("file://")) == 0)
|
if(g_ascii_strncasecmp(argv[0], "file://", strlen("file://")) == 0)
|
||||||
file = g_strdup(argv[0]);
|
file = g_strdup(argv[0]);
|
||||||
else
|
else
|
||||||
|
@ -527,16 +647,17 @@ cmd_open(int argc, char** argv)
|
||||||
Zathura.PDF.document = poppler_document_new_from_file(file, (argc == 2) ? argv[1] : NULL, NULL);
|
Zathura.PDF.document = poppler_document_new_from_file(file, (argc == 2) ? argv[1] : NULL, NULL);
|
||||||
if(!Zathura.PDF.document)
|
if(!Zathura.PDF.document)
|
||||||
{
|
{
|
||||||
printf("Error: Could not open file %s\n", file);
|
notify(WARNING, "Can not open file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zathura.PDF.file = file;
|
Zathura.PDF.number_of_pages = poppler_document_get_n_pages(Zathura.PDF.document);
|
||||||
|
Zathura.PDF.file = file + strlen("file://");
|
||||||
set_page(0);
|
set_page(0);
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
|
|
||||||
update_status(DEFAULT, "");
|
update_status();
|
||||||
update_title();
|
update_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,7 +668,15 @@ cmd_goto(int argc, char** argv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int page = atoi(argv[0]);;
|
int page = atoi(argv[0]);;
|
||||||
set_page(page);
|
set_page(page - 1);
|
||||||
|
|
||||||
|
Argument argument;
|
||||||
|
argument.n = TOP;
|
||||||
|
sc_scroll(&argument);
|
||||||
|
|
||||||
|
draw();
|
||||||
|
|
||||||
|
update_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -568,24 +697,6 @@ cmd_rotate(int argc, char** argv)
|
||||||
sc_rotate(&argument);
|
sc_rotate(&argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
cmd_search(int argc, char** argv)
|
|
||||||
{
|
|
||||||
if(!Zathura.PDF.document || !Zathura.PDF.page || !argv[0])
|
|
||||||
return;
|
|
||||||
|
|
||||||
GList* results = poppler_page_find_text(Zathura.PDF.page, argv[0]);
|
|
||||||
GList* list;
|
|
||||||
|
|
||||||
if(results)
|
|
||||||
{
|
|
||||||
for(list = results; list && list->data; list = g_list_next(list))
|
|
||||||
{
|
|
||||||
//PopplerRectangle *rectangle = (PopplerRectangle*) list->data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_zoom(int argc, char** argv)
|
cmd_zoom(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -612,8 +723,6 @@ cb_draw(GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
gdk_window_clear(widget->window);
|
gdk_window_clear(widget->window);
|
||||||
|
|
||||||
draw();
|
|
||||||
|
|
||||||
cairo_t *cairo = gdk_cairo_create(widget->window);
|
cairo_t *cairo = gdk_cairo_create(widget->window);
|
||||||
cairo_set_source_surface(cairo, Zathura.PDF.surface, 0, 0);
|
cairo_set_source_surface(cairo, Zathura.PDF.surface, 0, 0);
|
||||||
cairo_paint(cairo);
|
cairo_paint(cairo);
|
||||||
|
@ -661,11 +770,13 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data)
|
||||||
// special command
|
// special command
|
||||||
if(*tokens[0] == '/')
|
if(*tokens[0] == '/')
|
||||||
{
|
{
|
||||||
char *term = (char*) gtk_entry_get_text(entry) + 1;
|
Argument argument;
|
||||||
cmd_search(1, &term);
|
argument.data = (char*) gtk_entry_get_text(entry) + 1;
|
||||||
|
argument.n = -1;
|
||||||
|
sc_search(&argument);
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
|
update_status();
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(Zathura.view));
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.view));
|
||||||
update_status(DEFAULT, "");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,10 +792,9 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!success)
|
if(!success)
|
||||||
update_status(WARNING, "Not a valid command");
|
notify(ERROR, g_strdup_printf("\"%s\" is not a valid command", command));
|
||||||
else
|
|
||||||
update_status(DEFAULT, "");
|
|
||||||
|
|
||||||
|
update_status();
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(Zathura.view));
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.view));
|
||||||
}
|
}
|
||||||
|
@ -696,8 +806,9 @@ cb_inputbar_button_pressed(GtkWidget* widget, GdkEventButton* event, gpointer da
|
||||||
{
|
{
|
||||||
gtk_widget_modify_text(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_fg));
|
gtk_widget_modify_text(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_fg));
|
||||||
gtk_widget_modify_base(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_bg));
|
gtk_widget_modify_base(GTK_WIDGET(Zathura.inputbar), GTK_STATE_NORMAL, &(Zathura.Settings.inputbar_bg));
|
||||||
gtk_editable_set_position(GTK_EDITABLE(Zathura.inputbar), -1);
|
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(Zathura.inputbar));
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.inputbar));
|
||||||
|
gtk_entry_set_text(Zathura.inputbar, "");
|
||||||
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.inputbar), -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +821,6 @@ cb_inputbar_key_pressed(GtkEntry* entry, GdkEventKey *event, gpointer data)
|
||||||
{
|
{
|
||||||
case GDK_Escape:
|
case GDK_Escape:
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(Zathura.view));
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.view));
|
||||||
update_status(DEFAULT, "");
|
|
||||||
argument.n = HIDE;
|
argument.n = HIDE;
|
||||||
return complete(&argument);
|
return complete(&argument);
|
||||||
case GDK_Tab:
|
case GDK_Tab:
|
||||||
|
@ -738,8 +848,10 @@ cb_inputbar_key_released(GtkEntry *entry, GdkEventKey *event, gpointer data)
|
||||||
}
|
}
|
||||||
else if(length > 1 && text[0] == '/')
|
else if(length > 1 && text[0] == '/')
|
||||||
{
|
{
|
||||||
char *term = text + 1;
|
Argument argument;
|
||||||
cmd_search(1, &term);
|
argument.data = (char*) text + 1;
|
||||||
|
argument.n = -1;
|
||||||
|
sc_search(&argument);
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(Zathura.inputbar));
|
gtk_widget_grab_focus(GTK_WIDGET(Zathura.inputbar));
|
||||||
gtk_editable_set_position(GTK_EDITABLE(Zathura.inputbar), -1);
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.inputbar), -1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue