void FillDeserializedTree(tree_node *RootNode) { std::vector<window_info*> Windows = GetAllWindowsOnDisplay(KWMScreen.Current->ID); tree_node *Current = NULL; GetFirstLeafNode(RootNode, (void**)&Current); std::size_t Counter = 0, Leafs = 0; while(Current) { if(Counter < Windows.size()) Current->WindowID = Windows[Counter++]->WID; Current = GetNearestTreeNodeToTheRight(Current); ++Leafs; } if(Leafs < Windows.size() && Counter < Windows.size()) { tree_node *Root = RootNode; for(; Counter < Windows.size(); ++Counter) { while(!IsLeafNode(Root)) { if(!IsLeafNode(Root->LeftChild) && IsLeafNode(Root->RightChild)) Root = Root->RightChild; else Root = Root->LeftChild; } DEBUG("FillDeserializedTree() Create pair of leafs"); CreateLeafNodePair(KWMScreen.Current, Root, Root->WindowID, Windows[Counter]->WID, GetOptimalSplitMode(Root)); Root = RootNode; } } }
tree_node *GetFirstPseudoLeafNode(tree_node *Node) { tree_node *Leaf = GetFirstLeafNode(Node); while(Leaf && Leaf->WindowID != -1) Leaf = GetNearestNodeToTheRight(Leaf, SpaceModeBSP); return Leaf; }
tree_node *GetFirstPseudoLeafNode(tree_node *Node) { tree_node *Leaf = NULL; GetFirstLeafNode(Node, (void**)&Leaf); while(Leaf && Leaf->WindowID != -1) Leaf = GetNearestTreeNodeToTheRight(Leaf); return Leaf; }
tree_node *GetTreeNodeFromLink(tree_node *Root, link_node *Link) { if(Root && Link) { tree_node *Node = NULL; GetFirstLeafNode(Root, (void**)&Node); while(Node) { if(GetLinkNodeFromTree(Node, Link->WindowID) == Link) return Node; Node = GetNearestTreeNodeToTheRight(Node); } } return NULL; }
tree_node *GetTreeNodeFromWindowID(tree_node *Node, int WindowID) { if(Node) { tree_node *CurrentNode = NULL; GetFirstLeafNode(Node, (void**)&CurrentNode); while(CurrentNode) { if(CurrentNode->WindowID == WindowID) return CurrentNode; CurrentNode = GetNearestTreeNodeToTheRight(CurrentNode); } } return NULL; }
link_node *GetLinkNodeFromWindowID(tree_node *Root, int WindowID) { if(Root) { tree_node *Node = NULL; GetFirstLeafNode(Root, (void**)&Node); while(Node) { link_node *Link = GetLinkNodeFromTree(Node, WindowID); if(Link) return Link; Node = GetNearestTreeNodeToTheRight(Node); } } return NULL; }
void GiveFocusToScreen(int ScreenIndex) { screen_info *Screen = GetDisplayFromScreenID(ScreenIndex); if(Screen) { CGPoint CursorPos = CGPointMake(Screen->X + (Screen->Width / 2), Screen->Y + (Screen->Height / 2)); CGEventRef MoveEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CursorPos, kCGMouseButtonLeft); CGEventSetFlags(MoveEvent, 0); CGEventPost(kCGHIDEventTap, MoveEvent); CFRelease(MoveEvent); DEBUG("GiveFocusToScreen() " << ScreenIndex) UpdateActiveWindowList(Screen); tree_node *NewFocusNode = GetFirstLeafNode(Screen->Space[Screen->ActiveSpace].RootNode); SetWindowFocusByNode(NewFocusNode); } }
void GiveFocusToScreen(unsigned int ScreenIndex, tree_node *FocusNode, bool Mouse, bool UpdateFocus) { screen_info *Screen = GetDisplayFromScreenID(ScreenIndex); if(Screen && Screen != KWMScreen.Current) { KWMScreen.PrevSpace = KWMScreen.Current->ActiveSpace; KWMScreen.Current = Screen; Screen->ActiveSpace = GetActiveSpaceOfDisplay(Screen); ShouldActiveSpaceBeManaged(); space_info *Space = GetActiveSpaceOfScreen(Screen); DEBUG("GiveFocusToScreen() " << ScreenIndex << \ ": Space transition ended " << KWMScreen.PrevSpace << \ " -> " << Screen->ActiveSpace); if(UpdateFocus) { if(Space->Initialized && FocusNode) { DEBUG("Populated Screen 'Window -f Focus'"); UpdateActiveWindowList(Screen); FilterWindowList(Screen); SetWindowFocusByNode(FocusNode); MoveCursorToCenterOfFocusedWindow(); } else if(Space->Initialized && Space->RootNode) { DEBUG("Populated Screen Key/Mouse Focus"); UpdateActiveWindowList(Screen); FilterWindowList(Screen); bool WindowBelowCursor = IsAnyWindowBelowCursor(); if(Mouse && !WindowBelowCursor) ClearFocusedWindow(); else if(Mouse && WindowBelowCursor) FocusWindowBelowCursor(); if(!Mouse) { if(Space->FocusedWindowID == -1) { if(Space->Settings.Mode == SpaceModeBSP) { void *FocusNode = NULL; GetFirstLeafNode(Space->RootNode, (void**)&FocusNode); Space->FocusedWindowID = ((tree_node*)FocusNode)->WindowID; } else if(Space->Settings.Mode == SpaceModeMonocle) { if(Space->RootNode->List) Space->FocusedWindowID = Space->RootNode->List->WindowID; } } FocusWindowByID(Space->FocusedWindowID); MoveCursorToCenterOfFocusedWindow(); } } else { if(!Space->Initialized || Space->Settings.Mode == SpaceModeFloating || !Space->RootNode) { DEBUG("Uninitialized Screen"); ClearFocusedWindow(); if(!Mouse) CGWarpMouseCursorPosition(CGPointMake(Screen->X + (Screen->Width / 2), Screen->Y + (Screen->Height / 2))); if(Space->Settings.Mode != SpaceModeFloating && !Space->RootNode) { CGPoint ClickPos = GetCursorPos(); CGEventRef ClickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, ClickPos, kCGMouseButtonLeft); CGEventSetFlags(ClickEvent, 0); CGEventPost(kCGHIDEventTap, ClickEvent); CFRelease(ClickEvent); ClickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, ClickPos, kCGMouseButtonLeft); CGEventSetFlags(ClickEvent, 0); CGEventPost(kCGHIDEventTap, ClickEvent); CFRelease(ClickEvent); } } } } } }