flameshot-org / flameshot

Powerful yet simple to use screenshot software :desktop_computer: :camera_flash:
https://flameshot.org
GNU General Public License v3.0
24.05k stars 1.53k forks source link

flameshot with Gnome 44 and wayland working only in specific setting #3213

Open manfredlotz opened 1 year ago

manfredlotz commented 1 year ago

Flameshot Version

This is EndeavourOS with Gnome 44 and Wayland. flameshot is 12.1.0-1

Flameshot v12.1.0 (-) Compiled with Qt 5.15.5 linux: 6.3.4-zen1-1-zen endeavouros: unknown

Installation Type

Linux, MacOS, or Windows Package manager (apt, pacman, eopkg, choco, brew, ...)

Operating System type and version

Linux, 6.3.4-zen

Description

As I was unable to get a screenshot with flameshot I copied /usr/share/applications/org.flameshot.Flameshot.desktop to ~/.local/share/applications/org.flameshot.Flameshot.desktop

Then I changed the exec line to

Exec=env XDG_SESSION_TYPE= QT_QPA_PLATFORM=wayland /usr/bin/flameshot

flameshot starts ok but screenshot not working

I ran dbus-monitor --session sender=org.flameshot.Flameshot and got

method call time=1685385145.732791 sender=:1.314 -> destination=org.freedesktop.portal.Desktop serial=30 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.Screenshot; member=Screenshot
   string ""
   array [
      dict entry(
         string "handle_token"
         variant             string "e439ac62bf72498fb8b3c67a00fd9c88"
      )
      dict entry(
         string "interactive"
         variant             boolean false
      )
   ]

But when I create a script ~/bin/flameshot.sh containing

#! /bin/sh

env XDG_SESSION_TYPE= QT_QPA_PLATFORM=wayland /usr/bin/flameshot

then flameshot starts ok and screenshot is working fine

Here the dbus-monitor shows

method call time=1685385248.149252 sender=:1.354 -> destination=org.freedesktop.DBus serial=31 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.portal.Desktop'"
method call time=1685385248.149292 sender=:1.354 -> destination=org.freedesktop.DBus serial=32 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetNameOwner
   string "org.freedesktop.portal.Desktop"
method call time=1685385248.149642 sender=:1.354 -> destination=org.freedesktop.DBus serial=33 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetNameOwner
   string "org.freedesktop.portal.Desktop"
method call time=1685385248.149939 sender=:1.354 -> destination=org.freedesktop.DBus serial=34 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',sender='org.freedesktop.portal.Desktop',path='/org/freedesktop/portal/desktop/request/1_354/0617ee6d667a4d04afbeb06e5c7962cd',interface='org.freedesktop.portal.Request',member='Response'"
method call time=1685385248.149957 sender=:1.354 -> destination=org.freedesktop.DBus serial=35 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.portal.Desktop'"
method call time=1685385248.149966 sender=:1.354 -> destination=org.freedesktop.DBus serial=36 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetNameOwner
   string "org.freedesktop.portal.Desktop"
method call time=1685385248.150206 sender=:1.354 -> destination=org.freedesktop.portal.Desktop serial=37 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.Screenshot; member=Screenshot
   string ""
   array [
      dict entry(
         string "handle_token"
         variant             string "0617ee6d667a4d04afbeb06e5c7962cd"
      )
      dict entry(
         string "interactive"
         variant             boolean false
      )
   ]
method call time=1685385248.695167 sender=:1.354 -> destination=org.freedesktop.portal.Desktop serial=38 path=/org/freedesktop/portal/desktop/request/1_354/0617ee6d667a4d04afbeb06e5c7962cd; interface=org.freedesktop.portal.Request; member=Close
method call time=1685385248.696921 sender=:1.354 -> destination=org.freedesktop.DBus serial=39 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.freedesktop.portal.Desktop',path='/org/freedesktop/portal/desktop/request/1_354/0617ee6d667a4d04afbeb06e5c7962cd',interface='org.freedesktop.portal.Request',member='Response'"
method call time=1685385248.696945 sender=:1.354 -> destination=org.freedesktop.DBus serial=40 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.portal.Desktop'"
method call time=1685385248.696954 sender=:1.354 -> destination=org.freedesktop.DBus serial=41 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.portal.Desktop'"
method call time=1685385252.688376 sender=:1.354 -> destination=org.freedesktop.Notifications serial=42 path=/org/freedesktop/Notifications; interface=org.freedesktop.DBus.Introspectable; member=Introspect
method call time=1685385252.689504 sender=:1.354 -> destination=org.freedesktop.DBus serial=43 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.Notifications'"
method call time=1685385252.689563 sender=:1.354 -> destination=org.freedesktop.DBus serial=44 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetNameOwner
   string "org.freedesktop.Notifications"
