Commit d6ea6072 authored by Jonathan Marten's avatar Jonathan Marten

System tray: Open the main KMix window on "Restore"

It's not useful to pop up the volume control for this action, as there
is no position available and so the very small volume control popup
appears (and often doesn't get noticed by the user) at the top left of
the screen.  Do what would be expected from the action text and open
the main KMix window instead.
parent 873ddac9
......@@ -76,6 +76,7 @@ KMixDockWidget::KMixDockWidget(KMixWindow* parent)
connect(this, &KStatusNotifierItem::secondaryActivateRequested, this, &KMixDockWidget::dockMute);
// For bizarre reasons, we wrap the ViewDockAreaPopup in a QMenu. Must relate to how KStatusNotifierItem works.
// TODO: Is this necessary? Deleted and recreated in activate()
_dockAreaPopupMenuWrapper = new QMenu(parent);
_volWA = new QWidgetAction(_dockAreaPopupMenuWrapper);
_dockView = new ViewDockAreaPopup(_dockAreaPopupMenuWrapper, "dockArea", {}, QString("no-guiprofile-yet-in-dock"), parent);
......@@ -291,12 +292,28 @@ case '3': setIconByName("audio-volume-high");
}
/**
* Called whenever the icon gets "activated". Usually when its clicked.
* @overload
* @param pos
* Called when the system tray icon gets "activated".
*
* This can happen in two ways, either by a left-click on the icon or
* by "Restore" from the context menu. In the first case the sender()
* is a null pointer and 'pos' is the popup position. In the second
* case the sender() is the KStatusNotifierItem's QAction and 'pos' is
* a null QPoint.
*
* Left-clicking on the system tray icon should pop up the volume control,
* as expected. However, it is not useful to do the same for "Restore" as
* there is no 'pos' to open at (and no way to find it), so the popup volume
* control appears at the top left of the screen. It is more useful, and
* follows the action label more accurately, to open the main KMix window.
*/
void KMixDockWidget::activate(const QPoint &pos)
{
if (pos.isNull()) // "Restore" from the menu
{
_dockView->showPanelSlot();
return;
}
QWidget* dockAreaPopup = _dockAreaPopupMenuWrapper; // TODO Refactor to use _dockAreaPopupMenuWrapper directly
if (dockAreaPopup->isVisible())
{
......@@ -358,7 +375,6 @@ void KMixDockWidget::activate(const QPoint &pos)
qCDebug(KMIX_LOG) << "Multihead: (case 4) moving to" << x << "," << y;
}
KWindowSystem::setType(dockAreaPopup->winId(), NET::Dock);
KWindowSystem::setState(dockAreaPopup->winId(), NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager);
dockAreaPopup->show();
......
......@@ -49,9 +49,10 @@
#undef RESTORE_VOLUME_BUTTON
ViewDockAreaPopup::ViewDockAreaPopup(QWidget* parent, const QString &id, ViewBase::ViewFlags vflags, const QString &guiProfileId,
KMixWindow *dockW) :
ViewBase(parent, id, {}, vflags, guiProfileId), _kmixMainWindow(dockW)
ViewDockAreaPopup::ViewDockAreaPopup(QWidget* parent, const QString &id, ViewBase::ViewFlags vflags,
const QString &guiProfileId, KMixWindow *dockW)
: ViewBase(parent, id, {}, vflags, guiProfileId),
_kmixMainWindow(dockW)
{
resetRefs();
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
......@@ -141,7 +142,7 @@ void ViewDockAreaPopup::keyPressEvent(QKeyEvent *ev)
int key = ev->key();
const QKeySequence seq(key);
// KGlobalAccel::shortcut() is safe if called with nullptr.
// KGlobalAccel::shortcut() is safe if called with a null pointer.
if (KGlobalAccel::self()->shortcut(actUp).contains(seq)) key = Qt::Key_Up;
if (KGlobalAccel::self()->shortcut(actDown).contains(seq)) key = Qt::Key_Down;
if (KGlobalAccel::self()->shortcut(actMute).contains(seq)) key = Qt::Key_Space;
......@@ -212,24 +213,24 @@ void ViewDockAreaPopup::configurationUpdate()
void ViewDockAreaPopup::resetRefs()
{
seperatorBetweenMastersAndStreams = 0;
seperatorBetweenMastersAndStreams = nullptr;
separatorBetweenMastersAndStreamsInserted = false;
separatorBetweenMastersAndStreamsRequired = false;
configureViewButton = 0;
restoreVolumeButton1 = 0;
restoreVolumeButton2 = 0;
restoreVolumeButton3 = 0;
restoreVolumeButton4 = 0;
mainWindowButton = 0;
optionsLayout = 0;
_layoutMDW = 0;
configureViewButton = nullptr;
restoreVolumeButton1 = nullptr;
restoreVolumeButton2 = nullptr;
restoreVolumeButton3 = nullptr;
restoreVolumeButton4 = nullptr;
mainWindowButton = nullptr;
optionsLayout = nullptr;
_layoutMDW = nullptr;
}
void ViewDockAreaPopup::initLayout()
{
resetMdws();
if (optionsLayout != 0)
if (optionsLayout!=nullptr)
{
QLayoutItem *li2;
while ((li2 = optionsLayout->takeAt(0)))
......@@ -237,7 +238,7 @@ void ViewDockAreaPopup::initLayout()
}
// Hint : optionsLayout itself is deleted when "delete _layoutMDW" cascades down
if (_layoutMDW != 0)
if (_layoutMDW!=nullptr)
{
QLayoutItem *li;
while ((li = _layoutMDW->takeAt(0)))
......@@ -254,7 +255,7 @@ Application: KMix (kmix), signal: Segmentation fault
#8 0x00007f9c9d425700 in ViewBase::createDeviceWidgets (this=0x1272b60) at /home/chris/workspace/kmix-git-trunk/gui/viewbase.cpp:137
#9 0x00007f9c9d42845b in ViewDockAreaPopup::controlsChange (this=0x1272b60, changeType=2) at /home/chris/workspace/kmix-git-trunk/gui/viewdockareapopup.cpp:91
*/
// if ( optionsLayout != 0 )
// if ( optionsLayout != nullptr )
// {
// QLayoutItem *li2;
// while ( ( li2 = optionsLayout->takeAt(0) ) ) // strangely enough, it crashes here
......@@ -283,7 +284,7 @@ Application: KMix (kmix), signal: Segmentation fault
* of this ViewDockAreaPopup
* (Hint: it might have been 0 already. Nowadays it is definitely, see #resetRefs())
*/
delete layout(); // BKO 299754
delete layout(); // Bug 299754
_layoutMDW = new QGridLayout(this);
_layoutMDW->setSpacing(DialogBase::verticalSpacing());
// Review #121166: Add some space over device icons, otherwise they may hit window border
......@@ -498,7 +499,7 @@ void ViewDockAreaPopup::configureView()
}
/**
* This gets activated whne a user clicks the "Mixer" PushButton in this popup.
* This gets activated when a user clicks the "Mixer" PushButton in this popup.
*/
void ViewDockAreaPopup::showPanelSlot()
{
......
......@@ -61,7 +61,8 @@ private:
KMixWindow *_kmixMainWindow;
QGridLayout *_layoutMDW;
QPushButton* createRestoreVolumeButton ( int storageSlot );
QPushButton* createRestoreVolumeButton (int storageSlot);
void resetRefs();
bool separatorBetweenMastersAndStreamsInserted;
bool separatorBetweenMastersAndStreamsRequired;
......@@ -75,17 +76,10 @@ private:
QPushButton *restoreVolumeButton4;
QIcon restoreVolumeIcon;
static ProfControl* MatchAllForSoundMenu;
static QString InternedString_Star;
static QString InternedString_Subcontrols;
public slots:
void controlsChange(ControlManager::ChangeType changeType);
void configureView() override;
private slots:
void controlsChange(ControlManager::ChangeType changeType);
void configureView() override;
void showPanelSlot();
void resetRefs();
};
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment