aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/fullscreen.cpp
blob: f092973ff521e9ccf63c5604afb189ec4bbd7d13 (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/** (c) Nullsoft, Inc.         C O N F I D E N T I A L
 ** Filename: 
 ** Project:
 ** Description:
 ** Author:
 ** Created:
 **/

#include "main.h"



HWND hFSMonitorWindow;
extern "C"
{
	int g_fsapp = 0;
	int g_restoreaot_timer_set = 0;
	int g_dropaot_timer_set = 0;
}
#define APPBAR_CALLBACK 	WM_USER + 1010
#define appbartag L"wa_fsmonitorclass"
LRESULT CALLBACK fsMonitorWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

void BeginFullscreenAppMonitor()
{
	// this lets us receive appbar messages.
	// we're interested in ABN_FULLSCREENAPP so we can turn AOT off temporarily
	APPBARDATA abd;

	WNDCLASSW wc;
	if (!GetClassInfoW(hMainInstance, appbartag, &wc))
	{
		memset(&wc, 0, sizeof(wc));
		wc.lpfnWndProc = fsMonitorWndProc;
		wc.hInstance = hMainInstance;
		wc.lpszClassName = appbartag;
		wc.style = 0;

		RegisterClassW(&wc);
	}

	hFSMonitorWindow = CreateWindowExW(0, appbartag, L"", 0, 0, 0, 1, 1, NULL, NULL, hMainInstance, NULL);

	abd.cbSize = sizeof(APPBARDATA);
	abd.hWnd = hFSMonitorWindow;
	abd.uCallbackMessage = APPBAR_CALLBACK;
	abd.uEdge = ABE_TOP;
	memset(&abd.rc, 0, sizeof(RECT));

	SHAppBarMessage(ABM_NEW, &abd);
}

void EndFullscreenAppMonitor()
{
	APPBARDATA abd;

	abd.cbSize = sizeof(APPBARDATA);
	abd.hWnd = hFSMonitorWindow;

	SHAppBarMessage(ABM_REMOVE, &abd);

	if (IsWindow(hFSMonitorWindow))
		DestroyWindow(hFSMonitorWindow);
}


void OnFullscreenApp()
{
	// ignore this event if the window going fullscreen is a winamp window
	if (!is_fullscreen_video && !vis_fullscreen)
	{
		if (g_restoreaot_timer_set)
		{
			g_restoreaot_timer_set = 0;
			KillTimer(hMainWindow, 100);
		}
		else
		{
			g_dropaot_timer_set = 1;
			SetTimer(hMainWindow, 99, 250, NULL);
		}
	}
}

void OnCancelFullscreenApp()
{
	if (!is_fullscreen_video && !vis_fullscreen)
	{
		if (g_dropaot_timer_set)
		{
			KillTimer(hMainWindow, 99);
			g_dropaot_timer_set = 0;
		}
		else
		{
			SetTimer(hMainWindow, 100, 250, NULL);
			g_restoreaot_timer_set = 1;
		}
	}
}

LRESULT CALLBACK fsMonitorWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case APPBAR_CALLBACK:
		switch (wParam)
		{
		case ABN_FULLSCREENAPP:
			if (lParam && !g_fsapp)
			{
				g_fsapp = 1;
				OnFullscreenApp();
			}
			else if (!lParam && g_fsapp)
			{
				g_fsapp = 0;
				OnCancelFullscreenApp();
			}
		}
		return 0;
	}
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}



void dropAOT()
{
	if (!config_dropaotfs) return ;
	set_aot(0);
	if (config_aot)
	{
		SetWindowPos(hMainWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
		SetWindowPos(hMainWindow, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
	}
}

void restoreAOT()
{
	if (!config_dropaotfs) return ;
	if (config_aot)
	{
		// normally, changing hMainWindow's ONTOP flag should be enough to change all the owned window' z-orders too,
		// but for some reason I cannot figure out, it does not work unless WA has been clicked away and back in focus.
		// if that hasn't been done, then reseting the flag on each window is necessary.
		// now for the fun part: the above is true for classic skin, but in modern skins, reseting the flag
		// on those windows actually prevents the player from coming back ONTOP! FUN!
		if (GetParent(hPLWindow) == NULL)
		{
			SetWindowPos(hPLWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
			SetWindowPos(hVideoWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
			SetWindowPos(hEQWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
		}
		SetWindowPos(hMainWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
		SetWindowPos(hMainWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
	}
	set_aot(0);
}