diff options
author | rbuj <[email protected]> | 2019-08-02 12:56:13 +0200 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2019-08-10 22:58:36 -0400 |
commit | d387353c800961b730496dc79d2372b2a56875d9 (patch) | |
tree | fe01277680a993b2b1f666ade7f8410fad21ab2f | |
parent | 82d6a871b48c5054c629c83612b60dba63e70cc9 (diff) | |
download | atril-d387353c800961b730496dc79d2372b2a56875d9.tar.bz2 atril-d387353c800961b730496dc79d2372b2a56875d9.tar.xz |
DPI: compute monitor resolution or get screen resolution
-rw-r--r-- | libdocument/ev-document-misc.c | 10 | ||||
-rw-r--r-- | libdocument/ev-document-misc.h | 2 | ||||
-rw-r--r-- | libview/ev-annotation-window.c | 14 | ||||
-rw-r--r-- | libview/ev-view.c | 29 | ||||
-rw-r--r-- | previewer/ev-previewer-window.c | 14 | ||||
-rw-r--r-- | shell/ev-window.c | 24 |
6 files changed, 50 insertions, 43 deletions
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index 1a07781c..e25b9ca6 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -339,16 +339,20 @@ ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf) } gdouble -ev_document_misc_get_screen_dpi (GdkScreen *screen, GdkMonitor *monitor) +ev_document_misc_get_monitor_dpi (GdkMonitor *monitor) { + GdkRectangle geometry; + int s; gdouble dp, di; + gdk_monitor_get_geometry (monitor, &geometry); + s = gdk_monitor_get_scale_factor (monitor); + /*diagonal in pixels*/ - dp = hypot (WidthOfScreen (gdk_x11_screen_get_xscreen (screen)), HeightOfScreen (gdk_x11_screen_get_xscreen (screen))); + dp = hypot (geometry.width * s, geometry.height * s); /*diagonal in inches*/ di = hypot (gdk_monitor_get_width_mm(monitor), gdk_monitor_get_height_mm (monitor)) / 25.4; - di /= gdk_monitor_get_scale_factor (monitor); return (dp / di); } diff --git a/libdocument/ev-document-misc.h b/libdocument/ev-document-misc.h index 5dec395a..3b97e3f8 100644 --- a/libdocument/ev-document-misc.h +++ b/libdocument/ev-document-misc.h @@ -61,7 +61,7 @@ cairo_surface_t *ev_document_misc_surface_rotate_and_scale (cairo_surface_t *sur void ev_document_misc_invert_surface (cairo_surface_t *surface); void ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf); -gdouble ev_document_misc_get_screen_dpi (GdkScreen *screen, GdkMonitor *monitor); +gdouble ev_document_misc_get_monitor_dpi (GdkMonitor *monitor); gchar *ev_document_misc_format_date (GTime utime); 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); } diff --git a/previewer/ev-previewer-window.c b/previewer/ev-previewer-window.c index a7db8b32..b10015f3 100644 --- a/previewer/ev-previewer-window.c +++ b/previewer/ev-previewer-window.c @@ -68,17 +68,17 @@ enum { G_DEFINE_TYPE (EvPreviewerWindow, ev_previewer_window, GTK_TYPE_WINDOW) static gdouble -get_screen_dpi (EvPreviewerWindow *window) +get_monitor_dpi (EvPreviewerWindow *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); } #if GTKUNIXPRINT_ENABLED @@ -528,7 +528,7 @@ ev_previewer_window_constructor (GType type, construct_params); window = EV_PREVIEWER_WINDOW (object); - dpi = get_screen_dpi (window); + dpi = get_monitor_dpi (window); ev_document_model_set_min_scale (window->model, MIN_SCALE * dpi / 72.0); ev_document_model_set_max_scale (window->model, MAX_SCALE * dpi / 72.0); ev_document_model_set_sizing_mode (window->model, EV_SIZING_FIT_WIDTH); diff --git a/shell/ev-window.c b/shell/ev-window.c index 2454cd59..82aa74a7 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -395,17 +395,17 @@ static gchar *caja_sendto = NULL; G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_APPLICATION_WINDOW) static gdouble -get_screen_dpi (EvWindow *window) +get_monitor_dpi (EvWindow *ev_window) { - GdkScreen *screen; + GdkWindow *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); + window = gtk_widget_get_window (GTK_WIDGET (ev_window)); + display = gdk_window_get_display (window); + monitor = gdk_display_get_monitor_at_window (display, window); - return ev_document_misc_get_screen_dpi (screen, monitor); + return ev_document_misc_get_monitor_dpi (monitor); } static void @@ -643,7 +643,7 @@ ev_window_update_actions (EvWindow *ev_window) G_GNUC_END_IGNORE_DEPRECATIONS; real_zoom = ev_document_model_get_scale (ev_window->priv->model); - real_zoom *= 72.0 / get_screen_dpi (ev_window); + real_zoom *= 72.0 / get_monitor_dpi (ev_window); zoom = ephy_zoom_get_nearest_zoom_level (real_zoom); ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom); @@ -1307,7 +1307,7 @@ setup_model_from_metadata (EvWindow *window) /* Zoom */ if (ev_document_model_get_sizing_mode (window->priv->model) == EV_SIZING_FREE) { if (ev_metadata_get_double (window->priv->metadata, "zoom", &zoom)) { - zoom *= get_screen_dpi (window) / 72.0; + zoom *= get_monitor_dpi (window) / 72.0; ev_document_model_set_scale (window->priv->model, zoom); } } @@ -4586,7 +4586,7 @@ ev_window_update_max_min_scale (EvWindow *window) return; page_cache_mb = g_settings_get_uint (window->priv->settings, GS_PAGE_CACHE_SIZE); - dpi = get_screen_dpi (window) / 72.0; + dpi = get_monitor_dpi (window) / 72.0; ev_document_get_min_page_size (window->priv->document, &min_width, &min_height); width = (rotation == 0 || rotation == 180) ? min_width : min_height; @@ -4811,7 +4811,7 @@ ev_window_cmd_edit_save_settings (GtkAction *action, EvWindow *ev_window) if (sizing_mode == EV_SIZING_FREE) { gdouble zoom = ev_document_model_get_scale (model); - zoom *= 72.0 / get_screen_dpi (ev_window); + zoom *= 72.0 / get_monitor_dpi (ev_window); g_settings_set_double (settings, "zoom", zoom); } g_settings_set_boolean (settings, "show-toolbar", @@ -5198,7 +5198,7 @@ ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow * gdouble zoom; zoom = ev_document_model_get_scale (model); - zoom *= 72.0 / get_screen_dpi (ev_window); + zoom *= 72.0 / get_monitor_dpi (ev_window); ev_metadata_set_double (ev_window->priv->metadata, "zoom", zoom); } } @@ -5989,7 +5989,7 @@ zoom_control_changed_cb (EphyZoomAction *action, if (mode == EV_SIZING_FREE) { ev_document_model_set_scale (ev_window->priv->model, - zoom * get_screen_dpi (ev_window) / 72.0); + zoom * get_monitor_dpi (ev_window) / 72.0); } } |