Skip to content

Commit

Permalink
LibGUI+WindowServer: Remove ResizeEvent::old_size()
Browse files Browse the repository at this point in the history
Turns out nobody was using this information anyway, so let's not go
through all the trouble of plumbing it from WindowServer to LibGUI.

Fixes SerenityOS#3247.
  • Loading branch information
awesomekling committed Aug 22, 2020
1 parent 683ae4f commit e374eb3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 33 deletions.
5 changes: 1 addition & 4 deletions Libraries/LibGUI/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,15 @@ class PaintEvent final : public Event {

class ResizeEvent final : public Event {
public:
explicit ResizeEvent(const Gfx::IntSize& old_size, const Gfx::IntSize& size)
explicit ResizeEvent(const Gfx::IntSize& size)
: Event(Event::Resize)
, m_old_size(old_size)
, m_size(size)
{
}

const Gfx::IntSize& old_size() const { return m_old_size; }
const Gfx::IntSize& size() const { return m_size; }

private:
Gfx::IntSize m_old_size;
Gfx::IntSize m_size;
};

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibGUI/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Widget::set_relative_rect(const Gfx::IntRect& a_rect)
m_relative_rect = rect;

if (size_changed) {
ResizeEvent resize_event(m_relative_rect.size(), rect.size());
ResizeEvent resize_event(rect.size());
event(resize_event);
}

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibGUI/WindowServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void WindowServerConnection::handle(const Messages::WindowClient::Paint& message
void WindowServerConnection::handle(const Messages::WindowClient::WindowResized& message)
{
if (auto* window = Window::from_window_id(message.window_id())) {
Core::EventLoop::current().post_event(*window, make<ResizeEvent>(message.old_rect().size(), message.new_rect().size()));
Core::EventLoop::current().post_event(*window, make<ResizeEvent>(message.new_rect().size()));
}
}

Expand Down
9 changes: 3 additions & 6 deletions Services/WindowServer/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class Event : public Core::Event {
WindowResized,
};

Event() {}
Event() { }
explicit Event(Type type)
: Core::Event(type)
{
}
virtual ~Event() {}
virtual ~Event() { }

bool is_mouse_event() const { return type() == MouseMove || type() == MouseDown || type() == MouseDoubleClick || type() == MouseUp || type() == MouseWheel; }
bool is_key_event() const { return type() == KeyUp || type() == KeyDown; }
Expand Down Expand Up @@ -144,18 +144,15 @@ class MouseEvent final : public Event {

class ResizeEvent final : public Event {
public:
ResizeEvent(const Gfx::IntRect& old_rect, const Gfx::IntRect& rect)
ResizeEvent(const Gfx::IntRect& rect)
: Event(Event::WindowResized)
, m_old_rect(old_rect)
, m_rect(rect)
{
}

Gfx::IntRect old_rect() const { return m_old_rect; }
Gfx::IntRect rect() const { return m_rect; }

private:
Gfx::IntRect m_old_rect;
Gfx::IntRect m_rect;
};

Expand Down
23 changes: 8 additions & 15 deletions Services/WindowServer/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,14 @@ void Window::set_maximized(bool maximized)
set_tiled(WindowTileType::None);
m_maximized = maximized;
update_menu_item_text(PopupMenuItem::Maximize);
auto old_rect = m_rect;
if (maximized) {
m_unmaximized_rect = m_rect;
set_rect(WindowManager::the().maximized_window_rect(*this));
} else {
set_rect(m_unmaximized_rect);
}
m_frame.did_set_maximized({}, maximized);
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(old_rect, m_rect));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
set_default_positioned(false);
}

Expand Down Expand Up @@ -376,11 +375,7 @@ void Window::event(Core::Event& event)
m_client->post_message(Messages::WindowClient::WindowCloseRequest(m_window_id));
break;
case Event::WindowResized:
m_client->post_message(
Messages::WindowClient::WindowResized(
m_window_id,
static_cast<const ResizeEvent&>(event).old_rect(),
static_cast<const ResizeEvent&>(event).rect()));
m_client->post_message(Messages::WindowClient::WindowResized(m_window_id, static_cast<const ResizeEvent&>(event).rect()));
break;
default:
break;
Expand All @@ -400,9 +395,9 @@ void Window::set_visible(bool b)

Compositor::the().invalidate_occlusions();
if (m_visible)
invalidate(true);
invalidate(true);
else
Compositor::the().invalidate_screen(frame().rect());
Compositor::the().invalidate_screen(frame().rect());
}

