Skip to content

Commit

Permalink
Apply fix for #123, thanks @jsm222
Browse files Browse the repository at this point in the history
@jsm222 says: Needs some polish but workarounds the problem of new fast spawning windows
with same servicename and different object paths...
  • Loading branch information
probonopd committed Dec 23, 2022
1 parent 267f193 commit 71ce4a8
Show file tree
Hide file tree
Showing 32 changed files with 298 additions and 285 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*.so.*
*.dll
*.dylib
*.orig
*.rej

# Qt-es
object_script.*.Release
Expand Down
20 changes: 10 additions & 10 deletions Shutdown/Shutdown_de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,52 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1000"/>
<location filename="../src/appmenuwidget.cpp" line="1002"/>
<source>File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1001"/>
<location filename="../src/appmenuwidget.cpp" line="1003"/>
<source>Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1008"/>
<location filename="../src/appmenuwidget.cpp" line="1010"/>
<source>Quit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1016"/>
<location filename="../src/appmenuwidget.cpp" line="1018"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1017"/>
<location filename="../src/appmenuwidget.cpp" line="1019"/>
<source>Undo</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1047"/>
<location filename="../src/appmenuwidget.cpp" line="1049"/>
<source>Cut</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1052"/>
<location filename="../src/appmenuwidget.cpp" line="1054"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1057"/>
<location filename="../src/appmenuwidget.cpp" line="1059"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1204"/>
<location filename="../src/appmenuwidget.cpp" line="1206"/>
<source>About helloDesktop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/appmenuwidget.cpp" line="1235"/>
<location filename="../src/appmenuwidget.cpp" line="1237"/>
<source>About This Computer</source>
<translation type="unfinished"></translation>
</message>
Expand Down
14 changes: 11 additions & 3 deletions src/appmenu/appmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@
#include <QDBusServiceWatcher>
#include <QGuiApplication>
#include <QTimer>
#include <QMutex>
#include <QWidgetAction>
#include <QHBoxLayout>
#include <QDebug>
#include<QModelIndex>
#include <dbusmenu-qt5/dbusmenuimporter.h>

QMutex mutex;
static const QByteArray s_x11AppMenuServiceNamePropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_SERVICE_NAME");
static const QByteArray s_x11AppMenuObjectPathPropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_OBJECT_PATH");

static QHash<QByteArray, xcb_atom_t> s_atoms;


