72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
|
/**
|
||
|
* @author Christian Burger (christian@krikkel.de)
|
||
|
*/
|
||
|
|
||
|
#include <kNCurses/TilingWindowManager.hpp>
|
||
|
#include <kNCurses/Window.hpp>
|
||
|
#include <ncursesw/ncurses.h>
|
||
|
#include <algorithm>
|
||
|
|
||
|
namespace krikkel::NCurses
|
||
|
{
|
||
|
using std::list;
|
||
|
using std::recursive_mutex;
|
||
|
using std::scoped_lock;
|
||
|
using std::find;
|
||
|
|
||
|
TilingWindowManager::TilingWindowManager(NCursesWindow *rootWindow, recursive_mutex *ncursesMutex)
|
||
|
: rootWindow(new Window(*rootWindow)), ncursesMutex(ncursesMutex)
|
||
|
{}
|
||
|
|
||
|
void TilingWindowManager::addWindow(Window *window)
|
||
|
{
|
||
|
stack.push_back(window);
|
||
|
visibleStack.push_back(window);
|
||
|
}
|
||
|
|
||
|
void TilingWindowManager::hideWindow(Window *window)
|
||
|
{
|
||
|
visibleStack.remove(window);
|
||
|
window->hidden = true;
|
||
|
}
|
||
|
|
||
|
void TilingWindowManager::showWindow(Window *window)
|
||
|
{
|
||
|
if(!window->hidden)
|
||
|
return;
|
||
|
|
||
|
list<Window *>::iterator currentVisibleWindow = visibleStack.begin();
|
||
|
for(Window *currentWindow : stack)
|
||
|
{
|
||
|
if(currentWindow == window)
|
||
|
{
|
||
|
visibleStack.insert(currentVisibleWindow, window);
|
||
|
window->hidden = false;
|
||
|
break;
|
||
|
}
|
||
|
if(currentWindow != (*currentVisibleWindow))
|
||
|
continue;
|
||
|
++currentVisibleWindow;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TilingWindowManager::refresh()
|
||
|
{
|
||
|
scoped_lock lock(*ncursesMutex);
|
||
|
|
||
|
rootWindow->refresh();
|
||
|
for(Window *window : visibleStack)
|
||
|
window->refresh();
|
||
|
}
|
||
|
|
||
|
SingleUserInput TilingWindowManager::readSingleUserInput()
|
||
|
{
|
||
|
return rootWindow->readSingleUserInput();
|
||
|
}
|
||
|
|
||
|
void TilingWindowManager::resizeWindow(Window *window, uint16_t height, uint16_t width, uint16_t y, uint16_t x)
|
||
|
{
|
||
|
window->resize(height, width);
|
||
|
window->mvwin(y, x);
|
||
|
}
|
||
|
}
|