File indexing completed on 2024-02-18 16:20:15

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "syncalarmx11filter.h"
0011 #include "utils/xcbutils.h"
0012 #include "workspace.h"
0013 #include "x11window.h"
0014 
0015 namespace KWin
0016 {
0017 
0018 SyncAlarmX11Filter::SyncAlarmX11Filter()
0019     : X11EventFilter(QVector<int>{Xcb::Extensions::self()->syncAlarmNotifyEvent()})
0020 {
0021 }
0022 
0023 bool SyncAlarmX11Filter::event(xcb_generic_event_t *event)
0024 {
0025     auto alarmEvent = reinterpret_cast<xcb_sync_alarm_notify_event_t *>(event);
0026     auto client = workspace()->findClient([alarmEvent](const X11Window *client) {
0027         const auto syncRequest = client->syncRequest();
0028         return alarmEvent->alarm == syncRequest.alarm && alarmEvent->counter_value.hi == syncRequest.value.hi && alarmEvent->counter_value.lo == syncRequest.value.lo;
0029     });
0030     if (client) {
0031         client->handleSync();
0032     }
0033     return false;
0034 }
0035 
0036 } // namespace KWin