| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 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 "ShellSurfaceXdgShellUnstableV6.h" |
| 10 |
|
| 11 |
#include "Registry.h" |
| 12 |
#include "messaging/ApplicationMessenger.h" |
| 13 |
|
| 14 |
using namespace KODI::WINDOWING::WAYLAND; |
| 15 |
|
| 16 |
namespace |
| 17 |
{ |
| 18 |
|
| 19 |
IShellSurface::State ConvertStateFlag(wayland::zxdg_toplevel_v6_state flag) |
| 20 |
{ |
| 21 |
switch(flag) |
| 22 |
{ |
| 23 |
case wayland::zxdg_toplevel_v6_state::activated: |
| 24 |
return IShellSurface::STATE_ACTIVATED; |
| 25 |
case wayland::zxdg_toplevel_v6_state::fullscreen: |
| 26 |
return IShellSurface::STATE_FULLSCREEN; |
| 27 |
case wayland::zxdg_toplevel_v6_state::maximized: |
| 28 |
return IShellSurface::STATE_MAXIMIZED; |
| 29 |
case wayland::zxdg_toplevel_v6_state::resizing: |
| 30 |
return IShellSurface::STATE_RESIZING; |
| 31 |
default: |
| 32 |
throw std::runtime_error(std::string("Unknown xdg_toplevel state flag ") + std::to_string(static_cast<std::underlying_type<decltype(flag)>::type> (flag))); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
CShellSurfaceXdgShellUnstableV6* CShellSurfaceXdgShellUnstableV6::TryCreate(IShellSurfaceHandler& handler, CConnection& connection, const wayland::surface_t& surface, std::string const& title, std::string const& class_) |
| 39 |
{ |
| 40 |
wayland::zxdg_shell_v6_t shell; |
| 41 |
CRegistry registry{connection}; |
| 42 |
registry.RequestSingleton(shell, 1, 1, false); |
| 43 |
registry.Bind(); |
| 44 |
|
| 45 |
if (shell) |
| 46 |
{ |
| 47 |
return new CShellSurfaceXdgShellUnstableV6(handler, connection.GetDisplay(), shell, surface, title, class_); |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
return nullptr; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
CShellSurfaceXdgShellUnstableV6::CShellSurfaceXdgShellUnstableV6(IShellSurfaceHandler& handler, wayland::display_t& display, const wayland::zxdg_shell_v6_t& shell, const wayland::surface_t& surface, std::string const& title, std::string const& app_id) |
| 56 |
: m_handler{handler}, m_display{display}, m_shell{shell}, m_surface{surface}, m_xdgSurface{m_shell.get_xdg_surface(m_surface)}, m_xdgToplevel{m_xdgSurface.get_toplevel()} |
| 57 |
{ |
| 58 |
m_shell.on_ping() = [this](std::uint32_t serial) |
| 59 |
{ |
| 60 |
m_shell.pong(serial); |
| 61 |
}; |
| 62 |
m_xdgSurface.on_configure() = [this](std::uint32_t serial) |
| 63 |
{ |
| 64 |
m_handler.OnConfigure(serial, m_configuredSize, m_configuredState); |
| 65 |
}; |
| 66 |
m_xdgToplevel.on_close() = [this]() |
| 67 |
{ |
| 68 |
m_handler.OnClose(); |
| 69 |
}; |
| 70 |
m_xdgToplevel.on_configure() = |
| 71 |
[this](std::int32_t width, std::int32_t height, |
| 72 |
const std::vector<wayland::zxdg_toplevel_v6_state>& states) { |
| 73 |
m_configuredSize.Set(width, height); |
| 74 |
m_configuredState.reset(); |
| 75 |
for (auto state : states) |
| 76 |
{ |
| 77 |
m_configuredState.set(ConvertStateFlag(state)); |
| 78 |
} |
| 79 |
}; |
| 80 |
m_xdgToplevel.set_app_id(app_id); |
| 81 |
m_xdgToplevel.set_title(title); |
| 82 |
// Set sensible minimum size |
| 83 |
m_xdgToplevel.set_min_size(300, 200); |
| 84 |
} |
| 85 |
|
| 86 |
void CShellSurfaceXdgShellUnstableV6::Initialize() |
| 87 |
{ |
| 88 |
// Commit surface to confirm role |
| 89 |
// Don't do it in constructor since SetFullScreen might be called before |
| 90 |
m_surface.commit(); |
| 91 |
// Make sure we get the initial configure before continuing |
| 92 |
m_display.roundtrip(); |
| 93 |
} |
| 94 |
|
| 95 |
void CShellSurfaceXdgShellUnstableV6::AckConfigure(std::uint32_t serial) |
| 96 |
{ |
| 97 |
m_xdgSurface.ack_configure(serial); |
| 98 |
} |
| 99 |
|
| 100 |
CShellSurfaceXdgShellUnstableV6::~CShellSurfaceXdgShellUnstableV6() noexcept |
| 101 |
{ |
| 102 |
// xdg_shell is picky: must destroy toplevel role before surface |
| 103 |
m_xdgToplevel.proxy_release(); |
| 104 |
m_xdgSurface.proxy_release(); |
| 105 |
} |
| 106 |
|
| 107 |
void CShellSurfaceXdgShellUnstableV6::SetFullScreen(const wayland::output_t& output, float) |
| 108 |
{ |
| 109 |
// xdg_shell does not support refresh rate setting at the moment |
| 110 |
m_xdgToplevel.set_fullscreen(output); |
| 111 |
} |
| 112 |
|
| 113 |
void CShellSurfaceXdgShellUnstableV6::SetWindowed() |
| 114 |
{ |
| 115 |
m_xdgToplevel.unset_fullscreen(); |
| 116 |
} |
| 117 |
|
| 118 |
void CShellSurfaceXdgShellUnstableV6::SetMaximized() |
| 119 |
{ |
| 120 |
m_xdgToplevel.set_maximized(); |
| 121 |
} |
| 122 |
|
| 123 |
void CShellSurfaceXdgShellUnstableV6::UnsetMaximized() |
| 124 |
{ |
| 125 |
m_xdgToplevel.unset_maximized(); |
| 126 |
} |
| 127 |
|
| 128 |
void CShellSurfaceXdgShellUnstableV6::SetMinimized() |
| 129 |
{ |
| 130 |
m_xdgToplevel.set_minimized(); |
| 131 |
} |
| 132 |
|
| 133 |
void CShellSurfaceXdgShellUnstableV6::SetWindowGeometry(CRectInt geometry) |
| 134 |
{ |
| 135 |
m_xdgSurface.set_window_geometry(geometry.x1, geometry.y1, geometry.Width(), geometry.Height()); |
| 136 |
} |
| 137 |
|
| 138 |
void CShellSurfaceXdgShellUnstableV6::StartMove(const wayland::seat_t& seat, std::uint32_t serial) |
| 139 |
{ |
| 140 |
m_xdgToplevel.move(seat, serial); |
| 141 |
} |
| 142 |
|
| 143 |
void CShellSurfaceXdgShellUnstableV6::StartResize(const wayland::seat_t& seat, std::uint32_t serial, wayland::shell_surface_resize edge) |
| 144 |
{ |
| 145 |
// wl_shell shell_surface_resize is identical to xdg_shell resize_edge |
| 146 |
m_xdgToplevel.resize(seat, serial, static_cast<std::uint32_t> (edge)); |
| 147 |
} |
| 148 |
|
| 149 |
void CShellSurfaceXdgShellUnstableV6::ShowShellContextMenu(const wayland::seat_t& seat, std::uint32_t serial, CPointInt position) |
| 150 |
{ |
| 151 |
m_xdgToplevel.show_window_menu(seat, serial, position.x, position.y); |
| 152 |
} |