mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
This is partially an emergency fix also for https://invent.kde.org/plasma/plasma-mobile/-/issues/404, which was potentially introduced by https://invent.kde.org/plasma/plasma-mobile/-/merge_requests/582 This MR extracts the screen brightness implementation from initialstart to a QML plugin, and also ports the action drawer brightness slider implementation to it. This avoids importing the powerdevil screen brightness plugin on the lockscreen, which apparently has a race condition that causes it to sometimes segfault.
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
// SPDX-FileCopyrightText: 2024 Devin Lin <devin@kde.org>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <QDBusServiceWatcher>
|
|
#include <QObject>
|
|
#include <qqmlregistration.h>
|
|
|
|
#include "brightnesscontrolinterface.h"
|
|
|
|
/**
|
|
* Utility class that provides useful functions related to screen brightness.
|
|
*
|
|
* @author Devin Lin <devin@kde.org>
|
|
**/
|
|
class ScreenBrightnessUtil : public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged);
|
|
Q_PROPERTY(int maxBrightness READ maxBrightness NOTIFY maxBrightnessChanged)
|
|
Q_PROPERTY(bool brightnessAvailable READ brightnessAvailable NOTIFY brightnessAvailableChanged)
|
|
QML_ELEMENT
|
|
|
|
public:
|
|
ScreenBrightnessUtil(QObject *parent = nullptr);
|
|
|
|
int brightness() const;
|
|
void setBrightness(int brightness);
|
|
|
|
int maxBrightness() const;
|
|
|
|
bool brightnessAvailable() const;
|
|
|
|
Q_SIGNALS:
|
|
void brightnessChanged();
|
|
void maxBrightnessChanged();
|
|
void brightnessAvailableChanged();
|
|
|
|
private Q_SLOTS:
|
|
void fetchBrightness();
|
|
void fetchMaxBrightness();
|
|
|
|
private:
|
|
int m_brightness;
|
|
int m_maxBrightness;
|
|
|
|
org::kde::Solid::PowerManagement::Actions::BrightnessControl *m_brightnessInterface;
|
|
QDBusServiceWatcher *m_brightnessInterfaceWatcher;
|
|
};
|