Skip to content

Commit

Permalink
LXQtPanel: workaround KAcceleratorManager changing button text FIXME …
Browse files Browse the repository at this point in the history
…TODO

TODO: is this correct approach?
  • Loading branch information
gfgit committed Jul 12, 2024
1 parent 3985797 commit 89cc494
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
27 changes: 26 additions & 1 deletion plugin-taskbar/lxqttaskbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ LXQtTaskButton::~LXQtTaskButton() = default;
void LXQtTaskButton::updateText()
{
QString title = mBackend->getWindowTitle(mWindow);
setText(title.replace(QStringLiteral("&"), QStringLiteral("&&")));
setTextExplicitly(title.replace(QStringLiteral("&"), QStringLiteral("&&")));
setToolTip(title);
}

Expand Down Expand Up @@ -314,6 +314,30 @@ QMimeData * LXQtTaskButton::mimeData()
return mimedata;
}

/*!
* \brief LXQtTaskButton::setTextExplicitly
* \param str
*
* This is needed to workaround flickering caused by KAcceleratorManager
* This class is hooked by KDE Integration and adds accelerators to button text
* (Adds some '&' characters)
* This triggers widget update but soon after text is reset to original value
* This triggers a KAcceleratorManager update which again adds accelerator
* This happens in loop
*
* TODO: investigate proper solution
*/
void LXQtTaskButton::setTextExplicitly(const QString &str)
{
if(str == mExplicitlySetText)
{
return;
}

mExplicitlySetText = str;
setText(mExplicitlySetText);
}

/************************************************
************************************************/
Expand Down Expand Up @@ -688,6 +712,7 @@ void LXQtTaskButton::contextMenuEvent(QContextMenuEvent* event)
menu->addSeparator();
a = menu->addAction(XdgIcon::fromTheme(QStringLiteral("process-stop")), tr("&Close"));
connect(a, &QAction::triggered, this, &LXQtTaskButton::closeApplication);

menu->setGeometry(mParentTaskBar->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), menu->sizeHint()));
mPlugin->willShowWindow(menu);
menu->show();
Expand Down
4 changes: 4 additions & 0 deletions plugin-taskbar/lxqttaskbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public slots:

inline ILXQtPanelPlugin * plugin() const { return mPlugin; }

void setTextExplicitly(const QString& str);

protected:
//TODO: public getter instead?
ILXQtAbstractWMInterface *mBackend;
Expand All @@ -138,6 +140,8 @@ public slots:
int mIconSize;
int mWheelDelta;

QString mExplicitlySetText;

// Timer for when draggind something into a button (the button's window
// must be activated so that the use can continue dragging to the window
QTimer * mDNDTimer;
Expand Down
6 changes: 3 additions & 3 deletions plugin-taskbar/lxqttaskgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LXQtTaskGroup::LXQtTaskGroup(const QString &groupName, WId window, LXQtTaskBar *
Q_ASSERT(parent);

setObjectName(groupName);
setText(groupName);
setTextExplicitly(groupName);

connect(this, &LXQtTaskGroup::clicked, this, &LXQtTaskGroup::onClicked);
connect(parent, &LXQtTaskBar::buttonRotationRefreshed, this, &LXQtTaskGroup::setAutoRotation);
Expand Down Expand Up @@ -336,7 +336,7 @@ void LXQtTaskGroup::regroup()

if (button)
{
setText(button->text());
setTextExplicitly(button->text());
setToolTip(button->toolTip());
setWindowId(button->windowId());
}
Expand All @@ -347,7 +347,7 @@ void LXQtTaskGroup::regroup()
{
mSingleButton = false;
QString t = QString(QStringLiteral("%1 - %2 windows")).arg(mGroupName).arg(cont);
setText(t);
setTextExplicitly(t);
setToolTip(parentTaskBar()->isShowGroupOnHover() ? QString() : t);
}
}
Expand Down

0 comments on commit 89cc494

Please sign in to comment.