<commit_before>#include "kwm.h"

static CGWindowListOption OsxWindowListOption = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;

extern kwm_screen KWMScreen;
extern kwm_focus KWMFocus;
extern kwm_toggles KWMToggles;
extern kwm_mode KWMMode;
extern kwm_tiling KWMTiling;
extern kwm_cache KWMCache;
extern kwm_path KWMPath;
extern kwm_border KWMBorder;

void FocusedAXObserverCallback(AXObserverRef Observer, AXUIElementRef Element, CFStringRef Notification, void *ContextData)
{
    UpdateBorder("focused");
}

void ClearFocusedBorder()
{
    if(KWMBorder.FHandle)
    {
        std::string Border = "clear";
        fwrite(Border.c_str(), Border.size(), 1, KWMBorder.FHandle);
        fflush(KWMBorder.FHandle);
    }
}

kwm_time_point PerformUpdateBorderTimer(kwm_time_point Time)
{
    kwm_time_point NewBorderTime = std::chrono::steady_clock::now();
    std::chrono::duration<double> Diff = NewBorderTime - Time;
    while(Diff.count() < 0.10)
    {
        NewBorderTime = std::chrono::steady_clock::now();
        Diff = NewBorderTime - Time;
    }

    return NewBorderTime;
}

void UpdateBorder(std::string Border)
{
    if(Border == "focused")
    {
        if(KWMBorder.FEnabled)
        {
            if(KWMFocus.Window)
            {
                if(!KWMBorder.FHandle)
                {
                    std::string OverlayBin = KWMPath.FilePath + "/kwm-overlay";
                    KWMBorder.FHandle = popen(OverlayBin.c_str(), "w");
                    if(KWMBorder.FHandle == NULL)
                    {
                        KWMBorder.FEnabled = false;
                        return;
                    }
                }

                DEBUG("UpdateFocusedBorder()")
                KWMBorder.FTime = PerformUpdateBorderTimer(KWMBorder.FTime);
<commit_msg>fixes #89 - only allow border for windows with window-layer == 0<commit_after>#include "kwm.h"

static CGWindowListOption OsxWindowListOption = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;

extern kwm_screen KWMScreen;
extern kwm_focus KWMFocus;
extern kwm_toggles KWMToggles;
extern kwm_mode KWMMode;
extern kwm_tiling KWMTiling;
extern kwm_cache KWMCache;
extern kwm_path KWMPath;
extern kwm_border KWMBorder;

void FocusedAXObserverCallback(AXObserverRef Observer, AXUIElementRef Element, CFStringRef Notification, void *ContextData)
{
    UpdateBorder("focused");
}

void ClearFocusedBorder()
{
    if(KWMBorder.FHandle)
    {
        std::string Border = "clear";
        fwrite(Border.c_str(), Border.size(), 1, KWMBorder.FHandle);
        fflush(KWMBorder.FHandle);
    }
}

kwm_time_point PerformUpdateBorderTimer(kwm_time_point Time)
{
    kwm_time_point NewBorderTime = std::chrono::steady_clock::now();
    std::chrono::duration<double> Diff = NewBorderTime - Time;
    while(Diff.count() < 0.10)
    {
        NewBorderTime = std::chrono::steady_clock::now();
        Diff = NewBorderTime - Time;
    }

    return NewBorderTime;
}

void UpdateBorder(std::string Border)
{
    if(Border == "focused")
    {
        if(KWMBorder.FEnabled)
        {
            if(KWMFocus.Window && KWMFocus.Window->Layer == 0)
            {
                if(!KWMBorder.FHandle)
                {
                    std::string OverlayBin = KWMPath.FilePath + "/kwm-overlay";
                    KWMBorder.FHandle = popen(OverlayBin.c_str(), "w");
                    if(KWMBorder.FHandle == NULL)
                    {
                        KWMBorder.FEnabled = false;
                        return;
                    }
                }

                DEBUG("UpdateFocusedBorder()")
                KWMBorder.FTime = PerformUpdateBorderTimer(KWMBorder.FTime);

{'fraction_non_alphanumeric': 0.09989200863930886, 'fraction_numerical': 0.0032397408207343412, 'mean_word_length': 2.5285714285714285, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7506955', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1165, 'n_words': 199}