Skip to content

Conversation

@NH002
Copy link

@NH002 NH002 commented Mar 12, 2025

This new -e / --empty option allows -k / --keep and -x / --exchange options to operate on empty selections i.e. selections that are empty will not be ignored anymore.

So far, when it came to -k and -x options, if both PRIMARY or SECONDARY selections were empty (meaning NULL or ""), the program would simply "clear" them i.e. not ask for events associated with them anymore. This default behavior is not changed with this new addition; however, if now -e option is passed as well, selections that are NULL will be assigned a newly allocated "", and the program will proceed in the same way as if no selection were an empty string from the very beginning (since X server itself does not make a difference between "" and any other non-NULL selection).

This is something that may be useful if we want to preserve or exchange PRIMARY and SECONDARY selections on our system continuously, which we may achieve with this command: sh -c 'while xsel -kn; do :; done' (we let xsel -kn be our condition because it exits with failure immediately when the X session stops i.e. when the user logs out). The problem with that command is, since xsel -kn will exit immediately with success if both selections are empty, the command will create an insanely resource-consuming loop at startup; this issue may be mitigated in several ways, but the best one of which is this newly added -e option, which prevents such behavior: while xsel -ken; do :; done. A similar case is easy to imagine in case of -x option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant