internal void KwmScratchpadCommand(std::vector<std::string> &Tokens, int ClientSockFD) { if(Tokens[1] == "show") { ShowScratchpadWindow(ConvertStringToInt(Tokens[2])); } else if(Tokens[1] == "toggle") { ToggleScratchpadWindow(ConvertStringToInt(Tokens[2])); } else if(Tokens[1] == "hide") { HideScratchpadWindow(ConvertStringToInt(Tokens[2])); } else if(Tokens[1] == "add") { ax_application *Application = AXLibGetFocusedApplication(); if(Application && Application->Focus) AddWindowToScratchpad(Application->Focus); } else if(Tokens[1] == "remove") { ax_application *Application = AXLibGetFocusedApplication(); if(Application && Application->Focus) RemoveWindowFromScratchpad(Application->Focus); } else if(Tokens[1] == "list") { KwmWriteToSocket(ClientSockFD, GetWindowsOnScratchpad()); } }
void FocusWindowBelowCursor() { ax_application *Application = AXLibGetFocusedApplication(); ax_window *FocusedWindow = NULL; if(Application) { FocusedWindow = Application->Focus; if(FocusedWindow && IsWindowBelowCursor(FocusedWindow)) return; } std::vector<ax_window *> Windows = AXLibGetAllVisibleWindowsOrdered(); for(std::size_t Index = 0; Index < Windows.size(); ++Index) { ax_window *Window = Windows[Index]; if(IsWindowBelowCursor(Window)) { if(Application == Window->Application) { if(FocusedWindow != Window) AXLibSetFocusedWindow(Window); } else { AXLibSetFocusedWindow(Window); } return; } } }
int main(int argc, char **argv) { if(ParseArguments(argc, argv)) return 0; NSApplicationLoad(); if(!AXLibDisplayHasSeparateSpaces()) Fatal("Error: 'Displays have separate spaces' must be enabled!"); AXLibInit(&AXState); AXLibStartEventLoop(); if(!KwmStartDaemon()) Fatal("Error: Could not start daemon!"); OverlayLibInitialize(); DEBUG("OverlayLib initialized!"); ax_display *MainDisplay = AXLibMainDisplay(); ax_display *Display = MainDisplay; do { ax_space *PrevSpace = Display->Space; Display->Space = AXLibGetActiveSpace(Display); Display->PrevSpace = PrevSpace; Display = AXLibNextDisplay(Display); } while(Display != MainDisplay); FocusedDisplay = MainDisplay; FocusedApplication = AXLibGetFocusedApplication(); KwmInit(); KwmParseConfig(KWMPath.Config); KwmExecuteInitScript(); CreateWindowNodeTree(MainDisplay); /* TODO(koekeishiya): Probably want to defer this to run at some point where we know that * the focused application is set. This is usually the case as 'Finder' is always reported * as the active application when nothing is running. The following behaviour requries * refinement, because we will (sometimes ?) get NULL when started by launchd at login */ if(FocusedApplication && FocusedApplication->Focus) UpdateBorder(&FocusedBorder, FocusedApplication->Focus); ConfigureRunLoop(); CFRunLoopRun(); return 0; }