void HMenu::actionEvent(QActionEvent *e) {
if(e->type() == QEvent::ActionAdded) {
// probono: Remove mnemonics (underlined characters in menus represented by "&" in code)
Expand Down Expand Up @@ -380,6 +381,7 @@ void AppMenuModel::onActiveWindowChanged(WId id)

if(m_serviceName == serviceName &&
m_menuObjectPath == menuObjectPath) {
m_pending_service[m_serviceName]=true;
updateApplicationMenu(m_serviceName, m_menuObjectPath);
}else {
m_initialApplicationFromWindowId = -1;
Expand Down Expand Up @@ -453,7 +455,10 @@ void AppMenuModel::onActiveWindowChanged(WId id)
qDebug() << serviceName << menuObjectPath << __LINE__ << id;
if (!serviceName.isEmpty() && !menuObjectPath.isEmpty()) {
m_initialApplicationFromWindowId = id;
mutex.lock();
m_pending_service[m_serviceName]=true;
updateApplicationMenu(serviceName, menuObjectPath);
mutex.unlock();
return true;
}

Expand Down Expand Up @@ -756,7 +761,10 @@ void AppMenuModel::refreshSearch() {

void AppMenuModel::updateApplicationMenu(const QString &serviceName, const QString &menuObjectPath)
{

if(m_pending_service[serviceName] && m_serviceName == serviceName) {
qDebug() << "Skipping" << serviceName << menuObjectPath <<"switching too fast";
return;
}
QMenuBar * menuBar = qobject_cast<QMenuBar*>(w_parent);/*m_importers[serviceName+menuObjectPath]->menu()->parent());*/
int cnt = menuBar->actions().count();
QList<QAction*> remove;
Expand Down Expand Up @@ -784,7 +792,7 @@ void AppMenuModel::updateApplicationMenu(const QString &serviceName, const QStri

setMenuAvailable(!m_menu.isNull());

emit menuImported();
emit menuImported(serviceName);
}

void AppMenuModel::updateSearch() {
Expand Down
3 changes: 2 additions & 1 deletion src/appmenu/appmenumodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class AppMenuModel : public QAbstractItemModel, public QAbstractNativeEventFilte
MenuRole = Qt::UserRole + 1, // TODO this should be Qt::DisplayRole
ActionRole
};
QHash<QString,bool> m_pending_service;

QAction *findParent(QAction * child,QAction *root) const ;
/**
Expand Down Expand Up @@ -352,7 +353,7 @@ private Q_SLOTS:
signals:
void menuAvailableChanged();
void modelNeedsUpdate();
void menuImported();
void menuImported(QString serviceName);
void firstLevelParsed();
void filterByActiveChanged();
void filterChildrenChanged();
Expand Down
4 changes: 3 additions & 1 deletion src/appmenuwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ AppMenuWidget::AppMenuWidget(QWidget *parent)
m_appMenuModel = new AppMenuModel(m_menuBar);

connect(m_appMenuModel,&AppMenuModel::menuAboutToBeImported,this,&AppMenuWidget::menuAboutToBeImported);
connect(m_appMenuModel,&AppMenuModel::menuImported,this,[this,traverse] {
connect(m_appMenuModel,&AppMenuModel::menuImported,this,[this,traverse](QString serviceName) {




Expand All @@ -582,6 +583,7 @@ AppMenuWidget::AppMenuWidget(QWidget *parent)
iterate(QModelIndex(),m_appMenuModel,traverse);
});
}
m_appMenuModel->m_pending_service[serviceName]=false;
});
connect(m_appMenuModel, &AppMenuModel::menuAvailableChanged, this, &AppMenuWidget::updateMenu);

Expand Down
20 changes: 10 additions & 10 deletions src/translations/menubar_cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<translation>Vyhledávání</translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1235"/>
<location filename="../appmenuwidget.cpp" line="1237"/>
<source>About This Computer</source>
<translation>O tomto počítači</translation>
</message>
Expand Down Expand Up @@ -47,47 +47,47 @@
<translation>Vypnutí</translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1000"/>
<location filename="../appmenuwidget.cpp" line="1002"/>
<source>File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1001"/>
<location filename="../appmenuwidget.cpp" line="1003"/>
<source>Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1008"/>
<location filename="../appmenuwidget.cpp" line="1010"/>
<source>Quit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1016"/>
<location filename="../appmenuwidget.cpp" line="1018"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1017"/>
<location filename="../appmenuwidget.cpp" line="1019"/>
<source>Undo</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1047"/>
<location filename="../appmenuwidget.cpp" line="1049"/>
<source>Cut</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1052"/>
<location filename="../appmenuwidget.cpp" line="1054"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1057"/>
<location filename="../appmenuwidget.cpp" line="1059"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1204"/>
<location filename="../appmenuwidget.cpp" line="1206"/>
<source>About helloDesktop</source>
<translation type="unfinished"></translation>
</message>
Expand Down
20 changes: 10 additions & 10 deletions src/translations/menubar_da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<context>
<name>AppMenuWidget</name>
<message>
<location filename="../appmenuwidget.cpp" line="1235"/>
<location filename="../appmenuwidget.cpp" line="1237"/>
<source>About This Computer</source>
<translation>Om denne computer</translation>
</message>
Expand Down Expand Up @@ -54,47 +54,47 @@
<translation>Luk ned</translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1000"/>
<location filename="../appmenuwidget.cpp" line="1002"/>
<source>File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1001"/>
<location filename="../appmenuwidget.cpp" line="1003"/>
<source>Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1008"/>
<location filename="../appmenuwidget.cpp" line="1010"/>
<source>Quit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1016"/>
<location filename="../appmenuwidget.cpp" line="1018"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1017"/>
<location filename="../appmenuwidget.cpp" line="1019"/>
<source>Undo</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1047"/>
<location filename="../appmenuwidget.cpp" line="1049"/>
<source>Cut</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1052"/>
<location filename="../appmenuwidget.cpp" line="1054"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1057"/>
<location filename="../appmenuwidget.cpp" line="1059"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1204"/>
<location filename="../appmenuwidget.cpp" line="1206"/>
<source>About helloDesktop</source>
<translation type="unfinished"></translation>
</message>
Expand Down
20 changes: 10 additions & 10 deletions src/translations/menubar_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<translation>Suchen</translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1235"/>
<location filename="../appmenuwidget.cpp" line="1237"/>
<source>About This Computer</source>
<translation>Über diesen Computer</translation>
</message>
Expand Down Expand Up @@ -47,47 +47,47 @@
<translation>Ausschalten</translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1000"/>
<location filename="../appmenuwidget.cpp" line="1002"/>
<source>File</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1001"/>
<location filename="../appmenuwidget.cpp" line="1003"/>
<source>Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1008"/>
<location filename="../appmenuwidget.cpp" line="1010"/>
<source>Quit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1016"/>
<location filename="../appmenuwidget.cpp" line="1018"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1017"/>
<location filename="../appmenuwidget.cpp" line="1019"/>
<source>Undo</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1047"/>
<location filename="../appmenuwidget.cpp" line="1049"/>
<source>Cut</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1052"/>
<location filename="../appmenuwidget.cpp" line="1054"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1057"/>
<location filename="../appmenuwidget.cpp" line="1059"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../appmenuwidget.cpp" line="1204"/>
<location filename="../appmenuwidget.cpp" line="1206"/>
<source>About helloDesktop</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Loading

0 comments on commit 71ce4a8

Please sign in to comment.