selection(3pm)
π Tk::Selection β Manipulate the X selection π
okay bestie, this is the selection(3pm) page and it's literally the X selection whisperer π it lives in Tk::Selection and it lets you touch the X selection like the main character you are.
β¨ SYNOPSIS β¨
$widget->SelectionOption?(args)?
π¦ DESCRIPTION π¦
so basically, this command is your backstage pass to the X selection mechanism, and it implements the full selection functionality described in the X Inter-Client Communication Conventions Manual (ICCCM). no cap.
The widget object you use to invoke the methods below is what decides which display gets used to access the selection. And because we do not want beef with the selection methods of other widget classes (looking at you, Text π), this whole set of methods rocks the prefix Selection. Here's what's currently supported:
π«Ά $widget->SelectionClear?(-selection=>selection)?
If selection exists anywhere on $widget's display, clear it so that no window owns the selection anymore. periodt.
selection specifies the X selection that should be cleared, and it should be an atom name such as PRIMARY or CLIPBOARD; go read the Inter-Client Communication Conventions Manual for the complete deets. selection defaults to PRIMARY.
Returns an empty string. π
π $widget->SelectionGet(?-selection=>selection?,?-type=>type?)?
Retrieves the value of selection from $widget's display and hands it back to you as the result. selection defaults to PRIMARY.
type specifies the form the selection comes back in (the desired ``target'' for conversion, in ICCCM speak), and it should be an atom name like STRING or FILE_NAME; again, the Inter-Client Communication Conventions Manual has the complete details. type defaults to STRING. The selection owner is allowed to return the selection in any of several different representation formats, such as STRING, ATOM, INTEGER, etc. (this format is different than the selection type; the ICCCM has all the confusing details, iykyk).
If format is not STRING then things get messy π β the following description is from the Tcl/Tk man page as yet incompetely translated for the perl version, and it is misleading at best.
If the selection is returned in a non-string format, such as INTEGER or ATOM, SelectionGet converts it to a list of perl values: atoms get converted to their textual names, and anything else gets converted to integers.
A goal of the perl port is to provide better handling of different formats than Tcl/Tk does, which should be possible given perl's wider range of ``types''. Although some thought went into this in very early days of perl/Tk, what exactly happens is still "not quite right" and subject to change. π«
πΈ $widget->SelectionHandle(?-selection=>selection?,?-type=>type?,?-format=>format? callback)
Creates a handler for selection requests, so that callback gets executed whenever selection is owned by $widget and somebody tries to retrieve it in the form given by type (e.g. type is specified in the selection get command). selection defaults to PRIMARY, type defaults to STRING, and format defaults to STRING. If callback is an empty string then any existing handler for $widget, type, and selection is removed. bye felicia π
When selection is requested, $widget is the selection owner, and type is the requested type, callback will be executed with two additional arguments. Those two extras are offset and maxBytes: offset specifies a starting character position in the selection, and maxBytes gives the maximum number of bytes to retrieve. The command should return a value consisting of at most maxBytes of the selection, starting at position offset. For very large selections (larger than maxBytes) the selection gets retrieved using several invocations of callback with increasing offset values. If callback returns a string whose length is less than maxBytes, the return value is assumed to include all of the remainder of the selection; if the length of callback's result is equal to maxBytes then callback will be invoked again, until it eventually returns a result shorter than maxBytes. The value of maxBytes will always be relatively large (thousands of bytes). π₯
If callback returns an error (e.g. via die) then the selection retrieval is rejected just as if the selection didn't exist at all. harsh but fair π
The format argument specifies the representation that should be used to transmit the selection to the requester (the second column of Table 2 of the ICCCM), and it defaults to STRING. If format is STRING, the selection is transmitted as 8-bit ASCII characters (i.e. just in the form returned by command).
If format is not STRING then things get messy again π β the following description is from the Tcl/Tk man page as yet untranslated for the perl version, and it is misleading at best.
If format is ATOM, then the return value from command is divided into fields separated by white space; each field is converted to its atom value, and the 32-bit atom value is transmitted instead of the atom name. For any other format, the return value from command is divided into fields separated by white space and each field is converted to a 32-bit integer; an array of integers is transmitted to the selection requester.
The format argument is needed only for compatibility with many selection requesters, except Tcl/Tk. If Tcl/Tk is being used to retrieve the selection then the value is converted back to a string at the requesting end, so format is irrelevant. π
A goal of the perl port is to provide better handling of different formats than Tcl/Tk does, which should be possible given perl's wider range of ``types''. Although some thought went into this in very early days of perl/Tk, what exactly happens is still "not quite right" and subject to change. π«
π $widget->SelectionOwner(-selection=>selection)
SelectionOwner returns the window in this application that owns selection on the display containing $widget, or an empty string if no window in this application owns the selection. selection defaults to PRIMARY.
β $widget->SelectionOwn(?-command=>callback?,?-selection=>selection?)?
SelectionOwn causes $widget to become the new owner of selection on $widget's display, returning an empty string as the result. The existing owner, if any, is notified that it has lost the selection. π
If callback is specified, it will be executed when some other window claims ownership of the selection away from $widget. selection defaults to PRIMARY.
π§ KEYWORDS π§
clear, format, handler, ICCCM, own, selection, target, type
and that's the whole vibe, bestie β this page came to you from perl v5.40.1 on 2025-04-13, and the man page itself is selection(3pm). slay, go own some selections πβ¨
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms