Skip to content

Commit 005012f

Browse files
committed
Reformatted to make consistent
1 parent 6b61c6c commit 005012f

File tree

14 files changed

+135
-153
lines changed

14 files changed

+135
-153
lines changed

src/app/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifdef _WIN32
22
#include <windows.h>
3-
extern int RunWindowsApp();
3+
extern int RunWindowsApp ( );
44

5-
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
5+
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
66
return RunWindowsApp();
77
}
88
#else
9-
int main() {
9+
int main ( ) {
1010
return 0;
1111
}
1212
#endif

src/core/Backend.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
// src/core/Backend.h
21
#pragma once
32
#include <stdint.h>
43

5-
using WindowHandle = void*; // platform-specific opaque type
4+
using WindowHandle = void *;
65

76
class Backend {
87
public:
9-
virtual ~Backend() = default;
8+
virtual ~ Backend ( ) = default;
109

11-
virtual void init() = 0;
12-
virtual void shutdown() = 0;
10+
virtual void init ( ) = 0;
11+
virtual void shutdown ( ) = 0;
1312

14-
virtual void setTargetWindow(WindowHandle w) = 0;
15-
virtual void lockInput() = 0;
16-
virtual void unlockInput() = 0;
13+
virtual void setTargetWindow (WindowHandle w) = 0;
14+
virtual void lockInput ( ) = 0;
15+
virtual void unlockInput ( ) = 0;
1716

18-
virtual void sendVirtualKey(uint32_t key) = 0;
17+
virtual void sendVirtualKey (uint32_t key) = 0;
1918

20-
virtual bool processEvents() = 0;
19+
virtual bool processEvents ( ) = 0;
2120
};

src/core/Platform.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
#ifdef _WIN32
22
#include "Platform.h"
3-
#include "../win/WinBackend.h"
3+
#include "win/WinBackend.h"
44

55
namespace Platform {
66

7-
void init() {
7+
void init ( ) {
88
WinBackend::init();
99
}
1010

11-
void shutdown() {
11+
void shutdown ( ) {
1212
WinBackend::shutdown();
1313
}
1414

15-
void setTargetWindow(WindowHandle w) {
15+
void setTargetWindow (WindowHandle w) {
1616
WinBackend::setTargetWindow(w);
1717
}
1818

19-
void lockInput() {
19+
void lockInput ( ) {
2020
WinBackend::lockInput();
2121
}
2222

23-
void unlockInput() {
23+
void unlockInput ( ) {
2424
WinBackend::unlockInput();
2525
}
2626

27-
bool processEvents() {
27+
bool processEvents ( ) {
2828
return WinBackend::processEvents();
2929
}
3030

src/core/Platform.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#pragma once
22
#include <stdint.h>
33

4-
using WindowHandle = void*;
4+
using WindowHandle = void *;
55

66
namespace Platform {
7-
void init();
8-
void shutdown();
7+
void init ( );
8+
void shutdown ( );
99

10-
void setTargetWindow(WindowHandle w);
11-
void lockInput();
12-
void unlockInput();
10+
void setTargetWindow (WindowHandle w);
11+
void lockInput ( );
12+
void unlockInput ( );
1313

14-
bool processEvents();
14+
bool processEvents ( );
1515
}

src/win/WinApp.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
#include "WinSettings.h"
66

77

8-
static const char* WINDOW_CLASS = "SplitLoafTray";
8+
static const char * WINDOW_CLASS = "SplitLoafTray";
99
static HINSTANCE g_hInstance = NULL;
1010

11-
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
12-
{
11+
LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
1312
switch (msg) {
1413

1514
case TRAY_CALLBACK:
16-
if (lParam == WM_RBUTTONUP)
15+
if (lParam == WM_RBUTTONUP) {
1716
ShowTrayMenu(hwnd);
17+
}
1818
break;
1919

2020
case WM_COMMAND:
@@ -38,33 +38,26 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3838
return DefWindowProc(hwnd, msg, wParam, lParam);
3939
}
4040

41-
int RunWindowsApp()
42-
{
41+
int RunWindowsApp ( ) {
4342
g_hInstance = GetModuleHandle(NULL);
4443

45-
// Register class
4644
WNDCLASS wc = {};
4745
wc.lpfnWndProc = WindowProc;
4846
wc.hInstance = g_hInstance;
4947
wc.lpszClassName = WINDOW_CLASS;
50-
RegisterClass(&wc);
48+
RegisterClass(& wc);
5149

52-
// Create hidden window
53-
HWND hwnd = CreateWindowEx(
54-
0, WINDOW_CLASS, "Split Loaf",
55-
0, 0, 0, 0, 0,
56-
NULL, NULL, g_hInstance, NULL
57-
);
50+
HWND hwnd = CreateWindowEx(0, WINDOW_CLASS, "Split Loaf",0, 0, 0, 0, 0,NULL, NULL, g_hInstance, NULL);
5851

5952
InitTrayIcon(hwnd);
6053

6154
Platform::init();
6255

6356
MSG msg {};
6457
while (true) {
65-
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
66-
TranslateMessage(&msg);
67-
DispatchMessage(&msg);
58+
while (PeekMessage(& msg, NULL, 0, 0, PM_REMOVE)) {
59+
TranslateMessage(& msg);
60+
DispatchMessage(& msg);
6861

6962
if (msg.message == WM_QUIT) {
7063
Platform::shutdown();

src/win/WinApp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#pragma once
22

3-
int RunWindowsApp();
3+
int RunWindowsApp ( );

src/win/WinBackend.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,50 @@ static HWND targetWindow = NULL;
1515
static bool locked = false;
1616
static bool targetHasFocus = false;
1717

18-
HHOOK& WinHooks_GetKeyboardHook() { return keyboardHook; }
19-
HWND& WinHooks_GetTargetWindow() { return targetWindow; }
20-
bool& WinHooks_GetLockedFlag() { return locked; }
21-
bool& WinHooks_GetTargetFocusFlag() { return targetHasFocus; }
18+
HHOOK & WinHooks_GetKeyboardHook ( ) {
19+
return keyboardHook;
20+
}
21+
HWND & WinHooks_GetTargetWindow ( ) {
22+
return targetWindow;
23+
}
24+
bool & WinHooks_GetLockedFlag ( ) {
25+
return locked;
26+
}
27+
bool & WinHooks_GetTargetFocusFlag ( ) {
28+
return targetHasFocus;
29+
}
2230

23-
void WinBackend::init() {
24-
keyboardHook = SetWindowsHookEx(
25-
WH_KEYBOARD_LL,
26-
LowLevelKeyboardProc,
27-
GetModuleHandle(NULL),
28-
0
29-
);
31+
void WinBackend::init ( ) {
32+
keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,GetModuleHandle(NULL),0);
3033
}
3134

32-
void WinBackend::shutdown() {
35+
void WinBackend::shutdown ( ) {
3336
UnhookWindowsHookEx(keyboardHook);
3437
}
3538

36-
void WinBackend::setTargetWindow(WindowHandle w) {
39+
void WinBackend::setTargetWindow (WindowHandle w) {
3740
targetWindow = (HWND)w;
3841
}
3942

40-
void WinBackend::lockInput() {
43+
void WinBackend::lockInput ( ) {
4144
locked = true;
4245
}
4346

44-
void WinBackend::unlockInput() {
47+
void WinBackend::unlockInput ( ) {
4548
locked = false;
4649
targetHasFocus = false;
4750
}
4851

49-
void WinBackend::sendVirtualKey(uint32_t vk) {
52+
void WinBackend::sendVirtualKey (uint32_t vk) {
5053
INPUT in = {0};
5154

5255
in.type = INPUT_KEYBOARD;
5356
in.ki.wVk = vk;
5457

5558

56-
SendInput(1, &in, sizeof(INPUT));
59+
SendInput(1, & in, sizeof(INPUT));
5760
}
5861

59-
bool WinBackend::processEvents() {
62+
bool WinBackend::processEvents ( ) {
6063
return true;
6164
}

src/win/WinBackend.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#pragma once
22
#include <stdint.h>
33
#include <windows.h>
4-
#include "../core/Platform.h"
4+
#include "core/Platform.h"
55

66
namespace WinBackend {
7-
void init();
8-
void shutdown();
7+
void init ( );
8+
void shutdown ( );
99

10-
void setTargetWindow(WindowHandle w);
11-
void lockInput();
12-
void unlockInput();
10+
void setTargetWindow (WindowHandle w);
11+
void lockInput ( );
12+
void unlockInput ( );
1313

14-
bool processEvents();
15-
void sendVirtualKey(uint32_t vk);
14+
bool processEvents ( );
15+
void sendVirtualKey (uint32_t vk);
1616
}

src/win/WinHooks.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33
#include <windows.h>
44
#include <stdio.h>
55

6-
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
7-
if (nCode != HC_ACTION)
6+
LRESULT CALLBACK LowLevelKeyboardProc (int nCode, WPARAM wParam, LPARAM lParam) {
7+
if (nCode != HC_ACTION) {
88
return CallNextHookEx(NULL, nCode, wParam, lParam);
9+
}
910

10-
auto& targetWindow = WinHooks_GetTargetWindow();
11-
auto& locked = WinHooks_GetLockedFlag();
12-
auto& targetHasFocus = WinHooks_GetTargetFocusFlag();
11+
auto & targetWindow = WinHooks_GetTargetWindow();
12+
auto & locked = WinHooks_GetLockedFlag();
13+
auto & targetHasFocus = WinHooks_GetTargetFocusFlag();
1314

14-
KBDLLHOOKSTRUCT *kbd = (KBDLLHOOKSTRUCT*)lParam;
15+
KBDLLHOOKSTRUCT * kbd = (KBDLLHOOKSTRUCT *)lParam;
1516

16-
if (kbd->flags & LLKHF_INJECTED)
17+
if (kbd -> flags & LLKHF_INJECTED) {
1718
return CallNextHookEx(NULL, nCode, wParam, lParam);
19+
}
1820

1921
if (wParam == WM_KEYDOWN) {
20-
if (kbd->vkCode == VK_F8) {
22+
if (kbd -> vkCode == VK_F8) {
2123
POINT p;
22-
GetCursorPos(&p);
24+
GetCursorPos(& p);
2325
targetWindow = WindowFromPoint(p);
2426
printf("Target window: 0x%p\n", targetWindow);
2527
return 1;
2628
}
2729

28-
if (kbd->vkCode == VK_F6) {
30+
if (kbd -> vkCode == VK_F6) {
2931
locked = (targetWindow != NULL);
3032
if (locked) {
3133
SetForegroundWindow(targetWindow);
@@ -36,7 +38,7 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
3638
return 1;
3739
}
3840

39-
if (kbd->vkCode == VK_F7) {
41+
if (kbd -> vkCode == VK_F7) {
4042
locked = false;
4143
targetHasFocus = false;
4244
printf("Unlocked\n");
@@ -54,10 +56,11 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
5456
targetHasFocus = 1;
5557
}
5658

57-
WinBackend::sendVirtualKey (kbd->vkCode);
59+
WinBackend::sendVirtualKey(kbd -> vkCode);
5860
return 1;
5961
}
6062
}
6163

62-
return CallNextHookEx(NULL, nCode, wParam, lParam);
64+
return CallNextHookEx (NULL, nCode, wParam, lParam);
6365
}
66+

src/win/WinHooks.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#pragma once
22
#include <windows.h>
33

4-
LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wParam, LPARAM lParam);
4+
LRESULT CALLBACK LowLevelKeyboardProc (int code, WPARAM wParam, LPARAM lParam);
55

6-
// Access shared state inside WinBackend.cpp
7-
HHOOK& WinHooks_GetKeyboardHook();
8-
HWND& WinHooks_GetTargetWindow();
9-
bool& WinHooks_GetLockedFlag();
10-
bool& WinHooks_GetTargetFocusFlag();
6+
HHOOK & WinHooks_GetKeyboardHook ( );
7+
HWND & WinHooks_GetTargetWindow ( );
8+
bool & WinHooks_GetLockedFlag ( );
9+
bool & WinHooks_GetTargetFocusFlag ( );
1110

12-
void SendVirtualKeyToTarget(DWORD vkCode);
11+
void SendVirtualKeyToTarget (DWORD vkCode);

0 commit comments

Comments
 (0)