Listen on configure event for PPI changes

This allows detection of a PPI change due to the window moving to
another monitor
This commit is contained in:
Jeremie Knuesel 2018-02-23 15:28:22 +01:00
parent 8e3f056121
commit 063b234a2a
4 changed files with 37 additions and 5 deletions

View file

@ -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)
{

View file

@ -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).

View file

@ -868,9 +868,11 @@ 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);
if (widget != NULL) {
gtk_widget_set_size_request(widget, page_width, page_height);
gtk_widget_queue_resize(widget);
}
}
}
static gint

View file

@ -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;