From 8c9e2e1ff1d22f7954f5e75194e9f77cacffa3f6 Mon Sep 17 00:00:00 2001
From: Jan Beich <jbeich@FreeBSD.org>
Date: Tue, 18 Jul 2023 10:13:59 +0000
Subject: [PATCH] deps: update wlroots (#2734)

---
 flake.lock                          |  6 +++---
 nix/wlroots-nvidia.patch            | 28 ++++++++++++++++++++++++++++
 nix/wlroots.nix                     |  5 +----
 src/Compositor.cpp                  |  2 +-
 src/managers/input/InputManager.cpp | 16 ++++++++--------
 src/render/Renderer.cpp             |  6 +++---
 subprojects/wlroots                 |  2 +-
 subprojects/wlroots.wrap            |  2 +-
 8 files changed, 46 insertions(+), 21 deletions(-)
 create mode 100644 nix/wlroots-nvidia.patch

diff --git a/flake.lock b/flake.lock
index 3057c8c8..96f3f136 100644
--- a/flake.lock
+++ b/flake.lock
@@ -48,11 +48,11 @@
       "flake": false,
       "locked": {
         "host": "gitlab.freedesktop.org",
-        "lastModified": 1686753331,
-        "narHash": "sha256-KovjVFwcuoUO0eu/UiWrnD3+m/K+SHSAVIz4xF9K1XA=",
+        "lastModified": 1689611045,
+        "narHash": "sha256-3RTOlQabkNetQ4O4UzSf57JPco9VGVHhSU1ls5uKBeE=",
         "owner": "wlroots",
         "repo": "wlroots",
-        "rev": "7e7633abf09b362d0bad9e3fc650fd692369291d",
+        "rev": "7791ffe0584c4ac13c170e1661ce33bdbd4a9b9e",
         "type": "gitlab"
       },
       "original": {
diff --git a/nix/wlroots-nvidia.patch b/nix/wlroots-nvidia.patch
new file mode 100644
index 00000000..130eb041
--- /dev/null
+++ b/nix/wlroots-nvidia.patch
@@ -0,0 +1,28 @@
+diff --git a/types/output/render.c b/types/output/render.c
+index 2e38919a..97f78608 100644
+--- a/types/output/render.c
++++ b/types/output/render.c
+@@ -240,22 +240,7 @@ bool output_pick_format(struct wlr_output *output,
+ }
+ 
+ uint32_t wlr_output_preferred_read_format(struct wlr_output *output) {
+-	struct wlr_renderer *renderer = output->renderer;
+-	assert(renderer != NULL);
+-
+-	if (!renderer->impl->preferred_read_format || !renderer->impl->read_pixels) {
+-		return DRM_FORMAT_INVALID;
+-	}
+-
+-	if (!wlr_output_attach_render(output, NULL)) {
+-		return false;
+-	}
+-
+-	uint32_t fmt = renderer->impl->preferred_read_format(renderer);
+-
+-	output_clear_back_buffer(output);
+-
+-	return fmt;
++	return DRM_FORMAT_XRGB8888;
+ }
+ 
+ struct wlr_render_pass *wlr_output_begin_render_pass(struct wlr_output *output,
diff --git a/nix/wlroots.nix b/nix/wlroots.nix
index 7b05d9ff..2b93da9d 100644
--- a/nix/wlroots.nix
+++ b/nix/wlroots.nix
@@ -44,10 +44,7 @@ assert (lib.assertMsg (hidpiXWayland -> enableXWayland) ''
           })
         ])
         ++ (lib.optionals nvidiaPatches [
-          (fetchpatch {
-            url = "https://aur.archlinux.org/cgit/aur.git/plain/0001-nvidia-format-workaround.patch?h=hyprland-nvidia-screenshare-git";
-            sha256 = "A9f1p5EW++mGCaNq8w7ZJfeWmvTfUm4iO+1KDcnqYX8=";
-          })
+          ./wlroots-nvidia.patch
         ]);
       postPatch =
         (old.postPatch or "")
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 520b4342..cf4945a6 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -465,7 +465,7 @@ void CCompositor::startCompositor() {
         throw std::runtime_error("The backend could not start!");
     }
 
-    wlr_xcursor_manager_set_cursor_image(m_sWLRXCursorMgr, "left_ptr", m_sWLRCursor);
+    wlr_cursor_set_xcursor(m_sWLRCursor, m_sWLRXCursorMgr, "left_ptr");
 
 #ifdef USES_SYSTEMD
     if (sd_booted() > 0)
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index f423fd0d..8cb7f330 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -300,9 +300,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
             if (g_pHyprRenderer->m_bHasARenderedCursor) {
                 // TODO: maybe wrap?
                 if (m_ecbClickBehavior == CLICKMODE_KILL)
-                    wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "crosshair", g_pCompositor->m_sWLRCursor);
+                    wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "crosshair");
                 else
-                    wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor);
+                    wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "left_ptr");
             }
 
             m_bEmptyFocusCursorSet = true;
