goldberg_emulator/overlay_experimental/linux/X11_Hook.h

72 lines
2 KiB
C
Raw Normal View History

2022-08-05 08:06:42 +02:00
/*
* Copyright (C) 2019-2020 Nemirtingas
* This file is part of the ingame overlay project
*
* The ingame overlay project is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* The ingame overlay project 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the ingame overlay project; if not, see
* <http://www.gnu.org/licenses/>.
*/
2019-09-01 20:53:16 +02:00
2022-08-05 08:06:42 +02:00
#pragma once
2019-09-01 20:53:16 +02:00
2022-08-05 08:06:42 +02:00
#include <ingame_overlay/Renderer_Hook.h>
#include "../internal_includes.h"
2019-09-01 20:53:16 +02:00
#include <X11/X.h> // XEvent types
#include <X11/Xlib.h> // XEvent structure
2022-08-05 08:06:42 +02:00
#include <X11/Xutil.h> // XEvent keysym
2019-09-01 20:53:16 +02:00
2022-08-05 08:06:42 +02:00
class X11_Hook :
public Base_Hook
2019-09-01 20:53:16 +02:00
{
public:
static constexpr const char* DLL_NAME = "libX11.so";
private:
static X11_Hook* _inst;
// Variables
2022-08-05 08:06:42 +02:00
bool _Hooked;
bool _Initialized;
Window _GameWnd;
2019-09-01 20:53:16 +02:00
// Functions
X11_Hook();
2022-08-05 08:06:42 +02:00
int _CheckForOverlay(Display *d, int num_events);
2019-09-01 20:53:16 +02:00
// Hook to X11 window messages
2022-08-05 08:06:42 +02:00
decltype(::XEventsQueued)* XEventsQueued;
decltype(::XPending)* XPending;
2019-09-01 20:53:16 +02:00
static int MyXEventsQueued(Display * display, int mode);
static int MyXPending(Display* display);
2022-08-05 08:06:42 +02:00
std::function<bool(bool)> _KeyCombinationCallback;
2019-11-08 15:54:48 +01:00
public:
2022-08-05 08:06:42 +02:00
std::string LibraryName;
2019-09-01 20:53:16 +02:00
virtual ~X11_Hook();
2022-08-05 08:06:42 +02:00
void ResetRenderState();
2022-08-10 09:22:23 +02:00
void SetInitialWindowSize(Display* display, Window wnd);
2022-08-05 08:06:42 +02:00
bool PrepareForOverlay(Display *display, Window wnd);
2022-08-05 08:06:42 +02:00
Window GetGameWnd() const{ return _GameWnd; }
2019-09-01 20:53:16 +02:00
2022-08-05 08:06:42 +02:00
bool StartHook(std::function<bool(bool)>& key_combination_callback);
2019-09-01 20:53:16 +02:00
static X11_Hook* Inst();
2022-08-05 08:06:42 +02:00
virtual std::string GetLibraryName() const;
2019-09-01 20:53:16 +02:00
};