1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include <libfoundation/EventLoop.h>
10#include <libui/App.h>
11#include <libui/Responder.h>
12#include <libui/Window.h>
13
14namespace UI {
15
16bool Responder::send_invalidate_message_to_server(const LG::Rect& rect) const
17{
18 auto& app = App::the();
19 InvalidateMessage msg(Connection::the().key(), app.window().id(), rect);
20 return app.connection().send_async_message(msg);
21}
22
23void Responder::send_layout_message(Window& win, UI::View* for_view)
24{
25 LFoundation::EventLoop::the().add(win, new LayoutEvent(for_view));
26 m_display_message_sent = false;
27}
28
29void Responder::send_display_message_to_self(Window& win, const LG::Rect& display_rect)
30{
31 if (!m_display_message_sent || m_prev_display_message != display_rect) {
32 LFoundation::EventLoop::the().add(win, new DisplayEvent(display_rect));
33 m_display_message_sent = true;
34 m_prev_display_message = display_rect;
35 }
36}
37
38void Responder::receive_event(std::unique_ptr<LFoundation::Event> event)
39{
40 if (event->type() == Event::Type::MouseEvent) {
41 MouseEvent& own_event = *(MouseEvent*)event.get();
42 receive_mouse_move_event(own_event);
43 }
44 if (event->type() == Event::Type::DisplayEvent) {
45 DisplayEvent& own_event = *(DisplayEvent*)event.get();
46 receive_display_event(own_event);
47 }
48 if (event->type() == Event::Type::LayoutEvent) {
49 LayoutEvent& own_event = *(LayoutEvent*)event.get();
50 receive_layout_event(own_event);
51 }
52}
53
54} // namespace UI