From 36d9ece978b012d6515c0d51e7c6ae9190b74827 Mon Sep 17 00:00:00 2001 From: Jeremie Knuesel Date: Tue, 23 Jan 2018 09:34:22 +0100 Subject: [PATCH] HiDPI: add preprocessor conditionals --- config.mk | 9 +++++++++ zathura/callbacks.c | 4 ++++ zathura/render.c | 4 ++++ zathura/zathura.c | 2 ++ 4 files changed, 19 insertions(+) diff --git a/config.mk b/config.mk index 7a488cf..9d957bb 100644 --- a/config.mk +++ b/config.mk @@ -47,6 +47,15 @@ WITH_SYNCTEX ?= $(shell (${PKG_CONFIG} synctex && echo 1) || echo 0) # To disable support for mimetype detction with libmagic set WITH_MAGIC to 0. WITH_MAGIC ?= 1 +# HiDPI +HIDPI_SUPPORT_CAIRO = $(shell (${PKG_CONFIG} --atleast-version=1.14 cairo && echo 1) || echo 0) +HIDPI_SUPPORT_GTK = $(shell (${PKG_CONFIG} --atleast-version=3.10 ${GTK_PKG_CONFIG_NAME} && echo 1) || echo 0) +ifeq (${HIDPI_SUPPORT_CAIRO},1) +ifeq (${HIDPI_SUPPORT_GTK},1) +CPPFLAGS += -DHAVE_HIDPI_SUPPORT +endif +endif + # paths PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man diff --git a/zathura/callbacks.c b/zathura/callbacks.c index 4c4728d..b257b17 100644 --- a/zathura/callbacks.c +++ b/zathura/callbacks.c @@ -223,7 +223,11 @@ cb_scale_factor(GtkWidget* widget, GParamSpec* UNUSED(pspec), zathura_t* zathura return; } +#ifdef HAVE_HIDPI_SUPPORT int new_factor = gtk_widget_get_scale_factor(widget); +#else + int new_factor = 1; +#endif double current_x; double current_y; diff --git a/zathura/render.c b/zathura/render.c index 727d357..6c5db86 100644 --- a/zathura/render.c +++ b/zathura/render.c @@ -740,6 +740,7 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render &page_height, &page_width, false); +#ifdef HAVE_HIDPI_SUPPORT double device_scale_x; double device_scale_y; zathura_document_get_device_scale(document, &device_scale_x, &device_scale_y); @@ -748,6 +749,7 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render page_width *= device_scale_x; page_height *= device_scale_y; } +#endif cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height); @@ -759,6 +761,7 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render return false; } +#ifdef HAVE_HIDPI_SUPPORT if (device_scale_x != 0.0 && device_scale_y != 0.0) { cairo_surface_set_device_scale(surface, device_scale_x, device_scale_y); if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { @@ -766,6 +769,7 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render return false; } } +#endif cairo_t* cairo = cairo_create(surface); if (cairo == NULL) { diff --git a/zathura/zathura.c b/zathura/zathura.c index 2d9a5d6..e83bf7b 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -153,8 +153,10 @@ init_ui(zathura_t* zathura) g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view", G_CALLBACK(cb_refresh_view), zathura); +#ifdef HAVE_HIDPI_SUPPORT g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "notify::scale-factor", G_CALLBACK(cb_scale_factor), zathura); +#endif /* page view */ zathura->ui.page_widget = gtk_grid_new();