~lukas-kde/miral/shellchrome-windowinfo

« back to all changes in this revision

Viewing changes to miral-qt/src/common/debughelpers.cpp

  • Committer: Larry Price
  • Date: 2016-09-13 16:19:29 UTC
  • mto: (330.4.1 miral)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: larry.price@canonical.com-20160913161929-vs9ka1capmljq1es
Removing miral-qt from release branch, updating copyright file, and adding GPL3 license to root dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013-2015 Canonical, Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it under
5
 
 * the terms of the GNU Lesser General Public License version 3, as published by
6
 
 * the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
 
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
 * 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
 
 
17
 
#include "debughelpers.h"
18
 
#include <QTouchEvent>
19
 
 
20
 
#include <mir_toolkit/event.h>
21
 
 
22
 
// Unity API
23
 
#include <unity/shell/application/ApplicationInfoInterface.h>
24
 
 
25
 
const char *touchPointStateToString(Qt::TouchPointState state)
26
 
{
27
 
    switch (state) {
28
 
    case Qt::TouchPointPressed:
29
 
        return "pressed";
30
 
    case Qt::TouchPointMoved:
31
 
        return "moved";
32
 
    case Qt::TouchPointStationary:
33
 
        return "stationary";
34
 
    case Qt::TouchPointReleased:
35
 
        return "released";
36
 
    default:
37
 
        return "UNKNOWN!";
38
 
    }
39
 
}
40
 
 
41
 
QString touchEventToString(const QTouchEvent *ev)
42
 
{
43
 
    QString message;
44
 
 
45
 
    switch (ev->type()) {
46
 
    case QEvent::TouchBegin:
47
 
        message.append("TouchBegin ");
48
 
        break;
49
 
    case QEvent::TouchUpdate:
50
 
        message.append("TouchUpdate ");
51
 
        break;
52
 
    case QEvent::TouchEnd:
53
 
        message.append("TouchEnd ");
54
 
        break;
55
 
    case QEvent::TouchCancel:
56
 
        message.append("TouchCancel ");
57
 
        break;
58
 
    default:
59
 
        message.append("TouchUNKNOWN ");
60
 
    }
61
 
 
62
 
    for (int i=0; i < ev->touchPoints().size(); ++i) {
63
 
 
64
 
        const QTouchEvent::TouchPoint& touchPoint = ev->touchPoints().at(i);
65
 
        message.append(
66
 
            QStringLiteral("(id:%1, state:%2, scenePos:(%3,%4), pos:(%5,%6)) ")
67
 
                .arg(touchPoint.id())
68
 
                .arg(touchPointStateToString(touchPoint.state()))
69
 
                .arg(touchPoint.scenePos().x())
70
 
                .arg(touchPoint.scenePos().y())
71
 
                .arg(touchPoint.pos().x())
72
 
                .arg(touchPoint.pos().y())
73
 
            );
74
 
    }
75
 
 
76
 
    return message;
77
 
}
78
 
 
79
 
QString mirSurfaceAttribAndValueToString(MirSurfaceAttrib attrib, int value)
80
 
{
81
 
    QString str;
82
 
 
83
 
    switch (attrib) {
84
 
    case mir_surface_attrib_type:
85
 
        str = QStringLiteral("type=%1").arg(mirSurfaceTypeToStr(value));
86
 
        break;
87
 
 
88
 
    case mir_surface_attrib_state:
89
 
        str = QStringLiteral("state=%1").arg(mirSurfaceStateToStr(value));
90
 
        break;
91
 
 
92
 
    case mir_surface_attrib_swapinterval:
93
 
        str = QStringLiteral("swapinterval=%1").arg(value);
94
 
        break;
95
 
 
96
 
    case mir_surface_attrib_focus:
97
 
        str = QStringLiteral("focus=%1").arg(mirSurfaceFocusStateToStr(value));
98
 
        break;
99
 
 
100
 
    case mir_surface_attrib_dpi:
101
 
        str = QStringLiteral("dpi=%1").arg(value);
102
 
        break;
103
 
 
104
 
    case mir_surface_attrib_visibility:
105
 
        str = QStringLiteral("visibility=%1").arg(mirSurfaceVisibilityToStr(value));
106
 
        break;
107
 
    default:
108
 
        str = QStringLiteral("type'%1'=%2").arg((int)attrib).arg(value);
109
 
    }
110
 
 
111
 
    return str;
112
 
}
113
 
 
114
 
