Debian Codegraph @

xbmc/windowing/wayland/ShellSurfaceWebOSShell.cpp

raw
1 /*
2 * Copyright (C) 2017-2023 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "ShellSurfaceWebOSShell.h"
10
11 #include "CompileInfo.h"
12 #include "Registry.h"
13 #include "platform/Environment.h"
14 #include "utils/log.h"
15
16 using namespace KODI::WINDOWING::WAYLAND;
17 using namespace std::placeholders;
18
19 using namespace wayland;
20
21 CShellSurfaceWebOSShell::CShellSurfaceWebOSShell(IShellSurfaceHandler& handler,
22 CConnection& connection,
23 const wayland::surface_t& surface,
24 const std::string& title,
25 const std::string& className)
26 : m_handler{handler}
27 {
28 {
29 CRegistry registry{connection};
30 registry.RequestSingleton(m_shell, 1, 1);
31 registry.RequestSingleton(m_webos_shell, 1, 2);
32 registry.Bind();
33 }
34
35 m_shellSurface = m_shell.get_shell_surface(surface);
36
37 m_webos_shellSurface = m_webos_shell.get_shell_surface(surface);
38
39 m_webos_shellSurface.on_exposed() = [this](const std::vector<std::int32_t>& rect) {
40 if (rect.size() >= 4)
41 m_windowSize = {rect[2], rect[3]};
42 };
43
44 m_webos_shellSurface.on_state_changed() = [this](std::uint32_t state) {
45 switch (static_cast<webos_shell_surface_state>(state))
46 {
47 case webos_shell_surface_state::fullscreen:
48 CLog::Log(LOGDEBUG, "CShellSurfaceWebOSShell: State changed to full screen");
49 m_surfaceState.reset();
50 m_surfaceState.set(STATE_ACTIVATED);
51 m_surfaceState.set(STATE_FULLSCREEN);
52 m_handler.OnConfigure(0, m_windowSize, m_surfaceState);
53 break;
54 case webos_shell_surface_state::maximized:
55 CLog::Log(LOGDEBUG, "CShellSurfaceWebOSShell: State changed to maximized");
56 m_surfaceState.reset();
57 m_surfaceState.set(STATE_ACTIVATED);
58 m_surfaceState.set(STATE_MAXIMIZED);
59 m_handler.OnConfigure(0, m_windowSize, m_surfaceState);
60 break;
61 case webos_shell_surface_state::minimized:
62 CLog::Log(LOGDEBUG, "CShellSurfaceWebOSShell: State changed to minimized");
63 m_surfaceState.reset();
64 m_handler.OnConfigure(0, m_windowSize, m_surfaceState);
65 break;
66 case webos_shell_surface_state::_default:
67 CLog::Log(LOGDEBUG, "CShellSurfaceWebOSShell: State changed to default (windowed)");
68 m_surfaceState.reset();
69 m_surfaceState.set(STATE_ACTIVATED);
70 break;
71 }
72 };
73
74 m_webos_shellSurface.on_close() = [this]() {
75 CLog::Log(LOGDEBUG, "CShellSurfaceWebOSShell: Close notification received");
76 m_handler.OnClose();
77 };
78
79 std::string appId = CEnvironment::getenv("APP_ID");
80 if (appId.empty())
81 {
82 appId = CCompileInfo::GetPackage();
83 }
84
85 std::string displayId = CEnvironment::getenv("DISPLAY_ID");
86 if (displayId.empty())
87 {
88 displayId = "0";
89 }
90
91 CLog::Log(LOGDEBUG, "Passing appId {} and displayAffinity {} to wl_webos_shell", appId,
92 displayId);
93 m_webos_shellSurface.set_property("appId", appId);
94 m_webos_shellSurface.set_property("displayAffinity", displayId);
95
96 // Allow the back button the LG remote to be passed to Kodi and not intercepted
97 m_webos_shellSurface.set_property("_WEBOS_ACCESS_POLICY_KEYS_BACK", "true");
98
99 m_shellSurface.set_class(className);
100 m_shellSurface.set_title(title);
101 }
102
103 void CShellSurfaceWebOSShell::SetFullScreen(const wayland::output_t& output, float refreshRate)
104 {
105 m_webos_shellSurface.set_state(static_cast<std::uint32_t>(webos_shell_surface_state::fullscreen));
106 }
107
108 void CShellSurfaceWebOSShell::SetWindowed()
109 {
110 m_shellSurface.set_toplevel();
111 }
112
113 void CShellSurfaceWebOSShell::SetMaximized()
114 {
115 m_webos_shellSurface.set_state(static_cast<std::uint32_t>(webos_shell_surface_state::maximized));
116 }
117
118 void CShellSurfaceWebOSShell::UnsetMaximized()
119 {
120 }
121
122 void CShellSurfaceWebOSShell::SetMinimized()
123 {
124 m_webos_shellSurface.set_state(static_cast<std::uint32_t>(webos_shell_surface_state::minimized));
125 }
126
127 void CShellSurfaceWebOSShell::StartMove(const wayland::seat_t& seat, std::uint32_t serial)
128 {
129 m_shellSurface.move(seat, serial);
130 }
131
132 void CShellSurfaceWebOSShell::StartResize(const wayland::seat_t& seat,
133 std::uint32_t serial,
134 wayland::shell_surface_resize edge)
135 {
136 m_shellSurface.resize(seat, serial, edge);
137 }