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.
This commit is contained in:
parent
9ddb769cb4
commit
0a086ff604
13
DemoApp.cpp
13
DemoApp.cpp
|
@ -35,18 +35,19 @@ namespace krikkel::NCurses
|
||||||
{
|
{
|
||||||
windowManager
|
windowManager
|
||||||
= new VerticalTilingWindowManager(Root_Window, &ncursesMutex);
|
= new VerticalTilingWindowManager(Root_Window, &ncursesMutex);
|
||||||
|
topWindowManager
|
||||||
|
= new HorizontalTilingWindowManager(new Window(), &ncursesMutex);
|
||||||
|
|
||||||
dummyWindowTop = new Window(windowManager);
|
windowManager->addWindow(topWindowManager);
|
||||||
ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
|
ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
|
||||||
windowManager->addWindow(ptyWindow);
|
windowManager->addWindow(ptyWindow);
|
||||||
dummyWindowBottom = new Window(windowManager);
|
dummyWindowBottom = new Window(windowManager);
|
||||||
windowManager->updateLayout();
|
windowManager->updateLayout();
|
||||||
windowManager->refresh();
|
windowManager->refresh();
|
||||||
|
|
||||||
topWindowManager
|
|
||||||
= new HorizontalTilingWindowManager(dummyWindowTop, &ncursesMutex);
|
|
||||||
dummyWindowTopLeft = new Window(topWindowManager);
|
dummyWindowTopLeft = new Window(topWindowManager);
|
||||||
dummyWindowTopRight = new Window(topWindowManager);
|
dummyWindowTopRight = new Window(topWindowManager);
|
||||||
|
|
||||||
topWindowManager->updateLayout();
|
topWindowManager->updateLayout();
|
||||||
topWindowManager->refresh();
|
topWindowManager->refresh();
|
||||||
}
|
}
|
||||||
|
@ -93,10 +94,10 @@ namespace krikkel::NCurses
|
||||||
windowManager->updateLayout();
|
windowManager->updateLayout();
|
||||||
break;
|
break;
|
||||||
case KEY_F(1):
|
case KEY_F(1):
|
||||||
if(dummyWindowTop->isHidden())
|
if(topWindowManager->isHidden())
|
||||||
windowManager->showWindow(dummyWindowTop);
|
windowManager->showWindow(topWindowManager);
|
||||||
else
|
else
|
||||||
windowManager->hideWindow(dummyWindowTop);
|
windowManager->hideWindow(topWindowManager);
|
||||||
windowManager->updateLayout();
|
windowManager->updateLayout();
|
||||||
windowManager->refresh();
|
windowManager->refresh();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace krikkel::NCurses
|
||||||
private:
|
private:
|
||||||
VerticalTilingWindowManager *windowManager;
|
VerticalTilingWindowManager *windowManager;
|
||||||
HorizontalTilingWindowManager *topWindowManager;
|
HorizontalTilingWindowManager *topWindowManager;
|
||||||
Window *dummyWindowTop, *dummyWindowBottom, *dummyWindowTopLeft,
|
Window *dummyWindowBottom, *dummyWindowTopLeft,
|
||||||
*dummyWindowTopRight;
|
*dummyWindowTopRight;
|
||||||
PtyWindow *ptyWindow;
|
PtyWindow *ptyWindow;
|
||||||
std::recursive_mutex ncursesMutex;
|
std::recursive_mutex ncursesMutex;
|
||||||
|
|
|
@ -19,16 +19,17 @@ namespace krikkel::NCurses
|
||||||
|
|
||||||
void HorizontalTilingWindowManager::updateLayout()
|
void HorizontalTilingWindowManager::updateLayout()
|
||||||
{
|
{
|
||||||
|
scoped_lock lock(*ncursesMutex);
|
||||||
|
|
||||||
size_t stackSize = visibleStack.size();
|
size_t stackSize = visibleStack.size();
|
||||||
if(stackSize == 0)
|
if(stackSize == 0)
|
||||||
{
|
{
|
||||||
rootWindow->clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_lock lock(*ncursesMutex);
|
int availableWidth = width();
|
||||||
int availableWidth = rootWindow->width();
|
int availableHeight = height();
|
||||||
int availableHeight = rootWindow->height();
|
|
||||||
int windowWidth = availableWidth / stackSize - 1;
|
int windowWidth = availableWidth / stackSize - 1;
|
||||||
|
|
||||||
if((windowWidth + 1) * stackSize < availableWidth)
|
if((windowWidth + 1) * stackSize < availableWidth)
|
||||||
|
@ -43,8 +44,8 @@ namespace krikkel::NCurses
|
||||||
resizeWindow(*it++, availableHeight, windowWidth, 0, x);
|
resizeWindow(*it++, availableHeight, windowWidth, 0, x);
|
||||||
x += windowWidth;
|
x += windowWidth;
|
||||||
{
|
{
|
||||||
rootWindow->move(0, x++);
|
move(0, x++);
|
||||||
rootWindow->vline(availableHeight);
|
vline(availableHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resizeWindow(*it, availableHeight, availableWidth - x, 0, x);
|
resizeWindow(*it, availableHeight, availableWidth - x, 0, x);
|
||||||
|
|
|
@ -12,10 +12,9 @@ namespace krikkel::NCurses
|
||||||
using std::list;
|
using std::list;
|
||||||
using std::recursive_mutex;
|
using std::recursive_mutex;
|
||||||
using std::scoped_lock;
|
using std::scoped_lock;
|
||||||
using std::find;
|
|
||||||
|
|
||||||
TilingWindowManager::TilingWindowManager(NCursesWindow *rootWindow, recursive_mutex *ncursesMutex)
|
TilingWindowManager::TilingWindowManager(NCursesWindow *rootWindow, recursive_mutex *ncursesMutex)
|
||||||
: rootWindow(new Window(*rootWindow)), ncursesMutex(ncursesMutex)
|
: Window(*rootWindow), ncursesMutex(ncursesMutex)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void TilingWindowManager::addWindow(Window *window)
|
void TilingWindowManager::addWindow(Window *window)
|
||||||
|
@ -50,18 +49,29 @@ namespace krikkel::NCurses
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilingWindowManager::refresh()
|
int TilingWindowManager::resize(int rows, int cols)
|
||||||
|
{
|
||||||
|
int result = Window::resize(rows, cols);
|
||||||
|
updateLayout();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TilingWindowManager::refresh()
|
||||||
{
|
{
|
||||||
scoped_lock lock(*ncursesMutex);
|
scoped_lock lock(*ncursesMutex);
|
||||||
|
|
||||||
rootWindow->refresh();
|
int result = Window::refresh();
|
||||||
|
|
||||||
for(Window *window : visibleStack)
|
for(Window *window : visibleStack)
|
||||||
|
// @todo there are return values; compound them?
|
||||||
window->refresh();
|
window->refresh();
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleUserInput TilingWindowManager::readSingleUserInput()
|
SingleUserInput TilingWindowManager::readSingleUserInput()
|
||||||
{
|
{
|
||||||
return rootWindow->readSingleUserInput();
|
return Window::readSingleUserInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilingWindowManager::resizeWindow(Window *window, uint16_t height, uint16_t width, uint16_t y, uint16_t x)
|
void TilingWindowManager::resizeWindow(Window *window, uint16_t height, uint16_t width, uint16_t y, uint16_t x)
|
||||||
|
|
|
@ -19,16 +19,17 @@ namespace krikkel::NCurses
|
||||||
|
|
||||||
void VerticalTilingWindowManager::updateLayout()
|
void VerticalTilingWindowManager::updateLayout()
|
||||||
{
|
{
|
||||||
|
scoped_lock lock(*ncursesMutex);
|
||||||
|
|
||||||
size_t stackSize = visibleStack.size();
|
size_t stackSize = visibleStack.size();
|
||||||
if(stackSize == 0)
|
if(stackSize == 0)
|
||||||
{
|
{
|
||||||
rootWindow->clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_lock lock(*ncursesMutex);
|
int availableWidth = width();
|
||||||
int availableWidth = rootWindow->width();
|
int availableHeight = height();
|
||||||
int availableHeight = rootWindow->height();
|
|
||||||
int windowHeight = availableHeight / stackSize - 1;
|
int windowHeight = availableHeight / stackSize - 1;
|
||||||
|
|
||||||
if((windowHeight + 1) * stackSize < availableHeight)
|
if((windowHeight + 1) * stackSize < availableHeight)
|
||||||
|
@ -43,8 +44,8 @@ namespace krikkel::NCurses
|
||||||
resizeWindow(*it++, windowHeight, availableWidth, y, 0);
|
resizeWindow(*it++, windowHeight, availableWidth, y, 0);
|
||||||
y += windowHeight;
|
y += windowHeight;
|
||||||
{
|
{
|
||||||
rootWindow->move(y++, 0);
|
move(y++, 0);
|
||||||
rootWindow->hline(availableWidth);
|
hline(availableWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resizeWindow(*it, availableHeight - y, availableWidth, y, 0);
|
resizeWindow(*it, availableHeight - y, availableWidth, y, 0);
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
namespace krikkel::NCurses
|
namespace krikkel::NCurses
|
||||||
{
|
{
|
||||||
|
Window::Window() : NCursesWindow(0, 0, 0, 0)
|
||||||
|
{}
|
||||||
|
|
||||||
Window::Window(TilingWindowManager *windowManager)
|
Window::Window(TilingWindowManager *windowManager)
|
||||||
: NCursesWindow(0, 0, 0, 0)
|
: NCursesWindow(0, 0, 0, 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,21 +6,21 @@
|
||||||
#ifndef C51BA18F_0915_43B9_BD5D_129F0CDBC1CD
|
#ifndef C51BA18F_0915_43B9_BD5D_129F0CDBC1CD
|
||||||
#define C51BA18F_0915_43B9_BD5D_129F0CDBC1CD
|
#define C51BA18F_0915_43B9_BD5D_129F0CDBC1CD
|
||||||
|
|
||||||
#include <ncursesw/cursesw.h>
|
#include "Window.hpp"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace krikkel::NCurses
|
namespace krikkel::NCurses
|
||||||
{
|
{
|
||||||
class Window;
|
|
||||||
class SingleUserInput;
|
class SingleUserInput;
|
||||||
|
|
||||||
class TilingWindowManager
|
class TilingWindowManager : public Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex);
|
TilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex);
|
||||||
void addWindow(Window *window);
|
void addWindow(Window *window);
|
||||||
void refresh();
|
int resize(int rows, int cols) override;
|
||||||
|
int refresh() override;
|
||||||
virtual void updateLayout() = 0;
|
virtual void updateLayout() = 0;
|
||||||
|
|
||||||
void hideWindow(Window *window);
|
void hideWindow(Window *window);
|
||||||
|
@ -28,7 +28,6 @@ namespace krikkel::NCurses
|
||||||
SingleUserInput readSingleUserInput();
|
SingleUserInput readSingleUserInput();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Window *rootWindow;
|
|
||||||
std::recursive_mutex *ncursesMutex;
|
std::recursive_mutex *ncursesMutex;
|
||||||
std::list<Window *> stack, visibleStack;
|
std::list<Window *> stack, visibleStack;
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace krikkel::NCurses
|
||||||
friend class TilingWindowManager;
|
friend class TilingWindowManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Window();
|
||||||
Window(TilingWindowManager *windowManager);
|
Window(TilingWindowManager *windowManager);
|
||||||
Window(const NCursesWindow &window);
|
Window(const NCursesWindow &window);
|
||||||
Window(int lines, int columns, int y, int x);
|
Window(int lines, int columns, int y, int x);
|
||||||
|
|
Loading…
Reference in a new issue