Hypr/src/events/events.cpp

105 lines
3.5 KiB
C++
Raw Normal View History

#include "events.hpp"
2021-11-21 11:25:26 +01:00
void handle(sigval val) {
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() {
sigevent eventsig;
eventsig.sigev_notify = SIGEV_THREAD;
eventsig.sigev_notify_function = handle;
eventsig.sigev_notify_attributes = NULL;
eventsig.sigev_value.sival_ptr = &timerid;
timer_create(CLOCK_REALTIME, &eventsig, &timerid);
2021-11-21 12:40:03 +01:00
itimerspec t = {{0, 1000 * (1000 / ConfigManager::getInt("max_fps"))}, {1, 0}};
2021-11-21 11:25:26 +01:00
timer_settime(timerid, 0, &t, 0);
}
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);
// vvv insallah no segfaults
2021-11-20 09:25:21 +01:00
g_pWindowManager->getWindowFromDrawable(E->event)->setDirty(true);
}
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);
//
}
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);
// fix last window
2021-11-20 09:25:21 +01:00
const auto CLOSEDWINDOW = g_pWindowManager->getWindowFromDrawable(E->window);
if (CLOSEDWINDOW) {
2021-11-20 09:25:21 +01:00
g_pWindowManager->fixWindowOnClose(CLOSEDWINDOW);
// delete off of the arr
2021-11-20 09:25:21 +01:00
g_pWindowManager->removeWindowFromVectorSafe(E->window);
}
}
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-21 11:25:26 +01:00
// make sure it's not the bar!
if (E->window == g_pWindowManager->statusBar.getWindowID())
return;
// Map the window
2021-11-20 09:25:21 +01:00
xcb_map_window(g_pWindowManager->DisplayConnection, E->window);
// Do the setup of the window's params and stuf
CWindow window;
window.setDrawable(E->window);
window.setIsFloating(false);
window.setDirty(true);
window.setWorkspaceID(g_pWindowManager->activeWorkspace->getID());
// Also sets the old one
2021-11-20 09:25:21 +01:00
g_pWindowManager->calculateNewWindowParams(&window);
// Focus
2021-11-20 09:25:21 +01:00
g_pWindowManager->setFocusedWindow(E->window);
// Add to arr
2021-11-20 09:25:21 +01:00
g_pWindowManager->addWindowToVectorSafe(window);
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-20 09:25:21 +01:00
g_pWindowManager->setFocusedWindow(E->window);
2021-11-19 20:20:05 +01:00
}
void Events::eventKeyPress(xcb_generic_event_t* event) {
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 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();
}