Clipboard on Wayland

Tcl/Tk works on Wayland compositors through Xwayland. The contents of the Xwayland clipboard vanish when the application the content was copied from is closed, so this snippet executes wl-copy if the session is Wayland.

bind .copiable <Button-1> {
  global env
  if { $env(XDG_SESSION_TYPE) == "wayland" } {
    exec wl-copy "Copied! (Wayland)"
  } else {
    clipboard append "Copied! (X11)"
  }
}