Skip to content
Merged
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
12 changes: 9 additions & 3 deletions panels/notification/osd/brightness/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

find_package(TreelandProtocols REQUIRED)
find_package(TreelandProtocols 0.9 REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client)

Expand All @@ -11,12 +11,18 @@ add_library(osd-brightness SHARED
brightnessapplet.h
treelandbrightness.cpp
treelandbrightness.h
${CMAKE_SOURCE_DIR}/shell/treelandoutputuuid.h
${CMAKE_SOURCE_DIR}/shell/treelandoutputuuid.cpp
)

qt_generate_wayland_protocol_client_sources(osd-brightness
NO_INCLUDE_CORE_ONLY
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-unstable-v2.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-uuid-unstable-v1.xml
)

target_include_directories(osd-brightness PRIVATE
${CMAKE_SOURCE_DIR}/shell
)

target_link_libraries(osd-brightness PRIVATE
Expand Down
111 changes: 80 additions & 31 deletions panels/notification/osd/brightness/treelandbrightness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,151 @@

#include "treelandbrightness.h"

#include "wayland-treeland-output-manager-v1-client-protocol.h"
#include "wayland-treeland-output-manager-unstable-v2-client-protocol.h"

Check warning on line 7 in panels/notification/osd/brightness/treelandbrightness.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "wayland-treeland-output-manager-unstable-v2-client-protocol.h" not found.

#include <QGuiApplication>

Check warning on line 9 in panels/notification/osd/brightness/treelandbrightness.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QScreen>

Check warning on line 10 in panels/notification/osd/brightness/treelandbrightness.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScreen> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <wayland-client.h>

namespace osd {

TreelandColorControl::TreelandColorControl(struct ::treeland_output_color_control_v1 *object, QObject *parent)
TreelandPictureControl::TreelandPictureControl(struct ::treeland_output_picture_control_v2 *object, QObject *parent)
: QObject(parent)
, QtWayland::treeland_output_color_control_v1(object)
, QtWayland::treeland_output_picture_control_v2(object)
{
}

TreelandColorControl::~TreelandColorControl()
TreelandPictureControl::~TreelandPictureControl()
{
if (isInitialized()) {
destroy();
}
}

double TreelandColorControl::brightness() const
double TreelandPictureControl::brightness() const
{
return m_brightness;
}

void TreelandColorControl::treeland_output_color_control_v1_brightness(wl_fixed_t brightness)
void TreelandPictureControl::treeland_output_picture_control_v2_brightness(wl_fixed_t brightness)
{
m_brightness = wl_fixed_to_double(brightness);
Q_EMIT brightnessChanged(m_brightness);
}

void TreelandPictureControl::treeland_output_picture_control_v2_result(uint32_t result)
{
Q_EMIT resultReceived(result);
}

TreelandBrightness::TreelandBrightness(QObject *parent)
: QWaylandClientExtensionTemplate<TreelandBrightness>(treeland_output_manager_v1_interface.version)
: QWaylandClientExtensionTemplate<TreelandBrightness>(treeland_output_manager_v2_interface.version)
{
setParent(parent);

m_uuidManager = new ::TreelandOutputUuidManager(this);
connect(m_uuidManager, &::TreelandOutputUuidManager::activeChanged, this, &TreelandBrightness::refresh);
connect(this, &TreelandBrightness::activeChanged, this, &TreelandBrightness::refresh);
connect(qApp, &QGuiApplication::primaryScreenChanged, this, &TreelandBrightness::refresh);
}

TreelandBrightness::~TreelandBrightness()
{
delete m_control;
m_control = nullptr;
m_output = nullptr;
m_primaryScreen = nullptr;
delete m_uuidRequest;
m_uuidRequest = nullptr;
if (isInitialized()) {
destroy();
}
}

void TreelandBrightness::refresh()
{
if (!isActive()) {
if (!isActive() || !m_uuidManager || !m_uuidManager->isActive()) {
delete m_control;
m_control = nullptr;
m_output = nullptr;
m_primaryScreen = nullptr;
delete m_uuidRequest;
m_uuidRequest = nullptr;
m_currentUuid.clear();
return;
}

struct wl_output *output = primaryWlOutput();
if (m_control && m_output == output && output) {
QScreen *screen = qApp->primaryScreen();
if (m_primaryScreen == screen && m_control && !m_currentUuid.isEmpty()) {
return;
}

delete m_control;
m_control = nullptr;
m_output = output;
m_primaryScreen = screen;
m_currentUuid.clear();

if (!output) {
if (!screen) {
return;
}

auto *raw = get_color_control(output);
if (!raw) {
requestPrimaryUuid();
}

void TreelandBrightness::requestPrimaryUuid()
{
if (!m_uuidManager || !m_uuidManager->isActive())
return;
}

m_control = new TreelandColorControl(raw, this);
connect(m_control, &TreelandColorControl::brightnessChanged,
this, &TreelandBrightness::brightnessChanged);
if (!m_primaryScreen)
return;

auto *waylandScreen = m_primaryScreen->nativeInterface<QNativeInterface::QWaylandScreen>();
if (!waylandScreen || !waylandScreen->output())
return;

struct wl_output *output = waylandScreen->output();

delete m_uuidRequest;
m_uuidRequest = nullptr;

auto *raw = m_uuidManager->get_uuid(output);
if (!raw)
return;

m_uuidRequest = new ::TreelandOutputUuid(raw, this);

connect(m_uuidRequest, &::TreelandOutputUuid::uuidReceived, this, [this](const QString &uuid) {
if (sender() != m_uuidRequest)
return;

if (uuid.isEmpty())
return;

m_currentUuid = uuid;

delete m_uuidRequest;
m_uuidRequest = nullptr;
Comment on lines +129 to +130

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Event handling crashes the OSD

When a UUID or picture-control proxy delivers its event, the callbacks synchronously delete the proxy whose event is being dispatched, which can invalidate the active Wayland callback and crash the OSD.

Defer proxy deletion until event dispatch has returned.

Also at panels/notification/osd/brightness/treelandbrightness.cpp:141-143.

Prompt for AI agents
In `panels/notification/osd/brightness/treelandbrightness.cpp` at lines 129-130:

**Event handling crashes the OSD**

When a UUID or picture-control proxy delivers its event, the callbacks synchronously delete the proxy whose event is being dispatched, which can invalidate the active Wayland callback and crash the OSD.

Defer proxy deletion until event dispatch has returned.

Also at `panels/notification/osd/brightness/treelandbrightness.cpp:141-143`.


auto *raw = get_picture_control(uuid);
if (!raw)
return;

m_control = new TreelandPictureControl(raw, this);
connect(m_control, &TreelandPictureControl::brightnessChanged,
this, &TreelandBrightness::brightnessChanged);
connect(m_control, &TreelandPictureControl::resultReceived, this, [this](uint32_t result) {
if (result == TreelandPictureControl::commit_result_invalid_output) {
delete m_control;
m_control = nullptr;
m_currentUuid.clear();
Comment on lines +141 to +143

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Brightness stays stale after invalid output

When the compositor reports commit_result_invalid_output while the primary screen remains unchanged, the handler deletes m_control and clears m_currentUuid without emitting brightnessChanged or requesting a replacement control, so the provider loses brightness and the applet keeps displaying its cached value until another refresh trigger.

Emit the brightness update and retry acquiring the UUID and picture control after invalid output.

Prompt for AI agents
In `panels/notification/osd/brightness/treelandbrightness.cpp` at lines 141-143:

**Brightness stays stale after invalid output**

When the compositor reports `commit_result_invalid_output` while the primary screen remains unchanged, the handler deletes `m_control` and clears `m_currentUuid` without emitting `brightnessChanged` or requesting a replacement control, so the provider loses brightness and the applet keeps displaying its cached value until another refresh trigger.

Emit the brightness update and retry acquiring the UUID and picture control after invalid output.

}
});
});
}

double TreelandBrightness::brightness() const
{
return m_control ? m_control->brightness() : 0.0;
}

struct wl_output *TreelandBrightness::primaryWlOutput() const
{
auto *screen = qApp->primaryScreen();
if (!screen) {
return nullptr;
}

auto *waylandScreen = screen->nativeInterface<QNativeInterface::QWaylandScreen>();
return waylandScreen ? waylandScreen->output() : nullptr;
}

} // namespace osd
38 changes: 24 additions & 14 deletions panels/notification/osd/brightness/treelandbrightness.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,49 @@

#pragma once

#include "qwayland-treeland-output-manager-v1.h"
#include "treelandoutputuuid.h"

Check warning on line 7 in panels/notification/osd/brightness/treelandbrightness.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "treelandoutputuuid.h" not found.
#include "qwayland-treeland-output-manager-unstable-v2.h"

Check warning on line 8 in panels/notification/osd/brightness/treelandbrightness.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "qwayland-treeland-output-manager-unstable-v2.h" not found.

#include <QObject>

Check warning on line 10 in panels/notification/osd/brightness/treelandbrightness.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 11 in panels/notification/osd/brightness/treelandbrightness.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtWaylandClient/QWaylandClientExtension>

Check warning on line 12 in panels/notification/osd/brightness/treelandbrightness.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtWaylandClient/QWaylandClientExtension> not found. Please note: Cppcheck does not need standard library headers to get proper results.

struct wl_output;
struct treeland_output_color_control_v1;
struct treeland_output_picture_control_v2;
struct treeland_output_uuid_v1;

class QScreen;

namespace osd {

class TreelandColorControl : public QObject, public QtWayland::treeland_output_color_control_v1
class TreelandPictureControl : public QObject, public QtWayland::treeland_output_picture_control_v2
{
Q_OBJECT

public:
explicit TreelandColorControl(struct ::treeland_output_color_control_v1 *object, QObject *parent = nullptr);
~TreelandColorControl() override;
explicit TreelandPictureControl(struct ::treeland_output_picture_control_v2 *object, QObject *parent = nullptr);
~TreelandPictureControl() override;

double brightness() const;

Q_SIGNALS:
void brightnessChanged(double brightness);
void resultReceived(uint32_t result);

Check warning on line 34 in panels/notification/osd/brightness/treelandbrightness.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'resultReceived' shadows outer function

protected:
void treeland_output_color_control_v1_brightness(wl_fixed_t brightness) override;
void treeland_output_picture_control_v2_brightness(wl_fixed_t brightness) override;
void treeland_output_picture_control_v2_result(uint32_t result) override;

private:
double m_brightness = 0.0;
};

// Read-only Treeland brightness provider for the OSD. It binds a single
// treeland_output_color_control_v1 to the primary wl_output and caches the
// brightness reported by the compositor. It never commits brightness changes;
// dde-shortcut-tool is responsible for adjusting brightness, and this provider
// only reflects the resulting value.
class TreelandBrightness : public QWaylandClientExtensionTemplate<TreelandBrightness>, public QtWayland::treeland_output_manager_v1
// treeland_output_picture_control_v2 to the primary output (identified by uuid)
// and caches the brightness reported by the compositor. It never commits
// brightness changes; dde-shortcut-tool is responsible for adjusting brightness,
// and this provider only reflects the resulting value.
class TreelandBrightness : public QWaylandClientExtensionTemplate<TreelandBrightness>, public QtWayland::treeland_output_manager_v2
{
Q_OBJECT

Expand All @@ -56,10 +62,14 @@
void brightnessChanged(double brightness);

private:
struct wl_output *primaryWlOutput() const;
void requestPrimaryUuid();

QPointer<TreelandPictureControl> m_control;
QPointer<QScreen> m_primaryScreen;
QString m_currentUuid;

QPointer<TreelandColorControl> m_control;
struct wl_output *m_output = nullptr;
::TreelandOutputUuidManager *m_uuidManager = nullptr;
QPointer<::TreelandOutputUuid> m_uuidRequest;
};

} // namespace osd
7 changes: 5 additions & 2 deletions shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Widgets Gui WaylandClient)
find_package(TreelandProtocols REQUIRED)
find_package(TreelandProtocols 0.9 REQUIRED)
pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client)

if (NOT DEFINED SYSTEMD_USER_UNIT_DIR)
Expand All @@ -23,14 +23,17 @@ add_executable(dde-shell
shell.cpp
treelandoutputwatcher.h
treelandoutputwatcher.cpp
treelandoutputuuid.h
treelandoutputuuid.cpp
dde-shell.qrc
override_dtkdeclarative_qml.qrc
dde-shell-icons.qrc
)

qt_generate_wayland_protocol_client_sources(dde-shell
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-unstable-v2.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-uuid-unstable-v1.xml
)

target_compile_definitions(dde-shell
Expand Down
36 changes: 36 additions & 0 deletions shell/treelandoutputuuid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "treelandoutputuuid.h"
#include "wayland-treeland-output-uuid-unstable-v1-client-protocol.h"

Check warning on line 6 in shell/treelandoutputuuid.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "wayland-treeland-output-uuid-unstable-v1-client-protocol.h" not found.

TreelandOutputUuidManager::TreelandOutputUuidManager(QObject *parent)
: QWaylandClientExtensionTemplate<TreelandOutputUuidManager>(treeland_output_uuid_manager_v1_interface.version)
{
setParent(parent);
}

TreelandOutputUuidManager::~TreelandOutputUuidManager()
{
if (isInitialized())
destroy();
}

TreelandOutputUuid::TreelandOutputUuid(struct ::treeland_output_uuid_v1 *object, QObject *parent)
: QObject(parent)
, QtWayland::treeland_output_uuid_v1(object)
{
}

TreelandOutputUuid::~TreelandOutputUuid()
{
if (isInitialized())
destroy();
}

void TreelandOutputUuid::treeland_output_uuid_v1_uuid(const QString &uuid)
{
m_uuid = uuid;
Q_EMIT uuidReceived(uuid);
}
41 changes: 41 additions & 0 deletions shell/treelandoutputuuid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "qwayland-treeland-output-uuid-unstable-v1.h"
#include <QtWaylandClient/QWaylandClientExtension>
#include <QObject>
#include <QString>

class TreelandOutputUuidManager
: public QWaylandClientExtensionTemplate<TreelandOutputUuidManager>
, public QtWayland::treeland_output_uuid_manager_v1
{
Q_OBJECT
public:
TreelandOutputUuidManager(QObject *parent = nullptr);
~TreelandOutputUuidManager();
};

class TreelandOutputUuid
: public QObject
, public QtWayland::treeland_output_uuid_v1
{
Q_OBJECT
public:
TreelandOutputUuid(struct ::treeland_output_uuid_v1 *object, QObject *parent = nullptr);
~TreelandOutputUuid() override;

QString uuid() const { return m_uuid; }

Q_SIGNALS:
void uuidReceived(const QString &uuid);

protected:
void treeland_output_uuid_v1_uuid(const QString &uuid) override;

private:
QString m_uuid;
};
Loading
Loading