mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 13:16:00 +01:00
Scroll buffer command
Added a buffer command to move to a specific percental value of the alighment of the view window. E.g.: 25%
This commit is contained in:
parent
c7ebceb83a
commit
7b17a793c7
2 changed files with 45 additions and 4 deletions
|
@ -109,6 +109,7 @@ BufferCommand buffer_commands[] = {
|
||||||
{"^zO$", bcmd_zoom, { ZOOM_OUT } },
|
{"^zO$", bcmd_zoom, { ZOOM_OUT } },
|
||||||
{"^z0$", bcmd_zoom, { ZOOM_ORIGINAL } },
|
{"^z0$", bcmd_zoom, { ZOOM_ORIGINAL } },
|
||||||
{"^[0-9]+Z$", bcmd_zoom, { ZOOM_SPECIFIC } },
|
{"^[0-9]+Z$", bcmd_zoom, { ZOOM_SPECIFIC } },
|
||||||
|
{"^[0-9]+%$", bcmd_scroll, {0} },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* special commands */
|
/* special commands */
|
||||||
|
|
44
zathura.c
44
zathura.c
|
@ -193,6 +193,7 @@ struct
|
||||||
{
|
{
|
||||||
char* filename;
|
char* filename;
|
||||||
char* pages;
|
char* pages;
|
||||||
|
int scroll_percentage;
|
||||||
} State;
|
} State;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -266,6 +267,7 @@ Completion* cc_set(char*);
|
||||||
|
|
||||||
/* buffer command declarations */
|
/* buffer command declarations */
|
||||||
void bcmd_goto(char*, Argument*);
|
void bcmd_goto(char*, Argument*);
|
||||||
|
void bcmd_scroll(char*, Argument*);
|
||||||
void bcmd_zoom(char*, Argument*);
|
void bcmd_zoom(char*, Argument*);
|
||||||
|
|
||||||
/* special command delcarations */
|
/* special command delcarations */
|
||||||
|
@ -319,6 +321,7 @@ init_zathura()
|
||||||
|
|
||||||
Zathura.State.filename = (char*) DEFAULT_TEXT;
|
Zathura.State.filename = (char*) DEFAULT_TEXT;
|
||||||
Zathura.State.pages = "";
|
Zathura.State.pages = "";
|
||||||
|
Zathura.State.scroll_percentage = 0;
|
||||||
|
|
||||||
/* UI */
|
/* UI */
|
||||||
Zathura.UI.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
|
Zathura.UI.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
|
||||||
|
@ -601,7 +604,7 @@ update_status()
|
||||||
pthread_mutex_lock(&(Zathura.Lock.scale_lock));
|
pthread_mutex_lock(&(Zathura.Lock.scale_lock));
|
||||||
char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : "";
|
char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : "";
|
||||||
pthread_mutex_unlock(&(Zathura.Lock.scale_lock));
|
pthread_mutex_unlock(&(Zathura.Lock.scale_lock));
|
||||||
char* status_text = g_strdup_printf("%s %s", zoom_level, Zathura.State.pages);
|
char* status_text = g_strdup_printf("%s %d%% %s", zoom_level, Zathura.State.scroll_percentage, Zathura.State.pages);
|
||||||
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text);
|
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,6 +749,11 @@ set_page(int page)
|
||||||
|
|
||||||
Zathura.PDF.page_number = page;
|
Zathura.PDF.page_number = page;
|
||||||
Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages);
|
Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages);
|
||||||
|
|
||||||
|
Argument argument;
|
||||||
|
argument.n = TOP;
|
||||||
|
sc_scroll(&argument);
|
||||||
|
|
||||||
switch_view(Zathura.UI.drawing_area);
|
switch_view(Zathura.UI.drawing_area);
|
||||||
draw(page);
|
draw(page);
|
||||||
}
|
}
|
||||||
|
@ -842,6 +850,9 @@ sc_abort(Argument* argument)
|
||||||
void
|
void
|
||||||
sc_adjust_window(Argument* argument)
|
sc_adjust_window(Argument* argument)
|
||||||
{
|
{
|
||||||
|
if(!Zathura.PDF.document)
|
||||||
|
return;
|
||||||
|
|
||||||
GtkAdjustment* adjustment;
|
GtkAdjustment* adjustment;
|
||||||
double view_size;
|
double view_size;
|
||||||
double page_width;
|
double page_width;
|
||||||
|
@ -948,6 +959,14 @@ sc_scroll(Argument* argument)
|
||||||
gtk_adjustment_set_value(adjustment, max);
|
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));
|
||||||
|
|
||||||
|
int percentage = 100 * (value / max);
|
||||||
|
percentage = (percentage < 0) ? 0 : ((percentage > 100) ? 100 : percentage);
|
||||||
|
|
||||||
|
if( (argument->n != LEFT) && (argument->n != RIGHT) )
|
||||||
|
Zathura.State.scroll_percentage = percentage;
|
||||||
|
|
||||||
|
update_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2010,6 +2029,27 @@ bcmd_goto(char* buffer, Argument* argument)
|
||||||
update_status();
|
update_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bcmd_zoom(char* buffer, Argument* argument)
|
bcmd_zoom(char* buffer, Argument* argument)
|
||||||
{
|
{
|
||||||
|
@ -2155,7 +2195,7 @@ cb_view_kb_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* append only numbers and characters to buffer */
|
/* append only numbers and characters to buffer */
|
||||||
if( (event->keyval >= 0x30) && (event->keyval <= 0x7A))
|
if( (event->keyval >= 0x21) && (event->keyval <= 0x7A))
|
||||||
{
|
{
|
||||||
if(!Zathura.Global.buffer)
|
if(!Zathura.Global.buffer)
|
||||||
Zathura.Global.buffer = g_string_new("");
|
Zathura.Global.buffer = g_string_new("");
|
||||||
|
|
Loading…
Reference in a new issue