common: consider every subset sum as a candidate shelf width
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 21s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 19s
build / module (push) Failing after 16s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 20s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 19s
build / host-linux (push) Failing after 20s
build / host-windows-cross (push) Failing after 19s
build / obs (clang) (push) Failing after 20s
build / docs (push) Failing after 3s
build / obs (gcc) (push) Failing after 21s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s

Only trying running totals in packing order missed layouts where the
displays sharing a shelf are not the first few. A 4K above two 1440p side
by side is the common case: the 4K sorts first by height but belongs on a
shelf of its own, so the useful width is the sum of the other two.

For that arrangement the atlas drops from 3840x5040 to 5120x3600, about
5% fewer pixels per frame. With at most 8 displays this is 255 subsets,
so the extra search costs nothing.
This commit is contained in:
donny committed 2026-07-28 08:23:22 +00:00
1 parent b73ffa1b33
commit 76207dce41
8 files changed
+56 -18

No files matched your search

+32 -15
View File
@@ -126,29 +126,46 @@ bool lgDisplaysPack(
order[j] = v;
}
unsigned maxWidth = 0, totalWidth = 0;
unsigned maxWidth = 0;
for(unsigned i = 0; i < count; ++i)
{
if (in[i].width > maxWidth)
maxWidth = in[i].width;
totalWidth += in[i].width;
}
/* Candidate shelf widths: the widest single display (a pure vertical stack),
* every running total in packing order (which produces the natural "N per
* row" arrangements), and the sum of all widths (a single row). Every
* candidate is at least maxWidth so no display is ever too wide to place. */
unsigned candidates[KVMFR_MAX_DISPLAYS + 2];
/* Candidate shelf widths: the total width of every subset of displays.
*
* Any shelf is some set of displays sitting side by side, so its width is a
* subset sum; enumerating them covers every arrangement worth trying. Only
* considering running totals in packing order misses layouts where the
* displays that share a shelf are not the first few — a 4K above two 1440p
* side by side, for instance, since the 4K sorts first but belongs alone.
*
* With at most 8 displays this is 255 subsets, which costs nothing. Every
* candidate is raised to maxWidth so no display is ever too wide to place. */
unsigned candidates[1u << KVMFR_MAX_DISPLAYS];
unsigned candidateCount = 0;
candidates[candidateCount++] = maxWidth;
unsigned running = 0;
for(unsigned i = 0; i < count; ++i)
for(uint32_t mask = 1; mask < (1u << count); ++mask)
{
running += in[order[i]].width;
candidates[candidateCount++] = running < maxWidth ? maxWidth : running;
unsigned width = 0;
for(unsigned i = 0; i < count; ++i)
if (mask & (1u << i))
width += in[i].width;
if (width < maxWidth)
width = maxWidth;
// duplicates are common when displays share a width, so drop them
bool seen = false;
for(unsigned c = 0; c < candidateCount; ++c)
if (candidates[c] == width)
{
seen = true;
break;
}
if (!seen)
candidates[candidateCount++] = width;
}
candidates[candidateCount++] = totalWidth < maxWidth ? maxWidth : totalWidth;
unsigned bestX[KVMFR_MAX_DISPLAYS], bestY[KVMFR_MAX_DISPLAYS];
unsigned bestWidth = 0, bestHeight = 0;
+21
View File
@@ -203,6 +203,27 @@ int main(void)
};
run("3 identical 1080p displays", triple, 3);
/* One 4K next to two 1440p. The best layout puts the 4K on its own shelf
* with the two 1440p side by side below it, which is only found if the
* candidate shelf widths include sums of displays that are not the first
* few in packing order. */
const LGDisplayInfo mixed[3] = {
{ .id = 0, .name = "4K", .x = 0, .y = 0, .width = 3840, .height = 2160,
.primary = true },
{ .id = 1, .name = "1440pA", .x = 3840, .y = 0, .width = 2560, .height = 1440 },
{ .id = 2, .name = "1440pB", .x = 6400, .y = 0, .width = 2560, .height = 1440 },
};
run("4K plus two 1440p", mixed, 3);
{
KVMFRDisplay o[KVMFR_MAX_DISPLAYS];
unsigned aw, ah, dw, dh;
if (lgDisplaysPack(mixed, 3, 1, o, &aw, &ah, &dw, &dh))
check((uint64_t)aw * ah <= 18432000ULL,
"4K + 2x1440p packs into at most 5120x3600 (got %ux%u)", aw, ah);
else
check(false, "4K + 2x1440p packed");
}
const LGDisplayInfo single[1] = {
{ .id = 0, .name = "only", .x = 0, .y = 0, .width = 2560, .height = 1440 },
};
+1 -1
View File
@@ -1 +1 @@
B7-380-gb327abf6c6+
B7-385-gb73ffa1b33+
+1 -1
View File
@@ -1,2 +1,2 @@
#define LG_VERSION_STR "B7-380-gb327abf6c6+"
#define LG_VERSION_STR "B7-385-gb73ffa1b33+"
#define LG_CURRENT_YEAR 2026
+1 -1
View File
@@ -1 +1 @@
const char * BUILD_VERSION = "B7-380-gb327abf6c6+";
const char * BUILD_VERSION = "B7-385-gb73ffa1b33+";