1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:47:34 +00:00

WindowServer: Vertically maximize window

Button now can handle middle and right clicks.
Added 2 new handlers in button class: on_right_click for Right mouse
button and on_middle_click for middle mouse button.

Added functionality to vertically maximize window with middle mouse
click on the maximize window button.

Also added a way to vertically maximize window by resizing window
height-wise lower than the maximum window height.
This commit is contained in:
Camisul 2021-01-26 23:50:02 +03:00 committed by Andreas Kling
parent e1ee59ac9d
commit 8c220dee03
6 changed files with 48 additions and 4 deletions

View file

@ -62,22 +62,36 @@ void Button::on_mouse_event(const MouseEvent& event)
{
auto& wm = WindowManager::the();
if (event.type() == Event::MouseDown && event.button() == MouseButton::Left) {
if (event.type() == Event::MouseDown && (event.button() == MouseButton::Left || event.button() == MouseButton::Right || event.button() == MouseButton::Middle)) {
m_pressed = true;
wm.set_cursor_tracking_button(this);
m_frame.invalidate(m_relative_rect);
return;
}
if (event.type() == Event::MouseUp && event.button() == MouseButton::Left) {
if (event.type() == Event::MouseUp && (event.button() == MouseButton::Left || event.button() == MouseButton::Right || event.button() == MouseButton::Middle)) {
if (wm.cursor_tracking_button() != this)
return;
wm.set_cursor_tracking_button(nullptr);
bool old_pressed = m_pressed;
m_pressed = false;
if (rect().contains(event.position())) {
switch (event.button()) {
case MouseButton::Left:
if (on_click)
on_click(*this);
break;
case MouseButton::Right:
if (on_right_click)
on_right_click(*this);
break;
default:
if (on_middle_click)
on_middle_click(*this);
break;
}
}
if (old_pressed != m_pressed) {
// Would like to compute:

View file

@ -53,6 +53,8 @@ public:
void on_mouse_event(const MouseEvent&);
Function<void(Button&)> on_click;
Function<void(Button&)> on_right_click;
Function<void(Button&)> on_middle_click;
bool is_visible() const { return m_visible; }

View file

@ -360,7 +360,21 @@ void Window::set_maximized(bool maximized, Optional<Gfx::IntPoint> fixed_point)
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
set_default_positioned(false);
}
void Window::set_vertically_maximized()
{
if (m_maximized)
return;
if (!is_resizable() || resize_aspect_ratio().has_value())
return;
auto max_rect = WindowManager::the().maximized_window_rect(*this);
auto new_rect = Gfx::IntRect(
Gfx::IntPoint(rect().x(), max_rect.y()),
Gfx::IntSize(rect().width(), max_rect.height()));
set_rect(new_rect);
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(new_rect));
}
void Window::set_resizable(bool resizable)
{
if (m_resizable == resizable)

View file

@ -106,6 +106,8 @@ public:
bool is_maximized() const { return m_maximized; }
void set_maximized(bool, Optional<Gfx::IntPoint> fixed_point = {});
void set_vertically_maximized();
bool is_fullscreen() const { return m_fullscreen; }
void set_fullscreen(bool);

View file

@ -83,6 +83,9 @@ WindowFrame::WindowFrame(Window& window)
auto button = make<Button>(*this, [this](auto&) {
WindowManager::the().maximize_windows(m_window, !m_window.is_maximized());
});
button->on_middle_click = [&](auto&) {
m_window.set_vertically_maximized();
};
m_maximize_button = button.ptr();
m_buttons.append(move(button));
}

View file

@ -579,6 +579,15 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
if (event.type() == Event::MouseUp && event.button() == m_resizing_mouse_button) {
dbgln_if(RESIZE_DEBUG, "[WM] Finish resizing Window({})", m_resize_window);
auto max_rect = maximized_window_rect(*m_resize_window);
if (event.y() > max_rect.bottom()) {
dbgln<RESIZE_DEBUG>("Should Maximize vertically");
m_resize_window->set_vertically_maximized();
m_resize_window = nullptr;
m_resizing_mouse_button = MouseButton::None;
return true;
}
Core::EventLoop::current().post_event(*m_resize_window, make<ResizeEvent>(m_resize_window->rect()));
m_resize_window->invalidate();
if (m_resize_window->rect().contains(event.position()))