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::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);
    //tagList.at(currentTag).windowContainer.raiseAll();
    statusBar->setText(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);
    //tagList.at(currentTag).windowContainer.raiseAll();
    statusBar->setText(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)
        {
            std::cerr << "trying to focus " << win.name << std::endl;
            tag.windowContainer.focusWindow(win);
            currentTag = i;
            return true;
        }
		i++;
    }
    return false;
}