Ejemplo n.º 1
0
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());
    }
}
Ejemplo n.º 2
0
/* TODO(koekeishiya): This entire system is just stupid. Reimplement in a proper way. */
bool ApplyWindowRules(ax_window *Window)
{
    bool Skip = false;
    for(int Index = 0; Index < KWMSettings.WindowRules.size(); ++Index)
    {
        window_rule *Rule = &KWMSettings.WindowRules[Index];
        if(MatchWindowRule(Rule, Window))
        {
            if(Rule->Properties.Float == 1)
                AXLibAddFlags(Window, AXWindow_Floating);

            if(!Rule->Properties.Role.empty())
                Window->Type.CustomRole = CFStringCreateWithCString(NULL,
                                                                    Rule->Properties.Role.c_str(),
                                                                    kCFStringEncodingMacRoman);

            if(Rule->Properties.Scratchpad != -1)
            {
                AddWindowToScratchpad(Window);
                if(Rule->Properties.Scratchpad == 0)
                {
                    HideScratchpadWindow(GetScratchpadSlotOfWindow(Window));
                    Skip = true;
                }
            }

            if(Rule->Properties.Display != -1 && Rule->Properties.Space == -1)
            {
                if(!AXLibIsWindowStandard(Window) &&
                   !AXLibIsWindowCustom(Window))
                    continue;

                ax_display *Display = AXLibArrangementDisplay(Rule->Properties.Display);
                if(Display && Display != AXLibWindowDisplay(Window))
                {
                    MoveWindowToDisplay(Window, Display->ArrangementID, false);
                    Skip = true;
                }
            }

            if(Rule->Properties.Space != -1)
            {
                if(!AXLibIsWindowStandard(Window) &&
                   !AXLibIsWindowCustom(Window))
                    continue;

                int Display = Rule->Properties.Display == -1 ? 0 : Rule->Properties.Display;
                ax_display *SourceDisplay = AXLibWindowDisplay(Window);
                ax_display *DestinationDisplay = AXLibArrangementDisplay(Display);
                int TotalSpaces = AXLibDisplaySpacesCount(DestinationDisplay);
                if(Rule->Properties.Space <= TotalSpaces && Rule->Properties.Space >= 1)
                {
                    int SourceCGSSpaceID = SourceDisplay->Space->ID;
                    int DestinationCGSSpaceID = AXLibCGSSpaceIDFromDesktopID(DestinationDisplay, Rule->Properties.Space);
                    if(!AXLibSpaceHasWindow(Window, DestinationCGSSpaceID))
                    {
                        AXLibSpaceAddWindow(DestinationCGSSpaceID, Window->ID);
                        AXLibSpaceRemoveWindow(SourceCGSSpaceID, Window->ID);
                        Skip = true;
                    }
                }
            }
        }
    }

    return Skip;
}