1 //===========================================
2 //  Lumina-DE source code
3 //  Copyright (c) 2017, Ken Moore
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 //  This class governs all the xcb/randr interactions
8 //  and provides simpler Qt-based functions for use elsewhere
9 //===========================================
10 #ifndef _LUMINA_LIBRARY_RANDR_MONITORS_H
11 #define _LUMINA_LIBRARY_RANDR_MONITORS_H
12 
13 //Qt includes
14 #include <QSize>
15 #include <QString>
16 #include <QPoint>
17 #include <QRect>
18 #include <QList>
19 #include <QObject>
20 #include <QDebug>
21 #include <QX11Info>
22 
23 // XCB
24 #include "xcb/randr.h"
25 #include "xcb/xcb_atom.h"
26 
27 struct p_objects{
28 	xcb_randr_output_t output; //This is the index used to identify particular monitors (unique ID)
29 	xcb_randr_crtc_t crtc; //This is the index used for the current settings/configuration (associated with output)
30 
31 	//Cached Information
32 	bool primary;
33 	QRect geometry;
34 
35 	QSize physicalSizeMM; //physical size of the display in MM
36 	QString name;
37 
38 	xcb_randr_mode_t current_mode;
39 	QList<xcb_randr_mode_t> modes; //each mode is a combination of resolution + refresh rate
40 	QList<QSize> resolutions; //smaller subset of modes - just unique resolutions
41 
42 };
43 
44 class OutputDevice{
45 public:
46 
47   // EXPANSIONS TO-DO
48   //Refresh Rate
49   //int cHz; //current refresh rate
50   //QList<int> availHz; //available refresh rates
51   //Expand this later to include:
52   // panning (current/possible)
53   // rotation (current/possible)
54 
55 	//Global Listing of Devices
56 	static QList<OutputDevice> availableMonitors();
57 
58 	//FUNCTIONS (do not use directly - use the static list function instead)
59 	OutputDevice(QString id);
60 	~OutputDevice();
61 
62 	//Information
63 	QString ID();
64 
65 	bool isEnabled();
66 	bool isPrimary();
67 	bool isConnected();
68 	QList<QSize> availableResolutions();
69 	QSize currentResolution(); //could be different from geometry.size() if things like panning/rotation are enabled
70 	QRect currentGeometry();
71 	QSize physicalSizeMM();
72 	QSize physicalDPI();
73 
74 	//Modification
75 	bool setAsPrimary(bool);
76 	bool disable();
77 	bool enable(QRect geom); //if empty resolution is supplied (QSize(0,0)) it will use the highest-available resolution
78 	bool changeResolution(QSize); //change the resolution (but not position) of a currently-enabled screen
79 	bool move(QPoint); //move a currently-enabled screen to another place
80 	bool setGeometry(QRect); //move/resize a currently-enabled screen
81 
82 	void updateInfoCache(); //Run this after all modification functions to refresh the current info for this device
83 
84 	//Now define a simple public_objects class so that each implementation
85 	//  has a storage container for placing semi-private objects as needed
86 	//class p_objects; //forward declaration - defined in the .cpp file
87 	p_objects p_obj;
88 };
89 
90 class OutputDeviceList{
91 private:
92 	QList<OutputDevice> out_devs;
93 
94 public:
95 	OutputDeviceList();
96 	~OutputDeviceList();
97 
length()98 	int length(){ return out_devs.length(); }
99 
at(int i)100 	OutputDevice* at(int i){
101 	  if(i<out_devs.length()){ return &out_devs[i]; }
102            return 0;
103 	}
104 
105 	//Simplification functions for dealing with multiple monitors
106 	void setPrimaryMonitor(QString id);
107 	QString primaryMonitor();
108 
109 	bool disableMonitor(QString id);
110 	bool enableMonitor(QString id, QRect geom);
111 
112 };
113 #endif
114