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

Support for up & coming cosmic-desktop #3680

Open
gerelef opened this issue Jul 27, 2024 · 15 comments
Open

Support for up & coming cosmic-desktop #3680

gerelef opened this issue Jul 27, 2024 · 15 comments
Labels
Unconfirmed Bug The bug is not confirmed by anyone else.

Comments

@gerelef
Copy link

gerelef commented Jul 27, 2024

Flameshot Version

> flameshot --version
Flameshot v12.1.0 (-)
Compiled with Qt 5.15.12

Installation Type

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

Operating System type and version

fedora-40; cosmic-desktop DE

Description

Flameshot instantly fatally errors when attempting to take screenshot via any way.
Running under cosmic-desktop, installed in fedora 40 via copr

sudo dnf copr enable -y ryanabx/cosmic-epoch
sudo dnf install -y cosmic-desktop

Steps to reproduce

  1. install cosmic-desktop
  2. run flameshot gui in the terminal
  3. ???
  4. flameshot dies with the logs below:
> flameshot gui
flameshot: error: Unable to detect desktop environment (GNOME? KDE? Sway? ...)
flameshot: error: Hint: try setting the XDG_CURRENT_DESKTOP environment variable.
flameshot: error: Unable to capture screen
flameshot: error: Unable to capture screen
Unable to get current screen, starting to use primary screen. It may be a cause of logical error and working with a wrong screen.
Unable to get current screen, starting to use primary screen. It may be a cause of logical error and working with a wrong screen.
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
flameshot: info: Screenshot aborted.

Screenshots or screen recordings

No response

System Information

fedora 40, cosmic-desktop via copr running wayland w/ display layout:
screenshot-2024-07-27-16-37-44

@gerelef gerelef added the Unconfirmed Bug The bug is not confirmed by anyone else. label Jul 27, 2024
@nevdelap
Copy link

nevdelap commented Aug 10, 2024

COSMIC is looking brilliant, and I'm switching over on WFH machine, but living without Flameshot is unthinkable! 😉 👍

@py-crash
Copy link

Setting the variable XDG_CURRENT_DESKTOP will also not help:

$ XDG_CURRENT_DESKTOP=COSMIC  flameshot
QSocketNotifier: Can only be used with threads started with QThread
flameshot: error: Unable to detect desktop environment (GNOME? KDE? Sway? ...)
flameshot: error: Hint: try setting the XDG_CURRENT_DESKTOP environment variable.
flameshot: error: Unable to capture screen
flameshot: error: Unable to capture screen
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()

@chaimite
Copy link

chaimite commented Sep 3, 2024

+1 to fix this on cosmic

@GetPsyched
Copy link

GetPsyched commented Sep 8, 2024

Flameshot works fine on COSMIC for me. The only thing that's borked for me is #2848, which seems to be independent of COSMIC.

Flameshot v12.1.0 (-)
Compiled with Qt 5.15.14

Maybe trying newer versions of COSMIC could help? Idk, I'm new to COSMIC too.

@nevdelap
Copy link

nevdelap commented Sep 9, 2024

I've got the same version of Flameshot and Qt as you and I've updated to the lastest cosmic by removing the version from the Arch repos and installing cosmic-session-git from the AUR. Unfortunately for me it's not working.

10:23:49 zen ~ flameshot
QSocketNotifier: Can only be used with threads started with QThread
10:24:11 zen ~ flameshot gui
QSocketNotifier: Can only be used with threads started with QThread
flameshot: error: Unable to detect desktop environment (GNOME? KDE? Sway? ...)
flameshot: error: Hint: try setting the XDG_CURRENT_DESKTOP environment variable.
flameshot: error: Unable to capture screen
flameshot: error: Unable to capture screen
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
flameshot: info: Screenshot aborted.
10:24:13 zen ~

Clicking Take Screenshot in the Flameshot system tray applet's menu...

image

@GetPsyched
Copy link

NGL, if the error is this flakey, it seems like a bug in COSMIC than in Flameshot? But I don't know the internals of either software. Would be better if a maintainer commented here.

@manfredlotz
Copy link

