File indexing completed on 2024-05-12 09:41:26
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Dario Freddi <drf@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QHash> 0010 #include <QObject> 0011 0012 #include "powerdevilbrightnesslogic.h" 0013 #include "powerdevilkeyboardbrightnesslogic.h" 0014 #include "powerdevilscreenbrightnesslogic.h" 0015 0016 #include "powerdevilcore_export.h" 0017 0018 class KJob; 0019 0020 namespace PowerDevil 0021 { 0022 class POWERDEVILCORE_EXPORT BackendInterface : public QObject 0023 { 0024 Q_OBJECT 0025 Q_DISABLE_COPY(BackendInterface) 0026 0027 public: 0028 explicit BackendInterface(QObject *parent = nullptr); 0029 ~BackendInterface() override; 0030 0031 /** 0032 * This enum defines the different types of brightness controls. 0033 * 0034 * - UnknownBrightnessControl: Unknown 0035 * - Screen: Brightness control for a monitor or laptop panel 0036 * - Keyboard: Brightness control for a keyboard backlight 0037 */ 0038 enum BrightnessControlType { UnknownBrightnessControl = 0, Screen = 1, Keyboard = 2 }; 0039 Q_ENUM(BrightnessControlType) 0040 0041 /** 0042 * Initializes the backend. This function @b MUST be called before the backend is usable. Using 0043 * any method in BackendInterface without initializing it might lead to undefined behavior. The signal 0044 * @c backendReady will be streamed upon completion. 0045 * 0046 * @note Backend implementations @b MUST reimplement this function 0047 */ 0048 virtual void init() = 0; 0049 0050 /** 0051 * Gets the screen brightness value. 0052 * 0053 * @return the brightness of the screen, as an integer from 0 to brightnessValueMax 0054 */ 0055 virtual int screenBrightness() const = 0; 0056 0057 /** 0058 * Gets the maximum device brightness value. 0059 * 0060 * @param device the name of the device that you would like to control 0061 * @return the maximum brightness of the device 0062 */ 0063 virtual int screenBrightnessMax() const = 0; 0064 0065 int screenBrightnessSteps(); 0066 0067 virtual void setScreenBrightness(int value) = 0; 0068 0069 virtual int screenBrightnessKeyPressed(BrightnessLogic::BrightnessKeyType type) = 0; 0070 0071 virtual bool screenBrightnessAvailable() const = 0; 0072 0073 virtual int keyboardBrightness() const = 0; 0074 0075 virtual int keyboardBrightnessMax() const = 0; 0076 0077 int keyboardBrightnessSteps(); 0078 0079 virtual void setKeyboardBrightness(int value) = 0; 0080 0081 virtual int keyboardBrightnessKeyPressed(BrightnessLogic::BrightnessKeyType type) = 0; 0082 0083 virtual bool keyboardBrightnessAvailable() const = 0; 0084 0085 Q_SIGNALS: 0086 void screenBrightnessChanged(const BrightnessLogic::BrightnessInfo &brightnessInfo); 0087 0088 void keyboardBrightnessChanged(const BrightnessLogic::BrightnessInfo &brightnessInfo); 0089 0090 /** 0091 * This signal is emitted when the backend is ready to be used 0092 * 0093 * @see init 0094 */ 0095 void backendReady(); 0096 0097 protected: 0098 void onScreenBrightnessChanged(int value, int valueMax); 0099 void onKeyboardBrightnessChanged(int value, int valueMax, bool notify = false); 0100 0101 void setBackendIsReady(); 0102 0103 // Steps logic 0104 int calculateNextScreenBrightnessStep(int value, int valueMax, BrightnessLogic::BrightnessKeyType keyType); 0105 int calculateNextKeyboardBrightnessStep(int value, int valueMax, BrightnessLogic::BrightnessKeyType keyType); 0106 0107 private: 0108 ScreenBrightnessLogic m_screenBrightnessLogic; 0109 KeyboardBrightnessLogic m_keyboardBrightnessLogic; 0110 0111 friend class Core; 0112 0113 protected: 0114 int m_keyboardBrightnessBeforeTogglingOff; 0115 }; 0116 0117 }