예제 #1
0
internal void
KwmWindowCommand(std::vector<std::string> &Tokens)
{
    if(Tokens[1] == "-f")
    {
        if(Tokens[2] == "north")
            ShiftWindowFocusDirected(0);
        else if(Tokens[2] == "east")
            ShiftWindowFocusDirected(90);
        else if(Tokens[2] == "south")
            ShiftWindowFocusDirected(180);
        else if(Tokens[2] == "west")
            ShiftWindowFocusDirected(270);
        else if(Tokens[2] == "prev")
            ShiftWindowFocus(-1);
        else if(Tokens[2] == "next")
            ShiftWindowFocus(1);
        else if(Tokens[2] == "curr")
            FocusWindowBelowCursor();
        else
            FocusWindowByID(ConvertStringToUint(Tokens[2]));
    }
    else if(Tokens[1] == "-fm")
    {
        if(Tokens[2] == "prev")
            ShiftSubTreeWindowFocus(-1);
        else if(Tokens[2] == "next")
            ShiftSubTreeWindowFocus(1);
    }
    else if(Tokens[1] == "-s")
    {
        if(Tokens[2] == "north")
            SwapFocusedWindowDirected(0);
        else if(Tokens[2] == "east")
            SwapFocusedWindowDirected(90);
        else if(Tokens[2] == "south")
            SwapFocusedWindowDirected(180);
        else if(Tokens[2] == "west")
            SwapFocusedWindowDirected(270);
        else if(Tokens[2] == "prev")
            SwapFocusedWindowWithNearest(-1);
        else if(Tokens[2] == "next")
            SwapFocusedWindowWithNearest(1);
        else if(Tokens[2] == "mark")
            SwapFocusedWindowWithMarked();
    }
    else if(Tokens[1] == "-z")
    {
        if(Tokens[2] == "fullscreen")
            ToggleFocusedWindowFullscreen();
        else if(Tokens[2] == "parent")
            ToggleFocusedWindowParentContainer();
    }
    else if(Tokens[1] == "-t")
    {
        if(Tokens[2] == "focused")
            ToggleFocusedWindowFloating();
    }
    else if(Tokens[1] == "-r")
    {
        if(Tokens[2] == "focused")
            ResizeWindowToContainerSize();
    }
    else if(Tokens[1] == "-c")
    {
        if(Tokens[2] == "split-mode")
        {
            if(Tokens[3] == "toggle")
            {
                ToggleFocusedNodeSplitMode();
            }
        }
        else if(Tokens[2] == "type")
        {
            if(Tokens[3] == "monocle")
                ChangeTypeOfFocusedNode(NodeTypeLink);
            else if(Tokens[3] == "bsp")
                ChangeTypeOfFocusedNode(NodeTypeTree);
            else if(Tokens[3] == "toggle")
                ToggleTypeOfFocusedNode();
        }
        else if(Tokens[2] == "reduce" || Tokens[2] == "expand")
        {
            double Ratio = ConvertStringToDouble(Tokens[3]);
            Ratio = Tokens[2] == "reduce" ? -Ratio : Ratio;

            if(Tokens.size() == 5)
            {
                if(Tokens[4] == "north")
                    ModifyContainerSplitRatio(Ratio, 0);
                else if(Tokens[4] == "east")
                    ModifyContainerSplitRatio(Ratio, 90);
                else if(Tokens[4] == "south")
                    ModifyContainerSplitRatio(Ratio, 180);
                else if(Tokens[4] == "west")
                    ModifyContainerSplitRatio(Ratio, 270);
            }
            else
            {
                ModifyContainerSplitRatio(Ratio);
            }
        }
    }
    else if(Tokens[1] == "-m")
    {
        if(Tokens[2] == "space")
        {
            if(Tokens[3] == "previous")
                GoToPreviousSpace(true);
            else
                MoveFocusedWindowToSpace(Tokens[3]);
        }
        else if(Tokens[2] == "display")
        {
            ax_window *Window = FocusedApplication ? FocusedApplication->Focus : NULL;
            if(!Window)
                return;

            if(Tokens[3] == "prev")
                MoveWindowToDisplay(Window, -1, true);
            else if(Tokens[3] == "next")
                MoveWindowToDisplay(Window, 1, true);
            else
                MoveWindowToDisplay(Window, ConvertStringToInt(Tokens[3]), false);
        }
        else if(Tokens[2] == "north")
        {
            ax_window *Window = FocusedApplication ? FocusedApplication->Focus : NULL;
            if(Window)
                DetachAndReinsertWindow(Window->ID, 0);
        }
        else if(Tokens[2] == "east")
        {
            ax_window *Window = FocusedApplication ? FocusedApplication->Focus : NULL;
            if(Window)
                DetachAndReinsertWindow(Window->ID, 90);
        }
        else if(Tokens[2] == "south")
        {
            ax_window *Window = FocusedApplication ? FocusedApplication->Focus : NULL;
            if(Window)
                DetachAndReinsertWindow(Window->ID, 180);
        }
        else if(Tokens[2] == "west")
        {
            ax_window *Window = FocusedApplication ? FocusedApplication->Focus : NULL;
            if(Window)
                DetachAndReinsertWindow(Window->ID, 270);
        }
        else if(Tokens[2] == "mark")
        {
            if(MarkedWindow)
                DetachAndReinsertWindow(MarkedWindow->ID, 0);
        }
        else
        {
            int XOff = ConvertStringToInt(Tokens[2]);
            int YOff = ConvertStringToInt(Tokens[3]);
            MoveFloatingWindow(XOff, YOff);
        }
    }
    else if(Tokens[1] == "-mk")
    {
        if(Tokens[2] == "focused")
        {
            MarkFocusedWindowContainer();
            return;
        }

        ax_window *ClosestWindow = NULL;
        std::string Output = "-1";
        int Degrees = 0;

        if(Tokens[2] == "north")
            Degrees = 0;
        else if(Tokens[2] == "east")
            Degrees = 90;
        else if(Tokens[2] == "south")
            Degrees = 180;
        else if(Tokens[2] == "west")
            Degrees = 270;

        bool Wrap = Tokens[3] == "wrap" ? true : false;
        if((FindClosestWindow(Degrees, &ClosestWindow, Wrap)) &&
           (ClosestWindow))
            MarkWindowContainer(ClosestWindow);
    }
}
예제 #2
0
파일: display.cpp 프로젝트: JakimLi/kwm
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);
                    }
                }
            }
        }
    }
}