GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/x11logger.cpp Lines: 0 49 0.0 %
Date: 2021-03-17 Branches: 0 125 0.0 %

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