Hyprland/src/events/Misc.cpp

224 lines
8.6 KiB
C++
Raw Normal View History

2022-03-21 15:17:04 +01:00
#include "Events.hpp"
#include "../Compositor.hpp"
#include "../helpers/WLClasses.hpp"
2022-06-09 12:46:55 +02:00
#include "../managers/input/InputManager.hpp"
2022-03-21 15:17:04 +01:00
#include "../render/Renderer.hpp"
// ------------------------------ //
// __ __ _____ _____ _____ //
// | \/ |_ _|/ ____|/ ____| //
// | \ / | | | | (___ | | //
// | |\/| | | | \___ \| | //
// | | | |_| |_ ____) | |____ //
// |_| |_|_____|_____/ \_____| //
// //
// ------------------------------ //
void Events::listener_outputMgrApply(wl_listener* listener, void* data) {
const auto CONFIG = (wlr_output_configuration_v1*)data;
g_pHyprRenderer->outputMgrApplyTest(CONFIG, false);
}
void Events::listener_outputMgrTest(wl_listener* listener, void* data) {
const auto CONFIG = (wlr_output_configuration_v1*)data;
g_pHyprRenderer->outputMgrApplyTest(CONFIG, true);
}
void Events::listener_leaseRequest(wl_listener* listener, void* data) {
const auto REQUEST = (wlr_drm_lease_request_v1*)data;
2022-08-27 23:24:36 +02:00
struct wlr_drm_lease_v1* lease = wlr_drm_lease_request_v1_grant(REQUEST);
if (!lease) {
Debug::log(ERR, "Failed to grant lease request!");
2022-08-27 23:24:36 +02:00
wlr_drm_lease_request_v1_reject(REQUEST);
}
}
2022-03-21 15:17:04 +01:00
void Events::listener_requestSetPrimarySel(wl_listener* listener, void* data) {
const auto EVENT = (wlr_seat_request_set_primary_selection_event*)data;
2022-03-22 18:29:13 +01:00
wlr_seat_set_primary_selection(g_pCompositor->m_sSeat.seat, EVENT->source, EVENT->serial);
2022-03-21 15:17:04 +01:00
}
void Events::listener_requestSetSel(wl_listener* listener, void* data) {
const auto EVENT = (wlr_seat_request_set_selection_event*)data;
2022-03-22 18:29:13 +01:00
wlr_seat_set_selection(g_pCompositor->m_sSeat.seat, EVENT->source, EVENT->serial);
2022-03-21 15:17:04 +01:00
}
void Events::listener_readyXWayland(wl_listener* listener, void* data) {
2022-10-27 12:26:35 +02:00
#ifndef NO_XWAYLAND
2022-03-21 15:17:04 +01:00
const auto XCBCONNECTION = xcb_connect(g_pXWaylandManager->m_sWLRXWayland->display_name, NULL);
const auto ERR = xcb_connection_has_error(XCBCONNECTION);
if (ERR) {
Debug::log(LogLevel::ERR, "XWayland -> xcb_connection_has_error failed with %i", ERR);
return;
}
for (auto& ATOM : HYPRATOMS) {
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(XCBCONNECTION, 0, ATOM.first.length(), ATOM.first.c_str());
xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(XCBCONNECTION, cookie, NULL);
if (!reply) {
Debug::log(LogLevel::ERR, "XWayland -> Atom failed: %s", ATOM.first.c_str());
continue;
}
ATOM.second = reply->atom;
}
2022-03-22 18:29:13 +01:00
wlr_xwayland_set_seat(g_pXWaylandManager->m_sWLRXWayland, g_pCompositor->m_sSeat.seat);
2022-03-21 15:17:04 +01:00
const auto XCURSOR = wlr_xcursor_manager_get_xcursor(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", 1);
if (XCURSOR) {
wlr_xwayland_set_cursor(g_pXWaylandManager->m_sWLRXWayland, XCURSOR->images[0]->buffer, XCURSOR->images[0]->width * 4, XCURSOR->images[0]->width, XCURSOR->images[0]->height, XCURSOR->images[0]->hotspot_x, XCURSOR->images[0]->hotspot_y);
}
xcb_disconnect(XCBCONNECTION);
2022-10-27 12:26:35 +02:00
#endif
}
void Events::listener_requestDrag(wl_listener* listener, void* data) {
const auto E = (wlr_seat_request_start_drag_event*)data;
2022-03-22 18:29:13 +01:00
if (!wlr_seat_validate_pointer_grab_serial(g_pCompositor->m_sSeat.seat, E->origin, E->serial)) {
Debug::log(LOG, "Ignoring drag and drop request: serial mismatch.");
wlr_data_source_destroy(E->drag->source);
return;
}
2022-03-22 18:29:13 +01:00
wlr_seat_start_pointer_drag(g_pCompositor->m_sSeat.seat, E->drag, E->serial);
}
void Events::listener_startDrag(wl_listener* listener, void* data) {
2022-09-25 20:07:48 +02:00
2022-03-31 17:25:23 +02:00
if (g_pInputManager->m_sDrag.drag)
return; // don't handle multiple drags
g_pInputManager->m_sDrag.drag = (wlr_drag*)data;
wlr_drag* wlrDrag = (wlr_drag*)data;
Debug::log(LOG, "Started drag %x", wlrDrag);
wlrDrag->data = data;
g_pInputManager->m_sDrag.hyprListener_destroy.initCallback(&wlrDrag->events.destroy, &Events::listener_destroyDrag, &g_pInputManager->m_sDrag, "Drag");
if (wlrDrag->icon) {
Debug::log(LOG, "Drag started with an icon %x", wlrDrag->icon);
g_pInputManager->m_sDrag.dragIcon = wlrDrag->icon;
wlrDrag->icon->data = g_pInputManager->m_sDrag.dragIcon;
g_pInputManager->m_sDrag.hyprListener_mapIcon.initCallback(&wlrDrag->icon->events.map, &Events::listener_mapDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
g_pInputManager->m_sDrag.hyprListener_unmapIcon.initCallback(&wlrDrag->icon->events.unmap, &Events::listener_unmapDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
g_pInputManager->m_sDrag.hyprListener_destroyIcon.initCallback(&wlrDrag->icon->events.destroy, &Events::listener_destroyDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
g_pInputManager->m_sDrag.hyprListener_commitIcon.initCallback(&wlrDrag->icon->surface->events.commit, &Events::listener_commitDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
}
2022-08-06 22:26:32 +02:00
static auto *const PFOLLOWONDND = &g_pConfigManager->getConfigValuePtr("misc:always_follow_on_dnd")->intValue;
if (*PFOLLOWONDND)
g_pInputManager->m_pFollowOnDnDBegin = g_pCompositor->m_pLastWindow;
else
g_pInputManager->m_pFollowOnDnDBegin = nullptr;
2022-03-31 17:25:23 +02:00
}
void Events::listener_destroyDrag(void* owner, void* data) {
Debug::log(LOG, "Drag destroyed.");
static auto *const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue;
2022-09-08 21:25:16 +02:00
if (g_pInputManager->m_sDrag.drag && g_pInputManager->m_sDrag.dragIcon && g_pInputManager->m_sDrag.dragIcon->surface)
g_pHyprRenderer->damageBox(g_pInputManager->m_sDrag.pos.x - 2, g_pInputManager->m_sDrag.pos.y - 2, g_pInputManager->m_sDrag.dragIcon->surface->current.width + 4, g_pInputManager->m_sDrag.dragIcon->surface->current.height + 4);
2022-09-07 12:18:44 +02:00
2022-03-31 17:25:23 +02:00
g_pInputManager->m_sDrag.drag = nullptr;
g_pInputManager->m_sDrag.dragIcon = nullptr;
g_pInputManager->m_sDrag.hyprListener_destroy.removeCallback();
g_pInputManager->refocus();
2022-08-06 22:26:32 +02:00
if (g_pInputManager->m_pFollowOnDnDBegin && *PFOLLOWMOUSE != 1)
2022-08-06 22:26:32 +02:00
g_pCompositor->focusWindow(g_pInputManager->m_pFollowOnDnDBegin);
g_pInputManager->m_pFollowOnDnDBegin = nullptr;
2022-03-31 17:25:23 +02:00
}
void Events::listener_mapDragIcon(void* owner, void* data) {
Debug::log(LOG, "Drag icon mapped.");
g_pInputManager->m_sDrag.iconMapped = true;
}
void Events::listener_unmapDragIcon(void* owner, void* data) {
Debug::log(LOG, "Drag icon unmapped.");
g_pInputManager->m_sDrag.iconMapped = false;
}
void Events::listener_destroyDragIcon(void* owner, void* data) {
Debug::log(LOG, "Drag icon destroyed.");
g_pInputManager->m_sDrag.dragIcon = nullptr;
g_pInputManager->m_sDrag.hyprListener_commitIcon.removeCallback();
g_pInputManager->m_sDrag.hyprListener_destroyIcon.removeCallback();
g_pInputManager->m_sDrag.hyprListener_mapIcon.removeCallback();
g_pInputManager->m_sDrag.hyprListener_unmapIcon.removeCallback();
}
void Events::listener_commitDragIcon(void* owner, void* data) {
g_pInputManager->updateDragIcon();
Debug::log(LOG, "Drag icon committed.");
2022-03-22 18:29:13 +01:00
}
void Events::listener_InhibitActivate(wl_listener* listener, void* data) {
Debug::log(LOG, "Activated exclusive for %x.", g_pCompositor->m_sSeat.exclusiveClient);
2022-09-25 20:07:48 +02:00
2022-04-18 17:16:01 +02:00
g_pInputManager->refocus();
2022-03-24 21:34:24 +01:00
g_pCompositor->m_sSeat.exclusiveClient = g_pCompositor->m_sWLRInhibitMgr->active_client;
2022-03-22 18:29:13 +01:00
}
void Events::listener_InhibitDeactivate(wl_listener* listener, void* data) {
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "Deactivated exclusive.");
2022-03-22 18:29:13 +01:00
g_pCompositor->m_sSeat.exclusiveClient = nullptr;
g_pInputManager->refocus();
}
void Events::listener_RendererDestroy(wl_listener* listener, void* data) {
Debug::log(LOG, "!!Renderer destroyed!!");
2022-07-13 18:18:23 +02:00
}
void Events::listener_sessionActive(wl_listener* listener, void* data) {
Debug::log(LOG, "Session got activated!");
g_pCompositor->m_bSessionActive = true;
for (auto& m : g_pCompositor->m_vMonitors) {
g_pCompositor->scheduleFrameForMonitor(m.get());
}
g_pConfigManager->m_bWantsMonitorReload = true;
2022-07-30 22:41:24 +02:00
}
void Events::listener_powerMgrSetMode(wl_listener* listener, void* data) {
Debug::log(LOG, "PowerMgr set mode!");
const auto EVENT = (wlr_output_power_v1_set_mode_event*)data;
wlr_output_enable(EVENT->output, EVENT->mode == 1);
2022-09-25 20:07:48 +02:00
2022-07-30 22:41:24 +02:00
if (!wlr_output_commit(EVENT->output))
Debug::log(ERR, "Couldn't set power mode");
2022-08-05 13:03:37 +02:00
}
void Events::listener_newIME(wl_listener* listener, void* data) {
Debug::log(LOG, "New IME added!");
g_pInputManager->m_sIMERelay.onNewIME((wlr_input_method_v2*)data);
}
void Events::listener_newTextInput(wl_listener* listener, void* data) {
Debug::log(LOG, "New TextInput added!");
g_pInputManager->m_sIMERelay.onNewTextInput((wlr_text_input_v3*)data);
2022-09-25 20:07:48 +02:00
}