summaryrefslogtreecommitdiffstats
path: root/tderandr/randr.h
blob: eb77b03aaffe66b9ebe4e90defe79e3e31403283 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * Copyright (c) 2002,2003 Hamish Rodda <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __RANDR_H__
#define __RANDR_H__

#include <tqobject.h>
#include <tqstringlist.h>
#include <tqptrlist.h>

#include <tdecmodule.h>
#include <tdeconfig.h>

class KTimerDialog;
class RandRScreenPrivate;

class KRANDR_EXPORT HotPlugRule {
	public:
		enum states {
			AnyState		= 0,
			Connected		= 1,
			Disconnected		= 2
		};

	public:
		HotPlugRule();
		virtual ~HotPlugRule();

	public:
		TQStringList outputs;
		TQValueList< int > states;
		TQString profileName;
};

typedef TQValueList< HotPlugRule > HotPlugRulesList;

class KRANDR_EXPORT SingleScreenData {
	public:
		SingleScreenData();
		virtual ~SingleScreenData();
	
	public:
		TQString screenUniqueName;
		TQString screenFriendlyName;
		bool generic_screen_detected;
		bool screen_connected;
	
		TQStringList resolutions;
		TQStringList refresh_rates;
		TQStringList color_depths;
		TQStringList rotations;
	
		int current_resolution_index;
		int current_refresh_rate_index;
		int current_color_depth_index;
	
		float gamma_red;
		float gamma_green;
		float gamma_blue;
	
		int current_rotation_index;
		int current_orientation_mask;
		bool has_x_flip;
		bool has_y_flip;
		bool supports_transformations;
	
		bool is_primary;
		bool is_extended;
		int absolute_x_position;
		int absolute_y_position;
		int current_x_pixel_count;
		int current_y_pixel_count;
	
		bool has_dpms;
		bool enable_dpms;
		unsigned int dpms_standby_delay;
		unsigned int dpms_suspend_delay;
		unsigned int dpms_off_delay;
};

class RandRScreen : public TQObject
{
	Q_OBJECT

public:
	enum orientations {
		Rotate0			= 0x1,
		Rotate90		= 0x2,
		Rotate180		= 0x4,
		Rotate270		= 0x8,
		RotateMask		= 15,
		RotationCount	= 4,
		ReflectX		= 0x10,
		ReflectY		= 0x20,
		ReflectMask		= 48,
		OrientationMask	= 63,
		OrientationCount = 6
	};

	RandRScreen(int screenIndex);
	~RandRScreen();

	void		loadSettings();
	void		setOriginal();

	bool		applyProposed();

	/**
	 * @returns false if the user did not confirm in time, or cancelled, or the change failed
	 */
	bool		applyProposedAndConfirm();

public slots:
	bool		confirm();
	bool		showTestConfigurationDialog();

public:
	TQString		changedMessage() const;

	bool		changedFromOriginal() const;
	void		proposeOriginal();

	bool		proposedChanged() const;

	static TQString	rotationName(int rotation, bool pastTense = false, bool capitalised = true);
	TQPixmap	        rotationIcon(int rotation) const;
	TQString			currentRotationDescription() const;

	int				rotationIndexToDegree(int rotation) const;
	int				rotationDegreeToIndex(int degree) const;

	/**
	 * Refresh rate functions.
	 */
	TQStringList refreshRates(int size) const;

	TQString		refreshRateDirectDescription(int rate) const;
	TQString		refreshRateIndirectDescription(int size, int index) const;
	TQString		refreshRateDescription(int size, int index) const;

	int			currentRefreshRate() const;
	TQString		currentRefreshRateDescription() const;

	// Refresh rate hz <==> index conversion
	int			refreshRateHzToIndex(int size, int hz) const;
	int			refreshRateIndexToHz(int size, int index) const;

	/**
	 * Screen size functions.
	 */
	int				numSizes() const;
	const TQSize&	pixelSize(int index) const;
	const TQSize&	mmSize(int index) const;
	int				pixelCount(int index) const;

	/**
	 * Retrieve the index of a screen size with a specified pixel size.
	 *
	 * @param pixelSize dimensions of the screen in pixels
	 * @returns the index of the requested screen size
	 */
	int				sizeIndex(TQSize pixelSize) const;

	int			rotations() const;

	/**
	 * Current setting functions.
	 */
	int			currentPixelWidth() const;
	int			currentPixelHeight() const;
	int			currentMMWidth() const;
	int			currentMMHeight() const;

	int			currentRotation() const;
	int			currentSize() const;

	/**
	 * Proposed setting functions.
	 */
	int			proposedSize() const;
	bool		proposeSize(int newSize);

	int			proposedRotation() const;
	void		proposeRotation(int newRotation);

	int			proposedRefreshRate() const;
	/**
	 * Propose a refresh rate.
	 * Please note that you must propose the target size first for this to work.
	 *
	 * @param index the index of the refresh rate (not a refresh rate in hz!)
	 * @returns true if successful, false otherwise.
	 */
	bool		proposeRefreshRate(int index);

	/**
	 * Configuration functions.
	 */
	void		load(TDEConfig& config);
	void		save(TDEConfig& config) const;

private:
	RandRScreenPrivate*	d;

	int			m_screen;

	TQValueList<TQSize>	m_pixelSizes;
	TQValueList<TQSize>	m_mmSizes;
	int					m_rotations;

	int			m_originalRotation;
	int			m_originalSize;
	int			m_originalRefreshRate;

	int			m_currentRotation;
	int			m_currentSize;
	int			m_currentRefreshRate;

	int			m_proposedRotation;
	int			m_proposedSize;
	int			m_proposedRefreshRate;

	KTimerDialog*	m_shownDialog;

private slots:
	void		desktopResized();
	void		shownDialogDestroyed();
};

typedef TQPtrList<RandRScreen> ScreenList;

class RandRDisplay
{
public:
	RandRDisplay();

	bool			isValid() const;
	const TQString&	errorCode() const;
	const TQString&	version() const;

	int		eventBase() const;
	int		screenChangeNotifyEvent() const;
	int		errorBase() const;

	int		screenIndexOfWidget(TQWidget* widget);

	int				numScreens() const;
	RandRScreen*	screen(int index);

	void			setCurrentScreen(int index);
	int				currentScreenIndex() const;
	RandRScreen*	currentScreen();

	void	refresh();

	/**
	 * Loads saved settings.
	 *
	 * @param config the TDEConfig object to load from
	 * @param loadScreens whether to call RandRScreen::load() for each screen
	 * @retuns true if the settings should be applied on KDE startup.
	 */
	bool	loadDisplay(TDEConfig& config, bool loadScreens = true);
	void	saveDisplay(TDEConfig& config, bool applyOnStartup, bool syncTrayApp);

	static bool		applyOnStartup(TDEConfig& config);
	static bool		syncTrayApp(TDEConfig& config);

	void	applyProposed(bool confirm = true);

	bool showTestConfigurationDialog();

private:
	int				m_numScreens;
	int				m_currentScreenIndex;
	RandRScreen*	m_currentScreen;
	ScreenList		m_screens;

	bool			m_valid;
	QString			m_errorCode;
	QString			m_version;

	int				m_eventBase;
	int				m_errorBase;
};

#endif