UI: Linux & Mac Support for Clipboard Copy/Paste Images #111404

Open
opened 2023-08-22 20:46:12 +02:00 by Harley Acheson · 20 comments
Member

As of the merge of #105833 Windows users can copy and paste images between Blender and other applications. That PR should have made it fairly easy to add similar support for other platforms.

Platform Support


Not shown in #105833 (added later) is that each platform has a "Capabilities" flag that indicates that some optional features are supported. For Mac, for example, you can open up intern/ghost/intern/GHOST_SystemCocoa.mm. There is a getCapabilities() function and you can just remove GHOST_kCapabilityClipboardImages from that list of things not supported.

Then you are going to declare a few functions in GHOST_WindowCocoa.hh and define them in GHOST_WindowCocoa.mm, using #105833 as a guide. GHOST_hasClipboardImage is meant to return true if the system clipboard contains a format that you are able to read and use. In the unlikely event that your platform does not provide this information you could just return true as that is only used to enable/disable the menu item.

putClipboardImage gives you an array of bytes in RGBA order, and a width and height of the image buffer. The data will be without padding, so 4 X width X height of bytes (0-255 per channel). You just need to massage it into whatever format your platform wants and put it on the system clipboard. Returning true if you are able to do so.

With getClipboardImage you need to confirm that there is indeed an image available, get that image from the system clipboard. Set *r_width and *r_height to the dimensions of the image. Then return a pointer to the image data as an array of RGBA bytes without padding. Use 255 for Alpha if your image does not support it. The memory that you malloc for the buffer will be managed by the caller of the function.

Note that the Windows implementation in GHOST_SystemWin32.cc is probably much more complicated that you will probably have to write. Windows has a long and strange history with clipboard formats and support for alpha. Implementations on other platforms could be extremely trivial in comparison.

As of the merge of #105833 Windows users can copy and paste images between Blender and other applications. That PR should have made it fairly easy to add similar support for other platforms. ### Platform Support - [x] MS-Windows !105833. - [x] Unix/Wayland !119117. - [ ] Unix/X11. - [ ] macOS. --- Not shown in #105833 (added later) is that each platform has a "Capabilities" flag that indicates that some optional features are supported. For Mac, for example, you can open up intern/ghost/intern/GHOST_SystemCocoa.mm. There is a getCapabilities() function and you can just remove `GHOST_kCapabilityClipboardImages` from that list of things not supported. Then you are going to declare a few functions in `GHOST_WindowCocoa.hh` and define them in `GHOST_WindowCocoa.mm`, using #105833 as a guide. `GHOST_hasClipboardImage` is meant to return true if the system clipboard contains a format that you are able to read and use. In the unlikely event that your platform does not provide this information you could just return true as that is only used to enable/disable the menu item. `putClipboardImage` gives you an array of bytes in RGBA order, and a width and height of the image buffer. The data will be without padding, so 4 X width X height of bytes (0-255 per channel). You just need to massage it into whatever format your platform wants and put it on the system clipboard. Returning true if you are able to do so. With `getClipboardImage` you need to confirm that there is indeed an image available, get that image from the system clipboard. Set *r_width and *r_height to the dimensions of the image. Then return a pointer to the image data as an array of RGBA bytes without padding. Use 255 for Alpha if your image does not support it. The memory that you malloc for the buffer will be managed by the caller of the function. Note that the Windows implementation in `GHOST_SystemWin32.cc` is probably much more complicated that you will probably have to write. Windows has a long and strange history with clipboard formats and support for alpha. Implementations on other platforms could be extremely trivial in comparison.
Harley Acheson added the
Type
To Do
label 2023-08-22 20:46:12 +02:00
Harley Acheson added this to the User Interface project 2023-08-22 20:46:14 +02:00
Harley Acheson added the
Meta
Good First Issue
label 2023-08-22 20:46:35 +02:00

Hello @Harley,

I'd like to ask you if it is necessary to have both Linux and Mac for this todo If so, can I use virtual machine for the Mac part ?

Thank you very much

Hello @Harley, I'd like to ask you if it is necessary to have both Linux and Mac for this todo If so, can I use virtual machine for the Mac part ? Thank you very much
Author
Member

Hi @nikolas111 !

I'd like to ask you if it is necessary to have both Linux and Mac for this todo

