mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-25 22:35:58 +01:00
floating windows
This commit is contained in:
parent
678cfc56b3
commit
d3d5e4379b
9 changed files with 75 additions and 7 deletions
|
@ -35,4 +35,4 @@ bind=SUPER,7,workspace,7
|
||||||
bind=SUPER,8,workspace,8
|
bind=SUPER,8,workspace,8
|
||||||
bind=SUPER,9,workspace,9
|
bind=SUPER,9,workspace,9
|
||||||
|
|
||||||
|
bind=SUPER,SPACE,togglefloating,
|
||||||
|
|
|
@ -40,6 +40,8 @@ uint32_t KeybindManager::getKeyCodeFromName(std::string name) {
|
||||||
return 0xff52;
|
return 0xff52;
|
||||||
} else if (name == "down") {
|
} else if (name == "down") {
|
||||||
return 0xff54;
|
return 0xff54;
|
||||||
|
} else if (name == "space") {
|
||||||
|
return 0x20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,3 +150,16 @@ void KeybindManager::toggleActiveWindowFullscreen(std::string unusedArg) {
|
||||||
g_pWindowManager->activeWorkspace->setHasFullscreenWindow(WINDOW->getFullscreen());
|
g_pWindowManager->activeWorkspace->setHasFullscreenWindow(WINDOW->getFullscreen());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) {
|
||||||
|
if (const auto PWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PWINDOW) {
|
||||||
|
PWINDOW->setIsFloating(!PWINDOW->getIsFloating());
|
||||||
|
PWINDOW->setDirty(true);
|
||||||
|
|
||||||
|
// Fix window as if it's closed if we just made it floating
|
||||||
|
if (PWINDOW->getIsFloating())
|
||||||
|
g_pWindowManager->fixWindowOnClose(PWINDOW);
|
||||||
|
|
||||||
|
g_pWindowManager->calculateNewWindowParams(PWINDOW);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,13 +15,13 @@ namespace KeybindManager {
|
||||||
xcb_keysym_t getKeysymFromKeycode(xcb_keycode_t keycode);
|
xcb_keysym_t getKeysymFromKeycode(xcb_keycode_t keycode);
|
||||||
xcb_keycode_t getKeycodeFromKeysym(xcb_keysym_t keysym);
|
xcb_keycode_t getKeycodeFromKeysym(xcb_keysym_t keysym);
|
||||||
|
|
||||||
|
uint32_t getKeyCodeFromName(std::string);
|
||||||
|
|
||||||
// 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);
|
void movewindow(std::string args);
|
||||||
void changeworkspace(std::string args);
|
void changeworkspace(std::string args);
|
||||||
void toggleActiveWindowFullscreen(std::string args);
|
void toggleActiveWindowFullscreen(std::string args);
|
||||||
|
void toggleActiveWindowFloating(std::string args);
|
||||||
|
|
||||||
uint32_t getKeyCodeFromName(std::string);
|
|
||||||
};
|
};
|
|
@ -48,6 +48,7 @@ void handleBind(const std::string& command, const std::string& value) {
|
||||||
if (HANDLER == "fullscreen") dispatcher = KeybindManager::toggleActiveWindowFullscreen;
|
if (HANDLER == "fullscreen") dispatcher = KeybindManager::toggleActiveWindowFullscreen;
|
||||||
if (HANDLER == "movewindow") dispatcher = KeybindManager::call;
|
if (HANDLER == "movewindow") dispatcher = KeybindManager::call;
|
||||||
if (HANDLER == "workspace") dispatcher = KeybindManager::changeworkspace;
|
if (HANDLER == "workspace") dispatcher = KeybindManager::changeworkspace;
|
||||||
|
if (HANDLER == "togglefloating") dispatcher = KeybindManager::toggleActiveWindowFloating;
|
||||||
|
|
||||||
if (dispatcher)
|
if (dispatcher)
|
||||||
KeybindManager::keybinds.push_back(Keybind(mod, KEY, COMMAND, dispatcher));
|
KeybindManager::keybinds.push_back(Keybind(mod, KEY, COMMAND, dispatcher));
|
||||||
|
|
|
@ -66,6 +66,9 @@ void Events::eventMapWindow(xcb_generic_event_t* event) {
|
||||||
window.setDirty(true);
|
window.setDirty(true);
|
||||||
window.setWorkspaceID(g_pWindowManager->activeWorkspace->getID());
|
window.setWorkspaceID(g_pWindowManager->activeWorkspace->getID());
|
||||||
|
|
||||||
|
window.setDefaultPosition(Vector2D(0,0));
|
||||||
|
window.setDefaultSize(Vector2D(g_pWindowManager->Screen->width_in_pixels/2.f,g_pWindowManager->Screen->height_in_pixels/2.f));
|
||||||
|
|
||||||
// Also sets the old one
|
// Also sets the old one
|
||||||
g_pWindowManager->calculateNewWindowParams(&window);
|
g_pWindowManager->calculateNewWindowParams(&window);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
|
|
||||||
CWindow::CWindow() { this->setDirty(true); }
|
CWindow::CWindow() { this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); }
|
||||||
CWindow::~CWindow() { }
|
CWindow::~CWindow() { }
|
|
@ -32,6 +32,10 @@ public:
|
||||||
// Workspace pointer
|
// Workspace pointer
|
||||||
EXPOSED_MEMBER(WorkspaceID, int, i);
|
EXPOSED_MEMBER(WorkspaceID, int, i);
|
||||||
|
|
||||||
|
// For floating
|
||||||
|
EXPOSED_MEMBER(DefaultSize, Vector2D, vec);
|
||||||
|
EXPOSED_MEMBER(DefaultPosition, Vector2D, vec);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -294,8 +294,41 @@ void CWindowManager::setEffectiveSizePosUsingConfig(CWindow* pWindow) {
|
||||||
pWindow->setEffectiveSize(pWindow->getEffectiveSize() - Vector2D(DISPLAYRIGHT ? ConfigManager::getInt("gaps_out") : ConfigManager::getInt("gaps_in"), DISPLAYBOTTOM ? ConfigManager::getInt("gaps_out") : ConfigManager::getInt("gaps_in")));
|
pWindow->setEffectiveSize(pWindow->getEffectiveSize() - Vector2D(DISPLAYRIGHT ? ConfigManager::getInt("gaps_out") : ConfigManager::getInt("gaps_in"), DISPLAYBOTTOM ? ConfigManager::getInt("gaps_out") : ConfigManager::getInt("gaps_in")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CWindow* CWindowManager::findWindowAtCursor() {
|
||||||
|
const auto POINTERCOOKIE = xcb_query_pointer(DisplayConnection, Screen->root);
|
||||||
|
|
||||||
|
xcb_query_pointer_reply_t* pointerreply = xcb_query_pointer_reply(DisplayConnection, POINTERCOOKIE, NULL);
|
||||||
|
if (!pointerreply) {
|
||||||
|
Debug::log(ERR, "Couldn't query pointer.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2D cursorPos = Vector2D(pointerreply->root_x, pointerreply->root_y);
|
||||||
|
|
||||||
|
free(pointerreply);
|
||||||
|
|
||||||
|
for (auto& window : windows) {
|
||||||
|
if (window.getWorkspaceID() == activeWorkspace->getID() && !window.getIsFloating()) {
|
||||||
|
|
||||||
|
if (cursorPos.x >= window.getPosition().x
|
||||||
|
&& cursorPos.x <= window.getPosition().x + window.getSize().x
|
||||||
|
&& cursorPos.y >= window.getPosition().y
|
||||||
|
&& cursorPos.y <= window.getPosition().y + window.getSize().y) {
|
||||||
|
|
||||||
|
return &window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CWindowManager::calculateNewTileSetOldTile(CWindow* pWindow) {
|
void CWindowManager::calculateNewTileSetOldTile(CWindow* pWindow) {
|
||||||
const auto PLASTWINDOW = getWindowFromDrawable(LastWindow);
|
auto PLASTWINDOW = getWindowFromDrawable(LastWindow);
|
||||||
|
|
||||||
|
if (PLASTWINDOW && PLASTWINDOW->getIsFloating()) {
|
||||||
|
// find a window manually
|
||||||
|
PLASTWINDOW = findWindowAtCursor();
|
||||||
|
}
|
||||||
|
|
||||||
if (PLASTWINDOW) {
|
if (PLASTWINDOW) {
|
||||||
const auto PLASTSIZE = PLASTWINDOW->getSize();
|
const auto PLASTSIZE = PLASTWINDOW->getSize();
|
||||||
const auto PLASTPOS = PLASTWINDOW->getPosition();
|
const auto PLASTPOS = PLASTWINDOW->getPosition();
|
||||||
|
@ -318,6 +351,14 @@ void CWindowManager::calculateNewTileSetOldTile(CWindow* pWindow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWindowManager::calculateNewFloatingWindow(CWindow* pWindow) {
|
||||||
|
if (!pWindow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pWindow->setPosition(pWindow->getDefaultPosition());
|
||||||
|
pWindow->setSize(pWindow->getDefaultSize());
|
||||||
|
}
|
||||||
|
|
||||||
void CWindowManager::calculateNewWindowParams(CWindow* pWindow) {
|
void CWindowManager::calculateNewWindowParams(CWindow* pWindow) {
|
||||||
// And set old one's if needed.
|
// And set old one's if needed.
|
||||||
if (!pWindow)
|
if (!pWindow)
|
||||||
|
@ -325,6 +366,8 @@ void CWindowManager::calculateNewWindowParams(CWindow* pWindow) {
|
||||||
|
|
||||||
if (!pWindow->getIsFloating()) {
|
if (!pWindow->getIsFloating()) {
|
||||||
calculateNewTileSetOldTile(pWindow);
|
calculateNewTileSetOldTile(pWindow);
|
||||||
|
} else {
|
||||||
|
calculateNewFloatingWindow(pWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pWindow->setDirty(true);
|
pWindow->setDirty(true);
|
||||||
|
@ -385,7 +428,7 @@ bool CWindowManager::canEatWindow(CWindow* a, CWindow* toEat) {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& w : windows) {
|
for (auto& w : windows) {
|
||||||
if (w.getDrawable() == a->getDrawable() || w.getDrawable() == toEat->getDrawable() || w.getWorkspaceID() != toEat->getWorkspaceID())
|
if (w.getDrawable() == a->getDrawable() || w.getDrawable() == toEat->getDrawable() || w.getWorkspaceID() != toEat->getWorkspaceID() || w.getIsFloating())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (doOverlap(&w))
|
if (doOverlap(&w))
|
||||||
|
|
|
@ -62,6 +62,8 @@ private:
|
||||||
bool canEatWindow(CWindow* a, CWindow* toEat);
|
bool canEatWindow(CWindow* a, CWindow* toEat);
|
||||||
bool isNeighbor(CWindow* a, CWindow* b);
|
bool isNeighbor(CWindow* a, CWindow* b);
|
||||||
void calculateNewTileSetOldTile(CWindow* pWindow);
|
void calculateNewTileSetOldTile(CWindow* pWindow);
|
||||||
|
void calculateNewFloatingWindow(CWindow* pWindow);
|
||||||
|
CWindow* findWindowAtCursor();
|
||||||
void setEffectiveSizePosUsingConfig(CWindow* pWindow);
|
void setEffectiveSizePosUsingConfig(CWindow* pWindow);
|
||||||
void cleanupUnusedWorkspaces();
|
void cleanupUnusedWorkspaces();
|
||||||
xcb_visualtype_t* setupColors();
|
xcb_visualtype_t* setupColors();
|
||||||
|
|
Loading…
Reference in a new issue