76 lines
2.2 KiB
C
Raw Normal View History

2022-08-05 02:06:42 -04: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 02:06:42 -04:00
#pragma once
2019-09-01 20:53:16 +02:00
2022-08-05 02:06:42 -04:00
#include <ingame_overlay/Renderer_Hook.h>
2023-12-27 09:21:59 +02:00
#include "overlay/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 02:06:42 -04:00
#include <X11/Xutil.h> // XEvent keysym
2019-09-01 20:53:16 +02:00
2022-08-05 02:06:42 -04: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 02:06:42 -04:00
bool _Hooked;
bool _Initialized;
Window _GameWnd;
2019-09-01 20:53:16 +02:00
2022-08-13 14:32:43 -04:00
// In (bool): Is toggle wanted
// Out(bool): Is the overlay visible, if true, inputs will be disabled
std::function<bool(bool)> _KeyCombinationCallback;
std::set<uint32_t> _NativeKeyCombination;
bool _KeyCombinationPushed;
2019-09-01 20:53:16 +02:00
// Functions
X11_Hook();
2022-08-05 02:06:42 -04:00
int _CheckForOverlay(Display *d, int num_events);
2019-09-01 20:53:16 +02:00
// Hook to X11 window messages
2022-08-05 02:06:42 -04: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);
2019-11-08 15:54:48 +01:00
public:
2022-08-05 02:06:42 -04:00
std::string LibraryName;
2019-09-01 20:53:16 +02:00
virtual ~X11_Hook();
2022-08-05 02:06:42 -04:00
void ResetRenderState();
2022-08-10 03:22:23 -04:00
void SetInitialWindowSize(Display* display, Window wnd);
2022-08-05 02:06:42 -04:00
bool PrepareForOverlay(Display *display, Window wnd);
2022-08-05 02:06:42 -04:00
Window GetGameWnd() const{ return _GameWnd; }
2019-09-01 20:53:16 +02:00
2022-08-13 14:32:43 -04:00
bool StartHook(std::function<bool(bool)>& key_combination_callback, std::set<ingame_overlay::ToggleKey> const& toggle_keys);
2019-09-01 20:53:16 +02:00
static X11_Hook* Inst();
2022-08-05 02:06:42 -04:00
virtual std::string GetLibraryName() const;
2019-09-01 20:53:16 +02:00
};