void SwapWindowWithFirstNonMasterWindow() { node* head = tags[current_tag].nodes; node* current = tags[current_tag].current_window; int sub_node_idx = tags[current_tag].masterarea_count; if (current != head) { node* nd = FindNodeInChain(head, sub_node_idx); SwapWindowWithNode(nd); } }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { node *current = NULL; node *nodes; unsigned short tag; switch (msg) { case WM_CREATE: if (experimental_mouse) { SetTimer(hwnd, TIMER_UPDATE_MOUSE, 500, NULL); // Poll for mouse position } break; case WM_CLOSE: { ClipCursor(0); // Release Cursor Lock DeregisterShellHookWindow(hwnd); UnregisterHotkeys(hwnd); if (experimental_mouse) { KillTimer(hwnd, TIMER_UPDATE_MOUSE); // Mouse Poll Timer } for (tag=0; tag<TAGS; tag++) { nodes = tags[tag].nodes; for (current = nodes; current;) { node *next = current->next; RestoreWindow(current->hwnd); RemoveNode(current->hwnd, tag); current = next; } DestroyWindow(hwnd); } } break; case WM_DESTROY: PostQuitMessage(WM_QUIT); break; case WM_HOTKEY: if (wParam >= KEY_TOGGLE_T1 && wParam < (KEY_TOGGLE_T1 + TAGS)) { ToggleTag(wParam - KEY_TOGGLE_T1); break; } else if (wParam >= KEY_SWITCH_T1 && wParam < (KEY_SWITCH_T1 + TAGS)) { MinimizeTag(current_tag); current_tag = wParam - KEY_SWITCH_T1; ArrangeWindows(); break; } current = tags[current_tag].current_window; switch (wParam) { case KEY_SELECT_UP: if (current) { tags[current_tag].current_window = GetNextNode(); FocusCurrent(); } break; case KEY_SELECT_DOWN: if (current) { tags[current_tag].current_window = GetPreviousNode(); FocusCurrent(); } break; case KEY_MOVE_MAIN: SwapWindowWithNode(tags[current_tag].nodes); ArrangeWindows(); break; case KEY_EXIT: PostMessage(hwnd, WM_CLOSE, 0, 0); break; case KEY_MARGIN_LEFT: margin -= 20; ArrangeWindows(); break; case KEY_MARGIN_RIGHT: margin += 20; ArrangeWindows(); break; case KEY_IGNORE: if (!disableNext) { disableNext = 1; } else { disableNext = 0; } break; case KEY_MOUSE_LOCK: if (lockMouse) { lockMouse = 0; ClipCursor(0); } else { lockMouse = 1; FocusCurrent(); } break; case KEY_TILING_MODE: tags[current_tag].tilingMode = (tags[current_tag].tilingMode + 1) % 3; ArrangeWindows(); break; case KEY_MOVE_UP: if (current) { SwapWindowWithNode(GetNextNode()); ArrangeWindows(); } break; case KEY_MOVE_DOWN: if (current) { SwapWindowWithNode(GetPreviousNode()); ArrangeWindows(); } break; case KEY_DISP_CLASS: { LPSTR temp = (LPSTR)malloc(sizeof(TCHAR) * 128); GetClassName(GetForegroundWindow(), temp, 128); MessageBox(NULL, temp, "Window Class", MB_OK); free(temp); } break; case KEY_TILE: if (IsGoodWindow(GetForegroundWindow())) { AddNode(GetForegroundWindow(), current_tag); ArrangeWindows(); } break; case KEY_UNTILE: FullRemoveNode(GetForegroundWindow()); ArrangeWindows(); break; case KEY_INC_AREA: tags[current_tag].masterarea_count++; ArrangeWindows(); break; case KEY_DEC_AREA: tags[current_tag].masterarea_count--; ArrangeWindows(); break; case KEY_CLOSE_WIN: PostMessage(GetForegroundWindow(), WM_CLOSE, 0, 0); break; } break; case WM_TIMER: switch (wParam) { case TIMER_UPDATE_MOUSE: UpdateMousePos(hwnd); break; } break; default: if (msg == shellhookid) { // Handle the Shell Hook message switch (wParam) { case HSHELL_WINDOWCREATED: if (IsGoodWindow((HWND)lParam)) { AddNode((HWND)lParam, current_tag); ArrangeWindows(); FocusCurrent(); } break; case HSHELL_WINDOWDESTROYED: FullRemoveNode((HWND)lParam); ArrangeWindows(); FocusCurrent(); break; case HSHELL_WINDOWACTIVATED: { node *found = FindNode((HWND)lParam, current_tag); if (found) { tags[current_tag].current_window = current = found; FocusCurrent(); } } break; } } else { return DefWindowProc(hwnd, msg, wParam, lParam); } } return 0; }