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

Add grim-based wayland universal screenshot adapter #3018

Merged
merged 8 commits into from
Feb 15, 2023
Merged

Add grim-based wayland universal screenshot adapter #3018

merged 8 commits into from
Feb 15, 2023

Conversation

jack9603301
Copy link
Contributor

In the past, flameshot used a special and superfluous method to call the wayland screenshot component - dbus protocol communication. Although this method is supported by a large number of distributions, it does not take into account the actual situation of wayland (including WM custom desktop environment users). Now, we can enable the wayland universal screenshot adapter with the help of grim, just add the following compilation flags in cmake:

-DUSE_WAYLAND_GRIM=true

In addition, the patch also adds HYPRLAND type and OTHER type support

@jack9603301
Copy link
Contributor Author

@mmahmoudian This PR is ready for review, please do a merge review.

@mmahmoudian
Copy link
Member

This looks good to me. I just request another dev to check it out as well. In the meantime I would be thankful if you can handle the clang format:
https://github.com/flameshot-org/flameshot/actions/runs/3692623906/jobs/6296081652

@jack9603301
Copy link
Contributor Author

@mmahmoudian I just did code formatting.

@kyechou
Copy link

kyechou commented Dec 18, 2022

I tested the patch with the additional cmake option in both Sway and Hyprland. Almost everything works flawlessly. There are two things:

  1. There's significant delay between the cursor moving and the screen capture window (with flameshot gui) moving with the cursor. I also tested the current master branch (b4300d3), where the issue also exists, and so I don't think the issue is related to this PR specifically. The issue doesn't exist with the current release v12.1.0. I went through some recent issues and didn't find anything similar to what I experienced. @mmahmoudian: Please let me know if I missed an old issue or if I should open a new one. Thanks!
  2. Another minor thing is that src/utils/screengrabber.cpp:147 won't ever be executed if I understand it correctly. It doesn't affect the functionality but just in case you care about such things.

@kyechou kyechou mentioned this pull request Dec 18, 2022
@yavko
Copy link

yavko commented Dec 19, 2022

Wouldn't it a better idea just to use the Wayland protocol? Also grim doesn't work under GNOME, as Mutter doesn't implement the required protocols that grim uses, so I think that should be added to the messages.

@jack9603301
Copy link
Contributor Author

jack9603301 commented Dec 19, 2022

2. Another minor thing is that src/utils/screengrabber.cpp:147 won't ever be executed if I understand it correctly. It doesn't affect the functionality but just in case you care about such things.

yes, what do you mean? should i delete it?

  1. There's significant delay between the cursor moving and the screen capture window (with flameshot gui) moving with the cursor. I also tested the current master branch (b4300d3), where the issue also exists, and so I don't think the issue is related to this PR specifically. The issue doesn't exist with the current release v12.1.0. I went through some recent issues and didn't find anything similar to what I experienced. @mmahmoudian: Please let me know if I missed an old issue or if I should open a new one. Thanks!

I was wondering about this issue, it shouldn't be my fault, there was a noticeable delay before I added this patch, I think you might want to open a new issue to fix it - it might not be related to this patch

@jack9603301
Copy link
Contributor Author

Wouldn't it a better idea just to use the Wayland protocol? Also grim doesn't work under GNOME, as Mutter doesn't implement the required protocols that grim uses, so I think that should be added to the messages.

The use of grim is mainly because it has implemented the implementation for wlroots. It should be used in a large number of wayland environments. Due to the wayland specification, its implementation is completely determined by the synthesizer. Therefore, for gnome, it is possible to use the dbus protocol to take screenshots is currently the way to go - until there are alternatives available for gnome-compositor

@yavko
Copy link

yavko commented Dec 19, 2022

Wouldn't it a better idea just to use the Wayland protocol? Also grim doesn't work under GNOME, as Mutter doesn't implement the required protocols that grim uses, so I think that should be added to the messages.

The use of grim is mainly because it has implemented the implementation for wlroots. It should be used in a large number of wayland environments. Due to the wayland specification, its implementation is completely determined by the synthesizer. Therefore, for gnome, it is possible to use the dbus protocol to take screenshots is currently the way to go - until there are alternatives available for gnome-compositor

Yeah I mean use the protocol that grim uses, if flameshot detects the user to be on a compositor that implements it. Also wasn't GNOME dbus api made private? Also I meant add it to the cmake messages

@jack9603301
Copy link
Contributor Author

Yeah I mean use the protocol that grim uses, if flameshot detects the user to be on a compositor that implements it. Also wasn't GNOME dbus api made private? Also I meant add it to the cmake messages

Do you mean, should I add a message telling users that grim is available in wlroots compositor based implementations?

src/CMakeLists.txt Outdated Show resolved Hide resolved
@jack9603301
Copy link
Contributor Author

@yavko Now, when users are running on GNOME or KDE, the grim-based generic screenshot adapter will not be enabled

@yavko
Copy link

yavko commented Dec 19, 2022

@yavko Now, when users are running on GNOME or KDE, the grim-based generic screenshot adapter will not be enabled

