Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore previous strut behavior #1963

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,13 @@ struct rect {
/// @brief Rectangle width.
/// @return width of this rectangle.
inline T width() const {
if constexpr (Kind == rect_kind::SIZED) {
return this->m_other.x();
} else {
return this->m_other.x() + this->m_pos.x();
}
return size().x();
}

/// @brief Rectangle height.
/// @return height of this rectangle.
inline T height() const {
if constexpr (Kind == rect_kind::SIZED) {
return this->m_other.y();
} else {
return this->m_other.y() + this->m_pos.y();
}
return size().y();
}

/// @brief Returns rectangle component at `index`.
Expand Down
65 changes: 24 additions & 41 deletions src/x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1144,50 +1144,33 @@ void set_struts(alignment align) {
int display_width = workarea.width();
int display_height = workarea.height();

switch (horizontal_alignment(align)) {
case axis_align::START:
sizes[*x11_strut::LEFT] = std::clamp(
window.geometry.x() + window.geometry.end_x(), 0, display_width);
sizes[*x11_strut::LEFT_START_Y] =
std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::LEFT_END_Y] = std::clamp(
window.geometry.y() + window.geometry.height(), 0, display_height);
switch (align) {
case alignment::TOP_LEFT:
case alignment::TOP_RIGHT:
case alignment::TOP_MIDDLE:
sizes[*x11_strut::TOP] = std::clamp(window.geometry.end_y(), 0, display_height);
sizes[*x11_strut::TOP_START_X] = std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::TOP_END_X] = std::clamp(window.geometry.end_x(), 0, display_width);
break;
case axis_align::END:
sizes[*x11_strut::RIGHT] =
std::clamp(display_width - window.geometry.x(), 0, display_width);
sizes[*x11_strut::RIGHT_START_Y] =
std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::RIGHT_END_Y] = std::clamp(
window.geometry.y() + window.geometry.height(), 0, display_height);
case alignment::BOTTOM_LEFT:
case alignment::BOTTOM_RIGHT:
case alignment::BOTTOM_MIDDLE:
sizes[*x11_strut::BOTTOM] = display_height - std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::BOTTOM_START_X] = std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::BOTTOM_END_X] = std::clamp(window.geometry.end_x(), 0, display_width);
break;
case alignment::MIDDLE_LEFT:
sizes[*x11_strut::LEFT] = std::clamp(window.geometry.end_x(), 0, display_width);
sizes[*x11_strut::LEFT_START_Y] = std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::LEFT_END_Y] = std::clamp(window.geometry.end_y(), 0, display_height);
break;
case alignment::MIDDLE_RIGHT:
sizes[*x11_strut::RIGHT] = display_width - std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::RIGHT_START_Y] = std::clamp(window.geometry.y(), 0, display_height);
sizes[*x11_strut::RIGHT_END_Y] = std::clamp(window.geometry.end_y(), 0, display_height);
break;
case axis_align::MIDDLE:
switch (vertical_alignment(align)) {
case axis_align::START:
sizes[*x11_strut::TOP] =
std::clamp(window.geometry.y() + window.geometry.height(), 0,
display_height);
sizes[*x11_strut::TOP_START_X] =
std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::TOP_END_X] =
std::clamp(window.geometry.x() + window.geometry.width(), 0,
display_width);
break;
case axis_align::END:
sizes[*x11_strut::BOTTOM] = std::clamp(
display_height - window.geometry.y(), 0, display_height);
sizes[*x11_strut::BOTTOM_START_X] =
std::clamp(window.geometry.x(), 0, display_width);
sizes[*x11_strut::BOTTOM_END_X] =
std::clamp(window.geometry.x() + window.geometry.width(), 0,
display_width);
break;
case axis_align::MIDDLE:
// can't reserve space in middle of the screen
default:
break;
}
default:
// can't reserve space in middle of the screen
break;
}

Expand Down
Loading