mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 21:44:20 +01:00
HiDPI: watch GtkWidget scale-factor property
The scale-factor property is more specific than the GDK configure event and is the recommended way to watch for scale factor changes.
This commit is contained in:
parent
b5d0b28bb9
commit
5fa4b8907e
@ -216,11 +216,11 @@ cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data)
|
||||
statusbar_page_number_update(zathura);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cb_window_configure(GtkWidget* widget, GdkEventConfigure* UNUSED(configure), zathura_t* zathura)
|
||||
void
|
||||
cb_scale_factor(GtkWidget* widget, GParamSpec* UNUSED(pspec), zathura_t* zathura)
|
||||
{
|
||||
if (widget == NULL || zathura == NULL || zathura->document == NULL) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
int new_factor = gtk_widget_get_scale_factor(widget);
|
||||
@ -230,12 +230,11 @@ cb_window_configure(GtkWidget* widget, GdkEventConfigure* UNUSED(configure), zat
|
||||
zathura_document_get_device_scale(zathura->document, ¤t_x, ¤t_y);
|
||||
|
||||
if (new_factor != current_x || new_factor != current_y) {
|
||||
zathura_document_set_device_scale(zathura->document, new_factor, new_factor);
|
||||
zathura_document_set_device_scale(zathura->document, new_factor,
|
||||
new_factor);
|
||||
girara_debug("New device scale: %d", new_factor);
|
||||
render_all(zathura);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -80,19 +80,16 @@ void cb_view_vadjustment_changed(GtkAdjustment *adjustment, gpointer data);
|
||||
void cb_refresh_view(GtkWidget* view, gpointer data);
|
||||
|
||||
/**
|
||||
* This function gets called when the main window is reconfigured, i.e. when
|
||||
* its size, position or stacking order has changed, or when the device scale
|
||||
* factor has changed (e.g. when moving from a regular to a HiDPI screen).
|
||||
* This function gets called when the view widget scale factor changes (e.g.
|
||||
* when moving from a regular to a HiDPI screen).
|
||||
*
|
||||
* It checks if the device scale factor has changed and if yes, records the new
|
||||
* value and triggers a re-rendering of the document.
|
||||
* It records the new value and triggers a re-rendering of the document.
|
||||
*
|
||||
* @param widget The main window GtkWidget
|
||||
* @param configure The GDK configure event
|
||||
* @param widget The view widget
|
||||
* @param pspec The GParamSpec for the scale-factor property
|
||||
* @param zathura The zathura instance
|
||||
*/
|
||||
gboolean cb_window_configure(GtkWidget* widget, GdkEventConfigure* configure,
|
||||
zathura_t* zathura);
|
||||
void cb_scale_factor(GtkWidget* widget, GParamSpec *pspec, zathura_t* zathura);
|
||||
|
||||
/**
|
||||
* This function gets called when the value of the "pages-per-row"
|
||||
|
@ -153,8 +153,8 @@ init_ui(zathura_t* zathura)
|
||||
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view",
|
||||
G_CALLBACK(cb_refresh_view), zathura);
|
||||
|
||||
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "configure-event",
|
||||
G_CALLBACK(cb_window_configure), zathura);
|
||||
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view),
|
||||
"notify::scale-factor", G_CALLBACK(cb_scale_factor), zathura);
|
||||
|
||||
/* page view */
|
||||
zathura->ui.page_widget = gtk_grid_new();
|
||||
@ -959,6 +959,10 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
|
||||
const unsigned int view_height = (unsigned int)floor(gtk_adjustment_get_page_size(vadjustment));
|
||||
zathura_document_set_viewport_height(zathura->document, view_height);
|
||||
|
||||
/* get initial device scale */
|
||||
int device_scale = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view);
|
||||
zathura_document_set_device_scale(zathura->document, device_scale, device_scale);
|
||||
|
||||
/* create blank pages */
|
||||
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
|
||||
if (zathura->pages == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user