I might be wrong here, but I think kwin (might) implement it, as it implements other wlroots protocols.

@jack9603301
Copy link
Contributor Author

@yavko Implementation excludes KDE

@jack9603301
Copy link
Contributor Author

If KDE does not support grim, it can be modified in another PR, or through the cmake flag to disable GRIM

@yavko
Copy link

yavko commented Dec 19, 2022

If KDE does not support grim, it can be modified in another PR, or through the cmake flag to disable GRIM

After doing some research I think that KDE doesn't support it, but apparently Mir does lol.

EDIT: This website says it doesn't, and its pretty accurate most of the time https://wayland.app/protocols/wlr-screencopy-unstable-v1#compositor-support

@jack9603301
Copy link
Contributor Author

jack9603301 commented Dec 19, 2022

@yavko Ok, do you think I need to remove it? Or keep it for now?

@yavko
Copy link

yavko commented Dec 19, 2022

Ok, do you think I need to remove it? Or keep it for now?

Well from what I've seen KDE implements stuff like layer shell, but I cant find anything on it implementing screencopy so maybe remove it, and someone can re-add it down the line if they so please. For KDE its probably be a better idea to implement the in house solution used by spectacle, in a different PR.

@jack9603301
Copy link
Contributor Author

@yavko OK, It can be re-added if someone needs it in KDE

@jack9603301
Copy link
Contributor Author

@yavko

Replenish:

Regarding the gnome adaptation method of wayland, the currently feasible method is to serve the desktop app of upwork, which is at this address:

https://github.com/MarSoft/upwork-wayland

