xoblite™ / Blackbox for Windows bb5 | RC6 preview | 0.25.2.14
http://xoblite.net/
Workspaces.cpp File Reference
#include "..\API\BBApi.h"
#include "Workspaces.h"
#include "..\Settings\Settings.h"
#include "..\Toolbar\Toolbar.h"
#include "..\Blackbox.h"

Functions

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
 

Variables

const char szWorkspacesName [] = "Workspaces"
 
WorkspacespWorkspaces
 
SettingspSettings
 
DesktoppDesktop
 
ToolbarpToolbar
 
TaskbarpTaskbar
 
int workspacesMessageSubscription [] = { BB_WORKSPACE, BB_RECONFIGURE, BB_SWITCHTON, BB_ACTIVETASK, BB_LISTDESKTOPS, BB_BRINGTOFRONT, 0 }
 
const long magicDWord = 0x49474541
 

Function Documentation

◆ WndProc()

LRESULT CALLBACK WndProc ( HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam )
129{
130 switch (message)
131 {
132 //====================
133
134 case BB_RECONFIGURE:
135 {
136 pWorkspaces->UpdateWorkspaceNames();
137 }
138 break;
139
140 //====================
141
142 case BB_SWITCHTON:
143 {
144 pWorkspaces->SwitchToWorkspace((int)wParam);
145 break;
146 }
147
148 //====================
149
150 case BB_ACTIVETASK:
151 {
152 // Change workspaces automatically when the active task changes? (e.g. via Alt+Tab)
153 if (pSettings->followActive) pWorkspaces->SwitchToWorkspace(pWorkspaces->GetWorkspaceByWindow((HWND)wParam));
154 }
155
156 //====================
157
158 case BB_LISTDESKTOPS:
159 {
160 DesktopInfo deskInfo;
161 ZeroMemory(&deskInfo, sizeof(deskInfo));
162 for (int i = 0; i < pSettings->numberOfWorkspaces; i++)
163 {
164 deskInfo.isCurrent = (pSettings->currentWorkspace == i);
165 deskInfo.number = i;
166
167 if (pWorkspaces->workspaceNames[i] == "null")
168 {
169 sprintf(deskInfo.name, "Workspace %d", i + 1);
170 }
171 else
172 {
173 strcpy(deskInfo.name, pWorkspaces->workspaceNames[i].c_str());
174 }
175
176 SendMessage((HWND)wParam, BB_DESKTOPINFO, 0, (LPARAM) &deskInfo);
177 }
178 break;
179 }
180
181 //====================
182
183 case BB_BRINGTOFRONT:
184 {
185 // Change window focus via message... (+ change workspace if needed)
186 int n = pWorkspaces->GetWorkspaceByWindow((HWND)lParam);
187 if (n != pSettings->currentWorkspace) pWorkspaces->SwitchToWorkspace(n);
188// BBSwitchToThisWindow((HWND)lParam, FALSE);
189 BringWindowToTop((HWND)lParam);
190 break;
191 }
192
193 //====================
194
195 case BB_WORKSPACE:
196 {
197 switch (wParam)
198 {
199 case 0: // "BBWS_PreviousWorkspace"
200 pWorkspaces->PreviousWorkspace();
201 break;
202 case 1: // "BBWS_NextWorkspace"
203 pWorkspaces->NextWorkspace();
204 break;
205 case 2: // "BBWS_NewWorkspace"
206 pWorkspaces->NewWorkspace();
207 break;
208 case 3: // "BBWS_RemoveLastWorkspace"
209 pWorkspaces->RemoveLastWorkspace();
210 break;
211 case 4: // "BBWS_SWITCHTODESK"
212 pWorkspaces->SwitchToWorkspace((int)lParam);
213 break;
214 case 5: // "BBWS_GATHERWINDOWS"
215 pWorkspaces->GatherWindows();
216 break;
217 case 6: // "BBWS_MOVEWINDOWLEFT"
218 pWorkspaces->MoveWindowToPreviousWorkspace((HWND)lParam);
219 break;
220 case 7: // "BBWS_MOVEWINDOWRIGHT"
221 pWorkspaces->MoveWindowToNextWorkspace((HWND)lParam);
222 break;
223 case 8: // "BBWS_PREVWINDOW"
224 if (pTaskbar) pTaskbar->PreviousTask(!(bool)lParam, false);
225 break;
226 case 9: // "BBWS_NEXTWINDOW"
227 if (pTaskbar) pTaskbar->NextTask(!(bool)lParam, false);
228 break;
229 case 10: // "BBWS_LastWorkspace"
230 pWorkspaces->LastWorkspace();
231 break;
232
233 //====================
234
235 // Below: Misc stuff included for for basic compatibility
236 // with the bb(C)Lean(Mod)(Zero) modified BBApi...
238 case BBWS_MAKESTICKY:
239 case BBWS_CLEARSTICKY:
240 case BBWS_TOGGLEONTOP:
241 {
242 HWND hwnd = (HWND)lParam;
243 if (hwnd == NULL)
244 {
245 if (pTaskbar) hwnd = pTaskbar->GetActiveWindow();
246 if (hwnd == NULL) hwnd = GetForegroundWindow();
247 }
248
249 if (message == BBWS_TOGGLESTICKY)
250 {
251 if (CheckSticky(hwnd)) RemoveSticky(hwnd);
252 else MakeSticky(hwnd);
253 }
254 else if (message == BBWS_MAKESTICKY) MakeSticky(hwnd);
255 else if (message == BBWS_CLEARSTICKY) RemoveSticky(hwnd);
256 else if (message == BBWS_TOGGLEONTOP)
257 {
258 LONG_PTR windowIsOnTop = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
259 if (windowIsOnTop & WS_EX_TOPMOST) SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
260 else SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
261 }
262 }
263 break;
264
265 //====================
266
267 default:
268 break; // Note: Breaking as default avoids unintended behaviour if receiving unknown wParam, e.g. ones defined by the bb(C)Lean(Mod)(Zero) modified BBApi...
269 }
270 }
271 break;
272
273 //====================
274
275 case WM_DISPLAYCHANGE:
276 {
277 pWorkspaces->ScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
278 pWorkspaces->ScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
279 }
280
281 //====================
282
283 default:
284 return DefWindowProc(hwnd,message,wParam,lParam);
285 }
286 return 0;
287}
void RemoveSticky(HWND window)
Definition BBApi.cpp:2978
bool CheckSticky(HWND window)
Definition BBApi.cpp:2994
Workspaces * pWorkspaces
Definition Blackbox.cpp:51
void MakeSticky(HWND window)
Definition BBApi.cpp:2965
Taskbar * pTaskbar
Definition Blackbox.cpp:47
Settings * pSettings
Definition Blackbox.cpp:46
#define BBWS_CLEARSTICKY
Definition BBApi.h:717
#define BB_ACTIVETASK
Definition BBApi.h:198
#define BBWS_MAKESTICKY
Definition BBApi.h:716
#define BBWS_TOGGLESTICKY
Definition BBApi.h:715
#define BB_RECONFIGURE
Definition BBApi.h:147
#define BBWS_TOGGLEONTOP
Definition BBApi.h:718
#define BB_WORKSPACE
Definition BBApi.h:183
#define BB_BRINGTOFRONT
Definition BBApi.h:182
#define BB_DESKTOPINFO
Definition BBApi.h:179
#define BB_SWITCHTON
Definition BBApi.h:181
#define BB_LISTDESKTOPS
Definition BBApi.h:180
Definition BBApi.h:644
bool isCurrent
Definition BBApi.h:647
char name[32]
Definition BBApi.h:646
int number
Definition BBApi.h:648

