56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
// Copyright (C) 2022 RozK
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#include "../events.hpp"
|
|
#include <X11/Xlib.h>
|
|
|
|
unsigned rk_events_mask = KeyPressMask | KeyReleaseMask;
|
|
extern Display * rk_display;
|
|
extern Window rk_window;
|
|
|
|
rk_uint rk_consume_events(
|
|
rk_event * events,
|
|
rk_uint max_events) {
|
|
if (!events || !max_events) {
|
|
return 0;
|
|
}
|
|
XEvent x11_event;
|
|
unsigned nevents = 0;
|
|
for ( ; nevents < max_events ; ++nevents) {
|
|
if (XCheckWindowEvent(rk_display, rk_window, rk_events_mask, &x11_event)) {
|
|
rk_event & event = events[nevents];
|
|
switch (x11_event.type) {
|
|
case KeyPress:
|
|
event.type = RK_EVENT_KEY_PRESS;
|
|
event.key.keycode = x11_event.xkey.keycode;
|
|
break;
|
|
case KeyRelease:
|
|
event.type = RK_EVENT_KEY_RELEASE;
|
|
event.key.keycode = x11_event.xkey.keycode;
|
|
break;
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
return nevents;
|
|
}
|
|
|
|
void rk_flush_events() {
|
|
XEvent x11_event;
|
|
while (XCheckWindowEvent(rk_display, rk_window, rk_events_mask, &x11_event)) {
|
|
}
|
|
}
|