@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
2222#pragma once
2323
24- #include < gdk/gdk .h>
24+ #include < gtk/gtk .h>
2525
2626#ifdef RUISAPP_RENDER_OPENGL
2727# include < GL/glx.h>
@@ -78,24 +78,22 @@ public:
7878 display_wrapper () :
7979 xorg_input_method (this ->xorg_display),
8080 scale_factor ([]() {
81- // get scale factor
82- gdk_init (nullptr , nullptr );
83-
84- // GDK-4 version commented out because GDK-4 is not available in Debian 11
85-
86- // auto display_name = DisplayString(ww.display.display);
87- // std::cout << "display name = " << display_name << std::endl;
88- // auto disp = gdk_display_open(display_name);
89- // utki::assert(disp, SL);
90- // std::cout << "gdk display name = " << gdk_display_get_name(disp) << std::endl;
91- // auto surf = gdk_surface_new_toplevel (disp);
92- // utki::assert(surf, SL);
93- // auto mon = gdk_display_get_monitor_at_surface (disp, surf);
94- // utki::assert(mon, SL);
95- // int sf = gdk_monitor_get_scale_factor(mon);
96-
97- // GDK-3 version
98- int sf = gdk_window_get_scale_factor (gdk_get_default_root_window ());
81+ gtk_init ();
82+
83+ auto disp = gdk_display_open (
84+ // We have to use NULL here because on Wayland it cannot connect to :0 X display even if XWayland is enabled,
85+ // because the display name in that case is 'wayland-0'.
86+ // Using NULL here makes it detect the correct display automatically.
87+ NULL
88+ );
89+ utki::assert (disp, SL);
90+ std::cout << " gdk display name = " << gdk_display_get_name (disp) << std::endl;
91+ auto surf = gdk_surface_new_toplevel (disp);
92+ utki::assert (surf, SL);
93+ auto mon = gdk_display_get_monitor_at_surface (disp, surf);
94+ utki::assert (mon, SL);
95+ int sf = gdk_monitor_get_scale_factor (mon);
96+
9997 auto scale_factor = ruis::real (sf);
10098
10199 std::cout << " display scale factor = " << scale_factor << std::endl;
0 commit comments