Commit fc5a344d authored by Jeremie Knuesel's avatar Jeremie Knuesel

Use signals to detect DPI change

parent 553a8ff4
...@@ -216,6 +216,44 @@ cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data) ...@@ -216,6 +216,44 @@ cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data)
statusbar_page_number_update(zathura); statusbar_page_number_update(zathura);
} }
void
cb_monitors_changed(GdkScreen* screen, gpointer data)
{
girara_debug("signal received");
zathura_t* zathura = data;
if (screen == NULL || zathura == NULL) {
return;
}
zathura_update_view_dpi(zathura);
}
void
cb_widget_screen_changed(GtkWidget* widget, GdkScreen* UNUSED(previous_screen), gpointer data)
{
girara_debug("signal received");
zathura_t* zathura = data;
if (widget == NULL || zathura == NULL) {
return;
}
if (gtk_widget_has_screen(widget)) {
GdkScreen* screen = gtk_widget_get_screen(widget);
/* disconnect signal on previous screen */
g_signal_handlers_disconnect_matched(screen, G_SIGNAL_MATCH_FUNC, 0, 0,
NULL, (gpointer) cb_monitors_changed, zathura);
/* connect to new screen */
g_signal_connect(G_OBJECT(screen),
"monitors-changed", G_CALLBACK(cb_monitors_changed), zathura);
}
zathura_update_view_dpi(zathura);
}
void void
cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data) cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data)
{ {
...@@ -235,6 +273,7 @@ cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data) ...@@ -235,6 +273,7 @@ cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data)
fabs(new_factor - current.y) >= DBL_EPSILON) { fabs(new_factor - current.y) >= DBL_EPSILON) {
zathura_document_set_device_factors(zathura->document, new_factor, new_factor); zathura_document_set_device_factors(zathura->document, new_factor, new_factor);
girara_debug("New device scale factor: %d", new_factor); girara_debug("New device scale factor: %d", new_factor);
zathura_update_view_dpi(zathura);
render_all(zathura); render_all(zathura);
} }
} }
......
...@@ -79,6 +79,30 @@ void cb_view_vadjustment_changed(GtkAdjustment *adjustment, gpointer data); ...@@ -79,6 +79,30 @@ void cb_view_vadjustment_changed(GtkAdjustment *adjustment, gpointer data);
*/ */
void cb_refresh_view(GtkWidget* view, gpointer data); 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 DPI.
*
* @param screen The GDK screen
* @param gpointer The zathura instance
*/
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 DPI.
*
* @param widget The view widget
* @param previous_screen The widget's previous screen
* @param gpointer The zathura instance
*/
void cb_widget_screen_changed(GtkWidget* widget, GdkScreen* previous_screen, gpointer data);
/** /**
* This function gets called when the view widget scale factor changes (e.g. * This function gets called when the view widget scale factor changes (e.g.
* when moving from a regular to a HiDPI screen). * when moving from a regular to a HiDPI screen).
......
...@@ -217,6 +217,9 @@ init_ui(zathura_t* zathura) ...@@ -217,6 +217,9 @@ init_ui(zathura_t* zathura)
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view),
"notify::scale-factor", G_CALLBACK(cb_scale_factor), zathura); "notify::scale-factor", G_CALLBACK(cb_scale_factor), zathura);
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view),
"screen-changed", G_CALLBACK(cb_widget_screen_changed), zathura);
/* page view */ /* page view */
zathura->ui.page_widget = gtk_grid_new(); zathura->ui.page_widget = gtk_grid_new();
gtk_grid_set_row_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE); gtk_grid_set_row_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE);
...@@ -1025,6 +1028,9 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* ...@@ -1025,6 +1028,9 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
zathura_update_view_dpi(zathura); zathura_update_view_dpi(zathura);
/* call screen-changed callback to connect monitors-changed signal on initial screen */
cb_widget_screen_changed(zathura->ui.session->gtk.view, NULL, zathura);
/* get initial device scale */ /* get initial device scale */
int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view);
zathura_document_set_device_factors(zathura->document, device_factor, device_factor); zathura_document_set_device_factors(zathura->document, device_factor, device_factor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment