add a custom refresh-view signal

Now we can trigger a gtk page refresh calling refresh_view. This
function triggers a custom signal refresh-view, whose handler copies the
position from the document object to the adjustments.
This commit is contained in:
Abdo Roig-Maranges 2013-10-22 21:24:26 +02:00
parent 030a8c65c1
commit 692e72abd4
4 changed files with 74 additions and 0 deletions

View file

@ -176,6 +176,32 @@ cb_view_vadjustment_changed(GtkAdjustment* adjustment, gpointer data)
zathura_adjustment_set_value_from_ratio(adjustment, ratio);
}
void
cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL) {
return;
}
unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL) {
return;
}
GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
double position_x = zathura_document_get_position_x(zathura->document);
double position_y = zathura_document_get_position_y(zathura->document);
zathura_adjustment_set_value_from_ratio(vadj, position_y);
zathura_adjustment_set_value_from_ratio(hadj, position_x);
statusbar_page_number_update(zathura);
}
void
cb_adjustment_track_value(GtkAdjustment* adjustment, gpointer data)
{

View file

@ -61,6 +61,17 @@ void cb_view_hadjustment_changed(GtkAdjustment *adjustment, gpointer data);
*/
void cb_view_vadjustment_changed(GtkAdjustment *adjustment, gpointer data);
/**
* This function gets called when the program need to refresh the document view.
*
* It adjusts the value of the scrollbars, triggering a redraw in the new
* position.
*
* @param view The view GtkWidget
* @param data The zathura instance
*/
void cb_refresh_view(GtkWidget* view, gpointer data);
/* This function gets called when the value of the adjustment changes.
*
* It updates the value of the tracking adjustment, only if the bounds of the

View file

@ -141,6 +141,21 @@ zathura_init(zathura_t* zathura)
zathura->ui.session->events.buffer_changed = cb_buffer_changed;
zathura->ui.session->events.unknown_command = cb_unknown_command;
/* zathura signals */
zathura->signals.refresh_view = g_signal_new("refresh-view",
GTK_TYPE_WIDGET,
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
1,
G_TYPE_POINTER);
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view",
G_CALLBACK(cb_refresh_view), zathura);
/* page view */
#if (GTK_MAJOR_VERSION == 3)
zathura->ui.page_widget = gtk_grid_new();
@ -1195,6 +1210,16 @@ position_set(zathura_t* zathura, double position_x, double position_y)
}
}
void
refresh_view(zathura_t* zathura) {
g_return_if_fail(zathura != NULL);
/* emit a custom refresh-view signal */
g_signal_emit(zathura->ui.session->gtk.view, zathura->signals.refresh_view,
0, zathura);
}
static void
zathura_jumplist_hide_inputbar(zathura_t* zathura)
{

View file

@ -132,6 +132,11 @@ struct zathura_s
unsigned int max_size;
} jumplist;
struct
{
guint refresh_view;
} signals;
struct
{
gchar* file;
@ -321,6 +326,13 @@ void position_set_delayed(zathura_t* zathura, double position_x, double position
*/
void position_set(zathura_t* zathura, double position_x, double position_y);
/**
* Refresh the page view
*
* @param zathura Zathura session
*/
void refresh_view(zathura_t* zathura);
/**
* Builds the box structure to show the rendered pages
*