~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/client/event_printer.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
ImportĀ upstreamĀ versionĀ 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright Ā© 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
 
17
 */
 
18
 
 
19
#include "mir/event_printer.h"
 
20
#include "mir/logging/input_timestamp.h"
 
21
 
 
22
std::ostream& mir::operator<<(std::ostream& out, MirInputEventModifier modifier)
 
23
{
 
24
    bool none = true;
 
25
#define PRINT_FLAG(base,name) if ((modifier & base ## _ ## name) == base ## _ ## name)\
 
26
    {\
 
27
        if (!none) out << ' ';\
 
28
        out << # name;\
 
29
        none= false;\
 
30
    }
 
31
 
 
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";
 
50
#undef PRINT_FLAG
 
51
    return out;
 
52
}
 
53
 
 
54
#define PRINT(base,name) case base ## _ ## name: return out << #name;
 
55
 
 
56
std::ostream& mir::operator<<(std::ostream& out, MirKeyboardAction action)
 
57
{
 
58
    switch (action)
 
59
    {
 
60
    PRINT(mir_keyboard_action,up);
 
61
    PRINT(mir_keyboard_action,down);
 
62
    PRINT(mir_keyboard_action,repeat);
 
63
    default:
 
64
        return out << static_cast<int>(action) << "<INVALID>";
 
65
    }
 
66
}
 
67
 
 
68
std::ostream& mir::operator<<(std::ostream& out, MirTouchAction action)
 
69
{
 
70
    switch (action)
 
71
    {
 
72
    PRINT(mir_touch_action,up);
 
73
    PRINT(mir_touch_action,down);
 
74
    PRINT(mir_touch_action,change);
 
75
    default:
 
76
        return out << static_cast<int>(action) << "<INVALID>";
 
77
    }
 
78
}
 
79
 
 
80
std::ostream& mir::operator<<(std::ostream& out, MirTouchTooltype type)
 
81
{
 
82
    switch (type)
 
83
    {
 
84
    PRINT(mir_touch_tooltype,finger);
 
85
    PRINT(mir_touch_tooltype,stylus);
 
86
    PRINT(mir_touch_tooltype,unknown);
 
87
    default:
 
88
        return out << static_cast<int>(type) << "<INVALID>";
 
89
    }
 
90
}
 
91
 
 
92
std::ostream& mir::operator<<(std::ostream& out, MirPointerAction action)
 
93
{
 
94
    switch (action)
 
95
    {
 
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);
 
101
    default:
 
102
        return out << static_cast<int>(action) << "<INVALID>";
 
103
    }
 
104
}
 
105
 
 
106
std::ostream& mir::operator<<(std::ostream& out, MirPromptSessionState state)
 
107
{
 
108
    switch (state)
 
109
    {
 
110
    PRINT(mir_prompt_session_state,started);
 
111
    PRINT(mir_prompt_session_state,stopped);
 
112
    PRINT(mir_prompt_session_state,suspended);
 
113
    default:
 
114
        return out << static_cast<int>(state) << "<INVALID>";
 
115
    }
 
116
}
 
117
 
 
118
std::ostream& mir::operator<<(std::ostream& out, MirOrientation orientation)
 
119
{
 
120
    switch (orientation)
 
121
    {
 
122
    PRINT(mir_orientation,right);
 
123
    PRINT(mir_orientation,inverted);
 
124
    PRINT(mir_orientation,left);
 
125
    PRINT(mir_orientation,normal);
 
126
    default:
 
127
        return out << static_cast<int>(orientation) << "<INVALID>";
 
128
    }
 
129
}
 
130
 
 
131
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceAttrib attribute)
 
132
{
 
133
    switch (attribute)
 
134
    {
 
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);
 
142
    default:
 
143
        return out << static_cast<int>(attribute) << "<INVALID>";
 
144
    }
 
145
}
 
146
 
 
147
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceFocusState state)
 
148
{
 
149
    switch (state)
 
150
    {
 
151
    PRINT(mir_surface,focused);
 
152
    PRINT(mir_surface,unfocused);
 
153
    default:
 
154
        return out << static_cast<int>(state) << "<INVALID>";
 
155
    }
 
156
}
 
157
 
 
158
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceVisibility state)
 
159
{
 
160
    switch (state)
 
161
    {
 
162
    PRINT(mir_surface_visibility,exposed);
 
163
    PRINT(mir_surface_visibility,occluded);
 
164
    default:
 
165
        return out << static_cast<int>(state) << "<INVALID>";
 
166
    }
 
167
}
 
168
 
 
169
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceType type)
 
170
{
 
171
    switch (type)
 
172
    {
 
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);
 
182
    default:
 
183
        return out << static_cast<int>(type) << "<INVALID>";
 
184
    }
 
