2022-08-05 14:06:42 +08: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-02 02:53:16 +08:00
|
|
|
|
2022-08-05 14:06:42 +08:00
|
|
|
#pragma once
|
2019-09-02 02:53:16 +08:00
|
|
|
|
2022-08-05 14:06:42 +08:00
|
|
|
#include <ingame_overlay/Renderer_Hook.h>
|
|
|
|
|
2023-12-27 15:21:59 +08:00
|
|
|
#include "overlay/internal_includes.h"
|
2019-09-02 02:53:16 +08:00
|
|
|
|
|
|
|
#include <X11/X.h> // XEvent types
|
|
|
|
#include <X11/Xlib.h> // XEvent structure
|
2022-08-05 14:06:42 +08:00
|
|
|
#include <X11/Xutil.h> // XEvent keysym
|
2019-09-02 02:53:16 +08:00
|
|
|
|
2022-08-05 14:06:42 +08:00
|
|
|
class X11_Hook :
|
|
|
|
public Base_Hook
|
2019-09-02 02:53:16 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr const char* DLL_NAME = "libX11.so";
|
|
|
|
|
|
|
|
private:
|
|
|
|
static X11_Hook* _inst;
|
|
|
|
|
|
|
|
// Variables
|
2022-08-05 14:06:42 +08:00
|
|
|
bool _Hooked;
|
|
|
|
bool _Initialized;
|
|
|
|
Window _GameWnd;
|
2019-09-02 02:53:16 +08:00
|
|
|
|
2022-08-14 02:32:43 +08: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-02 02:53:16 +08:00
|
|
|
// Functions
|
|
|
|
X11_Hook();
|
2022-08-05 14:06:42 +08:00
|
|
|
int _CheckForOverlay(Display *d, int num_events);
|
2019-09-02 02:53:16 +08:00
|
|
|
|
|
|
|
// Hook to X11 window messages
|
2022-08-05 14:06:42 +08:00
|
|
|
decltype(::XEventsQueued)* XEventsQueued;
|
|
|
|
decltype(::XPending)* XPending;
|
2019-09-02 02:53:16 +08:00
|
|
|
|
2019-09-03 16:32:32 +08:00
|
|
|
static int MyXEventsQueued(Display * display, int mode);
|
|
|
|
static int MyXPending(Display* display);
|
|
|
|
|
2019-11-08 22:54:48 +08:00
|
|
|
public:
|
2022-08-05 14:06:42 +08:00
|
|
|
std::string LibraryName;
|
|
|
|
|
2019-09-02 02:53:16 +08:00
|
|
|
virtual ~X11_Hook();
|
|
|
|
|
2022-08-05 14:06:42 +08:00
|
|
|
void ResetRenderState();
|
2022-08-10 15:22:23 +08:00
|
|
|
void SetInitialWindowSize(Display* display, Window wnd);
|
2022-08-05 14:06:42 +08:00
|
|
|
bool PrepareForOverlay(Display *display, Window wnd);
|
2019-09-03 16:32:32 +08:00
|
|
|
|
2022-08-05 14:06:42 +08:00
|
|
|
Window GetGameWnd() const{ return _GameWnd; }
|
2019-09-02 02:53:16 +08:00
|
|
|
|
2022-08-14 02:32:43 +08:00
|
|
|
bool StartHook(std::function<bool(bool)>& key_combination_callback, std::set<ingame_overlay::ToggleKey> const& toggle_keys);
|
2019-09-02 02:53:16 +08:00
|
|
|
static X11_Hook* Inst();
|
2022-08-05 14:06:42 +08:00
|
|
|
virtual std::string GetLibraryName() const;
|
2019-09-02 02:53:16 +08:00
|
|
|
};
|