Skip to content

Commit d05bdde

Browse files
committed
fix(compositor): honor explicit output layout coordinates
#84
1 parent 75a5518 commit d05bdde

2 files changed

Lines changed: 16 additions & 111 deletions

File tree

src/compositor/noctalia_compositor.c

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -630,73 +630,25 @@ static int layout_extents_max_x(struct greeter_server* server) {
630630

631631
static bool layout_output_at(struct greeter_output* output, int layout_x, int layout_y);
632632

633-
struct configured_layout_entry {
634-
struct greeter_output* output;
635-
struct greeter_output_placement cfg;
636-
};
637-
638-
static int compare_configured_layout_entry(const void* a, const void* b) {
639-
const struct configured_layout_entry* ea = a;
640-
const struct configured_layout_entry* eb = b;
641-
if (ea->cfg.y != eb->cfg.y) {
642-
return ea->cfg.y - eb->cfg.y;
643-
}
644-
if (ea->cfg.x != eb->cfg.x) {
645-
return ea->cfg.x - eb->cfg.x;
646-
}
647-
return strcmp(ea->cfg.name, eb->cfg.name);
648-
}
649-
650633
static void layout_outputs_from_config(struct greeter_server* server) {
651-
struct configured_layout_entry entries[16];
652-
size_t count = 0;
653634
for (size_t i = 0; i < server->output_placement_count; ++i) {
654635
const struct greeter_output_placement* cfg = &server->output_placements[i];
655636
struct greeter_output* output = output_by_name(server, cfg->name);
656637
if (output == NULL) {
657638
wlr_log(WLR_INFO, "output_layout: '%s' not connected", cfg->name);
658639
continue;
659640
}
660-
entries[count].output = output;
661-
entries[count].cfg = *cfg;
662-
++count;
663-
}
664-
if (count == 0) {
665-
return;
666-
}
667-
668-
qsort(entries, count, sizeof(entries[0]), compare_configured_layout_entry);
669-
670-
int row_cfg_y = entries[0].cfg.y;
671-
int layout_x = 0;
672-
int layout_y = 0;
673-
int row_max_effective_height = 0;
674-
for (size_t i = 0; i < count; ++i) {
675-
if (i > 0 && entries[i].cfg.y != row_cfg_y) {
676-
layout_y += row_max_effective_height;
677-
layout_x = 0;
678-
row_cfg_y = entries[i].cfg.y;
679-
row_max_effective_height = 0;
680-
}
681-
682-
if (!layout_output_at(entries[i].output, layout_x, layout_y)) {
641+
if (!layout_output_at(output, cfg->x, cfg->y)) {
683642
continue;
684643
}
685644

686645
int effective_width = 0;
687646
int effective_height = 0;
688-
wlr_output_effective_resolution(entries[i].output->wlr_output, &effective_width, &effective_height);
647+
wlr_output_effective_resolution(output->wlr_output, &effective_width, &effective_height);
689648
wlr_log(
690-
WLR_INFO, "greeter output: %s at (%d,%d) (configured %s:%d,%d; effective %dx%d)", entries[i].cfg.name, layout_x,
691-
layout_y, entries[i].cfg.name, entries[i].cfg.x, entries[i].cfg.y, effective_width, effective_height
649+
WLR_INFO, "greeter output: %s at (%d,%d) (effective %dx%d)", cfg->name, cfg->x, cfg->y, effective_width,
650+
effective_height
692651
);
693-
694-
if (effective_height > row_max_effective_height) {
695-
row_max_effective_height = effective_height;
696-
}
697-
if (effective_width > 0) {
698-
layout_x += effective_width;
699-
}
700652
}
701653

702654
int fallback_x = layout_extents_max_x(server);

src/wayland/wayland_client.cpp

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -84,73 +84,26 @@ namespace {
8484
return -1;
8585
}
8686

87-
[[nodiscard]] std::optional<WaylandOutputLayout> chainedLayoutForOutput(
88-
const WaylandOutputInfo& output, const std::vector<greeter::GreeterOutputPlacement>& layout,
89-
const std::vector<WaylandOutputInfo>& outputs
90-
) {
87+
[[nodiscard]] std::optional<WaylandOutputLayout>
88+
chainedLayoutForOutput(const WaylandOutputInfo& output, const std::vector<greeter::GreeterOutputPlacement>& layout) {
9189
if (layout.empty()) {
9290
return std::nullopt;
9391
}
9492

95-
std::vector<const greeter::GreeterOutputPlacement*> ordered;
96-
ordered.reserve(layout.size());
9793
for (const auto& placement : layout) {
98-
ordered.push_back(&placement);
99-
}
100-
std::sort(
101-
ordered.begin(), ordered.end(),
102-
[](const greeter::GreeterOutputPlacement* lhs, const greeter::GreeterOutputPlacement* rhs) {
103-
if (lhs->y != rhs->y) {
104-
return lhs->y < rhs->y;
105-
}
106-
if (lhs->x != rhs->x) {
107-
return lhs->x < rhs->x;
108-
}
109-
return lhs->name < rhs->name;
110-
}
111-
);
112-
113-
int32_t rowConfigY = ordered.front()->y;
114-
int32_t layoutX = 0;
115-
int32_t layoutY = 0;
116-
int32_t rowMaxLogicalHeight = 0;
117-
for (const greeter::GreeterOutputPlacement* placement : ordered) {
118-
const WaylandOutputInfo* out = nullptr;
119-
for (const auto& candidate : outputs) {
120-
if (candidate.done && candidate.name == placement->name) {
121-
out = &candidate;
122-
break;
123-
}
124-
}
125-
if (out == nullptr) {
94+
if (placement.name != output.name) {
12695
continue;
12796
}
128-
129-
const auto logical = logicalSizeForOutputInfo(*out);
97+
const auto logical = logicalSizeForOutputInfo(output);
13098
if (!logical) {
131-
continue;
132-
}
133-
134-
if (placement != ordered.front() && placement->y != rowConfigY) {
135-
layoutY += rowMaxLogicalHeight;
136-
layoutX = 0;
137-
rowConfigY = placement->y;
138-
rowMaxLogicalHeight = 0;
139-
}
140-
141-
if (out->output == output.output) {
142-
return WaylandOutputLayout{
143-
.x = layoutX,
144-
.y = layoutY,
145-
.width = logical->first,
146-
.height = logical->second,
147-
};
148-
}
149-
150-
if (static_cast<int32_t>(logical->second) > rowMaxLogicalHeight) {
151-
rowMaxLogicalHeight = static_cast<int32_t>(logical->second);
99+
return std::nullopt;
152100
}
153-
layoutX += static_cast<int32_t>(logical->first);
101+
return WaylandOutputLayout{
102+
.x = placement.x,
103+
.y = placement.y,
104+
.width = logical->first,
105+
.height = logical->second,
106+
};
154107
}
155108

156109
return std::nullopt;
@@ -536,7 +489,7 @@ std::optional<WaylandOutputLayout> WaylandClient::layoutForOutput(const WaylandO
536489
int32_t y = output.y;
537490
if (!allReadyOutputsShareOrigin(m_outputs)) {
538491
// Compositor layout coordinates already account for greeter output scale.
539-
} else if (const auto chained = chainedLayoutForOutput(output, m_outputLayout, m_outputs)) {
492+
} else if (const auto chained = chainedLayoutForOutput(output, m_outputLayout)) {
540493
x = chained->x;
541494
y = chained->y;
542495
kLog.info(

0 commit comments

Comments
 (0)