summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorCamisul <1397270-camisul@users.noreply.gitlab.com>2021-01-26 23:50:02 +0300
committerAndreas Kling <kling@serenityos.org>2021-02-09 21:36:11 +0100
commit8c220dee0375e92b1c386d72d3b6ce95b847591a (patch)
treee728372ddc3031a91ac4be2e49acb339f6403a37 /Userland
parente1ee59ac9de055fe9d9733235b89f671d88fc8d6 (diff)
downloadserenity-8c220dee0375e92b1c386d72d3b6ce95b847591a.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Services/WindowServer/Button.cpp22
-rw-r--r--Userland/Services/WindowServer/Button.h2
-rw-r--r--Userland/Services/WindowServer/Window.cpp14
-rw-r--r--Userland/Services/WindowServer/Window.h2
-rw-r--r--Userland/Services/WindowServer/WindowFrame.cpp3
-rw-r--r--Userland/Services/WindowServer/WindowManager.cpp9
6 files changed, 48 insertions, 4 deletions
diff --git a/Userland/Services/WindowServer/Button.cpp b/Userland/Services/WindowServer/Button.cpp
index 7265494b31..e428260b1b 100644
--- a/Userland/Services/WindowServer/Button.cpp
+++ b/Userland/Services/WindowServer/Button.cpp
@@ -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())) {
- if (on_click)
- on_click(*this);
+ 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:
diff --git a/Userland/Services/WindowServer/Button.h b/Userland/Services/WindowServer/Button.h
index e6c0433025..29de9488c4 100644
--- a/Userland/Services/WindowServer/Button.h
+++ b/Userland/Services/WindowServer/Button.h
@@ -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; }
diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp
index 2d8889c7ea..04095761a3 100644
--- a/Userland/Services/WindowServer/Window.cpp
+++ b/Userland/Services/WindowServer/Window.cpp
@@ -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)
diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h
index 3e8e2b18b3..9debf465b3 100644
--- a/Userland/Services/WindowServer/Window.h
+++ b/Userland/Services/WindowServer/Window.h
@@ -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);
diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp
index 49fd3b2cd8..85b13b554d 100644
--- a/Userland/Services/WindowServer/WindowFrame.cpp
+++ b/Userland/Services/WindowServer/WindowFrame.cpp
@@ -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));
}
diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp
index 602b3e8e3b..134715eac1 100644
--- a/Userland/Services/WindowServer/WindowManager.cpp
+++ b/Userland/Services/WindowServer/WindowManager.cpp
@@ -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()))