summaryrefslogtreecommitdiffstats
path: root/xbmc/windowing/wayland/ShellSurfaceWlShell.cpp
blob: 2c91858c8b44945ef413c4dfd8de80baee61fcad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 *  Copyright (C) 2017-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "ShellSurfaceWlShell.h"

#include "Registry.h"

#include <cmath>

using namespace KODI::WINDOWING::WAYLAND;
using namespace std::placeholders;

CShellSurfaceWlShell::CShellSurfaceWlShell(IShellSurfaceHandler& handler,
                                           CConnection& connection,
                                           const wayland::surface_t& surface,
                                           const std::string& title,
                                           const std::string& class_)
  : m_handler{handler}
{
  {
    CRegistry registry{connection};
    registry.RequestSingleton(m_shell, 1, 1);
    registry.Bind();
  }

  m_shellSurface = m_shell.get_shell_surface(surface);

  m_surfaceState.set(STATE_ACTIVATED);
  m_shellSurface.set_class(class_);
  m_shellSurface.set_title(title);
  m_shellSurface.on_ping() = [this](std::uint32_t serial)
  {
    m_shellSurface.pong(serial);
  };
  m_shellSurface.on_configure() = [this](const wayland::shell_surface_resize&, std::int32_t width,
                                         std::int32_t height) {
    // wl_shell does not have serials
    m_handler.OnConfigure(0, {width, height}, m_surfaceState);
  };
}

void CShellSurfaceWlShell::AckConfigure(std::uint32_t)
{
}

void CShellSurfaceWlShell::Initialize()
{
  // Nothing to do here - constructor already handles it
  // This is not a problem since the constructor is guaranteed not to call
  // handler functions since the event loop is not running.
}

void CShellSurfaceWlShell::SetFullScreen(const wayland::output_t& output, float refreshRate)
{
  m_shellSurface.set_fullscreen(wayland::shell_surface_fullscreen_method::driver, std::round(refreshRate * 1000.0f), output);
  m_surfaceState.set(STATE_FULLSCREEN);
}

void CShellSurfaceWlShell::SetWindowed()
{
  m_shellSurface.set_toplevel();
  m_surfaceState.reset(STATE_FULLSCREEN);
}

void CShellSurfaceWlShell::SetMaximized()
{
  m_shellSurface.set_maximized(wayland::output_t());
  m_surfaceState.set(STATE_MAXIMIZED);
}

void CShellSurfaceWlShell::UnsetMaximized()
{
  m_surfaceState.reset(STATE_MAXIMIZED);
}

void CShellSurfaceWlShell::SetMinimized()
{
}

void CShellSurfaceWlShell::SetWindowGeometry(CRectInt)
{
}

void CShellSurfaceWlShell::StartMove(const wayland::seat_t& seat, std::uint32_t serial)
{
  m_shellSurface.move(seat, serial);
}

void CShellSurfaceWlShell::StartResize(const wayland::seat_t& seat, std::uint32_t serial, wayland::shell_surface_resize edge)
{
  m_shellSurface.resize(seat, serial, edge);
}

void CShellSurfaceWlShell::ShowShellContextMenu(const wayland::seat_t&, std::uint32_t, CPointInt)
{
}