mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-25 22:35:58 +01:00
added moving windows and fixed sticks
This commit is contained in:
parent
76dca3d32c
commit
dcbf69f8b8
5 changed files with 88 additions and 6 deletions
|
@ -17,9 +17,16 @@ void KeybindManager::reloadAllKeybinds() {
|
|||
// todo: config
|
||||
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, 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, 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) {
|
||||
|
@ -95,3 +102,7 @@ void KeybindManager::call(std::string args) {
|
|||
}
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
void KeybindManager::movewindow(std::string arg) {
|
||||
WindowManager::moveActiveWindowTo(arg[0]);
|
||||
}
|
|
@ -17,4 +17,5 @@ namespace KeybindManager {
|
|||
// Dispatchers
|
||||
void call(std::string args);
|
||||
void killactive(std::string args);
|
||||
void movewindow(std::string args);
|
||||
};
|
|
@ -21,4 +21,4 @@
|
|||
#define EVENT(name) \
|
||||
void event##name(xcb_generic_event_t* event);
|
||||
|
||||
#define STICKS(a, b) abs(a - b) < 2
|
||||
#define STICKS(a, b) abs((a) - (b)) < 2
|
|
@ -78,6 +78,8 @@ bool WindowManager::handleEvent() {
|
|||
void WindowManager::refreshDirtyWindows() {
|
||||
for(auto& window : windows) {
|
||||
if (window.getDirty()) {
|
||||
|
||||
|
||||
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);
|
||||
|
@ -109,7 +111,7 @@ void WindowManager::refreshDirtyWindows() {
|
|||
|
||||
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) {
|
||||
return &w;
|
||||
}
|
||||
|
||||
Debug::log(LOG, "Not " + std::to_string(w.getDrawable()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -159,7 +159,6 @@ void WindowManager::removeWindowFromVectorSafe(xcb_drawable_t window) {
|
|||
WindowManager::windows.push_back(p);
|
||||
continue;
|
||||
}
|
||||
Debug::log(LOG, "Is, removing: " + std::to_string(p.getDrawable()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,3 +323,72 @@ void WindowManager::fixWindowOnClose(CWindow* pClosedWindow) {
|
|||
|
||||
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);
|
||||
}
|
|
@ -34,4 +34,6 @@ namespace WindowManager {
|
|||
|
||||
void calculateNewWindowParams(CWindow*);
|
||||
void fixWindowOnClose(CWindow*);
|
||||
|
||||
void moveActiveWindowTo(char);
|
||||
};
|
Loading…
Reference in a new issue