Source

Mirror / src / monitor.cpp

Full commit
#include "monitor.h"
#include "statusBar.h"

Monitor::Monitor(xcb_rectangle_t area):
	area(area),
    currentTag(0)
{
    statusBar = nullptr;
}

Monitor::~Monitor()
{
    delete statusBar;
}

void Monitor::setStatusBar(StatusBar* newStatusBar)
{
    statusBar = newStatusBar;
    std::vector<std::string> tagNames;
    for (auto& tag : tagList)
    {
        tagNames.push_back(tag.name);
    }
    statusBar->setTagNames(tagNames);
    statusBar->setActiveTag(tagList.at(currentTag).name);
}

void Monitor::nextTag()
{
    xcb_rectangle_t rect = area;
    rect.x = 0 - rect.width;
    rect.y = 0 - rect.height;
    tagList.at(currentTag).windowContainer.layoutWindows(rect);
    currentTag++;

    if (currentTag > tagList.size()-1)
        currentTag = 0;

    tagList.at(currentTag).windowContainer.layoutWindows(area);
    statusBar->setActiveTag(tagList.at(currentTag).name);
}

void Monitor::prevTag()
{
    xcb_rectangle_t rect = area;
    rect.x = 0 - rect.width;
    rect.y = 0 - rect.height;
    tagList.at(currentTag).windowContainer.layoutWindows(rect);
    currentTag--;
    if (currentTag < 0)
    {
        currentTag = tagList.size()-1;
    }

    tagList.at(currentTag).windowContainer.layoutWindows(area);
    statusBar->setActiveTag(tagList.at(currentTag).name);

}

void Monitor::layoutWindows()
{
    tagList.at(currentTag).windowContainer.layoutWindows(area);
    xcb_rectangle_t offscreenRect = area;
    offscreenRect.y = 0 - area.height;
    offscreenRect.x = 0 - area.width;
    for (auto &tag : tagList)
    {
        if (tag.name == tagList.at(currentTag).name)
        {
            continue;
        }
        tag.windowContainer.layoutWindows(offscreenRect);
    }
}

bool Monitor::focusWindow(xcb_window_t window)
{
    int i=0;
	for (auto& tag : tagList)
    {
        auto &win = tag.windowContainer.findWindow(window);
        if (win)
        {
            tag.windowContainer.focusWindow(win);
            currentTag = i;
            return true;
        }
		i++;
    }
    return false;
}

void Monitor::addStrut(xcb_ewmh_wm_strut_partial_t strut)
{
    //add strut to struts
    //and then call recalculateStruts()
}

void Monitor::removeStrut(xcb_ewmh_wm_strut_partial_t strut)
{
    //remove strut from struts
    //and then call recalculateStruts()
    
}