const char *mirSurfaceTypeToStr(int value)
115
 
{
116
 
    switch (value) {
117
 
    case mir_surface_type_normal:
118
 
        return "normal";
119
 
    case mir_surface_type_utility:
120
 
        return "utility";
121
 
    case mir_surface_type_dialog:
122
 
        return "dialog";
123
 
    case mir_surface_type_overlay:
124
 
        return "overlay";
125
 
    case mir_surface_type_freestyle:
126
 
        return "freestyle";
127
 
    case mir_surface_type_popover:
128
 
        return "popover";
129
 
    case mir_surface_type_inputmethod:
130
 
        return "inputmethod";
131
 
    default:
132
 
        return "???";
133
 
    }
134
 
}
135
 
 
136
 
const char *mirSurfaceStateToStr(int value)
137
 
{
138
 
    switch (value) {
139
 
    case mir_surface_state_unknown:
140
 
        return "unknown";
141
 
    case mir_surface_state_restored:
142
 
        return "restored";
143
 
    case mir_surface_state_minimized:
144
 
        return "minimized";
145
 
    case mir_surface_state_maximized:
146
 
        return "maximized";
147
 
    case mir_surface_state_vertmaximized:
148
 
        return "vertmaximized";
149
 
    case mir_surface_state_fullscreen:
150
 
        return "fullscreen";
151
 
    default:
152
 
        return "???";
153
 
    }
154
 
}
155
 
 
156
 
const char *mirSurfaceFocusStateToStr(int value)
157
 
{
158
 
    switch (value) {
159
 
    case mir_surface_unfocused:
160
 
        return "unfocused";
161
 
    case mir_surface_focused:
162
 
        return "focused";
163
 
    default:
164
 
        return "???";
165
 
    }
166
 
}
167
 
 
168
 
const char *mirSurfaceVisibilityToStr(int value)
169
 
{
170
 
    switch (value) {
171
 
    case mir_surface_visibility_occluded:
172
 
        return "occluded";
173
 
    case mir_surface_visibility_exposed:
174
 
        return "exposed";
175
 
    default:
176
 
        return "???";
177
 
    }
178
 
}
179
 
 
180
 
const char *mirTouchActionToStr(MirTouchAction action)
181
 
{
182
 
    switch (action) {
183
 
    case mir_touch_action_up:
184
 
        return "up";
185
 
    case mir_touch_action_down:
186
 
        return "down";
187
 
    case mir_touch_action_change:
188
 
        return "change";
189
 
    default:
190
 
        return "???";
191
 
    }
192
 
}
193
 
 
194
 
using namespace unity::shell::application;
195
 
 
196
 
const char *applicationStateToStr(int state)
197
 
{
198
 
    switch (state) {
199
 
    case ApplicationInfoInterface::Starting:
200
 
        return "starting";
201
 
    case ApplicationInfoInterface::Running:
202
 
        return "running";
203
 
    case ApplicationInfoInterface::Suspended:
204
 
        return "suspended";
205
 
    case ApplicationInfoInterface::Stopped:
206
 
        return "stopped";
207
 
    default:
208
 
        return "???";
209
 
    }
210
 
}
211
 
 
212
 
QString mirPointerEventToString(MirPointerEvent const* event)
213
 
{
214
 
    QString string = QStringLiteral("MirPointerEvent(x=%1,y=%2,relative_x=%3,relative_y=%4)")
215
 
        .arg(mir_pointer_event_axis_value(event, mir_pointer_axis_x))
216
 
        .arg(mir_pointer_event_axis_value(event, mir_pointer_axis_y))
217
 
        .arg(mir_pointer_event_axis_value(event, mir_pointer_axis_relative_x))
218
 
        .arg(mir_pointer_event_axis_value(event, mir_pointer_axis_relative_y));
219
 
 
220
 
    return string;
221
 
}
222
 
 
223
 
QString mirTouchEventToString(MirTouchEvent const* event)
224
 
