added moving windows and fixed sticks

This commit is contained in:
vaxerski 2021-11-19 22:29:44 +01:00
parent 76dca3d32c
commit dcbf69f8b8
5 changed files with 88 additions and 6 deletions

View File

@ -17,9 +17,16 @@ void KeybindManager::reloadAllKeybinds() {
// todo: config // todo: config
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x72 /* R */, "dmenu_run", &KeybindManager::call)); KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x72 /* R */, "dmenu_run", &KeybindManager::call));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x71 /* Q */, "kitty", &KeybindManager::call)); KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x71 /* Q */, "kitty", &KeybindManager::call));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0xff0d /* Enter */, "xterm", &KeybindManager::call));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x62 /* G */, "google-chrome-stable", &KeybindManager::call)); KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x62 /* G */, "google-chrome-stable", &KeybindManager::call));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x63 /* C */, "", &KeybindManager::killactive)); KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0x63 /* C */, "", &KeybindManager::killactive));
// move window
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0xff51 /* < */, "l", &KeybindManager::movewindow));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0xff53 /* > */, "r", &KeybindManager::movewindow));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0xff52 /* ^ */, "t", &KeybindManager::movewindow));
KeybindManager::keybinds.push_back(Keybind(MOD_SUPER, 0xff54 /* v */, "b", &KeybindManager::movewindow));
} }
unsigned int KeybindManager::modToMask(MODS mod) { unsigned int KeybindManager::modToMask(MODS mod) {
@ -94,4 +101,8 @@ void KeybindManager::call(std::string args) {
_exit(0); _exit(0);
} }
wait(NULL); wait(NULL);
}
void KeybindManager::movewindow(std::string arg) {
WindowManager::moveActiveWindowTo(arg[0]);
} }

View File

@ -17,4 +17,5 @@ namespace KeybindManager {
// Dispatchers // Dispatchers
void call(std::string args); void call(std::string args);
void killactive(std::string args); void killactive(std::string args);
void movewindow(std::string args);
}; };

View File

@ -21,4 +21,4 @@
#define EVENT(name) \ #define EVENT(name) \
void event##name(xcb_generic_event_t* event); void event##name(xcb_generic_event_t* event);
#define STICKS(a, b) abs(a - b) < 2 #define STICKS(a, b) abs((a) - (b)) < 2

View File

@ -78,6 +78,8 @@ bool WindowManager::handleEvent() {
void WindowManager::refreshDirtyWindows() { void WindowManager::refreshDirtyWindows() {
for(auto& window : windows) { for(auto& window : windows) {
if (window.getDirty()) { if (window.getDirty()) {
Values[0] = (int)window.getEffectiveSize().x; Values[0] = (int)window.getEffectiveSize().x;
Values[1] = (int)window.getEffectiveSize().y; Values[1] = (int)window.getEffectiveSize().y;
xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values); xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
@ -109,7 +111,7 @@ void WindowManager::refreshDirtyWindows() {
window.setDirty(false); window.setDirty(false);
Debug::log(LOG, "Refreshed dirty window."); Debug::log(LOG, "Refreshed dirty window, with an ID of " + std::to_string(window.getDrawable()));
} }
} }
} }
@ -131,8 +133,6 @@ CWindow* WindowManager::getWindowFromDrawable(xcb_drawable_t window) {
if (w.getDrawable() == window) { if (w.getDrawable() == window) {
return &w; return &w;
} }
Debug::log(LOG, "Not " + std::to_string(w.getDrawable()));
} }
return nullptr; return nullptr;
} }
@ -159,7 +159,6 @@ void WindowManager::removeWindowFromVectorSafe(xcb_drawable_t window) {
WindowManager::windows.push_back(p); WindowManager::windows.push_back(p);
continue; continue;
} }
Debug::log(LOG, "Is, removing: " + std::to_string(p.getDrawable()));
} }
} }
@ -286,7 +285,7 @@ bool canEatWindow(CWindow* a, CWindow* toEat) {
} }
void eatWindow(CWindow* a, CWindow* toEat) { void eatWindow(CWindow* a, CWindow* toEat) {
// Size is pos + size max - pos // Size is pos + size max - pos
const auto OPPCORNERA = a->getPosition() + a->getSize(); const auto OPPCORNERA = a->getPosition() + a->getSize();
const auto OPPCORNERB = toEat->getPosition() + toEat->getSize(); const auto OPPCORNERB = toEat->getPosition() + toEat->getSize();
@ -323,4 +322,73 @@ void WindowManager::fixWindowOnClose(CWindow* pClosedWindow) {
WindowManager::setFocusedWindow(neighbor->getDrawable()); // Set focus. :) WindowManager::setFocusedWindow(neighbor->getDrawable()); // Set focus. :)
setEffectiveSizePosUsingConfig(neighbor); setEffectiveSizePosUsingConfig(neighbor);
}
CWindow* getNeighborInDir(char dir) {
const auto CURRENTWINDOW = WindowManager::getWindowFromDrawable(WindowManager::LastWindow);
if (!CURRENTWINDOW)
return nullptr;
const auto POSA = CURRENTWINDOW->getPosition();
const auto SIZEA = CURRENTWINDOW->getSize();
for (auto& w : WindowManager::windows) {
if (w.getDrawable() == CURRENTWINDOW->getDrawable())
continue;
const auto POSB = w.getPosition();
const auto SIZEB = w.getSize();
switch (dir) {
case 'l':
if (STICKS(POSA.x, POSB.x + SIZEB.x))
return &w;
break;
case 'r':
if (STICKS(POSA.x + SIZEA.x, POSB.x))
return &w;
break;
case 't':
if (STICKS(POSA.y, POSB.y + SIZEB.y))
return &w;
break;
case 'b':
if (STICKS(POSA.y + SIZEA.y, POSB.y))
return &w;
break;
}
}
return nullptr;
}
void WindowManager::moveActiveWindowTo(char dir) {
const auto CURRENTWINDOW = WindowManager::getWindowFromDrawable(WindowManager::LastWindow);
if (!CURRENTWINDOW)
return;
const auto neighbor = getNeighborInDir(dir);
if (!neighbor)
return;
// swap their stuff and mark dirty
const auto TEMP_SIZEA = CURRENTWINDOW->getSize();
const auto TEMP_POSA = CURRENTWINDOW->getPosition();
CURRENTWINDOW->setSize(neighbor->getSize());
CURRENTWINDOW->setPosition(neighbor->getPosition());
neighbor->setSize(TEMP_SIZEA);
neighbor->setPosition(TEMP_POSA);
CURRENTWINDOW->setDirty(true);
neighbor->setDirty(true);
setEffectiveSizePosUsingConfig(neighbor);
setEffectiveSizePosUsingConfig(CURRENTWINDOW);
} }

View File

@ -34,4 +34,6 @@ namespace WindowManager {
void calculateNewWindowParams(CWindow*); void calculateNewWindowParams(CWindow*);
void fixWindowOnClose(CWindow*); void fixWindowOnClose(CWindow*);
void moveActiveWindowTo(char);
}; };