Not at all. I would expect two different people to do these two different platforms. If you want to do one, probably best to make a comment here though in case others want to try.

If so, can I use virtual machine for the Mac part ?

You can use any means, but this would probably require native debugging, where you can stop execution in an IDE and examine the state to make sure it is working as you expect. This wouldn't be quite simple enough where everything will likely go smoothly, mostly because you'll probably have to transform the color data buffers as they come in and out of the system clipboard.

Note that Mac probably does have support for copy/pasting text data so there probably is some code to open the clipboard, check for available formats, etc. Probably using https://developer.apple.com/documentation/appkit/nspasteboard#//apple_ref/occ/cl/NSPasteboard

Hi @nikolas111 ! > I'd like to ask you if it is necessary to have both Linux and Mac for this todo Not at all. I would expect two different people to do these two different platforms. If you want to do one, probably best to make a comment here though in case others want to try. > If so, can I use virtual machine for the Mac part ? You can use any means, but this would probably require native debugging, where you can stop execution in an IDE and examine the state to make sure it is working as you expect. This wouldn't be quite simple enough where everything will likely go smoothly, mostly because you'll probably have to transform the color data buffers as they come in and out of the system clipboard. Note that Mac probably does have support for copy/pasting text data so there probably is some code to open the clipboard, check for available formats, etc. Probably using https://developer.apple.com/documentation/appkit/nspasteboard#//apple_ref/occ/cl/NSPasteboard

Okay, then i would take the Linux part of this task @Harley .

Thank you very much

Okay, then i would take the Linux part of this task @Harley . Thank you very much
Author
Member

@nikolas111 - Okay, then i would take the Linux part of this task @Harley .

Awesome! Note that if you get stuck, ask for help. But if you have only bad luck, find you have no time, etc and want to give up please add notes here if they might help others.

> @nikolas111 - Okay, then i would take the Linux part of this task @Harley . Awesome! Note that if you get stuck, ask for help. But if you have only bad luck, find you have no time, etc and want to give up please add notes here if they might help others.

So I took a crack at this for OSX. I was able to get it to compile and run, but I'm having trouble testing it. Neither the "Image Copy" nor the "Image Paste" option ever shows up in the Image dropdown in the Image Editor, and I'm not sure why. here's what I tried:

  1. Took a screenshot
  2. Opened Screenshot in Preview, made a selection and copied it with command-c
  3. Made sure I could paste the image into other apps (gimp)
  4. Opened newly compiled Blender
  5. Opened the Image Editor and created a new image.
  6. Clicked on the Image menu, hoping to see the "Paste Image" option. (but did not see it!)

What would be the next steps to debugging this?

Here's a link to my branch and its diffs from main:

https://projects.blender.org/blender/blender/compare/main...Jim-Snavely/blender:osx-clipboard-111404

So I took a crack at this for OSX. I was able to get it to compile and run, but I'm having trouble testing it. Neither the "Image Copy" nor the "Image Paste" option ever shows up in the Image dropdown in the Image Editor, and I'm not sure why. here's what I tried: 1. Took a screenshot 2. Opened Screenshot in Preview, made a selection and copied it with command-c 3. Made sure I could paste the image into other apps (gimp) 4. Opened newly compiled Blender 5. Opened the Image Editor and created a new image. 6. Clicked on the Image menu, hoping to see the "Paste Image" option. (but did not see it!) What would be the next steps to debugging this? Here's a link to my branch and its diffs from main: https://projects.blender.org/blender/blender/compare/main...Jim-Snavely/blender:osx-clipboard-111404

@Harley am I even working in the right direction?

@Harley am I even working in the right direction?

@Jim-Snavely You will need to modify the UI files so that the operators are added when running Mac (sys.platform == "darwin"). Take a look here: https://projects.blender.org/blender/blender/src/branch/main/scripts/startup/bl_ui/space_image.py#L214

@Jim-Snavely You will need to modify the UI files so that the operators are added when running Mac (`sys.platform == "darwin"`). Take a look here: https://projects.blender.org/blender/blender/src/branch/main/scripts/startup/bl_ui/space_image.py#L214
Author
Member

@deadpin - Thanks, I totally forgot about that.

@deadpin - Thanks, I totally forgot about that.

