Skip to content

Commit

Permalink
Improve the logic of full screen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nir9 committed Jun 29, 2024
1 parent 3a6c1df commit d513b5f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The program will run in the background. To quit LightWM, use ```alt+q```.

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

You can use ```alt+f``` hotkey to toggle focus 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
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

You can use ```alt+1``` up until ```alt+9``` to go to workspace number ```1``` until ```9``` respectively

Expand Down
4 changes: 2 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#define TOGGLE_FOCUS_MODE_HOYKEY_ID 0x00
#define TOGGLE_FULLSCREEN_MODE_HOYKEY_ID 0x00
#define NEXT_WINDOW_HOTKEY_ID 0x01
#define PREV_WINDOW_HOTKEY_ID 0x02
#define QUIT_LIGHTWM_HOTKEY_ID 0x03
#define FORCE_TILE_LIGHTWM_HOTKEY_ID 0x04
#define WORKSPACE_LIGHTWM_HOTKEY_ID_BASE 0xFF

#define FOCUS_MODE_HOTKEY 'f'
#define FULLSCREEN_MODE_HOTKEY 'f'
#define NEXT_WINDOW_HOTKEY 'j'
#define PREV_WINDOW_HOTKEY 'k'
#define QUIT_LIGHTWM_HOTKEY 'q'
Expand Down
8 changes: 4 additions & 4 deletions keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void addKeyboardKeybind(int id, UINT keyCode)

bool initializeKeyboardConfig()
{
addKeyboardKeybind(TOGGLE_FOCUS_MODE_HOYKEY_ID, getKeyCode(FOCUS_MODE_HOTKEY));
addKeyboardKeybind(TOGGLE_FULLSCREEN_MODE_HOYKEY_ID, getKeyCode(FULLSCREEN_MODE_HOTKEY));
addKeyboardKeybind(NEXT_WINDOW_HOTKEY_ID, getKeyCode(NEXT_WINDOW_HOTKEY));
addKeyboardKeybind(PREV_WINDOW_HOTKEY_ID, getKeyCode(PREV_WINDOW_HOTKEY));
addKeyboardKeybind(QUIT_LIGHTWM_HOTKEY_ID, getKeyCode(QUIT_LIGHTWM_HOTKEY));
Expand All @@ -33,7 +33,7 @@ bool initializeKeyboardConfig()

void cleanupKeyboard()
{
UnregisterHotKey(NULL, TOGGLE_FOCUS_MODE_HOYKEY_ID);
UnregisterHotKey(NULL, TOGGLE_FULLSCREEN_MODE_HOYKEY_ID);
UnregisterHotKey(NULL, NEXT_WINDOW_HOTKEY_ID);
UnregisterHotKey(NULL, PREV_WINDOW_HOTKEY_ID);
UnregisterHotKey(NULL, QUIT_LIGHTWM_HOTKEY_ID);
Expand All @@ -46,8 +46,8 @@ void cleanupKeyboard()
void handleHotkey(WPARAM wparam, LPARAM lparam)
{
switch (wparam) {
case TOGGLE_FOCUS_MODE_HOYKEY_ID:
toggleFocusedWindow(GetForegroundWindow());
case TOGGLE_FULLSCREEN_MODE_HOYKEY_ID:
toggleFullscreenMode();
break;
case PREV_WINDOW_HOTKEY_ID:
focusNextWindow(true);
Expand Down
35 changes: 14 additions & 21 deletions tiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
typedef struct {
HWND handle;
int workspaceNumber;
bool isFocused;
bool shouldCleanup;
} ManagedWindow;

HWND focusedWindow = 0;
bool isFullscreen = false;
HWND managed[MAX_MANAGED];
ManagedWindow totalManaged[MAX_MANAGED];
int numOfTotalManaged = 0;
Expand Down Expand Up @@ -89,7 +88,6 @@ BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam)
}

totalManaged[numOfTotalManaged].handle = hwnd;
totalManaged[numOfTotalManaged].isFocused = false;
totalManaged[numOfTotalManaged].workspaceNumber = currentWorkspace;
totalManaged[numOfTotalManaged].shouldCleanup = false;
numOfTotalManaged++;
Expand All @@ -101,17 +99,17 @@ void updateManagedWindows()
{
numOfCurrentlyManaged = 0;

if (isFullscreen) {
managed[0] = GetForegroundWindow();
numOfCurrentlyManaged = 1;
return;
}

for (int i = 0; i < numOfTotalManaged; i++) {
if (totalManaged[i].workspaceNumber != currentWorkspace) {
continue;
}

if (totalManaged[i].isFocused) {
managed[0] = totalManaged[i].handle;
numOfCurrentlyManaged = 1;
break;
}

managed[numOfCurrentlyManaged] = totalManaged[i].handle;
ShowWindow(managed[numOfCurrentlyManaged], SW_RESTORE);
numOfCurrentlyManaged++;
Expand All @@ -123,7 +121,9 @@ void tileWindows()
if (newWorkspace) {
newWorkspace = false;
} else {
cleanupWorkspaceWindows();
if (!isFullscreen) {
cleanupWorkspaceWindows();
}
}

EnumChildWindows(GetDesktopWindow(), EnumChildProc, 0);
Expand All @@ -137,24 +137,17 @@ void tileWindows()
TileWindows(GetDesktopWindow(), MDITILE_VERTICAL | MDITILE_SKIPDISABLED, NULL, numOfCurrentlyManaged, managed);
}

void toggleFocusedWindow(HWND hwnd)
void toggleFullscreenMode()
{
if (focusedWindow != NULL) {
searchManaged(focusedWindow)->isFocused = false;
focusedWindow = NULL;
} else {
focusedWindow = hwnd;
searchManaged(focusedWindow)->isFocused = true;
}

isFullscreen = !isFullscreen;
newWorkspace = true;
tileWindows();
}

void focusNextWindow(bool goBack)
{
if (focusedWindow != NULL) {
toggleFocusedWindow(NULL);
if (isFullscreen) {
toggleFullscreenMode();
}

currentFocusedWindowIndex += goBack ? -1 : 1;
Expand Down
2 changes: 1 addition & 1 deletion tiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include <stdbool.h>

void tileWindows();
void toggleFocusedWindow(HWND hwnd);
void toggleFullscreenMode();
void focusNextWindow(bool goBack);
void gotoWorkspace(int number);

0 comments on commit d513b5f

Please sign in to comment.