summaryrefslogtreecommitdiff
path: root/libview
diff options
context:
space:
mode:
authorrbuj <[email protected]>2019-08-02 12:56:13 +0200
committerVictor Kareh <[email protected]>2019-08-10 22:58:36 -0400
commitd387353c800961b730496dc79d2372b2a56875d9 (patch)
treefe01277680a993b2b1f666ade7f8410fad21ab2f /libview
parent82d6a871b48c5054c629c83612b60dba63e70cc9 (diff)
downloadatril-d387353c800961b730496dc79d2372b2a56875d9.tar.bz2
atril-d387353c800961b730496dc79d2372b2a56875d9.tar.xz
DPI: compute monitor resolution or get screen resolution
Diffstat (limited to 'libview')
-rw-r--r--libview/ev-annotation-window.c14
-rw-r--r--libview/ev-view.c29
2 files changed, 23 insertions, 20 deletions
diff --git a/libview/ev-annotation-window.c b/libview/ev-annotation-window.c
index eab458c2..52be0298 100644
--- a/libview/ev-annotation-window.c
+++ b/libview/ev-annotation-window.c
@@ -94,17 +94,17 @@ send_focus_change (GtkWidget *widget,
}
static gdouble
-get_screen_dpi (EvAnnotationWindow *window)
+get_monitor_dpi (EvAnnotationWindow *window)
{
- GdkScreen *screen;
+ GdkWindow *gdk_window;
GdkMonitor *monitor;
GdkDisplay *display;
- screen = gtk_window_get_screen (GTK_WINDOW (window));
- display = gdk_screen_get_display (screen);
- monitor = gdk_display_get_primary_monitor (display);
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+ display = gdk_window_get_display (gdk_window);
+ monitor = gdk_display_get_monitor_at_window (display, gdk_window);
- return ev_document_misc_get_screen_dpi (screen, monitor);
+ return ev_document_misc_get_monitor_dpi (monitor);
}
static void
@@ -459,7 +459,7 @@ ev_annotation_window_constructor (GType type,
rect = &window->rect;
/* Rectangle is at doc resolution (72.0) */
- scale = get_screen_dpi (window) / 72.0;
+ scale = get_monitor_dpi (window) / 72.0;
gtk_window_resize (GTK_WINDOW (window),
(gint)((rect->x2 - rect->x1) * scale),
(gint)((rect->y2 - rect->y1) * scale));
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 7703c6ed..90f9d3cb 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -494,18 +494,19 @@ is_dual_page (EvView *view,
switch (view->page_layout) {
case EV_PAGE_LAYOUT_AUTOMATIC: {
- GdkScreen *screen;
- GdkMonitor *monitor;
- GdkDisplay *display;
+ GdkWindow *window;
+ GdkMonitor *monitor;
+ GdkDisplay *display;
double scale;
double doc_width;
double doc_height;
GtkAllocation allocation;
- screen = gtk_widget_get_screen (GTK_WIDGET (view));
- display = gdk_screen_get_display (screen);
- monitor = gdk_display_get_primary_monitor (display);
- scale = ev_document_misc_get_screen_dpi (screen, monitor) / 72.0;
+ window = gtk_widget_get_window (GTK_WIDGET (view));
+ display = gdk_window_get_display (window);
+ monitor = gdk_display_get_monitor_at_window (display, window);
+
+ scale = ev_document_misc_get_monitor_dpi (monitor) / 72.0;
ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
@@ -7105,8 +7106,6 @@ zoom_for_size_automatic (GdkScreen *screen,
int target_width,
int target_height)
{
- GdkMonitor *monitor;
- GdkDisplay *display;
double fit_width_scale;
double scale;
@@ -7118,11 +7117,15 @@ zoom_for_size_automatic (GdkScreen *screen,
fit_height_scale = zoom_for_size_fit_height (doc_width, doc_height, target_width, target_height);
scale = MIN (fit_width_scale, fit_height_scale);
} else {
- double actual_scale;
+ double actual_scale, resolution;
- display = gdk_screen_get_display (screen);
- monitor = gdk_display_get_primary_monitor (display);
- actual_scale = ev_document_misc_get_screen_dpi (screen, monitor) / 72.0;
+ resolution = gdk_screen_get_resolution (screen);
+ if (resolution == -1) {
+ GdkDisplay *display = gdk_screen_get_display (screen);
+ GdkMonitor *monitor = gdk_display_get_primary_monitor (display);
+ resolution = ev_document_misc_get_monitor_dpi (monitor);
+ }
+ actual_scale = resolution / 72.0;
scale = MIN (fit_width_scale, actual_scale);
}