Clemapfel/Mousetrap.jl

Windows dont move correctly with "non standard" screen scales.

MichaelSchloesser opened this issue · 3 comments

Windows 10 (and other OS as well) allows the user to set a scale parameter, that changes the size of text, apps and some other things. This is useful when using a device with high resolution but small display (in this case a microsoft surface). However when i create a window using Mousetrap, and try to drag it somewhere, this scale parameter does not seem to be taken into account. Suppose i use a scale of 200% and want to drag the window to a position (x, y) then it ends up at (2x, 2y) instead.

I was not able to reproduce this on any other Windows machine.

Device specifications:
Device name: Microsoft-Surface
Processor: Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz 1.50 GHz
Installed RAM: 8,00 GB (7,60 GB usable)
System type: 64-bit operating system, x64-based processor
Pen and touch: Pen and touch support with 10 touch points

Windows specifications:
Edition: Windows 10 Home
Version: 22H2
Installed on: ‎ 20/‎01/‎2023
OS build: 19045.3930
Experience: Windows Feature Experience Pack 1000.19053.1000.0

Hi, I think this is fixable but I need to research how to make the back-end aware of the monitor scale. I'll ask my GNOME contacts, which may take a few days, and get back to you.

Until then, could you run

begin
    using Mousetrap
    gtk4 = Mousetrap.detail.GTK4_jll.libgtk4
    gio = Mousetrap.detail.Glib_jll.libgio

    widget = Separator()
    widget_ptr = Mousetrap.as_gobject_pointer(widget)
    gtk_display = @ccall gtk4.gtk_widget_get_display(widget_ptr::Ptr{Cvoid})::Ptr{Cvoid}
    gtk_monitor_list = @ccall gtk4.gdk_display_get_monitors(gtk_display::Ptr{Cvoid})::Ptr{Cvoid}
    gtk_monitor = @ccall gio.g_list_model_get_item(gtk_monitor_list::Ptr{Cvoid}, 0::Int)::Ptr{Cvoid}
    println("Monitor Scale: ", @ccall gtk4.gdk_monitor_get_scale_factor(gtk_monitor::Ptr{Cvoid})::Int)
end

in the REPL and tell me what it prints?

Hi, thanks for your quick answer.

running your code get the following error (on both my surface and my desktop computer):

ERROR: UndefVarError: as_gobject_pointer not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:31
 [2] top-level scope
   @ .\REPL[2]:7

Sorry for the period of inactivity, I found out this was an issue fixed with GTK4.12: https://gitlab.gnome.org/GNOME/gtk/-/issues/5877, so it was a bug. This will be fixed when the binary builder jll package mousetrap depends on is updated.