Serenity Operating System
1/*
2 * Copyright (c) 2021, the SerenityOS developers.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibGUI/ConnectionToWindowManagerServer.h>
8#include <LibGUI/Event.h>
9#include <LibGUI/Window.h>
10
11namespace GUI {
12
13ConnectionToWindowManagerServer& ConnectionToWindowManagerServer::the()
14{
15 static RefPtr<ConnectionToWindowManagerServer> s_connection = nullptr;
16 if (!s_connection)
17 s_connection = ConnectionToWindowManagerServer::try_create().release_value_but_fixme_should_propagate_errors();
18 return *s_connection;
19}
20
21void ConnectionToWindowManagerServer::window_state_changed(i32 wm_id, i32 client_id, i32 window_id,
22 u32 workspace_row, u32 workspace_column, bool is_active, bool is_blocked, bool is_minimized, bool is_frameless,
23 i32 window_type, DeprecatedString const& title, Gfx::IntRect const& rect, Optional<i32> const& progress)
24{
25 if (auto* window = Window::from_window_id(wm_id))
26 Core::EventLoop::current().post_event(*window, make<WMWindowStateChangedEvent>(client_id, window_id, title, rect, workspace_row, workspace_column, is_active, is_blocked, static_cast<WindowType>(window_type), is_minimized, is_frameless, progress));
27}
28
29void ConnectionToWindowManagerServer::applet_area_size_changed(i32 wm_id, Gfx::IntSize size)
30{
31 if (auto* window = Window::from_window_id(wm_id))
32 Core::EventLoop::current().post_event(*window, make<WMAppletAreaSizeChangedEvent>(size));
33}
34
35void ConnectionToWindowManagerServer::window_rect_changed(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect const& rect)
36{
37 if (auto* window = Window::from_window_id(wm_id))
38 Core::EventLoop::current().post_event(*window, make<WMWindowRectChangedEvent>(client_id, window_id, rect));
39}
40
41void ConnectionToWindowManagerServer::window_icon_bitmap_changed(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap const& bitmap)
42{
43 if (auto* window = Window::from_window_id(wm_id)) {
44 Core::EventLoop::current().post_event(*window, make<WMWindowIconBitmapChangedEvent>(client_id, window_id, bitmap.bitmap()));
45 }
46}
47
48void ConnectionToWindowManagerServer::window_removed(i32 wm_id, i32 client_id, i32 window_id)
49{
50 if (auto* window = Window::from_window_id(wm_id))
51 Core::EventLoop::current().post_event(*window, make<WMWindowRemovedEvent>(client_id, window_id));
52}
53
54void ConnectionToWindowManagerServer::super_key_pressed(i32 wm_id)
55{
56 if (auto* window = Window::from_window_id(wm_id))
57 Core::EventLoop::current().post_event(*window, make<WMSuperKeyPressedEvent>(wm_id));
58}
59
60void ConnectionToWindowManagerServer::super_space_key_pressed(i32 wm_id)
61{
62 if (auto* window = Window::from_window_id(wm_id))
63 Core::EventLoop::current().post_event(*window, make<WMSuperSpaceKeyPressedEvent>(wm_id));
64}
65
66void ConnectionToWindowManagerServer::super_d_key_pressed(i32 wm_id)
67{
68 if (auto* window = Window::from_window_id(wm_id))
69 Core::EventLoop::current().post_event(*window, make<WMSuperDKeyPressedEvent>(wm_id));
70}
71
72void ConnectionToWindowManagerServer::super_digit_key_pressed(i32 wm_id, u8 digit)
73{
74 if (auto* window = Window::from_window_id(wm_id))
75 Core::EventLoop::current().post_event(*window, make<WMSuperDigitKeyPressedEvent>(wm_id, digit));
76}
77
78void ConnectionToWindowManagerServer::workspace_changed(i32 wm_id, u32 row, u32 column)
79{
80 if (auto* window = Window::from_window_id(wm_id))
81 Core::EventLoop::current().post_event(*window, make<WMWorkspaceChangedEvent>(wm_id, row, column));
82}
83
84void ConnectionToWindowManagerServer::keymap_changed(i32 wm_id, DeprecatedString const& keymap)
85{
86 if (auto* window = Window::from_window_id(wm_id))
87 Core::EventLoop::current().post_event(*window, make<WMKeymapChangedEvent>(wm_id, keymap));
88}
89
90}