HumbleUI/JWM

Ubuntu: getScreens might not find primary screens

tonsky opened this issue · 3 comments

@igorhub

Related code:

JWM/linux/cc/AppX11.cc

Lines 50 to 97 in a3c6e47

const std::vector<jwm::ScreenInfo>& jwm::AppX11::getScreens() {
if (_screens.empty()) {
Display* display = getWindowManager().getDisplay();
XRRScreenResources* resources = XRRGetScreenResources(display, getWindowManager().getRootWindow());
RROutput primaryOutput = XRRGetOutputPrimary(display, getWindowManager().getRootWindow());
int count = resources->ncrtc;
// skip empty monitors
for (int i = 0; i < resources->ncrtc; ++i) {
XRRCrtcInfo* info = XRRGetCrtcInfo(display, resources, resources->crtcs[i]);
if (info->width == 0) {
count -= 1;
}
XRRFreeCrtcInfo(info);
}
float dpi = jwm::app.getScale();
for (int i = 0; i < count; ++i) {
XRRCrtcInfo* info = XRRGetCrtcInfo(display, resources, resources->crtcs[i]);
// skip empty monitors
if (info->width != 0) {
bool isPrimary = false;
for (int o = 0; o < info->noutput; ++o) {
RROutput output = info->outputs[o];
if (output == primaryOutput) {
isPrimary = true;
break;
}
}
auto bounds = jwm::IRect::makeXYWH(info->x, info->y, info->width, info->height);
ScreenInfo myScreenInfo = {
long(info->outputs[0]),
bounds,
isPrimary
};
_screens.push_back(myScreenInfo);
}
XRRFreeCrtcInfo(info);
}
XRRFreeScreenResources(resources);
}
return _screens;
}

So, I found the problem:
The primaryOutput we get at the start of getScreens has different ID than the (single) output we get at info->outputs[o].
Other than ID they seem to be identical:

primaryOutput ID: 445
timestamp: 7820
crtc: 0
name: DP-0
nameLen: 4
mm_width: 0
mm_height: 0
connection: 1
subpixel_order: 0
ncrtc: 4
nclone: 0
nmode: 0
npreferred: 0

output ID: 447
timestamp: 7820
crtc: 0
name: DP-0
nameLen: 4
mm_width: 0
mm_height: 0
connection: 1
subpixel_order: 0
ncrtc: 4
nclone: 0
nmode: 0
npreferred: 0

I'm not sure what the proper solution is.
Perhaps, we should compare names instead of IDs?