Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: region selection incorrect on Wayland with scaling #195

Open
davisrichard437 opened this issue Jul 3, 2024 · 11 comments
Open

Bug: region selection incorrect on Wayland with scaling #195

davisrichard437 opened this issue Jul 3, 2024 · 11 comments
Labels

Comments

@davisrichard437
Copy link

Summary

I am having trouble using gscreenshot's region capture on Wayland. I am using sway with fractional scaling (1.5x). When I attempt to take a screenshot via a region selection, the resulting image is of a smaller region than I selected, with corners up and to the left of the selected region.

gscreenshot examples

For example, here is a screenshot of the entire screen (no region selection):

image

And here is a screenshot where I have used selected the entire screen as a region:

image

I do not have this problem when sway is unscaled (swaymsg output eDP-1 scale 1.0 or similar). Here is a screenshot using a region selection of the whole screen with 1.0 scaling:

image

The problem persists with 2.0 scaling, so it is not an issue of fractional or whole-number scaling. Here is a screenshot using region selection of the whole screen with 2.0 scaling:

image

This screenshot is (visually) exactly half the screen, so I imagine the program somehow misinterprets scaled coordinates.

grim/slurp examples

I do not have this same problem with "raw" grim/slurp region selection (grim -g "$(slurp)").

No region selection:

image

Region selection of the entire screen:

image

Some information

  • OS: NixOS Unstable 24.11.20240613.e9ee548 (Vicuna)
  • WM: sway 1.9
  • gscreenshot --version
Using grim screenshot backend
gscreenshot 3.5.1; A simple screenshot tool supporting multiple backends.
Available features: Cursor Capture (gscreenshot), Full Screen Capture (grim), Alternate Cursor (gscreenshot), Region Selection (slurp), Reuse Region (slurp)
https://github.com/thenaterhood/gscreenshot
...
  • Package: mine for NixOS/nixpkgs. There's a chance I have it packaged wrong, so I'd be interested to know if others can reproduce this error.
@thenaterhood
Copy link
Owner

That's very interesting! For context about how gscreenshot does region selection, it takes a screenshot of the entire display then crops it based on the output of the region selection tool, in your case slurp. It's possible that gscreenshot needs to adjust something by the scaling ratio.

@thenaterhood
Copy link
Owner

Reproducible in KDE

@thenaterhood
Copy link
Owner

This should be working in gscreenshot 3.6.1

@davisrichard437
Copy link
Author

I'm afraid it still doesn't work for me, but I'll do some more digging

@thenaterhood
Copy link
Owner

Try out version 3.6.2 which I just released this morning and see if it works any better. One of the Gtk calls was wrong and gscreenshot was falling back to another method of getting the scaling that might not have been accurate on your setup.

@davisrichard437
Copy link
Author

Unfortunately no, now I get something like this:

image

It seems to be larger (dilated down and to the right) than the region selection I had chosen, even going off the screen. For comparison, with grim/slurp:

image

One thing to consider is that I am currently using two monitors with different scaling; this could potentially be a problem in detecting scaling. One is a 1920x1080 external display with no scaling and the other is a 2256x1504 laptop screen with 1.5 scaling. However, even when I disconnect the external display, the problem persists, so I doubt this is the cause of the issue.

If it would help, I'd be happy to run a version with debugging/print statements and send the output here.

@thenaterhood
Copy link
Owner

Here's a Python script you can run which should output the scaling factor of the current screen. It will call into gscreenshot's functions as well as another call that uses a different approach.

from gscreenshot.scaling.scaling_factor import (
    get_scaling_from_gdk,
    get_scaling_from_qt,
    get_scaling_from_xft_dpi,
)

def another_method_getting_scaling_from_gdk():
    """Get scaling factor from Gtk"""
    # pylint: disable=import-outside-toplevel
    import gi
    gi.require_version('Gtk', '3.0')
    from gi.repository import Gtk # type: ignore

    w = Gtk.Window()
    screen = w.get_screen()
    display = screen.get_display()
    monitor = (
        display.get_monitor_at_window(screen.get_root_window())
        or display.get_primary_monitor()
        or display.get_monitor(0)
    )
    if monitor:
        return monitor.get_scale_factor()
    return None

for scaling_detector in (
    get_scaling_from_gdk,
    another_method_getting_scaling_from_gdk,
    get_scaling_from_qt,
    get_scaling_from_xft_dpi,
):
    print(f"{scaling_detector} says scale is {scaling_detector()}")

@Momo8289
Copy link

Momo8289 commented Nov 5, 2024

I'm having the same issue as davis above, where taking a screenshot by selecting an area is offset from where it should be (and contains black spaces). I'm using KDE Plasma and wayland, and I have my screen scaling set to 125%. Changing it to 100% does fix the issue, so that does seem to be the source of the problem. The output I get from your script is the following:

<function get_scaling_from_gtk at 0x7577b2474540> says scale is 2
<function another_method_getting_scaling_from_gdk at 0x7577b34fa480> says scale is 2
<function get_scaling_from_qt at 0x7577b2474680> says scale is None
<function get_scaling_from_xft_dpi at 0x7577b24745e0> says scale is 1.25

I'm using gscreenshot 3.6.3.

@thenaterhood
Copy link
Owner

Fantastic, thank you! That's a really good datapoint. Interesting variation between those with only one of them actually having the correct value for your setup.

@thenaterhood thenaterhood reopened this Nov 5, 2024
@Momo8289
Copy link

Momo8289 commented Dec 9, 2024

This appears to be fixed for me in the latest version, 3.8.0-1

@thenaterhood
Copy link
Owner

Thanks @Momo8289! I did slip some scaling improvements into 3.8.0 :). Glad to hear it helped someone.

While I think it's better "in general," on my own setup I still have some misalignment of selections so there's still room for improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants