WindowServer: Resize from closest corner
This commit is contained in:
parent
c9057aa498
commit
3b02a9d4fe
|
@ -477,6 +477,11 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
|
||||||
{
|
{
|
||||||
m_state = State::Resizing;
|
m_state = State::Resizing;
|
||||||
m_resize_start = m_cursor;
|
m_resize_start = m_cursor;
|
||||||
|
|
||||||
|
const bool right = m_cursor.x >= target_window->full_x() + target_window->full_width() / 2;
|
||||||
|
const bool bottom = m_cursor.y >= target_window->full_y() + target_window->full_height() / 2;
|
||||||
|
m_resize_quadrant = right + 2 * bottom;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -522,6 +527,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
|
||||||
dwarnln("could not resize client window {}", ret.error());
|
dwarnln("could not resize client window {}", ret.error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_focused_window->set_position({ resize_area.x, resize_area.y + m_focused_window->title_bar_height() });
|
||||||
|
|
||||||
LibGUI::EventPacket::ResizeWindowEvent event;
|
LibGUI::EventPacket::ResizeWindowEvent event;
|
||||||
event.width = m_focused_window->client_width();
|
event.width = m_focused_window->client_width();
|
||||||
|
@ -622,11 +628,9 @@ void WindowServer::on_mouse_move(LibInput::MouseMoveEvent event)
|
||||||
}
|
}
|
||||||
case State::Resizing:
|
case State::Resizing:
|
||||||
{
|
{
|
||||||
const auto max_cursor = Position {
|
const auto old_resize_area = resize_area({ old_cursor.x, old_cursor.y });
|
||||||
.x = BAN::Math::max(old_cursor.x, new_cursor.x),
|
const auto new_resize_area = resize_area({ new_cursor.x, new_cursor.y });
|
||||||
.y = BAN::Math::max(old_cursor.y, new_cursor.y),
|
invalidate(old_resize_area.get_bounding_box(new_resize_area));
|
||||||
};
|
|
||||||
invalidate(resize_area(max_cursor).get_bounding_box(m_focused_window->full_area()));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1169,11 +1173,29 @@ Rectangle WindowServer::cursor_area() const
|
||||||
|
|
||||||
Rectangle WindowServer::resize_area(Position cursor) const
|
Rectangle WindowServer::resize_area(Position cursor) const
|
||||||
{
|
{
|
||||||
|
int32_t diff_x = m_resize_start.x - cursor.x;
|
||||||
|
if (m_resize_quadrant % 2)
|
||||||
|
diff_x = -diff_x;
|
||||||
|
diff_x = BAN::Math::max(diff_x, -m_focused_window->client_width() + 20);
|
||||||
|
|
||||||
|
int32_t diff_y = m_resize_start.y - cursor.y;
|
||||||
|
if (m_resize_quadrant / 2)
|
||||||
|
diff_y = -diff_y;
|
||||||
|
diff_y = BAN::Math::max(diff_y, -m_focused_window->client_height() + 20);
|
||||||
|
|
||||||
|
int32_t off_x = 0;
|
||||||
|
if (m_resize_quadrant % 2 == 0)
|
||||||
|
off_x = -diff_x;
|
||||||
|
|
||||||
|
int32_t off_y = 0;
|
||||||
|
if (m_resize_quadrant / 2 == 0)
|
||||||
|
off_y = -diff_y;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
.x = m_focused_window->full_x(),
|
.x = off_x + m_focused_window->full_x(),
|
||||||
.y = m_focused_window->full_y(),
|
.y = off_y + m_focused_window->full_y(),
|
||||||
.width = BAN::Math::max<int32_t>(20, m_focused_window->full_width() + cursor.x - m_resize_start.x),
|
.width = diff_x + m_focused_window->full_width(),
|
||||||
.height = BAN::Math::max<int32_t>(20, m_focused_window->full_height() + cursor.y - m_resize_start.y),
|
.height = diff_y + m_focused_window->full_height(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,8 @@ private:
|
||||||
Position m_cursor;
|
Position m_cursor;
|
||||||
|
|
||||||
Rectangle m_non_full_screen_rect;
|
Rectangle m_non_full_screen_rect;
|
||||||
|
|
||||||
|
uint8_t m_resize_quadrant { 0 };
|
||||||
Position m_resize_start;
|
Position m_resize_start;
|
||||||
|
|
||||||
bool m_is_mouse_captured { false };
|
bool m_is_mouse_captured { false };
|
||||||
|
|
Loading…
Reference in New Issue