• 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 KDE_EXPORT RandRScreen::RandRScreen(int screenIndex)
57  : d(new RandRScreenPrivate())
58  , m_screen(screenIndex)
59  , m_shownDialog(NULL)
60 {
61  loadSettings();
62  setOriginal();
63 }
64 
65 KDE_EXPORT RandRScreen::~RandRScreen()
66 {
67  delete d;
68 }
69 
70 KDE_EXPORT 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 KDE_EXPORT void RandRScreen::setOriginal()
128 {
129  m_originalSize = m_currentSize;
130  m_originalRotation = m_currentRotation;
131  m_originalRefreshRate = m_currentRefreshRate;
132 }
133 
134 KDE_EXPORT 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 KDE_EXPORT 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 KDE_EXPORT 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 KDE_EXPORT void RandRScreen::shownDialogDestroyed()
232 {
233  m_shownDialog = NULL;
234  disconnect( kapp->desktop(), TQT_SIGNAL( resized(int)), this, TQT_SLOT( desktopResized()));
235 }
236 
237 KDE_EXPORT void RandRScreen::desktopResized()
238 {
239  if( m_shownDialog != NULL )
240  KDialog::centerOnScreen(m_shownDialog, m_screen);
241 }
242 
243 KDE_EXPORT 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 KDE_EXPORT bool RandRScreen::changedFromOriginal() const
259 {
260  return m_currentSize != m_originalSize || m_currentRotation != m_originalRotation || m_currentRefreshRate != m_originalRefreshRate;
261 }
262 
263 KDE_EXPORT void RandRScreen::proposeOriginal()
264 {
265  m_proposedSize = m_originalSize;
266  m_proposedRotation = m_originalRotation;
267  m_proposedRefreshRate = m_originalRefreshRate;
268 }
269 
270 KDE_EXPORT bool RandRScreen::proposedChanged() const
271 {
272  return m_currentSize != m_proposedSize || m_currentRotation != m_proposedRotation || m_currentRefreshRate != m_proposedRefreshRate;
273 }
274 
275 KDE_EXPORT 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 KDE_EXPORT 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 KDE_EXPORT 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  }
376  else {
377  ret += ", " + rotationName(m_currentRotation & (RR_Reflect_X + RR_Reflect_X), true, false);
378  }
379  }
380 
381  return ret;
382 }
383 
384 KDE_EXPORT int RandRScreen::rotationIndexToDegree(int rotation) const
385 {
386  switch (rotation & RotateMask) {
387  case RR_Rotate_90:
388  return 90;
389 
390  case RR_Rotate_180:
391  return 180;
392 
393  case RR_Rotate_270:
394  return 270;
395 
396  default:
397  return 0;
398  }
399 }
400 
401 KDE_EXPORT int RandRScreen::rotationDegreeToIndex(int degree) const
402 {
403  switch (degree) {
404  case 90:
405  return RR_Rotate_90;
406 
407  case 180:
408  return RR_Rotate_180;
409 
410  case 270:
411  return RR_Rotate_270;
412 
413  default:
414  return RR_Rotate_0;
415  }
416 }
417 
418 KDE_EXPORT int RandRScreen::currentPixelWidth() const
419 {
420  return m_pixelSizes[m_currentSize].width();
421 }
422 
423 KDE_EXPORT int RandRScreen::currentPixelHeight() const
424 {
425  return m_pixelSizes[m_currentSize].height();
426 }
427 
428 KDE_EXPORT int RandRScreen::currentMMWidth() const
429 {
430  return m_pixelSizes[m_currentSize].width();
431 }
432 
433 KDE_EXPORT int RandRScreen::currentMMHeight() const
434 {
435  return m_pixelSizes[m_currentSize].height();
436 }
437 
438 KDE_EXPORT TQStringList RandRScreen::refreshRates(int size) const
439 {
440  int nrates;
441  TQStringList ret;
442 
443  if (d->config) {
444  short* rates = XRRRates(qt_xdisplay(), m_screen, (SizeID)size, &nrates);
445 
446  for (int i = 0; i < nrates; i++)
447  ret << refreshRateDirectDescription(rates[i]);
448  }
449  else {
450  // Great, now we have to go after the information manually. Ughh.
451  ScreenInfo *screeninfo = internal_read_screen_info(qt_xdisplay());
452  int numSizes = screeninfo->res->nmode;
453  for (int i = 0; i < numSizes; i++) {
454  int refresh_rate = ((screeninfo->res->modes[i].dotClock*1.0)/((screeninfo->res->modes[i].hTotal)*(screeninfo->res->modes[i].vTotal)*1.0));
455  TQString newRate = refreshRateDirectDescription(refresh_rate);
456  if (!ret.contains(newRate)) {
457  ret.append(newRate);
458  }
459  }
460  }
461 
462  return ret;
463 }
464 
465 KDE_EXPORT TQString RandRScreen::refreshRateDirectDescription(int rate) const
466 {
467  return i18n("Refresh rate in Hertz (Hz)", "%1 Hz").arg(rate);
468 }
469 
470 KDE_EXPORT TQString RandRScreen::refreshRateIndirectDescription(int size, int index) const
471 {
472  return i18n("Refresh rate in Hertz (Hz)", "%1 Hz").arg(refreshRateIndexToHz(size, index));
473 }
474 
475 KDE_EXPORT TQString RandRScreen::refreshRateDescription(int size, int index) const
476 {
477  return refreshRates(size)[index];
478 }
479 
480 KDE_EXPORT bool RandRScreen::proposeRefreshRate(int index)
481 {
482  if (index >= 0 && (int)refreshRates(proposedSize()).count() > index) {
483  m_proposedRefreshRate = index;
484  return true;
485  }
486 
487  return false;
488 }
489 
490 KDE_EXPORT int RandRScreen::currentRefreshRate() const
491 {
492  return m_currentRefreshRate;
493 }
494 
495 KDE_EXPORT TQString RandRScreen::currentRefreshRateDescription() const
496 {
497  return refreshRateIndirectDescription(m_currentSize, m_currentRefreshRate);
498 }
499 
500 KDE_EXPORT int RandRScreen::proposedRefreshRate() const
501 {
502  return m_proposedRefreshRate;
503 }
504 
505 KDE_EXPORT int RandRScreen::refreshRateHzToIndex(int size, int hz) const
506 {
507  int nrates;
508  short* rates = XRRRates(qt_xdisplay(), m_screen, (SizeID)size, &nrates);
509 
510  for (int i = 0; i < nrates; i++)
511  if (hz == rates[i])
512  return i;
513 
514  if (nrates != 0)
515  // Wrong input Hz!
516  Q_ASSERT(false);
517 
518  return -1;
519 }
520 
521 KDE_EXPORT int RandRScreen::refreshRateIndexToHz(int size, int index) const
522 {
523  int nrates;
524  short* rates = XRRRates(qt_xdisplay(), m_screen, (SizeID)size, &nrates);
525 
526  if (nrates == 0 || index < 0)
527  return 0;
528 
529  // Wrong input Hz!
530  if(index >= nrates)
531  return 0;
532 
533  return rates[index];
534 }
535 
536 KDE_EXPORT int RandRScreen::numSizes() const
537 {
538  return m_pixelSizes.count();
539 }
540 
541 KDE_EXPORT const TQSize& RandRScreen::pixelSize(int index) const
542 {
543  return m_pixelSizes[index];
544 }
545 
546 KDE_EXPORT const TQSize& RandRScreen::mmSize(int index) const
547 {
548  return m_mmSizes[index];
549 }
550 
551 KDE_EXPORT int RandRScreen::sizeIndex(TQSize pixelSize) const
552 {
553  for (uint i = 0; i < m_pixelSizes.count(); i++)
554  if (m_pixelSizes[i] == pixelSize)
555  return i;
556 
557  return -1;
558 }
559 
560 KDE_EXPORT int RandRScreen::rotations() const
561 {
562  return m_rotations;
563 }
564 
565 KDE_EXPORT int RandRScreen::currentRotation() const
566 {
567  return m_currentRotation;
568 }
569 
570 KDE_EXPORT int RandRScreen::currentSize() const
571 {
572  return m_currentSize;
573 }
574 
575 KDE_EXPORT int RandRScreen::proposedRotation() const
576 {
577  return m_proposedRotation;
578 }
579 
580 KDE_EXPORT void RandRScreen::proposeRotation(int newRotation)
581 {
582  m_proposedRotation = newRotation & OrientationMask;
583 }
584 
585 KDE_EXPORT int RandRScreen::proposedSize() const
586 {
587  return m_proposedSize;
588 }
589 
590 KDE_EXPORT bool RandRScreen::proposeSize(int newSize)
591 {
592  if ((int)m_pixelSizes.count() > newSize) {
593  m_proposedSize = newSize;
594  return true;
595  }
596 
597  return false;
598 }
599 
600 KDE_EXPORT void RandRScreen::load(KConfig& config)
601 {
602  config.setGroup(TQString("Screen%1").arg(m_screen));
603 
604  if (proposeSize(sizeIndex(TQSize(config.readNumEntry("width", currentPixelWidth()), config.readNumEntry("height", currentPixelHeight())))))
605  proposeRefreshRate(refreshRateHzToIndex(proposedSize(), config.readNumEntry("refresh", currentRefreshRate())));
606 
607  proposeRotation(rotationDegreeToIndex(config.readNumEntry("rotation", 0)) + (config.readBoolEntry("reflectX") ? ReflectX : 0) + (config.readBoolEntry("reflectY") ? ReflectY : 0));
608 }
609 
610 KDE_EXPORT void RandRScreen::save(KConfig& config) const
611 {
612  config.setGroup(TQString("Screen%1").arg(m_screen));
613  config.writeEntry("width", currentPixelWidth());
614  config.writeEntry("height", currentPixelHeight());
615  config.writeEntry("refresh", refreshRateIndexToHz(currentSize(), currentRefreshRate()));
616  config.writeEntry("rotation", rotationIndexToDegree(currentRotation()));
617  config.writeEntry("reflectX", (bool)(currentRotation() & ReflectMask) == ReflectX);
618  config.writeEntry("reflectY", (bool)(currentRotation() & ReflectMask) == ReflectY);
619 }
620 
621 KDE_EXPORT RandRDisplay::RandRDisplay()
622  : m_valid(true)
623 {
624  // Check extension
625  Status s = XRRQueryExtension(qt_xdisplay(), &m_eventBase, &m_errorBase);
626  if (!s) {
627  m_errorCode = TQString("%1, base %1").arg(s).arg(m_errorBase);
628  m_valid = false;
629  return;
630  }
631 
632  // Sometimes the extension is available but does not return any screens (!)
633  // Check for that case
634  Display *randr_display = XOpenDisplay(NULL);
635  int screen_num;
636  Window root_window;
637 
638  screen_num = DefaultScreen (randr_display);
639  root_window = RootWindow (randr_display, screen_num);
640  if (XRRGetScreenResources (randr_display, root_window) == NULL) {
641  m_errorCode = i18n("No screens detected");
642  m_valid = false;
643  return;
644  }
645 
646  int major_version, minor_version;
647  XRRQueryVersion(qt_xdisplay(), &major_version, &minor_version);
648 
649  m_version = TQString("X Resize and Rotate extension version %1.%1").arg(major_version).arg(minor_version);
650 
651  m_numScreens = ScreenCount(qt_xdisplay());
652 
653  // This assumption is WRONG with Xinerama
654  // Q_ASSERT(TQApplication::desktop()->numScreens() == ScreenCount(qt_xdisplay()));
655 
656  m_screens.setAutoDelete(true);
657  for (int i = 0; i < m_numScreens; i++) {
658  m_screens.append(new RandRScreen(i));
659  }
660 
661  setCurrentScreen(TQApplication::desktop()->primaryScreen());
662 }
663 
664 KDE_EXPORT bool RandRDisplay::isValid() const
665 {
666  return m_valid;
667 }
668 
669 KDE_EXPORT const TQString& RandRDisplay::errorCode() const
670 {
671  return m_errorCode;
672 }
673 
674 KDE_EXPORT int RandRDisplay::eventBase() const
675 {
676  return m_eventBase;
677 }
678 
679 KDE_EXPORT int RandRDisplay::screenChangeNotifyEvent() const
680 {
681  return m_eventBase + RRScreenChangeNotify;
682 }
683 
684 KDE_EXPORT int RandRDisplay::errorBase() const
685 {
686  return m_errorBase;
687 }
688 
689 KDE_EXPORT const TQString& RandRDisplay::version() const
690 {
691  return m_version;
692 }
693 
694 KDE_EXPORT void RandRDisplay::setCurrentScreen(int index)
695 {
696  m_currentScreenIndex = index;
697  m_currentScreen = m_screens.at(m_currentScreenIndex);
698  Q_ASSERT(m_currentScreen);
699 }
700 
701 KDE_EXPORT int RandRDisplay::screenIndexOfWidget(TQWidget* widget)
702 {
703  int ret = TQApplication::desktop()->screenNumber(widget);
704  return ret != -1 ? ret : TQApplication::desktop()->primaryScreen();
705 }
706 
707 KDE_EXPORT int RandRDisplay::currentScreenIndex() const
708 {
709  return m_currentScreenIndex;
710 }
711 
712 KDE_EXPORT void RandRDisplay::refresh()
713 {
714  for (RandRScreen* s = m_screens.first(); s; s = m_screens.next())
715  s->loadSettings();
716 }
717 
718 KDE_EXPORT int RandRDisplay::numScreens() const
719 {
720  return m_numScreens;
721 }
722 
723 KDE_EXPORT RandRScreen* RandRDisplay::screen(int index)
724 {
725  return m_screens.at(index);
726 }
727 
728 KDE_EXPORT RandRScreen* RandRDisplay::currentScreen()
729 {
730  return m_currentScreen;
731 }
732 
733 KDE_EXPORT bool RandRDisplay::loadDisplay(KConfig& config, bool loadScreens)
734 {
735  if (loadScreens)
736  for (RandRScreen* s = m_screens.first(); s; s = m_screens.next())
737  s->load(config);
738 
739  return applyOnStartup(config);
740 }
741 
742 KDE_EXPORT bool RandRDisplay::applyOnStartup(KConfig& config)
743 {
744  config.setGroup("Display");
745  return config.readBoolEntry("ApplyOnStartup", false);
746 }
747 
748 KDE_EXPORT bool RandRDisplay::syncTrayApp(KConfig& config)
749 {
750  config.setGroup("Display");
751  return config.readBoolEntry("SyncTrayApp", false);
752 }
753 
754 KDE_EXPORT void RandRDisplay::saveDisplay(KConfig& config, bool applyOnStartup, bool syncTrayApp)
755 {
756  Q_ASSERT(!config.isReadOnly());
757 
758  config.setGroup("Display");
759  config.writeEntry("ApplyOnStartup", applyOnStartup);
760  config.writeEntry("SyncTrayApp", syncTrayApp);
761 
762  for (RandRScreen* s = m_screens.first(); s; s = m_screens.next())
763  s->save(config);
764 }
765 
766 KDE_EXPORT void RandRDisplay::applyProposed(bool confirm)
767 {
768  for (int screenIndex = 0; screenIndex < numScreens(); screenIndex++) {
769  if (screen(screenIndex)->proposedChanged()) {
770  if (confirm)
771  screen(screenIndex)->applyProposedAndConfirm();
772  else
773  screen(screenIndex)->applyProposed();
774  }
775  }
776 }
777 
778 KDE_EXPORT bool RandRDisplay::showTestConfigurationDialog()
779 {
780  return screen(0)->showTestConfigurationDialog();
781 }
782 
783 KDE_EXPORT bool RandRScreen::showTestConfigurationDialog()
784 {
785  // uncomment the line below and edit out the KTimerDialog stuff to get
786  // a version which works on today's kdelibs (no accept dialog is presented)
787 
788  // FIXME remember to put the dialog on the right screen
789 
790  KTimerDialog acceptDialog ( 15000, KTimerDialog::CountDown,
791  KApplication::kApplication()->mainWidget(),
792  "mainKTimerDialog",
793  true,
794  i18n("Confirm Display Settings"),
795  KTimerDialog::Ok|KTimerDialog::Cancel,
796  KTimerDialog::Cancel);
797 
798  acceptDialog.setButtonOK(KGuiItem(i18n("&Accept Configuration"), "button_ok"));
799  acceptDialog.setButtonCancel(KGuiItem(i18n("&Return to Previous Configuration"), "button_cancel"));
800 
801  KActiveLabel *label = new KActiveLabel(i18n("Your display devices has been configured "
802  "to match the settings shown above. Please indicate whether you wish to "
803  "keep this configuration. In 15 seconds the display will revert to your previous "
804  "settings."), &acceptDialog, "userSpecifiedLabel");
805 
806  acceptDialog.setMainWidget(label);
807 
808  KDialog::centerOnScreen(&acceptDialog, 0);
809 
810  m_shownDialog = &acceptDialog;
811  connect( m_shownDialog, TQT_SIGNAL( destroyed()), this, TQT_SLOT( shownDialogDestroyed()));
812  connect( kapp->desktop(), TQT_SIGNAL( resized(int)), this, TQT_SLOT( desktopResized()));
813 
814  return acceptDialog.exec();
815 }
816 
817 KDE_EXPORT int RandRScreen::pixelCount( int index ) const
818 {
819  TQSize sz = pixelSize(index);
820  return sz.width() * sz.height();
821 }
822 
823 #include "randr.moc"
KConfig::isReadOnly
bool isReadOnly() const
KStdAccel::label
TQString label(StdAccel id)
KConfig::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
klocale.h
KConfig::setGroup
void setGroup(const TQString &group)
KConfig::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
KConfig
KApplication::kApplication
static KApplication * kApplication()
KConfig::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
KTimerDialog
Provides a dialog that is only available for a specified amount of time, and reports the time remaini...
Definition: ktimerdialog.h:45

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.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |