2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-06-07 09:46:02 +00:00
|
|
|
#include <AK/HashMap.h>
|
2019-08-18 18:39:46 +00:00
|
|
|
#include <AK/JsonObject.h>
|
2019-12-26 21:13:50 +00:00
|
|
|
#include <AK/NeverDestroyed.h>
|
2020-01-01 17:53:34 +00:00
|
|
|
#include <AK/SharedBuffer.h>
|
2020-02-06 11:07:05 +00:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-02 00:57:57 +00:00
|
|
|
#include <LibGUI/GAction.h>
|
2019-07-23 16:16:25 +00:00
|
|
|
#include <LibGUI/GApplication.h>
|
|
|
|
#include <LibGUI/GEvent.h>
|
|
|
|
#include <LibGUI/GPainter.h>
|
|
|
|
#include <LibGUI/GWidget.h>
|
|
|
|
#include <LibGUI/GWindow.h>
|
2019-11-08 10:39:45 +00:00
|
|
|
#include <LibGUI/GWindowServerConnection.h>
|
2020-01-31 01:29:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2019-01-20 03:49:48 +00:00
|
|
|
|
2019-02-11 07:27:13 +00:00
|
|
|
//#define UPDATE_COALESCING_DEBUG
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
namespace GUI {
|
2019-01-20 04:48:43 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
static NeverDestroyed<HashTable<Window*>> all_windows;
|
|
|
|
static NeverDestroyed<HashMap<int, Window*>> reified_windows;
|
|
|
|
|
|
|
|
Window* Window::from_window_id(int window_id)
|
2019-01-20 04:48:43 +00:00
|
|
|
{
|
2019-12-26 21:13:50 +00:00
|
|
|
auto it = reified_windows->find(window_id);
|
|
|
|
if (it != reified_windows->end())
|
2019-01-20 04:48:43 +00:00
|
|
|
return (*it).value;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Window::Window(Core::Object* parent)
|
2020-02-02 11:34:39 +00:00
|
|
|
: Core::Object(parent)
|
2019-01-20 03:49:48 +00:00
|
|
|
{
|
2019-12-26 21:13:50 +00:00
|
|
|
all_windows->set(this);
|
2019-01-30 19:03:52 +00:00
|
|
|
m_rect_when_windowless = { 100, 400, 140, 140 };
|
|
|
|
m_title_when_windowless = "GWindow";
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Window::~Window()
|
2019-01-30 19:03:52 +00:00
|
|
|
{
|
2019-12-26 21:13:50 +00:00
|
|
|
all_windows->remove(this);
|
2019-01-30 19:03:52 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::close()
|
2019-01-30 19:03:52 +00:00
|
|
|
{
|
2019-09-21 16:53:17 +00:00
|
|
|
hide();
|
2019-01-30 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::move_to_front()
|
2019-06-01 18:10:37 +00:00
|
|
|
{
|
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
|
|
|
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::MoveWindowToFront>(m_window_id);
|
2019-06-01 18:10:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::show()
|
2019-01-30 19:03:52 +00:00
|
|
|
{
|
|
|
|
if (m_window_id)
|
|
|
|
return;
|
2020-02-06 19:20:44 +00:00
|
|
|
auto response = WindowServerConnection::the().send_sync<Messages::WindowServer::CreateWindow>(
|
2019-12-02 08:33:37 +00:00
|
|
|
m_rect_when_windowless,
|
|
|
|
m_has_alpha_channel,
|
|
|
|
m_modal,
|
2020-01-04 11:12:02 +00:00
|
|
|
m_minimizable,
|
2019-12-02 08:33:37 +00:00
|
|
|
m_resizable,
|
|
|
|
m_fullscreen,
|
|
|
|
m_show_titlebar,
|
|
|
|
m_opacity_when_windowless,
|
|
|
|
m_base_size,
|
|
|
|
m_size_increment,
|
|
|
|
(i32)m_window_type,
|
|
|
|
m_title_when_windowless);
|
|
|
|
m_window_id = response->window_id();
|
2019-01-20 04:48:43 +00:00
|
|
|
|
2019-08-02 19:02:56 +00:00
|
|
|
apply_icon();
|
|
|
|
|
2019-12-26 21:13:50 +00:00
|
|
|
reified_windows->set(m_window_id, this);
|
2020-02-02 14:07:41 +00:00
|
|
|
Application::the().did_create_window({});
|
2019-01-30 19:03:52 +00:00
|
|
|
update();
|
2019-01-20 03:49:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::hide()
|
2019-01-20 03:49:48 +00:00
|
|
|
{
|
2019-01-30 19:03:52 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2019-12-26 21:13:50 +00:00
|
|
|
reified_windows->remove(m_window_id);
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::DestroyWindow>(m_window_id);
|
2019-04-08 16:58:44 +00:00
|
|
|
m_window_id = 0;
|
|
|
|
m_pending_paint_event_rects.clear();
|
|
|
|
m_back_bitmap = nullptr;
|
|
|
|
m_front_bitmap = nullptr;
|
2019-09-21 16:53:17 +00:00
|
|
|
|
|
|
|
bool app_has_visible_windows = false;
|
2019-12-26 21:13:50 +00:00
|
|
|
for (auto& window : *all_windows) {
|
2019-09-21 16:53:17 +00:00
|
|
|
if (window->is_visible()) {
|
|
|
|
app_has_visible_windows = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!app_has_visible_windows)
|
2020-02-02 14:07:41 +00:00
|
|
|
Application::the().did_delete_last_window({});
|
2019-01-20 03:49:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_title(const StringView& title)
|
2019-01-20 03:49:48 +00:00
|
|
|
{
|
2019-03-18 23:01:02 +00:00
|
|
|
m_title_when_windowless = title;
|
2019-02-14 00:21:32 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowTitle>(m_window_id, title);
|
2019-01-20 03:49:48 +00:00
|
|
|
}
|
2019-01-20 05:02:09 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
String Window::title() const
|
2019-01-26 04:20:32 +00:00
|
|
|
{
|
2019-02-14 00:21:32 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return m_title_when_windowless;
|
2020-02-06 19:20:44 +00:00
|
|
|
return WindowServerConnection::the().send_sync<Messages::WindowServer::GetWindowTitle>(m_window_id)->title();
|
2019-01-26 04:20:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:02:38 +00:00
|
|
|
Gfx::Rect Window::rect() const
|
2019-02-07 23:13:35 +00:00
|
|
|
{
|
2019-02-14 00:21:32 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return m_rect_when_windowless;
|
2020-02-06 19:20:44 +00:00
|
|
|
return WindowServerConnection::the().send_sync<Messages::WindowServer::GetWindowRect>(m_window_id)->rect();
|
2019-02-07 23:13:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
void Window::set_rect(const Gfx::Rect& a_rect)
|
2019-01-20 03:49:48 +00:00
|
|
|
{
|
2019-01-30 19:03:52 +00:00
|
|
|
m_rect_when_windowless = a_rect;
|
2019-03-18 23:01:02 +00:00
|
|
|
if (!m_window_id) {
|
|
|
|
if (m_main_widget)
|
|
|
|
m_main_widget->resize(m_rect_when_windowless.size());
|
2019-02-14 00:21:32 +00:00
|
|
|
return;
|
2019-03-18 23:01:02 +00:00
|
|
|
}
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowRect>(m_window_id, a_rect);
|
2019-04-26 18:08:30 +00:00
|
|
|
if (m_back_bitmap && m_back_bitmap->size() != a_rect.size())
|
2019-04-10 12:35:13 +00:00
|
|
|
m_back_bitmap = nullptr;
|
2019-04-26 18:08:30 +00:00
|
|
|
if (m_front_bitmap && m_front_bitmap->size() != a_rect.size())
|
2019-04-10 12:35:13 +00:00
|
|
|
m_front_bitmap = nullptr;
|
2019-04-08 16:58:44 +00:00
|
|
|
if (m_main_widget)
|
|
|
|
m_main_widget->resize(a_rect.size());
|
2019-01-20 03:49:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_window_type(WindowType window_type)
|
2019-04-03 17:38:44 +00:00
|
|
|
{
|
|
|
|
m_window_type = window_type;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_override_cursor(StandardCursor cursor)
|
2019-03-31 21:52:02 +00:00
|
|
|
{
|
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowOverrideCursor>(m_window_id, (u32)cursor);
|
2019-03-31 21:52:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::event(Core::Event& event)
|
2019-01-20 03:49:48 +00:00
|
|
|
{
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::Drop) {
|
|
|
|
auto& drop_event = static_cast<DropEvent&>(event);
|
2019-12-08 15:50:23 +00:00
|
|
|
if (!m_main_widget)
|
|
|
|
return;
|
|
|
|
auto result = m_main_widget->hit_test(drop_event.position());
|
2020-02-02 14:07:41 +00:00
|
|
|
auto local_event = make<DropEvent>(result.local_position, drop_event.text(), drop_event.data_type(), drop_event.data());
|
2019-12-08 15:50:23 +00:00
|
|
|
ASSERT(result.widget);
|
|
|
|
return result.widget->dispatch_event(*local_event, this);
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::MouseUp || event.type() == Event::MouseDown || event.type() == Event::MouseDoubleClick || event.type() == Event::MouseMove || event.type() == Event::MouseWheel) {
|
|
|
|
auto& mouse_event = static_cast<MouseEvent&>(event);
|
2019-01-27 07:48:34 +00:00
|
|
|
if (m_global_cursor_tracking_widget) {
|
2019-02-26 09:34:05 +00:00
|
|
|
auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect();
|
2020-02-06 12:08:32 +00:00
|
|
|
Gfx::Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
|
2020-02-02 14:07:41 +00:00
|
|
|
auto local_event = make<MouseEvent>((Event::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
|
2019-09-20 18:37:31 +00:00
|
|
|
m_global_cursor_tracking_widget->dispatch_event(*local_event, this);
|
2019-03-24 14:01:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_automatic_cursor_tracking_widget) {
|
|
|
|
auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect();
|
2020-02-06 12:08:32 +00:00
|
|
|
Gfx::Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
|
2020-02-02 14:07:41 +00:00
|
|
|
auto local_event = make<MouseEvent>((Event::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
|
2019-09-20 18:37:31 +00:00
|
|
|
m_automatic_cursor_tracking_widget->dispatch_event(*local_event, this);
|
2019-03-25 00:42:15 +00:00
|
|
|
if (mouse_event.buttons() == 0)
|
2019-03-24 14:01:56 +00:00
|
|
|
m_automatic_cursor_tracking_widget = nullptr;
|
|
|
|
return;
|
2019-01-27 07:48:34 +00:00
|
|
|
}
|
2019-01-20 06:03:38 +00:00
|
|
|
if (!m_main_widget)
|
|
|
|
return;
|
2019-05-13 17:52:57 +00:00
|
|
|
auto result = m_main_widget->hit_test(mouse_event.position());
|
2020-02-02 14:07:41 +00:00
|
|
|
auto local_event = make<MouseEvent>((Event::Type)event.type(), result.local_position, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
|
2019-05-13 17:52:57 +00:00
|
|
|
ASSERT(result.widget);
|
|
|
|
set_hovered_widget(result.widget);
|
|
|
|
if (mouse_event.buttons() != 0 && !m_automatic_cursor_tracking_widget)
|
|
|
|
m_automatic_cursor_tracking_widget = result.widget->make_weak_ptr();
|
|
|
|
if (result.widget != m_global_cursor_tracking_widget.ptr())
|
2019-09-20 18:37:31 +00:00
|
|
|
return result.widget->dispatch_event(*local_event, this);
|
2019-01-26 20:58:43 +00:00
|
|
|
return;
|
2019-01-20 06:03:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::MultiPaint) {
|
2019-04-08 16:58:44 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2019-01-20 06:03:38 +00:00
|
|
|
if (!m_main_widget)
|
|
|
|
return;
|
2020-02-02 14:07:41 +00:00
|
|
|
auto& paint_event = static_cast<MultiPaintEvent&>(event);
|
2019-04-20 15:37:28 +00:00
|
|
|
auto rects = paint_event.rects();
|
|
|
|
ASSERT(!rects.is_empty());
|
2019-04-10 13:39:28 +00:00
|
|
|
if (m_back_bitmap && m_back_bitmap->size() != paint_event.window_size()) {
|
|
|
|
// Eagerly discard the backing store if we learn from this paint event that it needs to be bigger.
|
|
|
|
// Otherwise we would have to wait for a resize event to tell us. This way we don't waste the
|
|
|
|
// effort on painting into an undersized bitmap that will be thrown away anyway.
|
|
|
|
m_back_bitmap = nullptr;
|
|
|
|
}
|
2019-03-17 03:23:54 +00:00
|
|
|
bool created_new_backing_store = !m_back_bitmap;
|
2019-12-09 19:08:44 +00:00
|
|
|
if (!m_back_bitmap) {
|
2019-03-17 03:23:54 +00:00
|
|
|
m_back_bitmap = create_backing_bitmap(paint_event.window_size());
|
2019-12-09 19:08:44 +00:00
|
|
|
} else if (m_double_buffering_enabled) {
|
|
|
|
bool still_has_pixels = m_back_bitmap->shared_buffer()->set_nonvolatile();
|
|
|
|
if (!still_has_pixels) {
|
|
|
|
m_back_bitmap = create_backing_bitmap(paint_event.window_size());
|
|
|
|
created_new_backing_store = true;
|
|
|
|
}
|
|
|
|
}
|
2019-03-17 03:23:54 +00:00
|
|
|
|
2019-04-20 15:37:28 +00:00
|
|
|
auto rect = rects.first();
|
|
|
|
if (rect.is_empty() || created_new_backing_store) {
|
|
|
|
rects.clear();
|
2019-06-07 09:46:02 +00:00
|
|
|
rects.append({ {}, paint_event.window_size() });
|
2019-04-20 15:37:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 19:05:10 +00:00
|
|
|
for (auto& rect : rects)
|
2020-02-02 14:07:41 +00:00
|
|
|
m_main_widget->dispatch_event(*make<PaintEvent>(rect), this);
|
2019-03-17 03:23:54 +00:00
|
|
|
|
2019-05-21 19:05:10 +00:00
|
|
|
if (m_double_buffering_enabled)
|
|
|
|
flip(rects);
|
|
|
|
else if (created_new_backing_store)
|
2019-03-17 03:23:54 +00:00
|
|
|
set_current_backing_bitmap(*m_back_bitmap, true);
|
|
|
|
|
2019-01-30 19:03:52 +00:00
|
|
|
if (m_window_id) {
|
2020-02-06 12:02:38 +00:00
|
|
|
Vector<Gfx::Rect> rects_to_send;
|
2019-12-02 08:33:37 +00:00
|
|
|
for (auto& r : rects)
|
|
|
|
rects_to_send.append(r);
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().post_message(Messages::WindowServer::DidFinishPainting(m_window_id, rects_to_send));
|
2019-01-30 19:03:52 +00:00
|
|
|
}
|
2019-01-26 20:58:43 +00:00
|
|
|
return;
|
2019-01-20 06:03:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::KeyUp || event.type() == Event::KeyDown) {
|
2019-12-26 22:29:18 +00:00
|
|
|
if (m_focused_widget)
|
|
|
|
return m_focused_widget->dispatch_event(event, this);
|
|
|
|
if (m_main_widget)
|
|
|
|
return m_main_widget->dispatch_event(event, this);
|
2019-02-10 13:28:39 +00:00
|
|
|
return;
|
2019-01-26 05:39:13 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::WindowBecameActive || event.type() == Event::WindowBecameInactive) {
|
|
|
|
m_is_active = event.type() == Event::WindowBecameActive;
|
2019-02-10 13:28:39 +00:00
|
|
|
if (m_main_widget)
|
2019-09-20 18:37:31 +00:00
|
|
|
m_main_widget->dispatch_event(event, this);
|
2019-01-26 20:58:43 +00:00
|
|
|
if (m_focused_widget)
|
|
|
|
m_focused_widget->update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::WindowCloseRequest) {
|
2019-08-27 18:35:37 +00:00
|
|
|
if (on_close_request) {
|
2020-02-02 14:07:41 +00:00
|
|
|
if (on_close_request() == Window::CloseRequestDecision::StayOpen)
|
2019-08-27 18:35:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-02-05 09:31:37 +00:00
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::WindowLeft) {
|
2019-02-20 09:12:19 +00:00
|
|
|
set_hovered_widget(nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() == Event::Resize) {
|
|
|
|
auto new_size = static_cast<ResizeEvent&>(event).size();
|
2019-03-17 03:23:54 +00:00
|
|
|
if (m_back_bitmap && m_back_bitmap->size() != new_size)
|
|
|
|
m_back_bitmap = nullptr;
|
2019-04-21 23:15:47 +00:00
|
|
|
if (!m_pending_paint_event_rects.is_empty()) {
|
|
|
|
m_pending_paint_event_rects.clear_with_capacity();
|
2019-06-07 09:46:02 +00:00
|
|
|
m_pending_paint_event_rects.append({ {}, new_size });
|
2019-04-21 23:15:47 +00:00
|
|
|
}
|
2019-06-07 09:46:02 +00:00
|
|
|
m_rect_when_windowless = { {}, new_size };
|
|
|
|
m_main_widget->set_relative_rect({ {}, new_size });
|
2019-02-20 14:34:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
if (event.type() > Event::__Begin_WM_Events && event.type() < Event::__End_WM_Events)
|
|
|
|
return wm_event(static_cast<WMEvent&>(event));
|
2019-04-03 19:03:12 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
Core::Object::event(event);
|
2019-01-20 03:49:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
bool Window::is_visible() const
|
2019-01-20 03:49:48 +00:00
|
|
|
{
|
2019-06-22 08:37:03 +00:00
|
|
|
return m_window_id != 0;
|
2019-01-20 03:49:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::update()
|
2019-12-27 10:34:40 +00:00
|
|
|
{
|
|
|
|
update({ 0, 0, width(), height() });
|
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
void Window::update(const Gfx::Rect& a_rect)
|
2019-01-20 04:48:43 +00:00
|
|
|
{
|
2019-01-30 19:03:52 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2019-06-03 15:02:49 +00:00
|
|
|
|
2019-02-10 13:46:43 +00:00
|
|
|
for (auto& pending_rect : m_pending_paint_event_rects) {
|
|
|
|
if (pending_rect.contains(a_rect)) {
|
2019-02-11 07:27:13 +00:00
|
|
|
#ifdef UPDATE_COALESCING_DEBUG
|
2019-02-10 13:46:43 +00:00
|
|
|
dbgprintf("Ignoring %s since it's contained by pending rect %s\n", a_rect.to_string().characters(), pending_rect.to_string().characters());
|
2019-02-11 07:27:13 +00:00
|
|
|
#endif
|
2019-02-28 12:58:04 +00:00
|
|
|
return;
|
2019-02-10 13:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 13:19:02 +00:00
|
|
|
if (m_pending_paint_event_rects.is_empty()) {
|
2019-06-07 09:46:02 +00:00
|
|
|
deferred_invoke([this](auto&) {
|
2019-04-23 18:43:51 +00:00
|
|
|
auto rects = move(m_pending_paint_event_rects);
|
|
|
|
if (rects.is_empty())
|
|
|
|
return;
|
2020-02-06 12:02:38 +00:00
|
|
|
Vector<Gfx::Rect> rects_to_send;
|
2019-12-02 08:33:37 +00:00
|
|
|
for (auto& r : rects)
|
|
|
|
rects_to_send.append(r);
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().post_message(Messages::WindowServer::InvalidateRect(m_window_id, rects_to_send));
|
2019-04-20 13:19:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
m_pending_paint_event_rects.append(a_rect);
|
2019-01-20 04:48:43 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_main_widget(Widget* widget)
|
2019-01-20 04:48:43 +00:00
|
|
|
{
|
|
|
|
if (m_main_widget == widget)
|
|
|
|
return;
|
2019-08-18 10:17:09 +00:00
|
|
|
if (m_main_widget)
|
|
|
|
remove_child(*m_main_widget);
|
2019-01-20 04:48:43 +00:00
|
|
|
m_main_widget = widget;
|
2019-02-10 13:28:39 +00:00
|
|
|
if (m_main_widget) {
|
2019-08-18 10:17:09 +00:00
|
|
|
add_child(*widget);
|
2019-02-10 13:28:39 +00:00
|
|
|
auto new_window_rect = rect();
|
|
|
|
if (m_main_widget->horizontal_size_policy() == SizePolicy::Fixed)
|
|
|
|
new_window_rect.set_width(m_main_widget->preferred_size().width());
|
|
|
|
if (m_main_widget->vertical_size_policy() == SizePolicy::Fixed)
|
|
|
|
new_window_rect.set_height(m_main_widget->preferred_size().height());
|
|
|
|
set_rect(new_window_rect);
|
2019-06-07 09:46:02 +00:00
|
|
|
m_main_widget->set_relative_rect({ {}, new_window_rect.size() });
|
2019-02-10 13:28:39 +00:00
|
|
|
m_main_widget->set_window(this);
|
|
|
|
if (m_main_widget->accepts_focus())
|
|
|
|
m_main_widget->set_focus(true);
|
|
|
|
}
|
2019-01-20 04:48:43 +00:00
|
|
|
update();
|
|
|
|
}
|
2019-01-26 05:39:13 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_focused_widget(Widget* widget)
|
2019-01-26 05:39:13 +00:00
|
|
|
{
|
|
|
|
if (m_focused_widget == widget)
|
|
|
|
return;
|
2019-01-26 10:24:16 +00:00
|
|
|
if (m_focused_widget) {
|
2020-02-02 14:07:41 +00:00
|
|
|
Core::EventLoop::current().post_event(*m_focused_widget, make<Event>(Event::FocusOut));
|
2019-01-26 05:39:13 +00:00
|
|
|
m_focused_widget->update();
|
2019-01-26 10:24:16 +00:00
|
|
|
}
|
2019-04-18 21:16:57 +00:00
|
|
|
m_focused_widget = widget ? widget->make_weak_ptr() : nullptr;
|
2019-01-26 10:24:16 +00:00
|
|
|
if (m_focused_widget) {
|
2020-02-02 14:07:41 +00:00
|
|
|
Core::EventLoop::current().post_event(*m_focused_widget, make<Event>(Event::FocusIn));
|
2019-01-26 10:24:16 +00:00
|
|
|
m_focused_widget->update();
|
|
|
|
}
|
2019-01-26 05:39:13 +00:00
|
|
|
}
|
2019-01-27 07:48:34 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_global_cursor_tracking_widget(Widget* widget)
|
2019-01-27 07:48:34 +00:00
|
|
|
{
|
2019-04-14 00:36:06 +00:00
|
|
|
if (widget == m_global_cursor_tracking_widget)
|
2019-01-27 07:48:34 +00:00
|
|
|
return;
|
2019-01-31 16:31:23 +00:00
|
|
|
m_global_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
|
2019-03-24 14:01:56 +00:00
|
|
|
}
|
2019-02-14 00:21:32 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_automatic_cursor_tracking_widget(Widget* widget)
|
2019-03-24 14:01:56 +00:00
|
|
|
{
|
2019-04-14 00:36:06 +00:00
|
|
|
if (widget == m_automatic_cursor_tracking_widget)
|
2019-03-24 14:01:56 +00:00
|
|
|
return;
|
|
|
|
m_automatic_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
|
2019-01-27 07:48:34 +00:00
|
|
|
}
|
2019-02-19 00:42:53 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_has_alpha_channel(bool value)
|
2019-02-19 00:42:53 +00:00
|
|
|
{
|
2019-05-03 19:07:16 +00:00
|
|
|
if (m_has_alpha_channel == value)
|
|
|
|
return;
|
2019-02-19 00:42:53 +00:00
|
|
|
m_has_alpha_channel = value;
|
2019-05-03 19:07:16 +00:00
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_pending_paint_event_rects.clear();
|
|
|
|
m_back_bitmap = nullptr;
|
|
|
|
m_front_bitmap = nullptr;
|
|
|
|
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowHasAlphaChannel>(m_window_id, value);
|
2019-05-03 19:07:16 +00:00
|
|
|
update();
|
2019-02-19 00:42:53 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_double_buffering_enabled(bool value)
|
2019-03-17 03:23:54 +00:00
|
|
|
{
|
|
|
|
ASSERT(!m_window_id);
|
|
|
|
m_double_buffering_enabled = value;
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_opacity(float opacity)
|
2019-02-19 00:42:53 +00:00
|
|
|
{
|
|
|
|
m_opacity_when_windowless = opacity;
|
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowOpacity>(m_window_id, opacity);
|
2019-02-19 00:42:53 +00:00
|
|
|
}
|
2019-02-20 09:12:19 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_hovered_widget(Widget* widget)
|
2019-02-20 09:12:19 +00:00
|
|
|
{
|
2019-04-14 00:36:06 +00:00
|
|
|
if (widget == m_hovered_widget)
|
2019-02-20 09:12:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_hovered_widget)
|
2020-02-02 14:07:41 +00:00
|
|
|
Core::EventLoop::current().post_event(*m_hovered_widget, make<Event>(Event::Leave));
|
2019-02-20 09:12:19 +00:00
|
|
|
|
|
|
|
m_hovered_widget = widget ? widget->make_weak_ptr() : nullptr;
|
|
|
|
|
|
|
|
if (m_hovered_widget)
|
2020-02-02 14:07:41 +00:00
|
|
|
Core::EventLoop::current().post_event(*m_hovered_widget, make<Event>(Event::Enter));
|
2019-02-20 09:12:19 +00:00
|
|
|
}
|
2019-03-17 03:23:54 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
void Window::set_current_backing_bitmap(Gfx::Bitmap& bitmap, bool flush_immediately)
|
2019-03-17 03:23:54 +00:00
|
|
|
{
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBackingStore>(m_window_id, 32, bitmap.pitch(), bitmap.shared_buffer_id(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately);
|
2019-03-17 03:23:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:02:38 +00:00
|
|
|
void Window::flip(const Vector<Gfx::Rect, 32>& dirty_rects)
|
2019-03-17 03:23:54 +00:00
|
|
|
{
|
|
|
|
swap(m_front_bitmap, m_back_bitmap);
|
|
|
|
|
|
|
|
set_current_backing_bitmap(*m_front_bitmap);
|
|
|
|
|
|
|
|
if (!m_back_bitmap || m_back_bitmap->size() != m_front_bitmap->size()) {
|
|
|
|
m_back_bitmap = create_backing_bitmap(m_front_bitmap->size());
|
2019-05-08 01:33:44 +00:00
|
|
|
memcpy(m_back_bitmap->scanline(0), m_front_bitmap->scanline(0), m_front_bitmap->size_in_bytes());
|
2019-12-09 20:33:39 +00:00
|
|
|
m_back_bitmap->shared_buffer()->set_volatile();
|
2019-03-17 03:23:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy whatever was painted from the front to the back.
|
|
|
|
Painter painter(*m_back_bitmap);
|
2019-05-21 19:05:10 +00:00
|
|
|
for (auto& dirty_rect : dirty_rects)
|
|
|
|
painter.blit(dirty_rect.location(), *m_front_bitmap, dirty_rect);
|
2019-12-09 19:08:44 +00:00
|
|
|
|
|
|
|
m_back_bitmap->shared_buffer()->set_volatile();
|
2019-03-17 03:23:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> Window::create_shared_bitmap(Gfx::Bitmap::Format format, const Gfx::Size& size)
|
2019-03-17 03:23:54 +00:00
|
|
|
{
|
2020-02-02 14:07:41 +00:00
|
|
|
ASSERT(WindowServerConnection::the().server_pid());
|
2019-03-17 03:23:54 +00:00
|
|
|
ASSERT(!size.is_empty());
|
2020-02-06 10:56:38 +00:00
|
|
|
size_t pitch = round_up_to_power_of_two(size.width() * sizeof(Gfx::RGBA32), 16);
|
2019-05-06 12:04:54 +00:00
|
|
|
size_t size_in_bytes = size.height() * pitch;
|
2019-07-18 07:52:22 +00:00
|
|
|
auto shared_buffer = SharedBuffer::create_with_size(size_in_bytes);
|
2019-03-17 03:23:54 +00:00
|
|
|
ASSERT(shared_buffer);
|
2020-02-02 14:07:41 +00:00
|
|
|
shared_buffer->share_with(WindowServerConnection::the().server_pid());
|
2020-02-06 10:56:38 +00:00
|
|
|
return Gfx::Bitmap::create_with_shared_buffer(format, *shared_buffer, size);
|
2019-03-17 03:23:54 +00:00
|
|
|
}
|
2019-03-18 23:01:02 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> Window::create_backing_bitmap(const Gfx::Size& size)
|
2019-07-28 08:18:49 +00:00
|
|
|
{
|
2020-02-06 10:56:38 +00:00
|
|
|
auto format = m_has_alpha_channel ? Gfx::Bitmap::Format::RGBA32 : Gfx::Bitmap::Format::RGB32;
|
2019-07-28 08:18:49 +00:00
|
|
|
return create_shared_bitmap(format, size);
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_modal(bool modal)
|
2019-03-18 23:01:02 +00:00
|
|
|
{
|
|
|
|
ASSERT(!m_window_id);
|
|
|
|
m_modal = modal;
|
|
|
|
}
|
2019-04-03 19:03:12 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::wm_event(WMEvent&)
|
2019-04-03 19:03:12 +00:00
|
|
|
{
|
|
|
|
}
|
2019-04-13 14:59:55 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
void Window::set_icon(const Gfx::Bitmap* icon)
|
2019-07-28 08:18:49 +00:00
|
|
|
{
|
|
|
|
if (m_icon == icon)
|
|
|
|
return;
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
m_icon = create_shared_bitmap(Gfx::Bitmap::Format::RGBA32, icon->size());
|
2019-07-28 08:18:49 +00:00
|
|
|
{
|
2020-02-02 14:07:41 +00:00
|
|
|
Painter painter(*m_icon);
|
2019-07-28 08:18:49 +00:00
|
|
|
painter.blit({ 0, 0 }, *icon, icon->rect());
|
|
|
|
}
|
|
|
|
|
2019-08-02 19:02:56 +00:00
|
|
|
apply_icon();
|
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::apply_icon()
|
2019-08-02 19:02:56 +00:00
|
|
|
{
|
|
|
|
if (!m_icon)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
|
|
|
|
2019-07-29 05:26:01 +00:00
|
|
|
int rc = seal_shared_buffer(m_icon->shared_buffer_id());
|
|
|
|
ASSERT(rc == 0);
|
|
|
|
|
|
|
|
rc = share_buffer_globally(m_icon->shared_buffer_id());
|
|
|
|
ASSERT(rc == 0);
|
|
|
|
|
|
|
|
static bool has_set_process_icon;
|
|
|
|
if (!has_set_process_icon)
|
|
|
|
set_process_icon(m_icon->shared_buffer_id());
|
|
|
|
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowIconBitmap>(m_window_id, m_icon->shared_buffer_id(), m_icon->size());
|
2019-07-28 08:18:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::start_wm_resize()
|
2019-05-02 23:38:24 +00:00
|
|
|
{
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().post_message(Messages::WindowServer::WM_StartWindowResize(WindowServerConnection::the().my_client_id(), m_window_id));
|
2019-05-02 23:38:24 +00:00
|
|
|
}
|
2019-05-15 00:39:58 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Vector<Widget*> Window::focusable_widgets() const
|
2019-05-15 00:39:58 +00:00
|
|
|
{
|
|
|
|
if (!m_main_widget)
|
2019-06-07 09:46:02 +00:00
|
|
|
return {};
|
2019-05-15 00:39:58 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Vector<Widget*> collected_widgets;
|
2019-05-15 00:39:58 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Function<void(Widget&)> collect_focusable_widgets = [&](auto& widget) {
|
2019-05-15 00:39:58 +00:00
|
|
|
if (widget.accepts_focus())
|
|
|
|
collected_widgets.append(&widget);
|
2019-06-07 09:46:02 +00:00
|
|
|
widget.for_each_child_widget([&](auto& child) {
|
2019-05-27 01:52:33 +00:00
|
|
|
if (!child.is_visible())
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
if (!child.is_enabled())
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
collect_focusable_widgets(child);
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
2019-05-15 00:39:58 +00:00
|
|
|
};
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
collect_focusable_widgets(const_cast<Widget&>(*m_main_widget));
|
2019-05-15 00:39:58 +00:00
|
|
|
return collected_widgets;
|
|
|
|
}
|
2019-08-18 18:39:46 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::save_to(AK::JsonObject& json)
|
2019-08-18 18:39:46 +00:00
|
|
|
{
|
|
|
|
json.set("title", title());
|
|
|
|
json.set("visible", is_visible());
|
|
|
|
json.set("active", is_active());
|
2020-01-04 11:12:02 +00:00
|
|
|
json.set("minimizable", is_minimizable());
|
2019-08-18 18:39:46 +00:00
|
|
|
json.set("resizable", is_resizable());
|
|
|
|
json.set("fullscreen", is_fullscreen());
|
|
|
|
json.set("rect", rect().to_string());
|
|
|
|
json.set("base_size", base_size().to_string());
|
|
|
|
json.set("size_increment", size_increment().to_string());
|
2020-02-02 11:34:39 +00:00
|
|
|
Core::Object::save_to(json);
|
2019-08-18 18:39:46 +00:00
|
|
|
}
|
2019-09-16 16:38:42 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::set_fullscreen(bool fullscreen)
|
2019-09-16 16:38:42 +00:00
|
|
|
{
|
|
|
|
if (m_fullscreen == fullscreen)
|
|
|
|
return;
|
|
|
|
m_fullscreen = fullscreen;
|
|
|
|
if (!m_window_id)
|
|
|
|
return;
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetFullscreen>(m_window_id, fullscreen);
|
2019-09-16 16:38:42 +00:00
|
|
|
}
|
2019-10-26 10:27:01 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::schedule_relayout()
|
2019-10-26 10:27:01 +00:00
|
|
|
{
|
|
|
|
if (m_layout_pending)
|
|
|
|
return;
|
|
|
|
m_layout_pending = true;
|
|
|
|
deferred_invoke([this](auto&) {
|
|
|
|
if (main_widget())
|
|
|
|
main_widget()->do_layout();
|
|
|
|
update();
|
|
|
|
m_layout_pending = false;
|
|
|
|
});
|
|
|
|
}
|
2019-12-23 19:24:26 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::update_all_windows(Badge<WindowServerConnection>)
|
2019-12-23 19:24:26 +00:00
|
|
|
{
|
2019-12-26 21:13:50 +00:00
|
|
|
for (auto* window : *all_windows) {
|
2019-12-23 19:24:26 +00:00
|
|
|
window->update();
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 11:06:07 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void Window::notify_state_changed(Badge<WindowServerConnection>, bool minimized, bool occluded)
|
2019-12-26 11:06:07 +00:00
|
|
|
{
|
2019-12-29 14:58:07 +00:00
|
|
|
m_visible_for_timer_purposes = !minimized && !occluded;
|
|
|
|
|
2019-12-27 10:34:40 +00:00
|
|
|
// When double buffering is enabled, minimization/occlusion means we can mark the front bitmap volatile (in addition to the back bitmap.)
|
2019-12-26 11:06:07 +00:00
|
|
|
// When double buffering is disabled, there is only the back bitmap (which we can now mark volatile!)
|
2020-02-06 10:56:38 +00:00
|
|
|
RefPtr<Gfx::Bitmap>& bitmap = m_double_buffering_enabled ? m_front_bitmap : m_back_bitmap;
|
2019-12-26 11:06:07 +00:00
|
|
|
if (!bitmap)
|
|
|
|
return;
|
2019-12-27 10:34:40 +00:00
|
|
|
if (minimized || occluded) {
|
2019-12-26 11:06:07 +00:00
|
|
|
bitmap->shared_buffer()->set_volatile();
|
|
|
|
} else {
|
2019-12-27 10:34:40 +00:00
|
|
|
if (!bitmap->shared_buffer()->set_nonvolatile()) {
|
2019-12-26 11:06:07 +00:00
|
|
|
bitmap = nullptr;
|
2019-12-27 10:34:40 +00:00
|
|
|
update();
|
|
|
|
}
|
2019-12-26 11:06:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-02 00:57:57 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Action* Window::action_for_key_event(const KeyEvent& event)
|
2020-02-02 00:57:57 +00:00
|
|
|
{
|
2020-02-02 14:07:41 +00:00
|
|
|
Shortcut shortcut(event.modifiers(), (KeyCode)event.key());
|
|
|
|
Action* found_action = nullptr;
|
|
|
|
for_each_child_of_type<Action>([&](auto& action) {
|
2020-02-02 00:57:57 +00:00
|
|
|
if (action.shortcut() == shortcut) {
|
|
|
|
found_action = &action;
|
|
|
|
return IterationDecision::Break;
|
|
|
|
}
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
|
|
|
return found_action;
|
|
|
|
}
|
2020-02-02 14:07:41 +00:00
|
|
|
|
|
|
|
}
|