UI: Allow copy & paste images in linux/Wayland #119117

Manually merged
Campbell Barton merged 3 commits from Jose-Vicente-Barrachina/blender:wl-image-clipboard into main 2024-03-12 07:43:31 +01:00

Adds copy and paste images functionality to and from the image editor in linux/Wayland clipboard.


Basically, this PR adds the new functions stated in #111404, using the already existing code for copying and pasting text, and adapting it for its use with images. Paste option only gets activated when exists a supported image on the clipboard.

Keybord shortcuts (Ctrl-C, Ctrl-V) don't seem to be working. I don't know if this was intended also in #105833 or it is necessary to modify some other part of the code.

Since previous code was intended for use with text mime types, a refactor would be necessary to make the clipboard implementation more type-agnostic.

Currently, the only format supported is PNG, in accordance to #105833 and the use of alpha channels, but it will be easy to include other formats.

I've tested the functionality with:

  • Gimp, copying and pasting images, with and without alpha.
  • Krita, copying and pasting images, with and without alpha.
Adds **copy and paste images** functionality to and from the **image editor** in linux/Wayland clipboard. --- Basically, this PR adds the new functions stated in #111404, using the already existing code for copying and pasting text, and adapting it for its use with images. `Paste` option only gets activated when exists a supported image on the clipboard. Keybord shortcuts (Ctrl-C, Ctrl-V) don't seem to be working. I don't know if this was intended also in #105833 or it is necessary to modify some other part of the code. Since previous code was intended for use with text mime types, a refactor would be necessary to make the clipboard implementation more type-agnostic. Currently, the only format supported is `PNG`, in accordance to #105833 and the use of alpha channels, but it will be easy to include other formats. I've tested the functionality with: - Gimp, copying and pasting images, with and without alpha. - Krita, copying and pasting images, with and without alpha.
José Vicente Barrachina added 3 commits 2024-03-06 10:04:06 +01:00
Campbell Barton requested review from Campbell Barton 2024-03-06 11:20:52 +01:00
Member

@Jose-Vicente-Barrachina - Keyboard shortcuts (Ctrl-C, Ctrl-V) don't seem to be working

That is expected. Those obvious keyboard shortcuts are not in our keymap yet. While Image Editor is in "mask" mode then Ctrl-C and Ctrl-V are currently used for copying and pasting splines. I can imagine that we'll give this a rethink if we have image copy/paste for all platforms.

Currently, the only format supported is PNG, in accordance to #105833

The use of PNG in that was for a very platform-specific reason. Although Windows supplies clipboard copy/paste functionality with defined formats (along with the ability to define custom ones), the built-in formats did not support alpha channels until very recently. This meant that many programs used the same custom format (using PNG) to transfer in a way that preserved alpha. This means that on Windows we need to put two image formats on the clipboard at once so that applications can take whatever is best.

For Linux feel free to support whatever formats make the most sense there. Your testing to ensure that you can copy images with alpha with Gimp and Krita is probably all we really need. So if you can do that without using PNG that's great, or if just just using PNG works that's also fine.

I don't compile for Linux, so having Campbell as reviewer is perfect. But he is quite busy right now, so review by others is also welcome. Having expanded platform support of image copy/paste is on our short-term roadmap, so having this within the 4.2 release schedule would be ideal.

Thanks for working on this!

> @Jose-Vicente-Barrachina - Keyboard shortcuts (Ctrl-C, Ctrl-V) don't seem to be working That is expected. Those obvious keyboard shortcuts are not in our keymap yet. While Image Editor is in "mask" mode then Ctrl-C and Ctrl-V are currently used for copying and pasting splines. I can imagine that we'll give this a rethink if we have image copy/paste for all platforms. > Currently, the only format supported is PNG, in accordance to #105833 The use of PNG in that was for a very platform-specific reason. Although Windows supplies clipboard copy/paste functionality with defined formats (along with the ability to define custom ones), the built-in formats did not support alpha channels until very recently. This meant that many programs used the same custom format (using PNG) to transfer in a way that preserved alpha. This means that on Windows we need to put two image formats on the clipboard at once so that applications can take whatever is best. For Linux feel free to support whatever formats make the most sense there. Your testing to ensure that you can copy images with alpha with Gimp and Krita is probably all we really need. So if you can do that without using PNG that's great, or if just just using PNG works that's also fine. I don't compile for Linux, so having Campbell as reviewer is perfect. But he is quite busy right now, so review by others is also welcome. Having expanded platform support of image copy/paste is on our short-term roadmap, so having this within the 4.2 release schedule would be ideal. Thanks for working on this!
Author
Contributor