It seems to me that the code needs some small enhancements to make things work under COSMIC

  • In src/utils/desktopinfo.h a line COSMIC needs to be added in the enum WM
  • In src/utils/desktopinfo.cpp there is a function DesktopInfo::WM DesktopInfo::windowManager() which needs
            if (desktop.contains(QLatin1String("cosmic"))) {
              return DesktopInfo::COSMIC;
    

to be added

Then it should work in COSMIC>

@616b2f
Copy link

616b2f commented Sep 15, 2024

It seems to me that the code needs some small enhancements to make things work under COSMIC

  • In src/utils/desktopinfo.h a line COSMIC needs to be added in the enum WM
  • In src/utils/desktopinfo.cpp there is a function DesktopInfo::WM DesktopInfo::windowManager() which needs
            if (desktop.contains(QLatin1String("cosmic"))) {
              return DesktopInfo::COSMIC;
    

to be added

Then it should work in COSMIC>

If you already figured that out, maybe you could create an PR for it? :)

@manfredlotz
Copy link

Ok, will do

@nevdelap
Copy link

nevdelap commented Sep 18, 2024

Hi @manfredlotz. I gave that a go. I made the changes you suggested, and got this...

QSocketNotifier: Can only be used with threads started with QThread
flameshot: warning: grim's screenshot component is implemented based on wlroots, it may not be used in GNOME or similar desktop environments
flameshot: error: The universal wayland screen capture adapter requires Grim as the screen capture component of wayland. If the screen capture component is missing, please install it!
flameshot: error: Unable to capture screen
flameshot: error: Unable to capture screen
QLayout: Attempting to add QLayout "" to SidePanelWidget "", which already has a layout
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
flameshot: info: Screenshot aborted.

So I install grim, and got this...

QSocketNotifier: Can only be used with threads started with QThread
flameshot: warning: grim's screenshot component is implemented based on wlroots, it may not be used in GNOME or similar desktop environments
QLayout: Attempting to add QLayout "" to SidePanelWidget "", which already has a layout
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()

So there's more to it.

@manfredlotz
Copy link

Hm. I am running Arch based EndeavourOS and when I start flameshot gui in a terminal I get

flameshot: warning: If the USE_WAYLAND_GRIM option is not activated, the dbus protocol will be used. It should be noted that using the dbus protocol under wayland is not recommended. It is recommended to recompile with the USE_WAYLAND_GRIM flag to activate the grim-based general wayland screenshot adapter
QLayout: Attempting to add QLayout "" to SidePanelWidget "", which already has a layout
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()

and I can take a screenshot.

I have to admit that I did nothing special regarding USE_WAYLAND_GRIM.

@manfredlotz
Copy link

Checking with ldd I see that

        libwayland-client.so.0
        libwayland-cursor.so.0

are not linked in.

So if I should activate some USE_... options please tell me where to do that.

@manfredlotz
Copy link

manfredlotz commented Sep 18, 2024

Ok, I found out how to build and add USE_...

I did

cmake -B build   -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr/local \
                             -DUSE_WAYLAND_CLIPBOARD=1 -DUSE_WAYLAND_GRIM=1 \
                             -Wno-dev

and now when running flameshot gui I get

flameshot: warning: grim's screenshot component is implemented based on wlroots, it may not be used in GNOME or similar desktop environments
QLayout: Attempting to add QLayout "" to SidePanelWidget "", which already has a layout
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()

So it seems that I have to make grim's screenshot component happy. But to be honest I do not know enough here about wlroots and such.

@nevdelap
Copy link

nevdelap commented Sep 19, 2024

I've found that flameshot is calling grim -, and complaining if it doesn't exist at all, but if it does, it is not checking its exit status and not complaining - so it doesn't get data because in Cosmic grim - says that it doesn't support wlr-screencopy-unstable-v1, and it looks like it has hung because it doesn't show its UI.

The wlr-screencopy-unstable-v1 issue is discussed here. So I believe that shows that the whole problem is grim and Cosmic not being compatible with each other, and that flameshot would work if they were.

But I've found a partial workaround.

With the released version of flameshot installed (I have flameshot-git installed from the AUR - it doesn't need adding a mention of Cosmic in those two places)...

  1. Uninstall grim.
  2. Create a grim file on the path and chmod +x it. It will use cosmic-screenshot to take the screenshot before passing it on to flameshot.
#!/bin/bash
cosmic-screenshot > /dev/null
cat $(ls -tr ~/Pictures/screenshot-*.png | tail -n 1)
  1. Disable the 'Take a screenshot' default keyboard shortcut.
    disabled
  2. Bind the keyboard shortcut to flameshot gui.
    print
  3. When you capture a screenshot set it to 'Save to Pictures'.
  4. The flameshot gui runs, you mark it up.
    image
  5. Save it. See the caveat below. I cannot copy it.
    flameshot

Yes! Those screenshots are annotated in flameshot in Cosmic.

There is one major caveat that I haven't found a solution for: copying to the clipboard in 'flameshot' says it copied to the clipboard, but I cannot paste from it. So you have to save the screen shot, and insert it where you want it instead of just Ctrl+Ving where you want it.

Update: If you make your keyboard shortcut do flameshot gui --raw | wl-copy you'll have a tick button on the toolbar instead of copy and save buttons, and that will successfully copy to the clipboard. Thanks @GetPsyched! #2848

image

One other thing to note: cosmic-screenshot takes the screenshot on whichever screen, but flameshot opens it for annotating only on my leftmost screen (my laptop) which is screen 1 according to cosmic-settings. It will probably never be a problem. The only reason it might be a problem is if I take a screenshot on my external monitor that is larger than my laptop screen.

And one another: if you exit out of cosmic-screenshot with the X flameshot will open the last screenshot, because the grim script ignores the exit code of cosmic-screenshot. It has to, since if grim exits without catting an image to stdout flameshot gui will continue running in the background and you have to manually kill it.

If flameshot gui is updated to check the exit code of grim, grim could be updated to...

#!/bin/bash
cosmic-screenshot > /dev/null && cat $(ls ~/Pictures/*.png | tail -n 1)

The other things I tried was this...

cosmic-screenshot --interactive=false --save-dir=~/Pictures > /dev/null
cat $(ls ~/Pictures/*.png | tail -n 1)

...but that takes a screenshot of the laptop screen, rather than the current screen. I'll raise an issue about that.

@GetPsyched
Copy link

@nevdelap not being able to copy the screenshot is an issue independent of COSMIC AFAIK, it's because of Wayland. See #2848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unconfirmed Bug The bug is not confirmed by anyone else.
Projects
None yet
Development

No branches or pull requests

7 participants