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
|
#include "mixerwindow.h"
#include "preferencesdlg.h"
#include "devicewidget.h"
#include "../model/pulsemodel.h"
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqscrollview.h>
#include <tqwidgetstack.h>
#include <tqtoolbutton.h>
#include <tqtooltip.h>
#include <tqevent.h>
#include <ktabwidget.h>
#include <tdelocale.h>
#include <kiconloader.h>
#include <tdeglobal.h>
#include <tdestandarddirs.h>
#include <tdeaction.h>
#include <tdeactioncollection.h>
#include <tdeglobalaccel.h>
#include <kkeydialog.h>
#include <tdemenubar.h>
#include <tdepopupmenu.h>
#include <tdeaboutapplication.h>
#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <twin.h>
#include "tmixtray.h"
#include "devicespage.h"
#include <tdeconfig.h>
#include <tdemessagebox.h>
#include <kstdguiitem.h>
// ---- tab helper -------------------------------------------------------------
static MixerWindow::Tab makeTab( KTabWidget *tabs, const TQString &label )
{
MixerWindow::Tab t;
TQScrollView *sv = new TQScrollView( tabs );
sv->setFrameStyle( TQFrame::NoFrame );
sv->setHScrollBarMode( TQScrollView::Auto );
sv->setVScrollBarMode( TQScrollView::AlwaysOff );
sv->setResizePolicy( TQScrollView::AutoOneFit );
t.page = new TQWidget( sv->viewport() );
sv->addChild( t.page, 0, 0 );
t.layout = new TQHBoxLayout( t.page, 6, 4 );
t.layout->addStretch( 1 );
t.scroll = sv;
t.count = 0;
tabs->addTab( sv, label );
return t;
}
MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent )
: TDEMainWindow(parent), m_model(model), m_defaultDevice(0), m_globalAccel(0),
m_prefsDlg(0), m_devicesBtn(0), m_devicesPage(0), m_devicesInTabs(false),
m_quitting(false), m_totalDevCount(0), m_waitLabel(0)
{
setPlainCaption( i18n("Volume Control") );
setIcon( TDEGlobal::iconLoader()->loadIcon( "kmix", TDEIcon::Desktop, 48 ) );
// ---- menu bar -----------------------------------------------------------
TDEPopupMenu *fileMenu = new TDEPopupMenu( this );
fileMenu->insertItem( SmallIcon("application-exit"), i18n("&Quit"), this, TQ_SLOT(quit()) );
TDEPopupMenu *settingsMenu = new TDEPopupMenu( this );
settingsMenu->insertItem( SmallIcon("configure"), i18n("&Configure TMix..."),
this, TQ_SLOT(showPreferences()) );
settingsMenu->insertItem( SmallIcon("configure"), i18n("Configure &Global Shortcuts..."),
this, TQ_SLOT(slotConfigureGlobalShortcuts()) );
TDEPopupMenu *helpMenu = new TDEPopupMenu( this );
helpMenu->insertItem( SmallIcon("help"), i18n("&About TMix"), this, TQ_SLOT(showAbout()) );
menuBar()->insertItem( i18n("&File"), fileMenu );
menuBar()->insertItem( i18n("&Settings"), settingsMenu );
menuBar()->insertItem( i18n("&Help"), helpMenu );
// ---- system tray --------------------------------------------------------
m_tray = new TmixTray( this );
m_tray->setModel( model );
connect( model, TQ_SIGNAL(defaultOutputChanged(AudioDevice*)),
this, TQ_SLOT(onDefaultOutputChanged(AudioDevice*)) );
onDefaultOutputChanged( model->defaultOutput() );
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("Tray");
if ( cfg->readBoolEntry("DockInTray", true) )
m_tray->show();
// ---- global hotkeys -----------------------------------------------------
m_globalAccel = new TDEGlobalAccel( this, "TMix" );
m_globalAccel->insert( "Increase volume", i18n("Increase Volume"), TQString(),
TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotVolumeUp()) );
m_globalAccel->insert( "Decrease volume", i18n("Decrease Volume"), TQString(),
TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotVolumeDown()) );
m_globalAccel->insert( "Toggle mute", i18n("Toggle Mute"), TQString(),
TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotToggleMute()) );
m_globalAccel->insert( "Toggle input mute", i18n("Toggle Mute of Microphone"), TQString(),
TDEShortcut(), TDEShortcut(), this, TQ_SLOT(slotToggleInputMute()) );
m_globalAccel->readSettings();
m_globalAccel->updateConnections();
// ---- central widget -----------------------------------------------------
TQWidget *central = new TQWidget( this );
setCentralWidget( central );
setMinimumSize( 300, 200 );
TQVBoxLayout *top = new TQVBoxLayout( central, 0, 0 );
// Outer stack: page 0 = mixer, page 1 = devices (no-tab mode), page 2 = waiting
m_outerStack = new TQWidgetStack( central );
top->addWidget( m_outerStack, 1 );
TQWidget *mixerPage = new TQWidget( m_outerStack );
TQVBoxLayout *mixerLayout = new TQVBoxLayout( mixerPage, 0, 0 );
m_outerStack->addWidget( mixerPage, 0 );
// Page 2: shown when PA is not yet connected / no devices present
TQWidget *waitPage = new TQWidget( m_outerStack );
TQVBoxLayout *waitLayout = new TQVBoxLayout( waitPage, 0, 0 );
m_waitLabel = new TQLabel( i18n("Waiting for PulseAudio to start..."), waitPage );
m_waitLabel->setAlignment( TQt::AlignCenter );
waitLayout->addWidget( m_waitLabel );
m_outerStack->addWidget( waitPage, 2 );
m_outerStack->raiseWidget( 2 ); // start on waiting page; switch to 0 on first device
m_stack = new TQWidgetStack( mixerPage );
mixerLayout->addWidget( m_stack );
// Page 0: tabbed view
m_tabs = new KTabWidget( m_stack );
m_stack->addWidget( m_tabs, 0 );
m_output = makeTab( m_tabs, i18n("Output") );
m_input = makeTab( m_tabs, i18n("Input") );
m_playback = makeTab( m_tabs, i18n("Playback") );
m_recording = makeTab( m_tabs, i18n("Recording") );
// Page 1: all-in-one flat view (scrollable)
{
TQScrollView *sv = new TQScrollView( m_stack );
sv->setFrameStyle( TQFrame::NoFrame );
sv->setHScrollBarMode( TQScrollView::Auto );
sv->setVScrollBarMode( TQScrollView::AlwaysOff );
sv->setResizePolicy( TQScrollView::AutoOneFit );
m_allPage = sv;
m_allStrip = new TQWidget( sv->viewport() );
sv->addChild( m_allStrip, 0, 0 );
m_allLayout = new TQHBoxLayout( m_allStrip, 2, 4 );
m_allLayout->addStretch( 1 );
m_allCount = 0;
m_stack->addWidget( sv, 1 );
}
// Floating toggle button — child of central widget so TQWidgetStack page
// switches don't hide it; positioned over m_outerStack's bottom-right corner.
m_devicesBtn = new TQToolButton( central );
m_devicesBtn->setIconSet( SmallIconSet("configure") );
m_devicesBtn->resize( 24, 24 );
TQToolTip::add( m_devicesBtn, i18n("Device Configuration") );
connect( m_devicesBtn, TQ_SIGNAL(clicked()), this, TQ_SLOT(toggleDevices()) );
central->installEventFilter( this );
// DevicesPage — placement depends on tab/no-tab mode (set below)
m_devicesPage = new DevicesPage( model, this );
{
TDEConfig *c = TDEGlobal::config();
c->setGroup("View");
bool noTabs = c->readBoolEntry("NoTabs", false);
m_stack->raiseWidget( noTabs ? 1 : 0 );
// Place DevicesPage in the right home for the initial mode
if ( noTabs ) {
m_devicesPage->reparent( m_outerStack, 0, TQPoint(), false );
m_outerStack->addWidget( m_devicesPage, 1 );
m_devicesInTabs = false;
} else {
m_devicesPage->reparent( m_tabs, 0, TQPoint(), false );
m_tabs->addTab( m_devicesPage, i18n("Devices") );
m_devicesInTabs = true;
}
}
setAutoSaveSettings( "MainWindow" );
// Position button after layout is set; hide if in tab mode (has its own tab)
repositionDevicesBtn();
m_devicesBtn->setShown( !m_devicesInTabs );
connect( model, TQ_SIGNAL(deviceAdded(AudioDevice*)), this, TQ_SLOT(onDeviceAdded(AudioDevice*)) );
connect( model, TQ_SIGNAL(deviceRemoved(AudioDevice*)), this, TQ_SLOT(onDeviceRemoved(AudioDevice*)) );
connect( tqApp, TQ_SIGNAL(aboutToQuit()), this, TQ_SLOT(onAppAboutToQuit()) );
// Populate with any devices already known at construction time.
AudioDevice::Category cats[] = {
AudioDevice::Output, AudioDevice::Input,
AudioDevice::Playback, AudioDevice::Recording
};
for ( int i = 0; i < 4; i++ ) {
TQPtrList<AudioDevice> devs = model->devices( cats[i] );
for ( TQPtrListIterator<AudioDevice> it(devs); *it; ++it )
onDeviceAdded( *it );
}
}
bool MixerWindow::queryClose()
{
if ( m_quitting || tdeApp->sessionSaving() )
return true;
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("Tray");
if ( cfg->readBoolEntry("DockInTray", true) ) {
saveMainWindowSettings( TDEGlobal::config(), "MainWindow" );
TDEConfig *c = TDEGlobal::config();
c->setGroup("MainWindow");
c->writeEntry("XPos", x());
c->writeEntry("YPos", y());
c->sync();
hide();
return false;
}
// Not in systray — show confirm if needed, then let TDE close the window
// normally (returning true). TDE quits the app when the last main window closes.
TDEConfig *gcfg = TDEGlobal::config();
gcfg->setGroup("General");
if ( gcfg->readBoolEntry("ConfirmQuit", false) ) {
int r = KMessageBox::questionYesNo(
this,
i18n("Are you sure you want to quit TMix?"),
i18n("Quit TMix"),
KStdGuiItem::quit(),
KStdGuiItem::cancel() );
if ( r != KMessageBox::Yes )
return false;
}
m_quitting = true;
return true;
}
void MixerWindow::bringToFront()
{
show();
KWin::forceActiveWindow( winId() );
}
void MixerWindow::showDevices()
{
if ( m_devicesInTabs ) {
m_outerStack->raiseWidget( 0 );
m_tabs->showPage( m_devicesPage );
} else {
m_outerStack->raiseWidget( 1 );
updateDevicesButton();
repositionDevicesBtn();
m_devicesBtn->raise();
}
bringToFront();
}
void MixerWindow::showMixer()
{
if ( m_devicesInTabs ) {
m_outerStack->raiseWidget( 0 );
if ( m_tabs->currentPage() == m_devicesPage )
m_tabs->showPage( m_output.scroll );
} else {
m_outerStack->raiseWidget( 0 );
updateDevicesButton();
repositionDevicesBtn();
m_devicesBtn->raise();
}
bringToFront();
}
void MixerWindow::showAbout()
{
TDEAboutData about(
"tmix", I18N_NOOP("TMix"), "0.1",
I18N_NOOP("Volume control for TDE / PulseAudio"),
TDEAboutData::License_GPL,
"(c) 2026", 0, 0, 0 );
TDEAboutApplication dlg( &about, this );
dlg.exec();
}
MixerWindow::Tab &MixerWindow::tabForCategory( AudioDevice::Category cat )
{
switch ( cat ) {
case AudioDevice::Output: return m_output;
case AudioDevice::Input: return m_input;
case AudioDevice::Playback: return m_playback;
case AudioDevice::Recording: return m_recording;
}
return m_output;
}
static void updateSeparators( TQHBoxLayout *layout )
{
TQLayoutIterator it = layout->iterator();
DeviceWidget *last = 0;
while ( TQLayoutItem *item = it.current() ) {
DeviceWidget *dw = dynamic_cast<DeviceWidget*>( item->widget() );
if ( dw ) {
if ( last ) last->setSeparatorVisible( true );
last = dw;
}
++it;
}
if ( last ) last->setSeparatorVisible( false );
}
void MixerWindow::onDeviceAdded( AudioDevice *dev )
{
if ( m_totalDevCount == 0 )
m_outerStack->raiseWidget( 0 );
m_totalDevCount++;
if ( m_stack->id( m_stack->visibleWidget() ) == 1 ) {
TQWidget *w = dev->createWidget( m_allStrip );
m_allLayout->insertWidget( m_allCount, w );
m_allCount++;
w->show();
m_widgets.insert( dev, w );
updateSeparators( m_allLayout );
} else {
Tab &t = tabForCategory( dev->category() );
TQWidget *w = dev->createWidget( t.page );
t.layout->insertWidget( t.count, w );
t.count++;
w->show();
m_widgets.insert( dev, w );
updateSeparators( t.layout );
}
}
void MixerWindow::onDefaultOutputChanged( AudioDevice *dev )
{
m_defaultDevice = dev;
m_tray->setDevice( dev );
}
void MixerWindow::slotVolumeUp()
{
if ( !m_defaultDevice ) return;
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("Tray");
int step = cfg->readNumEntry("ScrollStep", 5);
int v = m_defaultDevice->volume() + step;
m_defaultDevice->setVolume( v > 100 ? 100 : v );
}
void MixerWindow::slotVolumeDown()
{
if ( !m_defaultDevice ) return;
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("Tray");
int step = cfg->readNumEntry("ScrollStep", 5);
int v = m_defaultDevice->volume() - step;
m_defaultDevice->setVolume( v < 0 ? 0 : v );
}
void MixerWindow::slotToggleMute()
{
if ( !m_defaultDevice ) return;
m_defaultDevice->setMuted( !m_defaultDevice->muted() );
}
void MixerWindow::slotToggleInputMute()
{
AudioDevice *dev = m_model->defaultInput();
if ( !dev ) return;
dev->setMuted( !dev->muted() );
}
void MixerWindow::slotConfigureGlobalShortcuts()
{
KKeyDialog::configure( m_globalAccel, 0, false );
m_globalAccel->writeSettings();
m_globalAccel->updateConnections();
}
void MixerWindow::onDeviceRemoved( AudioDevice *dev )
{
TQWidget *w = m_widgets[dev];
if ( !w ) return;
if ( m_stack->id( m_stack->visibleWidget() ) == 1 ) {
m_allLayout->remove( w );
m_allCount--;
m_widgets.remove( dev );
delete w;
updateSeparators( m_allLayout );
} else {
Tab &t = tabForCategory( dev->category() );
t.layout->remove( w );
t.count--;
m_widgets.remove( dev );
delete w;
updateSeparators( t.layout );
}
m_totalDevCount--;
if ( m_totalDevCount == 0 )
m_outerStack->raiseWidget( 2 );
}
void MixerWindow::quit()
{
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("General");
if ( cfg->readBoolEntry("ConfirmQuit", false) ) {
int r = KMessageBox::questionYesNo(
this,
i18n("Are you sure you want to quit TMix?"),
i18n("Quit TMix"),
KStdGuiItem::quit(),
KStdGuiItem::cancel() );
if ( r != KMessageBox::Yes )
return;
}
m_quitting = true;
tqApp->quit();
}
void MixerWindow::onAppAboutToQuit()
{
m_quitting = true;
}
void MixerWindow::showPreferences()
{
if ( !m_prefsDlg ) {
m_prefsDlg = new PreferencesDlg( this );
connect( m_prefsDlg, TQ_SIGNAL(settingsChanged()), this, TQ_SLOT(applySettings()) );
}
m_prefsDlg->load();
m_prefsDlg->show();
m_prefsDlg->raise();
m_prefsDlg->setActiveWindow();
}
void MixerWindow::rebuildView()
{
// Tear down all existing device widgets
for ( TQMap<AudioDevice*, TQWidget*>::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it )
delete it.data();
m_widgets.clear();
m_output.count = m_input.count = m_playback.count = m_recording.count = 0;
m_allCount = 0;
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("View");
bool noTabs = cfg->readBoolEntry("NoTabs", false);
m_stack->raiseWidget( noTabs ? 1 : 0 );
if ( noTabs && m_devicesInTabs ) {
// Move DevicesPage from m_tabs → m_outerStack
m_tabs->removePage( m_devicesPage );
m_devicesPage->reparent( m_outerStack, 0, TQPoint(), false );
m_outerStack->addWidget( m_devicesPage, 1 );
m_outerStack->raiseWidget( 0 );
updateDevicesButton();
m_devicesInTabs = false;
m_devicesBtn->show();
repositionDevicesBtn();
} else if ( !noTabs && !m_devicesInTabs ) {
// Move DevicesPage from m_outerStack → m_tabs
m_outerStack->removeWidget( m_devicesPage );
m_devicesPage->reparent( m_tabs, 0, TQPoint(), false );
m_tabs->addTab( m_devicesPage, i18n("Devices") );
m_outerStack->raiseWidget( 0 );
m_devicesInTabs = true;
m_devicesBtn->hide();
}
// Repopulate into whichever view is now active
AudioDevice::Category cats[] = {
AudioDevice::Output, AudioDevice::Input,
AudioDevice::Playback, AudioDevice::Recording
};
for ( int i = 0; i < 4; i++ ) {
TQPtrList<AudioDevice> devs = m_model->devices( cats[i] );
for ( TQPtrListIterator<AudioDevice> jt(devs); *jt; ++jt )
onDeviceAdded( *jt );
}
}
void MixerWindow::applySettings()
{
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("Tray");
if ( cfg->readBoolEntry("DockInTray", true) )
m_tray->show();
else
m_tray->hide();
cfg->setGroup("View");
bool noTabs = cfg->readBoolEntry("NoTabs", false);
if ( noTabs != ( m_stack->id( m_stack->visibleWidget() ) == 1 ) ) {
rebuildView();
} else {
// Tabs mode: apply per-tab visibility
m_tabs->setTabEnabled( m_output.scroll, cfg->readBoolEntry("ShowOutput", true) );
m_tabs->setTabEnabled( m_input.scroll, cfg->readBoolEntry("ShowInput", true) );
m_tabs->setTabEnabled( m_playback.scroll, cfg->readBoolEntry("ShowPlayback", true) );
m_tabs->setTabEnabled( m_recording.scroll, cfg->readBoolEntry("ShowRecording", true) );
}
emit settingsChanged();
}
void MixerWindow::toggleDevices()
{
int next = ( m_outerStack->id( m_outerStack->visibleWidget() ) == 0 ) ? 1 : 0;
m_outerStack->raiseWidget( next );
updateDevicesButton();
repositionDevicesBtn();
m_devicesBtn->raise();
}
void MixerWindow::updateDevicesButton()
{
if ( m_outerStack->id( m_outerStack->visibleWidget() ) == 0 ) {
m_devicesBtn->setIconSet( SmallIconSet("configure") );
TQToolTip::add( m_devicesBtn, i18n("Device Configuration") );
} else {
m_devicesBtn->setIconSet( SmallIconSet("kmix") );
TQToolTip::add( m_devicesBtn, i18n("Mixer") );
}
}
void MixerWindow::repositionDevicesBtn()
{
int bw = m_devicesBtn->width() ? m_devicesBtn->width() : 24;
int bh = m_devicesBtn->height() ? m_devicesBtn->height() : 24;
// Position in bottom-right of m_outerStack, mapped to centralWidget coords
TQPoint origin = m_outerStack->mapTo( centralWidget(), TQPoint(0, 0) );
int x = origin.x() + m_outerStack->width() - bw - 4;
int y = origin.y() + m_outerStack->height() - bh - 4;
m_devicesBtn->move( x, y );
m_devicesBtn->raise();
}
bool MixerWindow::eventFilter( TQObject *obj, TQEvent *e )
{
if ( obj == centralWidget() && e->type() == TQEvent::Resize )
repositionDevicesBtn();
return false;
}
void MixerWindow::showEvent( TQShowEvent *e )
{
TDEMainWindow::showEvent( e );
repositionDevicesBtn();
TDEConfig *c = TDEGlobal::config();
c->setGroup("MainWindow");
if ( c->hasKey("XPos") && c->hasKey("YPos") )
move( c->readNumEntry("XPos"), c->readNumEntry("YPos") );
m_model->addLevelViewer();
}
void MixerWindow::hideEvent( TQHideEvent *e )
{
TDEMainWindow::hideEvent( e );
m_model->removeLevelViewer();
}
#include "mixerwindow.moc"
|