method call time=1685385252.690196 sender=:1.354 -> destination=org.freedesktop.Notifications serial=45 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=Notify
   string "flameshot"
   uint32 0
   string "flameshot"
   string "Flameshot Info"
   string "Capture saved to clipboard."
   array [
   ]
   array [
   ]
   int32 5000
method call time=1685385252.699636 sender=:1.354 -> destination=org.freedesktop.DBus serial=46 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.Notifications'"

I have no idea if this is a flameshot specific error or if there is some kind of permission which flameshot lacks when called directly

Steps to reproduce

see above in the description

Screenshots or screen recordings

No response

System Information

System:
  Host: hogwart Kernel: 6.3.4-zen1-1-zen arch: x86_64 bits: 64 Desktop: GNOME
    v: 44.1 Distro: EndeavourOS
Graphics:
  Device-1: NVIDIA TU116M [GeForce GTX 1650 Ti Mobile] driver: nvidia
    v: 530.41.03
  Device-2: AMD Renoir driver: amdgpu v: kernel
  Device-3: Chicony HD Webcam driver: uvcvideo type: USB
  Display: wayland server: X.org v: 1.21.1.8 with: Xwayland v: 23.1.1
    compositor: gnome-shell v: 44.1 driver: X: loaded: amdgpu,nvidia
    unloaded: modesetting,radeon dri: radeonsi gpu: nvidia,amdgpu
    resolution: 1920x1080
  API: OpenGL v: 4.6 Mesa 23.1.1 renderer: AMD Radeon Graphics (renoir LLVM
    15.0.7 DRM 3.52 6.3.4-zen1-1-zen)
manfredlotz commented 1 year ago

I forgot to mention that in case the screenshot doesn't work I also see

May 29 13:01:49 hogwart xdg-desktop-por[8123]: Failed to show access dialog: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: 
Only the focused app is allowed to show a system access dialog

in the syslogs

mmahmoudian commented 1 year ago

Thanks for the detailed report. It is highly appreciated.

manfredlotz commented 1 year ago

I have to say thank you for your work on this great tool!! :-)

jack9603301 commented 1 year ago

@manfredlotz Hi, can you help to test if grim can take screenshots?

manfredlotz commented 1 year ago

Hm, when I install grim from extra, i.e extra/grim 1.4.0-3 and try to start it I get

compositor doesn't support wlr-screencopy-unstable-v1

There is more grim like stuff in AUR. Which one should I try?

jack9603301 commented 1 year ago

Sure enough, wlroots' screenshot adapter doesn't work, can you find other command line screenshots for gnome?

manfredlotz commented 1 year ago

You mean one working with Wayland, I assume. I will take a look.

manfredlotz commented 1 year ago

The Gnome builtin screenshot utiliy works of course but I guess this is not a test you like to see.

jack9603301 commented 1 year ago

You mean one working with Wayland, I assume. I will take a look.

yep

Just find the command line screencast tool for gnome's wayland technology, and I'll be able to use it as a screencast adapter

jack9603301 commented 1 year ago

The Gnome builtin screenshot utiliy works of course but I guess this is not a test you like to see.

It should be a command-line screenshot tool that can output screenshots through stdout or files, without any graphical interface, and it applies to the wayland screenshot protocol of GNOME and can work properly in the wayland environment of gnome.

jack9603301 commented 1 year ago

@manfredlotz Can you help me find it?

manfredlotz commented 1 year ago

I will try. I wasn't yet successful to find a command line screenshot tool working with Wayland. Searching....

jack9603301 commented 1 year ago

I will try. I wasn't yet successful to find a command line screenshot tool working with Wayland. Searching....

If you find it, just let me know, and then I'll check the documentation for this tool, and then, I'll submit a PR to enable this adapter.

This solves the problem of relying on dbus under wayland

manfredlotz commented 1 year ago

Not yet found anything. The only quick and dirty way I found was

