Move tearing to hyprwayland-scanner

This commit is contained in:
Vaxry 2024-04-20 01:42:01 +01:00
parent 1ebc32f5f4
commit 63ff7997e8
4 changed files with 32 additions and 51 deletions

4
.gitignore vendored
View file

@ -17,8 +17,8 @@ result*
.cache
*.o
*-protocol.c
*-protocol.h
protocols/*.c*
protocols/*.h*
.ccls-cache
*.so

View file

@ -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)

View file

@ -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<CTearingControlProtocol*>(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<CTearingControlProtocol*>(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<CWindow*>(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<CWaylandResource>(client, &wp_tearing_control_manager_v1_interface, ver, id)).get();
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CWpTearingControlManagerV1>(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<CTearingControl>(
std::make_shared<CWaylandResource>(client, &wp_tearing_control_v1_interface, wl_resource_get_version(resource), id), surf))
std::make_shared<CWpTearingControlV1>(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<CTearingControl*>(PRESOURCE->data()));
}
static void setPresentationHint(wl_client* client, wl_resource* resource, uint32_t hint) {
RESOURCE_OR_BAIL(PRESOURCE);
reinterpret_cast<CTearingControl*>(PRESOURCE->data())->onHint(hint);
}
static const struct wp_tearing_control_v1_interface CONTROLLER_IMPL = {
.set_presentation_hint = ::setPresentationHint,
.destroy = ::destroyController,
};
CTearingControl::CTearingControl(SP<CWaylandResource> resource_, wlr_surface* surf_) : resource(resource_) {
resource->setImplementation(&CONTROLLER_IMPL, nullptr);
CTearingControl::CTearingControl(SP<CWpTearingControlV1> resource_, wlr_surface* surf_) : resource(resource_) {
resource->setData(this);
resource->setOnDestroyHandler([](CWaylandResource* res) { PROTO::tearing->onControllerDestroy(reinterpret_cast<CTearingControl*>(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();
}

View file

@ -2,6 +2,7 @@
#include <memory>
#include "WaylandProtocol.hpp"
#include "tearing-control-v1.hpp"
class CWindow;
@ -14,7 +15,7 @@ class CTearingControlProtocol;
class CTearingControl {
public:
CTearingControl(SP<CWaylandResource> resource_, wlr_surface* surf_);
CTearingControl(SP<CWpTearingControlV1> resource_, wlr_surface* surf_);
void onHint(uint32_t hint_);
@ -31,7 +32,7 @@ class CTearingControl {
private:
void updateWindow();
SP<CWaylandResource> resource;
SP<CWpTearingControlV1> resource;
CWindow* pWindow = nullptr;
eTearingPresentationHint hint = TEARING_VSYNC;
@ -51,7 +52,7 @@ class CTearingControlProtocol : public IWaylandProtocol {
private:
void onWindowDestroy(CWindow* pWindow);
std::vector<UP<CWaylandResource>> m_vManagers;
std::vector<UP<CWpTearingControlManagerV1>> m_vManagers;
std::vector<UP<CTearingControl>> m_vTearingControllers;
};