Perhaps understanding how X11 works would be helpful? Programs run _under_ X11, so if they are started outside that session, there shouldn't be any access allowed. X11 doesn't have much security, but what it does have is useful to prevent people over the network from having access to information they shouldn't be able to access. X11 is udp, so there isn't any real security other than the built-in session security. Over the many decades, new security measures have been added to X11. When I was coding X11 apps, it was only the DISPLAY that controlled access with an xhost + {remote-client-IP/name}. I'm not sure when, but that changed. I don't know much about the new stuff, so you'll have to figure that out on your own.
Now, if you want to capture a screen, look at SimpleScreenRecorder or ffmpeg
https://trac.ffmpeg.org/wiki/Capture/Desktop or any of the other X11-capable screen capture tools. Those 2 are the lightest and easiest. If you need more, OBS is there, but it is heavy and for production video.
If you want to input commands to X11 programs, there are a few tools.
cnee is what I've been using when xdotool doesn't work, but there are lots of better options if you have $$$$ for a proper, commercial, testing tool.
I have no idea how to have a single program be able to get passed X-security for multiple users. For one user, you can try to set the DISPLAY (correctly), but that will only work if an X/session exists and doesn't violate X/security. The X/Client is the application and sends commands to the X/Server for display and interaction. That client-server connection is where most programs inject/break the security to accomplish non-standard things. I'm loath to share this, but check out
xhost which can be used to break X11 security. The X/session on the client will need to allow it. It is a really bad idea, but some places use it, opening up every machine to attacks.
If you use Wayland, I have ZERO idea how to accomplish this. I think the only working screen capture things are from the Gnome project. Wayland and Gnome seem to be partners in this crime. OTOH, Wayland is local-only, non-networked, so the main goal for it is simplicity and performance.
Bookmarks