Author: Marc Culler
State: Withdrawn
Type: Project
Created: 2025-06-07
Tcl-Version: 9.1
Keywords: clipboard
Abstract
This TIP proposes to do two things:
- Change the behavior of the clipboard command on the Aqua platform;
- Augment the clipboard command by adding a new subcommand transient.
The first item fixes ticket [e94c8bc845]: "macOS clipboard managers do not notice clipboard changes done by Tk". It has no effect on platforms other than Aqua.
The second item is an API change, intended to support copying a password to the clipboard and pasting it into another application without forcing clipboard managers to archive the password. While this API change necessarily applies to all platforms, the implementation makes it a no-op on platforms other than Aqua. The author does not know how to implement the appropriate behavior on the other platforms.
Target
This TIP targets version 9.1 of Tk.
Rationale
The Apple Appkit provides an Objective C class NSPasteboard which is the basis for the Aqua implementation of the platform-specific code used for the Tk clipboard. There is a singleton instance of NSPasteboard, called the general Pasteboard which can be used by any application running on the system, allowing copying data from one application and pasting it into another one.
There are two ways to add data (of type NSPasteboardTypeString only, in the case of Tk) to an instance of NSPasteboard. One way, which is currently used by Tk, is to create an Objective C Object which supports the NSPasteboardTypeOwner protocol and declare that object to be the owner of a specific pasteboard type. The protocol requires the object to provide a method which will be called by the NSPasteboard instance the next time that a request is made for its contents of that type. In the Tk implementation, the NSApplication instance created by loading the Tk package is the object which supports the NSPasteboardTypeOwner protocol.
The second way, which is used in the implementation of this TIP, is to declare that the nil Object is the owner of the NSPasteboardTypeString and to immediately supply a string value to the NSPasteboard by calling its setstring method. Clearly this has some performance disadvantages over the other "lazy" method currently being used by Tk. But it simplifies interactions with a clipboard manager.
Apple does not provide any sort of callback or notification to which an application can subscribe in order to find out whether the contents of a given type in the general Pasteboard have changed. Instead, there is an integer-valued property changeCount which should be incremented each time that the contents change. Clipboard managers are expected to check the value of the changeCount at some reasonable frequency and to read and archive the value of the pasteboard each time that changeCount is incremented.
The changeCount scheme does not interact well with the "lazy" method of setting the pasteboard value. Any performance benefit from the "lazy" method is lost if a clipboard manager succeeds at recording every value held by the pasteboard because that requires reading copying and saving each new value. So a choice must be made between supporting the use of a clipboard manager (which has become an increasing popular tool) and benefitting from the efficiency of the "lazy" update method.
However, there is a completely different benefit from the fact that the "lazy" update method allows the pasteboard contents to be updated without notifying the pasteboard or, consequently, any clipboard manager. That other benefit is made available by the proposed API change in this TIP. The new command allows placing "transient" data on the clipboard, which will persist only for the time between the cut and the paste, and which will not be recorded by a clipboard manager. The context in which this is useful is one where a user has private date within a Tk app (for example, a password) and would like to paste that data into another application (for example, a web browser) without having it be recorded by any other application (for example, a clipboard manager).
Specification
The signature of the new subcommand is:
clipboard transient ?-displayof window? data
The command has no return value. It causes the following things to happen in succession (on Aqua - there are no side effects on other platforms):
- the clipboard is cleared;
- the string specified as data is appended to the internal Tk clipboard;
- the state of the native clipboard is changed so that 1 second after the the next paste the clipboard will be cleared again.
The current Aqua implementation arranges that the changeCount of the general pasteboard does not change, allowing a clipboard manager to sleep through the entire sequence.
Compatibility
There should be no change to the behavior of any code using the current clipboard command except that, on Aqua, clipboard append and clipboard clear will be observed by a clipboard manager which monitors the changeCount of the general pasteboard.
Reference Implementation
This TIP is implemented in the clipboard_transient branch of the Tk fossil repository.
Resolution
As a result of the discussion on the Core list, this TIP is withdrawn. The new behavior of the clipboard command will be retained as a bug fix, but the new clipboard transient command would be better suited to a platform specific extension.
Copyright
This document has been placed in the public domain.