The author is a freelancer who prepared this for sway, and I implemented a fork that undoes more parts of sway than implements, at (since I'm not sway):

https://github.com/jack9603301/upwork-wayland

This adapter is implemented to run freelance work software such as upwork that relies on the gnome interface under wayland, but it may provide an implementation for gnome software. Although grim may not be available on gnome, we can know that gnome The status of the interface used

With the help of this simple dbus adapter, some software with the screenshot function of the gnome screenshot protocol can be used freely under wlroots of wayland - because it simulates the interface of gnome

@yavko
Copy link

yavko commented Dec 19, 2022

@yavko

Replenish:

Regarding the gnome adaptation method of wayland, the currently feasible method is to serve the desktop app of upwork, which is at this address:

MarSoft/upwork-wayland

The author is a freelancer who prepared this for sway, and I implemented a fork that undoes more parts of sway than implements, at (since I'm not sway):

jack9603301/upwork-wayland

This adapter is implemented to run freelance work software such as upwork that relies on the gnome interface under wayland, but it may provide an implementation for gnome software. Although grim may not be available on gnome, we can know that gnome The status of the interface used

With the help of this simple dbus adapter, some software with the screenshot function of the gnome screenshot protocol can be used freely under wlroots of wayland - because it simulates the interface of gnome

Yeah apps can still use that dbus api, but GNOME removed it on GNOME, in GNOME 41. So if its implemented apps that were made to use it work, but it doesn't work on versions of GNOME newer than 41, 40 and below is fine tho.

EDIT: This is why zoom screensharing stopped working after GNOME 41, so they implemented the portal method

@MitchMG2
Copy link

Can this be merged as an opt-in with some make flags to enable it? Those of us not using gnome are waiting on this patch as well, have several open issues which would be resolved by it. We should not be punished because of gnome's design decisions when it comes to implementing wayland.

@yavko
Copy link

yavko commented Dec 22, 2022

Can this be merged as an opt-in with some make flags to enable it?

That's what this PR adds.

those of us not using gnome are waiting on this patch as well, have several open issues which would be resolved by it.

this ONLY adds support for wlroots, and is not a universal solution. That's why the portal exists and mostly works fine.

We should not be punished because of gnome's design decisions when it comes to implementing wayland.

GNOME itself doesn't have working screenshotting it has nothing to do with GNOME's design decisions. GNOME had a internal dbus api that apps leveraged that was made private, which doesn't affect other compositors in anyways. People need to stop blaming everything on GNOME

@jack9603301
Copy link
Contributor Author

jack9603301 commented Dec 22, 2022

@mgil2 GRIM is currently known to work with wlrools, it is not really a general solution for GNOME, it is very likely that grim will not work properly under GNOME, when you find an alternative available for gnome, you or other community members can do it via PR Realize it

When you use most compositors based on wlroots other than gnome and kde, you can enable the grim screenshot adapter

@mmahmoudian
Copy link
Member

@jack9603301 Thank you for keeping this branch up to date. I appreciate the efforts. I'm still waiting for other dev to approve the PR.

Copy link
Contributor

@veracioux veracioux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jack9603301 @mmahmoudian Sorry for the long wait. I have reviewed the code - looks good. I have compiled flameshot with the -DUSE_WAYLAND_GRIM option and it works good on sway. Although I need to mention that without this option flameshot doesn't work for me on wayland. Not that it's in any way this PR's fault, but this means I can't verify if these changes break anything on wayland without grim. So I'll defer to other people's experience with this. I can verify that nothing breaks when running flameshot under X.

Just fix the formatting please.

In the past, flameshot used a special and superfluous method to call the wayland screenshot component
- dbus protocol communication. Although this method is supported by a large number of distributions,
it does not take into account the actual situation of wayland (including WM custom desktop environment users).
Now, we can enable the wayland universal screenshot adapter with the help of grim,
just add the following compilation flags in cmake:

```
-DUSE_WAYLAND_GRIM=true
```

In addition, the patch also adds HYPRLAND type and OTHER type support
Due to the dependency problem of USE_WAYLAND_CLIPBOARD,
cancel USE_WAYLAND_GRIM to activate USE_WAYLAND_CLIPBOARD by default,
Add a warning prompt to activate USE_WAYLAND_GRIM when USE_WAYLAND_CLIPBOARD is activated
The grim adapter cannot be used in gnome and similar environments, modify the cmake message to express it
Generic screenshot adapter is only supported on compositors that support wlroots
@veracioux veracioux merged commit 3ededae into flameshot-org:master Feb 15, 2023
@jack9603301 jack9603301 deleted the grim_wayland_adapter branch February 17, 2023 07:14
panpuchkov pushed a commit to namecheap/flameshot that referenced this pull request Feb 18, 2023
* Add grim-based wayland universal screenshot adapter

In the past, flameshot used a special and superfluous method to call the wayland screenshot component
- dbus protocol communication. Although this method is supported by a large number of distributions,
it does not take into account the actual situation of wayland (including WM custom desktop environment users).
Now, we can enable the wayland universal screenshot adapter with the help of grim,
just add the following compilation flags in cmake:

```
-DUSE_WAYLAND_GRIM=true
```

In addition, the patch also adds HYPRLAND type and OTHER type support

* grim outputs to standard streams instead of files

* Automatically enable wayland clipboard support when USE_WAYLAND_GRIM is enabled

* Cancel USE_WAYLAND_GRIM Activate USE_WAYLAND_CLIPBOARD by default

Due to the dependency problem of USE_WAYLAND_CLIPBOARD,
cancel USE_WAYLAND_GRIM to activate USE_WAYLAND_CLIPBOARD by default,
Add a warning prompt to activate USE_WAYLAND_GRIM when USE_WAYLAND_CLIPBOARD is activated

* perform formatting

* modify cmake message

The grim adapter cannot be used in gnome and similar environments, modify the cmake message to express it

* remove generic screenshot adapter for gnome

Generic screenshot adapter is only supported on compositors that support wlroots

* Update format

(cherry picked from commit 3ededae)
@mmahmoudian
Copy link
Member

mmahmoudian commented Feb 19, 2023

@veracioux

I have compiled flameshot with the -DUSE_WAYLAND_GRIM option and it works good on sway

Is this something that we should also add to our AUR build instructions and also to our docs/Sway and wlroots support.md ?

@veracioux
Copy link
Contributor

@mmahmoudian To docs/Sway and wlroots support.md the answer is probably yes. For AUR build instructions, do you mean we should add it as a comment, or enable the option while building based on some condition?

@mmahmoudian
Copy link
Member

@veracioux

To docs/Sway and wlroots support.md the answer is probably yes.

Would it be possible for you to add it? This was we can ask others to test it for us. And also I get a better understanding of where you have used that flag

For AUR build instructions, do you mean we should add it as a comment, or enable the option while building based on some condition?

Good question. Initially I thought that if it doesn't break X11, we can have it for eveyone and always build with that flag, but then I realized this might be wlroot specific as in KDE Plasma Wayland and Gnome Wayland, Flameshot is already functional. I think this needs some investigation. I have Hyprland on my machine but few others can be tested either by the community or through VM. What do you think?

@mmahmoudian mmahmoudian added this to the v13 milestone Feb 20, 2023
@jack9603301
Copy link
Contributor Author

jack9603301 commented Feb 23, 2023

I think it's now necessary to sync to other distro's main repos, this includes aur and ebuilds

Meanwhile I think this should be added to the docs

@jack9603301
Copy link
Contributor Author

Good question. Initially I thought that if it doesn't break X11, we can have it for eveyone and always build with that flag, but then I realized this might be wlroot specific as in KDE Plasma Wayland and Gnome Wayland, Flameshot is already functional. I think this needs some investigation. I have Hyprland on my machine but few others can be tested either by the community or through VM. What do you think?

Can be used as an option to enable the flag when the user turns on

@GaetanLepage
Copy link

I was wondering about this issue, it shouldn't be my fault, there was a noticeable delay before I added this patch, I think you might want to open a new issue to fix it - it might not be related to this patch

I confirm that I observe this behavior as well.

Moreover, even when compiling with both DUSE_WAYLAND_CLIPBOARD=true and -DUSE_WAYLAND_GRIM=true my screenshots are mostly black. Cf #3142

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

Successfully merging this pull request may close these issues.

7 participants