Skip to content

Commit

Permalink
Restore previous strut behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
m42a authored and brndnmtthws committed Jun 10, 2024
1 parent f88b50d commit 9f83022
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 51 deletions.
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

0 comments on commit 9f83022

Please sign in to comment.