forked from nir9/lightwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.c
75 lines (64 loc) · 2.32 KB
/
keyboard.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
#include <windows.h>
#include "keyboard.h"
#include "tiling.h"
#include "error.h"
#include "config.h"
UINT getKeyCode(char value)
{
return VkKeyScanEx(value, GetKeyboardLayout(0));
}
void addKeyboardKeybind(int id, UINT keyCode, UINT modifiers)
{
if (!RegisterHotKey(NULL, id, modifiers, keyCode)) {
reportWin32Error(L"Failed to register hotkey");
}
}
bool initializeKeyboardConfig()
{
addKeyboardKeybind(TOGGLE_FULLSCREEN_MODE_HOTKEY_ID, getKeyCode(FULLSCREEN_MODE_HOTKEY), MOD_ALT | MOD_NOREPEAT);
addKeyboardKeybind(NEXT_WINDOW_HOTKEY_ID, getKeyCode(NEXT_WINDOW_HOTKEY), MOD_ALT | MOD_NOREPEAT);
addKeyboardKeybind(PREV_WINDOW_HOTKEY_ID, getKeyCode(PREV_WINDOW_HOTKEY), MOD_ALT | MOD_NOREPEAT);
addKeyboardKeybind(QUIT_LIGHTWM_HOTKEY_ID, getKeyCode(QUIT_LIGHTWM_HOTKEY), MOD_ALT | MOD_NOREPEAT);
addKeyboardKeybind(FORCE_TILE_LIGHTWM_HOTKEY_ID, getKeyCode(FORCE_TILE_LIGHTWM_HOTKEY), MOD_ALT | MOD_NOREPEAT);
for (int i = 0; i < 9; i++) {
addKeyboardKeybind(WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + i, getKeyCode('1' + i), MOD_ALT | MOD_NOREPEAT);
}
for (int i = 0; i < 9; i++) {
addKeyboardKeybind(SWITCH_WORKSPACE_HOTKEY_ID + i, getKeyCode('1' + i), MOD_ALT | MOD_SHIFT | MOD_NOREPEAT);
}
return true;
}
void cleanupKeyboard()
{
UnregisterHotKey(NULL, TOGGLE_FULLSCREEN_MODE_HOTKEY_ID);
UnregisterHotKey(NULL, NEXT_WINDOW_HOTKEY_ID);
UnregisterHotKey(NULL, PREV_WINDOW_HOTKEY_ID);
UnregisterHotKey(NULL, QUIT_LIGHTWM_HOTKEY_ID);
UnregisterHotKey(NULL, FORCE_TILE_LIGHTWM_HOTKEY_ID);
for (int i = 0; i < 9; i++) {
UnregisterHotKey(NULL, WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + i);
UnregisterHotKey(NULL, SWITCH_WORKSPACE_HOTKEY_ID + i);
}
}
void handleHotkey(WPARAM wparam, LPARAM lparam)
{
switch (wparam) {
case TOGGLE_FULLSCREEN_MODE_HOTKEY_ID:
toggleFullscreenMode();
break;
case NEXT_WINDOW_HOTKEY_ID:
focusNextWindow(false, 0);
break;
case PREV_WINDOW_HOTKEY_ID:
focusNextWindow(true, 0);
break;
case FORCE_TILE_LIGHTWM_HOTKEY_ID:
tileWindows();
break;
}
if (wparam >= WORKSPACE_LIGHTWM_HOTKEY_ID_BASE && wparam < WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + 9) {
gotoWorkspace((int)wparam - WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + 1);
} else if (wparam >= SWITCH_WORKSPACE_HOTKEY_ID && wparam < SWITCH_WORKSPACE_HOTKEY_ID + 9) {
moveWindowToWorkspace((int)wparam - SWITCH_WORKSPACE_HOTKEY_ID + 1);
}
}