{
225
 
    const int pointerCount = mir_touch_event_point_count(event);
226
 
 
227
 
    QString string(QStringLiteral("MirTouchEvent("));
228
 
 
229
 
    for (int i = 0; i < pointerCount; ++i) {
230
 
 
231
 
        if (i > 0) {
232
 
            string.append(",");
233
 
        }
234
 
 
235
 
        MirTouchAction touchAction = mir_touch_event_action(event, i);
236
 
 
237
 
        QString touchStr = QStringLiteral("(id=%1,action=%2,x=%3,y=%4)")
238
 
            .arg(mir_touch_event_id(event, i))
239
 
            .arg(mirTouchActionToString(touchAction))
240
 
            .arg(mir_touch_event_axis_value(event, i, mir_touch_axis_x))
241
 
            .arg(mir_touch_event_axis_value(event, i, mir_touch_axis_y));
242
 
 
243
 
        string.append(touchStr);
244
 
    }
245
 
 
246
 
    string.append(")");
247
 
 
248
 
    return string;
249
 
}
250
 
 
251
 
const char *mirTouchActionToString(MirTouchAction touchAction)
252
 
{
253
 
    switch (touchAction)
254
 
    {
255
 
    case mir_touch_action_up:
256
 
        return "up";
257
 
        break;
258
 
    case mir_touch_action_down:
259
 
        return "down";
260
 
        break;
261
 
    case mir_touch_action_change:
262
 
        return "change";
263
 
        break;
264
 
    default:
265
 
        return "???";
266
 
        break;
267
 
    }
268
 
}
269
 
 
270
 
namespace {
271
 
const char *mirKeyboardActionToString(MirKeyboardAction keyboardAction)
272
 
{
273
 
    switch (keyboardAction)
274
 
    {
275
 
    case mir_keyboard_action_up:
276
 
        return "up";
277
 
    case mir_keyboard_action_down:
278
 
        return "down";
279
 
    case mir_keyboard_action_repeat:
280
 
        return "repeat";
281
 
    default:
282
 
        return "???";
283
 
        break;
284
 
    }
285
 
}
286
 
}
287
 
 
288
 
QString mirKeyboardEventToString(MirKeyboardEvent const* event)
289
 
{
290
 
    MirKeyboardAction keyboardAction = mir_keyboard_event_action(event);
291
 
 
292
 
    xkb_keysym_t keyCode = mir_keyboard_event_key_code(event);
293
 
 
294
 
    return QStringLiteral("MirKeyboardEvent(action=%1,key_code=0x%2)")
295
 
        .arg(mirKeyboardActionToString(keyboardAction))
296
 
        .arg(keyCode, 4, 16, QLatin1Char('0'));
297
 
}
298
 
 
299
 
const char *qtCursorShapeToStr(Qt::CursorShape shape)
300
 
{
301
 
    switch(shape) {
302
 
    case Qt::ArrowCursor:
303
 
        return "Arrow";
304
 
    case Qt::UpArrowCursor:
305
 
        return "UpArrow";
306
 
    case Qt::CrossCursor:
307
 
        return "Cross";
308
 
    case Qt::WaitCursor:
309
 
        return "Wait";
310
 
    case Qt::IBeamCursor:
311
 
        return "IBeam";
312
 
    case Qt::SizeVerCursor:
313
 
        return "SizeVer";
314
 
    case Qt::SizeHorCursor:
315
 
        return "SizeHor";
316
 
    case Qt::SizeBDiagCursor:
317
 
        return "SizeBDiag";
318
 
    case Qt::SizeFDiagCursor:
319
 
        return "SizeFDiag";
320
 
    case Qt::SizeAllCursor:
321
 
        return "SizeAll";
322
 
    case Qt::BlankCursor:
323
 
        return "Blank";
324
 
    case Qt::SplitVCursor:
325
 
        return "SplitV";
326
 
    case Qt::SplitHCursor:
327
 
        return "SplitH";
328
 
    case Qt::PointingHandCursor:
329
 
        return "PointingHand";
330
 
    case Qt::ForbiddenCursor:
331
 
        return "Forbidden";
332
 
    case Qt::WhatsThisCursor:
333
 
        return "WhatsThis";
334
 
    case Qt::BusyCursor:
335
 
        return "Busy";
336
 
    case Qt::OpenHandCursor:
337
 
        return "OpenHand";
338
 
    case Qt::ClosedHandCursor:
339
 
        return "ClosedHand";
340
 
    case Qt::DragCopyCursor:
341
 
        return "DragCopy";
342
 
    case Qt::DragMoveCursor:
343
 
        return "DragMove";
344
 
    case Qt::DragLinkCursor:
345
 
        return "DragLink";
346
 
    case Qt::BitmapCursor:
347
 
        return "Bitmap";
348
 
    default:
349
 
        return "???";
350
 
    }
351
 
}