2021-11-18 18:04:09 +01:00
|
|
|
#include "events.hpp"
|
|
|
|
|
2021-11-21 16:53:06 +01:00
|
|
|
void handle() {
|
2021-11-21 11:25:26 +01:00
|
|
|
g_pWindowManager->statusBar.draw();
|
2021-11-21 12:40:03 +01:00
|
|
|
|
|
|
|
// check config
|
|
|
|
ConfigManager::tick();
|
2021-11-21 11:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Events::setThread() {
|
|
|
|
|
2021-11-21 16:53:06 +01:00
|
|
|
g_pWindowManager->barThread = new std::thread([&]() {
|
|
|
|
for (;;) {
|
|
|
|
handle();
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / ConfigManager::getInt("max_fps")));
|
|
|
|
}
|
|
|
|
});
|
2021-11-21 11:25:26 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 18:04:09 +01:00
|
|
|
void Events::eventEnter(xcb_generic_event_t* event) {
|
|
|
|
const auto E = reinterpret_cast<xcb_enter_notify_event_t*>(event);
|
|
|
|
|
|
|
|
// Just focus it and update.
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->setFocusedWindow(E->event);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
// vvv insallah no segfaults
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->getWindowFromDrawable(E->event)->setDirty(true);
|
2021-11-18 18:04:09 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 22:08:28 +01:00
|
|
|
void Events::eventLeave(xcb_generic_event_t* event) {
|
|
|
|
const auto E = reinterpret_cast<xcb_leave_notify_event_t*>(event);
|
|
|
|
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2021-11-18 18:04:09 +01:00
|
|
|
void Events::eventDestroy(xcb_generic_event_t* event) {
|
2021-11-18 22:21:52 +01:00
|
|
|
const auto E = reinterpret_cast<xcb_destroy_notify_event_t*>(event);
|
2021-11-20 09:25:21 +01:00
|
|
|
xcb_kill_client(g_pWindowManager->DisplayConnection, E->window);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
// fix last window
|
2021-11-20 09:25:21 +01:00
|
|
|
const auto CLOSEDWINDOW = g_pWindowManager->getWindowFromDrawable(E->window);
|
2021-11-18 18:04:09 +01:00
|
|
|
if (CLOSEDWINDOW) {
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->fixWindowOnClose(CLOSEDWINDOW);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
// delete off of the arr
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->removeWindowFromVectorSafe(E->window);
|
2021-11-18 18:04:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::eventMapWindow(xcb_generic_event_t* event) {
|
2021-11-18 22:21:52 +01:00
|
|
|
const auto E = reinterpret_cast<xcb_map_request_event_t*>(event);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
2021-11-21 11:25:26 +01:00
|
|
|
// make sure it's not the bar!
|
|
|
|
if (E->window == g_pWindowManager->statusBar.getWindowID())
|
|
|
|
return;
|
|
|
|
|
2021-11-18 18:04:09 +01:00
|
|
|
// Map the window
|
2021-11-20 09:25:21 +01:00
|
|
|
xcb_map_window(g_pWindowManager->DisplayConnection, E->window);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
// Do the setup of the window's params and stuf
|
|
|
|
CWindow window;
|
|
|
|
window.setDrawable(E->window);
|
|
|
|
window.setIsFloating(false);
|
|
|
|
window.setDirty(true);
|
2021-11-21 17:40:02 +01:00
|
|
|
const auto CURRENTSCREEN = g_pWindowManager->getMonitorFromCursor()->ID;
|
2021-11-21 19:59:59 +01:00
|
|
|
window.setWorkspaceID(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]);
|
2021-11-21 17:40:02 +01:00
|
|
|
window.setMonitor(CURRENTSCREEN);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
2021-11-21 15:15:33 +01:00
|
|
|
window.setDefaultPosition(Vector2D(0,0));
|
|
|
|
window.setDefaultSize(Vector2D(g_pWindowManager->Screen->width_in_pixels/2.f,g_pWindowManager->Screen->height_in_pixels/2.f));
|
|
|
|
|
2021-11-22 18:43:55 +01:00
|
|
|
// Set the parent
|
|
|
|
// check if lastwindow is on our workspace
|
|
|
|
if (auto PLASTWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PLASTWINDOW
|
|
|
|
&& PLASTWINDOW->getWorkspaceID() == g_pWindowManager->activeWorkspaces[CURRENTSCREEN]) {
|
|
|
|
// LastWindow is on our workspace, let's make a new split node
|
|
|
|
|
|
|
|
if (PLASTWINDOW->getIsFloating()) {
|
|
|
|
// find a window manually
|
|
|
|
PLASTWINDOW = g_pWindowManager->findWindowAtCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
CWindow newWindowSplitNode;
|
|
|
|
newWindowSplitNode.setPosition(PLASTWINDOW->getPosition());
|
|
|
|
newWindowSplitNode.setSize(PLASTWINDOW->getSize());
|
|
|
|
|
|
|
|
newWindowSplitNode.setChildNodeAID(PLASTWINDOW->getDrawable());
|
|
|
|
newWindowSplitNode.setChildNodeBID(E->window);
|
|
|
|
|
|
|
|
newWindowSplitNode.setParentNodeID(PLASTWINDOW->getParentNodeID());
|
|
|
|
|
|
|
|
newWindowSplitNode.setWorkspaceID(window.getWorkspaceID());
|
|
|
|
newWindowSplitNode.setMonitor(window.getMonitor());
|
|
|
|
|
|
|
|
// generates a negative node ID
|
|
|
|
newWindowSplitNode.generateNodeID();
|
|
|
|
|
|
|
|
// update the parent if exists
|
|
|
|
if (const auto PREVPARENT = g_pWindowManager->getWindowFromDrawable(PLASTWINDOW->getParentNodeID()); PREVPARENT) {
|
|
|
|
if (PREVPARENT->getChildNodeAID() == PLASTWINDOW->getDrawable()) {
|
|
|
|
PREVPARENT->setChildNodeAID(newWindowSplitNode.getDrawable());
|
|
|
|
} else {
|
|
|
|
PREVPARENT->setChildNodeBID(newWindowSplitNode.getDrawable());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.setParentNodeID(newWindowSplitNode.getDrawable());
|
|
|
|
PLASTWINDOW->setParentNodeID(newWindowSplitNode.getDrawable());
|
|
|
|
|
|
|
|
g_pWindowManager->addWindowToVectorSafe(newWindowSplitNode);
|
|
|
|
} else {
|
|
|
|
// LastWindow is not on our workspace, so set the parent to 0.
|
|
|
|
window.setParentNodeID(0);
|
|
|
|
}
|
|
|
|
|
2021-11-18 18:04:09 +01:00
|
|
|
// Also sets the old one
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->calculateNewWindowParams(&window);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
// Focus
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->setFocusedWindow(E->window);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
// Add to arr
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->addWindowToVectorSafe(window);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
|
|
|
Debug::log(LOG, "Created a new window! X: " + std::to_string(window.getPosition().x) + ", Y: " + std::to_string(window.getPosition().y) + ", W: "
|
|
|
|
+ std::to_string(window.getSize().x) + ", H:" + std::to_string(window.getSize().y) + " ID: " + std::to_string(E->window));
|
|
|
|
|
|
|
|
// Set map values
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->Values[0] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE;
|
|
|
|
xcb_change_window_attributes_checked(g_pWindowManager->DisplayConnection, E->window, XCB_CW_EVENT_MASK, g_pWindowManager->Values);
|
2021-11-18 18:04:09 +01:00
|
|
|
|
2021-11-20 09:25:21 +01:00
|
|
|
g_pWindowManager->setFocusedWindow(E->window);
|
2021-11-19 20:20:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 15:25:57 +01:00
|
|
|
void Events::eventButtonPress(xcb_generic_event_t* event) {
|
2021-11-19 20:20:05 +01:00
|
|
|
const auto E = reinterpret_cast<xcb_key_press_event_t*>(event);
|
|
|
|
|
|
|
|
const auto KEYSYM = KeybindManager::getKeysymFromKeycode(E->detail);
|
|
|
|
|
|
|
|
for (auto& keybind : KeybindManager::keybinds) {
|
|
|
|
if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && KeybindManager::modToMask(keybind.getMod()) == E->state) {
|
|
|
|
keybind.getDispatcher()(keybind.getCommand());
|
2021-11-21 19:59:59 +01:00
|
|
|
return;
|
|
|
|
// TODO: fix duplicating keybinds
|
2021-11-19 20:20:05 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-21 11:25:26 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 15:25:57 +01:00
|
|
|
void Events::eventKeyPress(xcb_generic_event_t* event) {
|
|
|
|
const auto E = reinterpret_cast<xcb_key_press_event_t*>(event);
|
|
|
|
|
|
|
|
// todo: super resize and move floating
|
|
|
|
}
|
|
|
|
|
2021-11-21 11:25:26 +01:00
|
|
|
void Events::eventExpose(xcb_generic_event_t* event) {
|
|
|
|
const auto E = reinterpret_cast<xcb_expose_event_t*>(event);
|
|
|
|
|
|
|
|
// Draw the bar
|
|
|
|
g_pWindowManager->statusBar.draw();
|
2021-11-18 18:04:09 +01:00
|
|
|
}
|