1 /*  This file is part of the KDE project
2  *    Copyright (C) 2010 Lukas Tinkl <ltinkl@redhat.com>
3  *    Copyright (C) 2015 Kai Uwe Broulik <kde@privat.broulik.de>
4  *
5  *    This library is free software; you can redistribute it and/or
6  *    modify it under the terms of the GNU Library General Public
7  *    License version 2 as published by the Free Software Foundation.
8  *
9  *    This library is distributed in the hope that it will be useful,
10  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *    Library General Public License for more details.
13  *
14  *    You should have received a copy of the GNU Library General Public License
15  *    along with this library; see the file COPYING.LIB.  If not, write to
16  *    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  *    Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #ifndef XRANDRBRIGHTNESS_H
22 #define XRANDRBRIGHTNESS_H
23 
24 #include <xcb/xcb.h>
25 #include <xcb/randr.h>
26 
27 #include <QScopedPointer>
28 #include <QList>
29 
30 #include "monitorinfo.h"
31 
32 template <typename T> using ScopedCPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
33 
34 class XRandrBrightness
35 {
36 public:
37     XRandrBrightness();
38     ~XRandrBrightness() = default;
39 
40     QList<MonitorInfo> getMonitorsInfo();
41     void setMonitorsSettings(QList<MonitorInfo> monitors);
42 
43 private:
44     bool backlight_get_with_range(xcb_randr_output_t output, long &value, long &min, long &max) const;
45     long backlight_get(xcb_randr_output_t output) const;
46     void backlight_set(xcb_randr_output_t output, long value);
47     float gamma_brightness_get(xcb_randr_output_t output);
48     void gamma_brightness_set(xcb_randr_output_t output, float percent);
49 
50     xcb_atom_t m_backlight = XCB_ATOM_NONE;
51     ScopedCPointer<xcb_randr_get_screen_resources_current_reply_t> m_resources;
52 
53 };
54 
55 #endif // XRANDRBRIGHTNESS_H
56 
57