2020-04-01 19:52:12 +00:00
|
|
|
#pragma once
|
2020-07-06 17:31:40 +00:00
|
|
|
#ifndef MANGOHUD_KEYBINDS_H
|
|
|
|
#define MANGOHUD_KEYBINDS_H
|
|
|
|
|
2020-09-06 09:41:31 +00:00
|
|
|
#ifdef HAVE_X11
|
2020-04-01 19:52:12 +00:00
|
|
|
#include "shared_x11.h"
|
|
|
|
#include "loaders/loader_x11.h"
|
2020-09-06 09:41:31 +00:00
|
|
|
#endif
|
2024-02-19 12:59:51 +00:00
|
|
|
#ifdef HAVE_WAYLAND
|
|
|
|
#include "wayland_hook.h"
|
|
|
|
#endif
|
2020-04-01 19:52:12 +00:00
|
|
|
|
|
|
|
#ifndef KeySym
|
|
|
|
typedef unsigned long KeySym;
|
|
|
|
#endif
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
#if defined(HAVE_X11) || defined(HAVE_WAYLAND)
|
|
|
|
static inline bool keys_are_pressed(const std::vector<KeySym>& keys)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_WAYLAND)
|
|
|
|
if(wl_display_ptr && wl_handle)
|
|
|
|
{
|
|
|
|
update_wl_queue();
|
2020-01-28 04:11:05 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
if(wl_pressed_keys.size() == keys.size() && wl_pressed_keys == keys)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-01 19:52:12 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
#if defined(HAVE_X11)
|
|
|
|
if (init_x11())
|
|
|
|
{
|
|
|
|
char keys_return[32];
|
|
|
|
size_t pressed = 0;
|
2020-04-01 19:52:12 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
auto libx11 = get_libx11();
|
|
|
|
libx11->XQueryKeymap(get_xdisplay(), keys_return);
|
2020-05-06 02:10:45 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
for (KeySym ks : keys) {
|
|
|
|
KeyCode kc2 = libx11->XKeysymToKeycode(get_xdisplay(), ks);
|
2023-04-16 17:02:34 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
bool isPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7)));
|
2020-05-06 02:10:45 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
if (isPressed)
|
|
|
|
pressed++;
|
|
|
|
}
|
2020-05-06 02:10:45 +00:00
|
|
|
|
2024-02-19 12:59:51 +00:00
|
|
|
if (pressed > 0 && pressed == keys.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-06 02:10:45 +00:00
|
|
|
}
|
2024-02-19 12:59:51 +00:00
|
|
|
#endif
|
2020-05-06 02:10:45 +00:00
|
|
|
|
|
|
|
return false;
|
2020-01-28 04:11:05 +00:00
|
|
|
}
|
2022-03-06 12:43:06 +00:00
|
|
|
#elif defined(_WIN32)
|
2020-09-07 05:26:53 +00:00
|
|
|
#include <windows.h>
|
2023-03-03 10:43:59 +00:00
|
|
|
static inline bool keys_are_pressed(const std::vector<KeySym>& keys) {
|
2020-09-07 05:26:53 +00:00
|
|
|
size_t pressed = 0;
|
|
|
|
|
|
|
|
for (KeySym ks : keys) {
|
|
|
|
if (GetAsyncKeyState(ks) & 0x8000)
|
|
|
|
pressed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pressed > 0 && pressed == keys.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-09-19 10:53:24 +00:00
|
|
|
#endif //MANGOHUD_KEYBINDS_H
|