So few things to set the scene:
* I use emacs with server mode (i.e. emacsclient)
* I am running on Wayland (29.x - using native pgtk)
* Lately I have a need to occasionally ssh into my desktop from another machine running wayland session, edit/view things. Occasionally read email + open PDFs etc, and I want to be able to copy-paste into the emacsclient frame from remote host
* Emacs on terminal over ssh can copy-paste, but can't easily view PDFs etc. And GUI emacs over waypipe opens external programs on remote host by default and copy-paste is broken too.
Now why the problem with GUI happens:
* When emacs starts on host A it takes environment from that host (the important part being WAYLAND_DISPLAY being equal to wayland-1 or whatever)
* Things work fine on host A...
* I move to host B and realize I need to access email/stuff on host A. Tramp works for files, but not really for my email setup. So ... I use waypipe (for those unaware - a replacement for `ssh -X` in Wayland). I can execute emacsclient and have a new local frame on host B that's actually backed by emacs on host A.
* I need to copy stuff to/from clipboard in that emacsclient window. The problem is - WAYLAND_DISPLAY is set to wayland-1 and and not wayland-<whatever weird hash> which is for the remote wayland connection).
I found a way to make copy-paste work using a combination of following snippet:
https://gist.github.com/yorickvP/6132f237fbc289a45c808d8d75e0e1fb
And me setting up WAYLAND_DISPLAY like this:
```
(setenv "WAYLAND_DISPLAY" (frame-parameter (selected-frame) 'display))
```
Now to the question - I guess I could wrap this all up in some nice way and make a new package for others to use. But I kinda feel like I am perhaps going about it the wrong way. Also ideally - I could automatically set/reset the WAYLAND_DISPLAY and interprogram-cut-function/paste functions based on activity in different frames. I even thought of overriding `start-process` and/or `make-process` to use `with-environment` but I am not quite sure how that would go.
Or maybe I am thinking about this wrong and it's a misbehaviour in pgtk. Or ... something else. Thoughts?