Open Salama opened 2 years ago
This is feasible with virtual monitors, though i don't know if this hack works with any xorg driver.
see: https://unix.stackexchange.com/questions/626451/displaying-an-x11-virtual-screen-in-a-window#631697
I used that before, but I changed from intel driver to modesetting due to performance improvements and I haven't found a working virtual display setup that doesn't include fake disconnected monitors that are still there. Discord can somehow screenshare a disconnected monitor, so it should be possible.
perhaps you can use ltrace or wireshark to trace the calls to the xrandr API and see how it achieves that
Looks like it can be achieved by removing
#ifdef HAVE_XRANDR
if (xrandr_event_base)
{
if (ev->type == xrandr_event_base + RRScreenChangeNotify) {
squint_disable();
}
}
#endif
and somehow finding the monitor dimensions even though it's disconnected (maybe another library?). I was able to get it to work by hardcoding src_rect and dst_rect.
Here is an example code that can get the monitor dimensions with their names even if they're disconnected.
#include <X11/extensions/Xrandr.h>
#include <stdio.h>
int main() {
Display *display;
display = XOpenDisplay(0);
int nmonitors = 0;
XRRMonitorInfo *monitors;
monitors = XRRGetMonitors(display, DefaultRootWindow(display), 1, &nmonitors);
XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display));
for(unsigned i = 0; i < nmonitors; i++) {
XRRCrtcInfo *screen_info = XRRGetCrtcInfo(display, screen_res, screen_res->crtcs[i]);
XRROutputInfo *output_info = XRRGetOutputInfo(display, screen_res, screen_res->outputs[i]);
fprintf(stdout, "%s %d %d %d %d\n", output_info->name, screen_info->x, screen_info->y, screen_info->width, screen_info->height);
}
}
Should I implement this and make a pull request or will you? If I make it, should libxrandr be kept as an optional dependency for a chance of having it merged?
That would be fine.
I've had a look at the sources of gdk3 and i have several points to add:
gdk3 already requires xrandr 1.3 to detect multihead screens, so adding a mandatory dependency on libxrandr is definitely not a concern https://gitlab.gnome.org/GNOME/gtk/-/blob/3.24.34/gdk/x11/gdkscreen-x11.c#L766
the method to discover monitor geometry depends on the xrandr version supported by the server
XRRGetCrtcInfo()
https://gitlab.gnome.org/GNOME/gtk/-/blob/3.24.34/gdk/x11/gdkscreen-x11.c#L846XRRGetMonitors()
https://gitlab.gnome.org/GNOME/gtk/-/blob/3.24.34/gdk/x11/gdkscreen-x11.c#L663in both cases there is a scale factor to be taken into account (x11_screen->window_scale
)
My thoughts for the merge request:
the detection code has to be functionally equivalent to the gtk3 implementation (especially the scale factor has to be supported), otherwise we may break existing setups
we can drop the support for xrandr 1.3, i think it will not impact anyone since xrandr 1.5 was introduced in 2015 (so only the xrandr 1.5 case needs to be implemented) https://en.wikipedia.org/wiki/X.Org_Server#Releases
the 'disconnected' state of each monitor should be displayed in the appindicator menu to avoid confusion for the users
the procedure to set up a disconnected screen should be documented in the man page (list of xrandr commands to be executed)
the auto-selection feature for the destination monitor should exclude disconnected monitors (i.e. use the first connected monitor that is still unused instead of use the first unused monitor) https://github.com/a-ba/squint/blob/v0.8.3/squint.c#L543
Should connected source monitors have priority over disconnected ones in auto selection unless there is only one connected monitor?
I have not really thought about it. I am only concerned about the destination: we must avoid auto-selecting a disconnected monitor for destination so as not to undermine the user experience (because nothing would appear on any monitor).
I do not have any clear idea for the source. At first sight I would rather give priority to the disconnected monitors (assuming that the user wants to see the undisplayed parts of the screen), but that's just a guts feeling.
Mirroring disconnected monitors would be useful for online presentations