Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/x11/common/ge_event_mem_mover.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2018 Martin Flöser <mgraesslin@kde.org> | ||||
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 | (at your option) 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 | #pragma once | ||||
21 | | ||||
22 | #include <xcb/xcb.h> | ||||
23 | | ||||
24 | #include <string.h> | ||||
25 | | ||||
26 | namespace KWin | ||||
27 | { | ||||
28 | | ||||
29 | class GeEventMemMover | ||||
30 | { | ||||
31 | public: | ||||
32 | GeEventMemMover(xcb_generic_event_t *event) | ||||
33 | : m_event(reinterpret_cast<xcb_ge_generic_event_t *>(event)) | ||||
34 | { | ||||
35 | // xcb event structs contain stuff that wasn't on the wire, the full_sequence field | ||||
36 | // adds an extra 4 bytes and generic events cookie data is on the wire right after the standard 32 bytes. | ||||
37 | // Move this data back to have the same layout in memory as it was on the wire | ||||
38 | // and allow casting, overwriting the full_sequence field. | ||||
39 | memmove((char*) m_event + 32, (char*) m_event + 36, m_event->length * 4); | ||||
40 | } | ||||
41 | ~GeEventMemMover() | ||||
42 | { | ||||
43 | // move memory layout back, so that Qt can do the same without breaking | ||||
44 | memmove((char*) m_event + 36, (char *) m_event + 32, m_event->length * 4); | ||||
45 | } | ||||
46 | | ||||
47 | xcb_ge_generic_event_t *operator->() const { | ||||
48 | return m_event; | ||||
49 | } | ||||
50 | | ||||
51 | private: | ||||
52 | xcb_ge_generic_event_t *m_event; | ||||
53 | }; | ||||
54 | | ||||
55 | } |