File indexing completed on 2024-12-15 05:06:52

0001 /*
0002  *   SPDX-FileCopyrightText: 2010 Dario Freddi <drf@kde.org>
0003  *   SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0004  *
0005  *   SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include <KScreen/Types>
0011 
0012 #include <powerdevilaction.h>
0013 #include <powerdevilenums.h>
0014 
0015 #include <optional>
0016 
0017 namespace PowerDevil::BundledActions
0018 {
0019 class HandleButtonEvents : public PowerDevil::Action
0020 {
0021     Q_OBJECT
0022     Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.PowerManagement.Actions.HandleButtonEvents")
0023 
0024 public:
0025     explicit HandleButtonEvents(QObject *parent);
0026     ~HandleButtonEvents() override;
0027 
0028     bool loadAction(const PowerDevil::ProfileSettings &profileSettings) override;
0029     bool isSupported() override;
0030 
0031 Q_SIGNALS:
0032     void triggersLidActionChanged(bool triggers);
0033 
0034 protected:
0035     void triggerImpl(const QVariantMap &args) override;
0036     void onProfileUnload() override;
0037     void onIdleTimeout(std::chrono::milliseconds timeout) override;
0038 
0039 public Q_SLOTS:
0040     int lidAction() const;
0041     bool triggersLidAction() const;
0042 
0043 private Q_SLOTS:
0044     void onLidClosedChanged(bool closed);
0045     void powerOffButtonTriggered();
0046     void powerDownButtonTriggered();
0047     void sleep();
0048     void hibernate();
0049 
0050     void checkOutputs();
0051 
0052 private:
0053     void processAction(PowerDevil::PowerButtonAction action);
0054     void triggerAction(const QString &action, const QVariant &type);
0055 
0056     KScreen::ConfigPtr m_screenConfiguration;
0057     PowerDevil::PowerButtonAction m_lidAction = PowerDevil::PowerButtonAction::NoAction;
0058     bool m_triggerLidActionWhenExternalMonitorPresent = false;
0059     std::optional<bool> m_externalMonitorPresent;
0060 
0061     PowerDevil::PowerButtonAction m_powerButtonAction = PowerDevil::PowerButtonAction::NoAction;
0062     PowerDevil::PowerButtonAction m_powerDownButtonAction = PowerDevil::PowerButtonAction::NoAction;
0063     PowerDevil::PowerButtonAction m_sleepButtonAction = PowerDevil::PowerButtonAction::Sleep;
0064     PowerDevil::PowerButtonAction m_hibernateButtonAction = PowerDevil::PowerButtonAction::Hibernate;
0065 
0066     std::optional<int> m_oldKeyboardBrightness;
0067 };
0068 
0069 }