185
}
 
186
 
 
187
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceState state)
 
188
{
 
189
    switch (state)
 
190
    {
 
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);
 
199
    default:
 
200
        return out << static_cast<int>(state) << "<INVALID>";
 
201
    }
 
202
}
 
203
 
 
204
#undef PRINT
 
205
 
 
206
std::ostream& mir::operator<<(std::ostream& out, MirInputEvent const& event)
 
207
{
 
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))
 
211
    {
 
212
    case mir_input_event_type_key:
 
213
        {
 
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) << ')';
 
220
        }
 
221
    case mir_input_event_type_touch:
 
222
        {
 
223
            auto touch_event = mir_input_event_get_touch_event(&event);
 
224
            out << "touch_event(when=" << event_time << ", from=" << device_id << ", touch = {";
 
225
 
 
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) << '}';
 
236
 
 
237
            return out << ", modifiers=" << mir_touch_event_modifiers(touch_event) << ')';
 
238
        }
 
239
    case mir_input_event_type_pointer:
 
240
        {
 
241
            auto pointer_event = mir_input_event_get_pointer_event(&event);
 
242
            unsigned int button_state = 0;
 
243
 
 
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;
 
247
 
 
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) << ')';
 
255
        }
 
256
    default:
 
257
        return out << "<INVALID>";
 
258
    }
 
259
}
 
260
 
 
261
std::ostream& mir::operator<<(std::ostream& out, MirPromptSessionEvent const& event)
 
262
{
 
263
    return out << "prompt_session_event(state=" << mir_prompt_session_event_get_state(&event) << ")";
 
264
}
 
265
 
 
266
std::ostream& mir::operator<<(std::ostream& out, MirResizeEvent const& event)
 
267
{
 
268
    return out << "resize_event(state=" << mir_resize_event_get_width(&event) << "x"
 
269
        << mir_resize_event_get_height(&event) << ")";
 
270
}
 
271
 
 
272
std::ostream& mir::operator<<(std::ostream& out, MirOrientationEvent const& event)
 
273
{
 
274
    return out << "orientation_event(" << mir_orientation_event_get_direction(&event) << ")";
 
275
}
 
276
 
 
277
std::ostream& mir::operator<<(std::ostream& out, MirKeymapEvent const& event)
 
278
{
 
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") << ")";
 
287
}
 
288
 
 
289
std::ostream& mir::operator<<(std::ostream& out, MirCloseSurfaceEvent const&)
 
290
{
 
291
    return out << "close_surface_event()";
 
292
}
 
293
 
 
294
std::ostream& mir::operator<<(std::ostream& out, MirSurfaceEvent const& event)
 
295
{
 
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))
 
300
    {
 
301
    case mir_surface_attrib_type:
 
302
        out << static_cast<MirSurfaceType>(value);
 
303
        break;
 
304
    case mir_surface_attrib_state:
 
305
        out << static_cast<MirSurfaceState>(value);
 
306
        break;
 
307
    case mir_surface_attrib_swapinterval:
 
308
        out << value;
 
309
        break;
 
310
    case mir_surface_attrib_focus:
 
311
        out << static_cast<MirSurfaceFocusState>(value);
 
312
        break;
 
313
    case mir_surface_attrib_dpi:
 
314
        out << value;
 
315
        break;
 
316
    case mir_surface_attrib_visibility:
 
317
        out << static_cast<MirSurfaceVisibility>(value);
 
318
        break;
 
319
    case mir_surface_attrib_preferred_orientation:
 
320
        out << value;
 
321
        break;
 
322
    default:
 
323
        break;
 
324
    }
 
325
 
 
326
    return out << ')';
 
327
}
 
328
 
 
329
#define PRINT_EVENT(type) case mir_event_type_ ## type : return out << *mir_event_get_ ## type ## _event(&event);
 
330
 
 
331
std::ostream& mir::operator<<(std::ostream& out, MirEvent const& event)
 
332
{
 
333
    auto type = mir_event_get_type(&event);
 
334
    switch (type)
 
335
    {
 
336
        PRINT_EVENT(surface);
 
337
        PRINT_EVENT(resize);
 
338
        PRINT_EVENT(orientation);
 
339
        PRINT_EVENT(close_surface);
 
340
        PRINT_EVENT(input);
 
341
        PRINT_EVENT(keymap);
 
342
    case mir_event_type_prompt_session_state_change:
 
343
        return out << *mir_event_get_prompt_session_event(&event);
 
344
    default:
 
345
        return out << static_cast<int>(type) << "<INVALID>";
 
346
    }
 
347
}
 
348