• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tderandr
 

tderandr

  • tderandr
randr.cpp
1/*
2 * Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "randr.h"
20#include "lowlevel_randr.h"
21
22#include <tqtimer.h>
23
24#include <kdebug.h>
25#include <tdelocale.h>
26#include <tdeglobal.h>
27#include <tdeapplication.h>
28#include <kiconloader.h>
29#include <dcopclient.h>
30#include <kipc.h>
31#include <kactivelabel.h>
32
33#include "ktimerdialog.h"
34
35#include <X11/Xlib.h>
36#define INT8 _X11INT8
37#define INT32 _X11INT32
38#include <X11/Xproto.h>
39#undef INT8
40#undef INT32
41#include <X11/extensions/Xrandr.h>
42
43HotPlugRule::HotPlugRule()
44{
45 //
46}
47
48HotPlugRule::~HotPlugRule()
49{
50 //
51}
52
53SingleScreenData::SingleScreenData()
54{
55 generic_screen_detected = false;
56 screen_connected = false;
57
58 current_resolution_index = 0;
59 current_refresh_rate_index = 0;
60 current_color_depth_index = 0;
61
62 gamma_red = 0.0;
63 gamma_green = 0.0;
64 gamma_blue = 0.0;
65
66 current_rotation_index = ROTATION_0_DEGREES_INDEX;
67 current_orientation_mask = 0;
68 has_x_flip = false;
69 has_y_flip = false;
70 supports_transformations = false;
71
72 is_primary = false;
73 is_extended = false;
74 absolute_x_position = 0;
75 absolute_y_position = 0;
76 current_x_pixel_count = 0;
77 current_y_pixel_count = 0;
78
79 has_dpms = false;
80 enable_dpms = false;
81 dpms_standby_delay = 0;
82 dpms_suspend_delay = 0;
83 dpms_off_delay = 0;
84}
85
86SingleScreenData::~SingleScreenData()
87{
88 //
89}
90
91class RandRScreenPrivate
92{
93public:
94 RandRScreenPrivate() : config(0L) {};
95 ~RandRScreenPrivate()
96 {
97 if (config) {
98 XRRFreeScreenConfigInfo(config);
99 }
100 }
101
102 XRRScreenConfiguration* config;
103};
104
105TDE_EXPORT RandRScreen::RandRScreen(int screenIndex)
106 : d(new RandRScreenPrivate())
107 , m_screen(screenIndex)
108 , m_shownDialog(NULL)
109{
110 loadSettings();
111 setOriginal();
112}
113
114TDE_EXPORT RandRScreen::~RandRScreen()
115{
116 delete d;
117}
118
119TDE_EXPORT void RandRScreen::loadSettings()
120{
121 if (d->config) {
122 XRRFreeScreenConfigInfo(d->config);
123 }
124
125 d->config = XRRGetScreenInfo(tqt_xdisplay(), RootWindow(tqt_xdisplay(), m_screen));
126
127 Rotation rotation;
128 if (d->config) {
129 m_currentSize = m_proposedSize = XRRConfigCurrentConfiguration(d->config, &rotation);
130 m_currentRotation = m_proposedRotation = rotation;
131 }
132 else {
133 m_currentSize = m_proposedSize = 0;
134 m_currentRotation = m_proposedRotation = 0;
135 }
136
137 m_pixelSizes.clear();
138 m_mmSizes.clear();
139
140 if (d->config) {
141 int numSizes;
142 XRRScreenSize* sizes = XRRSizes(tqt_xdisplay(), m_screen, &numSizes);
143 for (int i = 0; i < numSizes; i++) {
144 m_pixelSizes.append(TQSize(sizes[i].width, sizes[i].height));
145 m_mmSizes.append(TQSize(sizes[i].mwidth, sizes[i].mheight));
146 }
147
148 m_rotations = XRRRotations(tqt_xdisplay(), m_screen, &rotation);
149 }
150 else {
151 // Great, now we have to go after the information manually. Ughh.
152 ScreenInfo *screeninfo = internal_read_screen_info(tqt_xdisplay());
153 XRROutputInfo *output_info = screeninfo->outputs[m_screen]->info;
154 CrtcInfo *current_crtc = screeninfo->outputs[m_screen]->cur_crtc;
155 int numSizes = output_info->nmode;
156 for (int i = 0; i < numSizes; i++) {
157 XRRModeInfo *xrrmode;
158 xrrmode = internal_find_mode_by_xid (screeninfo, output_info->modes[i]);
159 TQSize newSize = TQSize(xrrmode->width, xrrmode->height);
160 if (!m_pixelSizes.contains(newSize)) {
161 m_pixelSizes.append(newSize);
162 m_mmSizes.append(TQSize(output_info->mm_width, output_info->mm_height));
163 }
164 }
165 if (current_crtc) {
166 m_rotations = current_crtc->rotations;
167 m_currentRotation = m_proposedRotation = current_crtc->cur_rotation;
168 }
169 }
170
171 if (d->config) {
172 m_currentRefreshRate = m_proposedRefreshRate = refreshRateHzToIndex(m_currentSize, XRRConfigCurrentRate(d->config));
173 }
174 else {
175 m_currentRefreshRate = m_proposedRefreshRate = 0;
176 }
177}
178
179TDE_EXPORT void RandRScreen::setOriginal()
180{
181 m_originalSize = m_currentSize;
182 m_originalRotation = m_currentRotation;
183 m_originalRefreshRate = m_currentRefreshRate;
184}
185
186TDE_EXPORT bool RandRScreen::applyProposed()
187{
188 //kdDebug() << k_funcinfo << " size " << (SizeID)proposedSize() << ", rotation " << proposedRotation() << ", refresh " << refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) << endl;
189
190 Status status;
191
192 if (!d->config) {
193 d->config = XRRGetScreenInfo(tqt_xdisplay(), RootWindow(tqt_xdisplay(), m_screen));
194 Q_ASSERT(d->config);
195 }
196
197 if (d->config) {
198 if (proposedRefreshRate() < 0)
199 status = XRRSetScreenConfig(tqt_xdisplay(), d->config, DefaultRootWindow(tqt_xdisplay()), (SizeID)proposedSize(), (Rotation)proposedRotation(), CurrentTime);
200 else {
201 if( refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) <= 0 ) {
202 m_proposedRefreshRate = 0;
203 }
204 status = XRRSetScreenConfigAndRate(tqt_xdisplay(), d->config, DefaultRootWindow(tqt_xdisplay()), (SizeID)proposedSize(), (Rotation)proposedRotation(), refreshRateIndexToHz(proposedSize(), proposedRefreshRate()), CurrentTime);
205 }
206 }
207 else {
208 // Great, now we have to set the information manually. Ughh.
209 // FIXME--this does not work!
210 ScreenInfo *screeninfo = internal_read_screen_info(tqt_xdisplay());
211 screeninfo->cur_width = (*m_pixelSizes.at(proposedSize())).width();
212 screeninfo->cur_height = (*m_pixelSizes.at(proposedSize())).height();
213 internal_main_low_apply(screeninfo);
214
215 status = RRSetConfigSuccess;
216 }
217
218 //kdDebug() << "New size: " << WidthOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), screen)) << ", " << HeightOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), screen)) << endl;
219
220 if (status == RRSetConfigSuccess) {
221 m_currentSize = m_proposedSize;
222 m_currentRotation = m_proposedRotation;
223 m_currentRefreshRate = m_proposedRefreshRate;
224 return true;
225 }
226
227 return false;
228}
229
230TDE_EXPORT bool RandRScreen::applyProposedAndConfirm()
231{
232 if (proposedChanged()) {
233 setOriginal();
234
235 if (applyProposed()) {
236 if (!confirm()) {
237 proposeOriginal();
238 applyProposed();
239 return false;
240 }
241 } else {
242 return false;
243 }
244 }
245
246 return true;
247}
248
249TDE_EXPORT bool RandRScreen::confirm()
250{
251 // uncomment the line below and edit out the KTimerDialog stuff to get
252 // a version which works on today's tdelibs (no accept dialog is presented)
253
254 // FIXME remember to put the dialog on the right screen
255
256 KTimerDialog acceptDialog ( 15000, KTimerDialog::CountDown,
257 tdeApp->mainWidget(),
258 "mainKTimerDialog",
259 true,
260 i18n("Confirm Display Setting Change"),
261 KTimerDialog::Ok|KTimerDialog::Cancel,
262 KTimerDialog::Cancel);
263
264 acceptDialog.setButtonOK(KGuiItem(i18n("&Accept Configuration"), "button_ok"));
265 acceptDialog.setButtonCancel(KGuiItem(i18n("&Return to Previous Configuration"), "button_cancel"));
266
267 KActiveLabel *label = new KActiveLabel(i18n("Your screen orientation, size and refresh rate "
268 "have been changed to the requested settings. Please indicate whether you wish to "
269 "keep this configuration. In 15 seconds the display will revert to your previous "
270 "settings."), &acceptDialog, "userSpecifiedLabel");
271
272 acceptDialog.setMainWidget(label);
273
274 KDialog::centerOnScreen(&acceptDialog, m_screen);
275
276 m_shownDialog = &acceptDialog;
277 connect( m_shownDialog, TQ_SIGNAL( destroyed()), this, TQ_SLOT( shownDialogDestroyed()));
278 connect( tdeApp->desktop(), TQ_SIGNAL( resized(int)), this, TQ_SLOT( desktopResized()));
279
280 return acceptDialog.exec();
281}
282
283TDE_EXPORT void RandRScreen::shownDialogDestroyed()
284{
285 m_shownDialog = NULL;
286 disconnect( tdeApp->desktop(), TQ_SIGNAL( resized(int)), this, TQ_SLOT( desktopResized()));
287}
288
289TDE_EXPORT void RandRScreen::desktopResized()
290{
291 if( m_shownDialog != NULL )
292 KDialog::centerOnScreen(m_shownDialog, m_screen);
293}
294
295TDE_EXPORT TQString RandRScreen::changedMessage() const
296{
297 if (currentRefreshRate() == -1)
298 return i18n("New configuration:\nResolution: %1 x %2\nOrientation: %3")
299 .arg(currentPixelWidth())
300 .arg(currentPixelHeight())
301 .arg(currentRotationDescription());
302 else
303 return i18n("New configuration:\nResolution: %1 x %2\nOrientation: %3\nRefresh rate: %4")
304 .arg(currentPixelWidth())
305 .arg(currentPixelHeight())
306 .arg(currentRotationDescription())
307 .arg(currentRefreshRateDescription());
308}
309
310TDE_EXPORT bool RandRScreen::changedFromOriginal() const
311{
312 return m_currentSize != m_originalSize || m_currentRotation != m_originalRotation || m_currentRefreshRate != m_originalRefreshRate;
313}
314
315TDE_EXPORT void RandRScreen::proposeOriginal()
316{
317 m_proposedSize = m_originalSize;
318 m_proposedRotation = m_originalRotation;
319 m_proposedRefreshRate = m_originalRefreshRate;
320}
321
322TDE_EXPORT bool RandRScreen::proposedChanged() const
323{
324 return m_currentSize != m_proposedSize || m_currentRotation != m_proposedRotation || m_currentRefreshRate != m_proposedRefreshRate;
325}
326
327TDE_EXPORT TQString RandRScreen::rotationName(int rotation, bool pastTense, bool capitalised)
328{
329 if (!pastTense)
330 switch (rotation) {
331 case RR_Rotate_0:
332 return i18n("Normal");
333 case RR_Rotate_90:
334 return i18n("Left (90 degrees)");
335 case RR_Rotate_180:
336 return i18n("Upside-down (180 degrees)");
337 case RR_Rotate_270:
338 return i18n("Right (270 degrees)");
339 case RR_Reflect_X:
340 return i18n("Mirror horizontally");
341 case RR_Reflect_Y:
342 return i18n("Mirror vertically");
343 default:
344 return i18n("Unknown orientation");
345 }
346
347 switch (rotation) {
348 case RR_Rotate_0:
349 return i18n("Normal");
350 case RR_Rotate_90:
351 return i18n("Rotated 90 degrees counterclockwise");
352 case RR_Rotate_180:
353 return i18n("Rotated 180 degrees counterclockwise");
354 case RR_Rotate_270:
355 return i18n("Rotated 270 degrees counterclockwise");
356 default:
357 if (rotation & RR_Reflect_X)
358 if (rotation & RR_Reflect_Y)
359 if (capitalised)
360 return i18n("Mirrored horizontally and vertically");
361 else
362 return i18n("mirrored horizontally and vertically");
363 else
364 if (capitalised)
365 return i18n("Mirrored horizontally");
366 else
367 return i18n("mirrored horizontally");
368 else if (rotation & RR_Reflect_Y)
369 if (capitalised)
370 return i18n("Mirrored vertically");
371 else
372 return i18n("mirrored vertically");
373 else
374 if (capitalised)
375 return i18n("Unknown orientation");
376 else
377 return i18n("unknown orientation");
378 }
379}
380
381TDE_EXPORT TQPixmap RandRScreen::rotationIcon(int rotation) const
382{
383 // Adjust icons for current screen orientation
384 if (!(m_currentRotation & RR_Rotate_0) && rotation & (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)) {
385 int currentAngle = m_currentRotation & (RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270);
386 switch (currentAngle) {
387 case RR_Rotate_90:
388 rotation <<= 3;
389 break;
390 case RR_Rotate_180:
391 rotation <<= 2;
392 break;
393 case RR_Rotate_270:
394 rotation <<= 1;
395 break;
396 }
397
398 // Fix overflow
399 if (rotation > RR_Rotate_270) {
400 rotation >>= 4;
401 }
402 }
403
404 switch (rotation) {
405 case RR_Rotate_0:
406 return SmallIcon("go-up");
407 case RR_Rotate_90:
408 return SmallIcon("back");
409 case RR_Rotate_180:
410 return SmallIcon("go-down");
411 case RR_Rotate_270:
412 return SmallIcon("forward");
413 case RR_Reflect_X:
414 case RR_Reflect_Y:
415 default:
416 return SmallIcon("process-stop");
417 }
418}
419
420TDE_EXPORT TQString RandRScreen::currentRotationDescription() const
421{
422 TQString ret = rotationName(m_currentRotation & RotateMask);
423
424 if (m_currentRotation != (m_currentRotation & RotateMask)) {
425 if (m_currentRotation & RR_Rotate_0) {
426 ret = rotationName(m_currentRotation & (RR_Reflect_X + RR_Reflect_X), true, true);
427 }
428 else {
429 ret += ", " + rotationName(m_currentRotation & (RR_Reflect_X + RR_Reflect_X), true, false);
430 }
431 }
432
433 return ret;
434}
435
436TDE_EXPORT int RandRScreen::rotationIndexToDegree(int rotation) const
437{
438 switch (rotation & RotateMask) {
439 case RR_Rotate_90:
440 return 90;
441
442 case RR_Rotate_180:
443 return 180;
444
445 case RR_Rotate_270:
446 return 270;
447
448 default:
449 return 0;
450 }
451}
452
453TDE_EXPORT int RandRScreen::rotationDegreeToIndex(int degree) const
454{
455 switch (degree) {
456 case 90:
457 return RR_Rotate_90;
458
459 case 180:
460 return RR_Rotate_180;
461
462 case 270:
463 return RR_Rotate_270;
464
465 default:
466 return RR_Rotate_0;
467 }
468}
469
470TDE_EXPORT int RandRScreen::currentPixelWidth() const
471{
472 return m_pixelSizes[m_currentSize].width();
473}
474
475TDE_EXPORT int RandRScreen::currentPixelHeight() const
476{
477 return m_pixelSizes[m_currentSize].height();
478}
479
480TDE_EXPORT int RandRScreen::currentMMWidth() const
481{
482 return m_pixelSizes[m_currentSize].width();
483}
484
485TDE_EXPORT int RandRScreen::currentMMHeight() const
486{
487 return m_pixelSizes[m_currentSize].height();
488}
489
490TDE_EXPORT TQStringList RandRScreen::refreshRates(int size) const
491{
492 int nrates;
493 TQStringList ret;
494
495 if (d->config) {
496 short* rates = XRRRates(tqt_xdisplay(), m_screen, (SizeID)size, &nrates);
497
498 for (int i = 0; i < nrates; i++)
499 ret << refreshRateDirectDescription(rates[i]);
500 }
501 else {
502 // Great, now we have to go after the information manually. Ughh.
503 ScreenInfo *screeninfo = internal_read_screen_info(tqt_xdisplay());
504 int numSizes = screeninfo->res->nmode;
505 for (int i = 0; i < numSizes; i++) {
506 int refresh_rate = ((screeninfo->res->modes[i].dotClock*1.0)/((screeninfo->res->modes[i].hTotal)*(screeninfo->res->modes[i].vTotal)*1.0));
507 TQString newRate = refreshRateDirectDescription(refresh_rate);
508 if (!ret.contains(newRate)) {
509 ret.append(newRate);
510 }
511 }
512 }
513
514 return ret;
515}
516
517TDE_EXPORT TQString RandRScreen::refreshRateDirectDescription(int rate) const
518{
519 return i18n("Refresh rate in Hertz (Hz)", "%1 Hz").arg(rate);
520}
521
522TDE_EXPORT TQString RandRScreen::refreshRateIndirectDescription(int size, int index) const
523{
524 return i18n("Refresh rate in Hertz (Hz)", "%1 Hz").arg(refreshRateIndexToHz(size, index));
525}
526
527TDE_EXPORT TQString RandRScreen::refreshRateDescription(int size, int index) const
528{
529 return refreshRates(size)[index];
530}
531
532TDE_EXPORT bool RandRScreen::proposeRefreshRate(int index)
533{
534 if (index >= 0 && (int)refreshRates(proposedSize()).count() > index) {
535 m_proposedRefreshRate = index;
536 return true;
537 }
538
539 return false;
540}
541
542TDE_EXPORT int RandRScreen::currentRefreshRate() const
543{
544 return m_currentRefreshRate;
545}
546
547TDE_EXPORT TQString RandRScreen::currentRefreshRateDescription() const
548{
549 return refreshRateIndirectDescription(m_currentSize, m_currentRefreshRate);
550}
551
552TDE_EXPORT int RandRScreen::proposedRefreshRate() const
553{
554 return m_proposedRefreshRate;
555}
556
557TDE_EXPORT int RandRScreen::refreshRateHzToIndex(int size, int hz) const
558{
559 int nrates;
560 short* rates = XRRRates(tqt_xdisplay(), m_screen, (SizeID)size, &nrates);
561
562 for (int i = 0; i < nrates; i++)
563 if (hz == rates[i])
564 return i;
565
566 if (nrates != 0)
567 // Wrong input Hz!
568 Q_ASSERT(false);
569
570 return -1;
571}
572
573TDE_EXPORT int RandRScreen::refreshRateIndexToHz(int size, int index) const
574{
575 int nrates;
576 short* rates = XRRRates(tqt_xdisplay(), m_screen, (SizeID)size, &nrates);
577
578 if (nrates == 0 || index < 0)
579 return 0;
580
581 // Wrong input Hz!
582 if(index >= nrates)
583 return 0;
584
585 return rates[index];
586}
587
588TDE_EXPORT int RandRScreen::numSizes() const
589{
590 return m_pixelSizes.count();
591}
592
593TDE_EXPORT const TQSize& RandRScreen::pixelSize(int index) const
594{
595 return m_pixelSizes[index];
596}
597
598TDE_EXPORT const TQSize& RandRScreen::mmSize(int index) const
599{
600 return m_mmSizes[index];
601}
602
603TDE_EXPORT int RandRScreen::sizeIndex(TQSize pixelSize) const
604{
605 for (uint i = 0; i < m_pixelSizes.count(); i++)
606 if (m_pixelSizes[i] == pixelSize)
607 return i;
608
609 return -1;
610}
611
612TDE_EXPORT int RandRScreen::rotations() const
613{
614 return m_rotations;
615}
616
617TDE_EXPORT int RandRScreen::currentRotation() const
618{
619 return m_currentRotation;
620}
621
622TDE_EXPORT int RandRScreen::currentSize() const
623{
624 return m_currentSize;
625}
626
627TDE_EXPORT int RandRScreen::proposedRotation() const
628{
629 return m_proposedRotation;
630}
631
632TDE_EXPORT void RandRScreen::proposeRotation(int newRotation)
633{
634 m_proposedRotation = newRotation & OrientationMask;
635}
636
637TDE_EXPORT int RandRScreen::proposedSize() const
638{
639 return m_proposedSize;
640}
641
642TDE_EXPORT bool RandRScreen::proposeSize(int newSize)
643{
644 if ((int)m_pixelSizes.count() > newSize) {
645 m_proposedSize = newSize;
646 return true;
647 }
648
649 return false;
650}
651
652TDE_EXPORT void RandRScreen::load(TDEConfig& config)
653{
654 config.setGroup(TQString("Screen%1").arg(m_screen));
655
656 if (proposeSize(sizeIndex(TQSize(config.readNumEntry("width", currentPixelWidth()), config.readNumEntry("height", currentPixelHeight())))))
657 proposeRefreshRate(refreshRateHzToIndex(proposedSize(), config.readNumEntry("refresh", currentRefreshRate())));
658
659 proposeRotation(rotationDegreeToIndex(config.readNumEntry("rotation", 0)) + (config.readBoolEntry("reflectX") ? ReflectX : 0) + (config.readBoolEntry("reflectY") ? ReflectY : 0));
660}
661
662TDE_EXPORT void RandRScreen::save(TDEConfig& config) const
663{
664 config.setGroup(TQString("Screen%1").arg(m_screen));
665 config.writeEntry("width", currentPixelWidth());
666 config.writeEntry("height", currentPixelHeight());
667 config.writeEntry("refresh", refreshRateIndexToHz(currentSize(), currentRefreshRate()));
668 config.writeEntry("rotation", rotationIndexToDegree(currentRotation()));
669 config.writeEntry("reflectX", (bool)(currentRotation() & ReflectMask) == ReflectX);
670 config.writeEntry("reflectY", (bool)(currentRotation() & ReflectMask) == ReflectY);
671}
672
673TDE_EXPORT RandRDisplay::RandRDisplay()
674 : m_valid(true)
675{
676 // Check extension
677 Status s = XRRQueryExtension(tqt_xdisplay(), &m_eventBase, &m_errorBase);
678 if (!s) {
679 m_errorCode = TQString("%1, base %1").arg(s).arg(m_errorBase);
680 m_valid = false;
681 return;
682 }
683
684 // Sometimes the extension is available but does not return any screens (!)
685 // Check for that case
686 Display *randr_display = XOpenDisplay(NULL);
687 int screen_num;
688 Window root_window;
689
690 screen_num = DefaultScreen (randr_display);
691 root_window = RootWindow (randr_display, screen_num);
692 if (XRRGetScreenResources (randr_display, root_window) == NULL) {
693 m_errorCode = i18n("No screens detected");
694 m_valid = false;
695 return;
696 }
697
698 int major_version, minor_version;
699 XRRQueryVersion(tqt_xdisplay(), &major_version, &minor_version);
700
701 m_version = TQString("X Resize and Rotate extension version %1.%1").arg(major_version).arg(minor_version);
702
703 m_numScreens = ScreenCount(tqt_xdisplay());
704
705 // This assumption is WRONG with Xinerama
706 // Q_ASSERT(TQApplication::desktop()->numScreens() == ScreenCount(tqt_xdisplay()));
707
708 m_screens.setAutoDelete(true);
709 for (int i = 0; i < m_numScreens; i++) {
710 m_screens.append(new RandRScreen(i));
711 }
712
713 setCurrentScreen(TQApplication::desktop()->primaryScreen());
714}
715
716TDE_EXPORT bool RandRDisplay::isValid() const
717{
718 return m_valid;
719}
720
721TDE_EXPORT const TQString& RandRDisplay::errorCode() const
722{
723 return m_errorCode;
724}
725
726TDE_EXPORT int RandRDisplay::eventBase() const
727{
728 return m_eventBase;
729}
730
731TDE_EXPORT int RandRDisplay::screenChangeNotifyEvent() const
732{
733 return m_eventBase + RRScreenChangeNotify;
734}
735
736TDE_EXPORT int RandRDisplay::errorBase() const
737{
738 return m_errorBase;
739}
740
741TDE_EXPORT const TQString& RandRDisplay::version() const
742{
743 return m_version;
744}
745
746TDE_EXPORT void RandRDisplay::setCurrentScreen(int index)
747{
748 m_currentScreenIndex = index;
749 m_currentScreen = m_screens.at(m_currentScreenIndex);
750 Q_ASSERT(m_currentScreen);
751}
752
753TDE_EXPORT int RandRDisplay::screenIndexOfWidget(TQWidget* widget)
754{
755 int ret = TQApplication::desktop()->screenNumber(widget);
756 return ret != -1 ? ret : TQApplication::desktop()->primaryScreen();
757}
758
759TDE_EXPORT int RandRDisplay::currentScreenIndex() const
760{
761 return m_currentScreenIndex;
762}
763
764TDE_EXPORT void RandRDisplay::refresh()
765{
766 for (RandRScreen* s = m_screens.first(); s; s = m_screens.next())
767 s->loadSettings();
768}
769
770TDE_EXPORT int RandRDisplay::numScreens() const
771{
772 return m_numScreens;
773}
774
775TDE_EXPORT RandRScreen* RandRDisplay::screen(int index)
776{
777 return m_screens.at(index);
778}
779
780TDE_EXPORT RandRScreen* RandRDisplay::currentScreen()
781{
782 return m_currentScreen;
783}
784
785TDE_EXPORT bool RandRDisplay::loadDisplay(TDEConfig& config, bool loadScreens)
786{
787 if (loadScreens)
788 for (RandRScreen* s = m_screens.first(); s; s = m_screens.next())
789 s->load(config);
790
791 return applyOnStartup(config);
792}
793
794TDE_EXPORT bool RandRDisplay::applyOnStartup(TDEConfig& config)
795{
796 config.setGroup("Display");
797 return config.readBoolEntry("ApplyOnStartup", false);
798}
799
800TDE_EXPORT bool RandRDisplay::syncTrayApp(TDEConfig& config)
801{
802 config.setGroup("Display");
803 return config.readBoolEntry("SyncTrayApp", false);
804}
805
806TDE_EXPORT void RandRDisplay::saveDisplay(TDEConfig& config, bool applyOnStartup, bool syncTrayApp)
807{
808 Q_ASSERT(!config.isReadOnly());
809
810 config.setGroup("Display");
811 config.writeEntry("ApplyOnStartup", applyOnStartup);
812 config.writeEntry("SyncTrayApp", syncTrayApp);
813
814 for (RandRScreen* s = m_screens.first(); s; s = m_screens.next())
815 s->save(config);
816}
817
818TDE_EXPORT void RandRDisplay::applyProposed(bool confirm)
819{
820 for (int screenIndex = 0; screenIndex < numScreens(); screenIndex++) {
821 if (screen(screenIndex)->proposedChanged()) {
822 if (confirm)
823 screen(screenIndex)->applyProposedAndConfirm();
824 else
825 screen(screenIndex)->applyProposed();
826 }
827 }
828}
829
830TDE_EXPORT bool RandRDisplay::showTestConfigurationDialog()
831{
832 RandRScreen* firstScreen = screen(0);
833 if (firstScreen) {
834 return firstScreen->showTestConfigurationDialog();
835 }
836 else {
837 return false;
838 }
839}
840
841TDE_EXPORT bool RandRScreen::showTestConfigurationDialog()
842{
843 // uncomment the line below and edit out the KTimerDialog stuff to get
844 // a version which works on today's tdelibs (no accept dialog is presented)
845
846 // FIXME remember to put the dialog on the right screen
847
848 KTimerDialog acceptDialog ( 15000, KTimerDialog::CountDown,
849 tdeApp->mainWidget(),
850 "mainKTimerDialog",
851 true,
852 i18n("Confirm Display Settings"),
853 KTimerDialog::Ok|KTimerDialog::Cancel,
854 KTimerDialog::Cancel);
855
856 acceptDialog.setButtonOK(KGuiItem(i18n("&Accept Configuration"), "button_ok"));
857 acceptDialog.setButtonCancel(KGuiItem(i18n("&Return to Previous Configuration"), "button_cancel"));
858
859 KActiveLabel *label = new KActiveLabel(i18n("Your display devices has been configured "
860 "to match the settings shown above. Please indicate whether you wish to "
861 "keep this configuration. In 15 seconds the display will revert to your previous "
862 "settings."), &acceptDialog, "userSpecifiedLabel");
863
864 acceptDialog.setMainWidget(label);
865
866 KDialog::centerOnScreen(&acceptDialog, 0);
867
868 m_shownDialog = &acceptDialog;
869 connect( m_shownDialog, TQ_SIGNAL( destroyed()), this, TQ_SLOT( shownDialogDestroyed()));
870 connect( tdeApp->desktop(), TQ_SIGNAL( resized(int)), this, TQ_SLOT( desktopResized()));
871
872 return acceptDialog.exec();
873}
874
875TDE_EXPORT int RandRScreen::pixelCount( int index ) const
876{
877 TQSize sz = pixelSize(index);
878 return sz.width() * sz.height();
879}
880
881#include "randr.moc"
KTimerDialog
Provides a dialog that is only available for a specified amount of time, and reports the time remaini...
Definition: ktimerdialog.h:46
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
TDEConfigBase::isReadOnly
bool isReadOnly() const
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig
TDEStdAccel::label
TQString label(StdAccel id)
tdelocale.h

tderandr

Skip menu "tderandr"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tderandr

Skip menu "tderandr"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tderandr by doxygen 1.9.4
This website is maintained by Timothy Pearson.