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
3 changes: 3 additions & 0 deletions src/plugin-qt/shortcut/tools/dde-shortcut-tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ add_executable(dde-shortcut-tool
touchpadcontroller.h
powercontroller.cpp
powercontroller.h
treelandbrightnesscontroller.cpp
treelandbrightnesscontroller.h
treelandlockscreenwrapper.cpp
treelandlockscreenwrapper.h
kbdlightcontroller.cpp
Expand All @@ -51,6 +53,7 @@ qt6_generate_wayland_protocol_client_sources(dde-shortcut-tool
NO_INCLUDE_CORE_ONLY
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-dde-shell-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-v1.xml
)

target_link_libraries(dde-shortcut-tool PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "displaycontroller.h"
#include "treelandbrightnesscontroller.h"

#include <QDebug>

Check warning on line 8 in src/plugin-qt/shortcut/tools/dde-shortcut-tool/displaycontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in src/plugin-qt/shortcut/tools/dde-shortcut-tool/displaycontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusReply>
#include <QDBusConnection>
#include <QProcess>
Expand All @@ -23,8 +24,8 @@
, m_isWayland(qEnvironmentVariable("XDG_SESSION_TYPE").toLower() == "wayland")
{
if (m_isWayland) {
// TODO: Display1 is not available on Wayland. Adapt display actions to
// Treeland/compositor APIs instead of using org.deepin.dde.Display1.
// Brightness uses Treeland directly on Wayland. Other display actions
// still avoid the unavailable org.deepin.dde.Display1 service.
qInfo() << "DisplayController: skip Display1 initialization on Wayland";
return;
}
Expand Down Expand Up @@ -101,42 +102,48 @@

bool DisplayController::changeBrightness(bool raised)
{
if (m_isWayland) {
// TODO: Implement Wayland brightness control without Display1.
qWarning() << "DisplayController: brightness control is not supported on Wayland";
return false;
}

if (!m_displayInterface || !m_displayInterface->isValid()) {
if (!m_isWayland && (!m_displayInterface || !m_displayInterface->isValid())) {
qWarning() << "Display interface not available";
return false;
}

auto *powerConfig = DConfig::create("org.deepin.dde.daemon", "org.deepin.dde.daemon.power", "", this);
if (!powerConfig->isValid()) {
qWarning() << "daemon power config is not valid";
powerConfig->deleteLater();
return false;
}

// Check if ambient light auto-adjustment is enabled, disable it first if so
QVariant autoAdjustValue = powerConfig->value("ambientLightAdjustBrightness");
if (autoAdjustValue.toBool()) {
powerConfig->setValue("ambientLightAdjustBrightness", false);
qDebug() << "Disabled ambient light auto brightness adjustment";
const bool autoAdjustEnabled =
powerConfig->value("ambientLightAdjustBrightness").toBool();

bool success = false;
if (m_isWayland) {
TreelandBrightnessController controller;
success = controller.changeBrightness(raised);
} else {
// Call Display1's ChangeBrightness method directly
QDBusReply<void> reply = m_displayInterface->call("ChangeBrightness", raised);
if (!reply.isValid()) {
qWarning() << "Failed to change brightness:" << reply.error().message();
} else {
success = true;
}
}

// Call Display1's ChangeBrightness method directly
QDBusReply<void> reply = m_displayInterface->call("ChangeBrightness", raised);
if (!reply.isValid()) {
qWarning() << "Failed to change brightness:" << reply.error().message();
if (!success) {
powerConfig->deleteLater();
return false;
}

qDebug() << "Changed brightness:" << (raised ? "up" : "down");
showOSD(raised ? "BrightnessUp" : "BrightnessDown");

if (autoAdjustEnabled) {
powerConfig->setValue("ambientLightAdjustBrightness", false);
qDebug() << "Disabled ambient light auto brightness adjustment";
}
powerConfig->deleteLater();


qDebug() << "Changed brightness:" << (raised ? "up" : "down");
showOSD(raised ? "BrightnessUp" : "BrightnessDown");
return true;
}

Expand Down
Loading
Loading