summaryrefslogtreecommitdiffstats
path: root/src/x.h
blob: 50008c40d415ded5b9eff21472cba88f0caf7b71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef XRANDR_H
#define XRANDR_H

#include <QDebug>
#include <QList>
#include <QHash>
#include <QString>
#include <QRect>
#include <QSet>
#include <QSize>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>

struct OutputInfo;


///////////////////////////////////////////////////////////////////////////

enum class ScreenMode
{
	Single,
	Clone,
	Dual,
	Advanced,
};

class ScreenSetup
{
public:

	typedef QHash<RRMode, XRRModeInfo*>       ModeMap;
	typedef QHash<RRCrtc, XRRCrtcInfo*>       CrtcMap;
	typedef QHash<RROutput, OutputInfo*>      OutputMap;
	typedef QVector<QSize>                    ResolutionVector;

	void         updateScreenResources();
	bool         applyChanges();
	void         initModes();
	XRRModeInfo* getPreferredMode(OutputInfo *oi) const;
	QList<QSize> getTotalSize(const QList<OutputInfo*> &projectors, const QList<OutputInfo*> &screens) const;
	void         setOutputResolution(OutputInfo *oi, int x, int y, const QSize &size, bool dryRun = false);
	ScreenMode   getCurrentMode();
	ScreenMode   setDefaultMode(bool dryRun = false);
	void         copyModesToAll(RROutput id, int num);
	RRMode       getOutputModeForResolution(const XRROutputInfo *output, unsigned int width, unsigned int height) const;
	bool         createMode(unsigned int resX, unsigned int resY, float refresh, QString name);
	void         revertChanges();
	QList<QPair<quint32, quint32>> getCommonModes() const;
	int getOutputCount() const { return _outputMap.size(); }
	QHash<QString, int> getScreenPositions() const;
	const ResolutionVector &getVirtualResolutions() const { return _resolutions; }

	// Singleton
	inline static ScreenSetup*             inst() {
		if (_instance == nullptr) _instance = new ScreenSetup();
		return _instance;
	}

private:
	ScreenSetup();
	~ScreenSetup();

	void         freeResources();
	bool         readEdid(OutputInfo* output);

	static ScreenSetup *     _instance;
	Display*            _display;
	Atom                _EDID_ATOM;
	XRRScreenResources* _screenResources;
	ModeMap             _modeMap;
	CrtcMap             _crtcMap;
	OutputMap           _outputMap;
	ResolutionVector    _resolutions;
};

///////////////////////////////////////////////////////////////////////////

#endif // XRANDR_H