diff --git a/zathura/callbacks.c b/zathura/callbacks.c index 4499cdb..63024da 100644 --- a/zathura/callbacks.c +++ b/zathura/callbacks.c @@ -256,6 +256,17 @@ cb_widget_screen_changed(GtkWidget* widget, GdkScreen* previous_screen, gpointer zathura_update_view_ppi(zathura); } +void +cb_widget_configured(GtkWidget* UNUSED(widget), GdkEvent* UNUSED(event), gpointer data) +{ + zathura_t* zathura = data; + if (zathura == NULL) { + return; + } + + zathura_update_view_ppi(zathura); +} + void cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data) { diff --git a/zathura/callbacks.h b/zathura/callbacks.h index ba49f9d..bee54e0 100644 --- a/zathura/callbacks.h +++ b/zathura/callbacks.h @@ -83,7 +83,8 @@ void cb_refresh_view(GtkWidget* view, gpointer data); * This function gets called when the monitors associated with the GdkScreen * change. * - * It udpates the stored value for the monitor PPI. + * It checks for a change of monitor PPI, storing the new value and triggering + * a refresh if appropriate. * * @param screen The GDK screen * @param gpointer The zathura instance @@ -94,8 +95,9 @@ void cb_monitors_changed(GdkScreen* screen, gpointer data); * This function gets called when the screen associated with the view widget * changes. * - * It udpates updates the connection on the monitors-changed ignal and the - * stored value for the monitor PPI. + * It updates the connection on the monitors-changed signal and checks for a + * change of monitor PPI, storing the new value and triggering a refresh if + * appropriate. * * @param widget The view widget * @param previous_screen The widget's previous screen @@ -103,6 +105,20 @@ void cb_monitors_changed(GdkScreen* screen, gpointer data); */ void cb_widget_screen_changed(GtkWidget* widget, GdkScreen* previous_screen, gpointer data); +/** + * This function gets called when the main window's size, position or stacking + * changes. + * + * It checks for a change of monitor PPI (due to the window moving between + * different monitors), storing the new value and triggering a refresh if + * appropriate. + * + * @param widget The main window widget + * @param event The configure event + * @param gpointer The zathura instance + */ +void cb_widget_configured(GtkWidget* widget, GdkEvent* event, gpointer data); + /** * This function gets called when the view widget scale factor changes (e.g. * when moving from a regular to a HiDPI screen). diff --git a/zathura/render.c b/zathura/render.c index 1d7636c..e7ddc6c 100644 --- a/zathura/render.c +++ b/zathura/render.c @@ -868,8 +868,10 @@ render_all(zathura_t* zathura) girara_debug("Queuing resize for page %u to %u x %u (%f x %f).", page_id, page_width, page_height, width, height); GtkWidget* widget = zathura_page_get_widget(zathura, page); - gtk_widget_set_size_request(widget, page_width, page_height); - gtk_widget_queue_resize(widget); + if (widget != NULL) { + gtk_widget_set_size_request(widget, page_width, page_height); + gtk_widget_queue_resize(widget); + } } } diff --git a/zathura/zathura.c b/zathura/zathura.c index 1e5fe9d..4516dfe 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -226,6 +226,9 @@ init_ui(zathura_t* zathura) g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "screen-changed", G_CALLBACK(cb_widget_screen_changed), zathura); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), + "configure-event", G_CALLBACK(cb_widget_configured), zathura); + /* initialize the screen-changed handler to 0 (i.e. invalid) */ zathura->signals.monitors_changed_handler = 0;