mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-16 18:35:40 +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
3 changed files with 17 additions and 17 deletions
|
@ -216,11 +216,11 @@ cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data)
|
||||||
statusbar_page_number_update(zathura);
|
statusbar_page_number_update(zathura);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
cb_window_configure(GtkWidget* widget, GdkEventConfigure* UNUSED(configure), zathura_t* zathura)
|
cb_scale_factor(GtkWidget* widget, GParamSpec* UNUSED(pspec), zathura_t* zathura)
|
||||||
{
|
{
|
||||||
if (widget == NULL || zathura == NULL || zathura->document == NULL) {
|
if (widget == NULL || zathura == NULL || zathura->document == NULL) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int new_factor = gtk_widget_get_scale_factor(widget);
|
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);
|
zathura_document_get_device_scale(zathura->document, ¤t_x, ¤t_y);
|
||||||
|
|
||||||
if (new_factor != current_x || new_factor != current_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);
|
girara_debug("New device scale: %d", new_factor);
|
||||||
render_all(zathura);
|
render_all(zathura);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -80,19 +80,16 @@ 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 main window is reconfigured, i.e. when
|
* This function gets called when the view widget scale factor changes (e.g.
|
||||||
* its size, position or stacking order has changed, or when the device scale
|
* when moving from a regular to a HiDPI screen).
|
||||||
* factor has changed (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
|
* It records the new value and triggers a re-rendering of the document.
|
||||||
* value and triggers a re-rendering of the document.
|
|
||||||
*
|
*
|
||||||
* @param widget The main window GtkWidget
|
* @param widget The view widget
|
||||||
* @param configure The GDK configure event
|
* @param pspec The GParamSpec for the scale-factor property
|
||||||
* @param zathura The zathura instance
|
* @param zathura The zathura instance
|
||||||
*/
|
*/
|
||||||
gboolean cb_window_configure(GtkWidget* widget, GdkEventConfigure* configure,
|
void cb_scale_factor(GtkWidget* widget, GParamSpec *pspec, zathura_t* zathura);
|
||||||
zathura_t* zathura);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function gets called when the value of the "pages-per-row"
|
* 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_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view",
|
||||||
G_CALLBACK(cb_refresh_view), zathura);
|
G_CALLBACK(cb_refresh_view), zathura);
|
||||||
|
|
||||||
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "configure-event",
|
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view),
|
||||||
G_CALLBACK(cb_window_configure), zathura);
|
"notify::scale-factor", G_CALLBACK(cb_scale_factor), zathura);
|
||||||
|
|
||||||
/* page view */
|
/* page view */
|
||||||
zathura->ui.page_widget = gtk_grid_new();
|
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));
|
const unsigned int view_height = (unsigned int)floor(gtk_adjustment_get_page_size(vadjustment));
|
||||||
zathura_document_set_viewport_height(zathura->document, view_height);
|
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 */
|
/* create blank pages */
|
||||||
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
|
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
|
||||||
if (zathura->pages == NULL) {
|
if (zathura->pages == NULL) {
|
||||||
|
|
Loading…
Reference in a new issue