diff --git a/.gitignore b/.gitignore index b8423e8f..3601f422 100644 --- a/.gitignore +++ b/.gitignore @@ -17,8 +17,8 @@ result* .cache *.o -*-protocol.c -*-protocol.h +protocols/*.c* +protocols/*.h* .ccls-cache *.so diff --git a/CMakeLists.txt b/CMakeLists.txt index b056402a..fe9bc5f7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ pkg_get_variable(WaylandScanner wayland-scanner wayland_scanner) message(STATUS "Found WaylandScanner at ${WaylandScanner}") pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir) message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}") +find_program(HYPRWAYLAND_SCANNER NAMES hyprwayland-scanner REQUIRED) if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) message(STATUS "Configuring Hyprland in Debug with CMake") @@ -238,6 +239,19 @@ function(protocol protoPath protoName external) target_sources(Hyprland PRIVATE protocols/${protoName}-protocol.c) endif() endfunction() +function(protocolNew protoPath protoName external) + if (external) + execute_process( + COMMAND hyprwayland-scanner ${WAYLAND_PROTOCOLS_DIR}/${protoPath} ${CMAKE_SOURCE_DIR}/protocols/ + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + target_sources(Hyprland PRIVATE protocols/${protoName}.cpp) + else() + execute_process( + COMMAND hyprwayland-scanner ${WAYLAND_PROTOCOLS_DIR}/${protoPath} ${CMAKE_SOURCE_DIR}/protocols/ + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + target_sources(Hyprland PRIVATE protocols/${protoName}.cpp) + endif() +endfunction() target_link_libraries(Hyprland ${CMAKE_SOURCE_DIR}/subprojects/wlroots-hyprland/build/libwlroots.a @@ -263,7 +277,7 @@ protocol("staging/fractional-scale/fractional-scale-v1.xml" "fractional-scale-v1 protocol("staging/tearing-control/tearing-control-v1.xml" "tearing-control-v1" false) protocol("unstable/text-input/text-input-unstable-v1.xml" "text-input-unstable-v1" false) protocol("staging/cursor-shape/cursor-shape-v1.xml" "cursor-shape-v1" false) -protocol("staging/tearing-control/tearing-control-v1.xml" "tearing-control-v1" false) +protocolNew("staging/tearing-control/tearing-control-v1.xml" "tearing-control-v1" false) # tools add_subdirectory(hyprctl) diff --git a/src/protocols/TearingControl.cpp b/src/protocols/TearingControl.cpp index f3c17bfb..4cc7a9c2 100644 --- a/src/protocols/TearingControl.cpp +++ b/src/protocols/TearingControl.cpp @@ -4,37 +4,17 @@ #include "../desktop/Window.hpp" #include "../Compositor.hpp" -static void destroyManager(wl_client* client, wl_resource* resource) { - RESOURCE_OR_BAIL(PRESOURCE); - reinterpret_cast(PRESOURCE->data())->onManagerResourceDestroy(resource); -} - -static void getTearingControl(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface) { - RESOURCE_OR_BAIL(PRESOURCE); - reinterpret_cast(PRESOURCE->data())->onGetController(client, resource, id, wlr_surface_from_resource(surface)); -} - -// - CTearingControlProtocol::CTearingControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { g_pHookSystem->hookDynamic("destroyWindow", [this](void* self, SCallbackInfo& info, std::any param) { this->onWindowDestroy(std::any_cast(param)); }); } -static const struct wp_tearing_control_manager_v1_interface MANAGER_IMPL = { - .destroy = ::destroyManager, - .get_tearing_control = ::getTearingControl, -}; - void CTearingControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { - const auto RESOURCE = m_vManagers.emplace_back(std::make_unique(client, &wp_tearing_control_manager_v1_interface, ver, id)).get(); + const auto RESOURCE = m_vManagers.emplace_back(std::make_unique(client, ver, id)).get(); + RESOURCE->setOnDestroy([this](CWpTearingControlManagerV1* p) { this->onManagerResourceDestroy(p->resource()); }); - if (!RESOURCE->good()) { - Debug::log(LOG, "Couldn't bind TearingControlMgr"); - return; - } - - RESOURCE->setImplementation(&MANAGER_IMPL, nullptr); - RESOURCE->setData(this); + RESOURCE->setDestroy([this](wl_client* c, wl_resource* resource) { this->onManagerResourceDestroy(resource); }); + RESOURCE->setGetTearingControl( + [this](wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface) { this->onGetController(client, resource, id, wlr_surface_from_resource(surface)); }); } void CTearingControlProtocol::onManagerResourceDestroy(wl_resource* res) { @@ -44,7 +24,7 @@ void CTearingControlProtocol::onManagerResourceDestroy(wl_resource* res) { void CTearingControlProtocol::onGetController(wl_client* client, wl_resource* resource, uint32_t id, wlr_surface* surf) { const auto CONTROLLER = m_vTearingControllers .emplace_back(std::make_unique( - std::make_shared(client, &wp_tearing_control_v1_interface, wl_resource_get_version(resource), id), surf)) + std::make_shared(client, wl_resource_get_version(resource), id), surf)) .get(); if (!CONTROLLER->good()) { @@ -66,25 +46,11 @@ void CTearingControlProtocol::onWindowDestroy(CWindow* pWindow) { // -static void destroyController(wl_client* client, wl_resource* resource) { - RESOURCE_OR_BAIL(PRESOURCE); - PROTO::tearing->onControllerDestroy(reinterpret_cast(PRESOURCE->data())); -} - -static void setPresentationHint(wl_client* client, wl_resource* resource, uint32_t hint) { - RESOURCE_OR_BAIL(PRESOURCE); - reinterpret_cast(PRESOURCE->data())->onHint(hint); -} - -static const struct wp_tearing_control_v1_interface CONTROLLER_IMPL = { - .set_presentation_hint = ::setPresentationHint, - .destroy = ::destroyController, -}; - -CTearingControl::CTearingControl(SP resource_, wlr_surface* surf_) : resource(resource_) { - resource->setImplementation(&CONTROLLER_IMPL, nullptr); +CTearingControl::CTearingControl(SP resource_, wlr_surface* surf_) : resource(resource_) { resource->setData(this); - resource->setOnDestroyHandler([](CWaylandResource* res) { PROTO::tearing->onControllerDestroy(reinterpret_cast(res->data())); }); + resource->setOnDestroy([this](CWpTearingControlV1* res) { PROTO::tearing->onControllerDestroy(this); }); + resource->setDestroy([this](wl_client* c, wl_resource* res) { PROTO::tearing->onControllerDestroy(this); }); + resource->setSetPresentationHint([this](wl_client* c, wl_resource* res, uint32_t hint) { this->onHint(hint); }); for (auto& w : g_pCompositor->m_vWindows) { if (w->m_pWLSurface.wlr() == surf_) { @@ -107,5 +73,5 @@ void CTearingControl::updateWindow() { } bool CTearingControl::good() { - return resource->good(); + return resource->resource(); } diff --git a/src/protocols/TearingControl.hpp b/src/protocols/TearingControl.hpp index f0dd8bfa..249c0472 100644 --- a/src/protocols/TearingControl.hpp +++ b/src/protocols/TearingControl.hpp @@ -2,6 +2,7 @@ #include #include "WaylandProtocol.hpp" +#include "tearing-control-v1.hpp" class CWindow; @@ -14,7 +15,7 @@ class CTearingControlProtocol; class CTearingControl { public: - CTearingControl(SP resource_, wlr_surface* surf_); + CTearingControl(SP resource_, wlr_surface* surf_); void onHint(uint32_t hint_); @@ -31,7 +32,7 @@ class CTearingControl { private: void updateWindow(); - SP resource; + SP resource; CWindow* pWindow = nullptr; eTearingPresentationHint hint = TEARING_VSYNC; @@ -51,7 +52,7 @@ class CTearingControlProtocol : public IWaylandProtocol { private: void onWindowDestroy(CWindow* pWindow); - std::vector> m_vManagers; + std::vector> m_vManagers; std::vector> m_vTearingControllers; };