123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- #include "GWindow.h"
- #include "GEvent.h"
- #include "GEventLoop.h"
- #include "GWidget.h"
- #include <AK/HashMap.h>
- #include <AK/StringBuilder.h>
- #include <LibC/stdio.h>
- #include <LibC/stdlib.h>
- #include <LibC/unistd.h>
- #include <LibGUI/GPainter.h>
- #include <SharedGraphics/GraphicsBitmap.h>
- //#define UPDATE_COALESCING_DEBUG
- static HashMap<int, GWindow*>* s_windows;
- static HashMap<int, GWindow*>& windows()
- {
- if (!s_windows)
- s_windows = new HashMap<int, GWindow*>;
- return *s_windows;
- }
- GWindow* GWindow::from_window_id(int window_id)
- {
- auto it = windows().find(window_id);
- if (it != windows().end())
- return (*it).value;
- return nullptr;
- }
- GWindow::GWindow(CObject* parent)
- : CObject(parent)
- {
- m_rect_when_windowless = { 100, 400, 140, 140 };
- m_title_when_windowless = "GWindow";
- }
- GWindow::~GWindow()
- {
- if (m_main_widget)
- delete m_main_widget;
- hide();
- }
- void GWindow::close()
- {
- if (should_exit_event_loop_on_close())
- GEventLoop::current().quit(0);
- delete_later();
- }
- void GWindow::move_to_front()
- {
- if (!m_window_id)
- return;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::MoveWindowToFront;
- request.window_id = m_window_id;
- GEventLoop::post_message_to_server(request);
- }
- void GWindow::show()
- {
- if (m_window_id)
- return;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::CreateWindow;
- request.window_id = m_window_id;
- request.window.rect = m_rect_when_windowless;
- request.window.has_alpha_channel = m_has_alpha_channel;
- request.window.modal = m_modal;
- request.window.resizable = m_resizable;
- request.window.fullscreen = m_fullscreen;
- request.window.show_titlebar = m_show_titlebar;
- request.window.opacity = m_opacity_when_windowless;
- request.window.background_color = m_background_color.value();
- request.window.size_increment = m_size_increment;
- request.window.base_size = m_base_size;
- request.window.type = (WSAPI_WindowType)m_window_type;
- ASSERT(m_title_when_windowless.length() < (ssize_t)sizeof(request.text));
- strcpy(request.text, m_title_when_windowless.characters());
- request.text_length = m_title_when_windowless.length();
- auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidCreateWindow);
- m_window_id = response.window_id;
- windows().set(m_window_id, this);
- update();
- }
- void GWindow::hide()
- {
- if (!m_window_id)
- return;
- windows().remove(m_window_id);
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::DestroyWindow;
- request.window_id = m_window_id;
- GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidDestroyWindow);
- m_window_id = 0;
- m_pending_paint_event_rects.clear();
- m_back_bitmap = nullptr;
- m_front_bitmap = nullptr;
- }
- void GWindow::set_title(const StringView& title)
- {
- m_title_when_windowless = title;
- if (!m_window_id)
- return;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::SetWindowTitle;
- request.window_id = m_window_id;
- ASSERT(m_title_when_windowless.length() < (ssize_t)sizeof(request.text));
- strcpy(request.text, m_title_when_windowless.characters());
- request.text_length = m_title_when_windowless.length();
- GEventLoop::current().post_message_to_server(request);
- }
- String GWindow::title() const
- {
- if (!m_window_id)
- return m_title_when_windowless;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::GetWindowTitle;
- request.window_id = m_window_id;
- auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidGetWindowTitle);
- return String(response.text, response.text_length);
- }
- Rect GWindow::rect() const
- {
- if (!m_window_id)
- return m_rect_when_windowless;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::GetWindowRect;
- request.window_id = m_window_id;
- auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidGetWindowRect);
- ASSERT(response.window_id == m_window_id);
- return response.window.rect;
- }
- void GWindow::set_rect(const Rect& a_rect)
- {
- m_rect_when_windowless = a_rect;
- if (!m_window_id) {
- if (m_main_widget)
- m_main_widget->resize(m_rect_when_windowless.size());
- return;
- }
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::SetWindowRect;
- request.window_id = m_window_id;
- request.window.rect = a_rect;
- GEventLoop::current().post_message_to_server(request);
- if (m_back_bitmap && m_back_bitmap->size() != a_rect.size())
- m_back_bitmap = nullptr;
- if (m_front_bitmap && m_front_bitmap->size() != a_rect.size())
- m_front_bitmap = nullptr;
- if (m_main_widget)
- m_main_widget->resize(a_rect.size());
- }
- void GWindow::set_window_type(GWindowType window_type)
- {
- m_window_type = window_type;
- }
- void GWindow::set_override_cursor(GStandardCursor cursor)
- {
- if (!m_window_id)
- return;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::SetWindowOverrideCursor;
- request.window_id = m_window_id;
- request.cursor.cursor = (WSAPI_StandardCursor)cursor;
- GEventLoop::current().post_message_to_server(request);
- }
- void GWindow::event(CEvent& event)
- {
- if (event.type() == GEvent::MouseUp || event.type() == GEvent::MouseDown || event.type() == GEvent::MouseDoubleClick || event.type() == GEvent::MouseMove || event.type() == GEvent::MouseWheel) {
- auto& mouse_event = static_cast<GMouseEvent&>(event);
- if (m_global_cursor_tracking_widget) {
- auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect();
- Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
- auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
- m_global_cursor_tracking_widget->event(*local_event);
- return;
- }
- if (m_automatic_cursor_tracking_widget) {
- auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect();
- Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
- auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
- m_automatic_cursor_tracking_widget->event(*local_event);
- if (mouse_event.buttons() == 0)
- m_automatic_cursor_tracking_widget = nullptr;
- return;
- }
- if (!m_main_widget)
- return;
- auto result = m_main_widget->hit_test(mouse_event.position());
- auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), result.local_position, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
- 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())
- return result.widget->event(*local_event);
- return;
- }
- if (event.type() == GEvent::MultiPaint) {
- if (!m_window_id)
- return;
- if (!m_main_widget)
- return;
- auto& paint_event = static_cast<GMultiPaintEvent&>(event);
- auto rects = paint_event.rects();
- ASSERT(!rects.is_empty());
- 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;
- }
- bool created_new_backing_store = !m_back_bitmap;
- if (!m_back_bitmap)
- m_back_bitmap = create_backing_bitmap(paint_event.window_size());
- auto rect = rects.first();
- if (rect.is_empty() || created_new_backing_store) {
- rects.clear();
- rects.append({ {}, paint_event.window_size() });
- }
- for (auto& rect : rects)
- m_main_widget->event(*make<GPaintEvent>(rect));
- paint_keybinds();
- if (m_double_buffering_enabled)
- flip(rects);
- else if (created_new_backing_store)
- set_current_backing_bitmap(*m_back_bitmap, true);
- if (m_window_id) {
- WSAPI_ClientMessage message;
- message.type = WSAPI_ClientMessage::Type::DidFinishPainting;
- message.window_id = m_window_id;
- message.rect_count = rects.size();
- for (int i = 0; i < min(WSAPI_ClientMessage::max_inline_rect_count, rects.size()); ++i)
- message.rects[i] = rects[i];
- ByteBuffer extra_data;
- if (rects.size() > WSAPI_ClientMessage::max_inline_rect_count)
- extra_data = ByteBuffer::wrap(&rects[WSAPI_ClientMessage::max_inline_rect_count], (rects.size() - WSAPI_ClientMessage::max_inline_rect_count) * sizeof(WSAPI_Rect));
- GEventLoop::current().post_message_to_server(message, extra_data);
- }
- return;
- }
- if (event.type() == GEvent::KeyUp || event.type() == GEvent::KeyDown) {
- auto keyevent = static_cast<GKeyEvent&>(event);
- if (keyevent.logo() && event.type() == GEvent::KeyUp) {
- if (m_keybind_mode) {
- m_keybind_mode = false;
- } else {
- m_keybind_mode = true;
- find_keyboard_selectable();
- m_entered_keybind = "";
- }
- update();
- return;
- }
- if (m_keybind_mode) {
- if (event.type() == GEvent::KeyUp) {
- StringBuilder builder;
- builder.append(m_entered_keybind);
- builder.append(keyevent.text());
- m_entered_keybind = builder.to_string();
- auto found_widget = m_hashed_potential_keybind_widgets.find(m_entered_keybind);
- if (found_widget != m_hashed_potential_keybind_widgets.end()) {
- m_keybind_mode = false;
- const auto &point = Point();
- auto event = make<GMouseEvent>(GEvent::MouseDown, point, 0, GMouseButton::Left, 0, 0);
- found_widget->value->event(*event);
- event = make<GMouseEvent>(GEvent::MouseUp, point, 0, GMouseButton::Left, 0, 0);
- found_widget->value->event(*event);
- } else if (m_entered_keybind.length() >= m_max_keybind_length) {
- m_keybind_mode = false;
- }
- update();
- }
- } else {
- if (m_focused_widget)
- return m_focused_widget->event(event);
- if (m_main_widget)
- return m_main_widget->event(event);
- }
- return;
- }
- if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) {
- if (event.type() == GEvent::WindowBecameInactive && m_keybind_mode) {
- m_keybind_mode = false;
- update();
- }
- m_is_active = event.type() == GEvent::WindowBecameActive;
- if (m_main_widget)
- m_main_widget->event(event);
- if (m_focused_widget)
- m_focused_widget->update();
- return;
- }
- if (event.type() == GEvent::WindowCloseRequest) {
- close();
- return;
- }
- if (event.type() == GEvent::WindowLeft) {
- set_hovered_widget(nullptr);
- return;
- }
- if (event.type() == GEvent::Resize) {
- auto new_size = static_cast<GResizeEvent&>(event).size();
- if (m_back_bitmap && m_back_bitmap->size() != new_size)
- m_back_bitmap = nullptr;
- if (!m_pending_paint_event_rects.is_empty()) {
- m_pending_paint_event_rects.clear_with_capacity();
- m_pending_paint_event_rects.append({ {}, new_size });
- }
- m_rect_when_windowless = { {}, new_size };
- m_main_widget->set_relative_rect({ {}, new_size });
- return;
- }
- if (event.type() > GEvent::__Begin_WM_Events && event.type() < GEvent::__End_WM_Events)
- return wm_event(static_cast<GWMEvent&>(event));
- CObject::event(event);
- }
- void GWindow::paint_keybinds() {
- if (!m_keybind_mode) return;
- GPainter painter(*m_main_widget);
- for (auto& keypair: m_hashed_potential_keybind_widgets) {
- auto widget = keypair.value;
- bool could_be_keybind = true;
- for (size_t i = 0; i < m_entered_keybind.length(); i++) {
- if (keypair.key.characters()[i] != m_entered_keybind.characters()[i]) {
- could_be_keybind = false;
- }
- }
- if (could_be_keybind) {
- auto rect = Rect(widget->x()-5, widget->y()-5, 4+Font::default_font().width(keypair.key), 16);
- auto highlight_rect = Rect(widget->x()-3, widget->y()-5, 0, 16);
- painter.fill_rect(rect, Color::LightGray);
- painter.draw_rect(rect, Color::Black, false);
- painter.draw_text(rect, keypair.key.characters(), TextAlignment::Center, Color::Black);
- painter.draw_text(highlight_rect, m_entered_keybind.characters(), TextAlignment::CenterLeft, Color::MidGray);
- }
- }
- }
- void GWindow::find_keyboard_selectable() {
- Vector<GWidget*> potential_keybind_widgets;
- m_hashed_potential_keybind_widgets.clear();
- find_keyboard_selectable_children(m_main_widget, potential_keybind_widgets);
- m_max_keybind_length = ceil_div(potential_keybind_widgets.size(), ('z'-'a'));
- size_t buffer_length = m_max_keybind_length + 1;
- char keybind_buffer[buffer_length];
- for (size_t i = 0; i < buffer_length-1; i++) {
- keybind_buffer[i] = 'a';
- }
- keybind_buffer[buffer_length-1] = '\0';
- for (auto& widget: potential_keybind_widgets) {
- m_hashed_potential_keybind_widgets.set(String(keybind_buffer), widget);
- for (size_t i = 0; i < buffer_length-1; i++) {
- if (keybind_buffer[i] >= 'z') {
- keybind_buffer[i] = 'a';
- } else {
- keybind_buffer[i]++;
- break;
- }
- }
- }
- }
- void GWindow::find_keyboard_selectable_children(GWidget* widget, Vector<GWidget*> &potential_keybind_widgets) {
- widget -> for_each_child_widget([&] (auto& child) {
- if (child.accepts_keyboard_select()) {
- potential_keybind_widgets.append(&child);
- find_keyboard_selectable_children(&child, potential_keybind_widgets);
- }
- return IterationDecision::Continue;
- });
- }
- bool GWindow::is_visible() const
- {
- return false;
- }
- void GWindow::update(const Rect& a_rect)
- {
- if (!m_window_id)
- return;
- for (auto& pending_rect : m_pending_paint_event_rects) {
- if (pending_rect.contains(a_rect)) {
- #ifdef UPDATE_COALESCING_DEBUG
- dbgprintf("Ignoring %s since it's contained by pending rect %s\n", a_rect.to_string().characters(), pending_rect.to_string().characters());
- #endif
- return;
- }
- }
- if (m_pending_paint_event_rects.is_empty()) {
- deferred_invoke([this](auto&) {
- auto rects = move(m_pending_paint_event_rects);
- if (rects.is_empty())
- return;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::InvalidateRect;
- request.window_id = m_window_id;
- for (int i = 0; i < min(WSAPI_ClientMessage::max_inline_rect_count, rects.size()); ++i)
- request.rects[i] = rects[i];
- ByteBuffer extra_data;
- if (rects.size() > WSAPI_ClientMessage::max_inline_rect_count)
- extra_data = ByteBuffer::wrap(&rects[WSAPI_ClientMessage::max_inline_rect_count], (rects.size() - WSAPI_ClientMessage::max_inline_rect_count) * sizeof(WSAPI_Rect));
- request.rect_count = rects.size();
- GEventLoop::current().post_message_to_server(request, extra_data);
- });
- }
- m_pending_paint_event_rects.append(a_rect);
- }
- void GWindow::set_main_widget(GWidget* widget)
- {
- if (m_main_widget == widget)
- return;
- m_main_widget = widget;
- if (m_main_widget) {
- 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);
- m_main_widget->set_relative_rect({ {}, new_window_rect.size() });
- m_main_widget->set_window(this);
- if (m_main_widget->accepts_focus())
- m_main_widget->set_focus(true);
- }
- update();
- }
- void GWindow::set_focused_widget(GWidget* widget)
- {
- if (m_focused_widget == widget)
- return;
- if (m_focused_widget) {
- GEventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusOut));
- m_focused_widget->update();
- }
- m_focused_widget = widget ? widget->make_weak_ptr() : nullptr;
- if (m_focused_widget) {
- GEventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusIn));
- m_focused_widget->update();
- }
- }
- void GWindow::set_global_cursor_tracking_widget(GWidget* widget)
- {
- if (widget == m_global_cursor_tracking_widget)
- return;
- m_global_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
- }
- void GWindow::set_automatic_cursor_tracking_widget(GWidget* widget)
- {
- if (widget == m_automatic_cursor_tracking_widget)
- return;
- m_automatic_cursor_tracking_widget = widget ? widget->make_weak_ptr() : nullptr;
- }
- void GWindow::set_has_alpha_channel(bool value)
- {
- if (m_has_alpha_channel == value)
- return;
- m_has_alpha_channel = value;
- if (!m_window_id)
- return;
- m_pending_paint_event_rects.clear();
- m_back_bitmap = nullptr;
- m_front_bitmap = nullptr;
- WSAPI_ClientMessage message;
- message.type = WSAPI_ClientMessage::Type::SetWindowHasAlphaChannel;
- message.window_id = m_window_id;
- message.value = value;
- GEventLoop::current().sync_request(message, WSAPI_ServerMessage::DidSetWindowHasAlphaChannel);
- update();
- }
- void GWindow::set_double_buffering_enabled(bool value)
- {
- ASSERT(!m_window_id);
- m_double_buffering_enabled = value;
- }
- void GWindow::set_opacity(float opacity)
- {
- m_opacity_when_windowless = opacity;
- if (!m_window_id)
- return;
- WSAPI_ClientMessage request;
- request.type = WSAPI_ClientMessage::Type::SetWindowOpacity;
- request.window_id = m_window_id;
- request.window.opacity = opacity;
- m_opacity_when_windowless = opacity;
- GEventLoop::current().post_message_to_server(request);
- }
- void GWindow::set_hovered_widget(GWidget* widget)
- {
- if (widget == m_hovered_widget)
- return;
- if (m_hovered_widget)
- GEventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Leave));
- m_hovered_widget = widget ? widget->make_weak_ptr() : nullptr;
- if (m_hovered_widget)
- GEventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Enter));
- }
- void GWindow::set_current_backing_bitmap(GraphicsBitmap& bitmap, bool flush_immediately)
- {
- WSAPI_ClientMessage message;
- message.type = WSAPI_ClientMessage::Type::SetWindowBackingStore;
- message.window_id = m_window_id;
- message.backing.bpp = 32;
- message.backing.pitch = bitmap.pitch();
- message.backing.shared_buffer_id = bitmap.shared_buffer_id();
- message.backing.has_alpha_channel = bitmap.has_alpha_channel();
- message.backing.size = bitmap.size();
- message.backing.flush_immediately = flush_immediately;
- GEventLoop::current().sync_request(message, WSAPI_ServerMessage::Type::DidSetWindowBackingStore);
- }
- void GWindow::flip(const Vector<Rect, 32>& dirty_rects)
- {
- 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());
- memcpy(m_back_bitmap->scanline(0), m_front_bitmap->scanline(0), m_front_bitmap->size_in_bytes());
- return;
- }
- // Copy whatever was painted from the front to the back.
- Painter painter(*m_back_bitmap);
- for (auto& dirty_rect : dirty_rects)
- painter.blit(dirty_rect.location(), *m_front_bitmap, dirty_rect);
- }
- Retained<GraphicsBitmap> GWindow::create_backing_bitmap(const Size& size)
- {
- ASSERT(GEventLoop::server_pid());
- ASSERT(!size.is_empty());
- size_t pitch = round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16);
- size_t size_in_bytes = size.height() * pitch;
- auto shared_buffer = SharedBuffer::create(GEventLoop::server_pid(), size_in_bytes);
- ASSERT(shared_buffer);
- auto format = m_has_alpha_channel ? GraphicsBitmap::Format::RGBA32 : GraphicsBitmap::Format::RGB32;
- return GraphicsBitmap::create_with_shared_buffer(format, *shared_buffer, size);
- }
- void GWindow::set_modal(bool modal)
- {
- ASSERT(!m_window_id);
- m_modal = modal;
- }
- void GWindow::wm_event(GWMEvent&)
- {
- }
- void GWindow::set_icon_path(const StringView& path)
- {
- if (m_icon_path == path)
- return;
- m_icon_path = path;
- if (!m_window_id)
- return;
- WSAPI_ClientMessage message;
- message.type = WSAPI_ClientMessage::Type::SetWindowIcon;
- message.window_id = m_window_id;
- ASSERT(path.length() < sizeof(message.text));
- strcpy(message.text, path.characters());
- message.text_length = path.length();
- GEventLoop::post_message_to_server(message);
- }
- void GWindow::start_wm_resize()
- {
- WSAPI_ClientMessage message;
- message.type = WSAPI_ClientMessage::Type::WM_StartWindowResize;
- message.wm.client_id = GEventLoop::my_client_id();
- message.wm.window_id = m_window_id;
- GEventLoop::post_message_to_server(message);
- }
- Vector<GWidget*> GWindow::focusable_widgets() const
- {
- if (!m_main_widget)
- return {};
- Vector<GWidget*> collected_widgets;
- Function<void(GWidget&)> collect_focusable_widgets = [&](GWidget& widget) {
- if (widget.accepts_focus())
- collected_widgets.append(&widget);
- widget.for_each_child_widget([&](auto& child) {
- if (!child.is_visible())
- return IterationDecision::Continue;
- if (!child.is_enabled())
- return IterationDecision::Continue;
- collect_focusable_widgets(child);
- return IterationDecision::Continue;
- });
- };
- collect_focusable_widgets(*m_main_widget);
- return collected_widgets;
- }
|