This works fine.

Should add that I did not specifically set any env var.

jack9603301 commented 1 year ago

Using dbus to take screenshots in wayland is not a good idea. I prefer to use a screenshot adapter that supports the corresponding wayland compositor screenshot protocol

I'll look for it, but I'm not sure I can find the right one. If you can, please let me know.

manfredlotz commented 1 year ago

It is not easy to find anything. I let you know if I will find something.

jack9603301 commented 1 year ago

@manfredlotz https://github.com/ksnip/ksnip

Can you help test this? Use the following command

ksnip -p 1.png -c

It also has a GUI function for editing, but we only need the command line

You can do automatic downloads from your distribution's package manager

manfredlotz commented 1 year ago

Hm, when I try

ksnip -p 1.png -c I get

Info: Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
Warning: No capture mode selected, using default.
Critical: Invalid reply from DBus: Screenshot is not allowed

Now trying: env XDG_SESSION_TYPE= QT_QPA_PLATFORM=wayland ksnip -p 1.png -c

and get

Critical: Unknown platform, using default X11 Image Grabber.
Warning: No capture mode selected, using default.
fish: Job 1, 'env XDG_SESSION_TYPE= QT_QPA_PL…' terminated by signal SIGSEGV (Address boundary error)
jack9603301 commented 1 year ago

Hm, when I try

ksnip -p 1.png -c I get

Info: Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
Warning: No capture mode selected, using default.
Critical: Invalid reply from DBus: Screenshot is not allowed

Now trying: env XDG_SESSION_TYPE= QT_QPA_PLATFORM=wayland ksnip -p 1.png -c

and get

Critical: Unknown platform, using default X11 Image Grabber.
Warning: No capture mode selected, using default.
fish: Job 1, 'env XDG_SESSION_TYPE= QT_QPA_PL…' terminated by signal SIGSEGV (Address boundary error)

GNOME seems to have only a dbus screenshot interface, my goodness!

jack9603301 commented 1 year ago

env XDG_SESSION_TYPE= QT_QPA_PLATFORM=wayland ksnip -p 1.png -c

env XDG_SESSION_TYPE=gnome QT_QPA_PLATFORM=wayland ksnip -p 1.png -c

try

manfredlotz commented 1 year ago

OK, I tried env XDG_SESSION_TYPE=gnome QT_QPA_PLATFORM=wayland ksnip -p 1.png -c

and got

Critical: Unknown platform, using default X11 Image Grabber.
Warning: No capture mode selected, using default.
fish: Job 1, 'env XDG_SESSION_TYPE=gnome QT_Q…' terminated by signal SIGSEGV (Address boundary error)

When I do env XDG_SESSION_TYPE=wayland QT_QPA_PLATFORM=wayland ksnip -p 1.png -c I can select an area for the screenshot but I get the following and there is no file 1.png

Info: Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
Warning: No capture mode selected, using default.
Warning: Wayland does not support QWindow::requestActivate()
Critical: Invalid reply from DBus: Screenshot is not allowed
jack9603301 commented 1 year ago

@manfredlotz okay It looks like gnome has to interface via the dbus bus

jack9603301 commented 1 year ago

@manfredlotz Can you check if gnome's official screenshot tool can meet the following requirements:

  1. pure command line calls
  2. can be invoked without GUI interface
  3. full-screen screenshots can be saved directly to a specified file or output from a standard output stream

If these requirements can be met, please provide valid command line parameters and explanation of the parameters

manfredlotz commented 1 year ago

In Gome 44 the screenshot utility is just part of gnome-shell

But I could install gnome-screenshot 41.0+r25+g45f08f0-1 and running gnome-screenshot -f 1.png in a terminal did just work fine.

-f, --file=filename            Save screenshot directly to this file
jack9603301 commented 1 year ago

@manfredlotz okay,I got it

jack9603301 commented 1 year ago

@manfredlotz https://github.com/flameshot-org/flameshot/pull/3215

Please help test this commit with the following cmake parameters

-DUSE_WAYLAND_GNOME=true
jack9603301 commented 1 year ago

Thanks for the detailed report. It is highly appreciated.

@mmahmoudian I tried to take the issue and start working on it, and now it has its first PR

manfredlotz commented 1 year ago

