2022-03-16 21:37:21 +01:00
|
|
|
#include "Compositor.hpp"
|
2022-07-10 15:41:26 +02:00
|
|
|
#include "helpers/Splashes.hpp"
|
|
|
|
#include <random>
|
2022-03-16 21:37:21 +01:00
|
|
|
|
2022-07-13 18:18:23 +02:00
|
|
|
int handleCritSignal(int signo, void* data) {
|
|
|
|
Debug::log(LOG, "Hyprland received signal %d", signo);
|
|
|
|
|
|
|
|
if (signo == SIGTERM || signo == SIGINT || signo == SIGKILL) {
|
|
|
|
g_pCompositor->cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // everything went fine
|
|
|
|
}
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
CCompositor::CCompositor() {
|
2022-06-03 17:41:57 +02:00
|
|
|
m_szInstanceSignature = GIT_COMMIT_HASH + std::string("_") + std::to_string(time(NULL));
|
2022-03-18 23:52:36 +01:00
|
|
|
|
2022-06-29 12:58:49 +02:00
|
|
|
setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true);
|
|
|
|
|
|
|
|
const auto INSTANCEPATH = "/tmp/hypr/" + m_szInstanceSignature;
|
|
|
|
mkdir(INSTANCEPATH.c_str(), S_IRWXU | S_IRWXG);
|
|
|
|
|
2022-06-03 17:48:07 +02:00
|
|
|
Debug::init(m_szInstanceSignature);
|
|
|
|
|
2022-06-03 17:41:57 +02:00
|
|
|
Debug::log(LOG, "Instance Signature: %s", m_szInstanceSignature.c_str());
|
|
|
|
|
2022-06-25 20:49:06 +02:00
|
|
|
Debug::log(LOG, "===== SYSTEM INFO: =====");
|
|
|
|
|
|
|
|
logSystemInfo();
|
|
|
|
|
|
|
|
Debug::log(LOG, "========================");
|
|
|
|
|
2022-06-25 21:16:52 +02:00
|
|
|
Debug::log(NONE, "\n\n"); // pad
|
|
|
|
|
|
|
|
Debug::log(INFO, "If you are crashing, or encounter any bugs, please consult https://github.com/hyprwm/Hyprland/wiki/Crashing-and-bugs\n\n");
|
|
|
|
|
2022-07-10 15:41:26 +02:00
|
|
|
setRandomSplash();
|
|
|
|
|
|
|
|
Debug::log(LOG, "\nCurrent splash: %s\n\n", m_szCurrentSplash.c_str());
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
m_sWLDisplay = wl_display_create();
|
|
|
|
|
2022-07-13 18:18:23 +02:00
|
|
|
m_sWLEventLoop = wl_display_get_event_loop(m_sWLDisplay);
|
|
|
|
|
|
|
|
// register crit signal handler
|
|
|
|
wl_event_loop_add_signal(m_sWLEventLoop, SIGTERM, handleCritSignal, nullptr);
|
|
|
|
//wl_event_loop_add_signal(m_sWLEventLoop, SIGINT, handleCritSignal, nullptr);
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
m_sWLRBackend = wlr_backend_autocreate(m_sWLDisplay);
|
|
|
|
|
|
|
|
if (!m_sWLRBackend) {
|
|
|
|
Debug::log(CRIT, "m_sWLRBackend was NULL!");
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("wlr_backend_autocreate() failed!");
|
2022-03-16 21:37:21 +01:00
|
|
|
}
|
|
|
|
|
2022-04-04 19:44:25 +02:00
|
|
|
m_iDRMFD = wlr_backend_get_drm_fd(m_sWLRBackend);
|
|
|
|
if (m_iDRMFD < 0) {
|
2022-03-24 15:57:46 +01:00
|
|
|
Debug::log(CRIT, "Couldn't query the DRM FD!");
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("wlr_backend_get_drm_fd() failed!");
|
2022-03-24 15:57:46 +01:00
|
|
|
}
|
|
|
|
|
2022-04-04 19:44:25 +02:00
|
|
|
m_sWLRRenderer = wlr_gles2_renderer_create_with_drm_fd(m_iDRMFD);
|
2022-03-16 21:37:21 +01:00
|
|
|
|
|
|
|
if (!m_sWLRRenderer) {
|
|
|
|
Debug::log(CRIT, "m_sWLRRenderer was NULL!");
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("wlr_gles2_renderer_create_with_drm_fd() failed!");
|
2022-03-16 21:37:21 +01:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:03:15 +01:00
|
|
|
wlr_renderer_init_wl_display(m_sWLRRenderer, m_sWLDisplay);
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
m_sWLRAllocator = wlr_allocator_autocreate(m_sWLRBackend, m_sWLRRenderer);
|
|
|
|
|
|
|
|
if (!m_sWLRAllocator) {
|
|
|
|
Debug::log(CRIT, "m_sWLRAllocator was NULL!");
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("wlr_allocator_autocreate() failed!");
|
2022-03-16 21:37:21 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 17:17:08 +01:00
|
|
|
m_sWLREGL = wlr_gles2_renderer_get_egl(m_sWLRRenderer);
|
|
|
|
|
|
|
|
if (!m_sWLREGL) {
|
|
|
|
Debug::log(CRIT, "m_sWLREGL was NULL!");
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("wlr_gles2_renderer_get_egl() failed!");
|
2022-03-24 17:17:08 +01:00
|
|
|
}
|
2022-03-16 21:37:21 +01:00
|
|
|
|
|
|
|
m_sWLRCompositor = wlr_compositor_create(m_sWLDisplay, m_sWLRRenderer);
|
2022-03-17 19:03:15 +01:00
|
|
|
m_sWLRSubCompositor = wlr_subcompositor_create(m_sWLDisplay);
|
|
|
|
m_sWLRDataDevMgr = wlr_data_device_manager_create(m_sWLDisplay);
|
|
|
|
|
2022-04-14 21:48:12 +02:00
|
|
|
m_sWLRDmabuf = wlr_linux_dmabuf_v1_create(m_sWLDisplay, m_sWLRRenderer);
|
2022-03-19 14:09:11 +01:00
|
|
|
wlr_export_dmabuf_manager_v1_create(m_sWLDisplay);
|
|
|
|
wlr_screencopy_manager_v1_create(m_sWLDisplay);
|
|
|
|
wlr_data_control_manager_v1_create(m_sWLDisplay);
|
|
|
|
wlr_gamma_control_manager_v1_create(m_sWLDisplay);
|
|
|
|
wlr_primary_selection_v1_device_manager_create(m_sWLDisplay);
|
|
|
|
wlr_viewporter_create(m_sWLDisplay);
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
m_sWLROutputLayout = wlr_output_layout_create();
|
|
|
|
|
2022-07-30 22:41:24 +02:00
|
|
|
m_sWLROutputPowerMgr = wlr_output_power_manager_v1_create(m_sWLDisplay);
|
|
|
|
|
2022-03-17 19:03:15 +01:00
|
|
|
m_sWLRScene = wlr_scene_create();
|
|
|
|
wlr_scene_attach_output_layout(m_sWLRScene, m_sWLROutputLayout);
|
2022-03-16 21:37:21 +01:00
|
|
|
|
2022-05-27 16:05:25 +02:00
|
|
|
m_sWLRXDGShell = wlr_xdg_shell_create(m_sWLDisplay, 3);
|
2022-03-16 21:37:21 +01:00
|
|
|
|
|
|
|
m_sWLRCursor = wlr_cursor_create();
|
|
|
|
wlr_cursor_attach_output_layout(m_sWLRCursor, m_sWLROutputLayout);
|
|
|
|
|
2022-03-17 19:03:15 +01:00
|
|
|
m_sWLRXCursorMgr = wlr_xcursor_manager_create(nullptr, 24);
|
|
|
|
wlr_xcursor_manager_load(m_sWLRXCursorMgr, 1);
|
2022-03-16 21:37:21 +01:00
|
|
|
|
2022-03-22 18:29:13 +01:00
|
|
|
m_sSeat.seat = wlr_seat_create(m_sWLDisplay, "seat0");
|
2022-03-17 19:03:15 +01:00
|
|
|
|
2022-03-17 20:22:29 +01:00
|
|
|
m_sWLRPresentation = wlr_presentation_create(m_sWLDisplay, m_sWLRBackend);
|
|
|
|
|
2022-03-18 20:42:49 +01:00
|
|
|
m_sWLRIdle = wlr_idle_create(m_sWLDisplay);
|
2022-03-19 13:54:24 +01:00
|
|
|
|
|
|
|
m_sWLRLayerShell = wlr_layer_shell_v1_create(m_sWLDisplay);
|
|
|
|
|
2022-05-10 11:01:03 +02:00
|
|
|
m_sWLRServerDecoMgr = wlr_server_decoration_manager_create(m_sWLDisplay);
|
|
|
|
m_sWLRXDGDecoMgr = wlr_xdg_decoration_manager_v1_create(m_sWLDisplay);
|
|
|
|
wlr_server_decoration_manager_set_default_mode(m_sWLRServerDecoMgr, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
|
2022-03-19 13:54:24 +01:00
|
|
|
|
|
|
|
wlr_xdg_output_manager_v1_create(m_sWLDisplay, m_sWLROutputLayout);
|
|
|
|
m_sWLROutputMgr = wlr_output_manager_v1_create(m_sWLDisplay);
|
2022-03-22 18:29:13 +01:00
|
|
|
|
|
|
|
m_sWLRInhibitMgr = wlr_input_inhibit_manager_create(m_sWLDisplay);
|
|
|
|
m_sWLRKbShInhibitMgr = wlr_keyboard_shortcuts_inhibit_v1_create(m_sWLDisplay);
|
2022-04-11 19:51:37 +02:00
|
|
|
|
|
|
|
m_sWLREXTWorkspaceMgr = wlr_ext_workspace_manager_v1_create(m_sWLDisplay);
|
2022-04-17 21:40:04 +02:00
|
|
|
|
|
|
|
m_sWLRPointerConstraints = wlr_pointer_constraints_v1_create(m_sWLDisplay);
|
|
|
|
|
|
|
|
m_sWLRRelPointerMgr = wlr_relative_pointer_manager_v1_create(m_sWLDisplay);
|
2022-04-27 17:29:33 +02:00
|
|
|
|
|
|
|
m_sWLRVKeyboardMgr = wlr_virtual_keyboard_manager_v1_create(m_sWLDisplay);
|
2022-05-12 12:13:02 +02:00
|
|
|
|
|
|
|
m_sWLRVirtPtrMgr = wlr_virtual_pointer_manager_v1_create(m_sWLDisplay);
|
2022-05-29 11:24:42 +02:00
|
|
|
|
|
|
|
m_sWLRToplevelMgr = wlr_foreign_toplevel_manager_v1_create(m_sWLDisplay);
|
2022-06-08 14:29:49 +02:00
|
|
|
|
|
|
|
m_sWLRTabletManager = wlr_tablet_v2_create(m_sWLDisplay);
|
2022-06-29 22:23:51 +02:00
|
|
|
|
|
|
|
m_sWLRForeignRegistry = wlr_xdg_foreign_registry_create(m_sWLDisplay);
|
|
|
|
|
2022-07-06 15:42:37 +02:00
|
|
|
m_sWLRIdleInhibitMgr = wlr_idle_inhibit_v1_create(m_sWLDisplay);
|
|
|
|
|
2022-06-29 22:23:51 +02:00
|
|
|
wlr_xdg_foreign_v1_create(m_sWLDisplay, m_sWLRForeignRegistry);
|
|
|
|
wlr_xdg_foreign_v2_create(m_sWLDisplay, m_sWLRForeignRegistry);
|
2022-07-07 11:52:12 +02:00
|
|
|
|
|
|
|
m_sWLRPointerGestures = wlr_pointer_gestures_v1_create(m_sWLDisplay);
|
2022-03-16 21:37:21 +01:00
|
|
|
|
2022-07-13 18:18:23 +02:00
|
|
|
m_sWLRSession = wlr_backend_get_session(m_sWLRBackend);
|
2022-04-21 15:59:28 +02:00
|
|
|
}
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-07-13 18:18:23 +02:00
|
|
|
CCompositor::~CCompositor() {
|
|
|
|
cleanup();
|
2022-03-17 15:53:45 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 15:41:26 +02:00
|
|
|
void CCompositor::setRandomSplash() {
|
|
|
|
std::random_device dev;
|
|
|
|
std::mt19937 engine(dev());
|
|
|
|
std::uniform_int_distribution<> distribution(0, SPLASHES.size() - 1);
|
|
|
|
|
|
|
|
m_szCurrentSplash = SPLASHES[distribution(engine)];
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:52:36 +01:00
|
|
|
void CCompositor::initAllSignals() {
|
2022-03-28 16:10:30 +02:00
|
|
|
addWLSignal(&m_sWLRBackend->events.new_output, &Events::listen_newOutput, m_sWLRBackend, "Backend");
|
|
|
|
addWLSignal(&m_sWLRXDGShell->events.new_surface, &Events::listen_newXDGSurface, m_sWLRXDGShell, "XDG Shell");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.motion, &Events::listen_mouseMove, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.motion_absolute, &Events::listen_mouseMoveAbsolute, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.button, &Events::listen_mouseButton, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.axis, &Events::listen_mouseAxis, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.frame, &Events::listen_mouseFrame, m_sWLRCursor, "WLRCursor");
|
2022-07-07 11:52:12 +02:00
|
|
|
addWLSignal(&m_sWLRCursor->events.swipe_begin, &Events::listen_swipeBegin, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.swipe_update, &Events::listen_swipeUpdate, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.swipe_end, &Events::listen_swipeEnd, m_sWLRCursor, "WLRCursor");
|
2022-07-16 16:12:31 +02:00
|
|
|
addWLSignal(&m_sWLRCursor->events.pinch_begin, &Events::listen_pinchBegin, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.pinch_update, &Events::listen_pinchUpdate, m_sWLRCursor, "WLRCursor");
|
|
|
|
addWLSignal(&m_sWLRCursor->events.pinch_end, &Events::listen_pinchEnd, m_sWLRCursor, "WLRCursor");
|
2022-03-28 16:10:30 +02:00
|
|
|
addWLSignal(&m_sWLRBackend->events.new_input, &Events::listen_newInput, m_sWLRBackend, "Backend");
|
|
|
|
addWLSignal(&m_sSeat.seat->events.request_set_cursor, &Events::listen_requestMouse, &m_sSeat, "Seat");
|
|
|
|
addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat");
|
|
|
|
addWLSignal(&m_sSeat.seat->events.request_start_drag, &Events::listen_requestDrag, &m_sSeat, "Seat");
|
2022-03-31 17:25:23 +02:00
|
|
|
addWLSignal(&m_sSeat.seat->events.start_drag, &Events::listen_startDrag, &m_sSeat, "Seat");
|
2022-07-17 18:56:01 +02:00
|
|
|
addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat");
|
|
|
|
addWLSignal(&m_sSeat.seat->events.request_set_primary_selection, &Events::listen_requestSetPrimarySel, &m_sSeat, "Seat");
|
2022-03-28 16:10:30 +02:00
|
|
|
addWLSignal(&m_sWLRLayerShell->events.new_surface, &Events::listen_newLayerSurface, m_sWLRLayerShell, "LayerShell");
|
|
|
|
addWLSignal(&m_sWLROutputLayout->events.change, &Events::listen_change, m_sWLROutputLayout, "OutputLayout");
|
|
|
|
addWLSignal(&m_sWLROutputMgr->events.apply, &Events::listen_outputMgrApply, m_sWLROutputMgr, "OutputMgr");
|
|
|
|
addWLSignal(&m_sWLROutputMgr->events.test, &Events::listen_outputMgrTest, m_sWLROutputMgr, "OutputMgr");
|
|
|
|
addWLSignal(&m_sWLRInhibitMgr->events.activate, &Events::listen_InhibitActivate, m_sWLRInhibitMgr, "InhibitMgr");
|
|
|
|
addWLSignal(&m_sWLRInhibitMgr->events.deactivate, &Events::listen_InhibitDeactivate, m_sWLRInhibitMgr, "InhibitMgr");
|
2022-04-17 21:40:04 +02:00
|
|
|
addWLSignal(&m_sWLRPointerConstraints->events.new_constraint, &Events::listen_newConstraint, m_sWLRPointerConstraints, "PointerConstraints");
|
2022-05-10 11:01:03 +02:00
|
|
|
addWLSignal(&m_sWLRXDGDecoMgr->events.new_toplevel_decoration, &Events::listen_NewXDGDeco, m_sWLRXDGDecoMgr, "XDGDecoMgr");
|
2022-05-12 12:13:02 +02:00
|
|
|
addWLSignal(&m_sWLRVirtPtrMgr->events.new_virtual_pointer, &Events::listen_newVirtPtr, m_sWLRVirtPtrMgr, "VirtPtrMgr");
|
2022-06-06 13:48:17 +02:00
|
|
|
addWLSignal(&m_sWLRRenderer->events.destroy, &Events::listen_RendererDestroy, m_sWLRRenderer, "WLRRenderer");
|
2022-07-06 15:42:37 +02:00
|
|
|
addWLSignal(&m_sWLRIdleInhibitMgr->events.new_inhibitor, &Events::listen_newIdleInhibitor, m_sWLRIdleInhibitMgr, "WLRIdleInhibitMgr");
|
2022-07-30 22:41:24 +02:00
|
|
|
addWLSignal(&m_sWLROutputPowerMgr->events.set_mode, &Events::listen_powerMgrSetMode, m_sWLROutputPowerMgr, "PowerMgr");
|
2022-07-13 18:31:09 +02:00
|
|
|
if (m_sWLRSession)
|
|
|
|
addWLSignal(&m_sWLRSession->events.active, &Events::listen_sessionActive, m_sWLRSession, "Session");
|
2022-04-21 15:59:28 +02:00
|
|
|
}
|
|
|
|
|
2022-07-13 18:18:23 +02:00
|
|
|
void CCompositor::cleanup() {
|
2022-04-21 15:59:28 +02:00
|
|
|
if (!m_sWLDisplay)
|
|
|
|
return;
|
|
|
|
|
2022-05-29 00:07:31 +02:00
|
|
|
m_pLastFocus = nullptr;
|
|
|
|
m_pLastWindow = nullptr;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
m_vWorkspaces.clear();
|
|
|
|
m_vWindows.clear();
|
2022-05-29 00:00:47 +02:00
|
|
|
|
2022-04-21 15:59:28 +02:00
|
|
|
if (g_pXWaylandManager->m_sWLRXWayland) {
|
|
|
|
wlr_xwayland_destroy(g_pXWaylandManager->m_sWLRXWayland);
|
|
|
|
g_pXWaylandManager->m_sWLRXWayland = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-13 18:18:23 +02:00
|
|
|
wl_display_terminate(m_sWLDisplay);
|
2022-04-21 15:59:28 +02:00
|
|
|
|
|
|
|
m_sWLDisplay = nullptr;
|
2022-03-18 23:52:36 +01:00
|
|
|
}
|
2022-03-17 17:08:54 +01:00
|
|
|
|
2022-03-18 23:52:36 +01:00
|
|
|
void CCompositor::startCompositor() {
|
2022-03-17 17:08:54 +01:00
|
|
|
// Init all the managers BEFORE we start with the wayland server so that ALL of the stuff is initialized
|
|
|
|
// properly and we dont get any bad mem reads.
|
|
|
|
//
|
2022-04-08 21:40:41 +02:00
|
|
|
Debug::log(LOG, "Creating the CHyprError!");
|
|
|
|
g_pHyprError = std::make_unique<CHyprError>();
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
Debug::log(LOG, "Creating the KeybindManager!");
|
|
|
|
g_pKeybindManager = std::make_unique<CKeybindManager>();
|
|
|
|
|
2022-04-23 21:47:16 +02:00
|
|
|
Debug::log(LOG, "Creating the AnimationManager!");
|
|
|
|
g_pAnimationManager = std::make_unique<CAnimationManager>();
|
|
|
|
|
2022-07-16 15:57:31 +02:00
|
|
|
Debug::log(LOG, "Creating the LayoutManager!");
|
|
|
|
g_pLayoutManager = std::make_unique<CLayoutManager>();
|
|
|
|
|
2022-03-18 20:03:39 +01:00
|
|
|
Debug::log(LOG, "Creating the ConfigManager!");
|
2022-03-17 17:08:54 +01:00
|
|
|
g_pConfigManager = std::make_unique<CConfigManager>();
|
|
|
|
|
2022-03-18 20:03:39 +01:00
|
|
|
Debug::log(LOG, "Creating the ThreadManager!");
|
|
|
|
g_pThreadManager = std::make_unique<CThreadManager>();
|
2022-03-17 17:08:54 +01:00
|
|
|
|
|
|
|
Debug::log(LOG, "Creating the InputManager!");
|
|
|
|
g_pInputManager = std::make_unique<CInputManager>();
|
2022-03-17 20:22:29 +01:00
|
|
|
|
2022-04-04 19:44:25 +02:00
|
|
|
Debug::log(LOG, "Creating the CHyprOpenGLImpl!");
|
|
|
|
g_pHyprOpenGL = std::make_unique<CHyprOpenGLImpl>();
|
|
|
|
|
2022-03-17 20:22:29 +01:00
|
|
|
Debug::log(LOG, "Creating the HyprRenderer!");
|
|
|
|
g_pHyprRenderer = std::make_unique<CHyprRenderer>();
|
2022-03-18 20:03:39 +01:00
|
|
|
|
|
|
|
Debug::log(LOG, "Creating the XWaylandManager!");
|
|
|
|
g_pXWaylandManager = std::make_unique<CHyprXWaylandManager>();
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2022-05-24 19:42:43 +02:00
|
|
|
Debug::log(LOG, "Creating the EventManager!");
|
|
|
|
g_pEventManager = std::make_unique<CEventManager>();
|
|
|
|
g_pEventManager->startThread();
|
2022-05-28 17:32:19 +02:00
|
|
|
|
|
|
|
Debug::log(LOG, "Creating the HyprDebugOverlay!");
|
|
|
|
g_pDebugOverlay = std::make_unique<CHyprDebugOverlay>();
|
2022-03-17 17:08:54 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2022-07-26 10:05:29 +02:00
|
|
|
// firefox wont detect wl
|
|
|
|
setenv("MOZ_ENABLE_WAYLAND", "1", 1);
|
|
|
|
|
2022-03-18 23:52:36 +01:00
|
|
|
initAllSignals();
|
|
|
|
|
2022-03-31 19:16:00 +02:00
|
|
|
// Set XDG_CURRENT_DESKTOP to our compositor's name
|
|
|
|
setenv("XDG_CURRENT_DESKTOP", "hyprland", true);
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
m_szWLDisplaySocket = wl_display_add_socket_auto(m_sWLDisplay);
|
|
|
|
|
|
|
|
if (!m_szWLDisplaySocket) {
|
|
|
|
Debug::log(CRIT, "m_szWLDisplaySocket NULL!");
|
2022-03-17 19:03:15 +01:00
|
|
|
wlr_backend_destroy(m_sWLRBackend);
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("m_szWLDisplaySocket was null! (wl_display_add_socket_auto failed)");
|
2022-03-16 21:37:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket, 1);
|
|
|
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
Debug::log(LOG, "Running on WAYLAND_DISPLAY: %s", m_szWLDisplaySocket);
|
2022-03-16 21:37:21 +01:00
|
|
|
|
|
|
|
if (!wlr_backend_start(m_sWLRBackend)) {
|
|
|
|
Debug::log(CRIT, "Backend did not start!");
|
2022-03-17 19:03:15 +01:00
|
|
|
wlr_backend_destroy(m_sWLRBackend);
|
|
|
|
wl_display_destroy(m_sWLDisplay);
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("The backend could not start!");
|
2022-03-16 21:37:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wlr_xcursor_manager_set_cursor_image(m_sWLRXCursorMgr, "left_ptr", m_sWLRCursor);
|
|
|
|
|
|
|
|
// This blocks until we are done.
|
|
|
|
Debug::log(LOG, "Hyprland is ready, running the event loop!");
|
|
|
|
wl_display_run(m_sWLDisplay);
|
2022-03-17 20:22:29 +01:00
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* CCompositor::getMonitorFromID(const int& id) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if (m->ID == (uint64_t)id) {
|
|
|
|
return m.get();
|
2022-03-17 20:22:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* CCompositor::getMonitorFromName(const std::string& name) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if (m->szName == name) {
|
|
|
|
return m.get();
|
2022-05-29 20:15:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* CCompositor::getMonitorFromCursor() {
|
2022-03-19 20:30:21 +01:00
|
|
|
const auto COORDS = Vector2D(m_sWLRCursor->x, m_sWLRCursor->y);
|
2022-03-17 20:22:29 +01:00
|
|
|
|
2022-05-25 18:40:03 +02:00
|
|
|
return getMonitorFromVector(COORDS);
|
2022-03-18 22:35:51 +01:00
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
|
2022-03-20 11:22:55 +01:00
|
|
|
const auto OUTPUT = wlr_output_layout_output_at(m_sWLROutputLayout, point.x, point.y);
|
|
|
|
|
|
|
|
if (!OUTPUT) {
|
2022-05-25 18:40:03 +02:00
|
|
|
float bestDistance = 0.f;
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* pBestMon = nullptr;
|
2022-05-25 18:40:03 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
float dist = vecToRectDistanceSquared(point, m->vecPosition, m->vecPosition + m->vecSize);
|
2022-05-25 18:40:03 +02:00
|
|
|
|
|
|
|
if (dist < bestDistance || !pBestMon) {
|
|
|
|
bestDistance = dist;
|
2022-06-30 15:44:26 +02:00
|
|
|
pBestMon = m.get();
|
2022-05-25 18:40:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pBestMon) { // ?????
|
|
|
|
Debug::log(WARN, "getMonitorFromVector no close mon???");
|
2022-06-30 15:44:26 +02:00
|
|
|
return m_vMonitors.front().get();
|
2022-05-25 18:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pBestMon;
|
2022-03-20 11:22:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return getMonitorFromOutput(OUTPUT);
|
|
|
|
}
|
|
|
|
|
2022-03-18 22:35:51 +01:00
|
|
|
void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) {
|
2022-06-30 15:44:26 +02:00
|
|
|
if (windowExists(pWindow) && !pWindow->m_bFadingOut){
|
|
|
|
if (pWindow->m_bIsX11 && pWindow->m_iX11Type == 2) {
|
|
|
|
m_dUnmanagedX11Windows.erase(std::remove_if(m_dUnmanagedX11Windows.begin(), m_dUnmanagedX11Windows.end(), [&](std::unique_ptr<CWindow>& el) { return el.get() == pWindow; }));
|
|
|
|
}
|
|
|
|
|
|
|
|
// if X11, also check its children
|
|
|
|
// and delete any needed
|
|
|
|
if (pWindow->m_bIsX11) {
|
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (!w->m_bIsX11)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (w->m_pX11Parent == pWindow)
|
|
|
|
m_vWindows.erase(std::remove_if(m_vWindows.begin(), m_vWindows.end(), [&](std::unique_ptr<CWindow>& el) { return el.get() == w.get(); }));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& w : m_dUnmanagedX11Windows) {
|
|
|
|
if (w->m_pX11Parent == pWindow)
|
|
|
|
m_dUnmanagedX11Windows.erase(std::remove_if(m_dUnmanagedX11Windows.begin(), m_dUnmanagedX11Windows.end(), [&](std::unique_ptr<CWindow>& el) { return el.get() == w.get(); }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_vWindows.erase(std::remove_if(m_vWindows.begin(), m_vWindows.end(), [&](std::unique_ptr<CWindow>& el) { return el.get() == pWindow; }));
|
|
|
|
}
|
2022-03-18 22:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCompositor::windowExists(CWindow* pWindow) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w.get() == pWindow)
|
2022-03-18 22:53:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::vectorToWindow(const Vector2D& pos) {
|
2022-03-20 15:55:47 +01:00
|
|
|
const auto PMONITOR = getMonitorFromVector(pos);
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
if (PMONITOR->specialWorkspaceOpen) {
|
2022-07-06 11:07:23 +02:00
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
|
|
|
if ((*w)->m_bIsFloating && (*w)->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && (*w)->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !(*w)->m_bHidden)
|
|
|
|
return (*w).get();
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
|
|
|
|
if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && !w->m_bIsFloating && !w->m_bHidden)
|
|
|
|
return w.get();
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
// first loop over floating cuz they're above, m_vWindows should be sorted bottom->top, for tiled it doesn't matter.
|
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
|
|
|
if (wlr_box_contains_point(&box, pos.x, pos.y) && (*w)->m_bIsMapped && (*w)->m_bIsFloating && isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden)
|
|
|
|
return w->get();
|
2022-03-22 17:14:07 +01:00
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
|
|
|
|
if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && !w->m_bIsFloating && PMONITOR->activeWorkspace == w->m_iWorkspaceID && !w->m_bHidden)
|
|
|
|
return w.get();
|
2022-03-18 22:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-20 18:31:58 +01:00
|
|
|
CWindow* CCompositor::vectorToWindowTiled(const Vector2D& pos) {
|
|
|
|
const auto PMONITOR = getMonitorFromVector(pos);
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
if (PMONITOR->specialWorkspaceOpen) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
|
|
|
|
if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, pos.x, pos.y) && !w->m_bIsFloating && !w->m_bHidden)
|
|
|
|
return w.get();
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
|
|
|
|
if (w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bIsFloating && !w->m_bHidden)
|
|
|
|
return w.get();
|
2022-03-20 18:31:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-12 09:49:56 +02:00
|
|
|
void findExtensionForVector2D(wlr_surface* surface, int x, int y, void* data) {
|
|
|
|
const auto DATA = (SExtensionFindingData*)data;
|
|
|
|
|
|
|
|
wlr_box box = {DATA->origin.x + x, DATA->origin.y + y, surface->current.width, surface->current.height};
|
|
|
|
|
|
|
|
if (wlr_box_contains_point(&box, DATA->vec.x, DATA->vec.y))
|
|
|
|
*DATA->found = surface;
|
|
|
|
}
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) {
|
2022-03-20 15:55:47 +01:00
|
|
|
const auto PMONITOR = getMonitorFromVector(pos);
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
// special workspace
|
|
|
|
if (PMONITOR->specialWorkspaceOpen) {
|
2022-07-06 11:07:23 +02:00
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
2022-07-08 23:37:55 +02:00
|
|
|
if ((*w)->m_bIsFloating && (*w)->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && (*w)->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !(*w)->m_bHidden && (*w)->m_iX11Type != 2)
|
2022-07-06 11:07:23 +02:00
|
|
|
return (*w).get();
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
|
2022-07-08 23:37:55 +02:00
|
|
|
if (!w->m_bIsFloating && w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !w->m_bHidden && w->m_iX11Type != 2)
|
2022-06-30 15:44:26 +02:00
|
|
|
return w.get();
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:25:30 +02:00
|
|
|
// first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter.
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
2022-07-12 09:49:56 +02:00
|
|
|
if ((*w)->m_bIsFloating && (*w)->m_bIsMapped && isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden && (*w)->m_iX11Type != 2) {
|
|
|
|
if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y))
|
|
|
|
return w->get();
|
|
|
|
|
|
|
|
if (!(*w)->m_bIsX11) {
|
|
|
|
wlr_surface* resultSurf = nullptr;
|
|
|
|
Vector2D origin =(*w)->m_vRealPosition.vec();
|
|
|
|
SExtensionFindingData data = {origin, pos, &resultSurf};
|
|
|
|
wlr_xdg_surface_for_each_popup_surface((*w)->m_uSurface.xdg, findExtensionForVector2D, &data);
|
|
|
|
|
|
|
|
if (resultSurf)
|
|
|
|
return w->get();
|
|
|
|
}
|
|
|
|
}
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
2022-07-12 09:49:56 +02:00
|
|
|
// for windows, we need to check their extensions too, first.
|
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (!w->m_bIsX11 && !w->m_bIsFloating && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bHidden && w->m_iX11Type != 2) {
|
|
|
|
wlr_surface* resultSurf = nullptr;
|
|
|
|
Vector2D origin = w->m_vRealPosition.vec();
|
|
|
|
SExtensionFindingData data = {origin, pos, &resultSurf};
|
|
|
|
wlr_xdg_surface_for_each_popup_surface(w->m_uSurface.xdg, findExtensionForVector2D, &data);
|
|
|
|
|
|
|
|
if (resultSurf)
|
|
|
|
return w.get();
|
|
|
|
}
|
|
|
|
}
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
|
2022-07-08 23:37:55 +02:00
|
|
|
if (!w->m_bIsFloating && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bHidden && w->m_iX11Type != 2)
|
2022-06-30 15:44:26 +02:00
|
|
|
return w.get();
|
2022-03-19 20:30:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::windowFromCursor() {
|
|
|
|
const auto PMONITOR = getMonitorFromCursor();
|
2022-03-20 11:14:24 +01:00
|
|
|
|
2022-05-31 14:01:00 +02:00
|
|
|
if (PMONITOR->specialWorkspaceOpen) {
|
2022-07-06 11:07:23 +02:00
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
|
|
|
if ((*w)->m_bIsFloating && (*w)->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && (*w)->m_bIsMapped && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && !(*w)->m_bHidden)
|
|
|
|
return (*w).get();
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
|
|
|
|
if (w->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped)
|
|
|
|
return w.get();
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:25:30 +02:00
|
|
|
// first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter.
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
|
|
|
if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && (*w)->m_bIsMapped && (*w)->m_bIsFloating && isWorkspaceVisible((*w)->m_iWorkspaceID))
|
|
|
|
return w->get();
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
|
|
|
|
if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace)
|
|
|
|
return w.get();
|
2022-03-19 17:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
CWindow* CCompositor::windowFloatingFromCursor() {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto w = m_vWindows.rbegin(); w != m_vWindows.rend(); w++) {
|
|
|
|
wlr_box box = {(*w)->m_vRealPosition.vec().x, (*w)->m_vRealPosition.vec().y, (*w)->m_vRealSize.vec().x, (*w)->m_vRealSize.vec().y};
|
|
|
|
if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && (*w)->m_bIsMapped && (*w)->m_bIsFloating && isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden)
|
|
|
|
return w->get();
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-02 13:02:16 +02:00
|
|
|
wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pWindow, Vector2D& sl) {
|
|
|
|
|
|
|
|
if (!windowValidMapped(pWindow))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
RASSERT(!pWindow->m_bIsX11, "Cannot call vectorWindowToSurface on an X11 window!");
|
|
|
|
|
|
|
|
const auto PSURFACE = pWindow->m_uSurface.xdg;
|
2022-05-10 11:01:03 +02:00
|
|
|
|
2022-04-02 13:02:16 +02:00
|
|
|
double subx, suby;
|
|
|
|
|
2022-06-22 15:45:56 +02:00
|
|
|
// calc for oversized windows... fucking bullshit, again.
|
|
|
|
wlr_box geom;
|
|
|
|
wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, &geom);
|
|
|
|
|
|
|
|
const auto PFOUND = wlr_xdg_surface_surface_at(PSURFACE, pos.x - pWindow->m_vRealPosition.vec().x + geom.x, pos.y - pWindow->m_vRealPosition.vec().y + geom.y, &subx, &suby);
|
2022-04-02 13:02:16 +02:00
|
|
|
|
|
|
|
if (PFOUND) {
|
|
|
|
sl.x = subx;
|
|
|
|
sl.y = suby;
|
|
|
|
return PFOUND;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
sl.x = pos.x - pWindow->m_vRealPosition.vec().x;
|
|
|
|
sl.y = pos.y - pWindow->m_vRealPosition.vec().y;
|
2022-04-02 13:02:16 +02:00
|
|
|
|
2022-06-22 15:45:56 +02:00
|
|
|
sl.x += geom.x;
|
|
|
|
sl.y += geom.y;
|
|
|
|
|
2022-04-02 13:02:16 +02:00
|
|
|
return PSURFACE->surface;
|
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* CCompositor::getMonitorFromOutput(wlr_output* out) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if (m->output == out) {
|
|
|
|
return m.get();
|
2022-03-19 20:56:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-02 18:57:09 +02:00
|
|
|
void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
|
2022-03-18 22:53:27 +01:00
|
|
|
|
2022-04-18 17:16:01 +02:00
|
|
|
if (g_pCompositor->m_sSeat.exclusiveClient) {
|
|
|
|
Debug::log(LOG, "Disallowing setting focus to a window due to there being an active input inhibitor layer.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-14 20:56:21 +02:00
|
|
|
if (!pWindow || !windowValidMapped(pWindow)) {
|
|
|
|
wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat);
|
2022-05-14 14:37:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-14 20:56:21 +02:00
|
|
|
if (pWindow->m_bNoFocus) {
|
|
|
|
Debug::log(LOG, "Ignoring focus to nofocus window!");
|
2022-03-18 22:53:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-14 18:16:09 +02:00
|
|
|
if (m_pLastWindow == pWindow && m_sSeat.seat->keyboard_state.focused_surface == pSurface)
|
2022-04-05 18:29:58 +02:00
|
|
|
return;
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
const auto PLASTWINDOW = m_pLastWindow;
|
|
|
|
m_pLastWindow = pWindow;
|
|
|
|
|
|
|
|
// we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window
|
|
|
|
if (windowValidMapped(PLASTWINDOW)) {
|
2022-07-12 13:40:55 +02:00
|
|
|
updateWindowAnimatedDecorationValues(PLASTWINDOW);
|
2022-04-23 14:16:02 +02:00
|
|
|
|
|
|
|
if (PLASTWINDOW->m_bIsX11) {
|
|
|
|
wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat);
|
|
|
|
wlr_seat_pointer_clear_focus(m_sSeat.seat);
|
|
|
|
}
|
2022-05-29 11:24:42 +02:00
|
|
|
|
|
|
|
if (PLASTWINDOW->m_phForeignToplevel)
|
|
|
|
wlr_foreign_toplevel_handle_v1_set_activated(PLASTWINDOW->m_phForeignToplevel, false);
|
2022-04-05 18:29:58 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
m_pLastWindow = PLASTWINDOW;
|
|
|
|
|
2022-04-02 18:57:09 +02:00
|
|
|
const auto PWINDOWSURFACE = pSurface ? pSurface : g_pXWaylandManager->getWindowSurface(pWindow);
|
2022-03-18 22:53:27 +01:00
|
|
|
|
2022-04-02 18:57:09 +02:00
|
|
|
focusSurface(PWINDOWSURFACE, pWindow);
|
|
|
|
|
2022-04-23 14:16:02 +02:00
|
|
|
g_pXWaylandManager->activateWindow(pWindow, true); // sets the m_pLastWindow
|
2022-04-02 18:57:09 +02:00
|
|
|
|
2022-04-14 21:30:18 +02:00
|
|
|
// do pointer focus too
|
2022-04-23 14:35:34 +02:00
|
|
|
const auto POINTERLOCAL = g_pInputManager->getMouseCoordsInternal() - pWindow->m_vRealPosition.goalv();
|
2022-04-14 21:30:18 +02:00
|
|
|
wlr_seat_pointer_notify_enter(m_sSeat.seat, PWINDOWSURFACE, POINTERLOCAL.x, POINTERLOCAL.y);
|
2022-04-13 20:19:40 +02:00
|
|
|
|
2022-07-12 13:40:55 +02:00
|
|
|
updateWindowAnimatedDecorationValues(pWindow);
|
2022-05-24 22:21:31 +02:00
|
|
|
|
|
|
|
// Send an event
|
2022-07-20 18:39:08 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", g_pXWaylandManager->getAppIDClass(pWindow) + "," + pWindow->m_szTitle});
|
2022-05-29 11:24:42 +02:00
|
|
|
|
|
|
|
if (pWindow->m_phForeignToplevel)
|
|
|
|
wlr_foreign_toplevel_handle_v1_set_activated(pWindow->m_phForeignToplevel, true);
|
2022-03-20 14:36:55 +01:00
|
|
|
}
|
|
|
|
|
2022-04-02 13:02:16 +02:00
|
|
|
void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
|
2022-04-18 17:16:01 +02:00
|
|
|
|
2022-04-02 13:02:16 +02:00
|
|
|
if (m_sSeat.seat->keyboard_state.focused_surface == pSurface || (pWindowOwner && m_sSeat.seat->keyboard_state.focused_surface == g_pXWaylandManager->getWindowSurface(pWindowOwner)))
|
2022-03-20 14:36:55 +01:00
|
|
|
return; // Don't focus when already focused on this.
|
|
|
|
|
2022-07-07 21:47:59 +02:00
|
|
|
// Unfocus last surface if should
|
|
|
|
if (m_pLastFocus && ((m_sSeat.seat->keyboard_state.focused_surface && wlr_surface_is_xdg_surface(m_pLastFocus)) || !pSurface))
|
|
|
|
g_pXWaylandManager->activateSurface(m_pLastFocus, false);
|
|
|
|
|
2022-07-11 12:29:50 +02:00
|
|
|
if (!pSurface) {
|
|
|
|
wlr_seat_keyboard_clear_focus(m_sSeat.seat);
|
2022-07-20 18:39:08 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","}); // unfocused
|
2022-03-27 19:16:33 +02:00
|
|
|
return;
|
2022-07-11 12:29:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-27 19:16:33 +02:00
|
|
|
|
2022-03-22 18:29:13 +01:00
|
|
|
const auto KEYBOARD = wlr_seat_get_keyboard(m_sSeat.seat);
|
2022-03-27 19:16:33 +02:00
|
|
|
|
|
|
|
if (!KEYBOARD)
|
|
|
|
return;
|
|
|
|
|
2022-03-22 18:29:13 +01:00
|
|
|
wlr_seat_keyboard_notify_enter(m_sSeat.seat, pSurface, KEYBOARD->keycodes, KEYBOARD->num_keycodes, &KEYBOARD->modifiers);
|
2022-03-18 22:53:27 +01:00
|
|
|
|
2022-04-02 19:09:27 +02:00
|
|
|
wlr_seat_keyboard_focus_change_event event = {
|
|
|
|
.seat = m_sSeat.seat,
|
|
|
|
.old_surface = m_pLastFocus,
|
|
|
|
.new_surface = pSurface,
|
|
|
|
};
|
|
|
|
wlr_signal_emit_safe(&m_sSeat.seat->keyboard_state.events.focus_change, &event);
|
|
|
|
|
2022-04-10 11:17:06 +02:00
|
|
|
if (pWindowOwner)
|
|
|
|
Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s", pSurface, pWindowOwner->m_szTitle.c_str());
|
2022-03-31 19:41:55 +02:00
|
|
|
else
|
2022-04-01 23:31:12 +02:00
|
|
|
Debug::log(LOG, "Set keyboard focus to surface %x", pSurface);
|
2022-07-08 13:19:57 +02:00
|
|
|
|
|
|
|
g_pXWaylandManager->activateSurface(pSurface, false);
|
|
|
|
m_pLastFocus = pSurface;
|
2022-03-18 23:16:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCompositor::windowValidMapped(CWindow* pWindow) {
|
|
|
|
if (!windowExists(pWindow))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (pWindow->m_bIsX11 && !pWindow->m_bMappedX11)
|
|
|
|
return false;
|
|
|
|
|
2022-03-22 20:53:11 +01:00
|
|
|
if (!pWindow->m_bIsMapped)
|
|
|
|
return false;
|
|
|
|
|
2022-04-12 16:44:18 +02:00
|
|
|
if (pWindow->m_bHidden)
|
|
|
|
return false;
|
|
|
|
|
2022-03-18 23:16:15 +01:00
|
|
|
return true;
|
2022-03-20 12:11:57 +01:00
|
|
|
}
|
|
|
|
|
2022-03-20 14:00:46 +01:00
|
|
|
CWindow* CCompositor::getWindowForPopup(wlr_xdg_popup* popup) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& p : m_vXDGPopups) {
|
|
|
|
if (p->popup == popup)
|
|
|
|
return p->parentWindow;
|
2022-03-20 14:00:46 +01:00
|
|
|
}
|
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-23 15:48:08 +02:00
|
|
|
wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector<std::unique_ptr<SLayerSurface>>* layerSurfaces, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) {
|
2022-06-10 15:18:30 +02:00
|
|
|
for (auto it = layerSurfaces->rbegin(); it != layerSurfaces->rend(); it++) {
|
|
|
|
if ((*it)->fadingOut || !(*it)->layerSurface || ((*it)->layerSurface && !(*it)->layerSurface->mapped))
|
2022-03-20 14:36:55 +01:00
|
|
|
continue;
|
|
|
|
|
2022-06-10 15:18:30 +02:00
|
|
|
const auto SURFACEAT = wlr_layer_surface_v1_surface_at((*it)->layerSurface, pos.x - (*it)->geometry.x, pos.y - (*it)->geometry.y, &sCoords->x, &sCoords->y);
|
2022-03-20 14:36:55 +01:00
|
|
|
|
2022-07-01 20:14:33 +02:00
|
|
|
if (SURFACEAT) {
|
2022-07-23 15:48:08 +02:00
|
|
|
*ppLayerSurfaceFound = it->get();
|
2022-03-20 14:36:55 +01:00
|
|
|
return SURFACEAT;
|
2022-07-01 20:14:33 +02:00
|
|
|
}
|
2022-03-20 14:36:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::getWindowFromSurface(wlr_surface* pSurface) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (g_pXWaylandManager->getWindowSurface(w.get()) == pSurface)
|
|
|
|
return w.get();
|
2022-03-20 14:36:55 +01:00
|
|
|
}
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w->m_iWorkspaceID == ID && w->m_bIsFullscreen)
|
|
|
|
return w.get();
|
2022-03-21 19:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
bool CCompositor::isWorkspaceVisible(const int& w) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if (m->activeWorkspace == w)
|
2022-03-20 15:55:47 +01:00
|
|
|
return true;
|
2022-05-31 14:01:00 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
if (m->specialWorkspaceOpen && w == SPECIAL_WORKSPACE_ID)
|
2022-05-31 14:01:00 +02:00
|
|
|
return true;
|
2022-03-20 15:55:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
CWorkspace* CCompositor::getWorkspaceByID(const int& id) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWorkspaces) {
|
|
|
|
if (w->m_iID == id)
|
|
|
|
return w.get();
|
2022-03-20 15:55:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::sanityCheckWorkspaces() {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto it = m_vWorkspaces.begin(); it != m_vWorkspaces.end(); ++it) {
|
2022-06-30 16:11:26 +02:00
|
|
|
const auto WINDOWSONWORKSPACE = getWindowsOnWorkspace((*it)->m_iID);
|
2022-06-30 16:00:44 +02:00
|
|
|
|
2022-06-30 16:11:26 +02:00
|
|
|
if ((WINDOWSONWORKSPACE == 0 && !isWorkspaceVisible((*it)->m_iID))) {
|
2022-06-30 15:44:26 +02:00
|
|
|
it = m_vWorkspaces.erase(it);
|
2022-05-31 14:01:00 +02:00
|
|
|
|
2022-06-30 16:11:26 +02:00
|
|
|
if (it == m_vWorkspaces.end())
|
|
|
|
break;
|
2022-07-07 19:00:34 +02:00
|
|
|
|
|
|
|
continue;
|
2022-06-30 16:11:26 +02:00
|
|
|
}
|
2022-06-30 16:00:44 +02:00
|
|
|
|
2022-06-30 16:11:26 +02:00
|
|
|
if ((*it)->m_iID == SPECIAL_WORKSPACE_ID && WINDOWSONWORKSPACE == 0) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
m->specialWorkspaceOpen = false;
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
it = m_vWorkspaces.erase(it);
|
2022-06-30 16:11:26 +02:00
|
|
|
|
|
|
|
if (it == m_vWorkspaces.end())
|
|
|
|
break;
|
2022-07-07 19:00:34 +02:00
|
|
|
|
|
|
|
continue;
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
2022-03-20 15:55:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCompositor::getWindowsOnWorkspace(const int& id) {
|
|
|
|
int no = 0;
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w->m_iWorkspaceID == id && w->m_bIsMapped)
|
2022-03-20 15:55:47 +01:00
|
|
|
no++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return no;
|
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::getFirstWindowOnWorkspace(const int& id) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w->m_iWorkspaceID == id)
|
|
|
|
return w.get();
|
2022-03-20 15:55:47 +01:00
|
|
|
}
|
|
|
|
|
2022-03-20 14:00:46 +01:00
|
|
|
return nullptr;
|
2022-03-20 19:14:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::fixXWaylandWindowsOnWorkspace(const int& id) {
|
2022-07-18 21:15:46 +02:00
|
|
|
// not needed anymore
|
|
|
|
return;
|
|
|
|
|
2022-03-20 19:14:17 +01:00
|
|
|
const auto ISVISIBLE = isWorkspaceVisible(id);
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id);
|
|
|
|
|
2022-05-30 20:05:38 +02:00
|
|
|
if (!PWORKSPACE)
|
|
|
|
return;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w->m_iWorkspaceID == id) {
|
2022-03-20 19:14:17 +01:00
|
|
|
|
|
|
|
// moveXWaylandWindow only moves XWayland windows
|
|
|
|
// so there is no need to check here
|
|
|
|
// if the window is XWayland or not.
|
2022-06-30 15:44:26 +02:00
|
|
|
if (ISVISIBLE && (!PWORKSPACE->m_bHasFullscreenWindow || w->m_bIsFullscreen))
|
|
|
|
g_pXWaylandManager->moveXWaylandWindow(w.get(), w->m_vRealPosition.vec());
|
2022-03-20 19:14:17 +01:00
|
|
|
else
|
2022-06-30 15:44:26 +02:00
|
|
|
g_pXWaylandManager->moveXWaylandWindow(w.get(), Vector2D(42069,42069));
|
2022-03-20 19:14:17 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 18:29:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCompositor::doesSeatAcceptInput(wlr_surface* surface) {
|
2022-03-22 21:59:14 +01:00
|
|
|
return !m_sSeat.exclusiveClient || (surface && m_sSeat.exclusiveClient == wl_resource_get_client(surface->resource));
|
2022-04-02 13:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCompositor::isWindowActive(CWindow* pWindow) {
|
2022-05-29 00:07:31 +02:00
|
|
|
if (!m_pLastWindow && !m_pLastFocus)
|
|
|
|
return false;
|
|
|
|
|
2022-04-02 18:57:09 +02:00
|
|
|
if (!windowValidMapped(pWindow))
|
|
|
|
return false;
|
|
|
|
|
2022-04-02 13:02:16 +02:00
|
|
|
const auto PSURFACE = g_pXWaylandManager->getWindowSurface(pWindow);
|
|
|
|
|
2022-04-02 18:57:09 +02:00
|
|
|
return PSURFACE == m_pLastFocus || pWindow == m_pLastWindow;
|
2022-04-04 16:25:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::moveWindowToTop(CWindow* pWindow) {
|
|
|
|
if (!windowValidMapped(pWindow))
|
|
|
|
return;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto it = m_vWindows.begin(); it != m_vWindows.end(); ++it) {
|
|
|
|
if (it->get() == pWindow) {
|
|
|
|
std::rotate(it, it + 1, m_vWindows.end());
|
2022-04-04 16:25:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 19:28:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-12 23:11:34 +02:00
|
|
|
void CCompositor::cleanupFadingOut(const int& monid) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindowsFadingOut) {
|
2022-04-26 17:51:00 +02:00
|
|
|
|
2022-07-12 23:11:34 +02:00
|
|
|
if (w->m_iMonitorID != (long unsigned int)monid)
|
|
|
|
continue;
|
|
|
|
|
2022-04-28 15:39:49 +02:00
|
|
|
bool valid = windowExists(w);
|
2022-06-30 15:44:26 +02:00
|
|
|
|
2022-04-26 17:51:00 +02:00
|
|
|
if (!valid || !w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) {
|
|
|
|
if (valid && !w->m_bReadyToDelete)
|
2022-04-10 11:17:06 +02:00
|
|
|
continue;
|
|
|
|
|
2022-04-05 20:49:15 +02:00
|
|
|
g_pHyprOpenGL->m_mWindowFramebuffers[w].release();
|
|
|
|
g_pHyprOpenGL->m_mWindowFramebuffers.erase(w);
|
2022-06-30 15:44:26 +02:00
|
|
|
removeWindowFromVectorSafe(w);
|
|
|
|
m_vWindowsFadingOut.erase(std::remove(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), w));
|
2022-04-10 11:17:06 +02:00
|
|
|
|
|
|
|
Debug::log(LOG, "Cleanup: destroyed a window");
|
2022-07-12 23:11:34 +02:00
|
|
|
|
|
|
|
glFlush(); // to free mem NOW.
|
2022-04-05 19:28:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-05-14 17:23:46 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& ls : m_vSurfacesFadingOut) {
|
2022-07-25 22:40:34 +02:00
|
|
|
|
|
|
|
// sometimes somehow fucking happens wtf
|
|
|
|
bool exists = false;
|
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
for (auto& lsl : m->m_aLayerSurfaceLists) {
|
|
|
|
for (auto& lsp : lsl) {
|
|
|
|
if (lsp.get() == ls) {
|
|
|
|
exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists) {
|
|
|
|
m_vSurfacesFadingOut.erase(std::remove(m_vSurfacesFadingOut.begin(), m_vSurfacesFadingOut.end(), ls));
|
|
|
|
|
|
|
|
Debug::log(LOG, "Fading out a non-existent LS??");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:11:34 +02:00
|
|
|
if (ls->monitorID != monid)
|
|
|
|
continue;
|
|
|
|
|
2022-05-14 17:23:46 +02:00
|
|
|
if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) {
|
|
|
|
g_pHyprOpenGL->m_mLayerFramebuffers[ls].release();
|
|
|
|
g_pHyprOpenGL->m_mLayerFramebuffers.erase(ls);
|
|
|
|
|
2022-07-23 15:48:08 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
for (auto& lsl : m->m_aLayerSurfaceLists) {
|
2022-07-25 21:08:54 +02:00
|
|
|
if (!lsl.empty() && std::find_if(lsl.begin(), lsl.end(), [&](std::unique_ptr<SLayerSurface>& other) { return other.get() == ls; }) != lsl.end()) {
|
2022-07-23 15:48:08 +02:00
|
|
|
lsl.erase(std::remove_if(lsl.begin(), lsl.end(), [&](std::unique_ptr<SLayerSurface>& other) { return other.get() == ls; }));
|
2022-07-25 21:08:54 +02:00
|
|
|
}
|
2022-07-23 15:48:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 22:00:46 +02:00
|
|
|
m_vSurfacesFadingOut.erase(std::remove(m_vSurfacesFadingOut.begin(), m_vSurfacesFadingOut.end(), ls));
|
|
|
|
|
2022-05-14 17:28:55 +02:00
|
|
|
Debug::log(LOG, "Cleanup: destroyed a layersurface");
|
|
|
|
|
2022-07-12 23:11:34 +02:00
|
|
|
glFlush(); // to free mem NOW.
|
2022-05-14 17:23:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-09 13:26:55 +02:00
|
|
|
}
|
|
|
|
|
2022-07-25 21:08:54 +02:00
|
|
|
void CCompositor::addToFadingOutSafe(SLayerSurface* pLS) {
|
|
|
|
const auto FOUND = std::find_if(m_vSurfacesFadingOut.begin(), m_vSurfacesFadingOut.end(), [&](SLayerSurface* other) { return other == pLS; });
|
|
|
|
|
|
|
|
if (FOUND != m_vSurfacesFadingOut.end())
|
|
|
|
return; // if it's already added, don't add it.
|
|
|
|
|
|
|
|
m_vSurfacesFadingOut.emplace_back(pLS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::addToFadingOutSafe(CWindow* pWindow) {
|
|
|
|
const auto FOUND = std::find_if(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), [&](CWindow* other) { return other == pWindow; });
|
|
|
|
|
|
|
|
if (FOUND != m_vWindowsFadingOut.end())
|
|
|
|
return; // if it's already added, don't add it.
|
|
|
|
|
|
|
|
m_vWindowsFadingOut.emplace_back(pWindow);
|
|
|
|
}
|
|
|
|
|
2022-04-09 13:26:55 +02:00
|
|
|
CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
|
2022-06-23 20:39:48 +02:00
|
|
|
|
|
|
|
const auto WINDOWIDEALBB = pWindow->getWindowIdealBoundingBoxIgnoreReserved();
|
|
|
|
|
|
|
|
const auto POSA = Vector2D(WINDOWIDEALBB.x, WINDOWIDEALBB.y);
|
|
|
|
const auto SIZEA = Vector2D(WINDOWIDEALBB.width, WINDOWIDEALBB.height);
|
2022-04-09 13:26:55 +02:00
|
|
|
|
|
|
|
auto longestIntersect = -1;
|
|
|
|
CWindow* longestIntersectWindow = nullptr;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w.get() == pWindow || !w->m_bIsMapped || w->m_bHidden || w->m_bIsFloating || !isWorkspaceVisible(w->m_iWorkspaceID))
|
2022-04-09 13:26:55 +02:00
|
|
|
continue;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
const auto BWINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved();
|
2022-06-23 20:39:48 +02:00
|
|
|
|
|
|
|
const auto POSB = Vector2D(BWINDOWIDEALBB.x, BWINDOWIDEALBB.y);
|
|
|
|
const auto SIZEB = Vector2D(BWINDOWIDEALBB.width, BWINDOWIDEALBB.height);
|
|
|
|
|
2022-04-09 13:26:55 +02:00
|
|
|
switch (dir) {
|
|
|
|
case 'l':
|
|
|
|
if (STICKS(POSA.x, POSB.x + SIZEB.x)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectWindow = w.get();
|
2022-04-09 13:26:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (STICKS(POSA.x + SIZEA.x, POSB.x)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectWindow = w.get();
|
2022-04-09 13:26:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
case 'u':
|
|
|
|
if (STICKS(POSA.y, POSB.y + SIZEB.y)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectWindow = w.get();
|
2022-04-09 13:26:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
case 'd':
|
|
|
|
if (STICKS(POSA.y + SIZEA.y, POSB.y)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectWindow = w.get();
|
2022-04-09 13:26:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (longestIntersect != -1)
|
|
|
|
return longestIntersectWindow;
|
|
|
|
|
|
|
|
return nullptr;
|
2022-04-11 19:51:37 +02:00
|
|
|
}
|
|
|
|
|
2022-04-28 17:55:25 +02:00
|
|
|
void CCompositor::deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWorkspaces) {
|
|
|
|
if (w->m_pWlrHandle && w->m_pWlrHandle != exclude)
|
|
|
|
w->setActive(false);
|
2022-04-11 19:51:37 +02:00
|
|
|
}
|
2022-04-13 20:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) {
|
|
|
|
bool gotToWindow = false;
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w.get() != pWindow && !gotToWindow)
|
2022-04-13 20:45:06 +02:00
|
|
|
continue;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
if (w.get() == pWindow) {
|
2022-04-13 20:45:06 +02:00
|
|
|
gotToWindow = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
if (w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->m_bHidden)
|
|
|
|
return w.get();
|
2022-04-13 20:45:06 +02:00
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w.get() != pWindow && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->m_bHidden)
|
|
|
|
return w.get();
|
2022-04-13 20:45:06 +02:00
|
|
|
}
|
|
|
|
|
2022-04-21 16:38:48 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-09 18:39:41 +02:00
|
|
|
CWindow* CCompositor::getPrevWindowOnWorkspace(CWindow* pWindow) {
|
|
|
|
bool gotToWindow = false;
|
|
|
|
for (auto it = m_vWindows.rbegin(); it != m_vWindows.rend(); it++) {
|
|
|
|
if (it->get() != pWindow && !gotToWindow)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (it->get() == pWindow) {
|
|
|
|
gotToWindow = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*it)->m_iWorkspaceID == pWindow->m_iWorkspaceID && (*it)->m_bIsMapped && !(*it)->m_bHidden)
|
|
|
|
return it->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = m_vWindows.rbegin(); it != m_vWindows.rend(); it++) {
|
|
|
|
if (it->get() != pWindow && (*it)->m_iWorkspaceID == pWindow->m_iWorkspaceID && (*it)->m_bIsMapped && !(*it)->m_bHidden)
|
|
|
|
return it->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:38:48 +02:00
|
|
|
int CCompositor::getNextAvailableNamedWorkspace() {
|
2022-04-21 21:35:08 +02:00
|
|
|
int lowest = -1337 + 1;
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWorkspaces) {
|
|
|
|
if (w->m_iID < -1 && w->m_iID < lowest)
|
|
|
|
lowest = w->m_iID;
|
2022-04-21 16:38:48 +02:00
|
|
|
}
|
|
|
|
|
2022-04-21 21:35:08 +02:00
|
|
|
return lowest - 1;
|
2022-04-21 16:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CWorkspace* CCompositor::getWorkspaceByName(const std::string& name) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWorkspaces) {
|
|
|
|
if (w->m_szName == name)
|
|
|
|
return w.get();
|
2022-04-21 16:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) {
|
|
|
|
if (str.find("name:") == 0) {
|
|
|
|
return getWorkspaceByName(str.substr(str.find_first_of(':') + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-05-30 14:18:46 +02:00
|
|
|
std::string name = "";
|
|
|
|
return getWorkspaceByID(getWorkspaceIDFromString(str, name));
|
2022-04-21 16:38:48 +02:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(ERR, "Error in getWorkspaceByString, invalid id");
|
|
|
|
}
|
|
|
|
|
2022-04-13 20:45:06 +02:00
|
|
|
return nullptr;
|
2022-04-23 14:16:02 +02:00
|
|
|
}
|
2022-04-24 17:53:50 +02:00
|
|
|
|
|
|
|
bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if (VECINRECT(point, m->vecPosition.x, m->vecPosition.y, m->vecSize.x + m->vecPosition.x, m->vecSize.y + m->vecPosition.y))
|
2022-04-24 17:53:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-04-25 13:40:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::getConstraintWindow(SMouse* pMouse) {
|
|
|
|
if (!pMouse->currentConstraint)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const auto PSURFACE = pMouse->currentConstraint->surface;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (PSURFACE == g_pXWaylandManager->getWindowSurface(w.get())) {
|
|
|
|
if (!w->m_bIsX11 && w->m_bIsMapped && !w->m_bHidden)
|
2022-04-25 13:40:46 +02:00
|
|
|
continue;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
return w.get();
|
2022-04-25 13:40:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 12:50:25 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* CCompositor::getMonitorInDirection(const char& dir) {
|
2022-05-05 12:50:25 +02:00
|
|
|
const auto POSA = m_pLastMonitor->vecPosition;
|
|
|
|
const auto SIZEA = m_pLastMonitor->vecSize;
|
|
|
|
|
|
|
|
auto longestIntersect = -1;
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* longestIntersectMonitor = nullptr;
|
2022-05-05 12:50:25 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if (m.get() == m_pLastMonitor)
|
2022-05-05 12:50:25 +02:00
|
|
|
continue;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
const auto POSB = m->vecPosition;
|
|
|
|
const auto SIZEB = m->vecSize;
|
2022-05-05 12:50:25 +02:00
|
|
|
switch (dir) {
|
|
|
|
case 'l':
|
|
|
|
if (STICKS(POSA.x, POSB.x + SIZEB.x)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectMonitor = m.get();
|
2022-05-05 12:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (STICKS(POSA.x + SIZEA.x, POSB.x)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectMonitor = m.get();
|
2022-05-05 12:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
case 'u':
|
|
|
|
if (STICKS(POSA.y, POSB.y + SIZEB.y)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectMonitor = m.get();
|
2022-05-05 12:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
case 'd':
|
|
|
|
if (STICKS(POSA.y + SIZEA.y, POSB.y)) {
|
|
|
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
|
|
|
|
if (INTERSECTLEN > longestIntersect) {
|
|
|
|
longestIntersect = INTERSECTLEN;
|
2022-06-30 15:44:26 +02:00
|
|
|
longestIntersectMonitor = m.get();
|
2022-05-05 12:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (longestIntersect != -1)
|
|
|
|
return longestIntersectMonitor;
|
|
|
|
|
2022-04-25 13:40:46 +02:00
|
|
|
return nullptr;
|
2022-05-14 17:23:46 +02:00
|
|
|
}
|
2022-05-26 21:23:13 +02:00
|
|
|
|
2022-07-12 13:40:55 +02:00
|
|
|
void CCompositor::updateAllWindowsAnimatedDecorationValues() {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (!w->m_bIsMapped)
|
2022-05-26 21:23:13 +02:00
|
|
|
continue;
|
|
|
|
|
2022-07-12 13:40:55 +02:00
|
|
|
updateWindowAnimatedDecorationValues(w.get());
|
2022-05-26 21:23:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 13:40:55 +02:00
|
|
|
void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
|
2022-05-26 21:23:13 +02:00
|
|
|
// optimization
|
|
|
|
static int64_t* ACTIVECOL = &g_pConfigManager->getConfigValuePtr("general:col.active_border")->intValue;
|
|
|
|
static int64_t* INACTIVECOL = &g_pConfigManager->getConfigValuePtr("general:col.inactive_border")->intValue;
|
2022-07-12 13:40:55 +02:00
|
|
|
static auto *const PINACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity")->floatValue;
|
|
|
|
static auto *const PACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:active_opacity")->floatValue;
|
|
|
|
static auto *const PFULLSCREENALPHA = &g_pConfigManager->getConfigValuePtr("decoration:fullscreen_opacity")->floatValue;
|
2022-07-16 12:44:45 +02:00
|
|
|
static auto *const PSHADOWCOL = &g_pConfigManager->getConfigValuePtr("decoration:col.shadow")->intValue;
|
|
|
|
static auto *const PSHADOWCOLINACTIVE = &g_pConfigManager->getConfigValuePtr("decoration:col.shadow_inactive")->intValue;
|
2022-07-12 13:40:55 +02:00
|
|
|
|
|
|
|
// border
|
2022-05-26 21:23:13 +02:00
|
|
|
const auto RENDERDATA = g_pLayoutManager->getCurrentLayout()->requestRenderHints(pWindow);
|
|
|
|
if (RENDERDATA.isBorderColor)
|
|
|
|
pWindow->m_cRealBorderColor = RENDERDATA.borderColor;
|
|
|
|
else
|
|
|
|
pWindow->m_cRealBorderColor = CColor(pWindow == m_pLastWindow ? *ACTIVECOL : *INACTIVECOL);
|
2022-07-12 13:40:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
// opacity
|
|
|
|
if (pWindow->m_bIsFullscreen) {
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
|
|
|
|
|
|
|
|
if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL)
|
|
|
|
pWindow->m_fActiveInactiveAlpha = *PFULLSCREENALPHA;
|
|
|
|
else {
|
|
|
|
if (pWindow == m_pLastWindow)
|
2022-07-14 18:45:16 +02:00
|
|
|
pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alpha * *PACTIVEALPHA;
|
2022-07-12 13:40:55 +02:00
|
|
|
else
|
2022-07-14 18:46:42 +02:00
|
|
|
pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaInactive != -1 ? pWindow->m_sSpecialRenderData.alphaInactive * *PINACTIVEALPHA : *PINACTIVEALPHA;
|
2022-07-12 13:40:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pWindow == m_pLastWindow)
|
2022-07-14 18:45:16 +02:00
|
|
|
pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alpha * *PACTIVEALPHA;
|
2022-07-12 13:40:55 +02:00
|
|
|
else
|
2022-07-14 18:46:42 +02:00
|
|
|
pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaInactive != -1 ? pWindow->m_sSpecialRenderData.alphaInactive * *PINACTIVEALPHA : *PINACTIVEALPHA;
|
2022-07-12 13:40:55 +02:00
|
|
|
}
|
2022-07-16 12:44:45 +02:00
|
|
|
|
|
|
|
// shadow
|
2022-07-18 12:39:57 +02:00
|
|
|
if (pWindow->m_iX11Type != 2 && !pWindow->m_bX11DoesntWantBorders) {
|
|
|
|
if (pWindow == m_pLastWindow) {
|
|
|
|
pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL);
|
|
|
|
} else {
|
|
|
|
pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL);
|
|
|
|
}
|
2022-07-16 12:44:45 +02:00
|
|
|
} else {
|
2022-07-18 12:39:57 +02:00
|
|
|
pWindow->m_cRealShadowColor.setValueAndWarp(CColor(0, 0, 0, 0)); // no shadow
|
2022-07-16 12:44:45 +02:00
|
|
|
}
|
2022-05-30 17:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::moveWindowToWorkspace(CWindow* pWindow, const std::string& work) {
|
|
|
|
m_pLastWindow = pWindow;
|
|
|
|
g_pKeybindManager->moveActiveToWorkspace(work);
|
|
|
|
|
|
|
|
g_pInputManager->refocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCompositor::getNextAvailableMonitorID() {
|
|
|
|
int64_t topID = -1;
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : m_vMonitors) {
|
|
|
|
if ((int64_t)m->ID > topID)
|
|
|
|
topID = m->ID;
|
2022-05-30 17:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return topID + 1;
|
|
|
|
}
|
2022-05-30 20:05:38 +02:00
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMonitor) {
|
2022-05-30 20:05:38 +02:00
|
|
|
|
|
|
|
// We trust the workspace and monitor to be correct.
|
|
|
|
|
|
|
|
if (pWorkspace->m_iMonitorID == pMonitor->ID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Debug::log(LOG, "moveWorkspaceToMonitor: Moving %d to monitor %d", pWorkspace->m_iID, pMonitor->ID);
|
|
|
|
|
|
|
|
const auto POLDMON = getMonitorFromID(pWorkspace->m_iMonitorID);
|
|
|
|
|
|
|
|
const bool SWITCHINGISACTIVE = POLDMON->activeWorkspace == pWorkspace->m_iID;
|
|
|
|
|
|
|
|
// fix old mon
|
|
|
|
int nextWorkspaceOnMonitorID = -1;
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWorkspaces) {
|
|
|
|
if (w->m_iMonitorID == POLDMON->ID && w->m_iID != pWorkspace->m_iID) {
|
|
|
|
nextWorkspaceOnMonitorID = w->m_iID;
|
2022-05-30 20:05:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextWorkspaceOnMonitorID == -1) {
|
|
|
|
nextWorkspaceOnMonitorID = 1;
|
|
|
|
|
|
|
|
while (getWorkspaceByID(nextWorkspaceOnMonitorID))
|
|
|
|
nextWorkspaceOnMonitorID++;
|
|
|
|
|
|
|
|
Debug::log(LOG, "moveWorkspaceToMonitor: Plugging gap with new %d", nextWorkspaceOnMonitorID);
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug::log(LOG, "moveWorkspaceToMonitor: Plugging gap with existing %d", nextWorkspaceOnMonitorID);
|
|
|
|
|
|
|
|
g_pKeybindManager->focusMonitor(std::to_string(POLDMON->ID));
|
|
|
|
g_pKeybindManager->changeworkspace(std::to_string(nextWorkspaceOnMonitorID));
|
|
|
|
|
|
|
|
// move the workspace
|
|
|
|
|
|
|
|
pWorkspace->m_iMonitorID = pMonitor->ID;
|
2022-05-30 20:51:45 +02:00
|
|
|
pWorkspace->moveToMonitor(pMonitor->ID);
|
2022-05-30 20:05:38 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWindows) {
|
2022-07-25 14:22:32 +02:00
|
|
|
if (w->m_iWorkspaceID == pWorkspace->m_iID) {
|
2022-06-30 15:44:26 +02:00
|
|
|
w->m_iMonitorID = pMonitor->ID;
|
2022-07-25 14:22:32 +02:00
|
|
|
|
|
|
|
// additionally, move floating windows manually
|
|
|
|
if (w->m_bIsFloating && w->m_bIsMapped && !w->m_bHidden) {
|
|
|
|
w->m_vRealPosition = w->m_vRealPosition.vec() - POLDMON->vecPosition + pMonitor->vecPosition;
|
|
|
|
}
|
|
|
|
}
|
2022-05-30 20:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SWITCHINGISACTIVE) { // if it was active, preserve its' status. If it wasn't, don't.
|
|
|
|
Debug::log(LOG, "moveWorkspaceToMonitor: SWITCHINGISACTIVE, active %d -> %d", pMonitor->activeWorkspace, pWorkspace->m_iID);
|
2022-05-31 17:17:44 +02:00
|
|
|
|
|
|
|
if (const auto PWORKSPACE = getWorkspaceByID(pMonitor->activeWorkspace); PWORKSPACE)
|
|
|
|
getWorkspaceByID(pMonitor->activeWorkspace)->startAnim(false, false);
|
2022-05-30 20:05:38 +02:00
|
|
|
|
|
|
|
pMonitor->activeWorkspace = pWorkspace->m_iID;
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitor->ID);
|
|
|
|
|
|
|
|
pWorkspace->startAnim(true, true, true);
|
|
|
|
|
|
|
|
wlr_cursor_warp(m_sWLRCursor, m_sSeat.mouse->mouse, pMonitor->vecPosition.x + pMonitor->vecTransformedSize.x / 2, pMonitor->vecPosition.y + pMonitor->vecTransformedSize.y / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// finalize
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID);
|
|
|
|
|
|
|
|
g_pInputManager->refocus();
|
2022-05-31 12:33:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCompositor::workspaceIDOutOfBounds(const int& id) {
|
|
|
|
int lowestID = 99999;
|
|
|
|
int highestID = -99999;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : m_vWorkspaces) {
|
|
|
|
if (w->m_iID < lowestID)
|
|
|
|
lowestID = w->m_iID;
|
2022-05-31 12:33:08 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
if (w->m_iID > highestID)
|
|
|
|
highestID = w->m_iID;
|
2022-05-31 12:33:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::clamp(id, lowestID, highestID) != id;
|
2022-06-26 12:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode mode) {
|
|
|
|
if (!windowValidMapped(pWindow))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->fullscreenRequestForWindow(pWindow, mode, on);
|
|
|
|
|
|
|
|
g_pXWaylandManager->setWindowFullscreen(pWindow, pWindow->m_bIsFullscreen && mode == FULLSCREEN_FULL);
|
|
|
|
// make all windows on the same workspace under the fullscreen window
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
|
|
|
if (w->m_iWorkspaceID == pWindow->m_iWorkspaceID)
|
|
|
|
w->m_bCreatedOverFullscreen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::moveUnmanagedX11ToWindows(CWindow* pWindow) {
|
|
|
|
for (auto it = m_dUnmanagedX11Windows.begin(); it != m_dUnmanagedX11Windows.end(); it++) {
|
|
|
|
if (it->get() == pWindow) {
|
|
|
|
m_vWindows.emplace_back(std::move(*it));
|
|
|
|
m_dUnmanagedX11Windows.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-26 12:12:29 +02:00
|
|
|
}
|
2022-06-30 15:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::getX11Parent(CWindow* pWindow) {
|
|
|
|
if (!pWindow->m_bIsX11)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (!w->m_bIsX11)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (w->m_uSurface.xwayland == pWindow->m_uSurface.xwayland->parent)
|
|
|
|
return w.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2022-07-07 11:52:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCompositor::updateWorkspaceWindowDecos(const int& id) {
|
|
|
|
for (auto& w : m_vWindows) {
|
|
|
|
if (w->m_iWorkspaceID != id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
w->updateWindowDecos();
|
|
|
|
}
|
|
|
|
}
|
2022-07-13 18:18:23 +02:00
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
void CCompositor::scheduleFrameForMonitor(CMonitor* pMonitor) {
|
2022-07-13 18:31:09 +02:00
|
|
|
if ((m_sWLRSession && !m_sWLRSession->active) || !m_bSessionActive)
|
2022-07-13 18:18:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
wlr_output_schedule_frame(pMonitor->output);
|
2022-07-26 17:30:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
|
|
|
|
eFocusWindowMode mode = MODE_CLASS_REGEX;
|
|
|
|
|
|
|
|
std::regex regexCheck(regexp);
|
|
|
|
std::string matchCheck;
|
|
|
|
if (regexp.find("title:") == 0) {
|
|
|
|
mode = MODE_TITLE_REGEX;
|
|
|
|
regexCheck = std::regex(regexp.substr(6));
|
|
|
|
} else if (regexp.find("address:") == 0) {
|
|
|
|
mode = MODE_ADDRESS;
|
|
|
|
matchCheck = regexp.substr(8);
|
|
|
|
} else if (regexp.find("pid:") == 0) {
|
|
|
|
mode = MODE_PID;
|
|
|
|
matchCheck = regexp.substr(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
|
|
|
if (!w->m_bIsMapped || w->m_bHidden)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_CLASS_REGEX: {
|
|
|
|
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get());
|
|
|
|
if (!std::regex_search(g_pXWaylandManager->getAppIDClass(w.get()), regexCheck))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_TITLE_REGEX: {
|
|
|
|
const auto windowTitle = g_pXWaylandManager->getTitle(w.get());
|
|
|
|
if (!std::regex_search(windowTitle, regexCheck))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_ADDRESS: {
|
|
|
|
std::string addr = getFormat("0x%x", w.get());
|
|
|
|
if (matchCheck != addr)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_PID: {
|
|
|
|
std::string pid = getFormat("%d", w->getPID());
|
|
|
|
if (matchCheck != pid)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return w.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2022-07-13 18:18:23 +02:00
|
|
|
}
|