selection own
Gives the owner of a selection, or makes a window the owner.
selection own ?-displayof WINDOW? ?-selection NAME?
selection own ?-command SCRIPT? ?-selection NAME? WINDOW
Description
With no WINDOW, gives the window that owns the selection, or an empty string when no window of the app owns it. A deleted window is no owner.
With WINDOW, makes WINDOW the owner. When another window owned the selection and set -command, its script runs first at the global level. ztk does not check that WINDOW exists.
Options
| Option | Type | Default | Description |
|---|---|---|---|
-command | script | empty | A script that runs when the window loses the selection. |
-displayof | window | none | A window of the display of the selection. |
-selection | string | PRIMARY | The name of the selection, such as PRIMARY or CLIPBOARD. |
-command SCRIPT
A script that runs when the window loses the selection.
The script runs at the global level when another window takes the selection, or when selection clear clears it.
% frame .c1
> frame .c2
> set lost 0
> selection own -command {set lost 1} .c1
> selection own .c2
> set lost
1Any text is a script. An error of the script is the error of the command that took the selection.
-displayof WINDOW
A window of the display of the selection.
ztk has one display for each app, so the value has no effect. ztk does not check that WINDOW exists.
% frame .d1
> selection own .d1
> selection own -displayof .
.d1ztk accepts any value of -displayof.
-selection NAME
The name of the selection, such as PRIMARY or CLIPBOARD.
Each name has its own owner. A short form such as -s works.
% selection clear
> frame .s1
> selection own -selection CLIPBOARD .s1
> list [selection own -selection CLIPBOARD] [selection own]
.s1 {}Any name is a selection.
Returns
The owner window, or an empty string.
Examples
% frame .o
> selection own .o
> selection own
.o
% frame .o2
> selection own .o2
> destroy .o2
> selection own
Errors
% selection own -cmd x .
bad option "-cmd": must be -command, -displayof, or -selection
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1