GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/x11logger.cpp Lines: 0 53 0.0 %
Date: 2017-11-29 Branches: 0 125 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#ifdef USE_X11
22
23
#include "utils/x11logger.h"
24
25
#include "logger.h"
26
27
PRAGMA48(GCC diagnostic push)
28
PRAGMA48(GCC diagnostic ignored "-Wshadow")
29
#include <SDL_events.h>
30
#include <SDL_syswm.h>
31
PRAGMA48(GCC diagnostic pop)
32
33
#include "utils/cast.h"
34
#include "utils/stringutils.h"
35
36
#include "debug.h"
37
38
#define logType(val, str) \
39
    case val: \
40
        typeStr = str; \
41
        break
42
43
bool X11Logger::logEvent(const SDL_Event &event)
44
{
45
    if (event.syswm.msg->subsystem != SDL_SYSWM_X11)
46
        return false;
47
    std::string typeStr;
48
49
#ifdef USE_SDL2
50
    XEvent &xEvent = event.syswm.msg->msg.x11.event;
51
#else  // USE_SDL2
52
53
    XEvent &xEvent = event.syswm.msg->event.xevent;
54
#endif  // USE_SDL2
55
56
    const int type = xEvent.type;
57
58
    switch (type)
59
    {
60
        logType(2, strprintf("KeyPress: %u,%u %d,%d",
61
            xEvent.xkey.keycode,
62
            xEvent.xkey.state,
63
            xEvent.xkey.x,
64
            xEvent.xkey.y));
65
        logType(3, strprintf("KeyRelease: %u,%u %d,%d",
66
            xEvent.xkey.keycode,
67
            xEvent.xkey.state,
68
            xEvent.xkey.x,
69
            xEvent.xkey.y));
70
        logType(4, strprintf("ButtonPress: %u,%u %d,%d",
71
            xEvent.xbutton.button,
72
            xEvent.xbutton.state,
73
            xEvent.xbutton.x,
74
            xEvent.xbutton.y));
75
        logType(5, strprintf("ButtonRelease: %u,%u %d,%d",
76
            xEvent.xbutton.button,
77
            xEvent.xbutton.state,
78
            xEvent.xbutton.x,
79
            xEvent.xbutton.y));
80
        logType(6, strprintf("MotionNotify: %d,%u %d,%d",
81
            CAST_S32(xEvent.xmotion.is_hint),
82
            xEvent.xmotion.state,
83
            xEvent.xmotion.x,
84
            xEvent.xmotion.y));
85
        logType(7, strprintf("EnterNotify: %d,%d,%d,%u, %d,%d",
86
            xEvent.xcrossing.mode,
87
            xEvent.xcrossing.detail,
88
            xEvent.xcrossing.focus ? 1 : 0,
89
            xEvent.xcrossing.state,
90
            xEvent.xcrossing.x,
91
            xEvent.xcrossing.y));
92
        logType(8, strprintf("LeaveNotify: %d,%d,%d,%u, %d,%d",
93
            xEvent.xcrossing.mode,
94
            xEvent.xcrossing.detail,
95
            xEvent.xcrossing.focus ? 1 : 0,
96
            xEvent.xcrossing.state,
97
            xEvent.xcrossing.x,
98
            xEvent.xcrossing.y));
99
        logType(9, strprintf("FocusIn: %d,%d",
100
            xEvent.xfocus.mode,
101
            xEvent.xfocus.detail));
102
        logType(10, strprintf("FocusOut: %d,%d",
103
            xEvent.xfocus.mode,
104
            xEvent.xfocus.detail));
105
        case 11:
106
            typeStr = "KeymapNotify: ";
107
            for (int f = 0; f < 32; f ++)
108
            {
109
                typeStr.append(strprintf("%u ",
110
                    CAST_U32(xEvent.xkeymap.key_vector[f])));
111
            }
112
            break;
113
        logType(12, strprintf("Expose: %d,%d,%d,%d %d",
114
            xEvent.xexpose.x,
115
            xEvent.xexpose.y,
116
            xEvent.xexpose.width,
117
            xEvent.xexpose.height,
118
            xEvent.xexpose.count));
119
        logType(13, strprintf("GraphicsExpose: %d,%d,%d,%d %d,%d,%d",
120
            xEvent.xgraphicsexpose.x,
121
            xEvent.xgraphicsexpose.y,
122
            xEvent.xgraphicsexpose.width,
123
            xEvent.xgraphicsexpose.height,
124
            xEvent.xgraphicsexpose.count,
125
            xEvent.xgraphicsexpose.major_code,
126
            xEvent.xgraphicsexpose.minor_code));
127
        logType(14, strprintf("NoExpose: %d,%d",
128
            xEvent.xnoexpose.major_code,
129
            xEvent.xnoexpose.minor_code));
130
        logType(15, strprintf("VisibilityNotify: %d",
131
            xEvent.xvisibility.state));
132
        logType(16, strprintf("CreateNotify: %d,%d,%d,%d %d,%d",
133
            xEvent.xcreatewindow.x,
134
            xEvent.xcreatewindow.y,
135
            xEvent.xcreatewindow.width,
136
            xEvent.xcreatewindow.height,
137
            xEvent.xcreatewindow.border_width,
138
            xEvent.xcreatewindow.override_redirect ? 1 : 0));
139
        logType(17, "DestroyNotify");
140
        logType(18, strprintf("UnmapNotify: %d",
141
            xEvent.xunmap.from_configure ? 1: 0));
142
        logType(19, strprintf("MapNotify: %d",
143
            xEvent.xmap.override_redirect ? 1 : 0));
144
        logType(20, "MapRequest");
145
        logType(21, strprintf("ReparentNotify: %d,%d, %d",
146
            xEvent.xreparent.x,
147
            xEvent.xreparent.y,
148
            xEvent.xreparent.override_redirect ? 1 : 0));
149
        logType(22, strprintf("ConfigureNotify: %d,%d %d,%d %d,%d",
150
            xEvent.xconfigure.x,
151
            xEvent.xconfigure.y,
152
            xEvent.xconfigure.width,
153
            xEvent.xconfigure.height,
154
            xEvent.xconfigure.border_width,
155
            xEvent.xconfigure.override_redirect ? 1 : 0));
156
        logType(23, strprintf("ConfigureRequest: %d,%d %d,%d %d,%d",
157
            xEvent.xconfigurerequest.x,
158
            xEvent.xconfigurerequest.y,
159
            xEvent.xconfigurerequest.width,
160
            xEvent.xconfigurerequest.height,
161
            xEvent.xconfigurerequest.border_width,
162
            xEvent.xconfigurerequest.detail));
163
        logType(24, strprintf("GravityNotify: %d,%d",
164
            xEvent.xgravity.x,
165
            xEvent.xgravity.y));
166
        logType(25, strprintf("ResizeRequest: %d,%d",
167
            xEvent.xresizerequest.width,
168
            xEvent.xresizerequest.height));
169
        logType(26, strprintf("CirculateNotify: %d",
170
            xEvent.xcirculate.place));
171
        logType(27, strprintf("CirculateRequest: %d",
172
            xEvent.xcirculaterequest.place));
173
        logType(28, strprintf("PropertyNotify: %u, %d",
174
            CAST_U32(xEvent.xproperty.atom),
175
            xEvent.xproperty.state));
176
        logType(29, strprintf("SelectionClear: %u",
177
            CAST_U32(xEvent.xselectionclear.selection)));
178
        logType(30, strprintf("SelectionRequest: %u,%u,%u",
179
            CAST_U32(xEvent.xselectionrequest.selection),
180
            CAST_U32(xEvent.xselectionrequest.target),
181
            CAST_U32(xEvent.xselectionrequest.property)));
182
        logType(31, strprintf("SelectionNotify: %u,%u,%u",
183
            CAST_U32(xEvent.xselection.selection),
184
            CAST_U32(xEvent.xselection.target),
185
            CAST_U32(xEvent.xselection.property)));
186
        logType(32, strprintf("ColormapNotify: %u,%d",
187
            CAST_U32(xEvent.xcolormap.colormap),
188
//            xEvent.xcolormap.new ? 1 : 0,
189
            xEvent.xcolormap.state));
190
        case 33:
191
            typeStr = strprintf("ClientMessage: %u,%d (",
192
                CAST_U32(xEvent.xclient.message_type),
193
                xEvent.xclient.format);
194
            for (int f = 0; f < 20; f ++)
195
                typeStr.append(strprintf("%c", xEvent.xclient.data.b[f]));
196
            typeStr.append(")");
197
            break;
198
        logType(34, strprintf("MappingNotify: %d,%d,%d",
199
            xEvent.xmapping.request,
200
            xEvent.xmapping.first_keycode,
201
            xEvent.xmapping.count));
202
        logType(35, "GenericEvent");
203
        default:
204
            typeStr = strprintf("Unknown: %d", type);
205
            break;
206
    }
207
208
    logger->log("event: SDL_SYSWMEVENT: X11: %s",
209
        typeStr.c_str());
210
    return true;
211
}
212
213
#endif  // USE_X11