Skip to content

Commit 4b1cce2

Browse files
committed
Workaround for Wayland with HiDPI settings
Wayland with hidpi settings did some double scaling which resulted in too large windows. When we detect a wayland session (via external C code) we 'fix' the wrong screen geometry.
1 parent bce939b commit 4b1cce2

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

src/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ endif()
5757

5858
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/paths.in ${CMAKE_CURRENT_BINARY_DIR}/paths.vala)
5959

60+
file (GLOB_RECURSE C_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c)
6061
file (GLOB_RECURSE VALA_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.vala)
6162
list(REMOVE_ITEM VALA_SRC paths.vala)
6263
if (MOVIES)
@@ -87,11 +88,12 @@ GENERATE_VAPI
8788
presenter
8889
CUSTOM_VAPIS
8990
${CMAKE_CURRENT_BINARY_DIR}/paths.vala
91+
${CMAKE_CURRENT_SOURCE_DIR}/custom_binding.vapi
9092
)
9193

92-
9394
add_executable(pdfpc
9495
${VALA_C}
96+
${C_SRC}
9597
)
9698

9799
# explicitly add libraries (needed e.g. for Fedora 13+)

src/classes/window/fullscreen.vala

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ namespace pdfpc.Window {
108108
}
109109

110110
this.gdk_scale = this.screen_to_use.get_monitor_scale_factor(this.screen_num_to_use);
111+
if (Pdfpc.is_Wayland_backend()) {
112+
// See issue 214. Wayland is doing some double scaling therefore
113+
// we are lying about the actual screen size
114+
this.screen_geometry.width /= this.gdk_scale;
115+
this.screen_geometry.height /= this.gdk_scale;
116+
}
111117

112118
this.overlay_layout = new Gtk.Overlay();
113119
this.pointer_drawing_surface = new Gtk.DrawingArea();

src/custom_binding.vapi

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[CCode (cheader_filename = "display_backend.h")]
2+
namespace Pdfpc {
3+
[CCode (cname = "is_Wayland_backend")]
4+
bool is_Wayland_backend();
5+
6+
[CCode (cname = "is_X11_backend")]
7+
bool is_X11_backend();
8+
}

src/display_backend.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "display_backend.h"
2+
3+
#include <stdio.h>
4+
5+
#include <gdk/gdk.h>
6+
#ifdef GDK_WINDOWING_X11
7+
#include <gdk/gdkx.h>
8+
#endif
9+
#ifdef GDK_WINDOWING_WAYLAND
10+
#include <gdk/gdkwayland.h>
11+
#endif
12+
13+
bool is_Wayland_backend() {
14+
GdkDisplay *gdk_display = gdk_display_get_default();
15+
#ifdef GDK_WINDOWING_WAYLAND
16+
if (GDK_IS_WAYLAND_DISPLAY(gdk_display)) {
17+
return true;
18+
}
19+
#endif
20+
21+
return false;
22+
}
23+
24+
bool is_X11_backend() {
25+
GdkDisplay *gdk_display = gdk_display_get_default();
26+
#ifdef GDK_WINDOWING_X11
27+
if (GDK_IS_X11_DISPLAY(gdk_display)) {
28+
return true;
29+
}
30+
#endif
31+
32+
return false;
33+
}
34+

src/display_backend.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef DISPLAY_BACKEND_H
2+
#define DISPLAY_BACKEND_H
3+
4+
#include <stdbool.h>
5+
6+
bool is_Wayland_backend();
7+
bool is_X11_backend();
8+
9+
#endif

0 commit comments

Comments
 (0)