thanks @deadpin and @Harley - now I'm in business

thanks @deadpin and @Harley - now I'm in business

Alright! Got it working and was able to test it locally. Also tested to make sure I didn't break the drag & drop. #112189

Alright! Got it working and was able to test it locally. Also tested to make sure I didn't break the drag & drop. https://projects.blender.org/blender/blender/pulls/112189

@Harley Can I put you down as a reviewer on my PR? Or is there someone else you would suggest?

@Harley Can I put you down as a reviewer on my PR? Or is there someone else you would suggest?

Hi, everybody.
If @nikolas111 don't mind, I'll be working on a possible solution for linux, starting with Wayland.

Please, @nikolas111, if it's not too much trouble, let me know if you're still working on this issue.

Thanks.

Hi, everybody. If @nikolas111 don't mind, I'll be working on a possible solution for **linux**, starting with **Wayland**. Please, @nikolas111, if it's not too much trouble, let me know if you're still working on this issue. Thanks.

@Jose-Vicente-Barrachina

Hello,

I was working on it, I almost completed the task but then and I simply lost the accumulated time I had for it and interest. For me the main problem was and probably still is that not all changes showed up in the executable after the build which made it a very time consuming task because I had to make a new clone to get really the changes I made to the executable. I don't know If it was my fault or if I was doing something wrong. I can provide you my progress. Personally I would like to complete it but after so much time spent just with the builds I lost the interest. So feel free to ask if you need any info for your start.

Thanks in advance

@Jose-Vicente-Barrachina Hello, I was working on it, I almost completed the task but then and I simply lost the accumulated time I had for it and interest. For me the main problem was and probably still is that not all changes showed up in the executable after the build which made it a very time consuming task because I had to make a new clone to get really the changes I made to the executable. I don't know If it was my fault or if I was doing something wrong. I can provide you my progress. Personally I would like to complete it but after so much time spent just with the builds I lost the interest. So feel free to ask if you need any info for your start. Thanks in advance

Ey, @nikolas111 , thank you for answering so quickly and for offering help.

I've already figured it out but, if you don't mind, I'll contact you in case I get stuck.

Ey, @nikolas111 , thank you for answering so quickly and for offering help. I've already figured it out but, if you don't mind, I'll contact you in case I get stuck.

Hi, everybody.

@Harley, PR that adds linux/Wayland support in #119117 waiting for review.

Thanks.

Hi, everybody. @Harley, PR that adds linux/Wayland support in #119117 waiting for review. Thanks.

Hi, everybody.
I would like to work on the Unix/X11 task.

Is it free to do or is someone already working on it?

Cheers,

Pascal

Hi, everybody. I would like to work on the Unix/X11 task. Is it free to do or is someone already working on it? Cheers, Pascal
Author
Member

@Pascal-Berndt - I would like to work on the Unix/X11 task...Is it free to do or is someone already working on it?

@Jose-Vicente-Barrachina added support for Wayland (#119117) and mentioned (on March 6th 2024) that he was also going to work on supporting X11. But he could also be busy.

> @Pascal-Berndt - I would like to work on the Unix/X11 task...Is it free to do or is someone already working on it? @Jose-Vicente-Barrachina added support for Wayland (#119117) and [mentioned](https://projects.blender.org/blender/blender/pulls/119117#issuecomment-1140205) (on March 6th 2024) that he was also going to work on supporting X11. But he could also be busy.

@Harley Thanks for the quick reply :)

Ok so I will wait for him to answer.

@Harley Thanks for the quick reply :) Ok so I will wait for him to answer.

Hi.

I'm pretty busy right now with my final year project at the university, and I've also been away from home for a few days, so I haven't been able to make much progress.
@Pascal-Berndt, feel free to work on it if you want.

Thanks.

Hi. I'm pretty busy right now with my final year project at the university, and I've also been away from home for a few days, so I haven't been able to make much progress. @Pascal-Berndt, feel free to work on it if you want. Thanks.

Hi @Jose-Vicente-Barrachina ,
thanks for the reply. Wish you all luck.

Ok so I will start by now.

Cheers.

Hi @Jose-Vicente-Barrachina , thanks for the reply. Wish you all luck. Ok so I will start by now. Cheers.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
6 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#111404
No description provided.