-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViWm.win32.cpp
266 lines (229 loc) · 8.43 KB
/
ViWm.win32.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include <assert.h>
#include "ViWm.h"
#include "Rendering/RenderWindow.h"
#include "Actions/Menu.h"
/**
* Ugly as hell, but, should work
*/
extern ViWm::ViWmManager *globalManager;
namespace ViWm
{
BOOL ViWmManager::monitorEnumerator( HMONITOR hMonitor
, HDC /* hdcMonitor */
, LPRECT /* intersectionRect */
, LPARAM userData
)
{
static int monitorCount = 0;
ViWmManager &instance = *reinterpret_cast<ViWmManager*>( userData );
DesktopLayout &myLayout = instance.currentLayout;
MONITORINFOEX minfo;
minfo.cbSize = sizeof( MONITORINFOEX );
GetMonitorInfo( hMonitor, &minfo );
// as MSDN state that some value may be negative for non-primary
// displays, we abs the width & height to get correct value to
// work on.
int winWidth = abs(minfo.rcWork.right - minfo.rcWork.left);
int winHeight = abs(minfo.rcWork.bottom - minfo.rcWork.top);
// yeah our nice window...
HWND fullScreenWin =
CreateWindowEx ( WS_EX_LAYERED | WS_EX_NOACTIVATE
| (monitorCount == 0 ? WS_EX_APPWINDOW : 0)
, fullScreenWindowClassName
, TEXT("ABack")
, WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS
/* style */
, minfo.rcWork.left
, minfo.rcWork.top
, winWidth
, winHeight
, NULL
, NULL /* menu */
, GetModuleHandle(0)
, NULL
);
if (!fullScreenWin) {
int err = GetLastError();
MessageBox( NULL
, TEXT("Error Creating Background Window")
, TEXT("Error")
, MB_OK | MB_ICONERROR);
exit( err ); /* Bail */
}
// if NULL, we need to create the menu action
// a bit hugly :s
if ( monitorCount++ == 0 )
{
instance.hotkeysDefinition.push_back(
HotKey( 'Z', new Actions::ActionMenu( instance.globalHotkeyListener
, instance.hotkeysDefinition )));
}
// ok we need our window to be always on bottom, let's hack to get that
// we also specify our really wanted size =)
SetWindowPos( fullScreenWin
, HWND_BOTTOM
, minfo.rcWork.left
, minfo.rcWork.top
, winWidth
, winHeight
, /*SWP_NOACTIVATE | */SWP_NOMOVE | SWP_NOSIZE
);
Renderer::RenderWindow *newWindow =
new Renderer::RenderWindow( fullScreenWin
, minfo.rcWork.left
, minfo.rcWork.top
, winWidth
, winHeight );
Screen newScreen
( *newWindow
, minfo.rcWork.left
, minfo.rcWork.top
, winWidth
, winHeight
);
myLayout.push_back( newScreen );
// we make the window transparent here
newWindow->begin( true );
newWindow->end();
assert( myLayout.size() >= 1 );
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
//// Win32 Event Listeners
//////////////////////////////////////////////////////////////////////////
LRESULT ViWmManager::HandleShellHook( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
if (msg != shellhookid)
return DefWindowProc(hwnd, msg, wParam, lParam);
TilledWindow *found;
switch (wParam)
{
case HSHELL_WINDOWCREATED:
if (TilledWindow::IsHandleTileable((HWND)lParam))
{
AddNode((HWND)lParam);
ArrangeWindows();
FocusCurrent();
selectWindow( (HWND)lParam );
_ASSERTE( _CrtCheckMemory() == TRUE );
}
break;
case HSHELL_WINDOWDESTROYED:
found = currentState.FindNode((HWND)lParam);
if ( found )
{
for (size_t i = 0; i < currentLayout.size(); ++i)
LayoutTree::removeClean( currentLayout[i].layoutRoot, (HWND) lParam );
currentState.RemoveNode((HWND)lParam, false);
ArrangeWindows();
FocusCurrent();
_ASSERTE( _CrtCheckMemory() == TRUE );
}
break;
case HSHELL_RUDEAPPACTIVATED:
case HSHELL_WINDOWACTIVATED:
if (globalManager->inDrag()) break;
found = currentState.FindNode((HWND)lParam);
if (found) {
if (currentState.current) {
currentState.current->SetTransparency( globalManager->conf.idleTransparency() );
}
currentState.current = found;
found->SetTransparency( 255 );
selectWindow( (HWND)lParam );
FocusCurrent();
}
_ASSERTE( _CrtCheckMemory() == TRUE );
break;
}
return 0;
}
LRESULT CALLBACK ViWmManager::keyListenerProc( HWND hwnd, UINT msg
, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
ClipCursor(0); /* Release Cursor Lock */
delete globalManager;
globalManager = 0;
PostQuitMessage(WM_QUIT);
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
case WM_COMMAND:
case WM_HOTKEY:
globalManager->HandleHotKey( wParam );
break;
default:
return globalManager->HandleShellHook( hwnd, msg, wParam, lParam );
}
return 0;
}
LRESULT CALLBACK ViWmManager::windowListenerProc( HWND hwnd , UINT msg
, WPARAM wParam , LPARAM lParam )
{
static HCURSOR horizontalSplitCursor = 0;
static HCURSOR verticalSplitCUrsor = 0;
POINT coord;
switch (msg)
{
case WM_NCCREATE: return TRUE;
case WM_CREATE:
if ( !horizontalSplitCursor || !verticalSplitCUrsor )
{
horizontalSplitCursor = LoadCursor( NULL, IDC_SIZENS );
verticalSplitCUrsor = LoadCursor( NULL, IDC_SIZEWE );
}
return 0;
// we handle this message to be able
// to get back mouse tracking messages.
case WM_NCHITTEST: return HTCLIENT;
case WM_MOUSEACTIVATE:
return MA_NOACTIVATE;
case WM_CLOSE: break;
case WM_LBUTTONDOWN:
case WM_NCLBUTTONDOWN:
coord.x = LOWORD( lParam );
coord.y = HIWORD( lParam );
MapWindowPoints( hwnd, NULL, &coord, 1 );
globalManager->beginPick( coord.x, coord.y );
SetCapture( hwnd );
// get selected band
break;
case WM_LBUTTONUP:
case WM_NCLBUTTONUP:
globalManager->endPick();
ReleaseCapture();
break;
case WM_MOUSEMOVE:
// move the splits
if ( wParam & MK_LBUTTON )
{
coord.x = LOWORD( lParam );
coord.y = HIWORD( lParam );
MapWindowPoints( hwnd, NULL, &coord, 1 );
globalManager->movePick( coord.x, coord.y );
}
else
{
coord.x = LOWORD( lParam );
coord.y = HIWORD( lParam );
MapWindowPoints( hwnd, NULL, &coord, 1 );
// cursor thingie
if (globalManager->QuerySplitDirection( coord.x, coord.y )
== LayoutTree::SplitHorizontal)
SetCursor( horizontalSplitCursor );
else
SetCursor( verticalSplitCUrsor );
}
break;
default:
DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
}