Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ Specific protocols can also be disabled:
[zwlr-screencopy-v1]: https://wayland.app/protocols/wlr-screencopy-unstable-v1
[hyprland-toplevel-export-v1]: https://wayland.app/protocols/hyprland-toplevel-export-v1

#### Render Control
Use quickshell's render control for Wayland windows and report changed frame regions
to the compositor. Enable it in a shell with `//@ pragma RenderControl`.
Requires Qt 6.8 or newer and is skipped on older versions.

To disable: `-DWAYLAND_RENDER_CONTROL=OFF`

Dependencies:
- `libgbm`
- `vulkan-headers` (build-time)

### X11
This feature enables x11 support. Currently this implements panel windows for X11 similarly
to the wlroots layershell above.
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ boption(SCREENCOPY " Screencopy" ON REQUIRES WAYLAND)
boption(SCREENCOPY_ICC " Image Copy Capture" ON REQUIRES WAYLAND)
boption(SCREENCOPY_WLR " Wlroots Screencopy" ON REQUIRES WAYLAND)
boption(SCREENCOPY_HYPRLAND_TOPLEVEL " Hyprland Toplevel Export" ON REQUIRES WAYLAND)
boption(WAYLAND_RENDER_CONTROL " Render Control" ON REQUIRES WAYLAND)
boption(X11 "X11" ON)
boption(I3 "I3/Sway" ON)
boption(I3_IPC " I3/Sway IPC" ON REQUIRES I3)
Expand Down Expand Up @@ -147,6 +148,12 @@ if (Qt6_VERSION VERSION_GREATER_EQUAL "6.9.0")
find_package(Qt6 REQUIRED COMPONENTS ${QT_PRIVDEPS})
endif()

# Render control paces animations with QChronoTimer, which was added in Qt 6.8.
if (WAYLAND_RENDER_CONTROL AND Qt6_VERSION VERSION_LESS "6.8.0")
message(STATUS " Render Control: OFF (Requires Qt 6.8)")
set(WAYLAND_RENDER_CONTROL OFF)
endif()

set(CMAKE_AUTOUIC OFF)
qt_standard_project_setup(REQUIRES 6.6)
set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml_modules)
Expand Down
1 change: 1 addition & 0 deletions changelog/next.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Other Changes

- Added experimental Wayland rendering with partial damage, enabled by the `RenderControl` pragma.
- `SystemTrayItem.activate()` now forwards Wayland activation tokens to applications.

## Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
(lib.cmakeBool "USE_JEMALLOC" withJemalloc)
(lib.cmakeBool "WAYLAND" withWayland)
(lib.cmakeBool "SCREENCOPY" (libgbm != null))
(lib.cmakeBool "WAYLAND_RENDER_CONTROL" (libgbm != null && lib.versionAtLeast qt6.qtbase.version "6.8"))
(lib.cmakeBool "SERVICE_PIPEWIRE" withPipewire)
(lib.cmakeBool "SERVICE_PAM" withPam)
(lib.cmakeBool "SERVICE_NETWORKMANAGER" withNetworkManager)
Expand Down
5 changes: 5 additions & 0 deletions src/launch/launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../core/qmlglobal.hpp"
#include "../core/rootwrapper.hpp"
#include "../ipc/ipc.hpp"
#include "../window/rendercontrol.hpp"
#include "build.hpp"
#include "launch_p.hpp"

