This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx11_kiosk_window_manager.cpp
127 lines (100 loc) · 4.25 KB
/
x11_kiosk_window_manager.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright © 2016-2020 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored By: Alan Griffiths <[email protected]>
*/
#include "x11_kiosk_window_manager.h"
#include <miral/application_info.h>
#include <miral/toolkit_event.h>
#include <miral/window_info.h>
#include <miral/window_manager_tools.h>
#include <linux/input.h>
namespace ms = mir::scene;
using namespace miral;
using namespace miral::toolkit;
bool X11KioskWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event)
{
return false;
}
bool X11KioskWindowManagerPolicy::handle_touch_event(MirTouchEvent const* event)
{
auto const count = mir_touch_event_point_count(event);
long total_x = 0;
long total_y = 0;
for (auto i = 0U; i != count; ++i)
{
total_x += mir_touch_event_axis_value(event, i, mir_touch_axis_x);
total_y += mir_touch_event_axis_value(event, i, mir_touch_axis_y);
}
Point const cursor{total_x/count, total_y/count};
tools.select_active_window(tools.window_at(cursor));
return false;
}
bool X11KioskWindowManagerPolicy::handle_pointer_event(MirPointerEvent const* event)
{
auto const action = mir_pointer_event_action(event);
Point const cursor{
mir_pointer_event_axis_value(event, mir_pointer_axis_x),
mir_pointer_event_axis_value(event, mir_pointer_axis_y)};
if (action == mir_pointer_action_button_down)
{
tools.select_active_window(tools.window_at(cursor));
}
return false;
}
auto X11KioskWindowManagerPolicy::place_new_window(ApplicationInfo const& app_info, WindowSpecification const& request)
-> WindowSpecification
{
WindowSpecification specification = CanonicalWindowManagerPolicy::place_new_window(app_info, request);
if ((specification.type() == mir_window_type_normal || specification.type() == mir_window_type_freestyle) &&
(!specification.parent().is_set() || !specification.parent().value().lock()))
{
specification.state() = mir_window_state_fullscreen;
specification.size() = mir::optional_value<Size>{}; // Ignore requested size (if any) when we maximize
tools.place_and_size_for_state(specification, WindowInfo{});
if (!request.state().is_set() || request.state().value() != mir_window_state_restored)
specification.state() = request.state();
}
return specification;
}
void X11KioskWindowManagerPolicy::handle_modify_window(WindowInfo& window_info, WindowSpecification const& modifications)
{
WindowSpecification specification = modifications;
if ((window_info.type() == mir_window_type_normal || window_info.type() == mir_window_type_freestyle) &&
!window_info.parent())
{
specification.state() = mir_window_state_fullscreen;
specification.size() = mir::optional_value<Size>{}; // Ignore requested size (if any) when we maximize
tools.place_and_size_for_state(specification, window_info);
if (!modifications.state().is_set() || modifications.state().value() != mir_window_state_restored)
specification.state() = modifications.state();
}
CanonicalWindowManagerPolicy::handle_modify_window(window_info, specification);
}
void X11KioskWindowManagerPolicy::handle_request_drag_and_drop(WindowInfo& /*window_info*/)
{
}
void X11KioskWindowManagerPolicy::handle_request_move(WindowInfo& /*window_info*/, MirInputEvent const* /*input_event*/)
{
}
void X11KioskWindowManagerPolicy::handle_request_resize(WindowInfo& /*window_info*/, MirInputEvent const* /*input_event*/, MirResizeEdge /*edge*/)
{
}
Rectangle
X11KioskWindowManagerPolicy::confirm_placement_on_display(WindowInfo const& /*window_info*/, MirWindowState /*new_state*/,
Rectangle const& new_placement)
{
return new_placement;
}