For Linux feel free to support whatever formats make the most sense there. Your testing to ensure that you can copy images with alpha with Gimp and Krita is probably all we really need. So if you can do that without using PNG that's great, or if just just using PNG works that's also fine.

Hi.

The "issue" here is that, if I've understood correctly how the clipboard works, Wayland requires creating a buffer for each type of image offered before the clients choose which format is best for them, you can't do it on demand. So, as many formats supported, more memory needed.

If png is enough I'd leave it as it is. Anyway, if other types are needed, adding them is trivial.

Thank you so much.
I'll be working on supporting this in X11.

> For Linux feel free to support whatever formats make the most sense there. Your testing to ensure that you can copy images with alpha with Gimp and Krita is probably all we really need. So if you can do that without using PNG that's great, or if just just using PNG works that's also fine. > Hi. The "_issue_" here is that, if I've understood correctly how the clipboard works, Wayland requires creating a buffer for each type of image offered before the clients choose which format is best for them, you can't do it on demand. So, as many formats supported, more memory needed. If `png` is enough I'd leave it as it is. Anyway, if other types are needed, adding them is trivial. Thank you so much. I'll be working on supporting this in X11.
Member

@Jose-Vicente-Barrachina

Sorry if I rambled and was not clear. I was only trying to say that you can disregard everything that I did for the Window code and do whatever makes sense, or is simplest, for this platform. So if supporting just PNG works, that's just awesome.

I'll be working on supporting this in X11.

Wonderful!

@Jose-Vicente-Barrachina Sorry if I rambled and was not clear. I was only trying to say that you can disregard everything that I did for the Window code and do whatever makes sense, or is simplest, for this platform. So if supporting just PNG works, that's just awesome. > I'll be working on supporting this in X11. Wonderful!
Author
Contributor

Oh, don't worry, not at all. I understood you perfectly.

I was trying to explain why I did it that way. I'm a noob 😄 .
I think all modern apps support png but, ni case I'm wrong, I just wanted to point out that adding other mime types is easy.

Sorry if I overexplain myself. English is not my first language and maybe I don't make thinks clear as I should.

Oh, don't worry, not at all. I understood you perfectly. I was trying to explain why I did it that way. I'm a noob 😄 . I think all modern apps support `png` but, ni case I'm wrong, I just wanted to point out that adding other mime types is easy. Sorry if I overexplain myself. English is not my first language and maybe I don't make thinks clear as I should.

Are there any remaining TODO's with this PR or is it ready for review?

Are there any remaining TODO's with this PR or is it ready for review?
Author
Contributor

It's ready for review. Do I have to remove the WIP prefix?

It doesn't include support for linux/X11 yet, but I was thinking of making a separate pull request, since this is functional.

It's ready for review. Do I have to remove the WIP prefix? It doesn't include support for linux/X11 yet, but I was thinking of making a separate pull request, since this is functional.
Campbell Barton changed title from WIP: UI: Allow copy & paste images in linux/Wayland to UI: Allow copy & paste images in linux/Wayland 2024-03-12 06:56:35 +01:00

Yes, remove the WIP prefix if it's ready (WIP means you intend to make further changes).

Also, best split X11 into a separate PR.

Yes, remove the WIP prefix if it's ready (WIP means you intend to make further changes). Also, best split X11 into a separate PR.
Campbell Barton manually merged commit 692de6d380 into main 2024-03-12 07:43:31 +01:00

Committed with minor edits:

  • Added missing null check on the data read which would be null on failure to read (broken pipe for e.g.).
  • Move data_len to ThreadResult for consistency.
  • IMAGE_MT_image checks explicitly for Wayland (instead of Linux).
Committed with minor edits: - Added missing null check on the `data` read which would be null on failure to read (broken pipe for e.g.). - Move `data_len` to `ThreadResult` for consistency. - `IMAGE_MT_image` checks explicitly for Wayland (instead of Linux).
Harley Acheson added this to the User Interface project 2024-03-12 15:48:27 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119117
No description provided.