Expand Down Expand Up @@ -73,6 +74,7 @@ int launch(const LaunchArgs& args, char** argv) {
struct {
bool useQApplication = false;
bool nativeTextRendering = false;
bool renderControl = false;
bool desktopSettingsAware = true;
bool useSystemStyle = false;
QString iconTheme = qEnvironmentVariable("QS_ICON_THEME");
Expand Down Expand Up @@ -110,6 +112,7 @@ int launch(const LaunchArgs& args, char** argv) {
else pragmas.envOverrides.insert(var, val);
} else if (pragma == "UseQApplication") pragmas.useQApplication = true;
else if (pragma == "NativeTextRendering") pragmas.nativeTextRendering = true;
else if (pragma == "RenderControl") pragmas.renderControl = true;
else if (pragma == "IgnoreSystemSettings") pragmas.desktopSettingsAware = false;
else if (pragma == "RespectSystemStyle") pragmas.useSystemStyle = true;
else if (pragma == "DropExpensiveFonts") pragmas.dropExpensiveFonts = true;
Expand Down Expand Up @@ -313,6 +316,8 @@ int launch(const LaunchArgs& args, char** argv) {
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
}

if (pragmas.renderControl) qs::window::WindowRenderControl::setEnabled(true);

qs::ipc::IpcServer::start();
QsPaths::instance()->createLock();

Expand Down
11 changes: 10 additions & 1 deletion src/wayland/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ if (WAYLAND_TOPLEVEL_MANAGEMENT)
list(APPEND WAYLAND_MODULES Quickshell.Wayland._ToplevelManagement)
endif()

if (SCREENCOPY)
if (SCREENCOPY OR WAYLAND_RENDER_CONTROL)
add_subdirectory(buffer)
endif()

if (SCREENCOPY)
add_subdirectory(screencopy)
list(APPEND WAYLAND_MODULES Quickshell.Wayland._Screencopy)
endif()

if (WAYLAND_RENDER_CONTROL)
target_sources(quickshell-wayland PRIVATE rendercontrol.cpp)
target_link_libraries(quickshell-wayland PRIVATE quickshell-wayland-buffer Qt::QuickPrivate)
target_compile_definitions(quickshell-wayland-init PRIVATE QS_WAYLAND_RENDER_CONTROL)
endif()


if (HYPRLAND)
add_subdirectory(hyprland)
Expand Down
2 changes: 2 additions & 0 deletions src/wayland/background_effect/qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void BackgroundEffect::onWindowPolished() {

this->surface->setBlurRegion(region);
this->pendingBlurRegion = false;

if (auto* window = qobject_cast<QsQuickWindowBase*>(this->mWindow)) window->requestCommit();
}

bool BackgroundEffect::eventFilter(QObject* object, QEvent* event) {
Expand Down
46 changes: 45 additions & 1 deletion src/wayland/buffer/dmabuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <libdrm/drm_fourcc.h>
#include <private/qquickwindow_p.h>
#include <private/qrhivulkan_p.h>
#include <private/qwaylandclientbufferintegration_p.h>
#include <private/qwaylandintegration_p.h>
#include <qcontainerfwd.h>
#include <qdebug.h>
#include <qdir.h>
Expand All @@ -36,6 +38,7 @@
#include <qwayland-linux-dmabuf-v1.h>
#include <qwaylandclientextension.h>
#include <sys/mman.h>
#include <sys/poll.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
Expand Down Expand Up @@ -342,8 +345,27 @@ bool LinuxDmabufManager::initRenderFormatsGl(QQuickWindow* window) {
return false;
}

auto* display = qEglContext->display();
return this->initRenderFormatsEgl(qEglContext->display());
}

bool LinuxDmabufManager::initRenderFormatsFromPlatformDisplay() {
auto* integration = QtWaylandClient::QWaylandIntegration::instance()->clientBufferIntegration();
if (!integration) {
qCCritical(logDmabuf) << "Failed to query render formats: No client buffer integration.";
return false;
}

auto* display =
integration->nativeResource(QtWaylandClient::QWaylandClientBufferIntegration::EglDisplay);
if (!display) {
qCCritical(logDmabuf) << "Failed to query render formats: No EGL display.";
return false;
}

return this->initRenderFormatsEgl(static_cast<EGLDisplay>(display));
}

bool LinuxDmabufManager::initRenderFormatsEgl(EGLDisplay display) {
static auto* eglQueryDisplayAttribEXT =
eglProc<PFNEGLQUERYDISPLAYATTRIBEXTPROC>("eglQueryDisplayAttribEXT");
static auto* eglQueryDeviceStringEXT =
Expand Down Expand Up @@ -884,6 +906,28 @@ WlBufferQSGTexture* WlDmaBuffer::createQsgTexture(QQuickWindow* window) const {
return this->createQsgTextureGl(window);
}

void WlDmaBuffer::finish() const {
// A driver with implicit sync keeps a write fence on the dmabuf until the GPU is done,
// which the compositor waits for; see dma_buf_poll().
if (this->planeCount != 0) {
const auto& plane = this->planes[0]; // NOLINT
auto fenced = pollfd {.fd = plane.fd, .events = POLLIN, .revents = 0};
if (poll(&fenced, 1, 0) == 0) return;
}

auto* display = eglGetCurrentDisplay();
auto* fence = eglCreateSync(display, EGL_SYNC_FENCE, nullptr);

if (fence == EGL_NO_SYNC) {
glFinish();
return;
}

auto status = eglClientWaitSync(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT, EGL_FOREVER);
eglDestroySync(display, fence);
if (status != EGL_CONDITION_SATISFIED) glFinish();
}

WlBufferQSGTexture* WlDmaBuffer::createQsgTextureGl(QQuickWindow* window) const {
static auto* glEGLImageTargetTexture2DOES = []() {
auto* fn = reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(
Expand Down
3 changes: 3 additions & 0 deletions src/wayland/buffer/dmabuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class WlDmaBuffer: public WlBuffer {

[[nodiscard]] bool isCompatible(const WlBufferRequest& request) const override;
[[nodiscard]] WlBufferQSGTexture* createQsgTexture(QQuickWindow* window) const override;
void finish() const override;

private:
WlDmaBuffer() noexcept = default;
Expand Down Expand Up @@ -237,9 +238,11 @@ class LinuxDmabufManager
);

bool initRenderFormats(QQuickWindow* window);
bool initRenderFormatsFromPlatformDisplay();

private:
bool initRenderFormatsGl(QQuickWindow* window);
bool initRenderFormatsEgl(EGLDisplay display);
bool initRenderFormatsVk(QQuickWindow* window);

void feedbackDone();
Expand Down
30 changes: 21 additions & 9 deletions src/wayland/buffer/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <qmatrix4x4.h>
#include <qnamespace.h>
#include <qquickwindow.h>
#include <qsgrendererinterface.h>
#include <qtenvironmentvariables.h>
#include <qtmetamacros.h>
#include <qvectornd.h>
Expand Down Expand Up @@ -75,17 +76,16 @@ void WlBufferManager::initWindow(QQuickWindow* window) {
}

qCDebug(logBuffer) << "Initializing render formats";
auto success = this->p->dmabuf.initRenderFormats(window);
this->p->renderFormatsDone(this->p->dmabuf.initRenderFormats(window));
}

if (!success) {
qCWarning(
logBuffer
) << "Render format initialization failed. All buffers will fall back to SHM.";
this->p->mRenderFormatsFailed = true;
}
bool WlBufferManager::initWithoutWindow() {
if (this->p->mRenderFormatsReady) return !this->p->mRenderFormatsFailed;
if (QQuickWindow::graphicsApi() != QSGRendererInterface::OpenGL) return true;

this->p->mRenderFormatsReady = true;
if (this->p->mDmabufFormatsReady) emit this->ready();
qCDebug(logBuffer) << "Initializing render formats from the platform display";
this->p->renderFormatsDone(this->p->dmabuf.initRenderFormatsFromPlatformDisplay());
return !this->p->mRenderFormatsFailed;
}

bool WlBufferManager::isReady() const {
Expand Down Expand Up @@ -137,6 +137,18 @@ WlBufferManagerPrivate::WlBufferManagerPrivate(WlBufferManager* manager)
: manager(manager)
, dmabuf(this) {}

void WlBufferManagerPrivate::renderFormatsDone(bool success) {
if (!success) {
qCWarning(
logBuffer
) << "Render format initialization failed. All buffers will fall back to SHM.";
this->mRenderFormatsFailed = true;
}

this->mRenderFormatsReady = true;
if (this->mDmabufFormatsReady) emit this->manager->ready();
}

void WlBufferManagerPrivate::dmabufReady() {
this->mDmabufFormatsReady = true;
if (this->mRenderFormatsReady) emit this->manager->ready();
Expand Down
5 changes: 5 additions & 0 deletions src/wayland/buffer/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class WlBuffer {

// Must be called from render thread.
[[nodiscard]] virtual WlBufferQSGTexture* createQsgTexture(QQuickWindow* window) const = 0;
// Blocks until the GPU has drawn what was rendered into the buffer, unless the compositor
// can wait for it. Must be called from render thread with the rendering context current.
virtual void finish() const {}

WlBufferTransform transform;

Expand Down Expand Up @@ -127,6 +130,8 @@ class WlBufferManager: public QObject {
static WlBufferManager* instance();

void initWindow(QQuickWindow* window);
// True when render formats work, or cannot be known before a window exists.
[[nodiscard]] bool initWithoutWindow();
[[nodiscard]] bool isReady() const;
[[nodiscard]] WlBuffer* createBuffer(const WlBufferRequest& request);

Expand Down
1 change: 1 addition & 0 deletions src/wayland/buffer/manager_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WlBufferManagerPrivate {
explicit WlBufferManagerPrivate(WlBufferManager* manager);

void dmabufReady();
void renderFormatsDone(bool success);

WlBufferManager* manager;
dmabuf::LinuxDmabufManager dmabuf;
Expand Down
3 changes: 3 additions & 0 deletions src/wayland/hyprland/surface/qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void HyprlandWindow::updateVisibleMask() {

void HyprlandWindow::onWindowPolished() {
if (!this->surface) return;
if (!this->pendingPolish.opacity && !this->pendingPolish.visibleMask) return;

if (this->pendingPolish.opacity) {
this->surface->setOpacity(this->mOpacity);
Expand All @@ -134,6 +135,8 @@ void HyprlandWindow::onWindowPolished() {
this->surface->setVisibleRegion(mask);
this->pendingPolish.visibleMask = false;
}

if (auto* window = qobject_cast<QsQuickWindowBase*>(this->mWindow)) window->requestCommit();
}

void HyprlandWindow::onWindowConnected() {
Expand Down
11 changes: 10 additions & 1 deletion src/wayland/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ void installWlProxySafeDeref(); // NOLINT(misc-use-internal-linkage)
void installPlatformMenuHook(); // NOLINT(misc-use-internal-linkage)
void installPopupPositioner(); // NOLINT(misc-use-internal-linkage)

#ifdef QS_WAYLAND_RENDER_CONTROL
void installRenderControl(); // NOLINT(misc-use-internal-linkage)
#endif

namespace {

class WaylandPlugin: public QsEnginePlugin {
Expand All @@ -33,7 +37,12 @@ class WaylandPlugin: public QsEnginePlugin {
return isWayland;
}

void preinit() override { installWlProxySafeDeref(); }
void preinit() override {
installWlProxySafeDeref();
#ifdef QS_WAYLAND_RENDER_CONTROL
installRenderControl();
#endif
}

void init() override {
installPlatformMenuHook();
Expand Down
Loading
Loading