-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
112 lines (85 loc) · 2.8 KB
/
main.c
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdbool.h>
RECT get_monitor_resolution(HWND hwnd)
{
MONITORINFO minfo;
minfo.cbSize = sizeof(minfo);
GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &minfo);
return minfo.rcMonitor;
}
BOOL CALLBACK find_thread_topwindow(HWND hwnd, LPARAM lParam)
{
HWND* pphWnd = (HWND*)lParam;
if (GetParent(hwnd))
{
*pphWnd = NULL;
return TRUE;
}
*pphWnd = hwnd;
return FALSE;
}
BOOL CALLBACK resize_vimtextarea(HWND hwnd, LPARAM lParam)
{
char lpszClassName[100];
GetClassName(hwnd, lpszClassName, 100);
if (strcmp(lpszClassName, "VimTextArea") == 0)
{
const LPCRECT r = (LPCRECT)lParam;
const int cx = r->right-r->left;
const int cy = r->bottom-r->top;
SetWindowPos(hwnd, NULL, 0, 0, cx, cy,
SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
}
return TRUE;
}
struct save_vim_wnd_info_t
{
DWORD style;
DWORD exstyle;
bool maximized;
RECT r;
LONG_PTR user_data;
};
LONG _declspec(dllexport) toggle_full_screen()
{
HWND vim_hwnd = NULL;
const DWORD threadId = GetCurrentThreadId();
EnumThreadWindows(threadId, find_thread_topwindow, (LPARAM)&vim_hwnd);
if (NULL == vim_hwnd)
return 1;
const bool fullscreen = (GetWindowLong(vim_hwnd, GWL_STYLE) & WS_CAPTION) != 0;
if (fullscreen)
{
struct save_vim_wnd_info_t *info = GlobalAlloc(GMEM_FIXED, sizeof(struct save_vim_wnd_info_t));
info->maximized = IsZoomed(vim_hwnd);
if (info->maximized)
SendMessage(vim_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
info->style = GetWindowLong(vim_hwnd, GWL_STYLE);
info->exstyle = GetWindowLong(vim_hwnd, GWL_EXSTYLE);
GetWindowRect(vim_hwnd, &info->r);
info->user_data = SetWindowLongPtr(vim_hwnd, GWLP_USERDATA, (LONG_PTR)info);
SetWindowLong(vim_hwnd, GWL_STYLE,
info->style & ~(WS_CAPTION|WS_THICKFRAME));
SetWindowLong(vim_hwnd, GWL_EXSTYLE,
info->exstyle & ~(WS_EX_WINDOWEDGE));
const RECT r = get_monitor_resolution(vim_hwnd);
SetWindowPos(vim_hwnd, NULL, r.left, r.top, r.right-r.left, r.bottom-r.top,
SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
EnumChildWindows(vim_hwnd, resize_vimtextarea, (LPARAM)&r);
}
else
{
struct save_vim_wnd_info_t *info = (struct save_vim_wnd_info_t*)GetWindowLongPtr(vim_hwnd, GWLP_USERDATA);
SetWindowLong(vim_hwnd, GWL_STYLE,
info->style | (WS_CAPTION|WS_THICKFRAME));
SetWindowLong(vim_hwnd, GWL_EXSTYLE,
info->exstyle | WS_EX_WINDOWEDGE);
SetWindowLongPtr(vim_hwnd, GWLP_USERDATA, info->user_data);
SetWindowPos(vim_hwnd, NULL, info->r.left, info->r.top,
info->r.right-info->r.left, info->r.bottom-info->r.top,
SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
GlobalFree(info);
}
return 0;
}