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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
/*
* 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.
*/
#include <qtimer.h>
#include <qtooltip.h>
#include <kaction.h>
#include <kapplication.h>
#include <kcmultidialog.h>
#include <kdebug.h>
#include <khelpmenu.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kpopupmenu.h>
#include <kstdaction.h>
#include <kstdguiitem.h>
#include <kglobal.h>
#include <kmessagebox.h>
#include <unistd.h>
#include "configdialog.h"
#include "krandrtray.h"
#include "krandrpassivepopup.h"
#include "krandrtray.moc"
#define OUTPUT_CONNECTED (1 << 0)
#define OUTPUT_UNKNOWN (1 << 1)
#define OUTPUT_DISCONNECTED (1 << 2)
#define OUTPUT_ON (1 << 3)
#define OUTPUT_ALL (0xf)
KRandRSystemTray::KRandRSystemTray(QWidget* parent, const char *name)
: KSystemTray(parent, name)
, m_popupUp(false)
, m_help(new KHelpMenu(this, KGlobal::instance()->aboutData(), false, actionCollection()))
{
setPixmap(KSystemTray::loadIcon("randr"));
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
connect(this, SIGNAL(quitSelected()), kapp, SLOT(quit()));
QToolTip::add(this, i18n("Screen resize & rotate"));
my_parent = parent;
//printf("Reading configuration...\n\r");
globalKeys = new KGlobalAccel(this);
KGlobalAccel* keys = globalKeys;
#include "krandrbindings.cpp"
// the keys need to be read from kdeglobals, not kickerrc
globalKeys->readSettings();
globalKeys->setEnabled(true);
globalKeys->updateConnections();
connect(kapp, SIGNAL(settingsChanged(int)), SLOT(slotSettingsChanged(int)));
#if (QT_VERSION-0 >= 0x030200) // XRANDR support
// connect(this, SIGNAL(screenSizeChanged(int, int)), kapp->desktop(), SLOT( desktopResized()));
#endif
randr_display = XOpenDisplay(NULL);
last_known_x = currentScreen()->currentPixelWidth();
last_known_y = currentScreen()->currentPixelHeight();
}
void KRandRSystemTray::mousePressEvent(QMouseEvent* e)
{
// Popup the context menu with left-click
if (e->button() == LeftButton) {
contextMenuAboutToShow(contextMenu());
contextMenu()->popup(e->globalPos());
e->accept();
return;
}
KSystemTray::mousePressEvent(e);
}
void KRandRSystemTray::contextMenuAboutToShow(KPopupMenu* menu)
{
//int lastIndex = 0;
// Reload the randr configuration...
XRROutputInfo *output_info;
char *output_name;
RROutput output_id;
int i;
int lastIndex = 0;
int screenDeactivated = 0;
if (isValid() == true) {
randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ON outputs
if (!randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
if (RR_Disconnected != randr_screen_info->outputs[i]->info->connection) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
// Deactivate this display to avoid a crash!
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[i];
randr_screen_info->cur_output->auto_set = 0;
randr_screen_info->cur_output->off_set = 1;
output_off(randr_screen_info, randr_screen_info->cur_output);
main_low_apply(randr_screen_info);
screenDeactivated = 1;
}
if (screenDeactivated == 1) {
findPrimaryDisplay();
refresh();
// HACK
// This is needed because Qt does not properly generate screen
// resize events when switching screens, so KDE gets stuck in the old resolution
currentScreen()->proposeSize(GetHackResolutionParameter());
currentScreen()->applyProposed();
currentScreen()->proposeSize(GetDefaultResolutionParameter());
currentScreen()->applyProposed();
}
}
menu->clear();
menu->setCheckable(true);
if (!isValid()) {
lastIndex = menu->insertItem(i18n("Required X Extension Not Available"));
menu->setItemEnabled(lastIndex, false);
} else {
m_screenPopups.clear();
for (int s = 0; s < numScreens() /*&& numScreens() > 1 */; s++) {
setCurrentScreen(s);
if (s == screenIndexOfWidget(this)) {
/*lastIndex = menu->insertItem(i18n("Screen %1").arg(s+1));
menu->setItemEnabled(lastIndex, false);*/
} else {
KPopupMenu* subMenu = new KPopupMenu(menu, QString("screen%1").arg(s+1).latin1());
m_screenPopups.append(subMenu);
populateMenu(subMenu);
lastIndex = menu->insertItem(i18n("Screen %1").arg(s+1), subMenu);
connect(subMenu, SIGNAL(activated(int)), SLOT(slotScreenActivated()));
}
}
setCurrentScreen(screenIndexOfWidget(this));
populateMenu(menu);
}
addOutputMenu(menu);
menu->insertTitle(SmallIcon("randr"), i18n("Global Configuation"));
// KAction *actPrefs = new KAction( i18n( "Configure Display..." ),
// SmallIconSet( "configure" ), KShortcut(), this, SLOT( slotPrefs() ),
// actionCollection() );
// actPrefs->plug( menu );
KAction *actSKeys = new KAction( i18n( "Configure Shortcut Keys..." ),
SmallIconSet( "configure" ), KShortcut(), this, SLOT( slotSKeys() ),
actionCollection() );
actSKeys->plug( menu );
menu->insertItem(SmallIcon("help"),KStdGuiItem::help().text(), m_help->menu());
KAction *quitAction = actionCollection()->action(KStdAction::name(KStdAction::Quit));
quitAction->plug(menu);
}
void KRandRSystemTray::slotScreenActivated()
{
setCurrentScreen(m_screenPopups.find(static_cast<const KPopupMenu*>(sender())));
}
void KRandRSystemTray::configChanged()
{
refresh();
static bool first = true;
if ((last_known_x == currentScreen()->currentPixelWidth()) && \
(last_known_y == currentScreen()->currentPixelHeight())) {
first = true;
}
last_known_x = currentScreen()->currentPixelWidth();
last_known_y = currentScreen()->currentPixelHeight();
if (!first) {
emit (screenSizeChanged(currentScreen()->currentPixelWidth(), currentScreen()->currentPixelHeight()));
KRandrPassivePopup::message(
i18n("Screen configuration has changed"),
currentScreen()->changedMessage(), SmallIcon("window_fullscreen"),
this, "ScreenChangeNotification");
}
first = false;
}
int KRandRSystemTray::GetDefaultResolutionParameter()
{
int returnIndex = 0;
int numSizes = currentScreen()->numSizes();
int* sizeSort = new int[numSizes];
for (int i = 0; i < numSizes; i++) {
sizeSort[i] = currentScreen()->pixelCount(i);
}
int highest = -1, highestIndex = -1;
for (int i = 0; i < numSizes; i++) {
if (sizeSort[i] && sizeSort[i] > highest) {
highest = sizeSort[i];
highestIndex = i;
}
}
sizeSort[highestIndex] = -1;
Q_ASSERT(highestIndex != -1);
returnIndex = highestIndex;
delete [] sizeSort;
sizeSort = 0L;
return returnIndex;
}
int KRandRSystemTray::GetHackResolutionParameter() {
int resparm;
resparm = GetDefaultResolutionParameter();
resparm++;
return resparm;
}
void KRandRSystemTray::populateMenu(KPopupMenu* menu)
{
int lastIndex = 0;
menu->insertTitle(SmallIcon("window_fullscreen"), i18n("Screen Size"));
int numSizes = currentScreen()->numSizes();
int* sizeSort = new int[numSizes];
for (int i = 0; i < numSizes; i++) {
sizeSort[i] = currentScreen()->pixelCount(i);
}
for (int j = 0; j < numSizes; j++) {
int highest = -1, highestIndex = -1;
for (int i = 0; i < numSizes; i++) {
if (sizeSort[i] && sizeSort[i] > highest) {
highest = sizeSort[i];
highestIndex = i;
}
}
sizeSort[highestIndex] = -1;
Q_ASSERT(highestIndex != -1);
lastIndex = menu->insertItem(i18n("%1 x %2").arg(currentScreen()->pixelSize(highestIndex).width()).arg(currentScreen()->pixelSize(highestIndex).height()));
if (currentScreen()->proposedSize() == highestIndex)
menu->setItemChecked(lastIndex, true);
menu->setItemParameter(lastIndex, highestIndex);
menu->connectItem(lastIndex, this, SLOT(slotResolutionChanged(int)));
}
delete [] sizeSort;
sizeSort = 0L;
// Don't display the rotation options if there is no point (ie. none are supported)
// XFree86 4.3 does not include rotation support.
if (currentScreen()->rotations() != RandRScreen::Rotate0) {
menu->insertTitle(SmallIcon("reload"), i18n("Orientation"));
for (int i = 0; i < 6; i++) {
if ((1 << i) & currentScreen()->rotations()) {
lastIndex = menu->insertItem(currentScreen()->rotationIcon(1 << i), RandRScreen::rotationName(1 << i));
if (currentScreen()->proposedRotation() & (1 << i))
menu->setItemChecked(lastIndex, true);
menu->setItemParameter(lastIndex, 1 << i);
menu->connectItem(lastIndex, this, SLOT(slotOrientationChanged(int)));
}
}
}
QStringList rr = currentScreen()->refreshRates(currentScreen()->proposedSize());
if (rr.count())
menu->insertTitle(SmallIcon("clock"), i18n("Refresh Rate"));
int i = 0;
for (QStringList::Iterator it = rr.begin(); it != rr.end(); ++it, i++) {
lastIndex = menu->insertItem(*it);
if (currentScreen()->proposedRefreshRate() == i)
menu->setItemChecked(lastIndex, true);
menu->setItemParameter(lastIndex, i);
menu->connectItem(lastIndex, this, SLOT(slotRefreshRateChanged(int)));
}
}
void KRandRSystemTray::slotResolutionChanged(int parameter)
{
if (currentScreen()->currentSize() == parameter) {
//printf("This resolution is already in use; applying again...\n\r");
currentScreen()->proposeSize(parameter);
currentScreen()->applyProposed();
return;
}
currentScreen()->proposeSize(parameter);
currentScreen()->proposeRefreshRate(-1);
if (currentScreen()->applyProposedAndConfirm()) {
KConfig config("kcmrandrrc");
if (syncTrayApp(config))
currentScreen()->save(config);
}
}
void KRandRSystemTray::slotOrientationChanged(int parameter)
{
int propose = currentScreen()->currentRotation();
if (parameter & RandRScreen::RotateMask)
propose &= RandRScreen::ReflectMask;
propose ^= parameter;
if (currentScreen()->currentRotation() == propose)
return;
currentScreen()->proposeRotation(propose);
if (currentScreen()->applyProposedAndConfirm()) {
KConfig config("kcmrandrrc");
if (syncTrayApp(config))
currentScreen()->save(config);
}
}
void KRandRSystemTray::slotRefreshRateChanged(int parameter)
{
if (currentScreen()->currentRefreshRate() == parameter)
return;
currentScreen()->proposeRefreshRate(parameter);
if (currentScreen()->applyProposedAndConfirm()) {
KConfig config("kcmrandrrc");
if (syncTrayApp(config))
currentScreen()->save(config);
}
}
void KRandRSystemTray::slotPrefs()
{
KCMultiDialog *kcm = new KCMultiDialog( KDialogBase::Plain, i18n( "Configure" ), this );
kcm->addModule( "displayconfig" );
kcm->setPlainCaption( i18n( "Configure Display" ) );
kcm->exec();
}
void KRandRSystemTray::slotSettingsChanged(int category)
{
if ( category == (int) KApplication::SETTINGS_SHORTCUTS ) {
globalKeys->readSettings();
globalKeys->updateConnections();
}
}
void KRandRSystemTray::slotSKeys()
{
ConfigDialog *dlg = new ConfigDialog(globalKeys, true);
if ( dlg->exec() == QDialog::Accepted ) {
dlg->commitShortcuts();
globalKeys->writeSettings(0, true);
globalKeys->updateConnections();
}
delete dlg;
}
void KRandRSystemTray::slotCycleDisplays()
{
XRROutputInfo *output_info;
char *output_name;
RROutput output_id;
int i;
int lastIndex = 0;
int current_on_index = -1;
int max_index = -1;
int prev_on_index;
Status s;
randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ON outputs...
if (!randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
// ...that are connected
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
current_on_index = i;
if (i > max_index) {
max_index = i;
}
}
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for CONNECTED outputs....
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
continue;
}
// ...that are not ON
if (randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
if (i > max_index) {
max_index = i;
}
}
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ALL outputs that are not connected....
if (RR_Disconnected != randr_screen_info->outputs[i]->info->connection) {
continue;
}
// ...or ON
if (randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
if (i > max_index) {
max_index = i;
}
}
//printf("Active: %d\n\r", current_on_index);
//printf("Max: %d\n\r", max_index);
if ((current_on_index == -1) && (max_index == -1)) {
// There is no connected display available! ABORT
return;
}
prev_on_index = current_on_index;
current_on_index = current_on_index + 1;
if (current_on_index > max_index) {
current_on_index = 0;
}
while (RR_Disconnected == randr_screen_info->outputs[current_on_index]->info->connection) {
current_on_index = current_on_index + 1;
if (current_on_index > max_index) {
current_on_index = 0;
}
}
if (prev_on_index != current_on_index) {
randr_screen_info->cur_crtc = randr_screen_info->outputs[current_on_index]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[current_on_index];
randr_screen_info->cur_output->auto_set = 1;
randr_screen_info->cur_output->off_set = 0;
output_auto (randr_screen_info, randr_screen_info->cur_output);
i=main_low_apply(randr_screen_info);
if (randr_screen_info->outputs[current_on_index]->cur_crtc) {
if (prev_on_index != -1) {
if (randr_screen_info->outputs[prev_on_index]->cur_crtc != NULL) {
if (RR_Disconnected != randr_screen_info->outputs[prev_on_index]->info->connection) {
randr_screen_info->cur_crtc = randr_screen_info->outputs[prev_on_index]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[prev_on_index];
randr_screen_info->cur_output->auto_set = 0;
randr_screen_info->cur_output->off_set = 1;
output_off(randr_screen_info, randr_screen_info->cur_output);
i=main_low_apply(randr_screen_info);
}
}
}
// Do something about the disconnected outputs
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ON outputs
if (!randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
if (RR_Disconnected != randr_screen_info->outputs[i]->info->connection) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
// Deactivate this display to avoid a crash!
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[i];
randr_screen_info->cur_output->auto_set = 0;
randr_screen_info->cur_output->off_set = 1;
output_off(randr_screen_info, randr_screen_info->cur_output);
main_low_apply(randr_screen_info);
}
findPrimaryDisplay();
refresh();
// HACK
// This is needed because Qt does not properly generate screen
// resize events when switching screens, so KDE gets stuck in the old resolution
currentScreen()->proposeSize(GetHackResolutionParameter());
currentScreen()->applyProposed();
currentScreen()->proposeSize(GetDefaultResolutionParameter());
currentScreen()->applyProposed();
}
else {
output_name = randr_screen_info->outputs[current_on_index]->info->name;
KMessageBox::sorry(my_parent, i18n("<b>Unable to activate output %1</b><p>Either the output is not connected to a display,<br>or the display configuration is not detectable").arg(output_name), i18n("Output Unavailable"));
}
}
}
void KRandRSystemTray::findPrimaryDisplay()
{
XRROutputInfo *output_info;
char *output_name;
RROutput output_id;
int i;
int lastIndex = 0;
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ON outputs...
if (!randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
// ...that are connected
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
//printf("ACTIVE CHECK: Found output %s\n\r", output_name);
randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[i];
}
}
void KRandRSystemTray::addOutputMenu(KPopupMenu* menu)
{
XRROutputInfo *output_info;
char *output_name;
RROutput output_id;
int i;
int lastIndex = 0;
int connected_displays = 0;
if (isValid() == true) {
menu->insertTitle(SmallIcon("kcmkwm"), i18n("Output Port"));
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ON outputs
if (!randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
//printf("ON: Found output %s\n\r", output_name);
lastIndex = menu->insertItem(i18n("%1 (Active)").arg(output_name));
menu->setItemChecked(lastIndex, true);
menu->connectItem(lastIndex, this, SLOT(slotOutputChanged(int)));
menu->setItemParameter(lastIndex, i);
connected_displays++;
}
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for CONNECTED outputs....
if (RR_Disconnected == randr_screen_info->outputs[i]->info->connection) {
continue;
}
// ...that are not ON
if (randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
//printf("CONNECTED, NOT ON: Found output %s\n\r", output_name);
lastIndex = menu->insertItem(i18n("%1 (Connected, Inactive)").arg(output_name));
menu->setItemChecked(lastIndex, false);
menu->connectItem(lastIndex, this, SLOT(slotOutputChanged(int)));
menu->setItemParameter(lastIndex, i);
connected_displays++;
}
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ALL outputs that are not connected....
if (RR_Disconnected != randr_screen_info->outputs[i]->info->connection) {
continue;
}
// ...or ON
if (randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
output_name = output_info->name;
output_id = randr_screen_info->outputs[i]->id;
//printf("DISCONNECTED, NOT ON: Found output %s\n\r", output_name);
lastIndex = menu->insertItem(i18n("%1 (Disconnected, Inactive)").arg(output_name));
menu->setItemChecked(lastIndex, false);
menu->setItemEnabled(lastIndex, false);
menu->connectItem(lastIndex, this, SLOT(slotOutputChanged(int)));
menu->setItemParameter(lastIndex, i);
}
lastIndex = menu->insertItem(SmallIcon("forward"), i18n("Next available output"));
if (connected_displays < 2) {
menu->setItemEnabled(lastIndex, false);
}
menu->connectItem(lastIndex, this, SLOT(slotCycleDisplays()));
}
}
void KRandRSystemTray::slotOutputChanged(int parameter)
{
XRROutputInfo *output_info;
char *output_name;
RROutput output_id;
int i;
Status s;
int num_outputs_on;
num_outputs_on = 0;
for (i = 0; i < randr_screen_info->n_output; i++) {
output_info = randr_screen_info->outputs[i]->info;
// Look for ON outputs
if (!randr_screen_info->outputs[i]->cur_crtc) {
continue;
}
num_outputs_on++;
}
if (!randr_screen_info->outputs[parameter]->cur_crtc) {
//printf("Screen was off, turning it on...\n\r");
randr_screen_info->cur_crtc = randr_screen_info->outputs[parameter]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[parameter];
randr_screen_info->cur_output->auto_set = 1;
randr_screen_info->cur_output->off_set = 0;
output_auto (randr_screen_info, randr_screen_info->cur_output);
i=main_low_apply(randr_screen_info);
if (!randr_screen_info->outputs[parameter]->cur_crtc) {
output_name = randr_screen_info->outputs[parameter]->info->name;
KMessageBox::sorry(my_parent, i18n("<b>Unable to activate output %1</b><p>Either the output is not connected to a display,<br>or the display configuration is not detectable").arg(output_name), i18n("Output Unavailable"));
}
}
else {
if (num_outputs_on > 1) {
//printf("Screen was on, turning it off...\n\r");
randr_screen_info->cur_crtc = randr_screen_info->outputs[parameter]->cur_crtc;
randr_screen_info->cur_output = randr_screen_info->outputs[parameter];
randr_screen_info->cur_output->auto_set = 0;
randr_screen_info->cur_output->off_set = 1;
output_off(randr_screen_info, randr_screen_info->cur_output);
i=main_low_apply(randr_screen_info);
findPrimaryDisplay();
refresh();
// HACK
// This is needed because Qt does not properly generate screen
// resize events when switching screens, so KDE gets stuck in the old resolution
currentScreen()->proposeSize(GetHackResolutionParameter());
currentScreen()->applyProposed();
currentScreen()->proposeSize(GetDefaultResolutionParameter());
currentScreen()->applyProposed();
}
else {
KMessageBox::sorry(my_parent, i18n("<b>You are attempting to deactivate the only active output</b><p>You must keep at least one display output active at all times!"), i18n("Invalid Operation Requested"));
}
}
}
|