kNCurses/TilingWindowManager.cpp
Christian Burger 0a086ff604 horizontal window manager now resizes correctly
Window managers are now descendants of windows instead of owning the
window in which they exist. This makes a clean window hierarchy.
2022-05-08 22:52:23 +02:00

82 lines
2.1 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;
TilingWindowManager::TilingWindowManager(NCursesWindow *rootWindow, recursive_mutex *ncursesMutex)
: 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;
}
}
int TilingWindowManager::resize(int rows, int cols)
{
int result = Window::resize(rows, cols);
updateLayout();
return result;
}
int TilingWindowManager::refresh()
{
scoped_lock lock(*ncursesMutex);
int result = Window::refresh();
for(Window *window : visibleStack)
// @todo there are return values; compound them?
window->refresh();
return result;
}
SingleUserInput TilingWindowManager::readSingleUserInput()
{
return Window::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);
}
}