2
* Copyright Ā© 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
19
#include "mir/event_printer.h"
20
#include "mir/logging/input_timestamp.h"
22
std::ostream& mir::operator<<(std::ostream& out, MirInputEventModifier modifier)
25
#define PRINT_FLAG(base,name) if ((modifier & base ## _ ## name) == base ## _ ## name)\
27
if (!none) out << ' ';\
32
PRINT_FLAG(mir_input_event_modifier, alt);
33
PRINT_FLAG(mir_input_event_modifier, alt_right);
34
PRINT_FLAG(mir_input_event_modifier, alt_left);
35
PRINT_FLAG(mir_input_event_modifier, shift);
36
PRINT_FLAG(mir_input_event_modifier, shift_left);
37
PRINT_FLAG(mir_input_event_modifier, shift_right);
38
PRINT_FLAG(mir_input_event_modifier, sym);
39
PRINT_FLAG(mir_input_event_modifier, function);
40
PRINT_FLAG(mir_input_event_modifier, ctrl);
41
PRINT_FLAG(mir_input_event_modifier, ctrl_left);
42
PRINT_FLAG(mir_input_event_modifier, ctrl_right);
43
PRINT_FLAG(mir_input_event_modifier, meta);
44
PRINT_FLAG(mir_input_event_modifier, meta_left);
45
PRINT_FLAG(mir_input_event_modifier, meta_right);
46
PRINT_FLAG(mir_input_event_modifier, caps_lock);
47
PRINT_FLAG(mir_input_event_modifier, num_lock);
48
PRINT_FLAG(mir_input_event_modifier, scroll_lock);
49
if (none) out << "none";
54
#define PRINT(base,name) case base ## _ ## name: return out << #name;
56
std::ostream& mir::operator<<(std::ostream& out, MirKeyboardAction action)
60
PRINT(mir_keyboard_action,up);
61
PRINT(mir_keyboard_action,down);
62
PRINT(mir_keyboard_action,repeat);
64
return out << static_cast<int>(action) << "<INVALID>";
68
std::ostream& mir::operator<<(std::ostream& out, MirTouchAction action)
72
PRINT(mir_touch_action,up);
73
PRINT(mir_touch_action,down);
74
PRINT(mir_touch_action,change);
76
return out << static_cast<int>(action) << "<INVALID>";
80
std::ostream& mir::operator<<(std::ostream& out, MirTouchTooltype type)
84
PRINT(mir_touch_tooltype,finger);
85
PRINT(mir_touch_tooltype,stylus);
86
PRINT(mir_touch_tooltype,unknown);
88
return out << static_cast<int>(type) << "<INVALID>";
92
std::ostream& mir::operator<<(std::ostream& out, MirPointerAction action)
96
PRINT(mir_pointer_action,button_up);
97
PRINT(mir_pointer_action,button_down);
98
PRINT(mir_pointer_action,enter);
99
PRINT(mir_pointer_action,leave);
100
PRINT(mir_pointer_action,motion);
102
return out << static_cast<int>(action) << "<INVALID>";
106
std::ostream& mir::operator<<(std::ostream& out, MirPromptSessionState state)
110
PRINT(mir_prompt_session_state,started);
111
PRINT(mir_prompt_session_state,stopped);
112
PRINT(mir_prompt_session_state,suspended);
114
return out << static_cast<int>(state) << "<INVALID>";
118
std::ostream& mir::operator<<(std::ostream& out, MirOrientation orientation)
122
PRINT(mir_orientation,right);
123
PRINT(mir_orientation,inverted);
124
PRINT(mir_orientation,left);
125
PRINT(mir_orientation,normal);
127
return out << static_cast<int>(orientation) << "<INVALID>";
131
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceAttrib attribute)
135
PRINT(mir_surface_attrib,type);
136
PRINT(mir_surface_attrib,dpi);
137
PRINT(mir_surface_attrib,focus);
138
PRINT(mir_surface_attrib,state);
139
PRINT(mir_surface_attrib,visibility);
140
PRINT(mir_surface_attrib,swapinterval);
141
PRINT(mir_surface_attrib,preferred_orientation);
143
return out << static_cast<int>(attribute) << "<INVALID>";
147
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceFocusState state)
151
PRINT(mir_surface,focused);
152
PRINT(mir_surface,unfocused);
154
return out << static_cast<int>(state) << "<INVALID>";
158
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceVisibility state)
162
PRINT(mir_surface_visibility,exposed);
163
PRINT(mir_surface_visibility,occluded);
165
return out << static_cast<int>(state) << "<INVALID>";
169
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceType type)
173
PRINT(mir_surface_type,normal);
174
PRINT(mir_surface_type,utility);
175
PRINT(mir_surface_type,dialog);
176
PRINT(mir_surface_type,gloss);
177
PRINT(mir_surface_type,freestyle);
178
PRINT(mir_surface_type,menu);
179
PRINT(mir_surface_type,inputmethod);
180
PRINT(mir_surface_type,satellite);
181
PRINT(mir_surface_type,tip);
183
return out << static_cast<int>(type) << "<INVALID>";
187
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceState state)
191
PRINT(mir_surface_state,unknown);
192
PRINT(mir_surface_state,restored);
193
PRINT(mir_surface_state,minimized);
194
PRINT(mir_surface_state,maximized);
195
PRINT(mir_surface_state,vertmaximized);
196
PRINT(mir_surface_state,fullscreen);
197
PRINT(mir_surface_state,horizmaximized);
198
PRINT(mir_surface_state,hidden);
200
return out << static_cast<int>(state) << "<INVALID>";
206
std::ostream& mir::operator<<(std::ostream& out, MirInputEvent const& event)
208
auto event_time = mir::logging::input_timestamp(std::chrono::nanoseconds(mir_input_event_get_event_time(&event)));
209
auto device_id = mir_input_event_get_device_id(&event);
210
switch (mir_input_event_get_type(&event))
212
case mir_input_event_type_key:
214
auto key_event = mir_input_event_get_keyboard_event(&event);
215
return out << "key_event(when=" << event_time << ", from=" << device_id << ", "
216
<< mir_keyboard_event_action(key_event)
217
<< ", code=" << mir_keyboard_event_key_code(key_event)
218
<< ", scan=" << mir_keyboard_event_scan_code(key_event) << ", modifiers=" << std::hex
219
<< mir_keyboard_event_modifiers(key_event) << ')';
221
case mir_input_event_type_touch:
223
auto touch_event = mir_input_event_get_touch_event(&event);
224
out << "touch_event(when=" << event_time << ", from=" << device_id << ", touch = {";
226
for (unsigned int index = 0, count = mir_touch_event_point_count(touch_event); index != count; ++index)
227
out << "{id=" << mir_touch_event_id(touch_event, index)
228
<< ", action=" << mir_touch_event_action(touch_event, index)
229
<< ", tool=" << mir_touch_event_tooltype(touch_event, index)
230
<< ", x=" << mir_touch_event_axis_value(touch_event, index, mir_touch_axis_x)
231
<< ", y=" << mir_touch_event_axis_value(touch_event, index, mir_touch_axis_y)
232
<< ", pressure=" << mir_touch_event_axis_value(touch_event, index, mir_touch_axis_pressure)
233
<< ", major=" << mir_touch_event_axis_value(touch_event, index, mir_touch_axis_touch_major)
234
<< ", minor=" << mir_touch_event_axis_value(touch_event, index, mir_touch_axis_touch_minor)
235
<< ", size=" << mir_touch_event_axis_value(touch_event, index, mir_touch_axis_size) << '}';
237
return out << ", modifiers=" << mir_touch_event_modifiers(touch_event) << ')';
239
case mir_input_event_type_pointer:
241
auto pointer_event = mir_input_event_get_pointer_event(&event);
242
unsigned int button_state = 0;
244
for (auto const a : {mir_pointer_button_primary, mir_pointer_button_secondary, mir_pointer_button_tertiary,
245
mir_pointer_button_back, mir_pointer_button_forward})
246
button_state |= mir_pointer_event_button_state(pointer_event, a) ? a : 0;
248
return out << "pointer_event(when=" << event_time << ", from=" << device_id << ", "
249
<< mir_pointer_event_action(pointer_event) << ", button_state=" << button_state
250
<< ", x=" << mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x)
251
<< ", y=" << mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y)
252
<< ", vscroll=" << mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_vscroll)
253
<< ", hscroll=" << mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll)
254
<< ", modifiers=" << mir_pointer_event_modifiers(pointer_event) << ')';
257
return out << "<INVALID>";
261
std::ostream& mir::operator<<(std::ostream& out, MirPromptSessionEvent const& event)
263
return out << "prompt_session_event(state=" << mir_prompt_session_event_get_state(&event) << ")";
266
std::ostream& mir::operator<<(std::ostream& out, MirResizeEvent const& event)
268
return out << "resize_event(state=" << mir_resize_event_get_width(&event) << "x"
269
<< mir_resize_event_get_height(&event) << ")";
272
std::ostream& mir::operator<<(std::ostream& out, MirOrientationEvent const& event)
274
return out << "orientation_event(" << mir_orientation_event_get_direction(&event) << ")";
277
std::ostream& mir::operator<<(std::ostream& out, MirKeymapEvent const& event)
279
xkb_rule_names names;
280
mir_keymap_event_get_rules(&event, &names);
281
return out << "keymap_event("
282
<< (names.rules?names.rules:"default rules") << ", "
283
<< (names.model?names.model:"default model") << ", "
284
<< (names.layout?names.layout:"default layout") << ", "
285
<< (names.variant?names.variant:"no variant") << ", "
286
<< (names.options?names.options:"no options") << ")";
289
std::ostream& mir::operator<<(std::ostream& out, MirCloseSurfaceEvent const&)
291
return out << "close_surface_event()";
294
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceEvent const& event)
296
out << "surface_event("
297
<< mir_surface_event_get_attribute(&event)<< '=';
298
auto value = mir_surface_event_get_attribute_value(&event);
299
switch (mir_surface_event_get_attribute(&event))
301
case mir_surface_attrib_type:
302
out << static_cast<MirSurfaceType>(value);
304
case mir_surface_attrib_state:
305
out << static_cast<MirSurfaceState>(value);
307
case mir_surface_attrib_swapinterval:
310
case mir_surface_attrib_focus:
311
out << static_cast<MirSurfaceFocusState>(value);
313
case mir_surface_attrib_dpi:
316
case mir_surface_attrib_visibility:
317
out << static_cast<MirSurfaceVisibility>(value);
319
case mir_surface_attrib_preferred_orientation:
329
#define PRINT_EVENT(type) case mir_event_type_ ## type : return out << *mir_event_get_ ## type ## _event(&event);
331
std::ostream& mir::operator<<(std::ostream& out, MirEvent const& event)
333
auto type = mir_event_get_type(&event);
336
PRINT_EVENT(surface);
338
PRINT_EVENT(orientation);
339
PRINT_EVENT(close_surface);
342
case mir_event_type_prompt_session_state_change:
343
return out << *mir_event_get_prompt_session_event(&event);
345
return out << static_cast<int>(type) << "<INVALID>";