-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (53 loc) · 2.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "hyprland/src/Compositor.hpp"
#include "hyprland/src/desktop/Window.hpp"
#include "hyprland/src/desktop/Workspace.hpp"
#include "hyprland/src/plugins/PluginAPI.hpp"
#include <unordered_map>
struct Status {
PHLWINDOW window;
SFullscreenState state;
};
std::unordered_map<PHLWINDOW, Status> previous_fs{};
inline HANDLE PHANDLE = nullptr;
inline CFunctionHook *g_pSetWindowFullscreenHook = nullptr;
typedef void (*origSetWindowFullscreen)(CCompositor *, PHLWINDOW,
SFullscreenState);
void hkSetWindowFullscreen(CCompositor *thisptr, PHLWINDOW pWindow,
SFullscreenState state) {
if (pWindow->m_sFullscreenState.internal == state.internal &&
pWindow->m_sFullscreenState.client == state.client)
return;
if (pWindow->m_bPinned && !pWindow->isFullscreen() &&
state.internal != FSMODE_NONE) {
auto w = pWindow->m_pWorkspace;
if (w->m_bHasFullscreenWindow) {
PHLWINDOW wfs = w->getFullscreenWindow();
previous_fs[pWindow] = {wfs, wfs->m_sFullscreenState};
}
}
(*(origSetWindowFullscreen)g_pSetWindowFullscreenHook->m_pOriginal)(
thisptr, pWindow, state);
if (pWindow->m_bPinFullscreened && state.internal == FSMODE_NONE) {
pWindow->m_bPinned = true;
pWindow->m_bPinFullscreened = false;
}
if (state.internal == FSMODE_NONE && previous_fs.contains(pWindow)) {
Status old_fs = previous_fs[pWindow];
if (valid(old_fs.window))
(*(origSetWindowFullscreen)g_pSetWindowFullscreenHook->m_pOriginal)(
thisptr, old_fs.window, old_fs.state);
previous_fs.erase(pWindow);
}
}
APICALL EXPORT std::string PLUGIN_API_VERSION() { return HYPRLAND_API_VERSION; }
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
static const auto METHODS =
HyprlandAPI::findFunctionsByName(PHANDLE, "setWindowFullscreenState");
g_pSetWindowFullscreenHook = HyprlandAPI::createFunctionHook(
handle, METHODS[0].address, (void *)&hkSetWindowFullscreen);
g_pSetWindowFullscreenHook->hook();
return {"hypr_fullscreen_plus", "Makes fullscreen better", "louisbui63",
"0.0.2"};
}
APICALL EXPORT void PLUGIN_EXIT() {}