added borders

This commit is contained in:
vaxerski 2021-11-18 22:08:28 +01:00
parent 53a64d9574
commit 92492c3ffe
5 changed files with 66 additions and 5 deletions

View File

@ -10,6 +10,12 @@ void Events::eventEnter(xcb_generic_event_t* event) {
WindowManager::getWindowFromDrawable(E->event)->setDirty(true);
}
void Events::eventLeave(xcb_generic_event_t* event) {
const auto E = reinterpret_cast<xcb_leave_notify_event_t*>(event);
//
}
void Events::eventDestroy(xcb_generic_event_t* event) {
const xcb_destroy_notify_event_t* E = reinterpret_cast<xcb_destroy_notify_event_t*>(event);
xcb_kill_client(WindowManager::DisplayConnection, E->window);

View File

@ -3,6 +3,7 @@
namespace Events {
EVENT(Enter);
EVENT(Leave);
EVENT(Destroy);
EVENT(MapWindow);
};

View File

@ -19,6 +19,8 @@ public:
EXPOSED_MEMBER(Dirty, bool, b);
EXPOSED_MEMBER(Size, Vector2D, vec);
EXPOSED_MEMBER(EffectiveSize, Vector2D, vec);
EXPOSED_MEMBER(EffectivePosition, Vector2D, vec);
EXPOSED_MEMBER(Position, Vector2D, vec);
EXPOSED_MEMBER(IsFloating, bool, b);
EXPOSED_MEMBER(Drawable, xcb_drawable_t, i);

View File

@ -33,6 +33,10 @@ bool WindowManager::handleEvent() {
Events::eventEnter(ev);
Debug::log(LOG, "Event dispatched ENTER");
break;
case XCB_LEAVE_NOTIFY:
Events::eventLeave(ev);
Debug::log(LOG, "Event dispatched LEAVE");
break;
case XCB_DESTROY_NOTIFY:
Events::eventDestroy(ev);
Debug::log(LOG, "Event dispatched DESTROY");
@ -61,14 +65,35 @@ bool WindowManager::handleEvent() {
void WindowManager::refreshDirtyWindows() {
for(auto& window : windows) {
if (window.getDirty()) {
Values[0] = (int)window.getSize().x;
Values[1] = (int)window.getSize().y;
Values[0] = (int)window.getEffectiveSize().x;
Values[1] = (int)window.getEffectiveSize().y;
xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
Values[0] = (int)window.getPosition().x;
Values[1] = (int)window.getPosition().y;
Values[0] = (int)window.getEffectivePosition().x;
Values[1] = (int)window.getEffectivePosition().y;
xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
// Focused special border.
if (window.getDrawable() == WindowManager::LastWindow) {
Values[0] = (int)BORDERSIZE;
xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values);
// Update the position because the border makes the window jump
// I have added the bordersize vec2d before in the setEffectiveSizePosUsingConfig function.
Values[0] = (int)window.getEffectivePosition().x - BORDERSIZE;
Values[1] = (int)window.getEffectivePosition().y - BORDERSIZE;
xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
Values[0] = 0xFF3333; // RED :)
xcb_change_window_attributes(WindowManager::DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values);
} else {
Values[0] = 0;
xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values);
Values[0] = 0x555555; // GRAY :)
xcb_change_window_attributes(WindowManager::DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values);
}
window.setDirty(false);
Debug::log(LOG, "Refreshed dirty window.");
@ -79,6 +104,11 @@ void WindowManager::refreshDirtyWindows() {
void WindowManager::setFocusedWindow(xcb_drawable_t window) {
if (window && window != WindowManager::Screen->root) {
xcb_set_input_focus(WindowManager::DisplayConnection, XCB_INPUT_FOCUS_POINTER_ROOT, window, XCB_CURRENT_TIME);
// Fix border from the old window that was in focus.
if (const auto PLASTWINDOW = WindowManager::getWindowFromDrawable(WindowManager::LastWindow); PLASTWINDOW)
PLASTWINDOW->setDirty(true);
WindowManager::LastWindow = window;
}
}
@ -120,6 +150,17 @@ void WindowManager::removeWindowFromVectorSafe(xcb_drawable_t window) {
}
}
void setEffectiveSizePosUsingConfig(CWindow* pWindow) {
// for now only border.
// todo: gaps.
if (!pWindow)
return;
pWindow->setEffectivePosition(pWindow->getPosition() + Vector2D(BORDERSIZE, BORDERSIZE));
pWindow->setEffectiveSize(pWindow->getSize() - (Vector2D(BORDERSIZE, BORDERSIZE) * 2));
}
void calculateNewTileSetOldTile(CWindow* pWindow) {
const auto PLASTWINDOW = WindowManager::getWindowFromDrawable(WindowManager::LastWindow);
if (PLASTWINDOW) {
@ -142,6 +183,9 @@ void calculateNewTileSetOldTile(CWindow* pWindow) {
pWindow->setSize(Vector2D(WindowManager::Screen->width_in_pixels, WindowManager::Screen->height_in_pixels));
pWindow->setPosition(Vector2D(0, 0));
}
setEffectiveSizePosUsingConfig(pWindow);
setEffectiveSizePosUsingConfig(PLASTWINDOW);
}
void WindowManager::calculateNewWindowParams(CWindow* pWindow) {
@ -218,9 +262,11 @@ void WindowManager::fixWindowOnClose(CWindow* pClosedWindow) {
if (!neighbor)
return; // No neighbor. Don't update, easy.
// update neighbor to "eat" closed.
eatWindow(neighbor, pClosedWindow);
neighbor->setDirty(true);
WindowManager::setFocusedWindow(neighbor->getDrawable()); // Set focus. :)
setEffectiveSizePosUsingConfig(neighbor);
}

View File

@ -5,6 +5,12 @@
#include <vector>
// temp config values
#define BORDERSIZE 1
#define GAPS_IN 10
#define GAPS_OUT 20
namespace WindowManager {
inline xcb_connection_t* DisplayConnection;
inline xcb_screen_t* Screen;