File indexing completed on 2024-11-10 04:56:34
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2018 Martin Flöser <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <xcb/xcb.h> 0012 0013 #include <cstring> 0014 0015 namespace KWin 0016 { 0017 0018 class GeEventMemMover 0019 { 0020 public: 0021 GeEventMemMover(xcb_generic_event_t *event) 0022 : m_event(reinterpret_cast<xcb_ge_generic_event_t *>(event)) 0023 { 0024 // xcb event structs contain stuff that wasn't on the wire, the full_sequence field 0025 // adds an extra 4 bytes and generic events cookie data is on the wire right after the standard 32 bytes. 0026 // Move this data back to have the same layout in memory as it was on the wire 0027 // and allow casting, overwriting the full_sequence field. 0028 memmove((char *)m_event + 32, (char *)m_event + 36, m_event->length * 4); 0029 } 0030 ~GeEventMemMover() 0031 { 0032 // move memory layout back, so that Qt can do the same without breaking 0033 memmove((char *)m_event + 36, (char *)m_event + 32, m_event->length * 4); 0034 } 0035 0036 xcb_ge_generic_event_t *operator->() const 0037 { 0038 return m_event; 0039 } 0040 0041 private: 0042 xcb_ge_generic_event_t *m_event; 0043 }; 0044 0045 }