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

krandr

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

krandr

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

krandr

Skip menu "krandr"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for krandr by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |