Skip to content

Commit

Permalink
core: Move tearing to hyprwayland-scanner (#5657)
Browse files Browse the repository at this point in the history
Adds a new dependency: hyprwayland-scanner https://github.com/hyprwm/hyprwayland-scanner

---------

Co-authored-by: Mihai Fufezan <[email protected]>
  • Loading branch information
vaxerski and fufexan authored Apr 20, 2024
1 parent 5c97b96 commit ea95449
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 78 deletions.
8 changes: 5 additions & 3 deletions .github/actions/setup_base/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ runs:
glslang \
go \
hyprlang \
hyprcursor \
jq \
libc++ \
libdisplay-info \
Expand All @@ -44,6 +45,7 @@ runs:
pango \
pixman \
pkgconf \
pugixml \
scdoc \
seatd \
systemd \
Expand All @@ -58,11 +60,11 @@ runs:
libzip \
librsvg
- name: Get hyprcursor-git
- name: Get hyprwayland-scanner-git
shell: bash
run: |
git clone https://github.com/hyprwm/hyprcursor --recursive
cd hyprcursor
git clone https://github.com/hyprwm/hyprwayland-scanner --recursive
cd hyprwayland-scanner
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
cmake --install build
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ result*
.cache

*.o
*-protocol.c
*-protocol.h
protocols/*.c*
protocols/*.h*
.ccls-cache
*.so

Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 ${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
Expand All @@ -260,10 +274,9 @@ protocol("stable/xdg-shell/xdg-shell.xml" "xdg-shell" false)
protocol("unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml" "linux-dmabuf-unstable-v1" false)
protocol("unstable/xdg-output/xdg-output-unstable-v1.xml" "xdg-output-unstable-v1" false)
protocol("staging/fractional-scale/fractional-scale-v1.xml" "fractional-scale-v1" false)
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)
Expand Down
24 changes: 24 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
inputs.systems.follows = "systems";
};

hyprwayland-scanner = {
url = "github:hyprwm/hyprwayland-scanner";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};

xdph = {
url = "github:hyprwm/xdg-desktop-portal-hyprland";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
hyprcursor,
hyprland-protocols,
hyprlang,
hyprwayland-scanner,
jq,
libGL,
libdrm,
Expand Down Expand Up @@ -86,6 +87,7 @@ in
'';

nativeBuildInputs = [
hyprwayland-scanner
jq
makeWrapper
meson
Expand Down
1 change: 1 addition & 0 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ in {
inputs.hyprcursor.overlays.default
inputs.hyprland-protocols.overlays.default
inputs.hyprlang.overlays.default
inputs.hyprwayland-scanner.overlays.default
self.overlays.wlroots-hyprland
self.overlays.udis86
# Hyprland packages themselves
Expand Down
29 changes: 26 additions & 3 deletions protocols/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ wayland_scanner = find_program(
wayland_scanner_dep.get_variable('wayland_scanner'),
native: true,
)
hyprwayland_scanner_dep = dependency('hyprwayland-scanner', native: true)
hyprwayland_scanner = find_program(
hyprwayland_scanner_dep.get_variable('hyprwayland_scanner'),
native: true,
)

protocols = [
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
Expand All @@ -25,7 +30,6 @@ protocols = [
[wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'],
[wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml'],
[wl_protocol_dir, 'staging/cursor-shape/cursor-shape-v1.xml'],
[wl_protocol_dir, 'staging/tearing-control/tearing-control-v1.xml'],
['wlr-foreign-toplevel-management-unstable-v1.xml'],
['wlr-layer-shell-unstable-v1.xml'],
['wlr-output-power-management-unstable-v1.xml'],
Expand All @@ -36,8 +40,14 @@ protocols = [
[hl_protocol_dir, 'protocols/hyprland-toplevel-export-v1.xml'],
[hl_protocol_dir, 'protocols/hyprland-global-shortcuts-v1.xml']
]

new_protocols = [
[wl_protocol_dir, 'staging/tearing-control/tearing-control-v1.xml'],
]

wl_protos_src = []
wl_protos_headers = []

foreach p : protocols
xml = join_paths(p)
wl_protos_src += custom_target(
Expand All @@ -56,15 +66,28 @@ foreach p : protocols
)
endforeach

new_wl_protos = []
foreach p : new_protocols
xml = join_paths(p)
new_wl_protos += custom_target(
xml.underscorify(),
input: xml,
install: true,
install_dir: [false, join_paths(get_option('includedir'), 'hyprland/protocols')],
output: ['@[email protected]', '@[email protected]'],
command: [hyprwayland_scanner, '@INPUT@', '@OUTDIR@'],
)
endforeach

wayland_server = dependency('wayland-server', version: '>=1.20.0')

lib_server_protos = static_library(
'server_protos',
wl_protos_src + wl_protos_headers,
wl_protos_src + wl_protos_headers + new_wl_protos,
dependencies: wayland_server.partial_dependency(compile_args: true),
)

server_protos = declare_dependency(
link_with: lib_server_protos,
sources: wl_protos_headers,
sources: wl_protos_headers + new_wl_protos,
)
2 changes: 1 addition & 1 deletion src/managers/ProtocolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../protocols/TearingControl.hpp"

#include "xdg-output-unstable-v1-protocol.h"
#include "tearing-control-v1-protocol.h"
#include "tearing-control-v1.hpp"

CProtocolManager::CProtocolManager() {
m_pToplevelExportProtocolManager = std::make_unique<CToplevelExportProtocolManager>();
Expand Down
68 changes: 16 additions & 52 deletions src/protocols/TearingControl.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
#include "TearingControl.hpp"
#include "tearing-control-v1-protocol.h"
#include "../managers/ProtocolManager.hpp"
#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](CWpTearingControlManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
RESOURCE->setGetTearingControl([this](CWpTearingControlManagerV1* pMgr, uint32_t id, wl_resource* surface) {
this->onGetController(wl_resource_get_client(pMgr->resource()), pMgr->resource(), id, wlr_surface_from_resource(surface));
});
}

void CTearingControlProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->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))
.get();
const auto CONTROLLER =
m_vTearingControllers.emplace_back(std::make_unique<CTearingControl>(std::make_shared<CWpTearingControlV1>(client, wl_resource_get_version(resource), id), surf)).get();

if (!CONTROLLER->good()) {
m_vTearingControllers.pop_back();
Expand All @@ -66,25 +44,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](CWpTearingControlV1* res) { PROTO::tearing->onControllerDestroy(this); });
resource->setSetPresentationHint([this](CWpTearingControlV1* res, wpTearingControlV1PresentationHint hint) { this->onHint(hint); });

for (auto& w : g_pCompositor->m_vWindows) {
if (w->m_pWLSurface.wlr() == surf_) {
Expand All @@ -94,18 +58,18 @@ CTearingControl::CTearingControl(SP<CWaylandResource> resource_, wlr_surface* su
}
}

void CTearingControl::onHint(uint32_t hint_) {
hint = hint_ == WP_TEARING_CONTROL_V1_PRESENTATION_HINT_VSYNC ? TEARING_VSYNC : TEARING_ASYNC;
void CTearingControl::onHint(wpTearingControlV1PresentationHint hint_) {
hint = hint_;
updateWindow();
}

void CTearingControl::updateWindow() {
if (!pWindow)
return;

pWindow->m_bTearingHint = hint == TEARING_ASYNC;
pWindow->m_bTearingHint = hint == PRESENTATION_HINT_ASYNC;
}

bool CTearingControl::good() {
return resource->good();
return resource->resource();
}
25 changes: 10 additions & 15 deletions src/protocols/TearingControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

#include <memory>
#include "WaylandProtocol.hpp"
#include "tearing-control-v1.hpp"

class CWindow;

enum eTearingPresentationHint {
TEARING_VSYNC = 0,
TEARING_ASYNC,
};

class CTearingControlProtocol;

class CTearingControl {
public:
CTearingControl(SP<CWaylandResource> resource_, wlr_surface* surf_);
CTearingControl(SP<CWpTearingControlV1> resource_, wlr_surface* surf_);

void onHint(uint32_t hint_);
void onHint(wpTearingControlV1PresentationHint hint_);

bool good();

Expand All @@ -29,11 +24,11 @@ class CTearingControl {
}

private:
void updateWindow();
void updateWindow();

SP<CWaylandResource> resource;
CWindow* pWindow = nullptr;
eTearingPresentationHint hint = TEARING_VSYNC;
SP<CWpTearingControlV1> resource;
CWindow* pWindow = nullptr;
wpTearingControlV1PresentationHint hint = PRESENTATION_HINT_VSYNC;

friend class CTearingControlProtocol;
};
Expand All @@ -49,10 +44,10 @@ class CTearingControlProtocol : public IWaylandProtocol {
void onGetController(wl_client* client, wl_resource* resource, uint32_t id, wlr_surface* surf);

private:
void onWindowDestroy(CWindow* pWindow);
void onWindowDestroy(CWindow* pWindow);

std::vector<UP<CWaylandResource>> m_vManagers;
std::vector<UP<CTearingControl>> m_vTearingControllers;
std::vector<UP<CWpTearingControlManagerV1>> m_vManagers;
std::vector<UP<CTearingControl>> m_vTearingControllers;
};

namespace PROTO {
Expand Down

0 comments on commit ea95449

Please sign in to comment.