Skip to content

Commit c5508f0

Browse files
committed
tiling: add disable tiling hotkey and some cleanup
1 parent fa7ab52 commit c5508f0

File tree

6 files changed

+52
-32
lines changed

6 files changed

+52
-32
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ Video in which I make the PoC of this project: https://youtu.be/cuPirXZ6AWo
1414

1515
After building, run the executable ```lightwm.exe``` which will reside in the release and/or debug folder, depending on what you built.
1616

17-
Upon running, it will immediately tile all the non-minimized windows on your screen.
17+
Upon running, it will immediately tile all the non-minimized windows on your screen. The program will run in the background.
1818

19-
The program will run in the background. To quit LightWM, use ```alt+q```.
19+
If you want to configure it to run when you login, you can use the `Run` utility and type `shell:startup`, then create a LightWM shortcut in that folder.
2020

21-
You can use ```alt+j``` and ```alt+k``` to go to the next/previous window with your keyboard.
21+
### Hotkeys
2222

23-
You can use ```alt+f``` hotkey to toggle fullscreen mode which will disable tiling and put the focused window in fullscreen, pressing ```alt+f``` again will enable tiling again and tile all non-minimized windows
24-
25-
You can use ```alt+1``` up until ```alt+9``` to go to workspace number ```1``` until ```9``` respectively
26-
27-
You can move the current focused window to a different workspace number by adding ```shift``` to the above command.
28-
29-
You can "force" retile by using ```alt+t```, you can use this as a trick to send the current focused window to the left.
23+
- ```alt+q``` - quit LightWM
24+
- ```alt+j``` - focus on next window
25+
- ```alt+k``` - focus on previous window
26+
- ```alt+f``` - toggle fullscreen mode (disables tiling and puts the focused window in fullscreen, pressing ```alt+f``` again will enable tiling again and tile all non-minimized windows)
27+
- ```alt+1``` up until ```alt+9``` - go to workspace number ```1``` until ```9``` respectively
28+
- You can move the current focused window to a different workspace number by adding ```shift``` to the above command.
29+
- You can "force" retile by using ```alt+t```, you can use this as a trick to send the current focused window to the left.
30+
- `alt+\` toggles whether the automatic tiling is enabled/disabled. This is useful if you also use programs which don't play well with LightWM automatic tiling
3031

3132
## Building
3233

config.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#define TOGGLE_FULLSCREEN_MODE_HOTKEY_ID 0x00
22
#define NEXT_WINDOW_HOTKEY_ID 0x01
33
#define PREV_WINDOW_HOTKEY_ID 0x02
4-
#define QUIT_LIGHTWM_HOTKEY_ID 0x03
5-
#define FORCE_TILE_LIGHTWM_HOTKEY_ID 0x04
6-
#define WORKSPACE_LIGHTWM_HOTKEY_ID_BASE 0xFF
7-
#define SWITCH_WORKSPACE_HOTKEY_ID 0x10
4+
#define QUIT_HOTKEY_ID 0x03
5+
#define FORCE_TILE_HOTKEY_ID 0x04
6+
#define TOGGLE_DISABLE_ENABLE_TILING_HOTKEY_ID 0x05
7+
#define WORKSPACE_HOTKEY_ID_BASE 0x10
8+
#define SWITCH_WORKSPACE_HOTKEY_ID_BASE 0x20
89

910
#define FULLSCREEN_MODE_HOTKEY 'f'
1011
#define NEXT_WINDOW_HOTKEY 'j'
1112
#define PREV_WINDOW_HOTKEY 'k'
12-
#define QUIT_LIGHTWM_HOTKEY 'q'
13-
#define FORCE_TILE_LIGHTWM_HOTKEY 't'
14-
#define WORKSPACE_LIGHTWM_HOTKEY_BASE '1'
15-
#define SWITCH_WORKSPACE_HOTKEY '1'
13+
#define QUIT_HOTKEY 'q'
14+
#define FORCE_TILE_HOTKEY 't'
15+
#define TOGGLE_DISABLE_ENABLE_TILING_HOTKEY '\\'

keyboard.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ bool initializeKeyboardConfig()
2222
addKeyboardKeybind(TOGGLE_FULLSCREEN_MODE_HOTKEY_ID, getKeyCode(FULLSCREEN_MODE_HOTKEY), MOD_ALT | MOD_NOREPEAT);
2323
addKeyboardKeybind(NEXT_WINDOW_HOTKEY_ID, getKeyCode(NEXT_WINDOW_HOTKEY), MOD_ALT | MOD_NOREPEAT);
2424
addKeyboardKeybind(PREV_WINDOW_HOTKEY_ID, getKeyCode(PREV_WINDOW_HOTKEY), MOD_ALT | MOD_NOREPEAT);
25-
addKeyboardKeybind(QUIT_LIGHTWM_HOTKEY_ID, getKeyCode(QUIT_LIGHTWM_HOTKEY), MOD_ALT | MOD_NOREPEAT);
26-
addKeyboardKeybind(FORCE_TILE_LIGHTWM_HOTKEY_ID, getKeyCode(FORCE_TILE_LIGHTWM_HOTKEY), MOD_ALT | MOD_NOREPEAT);
25+
addKeyboardKeybind(QUIT_HOTKEY_ID, getKeyCode(QUIT_HOTKEY), MOD_ALT | MOD_NOREPEAT);
26+
addKeyboardKeybind(FORCE_TILE_HOTKEY_ID, getKeyCode(FORCE_TILE_HOTKEY), MOD_ALT | MOD_NOREPEAT);
27+
addKeyboardKeybind(TOGGLE_DISABLE_ENABLE_TILING_HOTKEY_ID, getKeyCode(TOGGLE_DISABLE_ENABLE_TILING_HOTKEY), MOD_ALT | MOD_NOREPEAT);
2728

2829
for (int i = 0; i < 9; i++) {
29-
addKeyboardKeybind(WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + i, getKeyCode('1' + i), MOD_ALT | MOD_NOREPEAT);
30+
addKeyboardKeybind(WORKSPACE_HOTKEY_ID_BASE + i, getKeyCode('1' + i), MOD_ALT | MOD_NOREPEAT);
3031
}
3132

3233
for (int i = 0; i < 9; i++) {
33-
addKeyboardKeybind(SWITCH_WORKSPACE_HOTKEY_ID + i, getKeyCode('1' + i), MOD_ALT | MOD_SHIFT | MOD_NOREPEAT);
34+
addKeyboardKeybind(SWITCH_WORKSPACE_HOTKEY_ID_BASE + i, getKeyCode('1' + i), MOD_ALT | MOD_SHIFT | MOD_NOREPEAT);
3435
}
3536

3637
return true;
@@ -41,12 +42,13 @@ void cleanupKeyboard()
4142
UnregisterHotKey(NULL, TOGGLE_FULLSCREEN_MODE_HOTKEY_ID);
4243
UnregisterHotKey(NULL, NEXT_WINDOW_HOTKEY_ID);
4344
UnregisterHotKey(NULL, PREV_WINDOW_HOTKEY_ID);
44-
UnregisterHotKey(NULL, QUIT_LIGHTWM_HOTKEY_ID);
45-
UnregisterHotKey(NULL, FORCE_TILE_LIGHTWM_HOTKEY_ID);
45+
UnregisterHotKey(NULL, QUIT_HOTKEY_ID);
46+
UnregisterHotKey(NULL, FORCE_TILE_HOTKEY_ID);
47+
UnregisterHotKey(NULL, TOGGLE_DISABLE_ENABLE_TILING_HOTKEY_ID);
4648

4749
for (int i = 0; i < 9; i++) {
48-
UnregisterHotKey(NULL, WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + i);
49-
UnregisterHotKey(NULL, SWITCH_WORKSPACE_HOTKEY_ID + i);
50+
UnregisterHotKey(NULL, WORKSPACE_HOTKEY_ID_BASE + i);
51+
UnregisterHotKey(NULL, SWITCH_WORKSPACE_HOTKEY_ID_BASE + i);
5052
}
5153
}
5254

@@ -62,14 +64,17 @@ void handleHotkey(WPARAM wparam, LPARAM lparam)
6264
case PREV_WINDOW_HOTKEY_ID:
6365
focusNextWindow(true, 0);
6466
break;
65-
case FORCE_TILE_LIGHTWM_HOTKEY_ID:
67+
case FORCE_TILE_HOTKEY_ID:
6668
tileWindows();
6769
break;
70+
case TOGGLE_DISABLE_ENABLE_TILING_HOTKEY_ID:
71+
toggleDisableEnableTiling();
72+
break;
6873
}
6974

70-
if (wparam >= WORKSPACE_LIGHTWM_HOTKEY_ID_BASE && wparam < WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + 9) {
71-
gotoWorkspace((int)wparam - WORKSPACE_LIGHTWM_HOTKEY_ID_BASE + 1);
72-
} else if (wparam >= SWITCH_WORKSPACE_HOTKEY_ID && wparam < SWITCH_WORKSPACE_HOTKEY_ID + 9) {
73-
moveWindowToWorkspace((int)wparam - SWITCH_WORKSPACE_HOTKEY_ID + 1);
75+
if (wparam >= WORKSPACE_HOTKEY_ID_BASE && wparam < WORKSPACE_HOTKEY_ID_BASE + 9) {
76+
gotoWorkspace((int)wparam - WORKSPACE_HOTKEY_ID_BASE + 1);
77+
} else if (wparam >= SWITCH_WORKSPACE_HOTKEY_ID_BASE && wparam < SWITCH_WORKSPACE_HOTKEY_ID_BASE + 9) {
78+
moveWindowToWorkspace((int)wparam - SWITCH_WORKSPACE_HOTKEY_ID_BASE + 1);
7479
}
7580
}

tiling.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct {
1111
} ManagedWindow;
1212

1313
bool isFullscreen = false;
14+
bool isTilingEnabled = true;
1415
HWND managed[MAX_MANAGED];
1516
ManagedWindow totalManaged[MAX_MANAGED];
1617
int numOfTotalManaged = 0;
@@ -127,6 +128,10 @@ void updateManagedWindows()
127128

128129
void tileWindows()
129130
{
131+
if (!isTilingEnabled) {
132+
return;
133+
}
134+
130135
if (newWorkspace) {
131136
newWorkspace = false;
132137
} else {
@@ -213,3 +218,11 @@ void moveWindowToWorkspace(int workspaceNumber)
213218
managedWindow->workspaceNumber = workspaceNumber;
214219
tileWindows();
215220
}
221+
222+
void toggleDisableEnableTiling() {
223+
isTilingEnabled = !isTilingEnabled;
224+
225+
if (isTilingEnabled) {
226+
tileWindows();
227+
}
228+
}

tiling.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ void toggleFullscreenMode();
88
void focusNextWindow(bool, unsigned int);
99
void gotoWorkspace(int);
1010
void moveWindowToWorkspace(int);
11+
void toggleDisableEnableTiling();

wm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prevInstance, PWSTR cmdLine, i
6666
while (GetMessage(&msg, (HWND)-1, 0, 0) != 0) {
6767
switch (msg.message) {
6868
case WM_HOTKEY:
69-
if (msg.wParam == QUIT_LIGHTWM_HOTKEY_ID) {
69+
if (msg.wParam == QUIT_HOTKEY_ID) {
7070
exitCode = EXIT_OK;
7171
goto cleanup;
7272
}

0 commit comments

Comments
 (0)