void Window::invalidate(bool invalidate_frame)
Expand Down Expand Up @@ -472,7 +467,7 @@ Window* Window::is_blocked_by_modal_window()
{
// A window is blocked if any immediate child, or any child further
// down the chain is modal
for (auto& window: m_child_windows) {
for (auto& window : m_child_windows) {
if (window && !window->is_destroyed()) {
if (window->is_modal())
return window;
Expand Down Expand Up @@ -591,7 +586,7 @@ void Window::set_fullscreen(bool fullscreen)
new_window_rect = m_saved_nonfullscreen_rect;
}

Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect, new_window_rect));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(new_window_rect));
set_rect(new_window_rect);
}

Expand Down Expand Up @@ -622,11 +617,10 @@ void Window::set_tiled(WindowTileType tiled)
return;

m_tiled = tiled;
auto old_rect = m_rect;
if (tiled != WindowTileType::None)
m_untiled_rect = m_rect;
set_rect(tiled_rect(tiled));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(old_rect, m_rect));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
}

void Window::detach_client(Badge<ClientConnection>)
Expand All @@ -639,7 +633,6 @@ void Window::recalculate_rect()
if (!is_resizable())
return;

auto old_rect = m_rect;
bool send_event = true;
if (m_tiled != WindowTileType::None) {
set_rect(tiled_rect(m_tiled));
Expand All @@ -652,7 +645,7 @@ void Window::recalculate_rect()
}

if (send_event) {
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(old_rect, m_rect));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Services/WindowServer/WindowClient.ipc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endpoint WindowClient = 4
WindowDeactivated(i32 window_id) =|
WindowStateChanged(i32 window_id, bool minimized, bool occluded) =|
WindowCloseRequest(i32 window_id) =|
WindowResized(i32 window_id, Gfx::IntRect old_rect, Gfx::IntRect new_rect) =|
WindowResized(i32 window_id, Gfx::IntRect new_rect) =|

MenuItemActivated(i32 menu_id, i32 identifier) =|

Expand Down
8 changes: 3 additions & 5 deletions Services/WindowServer/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void WindowManager::add_window(Window& window)
m_windows_in_order.append(&window);

if (window.is_fullscreen()) {
Core::EventLoop::current().post_event(window, make<ResizeEvent>(window.rect(), Screen::the().rect()));
Core::EventLoop::current().post_event(window, make<ResizeEvent>(Screen::the().rect()));
window.set_rect(Screen::the().rect());
}

Expand Down Expand Up @@ -577,7 +577,7 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
#ifdef RESIZE_DEBUG
dbg() << "[WM] Finish resizing Window{" << m_resize_window << "}";
#endif
Core::EventLoop::current().post_event(*m_resize_window, make<ResizeEvent>(m_resize_window->rect(), m_resize_window->rect()));
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()))
hovered_window = m_resize_window;
Expand All @@ -589,8 +589,6 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
if (event.type() != Event::MouseMove)
return false;

auto old_rect = m_resize_window->rect();

int diff_x = event.x() - m_resize_origin.x();
int diff_y = event.y() - m_resize_origin.y();

Expand Down Expand Up @@ -679,7 +677,7 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
dbg() << "[WM] Resizing, original: " << m_resize_window_original_rect << ", now: " << new_rect;
#endif
m_resize_window->set_rect(new_rect);
Core::EventLoop::current().post_event(*m_resize_window, make<ResizeEvent>(old_rect, new_rect));
Core::EventLoop::current().post_event(*m_resize_window, make<ResizeEvent>(new_rect));
return true;
}

Expand Down

0 comments on commit e374eb3

Please sign in to comment.