I replaced the both ../src/utils/screengrabber.cpp and ../src/utils/screengrabber.h and rebuilt with cmake ../ -DUSE_WAYLAND_GNOME=true

How shall I invoke flameshot in the flameshot desktop file for testing? I mean which variables shall I explicitly set?

jack9603301 commented 1 year ago

@manfredlotz No, if you replace the source code, you must also replace the following files:

src/utils/screengrabber.cpp
src/utils/screengrabber.h
src/CMakeLists.txt

In fact you can also choose to pull branches by executing the following command

https://github.com/jack9603301/flameshot

then:

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_WAYLAND_GNOME=true -DCMAKE_BUILD_TYPE=Release
make
sudo make install

note: Please replace the file again or pull the branch, I found the error and have submitted a fix (forced commit)

manfredlotz commented 1 year ago

Ok, I got your repository and did like you described.

When invoking flameshot from command line I see

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

Now doing a screenshot by clicking on the flameshot icon in the system tray working fine and seeing these messages in the terminal

QLayout: Attempting to add QLayout "" to SidePanelWidget "", which already has a layout
flameshot: info: Capture saved to clipboard.

When starting flameshot from the desktop file (no variables set explicitly here) screenshot is not working

jack9603301 commented 1 year ago

@manfredlotz no

try run:

flameshot gui 
manfredlotz commented 1 year ago

flameshot gui from the command line works fine, as did flameshot without any parameter and clicking on the systray icon

jack9603301 commented 1 year ago

@manfredlotz That's right, how did you compile it, please tell me the compile command!

manfredlotz commented 1 year ago

I did exactly what you gave me, i.e. the cmake command was

cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_WAYLAND_GNOME=true -DCMAKE_BUILD_TYPE=Release

manfredlotz commented 1 year ago

Is there a way to get debug messages?

jack9603301 commented 1 year ago

I did exactly what you gave me, i.e. the cmake command was

cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_WAYLAND_GNOME=true -DCMAKE_BUILD_TYPE=Release

@manfredlotz Show me the .desktop file of your desktop flameshot file

manfredlotz commented 1 year ago

In order to be clean I removed my local .desktop file and took the one installed with sudo make install

jack9603301 commented 1 year ago

@manfredlotz okay, I suspect there is a problem with your local .desktop file definition

When you are sure there is no problem, test it, it should work fine with the presence of gnome's wayland screenshot adapter (gnome-screenshot)

manfredlotz commented 1 year ago

Being in the build/ directory I see that both

are the same.

jack9603301 commented 1 year ago

@manfredlotz You can try it, the command line launch flameshot can run, that means you create icons by mouse launch should also be normal

manfredlotz commented 1 year ago

Not sure I understand. In then end I want to autostart flameshot and being able to do a screenshot. Gnome auto-starts flameshot by using the flameshot .desktop file. And this doesn't work even with the newly built flameshot

jack9603301 commented 1 year ago

@manfredlotz Can you record a screen? Send it over and I'll take a look.

manfredlotz commented 1 year ago

After startup I have the flameshot icon in the systray at the upper right side

image

Now I want to be able to get a screenshot by clicking on the icon.

jack9603301 commented 1 year ago

@manfredlotz Don't you get a response when you click on this icon?

manfredlotz commented 1 year ago

When I use the installed .desktop file to let Gnome start flameshot and I click on that icon I get one shutter noise and nothing else.

But (as explained in my initial post) if I put the call to flameshot in a script and invoke that script via the .desktop file then things working fine.

jack9603301 commented 1 year ago

@manfredlotz How can it be so strange?

jack9603301 commented 1 year ago

@manfredlotz Would you like me to remote your computer in order to check what is going on with your system?

manfredlotz commented 1 year ago

No.

When I try to make a screenshot by clicking on the systray flameshot icon I get the message (seen by journalctl)

Jun 03 05:37:27 hogwart xdg-desktop-por[6966]: Failed to show access dialog: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Only the focused app is allowed to show a system access dialog

This is the same message I reported in the beginning when I opened the issue.

manfredlotz commented 1 year ago

On your system things are working fine?

manfredlotz commented 1 year ago

I found something. When I open flameshot configuration window and then try to make a screenshot by clicking the flameshot tray icon I get this window

image

Clicking on allow and taking screenshots is working fine.

I have no idea why I need to open the flameshot configuration window in order to be able to allow flameshot to take screenshots.