Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 pdf-presenter-console (4.1-2) unstable; urgency=medium
 .
   * Merge minor upstream bug fixes and documentation updates
Author: Barak A. Pearlmutter <bap@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2017-12-22

--- /dev/null
+++ pdf-presenter-console-4.1/FAQ.rst
@@ -0,0 +1,34 @@
+===
+FAQ
+===
+
+Scaling issues with Wayland
+===========================
+
+If you encounter wrong scaling of PDFs within the presenter and presentation
+window, you can try the::
+
+    --wayland-workaround
+
+flag. See issue #312 and #214 for more informations.
+
+Embedded video playback is not working.
+=======================================
+
+You likely have a ``gstreamer`` codec issue. Try loading the video file you
+want to play with the following command: ``gst-launch-1.0 filesrc
+location=<your video> ! decodebin !  autovideosink``  If the video plays, go
+ahead and `submit an issue <https://github.com/pdfpc/pdfpc/issues>`_.
+Otherwise, the command will likely output some good hints for why gstreamer
+cannot decode the video.
+
+Windows do not appear on the correct screen.
+============================================
+
+For tiling window managers, the movement and fullscreening of the windows do not work reliable.
+It is therefore important to tell your WM to force floating the pdfpc windows.
+
+If you are using i3-wm add this to your config file::
+
+    for_window [ title="^pdfpc - present" ] border none floating enable
+
--- pdf-presenter-console-4.1.orig/README.rst
+++ pdf-presenter-console-4.1/README.rst
@@ -65,7 +65,7 @@ Requirements
 In order to compile and run pdfpc the following
 requirements need to be met:
 
-- CMake Version >=2.6
+- CMake Version >=3.0
 - vala >= 0.26
 - GTK+ >= 3.10
 - gee 0.8
@@ -164,7 +164,6 @@ try running cmake with::
 
     cmake -DVALA_EXECUTABLE:NAMES=valac-0.28 ..
 
-
 Usage
 =====
 
@@ -172,28 +171,8 @@ Now download some [sample presentations]
 
     pdfpc pdfpc-demo.pdf
 
-FAQ
-===
-
-Embedded video playback is not working.
----------------------------------------
-
-You likely have a ``gstreamer`` codec issue. Try loading the video file you
-want to play with the following command: ``gst-launch-1.0 filesrc
-location=<your video> ! decodebin !  autovideosink``  If the video plays, go
-ahead and `submit an issue <https://github.com/pdfpc/pdfpc/issues>`_.
-Otherwise, the command will likely output some good hints for why gstreamer
-cannot decode the video.
-
-Windows do not appear on the correct screen.
----------------------------------------------------
-
-For tiling window managers, the movement and fullscreening of the windows do not work reliable.
-It is therefore important to tell your WM to force floating the pdfpc windows.
-
-If you are using i3-wm add this to your config file::
-
-    for_window [ title="^pdfpc - present" ] border none floating enable
+If you encounter problems while running pdfpc, please consult the `FAQ
+<FAQ.rst>`_ first.
 
 Acknowledgements
 ================
--- pdf-presenter-console-4.1.orig/man/pdfpc.in
+++ pdf-presenter-console-4.1/man/pdfpc.in
@@ -76,6 +76,9 @@ Force to use only one screen
 .BI "\-t, \-\-start\-time"=T
 Start time of the presentation to be used as a countdown. (Format: HH:MM (24h))
 .TP
+.BI "\-W, \-\-wayland\-workaround"
+Enable Wayland-specific workaround. This might fix HiDPI scaling problems.
+.TP
 .BI "\-w, \-\-windowed"
 Run in windowed mode
 .TP
--- pdf-presenter-console-4.1.orig/src/CMakeLists.txt
+++ pdf-presenter-console-4.1/src/CMakeLists.txt
@@ -50,8 +50,22 @@ include_directories(
     ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
+link_directories(
+    ${GOBJECT_LIBRARY_DIRS}
+    ${GIO_LIBRARY_DIRS}
+    ${GEE_LIBRARY_DIRS}
+    ${POPPLER_LIBRARY_DIRS}
+    ${GTK_LIBRARY_DIRS}
+    ${GTHREAD_LIBRARY_DIRS}
+    ${PANGOCAIRO_LIBRARY_DIRS}
+    ${GSTREAMER_LIBRARY_DIRS}
+    ${GSTINTERFACES_LIBRARY_DIRS}
+    ${GSTVIDEO_LIBRARY_DIRS}
+)
+
 if(${WITH_X11})
     include_directories(${X11_INCLUDE_DIRS})
+    link_directories(${X11_LIBRARY_DIRS})
     set(ADDITIONAL_LIBS ${X11_LIBRARIES})
 endif()
 
--- pdf-presenter-console-4.1.orig/src/classes/options.vala
+++ pdf-presenter-console-4.1/src/classes/options.vala
@@ -53,6 +53,11 @@ namespace pdfpc {
         public static bool windowed = false;
 
         /**
+         * Commandline option to enable Wayland specific scaling workarounds
+         */
+        public static bool wayland_workaround = false;
+
+        /**
          * Commandline option which allows the complete disabling of slide caching
          */
         public static bool disable_caching = false;
--- pdf-presenter-console-4.1.orig/src/classes/presentation_controller.vala
+++ pdf-presenter-console-4.1/src/classes/presentation_controller.vala
@@ -340,6 +340,7 @@ namespace pdfpc {
         protected void init_presentation_pen() {
             init_pen_drawing_if_needed(presentation_allocation);
             this.presentation_pen_surface = presentation.pen_drawing_surface;
+            this.presentation_pen_surface.hide();
             this.presentation_pen_surface.draw.connect ((context) => {
                 draw_pen_surface(context, presentation_allocation, false);
                 return true;
--- pdf-presenter-console-4.1.orig/src/classes/timer_label.vala
+++ pdf-presenter-console-4.1/src/classes/timer_label.vala
@@ -255,6 +255,8 @@ namespace pdfpc {
                 context.remove_class("pretalk");
                 context.remove_class("last-minutes");
                 context.remove_class("overtime");
+                context.remove_class("too-slow");
+                context.remove_class("too-fast");
                 if (this.time < this.duration) {
                     timeInSecs = duration - this.time;
                     // Still on presentation time
--- pdf-presenter-console-4.1.orig/src/classes/view/behaviour/pdf_link.vala
+++ pdf-presenter-console-4.1/src/classes/view/behaviour/pdf_link.vala
@@ -131,6 +131,14 @@ namespace pdfpc.View.Behaviour {
          * further requests and checks.
          */
         public void on_entering_slide(View.Pdf source, int page_number) {
+            // if target is not mapped (ie. the size is not known) post pone
+            // the mapping calculatation since the results wouldn't be correct
+            if (!target.get_mapped()) {
+                target.realize.connect(() => {
+                    this.on_entering_slide(source, page_number);
+                });
+            }
+
             // Get the link mapping table
             bool in_range = true;
             Metadata.Pdf metadata = source.get_renderer().metadata;
--- pdf-presenter-console-4.1.orig/src/classes/window/fullscreen.vala
+++ pdf-presenter-console-4.1/src/classes/window/fullscreen.vala
@@ -108,7 +108,7 @@ namespace pdfpc.Window {
             }
 
             this.gdk_scale = this.screen_to_use.get_monitor_scale_factor(this.screen_num_to_use);
-            if (Pdfpc.is_Wayland_backend()) {
+            if (Pdfpc.is_Wayland_backend() && Options.wayland_workaround) {
                 // See issue 214. Wayland is doing some double scaling therefore
                 // we are lying about the actual screen size
                 this.screen_geometry.width /= this.gdk_scale;
@@ -116,10 +116,27 @@ namespace pdfpc.Window {
             }
 
             this.overlay_layout = new Gtk.Overlay();
+            this.overlay_layout.halign = Gtk.Align.CENTER;
+            this.overlay_layout.valign = Gtk.Align.CENTER;
+
             this.pointer_drawing_surface = new Gtk.DrawingArea();
             this.pen_drawing_surface = new Gtk.DrawingArea();
             this.video_surface = new View.Video();
 
+            this.overlay_layout.add_overlay(this.video_surface);
+            this.overlay_layout.add_overlay(this.pen_drawing_surface);
+            this.overlay_layout.add_overlay(this.pointer_drawing_surface);
+
+            this.video_surface.realize.connect(() => {
+                this.set_widget_event_pass_though(this.video_surface, true);
+            });
+            this.pen_drawing_surface.realize.connect(() => {
+                this.set_widget_event_pass_though(this.pen_drawing_surface, true);
+            });
+            this.pointer_drawing_surface.realize.connect(() => {
+                this.set_widget_event_pass_though(this.pointer_drawing_surface, true);
+            });
+
             this.pointer_drawing_surface.halign = Gtk.Align.FILL;
             this.pointer_drawing_surface.valign = Gtk.Align.FILL;
 
@@ -236,6 +253,16 @@ namespace pdfpc.Window {
                 return true;
             }
         }
+
+        /**
+         * Set the widget passthrough.
+         *
+         * If set to true, the widget will not receive events and they will be forwarded to the
+         * underlying widgets within the Gtk.Overlay
+         */
+        protected void set_widget_event_pass_though(Gtk.Widget w, bool pass_through) {
+            this.overlay_layout.set_overlay_pass_through(w, pass_through);
+        }
     }
 }
 
--- pdf-presenter-console-4.1.orig/src/classes/window/presentation.vala
+++ pdf-presenter-console-4.1/src/classes/window/presentation.vala
@@ -73,12 +73,7 @@ namespace pdfpc.Window {
                 this.view.get_renderer().cache = Renderer.Cache.create(metadata);
             }
 
-            this.overlay_layout.halign = Gtk.Align.CENTER;
-            this.overlay_layout.valign = Gtk.Align.CENTER;
             this.overlay_layout.add(this.view);
-            this.overlay_layout.add_overlay(this.video_surface);
-            this.overlay_layout.add_overlay(this.pen_drawing_surface);
-            this.overlay_layout.add_overlay(this.pointer_drawing_surface);
 
             this.overlay_layout.set_size_request(
                 this.main_view.get_renderer().width / this.gdk_scale,
@@ -87,10 +82,6 @@ namespace pdfpc.Window {
 
             this.add(overlay_layout);
 
-            this.add_events(Gdk.EventMask.KEY_PRESS_MASK);
-            this.add_events(Gdk.EventMask.BUTTON_PRESS_MASK);
-            this.add_events(Gdk.EventMask.SCROLL_MASK);
-
             this.key_press_event.connect(this.presentation_controller.key_press);
             this.button_press_event.connect(this.presentation_controller.button_press);
             this.scroll_event.connect(this.presentation_controller.scroll);
--- pdf-presenter-console-4.1.orig/src/classes/window/presenter.vala
+++ pdf-presenter-console-4.1/src/classes/window/presenter.vala
@@ -361,12 +361,7 @@ namespace pdfpc.Window {
             strict_views.pack_start(this.strict_prev_view, false, false, 0);
             strict_views.pack_end(this.strict_next_view, false, false, 0);
 
-            this.overlay_layout.halign = Gtk.Align.CENTER;
-            this.overlay_layout.valign = Gtk.Align.CENTER;
             this.overlay_layout.add(this.current_view);
-            this.overlay_layout.add_overlay(this.video_surface);
-            this.overlay_layout.add_overlay(this.pen_drawing_surface);
-            this.overlay_layout.add_overlay(this.pointer_drawing_surface);
 
             this.overlay_layout.set_size_request(
                 this.main_view.get_renderer().width / this.gdk_scale,
--- pdf-presenter-console-4.1.orig/src/pdfpc.vala
+++ pdf-presenter-console-4.1/src/pdfpc.vala
@@ -68,6 +68,7 @@ namespace pdfpc {
             { "start-time", 't', 0, OptionArg.STRING, ref Options.start_time, "Start time of the presentation to be used as a countdown. (Format: HH:MM (24h))", "T" },
             { "version", 'v', 0, 0, ref Options.version, "Print the version string and copyright statement", null },
             { "windowed", 'w', 0, 0, ref Options.windowed, "Run in windowed mode (devel tool)", null},
+            { "wayland-workaround", 'W', 0, 0, ref Options.wayland_workaround, "Enable Wayland-specific workaround. This might fix HiDPI scaling problems", null},
             { "disable-compression", 'z', 0, 0, ref Options.disable_cache_compression, "Disable the compression of slide images to trade memory consumption for speed. (Avg. factor 30)", null },
             { "size", 'Z', 0, OptionArg.STRING, ref Options.size, "Size of the presentation window in width:height format (forces windowed mode)", null},
             { null }