@@ -372,7 +372,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
         // if (!m_bCursorImageOverridden) {
         //     if (!VECINRECT(m_vLastCursorPosFloored, pFoundWindow->m_vRealPosition.vec().x, pFoundWindow->m_vRealPosition.vec().y,
         //                    pFoundWindow->m_vRealPosition.vec().x + pFoundWindow->m_vRealSize.vec().x, pFoundWindow->m_vRealPosition.vec().y + pFoundWindow->m_vRealSize.vec().y)) {
-        //         wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor);
+        //         wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "left_ptr");
         //         cursorSurfaceInfo.bUsed = false;
         //     } else if (!cursorSurfaceInfo.bUsed) {
         //         cursorSurfaceInfo.bUsed = true;
@@ -478,7 +478,7 @@ void CInputManager::processMouseRequest(wlr_seat_pointer_request_set_cursor_even
     }
 
     if (m_ecbClickBehavior == CLICKMODE_KILL) {
-        wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "crosshair", g_pCompositor->m_sWLRCursor);
+        wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "crosshair");
         return;
     }
 
@@ -504,7 +504,7 @@ void CInputManager::setClickMode(eClickBehaviorMode mode) {
         case CLICKMODE_DEFAULT:
             Debug::log(LOG, "SetClickMode: DEFAULT");
             m_ecbClickBehavior = CLICKMODE_DEFAULT;
-            wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor);
+            wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "left_ptr");
             break;
 
         case CLICKMODE_KILL:
@@ -516,7 +516,7 @@ void CInputManager::setClickMode(eClickBehaviorMode mode) {
             refocus();
 
             // set cursor
-            wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "crosshair", g_pCompositor->m_sWLRCursor);
+            wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "crosshair");
             break;
         default: break;
     }
@@ -1444,7 +1444,7 @@ void CInputManager::destroySwitch(SSwitchDevice* pDevice) {
 }
 
 void CInputManager::setCursorImageUntilUnset(std::string name) {
-    wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, name.c_str(), g_pCompositor->m_sWLRCursor);
+    wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, name.c_str());
     m_bCursorImageOverridden = true;
 }
 
@@ -1454,7 +1454,7 @@ void CInputManager::unsetCursorImage() {
 
     m_bCursorImageOverridden = false;
     if (!g_pHyprRenderer->m_bWindowRequestedCursorHide)
-        wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor);
+        wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "left_ptr");
 }
 
 std::string CInputManager::deviceNameToInternalString(std::string in) {
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index f6a7132d..2345f02a 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -57,7 +57,7 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
 
     if (!g_pHyprRenderer->m_bBlockSurfaceFeedback) {
         wlr_surface_send_frame_done(surface, RDATA->when);
-        wlr_presentation_surface_sampled_on_output(g_pCompositor->m_sWLRPresentation, surface, RDATA->pMonitor->output);
+        wlr_presentation_surface_scanned_out_on_output(g_pCompositor->m_sWLRPresentation, surface, RDATA->pMonitor->output);
     }
 
     // reset the UV, we might've set it above
@@ -779,7 +779,7 @@ bool CHyprRenderer::attemptDirectScanout(CMonitor* pMonitor) {
     timespec now;
     clock_gettime(CLOCK_MONOTONIC, &now);
     wlr_surface_send_frame_done(PSURFACE, &now);
-    wlr_presentation_surface_sampled_on_output(g_pCompositor->m_sWLRPresentation, PSURFACE, pMonitor->output);
+    wlr_presentation_surface_scanned_out_on_output(g_pCompositor->m_sWLRPresentation, PSURFACE, pMonitor->output);
 
     if (wlr_output_commit(pMonitor->output)) {
         if (!m_pLastScanout) {
@@ -1918,7 +1918,7 @@ void CHyprRenderer::ensureCursorRenderingMode() {
             m_bHasARenderedCursor = true;
 
             if (!m_bWindowRequestedCursorHide)
-                wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor);
+                wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, "left_ptr");
 
             Debug::log(LOG, "Showing the cursor (timeout)");
 
diff --git a/subprojects/wlroots b/subprojects/wlroots
index 7e7633ab..7791ffe0 160000
--- a/subprojects/wlroots
+++ b/subprojects/wlroots
@@ -1 +1 @@
-Subproject commit 7e7633abf09b362d0bad9e3fc650fd692369291d
+Subproject commit 7791ffe0584c4ac13c170e1661ce33bdbd4a9b9e
diff --git a/subprojects/wlroots.wrap b/subprojects/wlroots.wrap
index 8597d1c5..366b62f0 100644
--- a/subprojects/wlroots.wrap
+++ b/subprojects/wlroots.wrap
@@ -1,7 +1,7 @@
 [wrap-git]
 directory = wlroots
 url = https://gitlab.freedesktop.org/wlroots/wlroots.git
-revision = 6e8fb5509f2c94d09d4efa0f9b1f40b37bf73863
+revision = 7791ffe0584c4ac13c170e1661ce33bdbd4a9b9e
 depth = 1
 
 diff_files = wlroots-meson-build.patch