XWayland and moved managers
This commit is contained in:
parent
854c827911
commit
a9773bd91a
13 changed files with 245 additions and 31 deletions
57
src/managers/InputManager.cpp
Normal file
57
src/managers/InputManager.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include "InputManager.hpp"
|
||||
#include "../Compositor.hpp"
|
||||
|
||||
void CInputManager::onMouseMoved(wlr_event_pointer_motion* e) {
|
||||
// TODO: sensitivity
|
||||
|
||||
float sensitivity = 0.25f;
|
||||
|
||||
m_vMouseCoords = m_vMouseCoords + Vector2D(e->delta_x * sensitivity, e->delta_y * sensitivity);
|
||||
|
||||
if (m_vMouseCoords.floor() != m_vWLRMouseCoords) {
|
||||
Vector2D delta = m_vMouseCoords - m_vWLRMouseCoords;
|
||||
m_vWLRMouseCoords = m_vMouseCoords.floor();
|
||||
|
||||
wlr_cursor_move(g_pCompositor->m_sWLRCursor, e->device, delta.floor().x, delta.floor().y);
|
||||
}
|
||||
}
|
||||
|
||||
void CInputManager::onMouseWarp(wlr_event_pointer_motion_absolute* e) {
|
||||
wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, e->device, e->x, e->y);
|
||||
}
|
||||
|
||||
Vector2D CInputManager::getMouseCoordsInternal() {
|
||||
return m_vMouseCoords;
|
||||
}
|
||||
|
||||
void CInputManager::newKeyboard(wlr_input_device* keyboard) {
|
||||
m_dKeyboards.push_back(SKeyboard());
|
||||
|
||||
const auto PNEWKEYBOARD = &m_dKeyboards.back();
|
||||
|
||||
PNEWKEYBOARD->keyboard = keyboard;
|
||||
|
||||
xkb_rule_names rules;
|
||||
|
||||
const auto CONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
const auto KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
|
||||
wlr_keyboard_set_keymap(keyboard->keyboard, KEYMAP);
|
||||
xkb_keymap_unref(KEYMAP);
|
||||
xkb_context_unref(CONTEXT);
|
||||
wlr_keyboard_set_repeat_info(keyboard->keyboard, 25, 600);
|
||||
|
||||
wl_signal_add(&keyboard->keyboard->events.modifiers, &PNEWKEYBOARD->listen_keyboardMod);
|
||||
wl_signal_add(&keyboard->keyboard->events.key, &PNEWKEYBOARD->listen_keyboardKey);
|
||||
wl_signal_add(&keyboard->events.destroy, &PNEWKEYBOARD->listen_keyboardDestroy);
|
||||
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, keyboard);
|
||||
}
|
||||
|
||||
void CInputManager::onKeyboardKey(wlr_event_keyboard_key* event) {
|
||||
|
||||
}
|
||||
|
||||
void CInputManager::onKeyboardMod(void* data) {
|
||||
|
||||
}
|
||||
27
src/managers/InputManager.hpp
Normal file
27
src/managers/InputManager.hpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include <deque>
|
||||
#include "../helpers/WLClasses.hpp"
|
||||
|
||||
class CInputManager {
|
||||
public:
|
||||
|
||||
void onMouseMoved(wlr_event_pointer_motion*);
|
||||
void onMouseWarp(wlr_event_pointer_motion_absolute*);
|
||||
void onKeyboardKey(wlr_event_keyboard_key*);
|
||||
void onKeyboardMod(void*);
|
||||
|
||||
void newKeyboard(wlr_input_device*);
|
||||
|
||||
Vector2D getMouseCoordsInternal();
|
||||
|
||||
private:
|
||||
Vector2D m_vMouseCoords = Vector2D(0,0);
|
||||
Vector2D m_vWLRMouseCoords = Vector2D(0,0);
|
||||
|
||||
std::deque<SKeyboard> m_dKeyboards;
|
||||
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CInputManager> g_pInputManager;
|
||||
25
src/managers/ThreadManager.cpp
Normal file
25
src/managers/ThreadManager.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "ThreadManager.hpp"
|
||||
|
||||
CThreadManager::CThreadManager() {
|
||||
m_tMainThread = new std::thread([&]() {
|
||||
// Call the handle method.
|
||||
this->handle();
|
||||
});
|
||||
|
||||
m_tMainThread->detach(); // detach and continue.
|
||||
}
|
||||
|
||||
CThreadManager::~CThreadManager() {
|
||||
//
|
||||
}
|
||||
|
||||
void CThreadManager::handle() {
|
||||
|
||||
g_pConfigManager->init();
|
||||
|
||||
while (3.1415f) {
|
||||
g_pConfigManager->tick();
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(1000000 / g_pConfigManager->getInt("max_fps")));
|
||||
}
|
||||
}
|
||||
19
src/managers/ThreadManager.hpp
Normal file
19
src/managers/ThreadManager.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include <thread>
|
||||
#include "../Compositor.hpp"
|
||||
|
||||
class CThreadManager {
|
||||
public:
|
||||
CThreadManager();
|
||||
~CThreadManager();
|
||||
|
||||
private:
|
||||
|
||||
void handle();
|
||||
|
||||
std::thread* m_tMainThread;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CThreadManager> g_pThreadManager;
|
||||
84
src/managers/XWaylandManager.cpp
Normal file
84
src/managers/XWaylandManager.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "XWaylandManager.hpp"
|
||||
#include "../Compositor.hpp"
|
||||
#include "../events/Events.hpp"
|
||||
|
||||
CHyprXWaylandManager::CHyprXWaylandManager() {
|
||||
m_sWLRXWayland = wlr_xwayland_create(g_pCompositor->m_sWLDisplay, g_pCompositor->m_sWLRCompositor, 1);
|
||||
|
||||
if (!m_sWLRXWayland) {
|
||||
Debug::log(ERR, "Couldn't start up the XWaylandManager because wlr_xwayland_create returned a nullptr!");
|
||||
return;
|
||||
}
|
||||
|
||||
wl_signal_add(&m_sWLRXWayland->events.ready, &Events::listen_readyXWayland);
|
||||
wl_signal_add(&m_sWLRXWayland->events.new_surface, &Events::listen_surfaceXWayland);
|
||||
|
||||
setenv("DISPLAY", m_sWLRXWayland->display_name, 1);
|
||||
|
||||
Debug::log(LOG, "CHyprXWaylandManager started on display %s", m_sWLRXWayland->display_name);
|
||||
}
|
||||
|
||||
CHyprXWaylandManager::~CHyprXWaylandManager() {
|
||||
|
||||
}
|
||||
|
||||
wlr_surface* CHyprXWaylandManager::getWindowSurface(CWindow* pWindow) {
|
||||
if (pWindow->m_bIsX11)
|
||||
return pWindow->m_uSurface.xwayland->surface;
|
||||
|
||||
return pWindow->m_uSurface.xdg->surface;
|
||||
}
|
||||
|
||||
void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate) {
|
||||
if (wlr_surface_is_xdg_surface(pSurface))
|
||||
wlr_xdg_toplevel_set_activated(wlr_xdg_surface_from_wlr_surface(pSurface)->toplevel, activate);
|
||||
|
||||
else if (wlr_surface_is_xwayland_surface(pSurface))
|
||||
wlr_xwayland_surface_activate(wlr_xwayland_surface_from_wlr_surface(pSurface), activate);
|
||||
}
|
||||
|
||||
void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) {
|
||||
if (pWindow->m_bIsX11) {
|
||||
pbox->x = pWindow->m_uSurface.xwayland->x;
|
||||
pbox->y = pWindow->m_uSurface.xwayland->y;
|
||||
pbox->width = pWindow->m_uSurface.xwayland->width;
|
||||
pbox->height = pWindow->m_uSurface.xwayland->height;
|
||||
} else {
|
||||
wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, pbox);
|
||||
}
|
||||
}
|
||||
|
||||
std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) {
|
||||
if (pWindow->m_bIsX11)
|
||||
return pWindow->m_uSurface.xwayland->title;
|
||||
|
||||
return pWindow->m_uSurface.xdg->toplevel->title;
|
||||
}
|
||||
|
||||
void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) {
|
||||
if (pWindow->m_bIsX11) {
|
||||
wlr_xwayland_surface_close(pWindow->m_uSurface.xwayland);
|
||||
} else {
|
||||
wlr_xdg_toplevel_send_close(pWindow->m_uSurface.xdg->toplevel);
|
||||
}
|
||||
}
|
||||
|
||||
void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, const Vector2D& size) {
|
||||
if (pWindow->m_bIsX11)
|
||||
wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vPosition.x, pWindow->m_vPosition.y, size.x, size.y);
|
||||
|
||||
else
|
||||
wlr_xdg_toplevel_set_size(pWindow->m_uSurface.xdg->toplevel, size.x, size.y);
|
||||
}
|
||||
|
||||
void CHyprXWaylandManager::setWindowStyleTiled(CWindow* pWindow, uint32_t edgez) {
|
||||
if (!pWindow->m_bIsX11)
|
||||
wlr_xdg_toplevel_set_tiled(pWindow->m_uSurface.xdg->toplevel, edgez);
|
||||
}
|
||||
|
||||
wlr_surface* CHyprXWaylandManager::surfaceAt(CWindow* pWindow, const Vector2D& client, Vector2D& server) {
|
||||
if (pWindow->m_bIsX11)
|
||||
return wlr_surface_surface_at(pWindow->m_uSurface.xwayland->surface, client.x, client.y, &server.x, &server.y);
|
||||
|
||||
return wlr_xdg_surface_surface_at(pWindow->m_uSurface.xdg, client.x, client.y, &server.x, &server.y);
|
||||
}
|
||||
23
src/managers/XWaylandManager.hpp
Normal file
23
src/managers/XWaylandManager.hpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "../Window.hpp"
|
||||
|
||||
class CHyprXWaylandManager {
|
||||
public:
|
||||
CHyprXWaylandManager();
|
||||
~CHyprXWaylandManager();
|
||||
|
||||
wlr_xwayland* m_sWLRXWayland;
|
||||
|
||||
wlr_surface* getWindowSurface(CWindow*);
|
||||
void activateSurface(wlr_surface*, bool);
|
||||
void getGeometryForWindow(CWindow*, wlr_box*);
|
||||
std::string getTitle(CWindow*);
|
||||
void sendCloseWindow(CWindow*);
|
||||
void setWindowSize(CWindow*, const Vector2D&);
|
||||
void setWindowStyleTiled(CWindow*, uint32_t);
|
||||
wlr_surface* surfaceAt(CWindow*, const Vector2D&, Vector2D&);
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CHyprXWaylandManager> g_pXWaylandManager;
|
||||
Loading…
Add table
Add a link
Reference in a new issue