◆ EnumWindowsProc()

BOOL CALLBACK EnumWindowsProc ( HWND hwnd,
LPARAM lParam )
297{
298 // Perform a few window validation checks...
299 // (nb. the taskbar already performs many such checks for its tasks prior to adding them, so we leverage that here too)
300 if (!IsOnTaskbar(hwnd)) return true;
301 if (CheckSticky(hwnd)) return true;
302 if (GetWindowLong(hwnd, GWLP_USERDATA) == magicDWord) return true; // For legacy backwards compatibility only (iirc this was used by the earliest bb4win sticky windows implementations)
303
304 // Disregard Rainmeter widgets... (i.e. exclude them from the Workspaces handling altogether to avoid possible conflicts)
305 char temp[MAX_LINE_LENGTH];
306 GetClassName(hwnd, temp, MAX_LINE_LENGTH);
307 if (!_stricmp(temp, "RainmeterMeterWindow")) return true;
308
309 //====================
310
311 RECT r;
312 GetWindowRect(hwnd, &r);
313
314 int addH = (int)lParam;
315 if (addH == -1)
316 {
317 int screenWidth = pWorkspaces->ScreenWidth;
318 int windowWidth = abs(r.right - r.left);
319
320 // Initial x/width position calculation...
321 if (r.left > screenWidth)
322 {
323 r.left %= (screenWidth + 10);
324 if (r.left > screenWidth) r.left -= (screenWidth + 10);
325 r.right = r.left + windowWidth;
326 }
327 else if (r.left < -10)
328 {
329 r.left %= (screenWidth + 10);
330 while (r.left < -10) r.left += (screenWidth + 10);
331 r.right = r.left + windowWidth;
332 }
333 }
334 else
335 {
336 r.left -= addH;
337 r.right -= addH;
338 }
339
340 HDWP hdwp = DeferWindowPos(pWorkspaces->dwp, hwnd, NULL, r.left, r.top, r.right-r.left, r.bottom-r.top, SWP_NOZORDER|SWP_NOACTIVATE);
341 if (hdwp != NULL) pWorkspaces->dwp = hdwp;
342/*
343 else if (pSettings->debugLogging)
344 {
345 char title[MAX_LINE_LENGTH], msg[MAX_LINE_LENGTH];
346 GetWindowText(hwnd, title, MAX_LINE_LENGTH);
347 sprintf(msg, "Workspaces -> DeferWindowPos() failed! -> %s", title);
348 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_ERROR_MESSAGE, (LPARAM)msg);
349 }
350*/
351 return true;
352}
bool IsOnTaskbar(HWND hwnd)
Definition BBApi.cpp:3262
#define MAX_LINE_LENGTH
Definition BBApi.h:64
const long magicDWord
Definition Workspaces.cpp:294

Variable Documentation

◆ szWorkspacesName

const char szWorkspacesName[] = "Workspaces"

◆ pWorkspaces

Workspaces* pWorkspaces
extern

◆ pSettings

Settings* pSettings
extern

◆ pDesktop

Desktop* pDesktop
extern

◆ pToolbar

Toolbar* pToolbar
extern

◆ pTaskbar

Taskbar* pTaskbar
extern

◆ workspacesMessageSubscription

◆ magicDWord

const long magicDWord = 0x49474541