[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Plasma-GlobalMenu Patch
From:       Aaron Lewis <aaron.lewis1989 () gmail ! com>
Date:       2010-08-27 14:11:10
Message-ID: 201008272211.23083.aaron.lewis1989 () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

Just updated source code , 0.20 now , fixed another problem.

http://kde-apps.org/content/show.php?content=129006

This patch is against 
http://websvn.kde.org/trunk/playground/base/plasma/globalmenu/

http://reviewboard.kde.org/ seems to be dead ?

SCMError at /r/new/
Unable to parse diff revision header '2010-08-27 21:56:51.012214294 +0800'

It crashed somehow..

-- 
Best Regards,
Aaron Lewis - PGP: 0x4A6D32A0
FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
irc: A4R0NL3WI5 on freenode

["plasma-globalmenu.patch" (text/x-patch)]

--- globalmenu.cpp	2010-08-27 21:56:51.012214294 +0800
+++ globalmenu-my.cpp	2010-08-27 21:57:28.675995620 +0800
@@ -54,21 +54,19 @@
 #include "globalmenu.h"
 #include "xbarclientadaptor.h"
 
+#define MSG(_FNC_) QDBusMessage::createMethodCall( "org.kde.XBar", "/XBar", \
"org.kde.XBar", _FNC_ ) +#define XBAR_SEND( _MSG_ ) \
QDBusConnection::sessionBus().send( _MSG_ ) +
 static GlobalMenu *self = 0;
 
 static const QString SERVICE_NAME = "org.kde.XBar-gtk";
 
 static QString windowName(WId wid)
 {
-    Status status;
-    XTextProperty tp;
-    char **list_return;
-    int list_count;
-    QString name;
-
     NETRootInfo rootInfo(QX11Info::display(), -1);
     NETWinInfo winInfo(QX11Info::display(), wid, rootInfo.rootWindow(), -1);
-    name = QString::fromUtf8(winInfo.visibleIconName());
+    QString name = QString::fromUtf8(winInfo.visibleIconName());
+
     if (name.isEmpty()) {
         name = QString::fromUtf8(winInfo.visibleName());
     }
@@ -91,23 +89,27 @@
     QStringList result;
 
     doc.setContent(source,false,&error);
+
     rootNode = doc.firstChild();
     for (QDomElement elem = rootNode.firstChildElement(); !elem.isNull(); elem = \
elem.nextSiblingElement()) {  if (elem.attribute("visible") != "0") {
-            result << elem.attribute("label").replace("(_","(&");
+            QString result_tmp = elem.attribute("label").replace("_","&");
+            result << result_tmp;
         }
     }
     return result;
 }
 
 GlobalMenu::GlobalMenu(QWidget *parent)
-    : QWidget(parent),
-      mMenu(0),
-      mMapper(new QSignalMapper(this))
+        : QWidget(parent),
+        mMenu(0),
+        mMapper(new QSignalMapper(this))
 {
     Q_ASSERT(self == 0);
     self = this;
 
+    lastWid = 0;
+
     QAbstractEventDispatcher::instance()->setEventFilter(x11EventFilter);
     mCtxAtom = XInternAtom(QX11Info::display(),"_NET_GLOBALMENU_MENU_CONTEXT",FALSE);
                
     mEvtAtom = XInternAtom(QX11Info::display(),"_NET_GLOBALMENU_MENU_EVENT",FALSE);
@@ -142,11 +144,13 @@
 
 void GlobalMenu::activate()
 {
+//    qDebug() << "Activate Now !";
     kDebug();
 }
 
 void GlobalMenu::deactivate()
 {
+//    qDebug() << "Deactivate Now !";
     kDebug();
 }
 
@@ -189,7 +193,7 @@
 void GlobalMenu::raise(qlonglong key)
 {
     Q_UNUSED(key);
-    kDebug();
+//    kDebug();
 }
 
 void GlobalMenu::windowAdded(WId wid)
@@ -197,26 +201,45 @@
     kDebug() << QString::number(wid,16);
     XSelectInput(QX11Info::display(),wid,PropertyChangeMask);
     qApp->syncX();
+    updateContextMap(wid);
 }
 
 void GlobalMenu::windowRemoved(WId wid)
 {
     kDebug() << QString::number(wid,16);
+    // Restore to "plasma" top menu when window closed.
+    XBAR_SEND( MSG("unregisterMenu") << (qlonglong)wid );
 }
 
 void GlobalMenu::windowChanged(WId wid)
 {
-    //updateContextMap(wid);
+    // Ugly Implementation , Check If Menu is hidden()
+    if (!mMenu->isHidden()) {
+        mMenu->hide();
+    }
+//    qDebug() << "LastWid: " << QString::number(lastWid,16) << " , Wid: " << \
QString::number(wid,16); +//	qDebug() << "Active: " << \
QString::number(KWindowSystem::activeWindow(),16);  }
 
 void GlobalMenu::activeWindowChanged(WId wid)
 {
-    kDebug() << QString::number(wid,16);
-    mMenu->hide();
+    if (!mMenu->isHidden()) {
+        mMenu->hide();
+    }
+
+//    kDebug() << QString::number(wid,16);
     QString ctxXML = mContextMap[wid];
     if (!ctxXML.isEmpty()) {
         bindGlobalShortcut(ctxXML);
         mXBarIfce->requestFocus(wid);
+        lastWid = wid;
+    // If last valid window exists , we unregister it
+    }  else if ( lastWid ) {
+        mXBarIfce->releaseFocus(lastWid);
+		lastWid = 0;
+    // Or it must be zero , so release
+    } else {
+		updateContextMap (wid);
     }
 }
 
@@ -235,17 +258,15 @@
         if (status) {
             if (list_count) {
                 ctxXML = QString::fromUtf8(list_return[0]);
-                if (ctxXML != mContextMap[wid]) {
-                    kDebug() << ctxXML;
-                    mContextMap.insert(wid,ctxXML);
-                    mXBarIfce->registerMenu(SERVICE_NAME,wid,
-                            windowName(wid),
-                            topMenuList(ctxXML));
-                    if (KWindowSystem::activeWindow() == wid) {
-                        mXBarIfce->requestFocus(wid);
-                    }
+//					if (ctxXML != mContextMap[wid]) 
+//                kDebug() << ctxXML;
+                mContextMap.insert(wid,ctxXML);
+                mXBarIfce->registerMenu(SERVICE_NAME,wid,
+                                        windowName(wid),
+                                        topMenuList(ctxXML));
+                if (KWindowSystem::activeWindow() == wid) {
+                    mXBarIfce->requestFocus(wid);
                 }
-
             } else {
                 ctxXML.clear();
             }
@@ -263,51 +284,30 @@
     }
     KAction *action;
     //KSelectAction *selectAction = 0;
+
     for (QDomElement itemElem = elem.firstChildElement("item"); !itemElem.isNull();
             itemElem = itemElem.nextSiblingElement("item")) {
-        if (itemElem.attribute("visible") == "0") {
-            continue;
-        }
 
-        if (itemElem.attribute("type") == "s") {
-            topMenu->addSeparator();
+        if (itemElem.attribute("visible") == "0" ) {
             continue;
-        }
+        } else if (itemElem.attribute("type") == "s") {
+            topMenu->addSeparator();
+        } else if (!itemElem.firstChildElement("menu").isNull() ) {
+            QString menu_tmp = itemElem.attribute("label").replace("_","&");
+
+            KMenu *childMenu = new KMenu(menu_tmp,topMenu);
 
-        if (!itemElem.firstChildElement("menu").isNull()) {
-            KMenu *childMenu = new \
KMenu(itemElem.attribute("label").replace("(_","(&"),topMenu);  \
                buildChildMenu(childMenu,itemElem.firstChildElement("menu"),
-                    QString("%1/%2").arg(prefix).arg(itemElem.attribute("id")));
+                           \
QString("%1/%2").arg(prefix).arg(itemElem.attribute("id"))); +
             topMenu->addMenu(childMenu);
             continue;
-        }
+        } else if ( !itemElem.attribute("label").isEmpty() ) {
+            QString menu_tmp = itemElem.attribute("label").replace("_","&");
 
-        if (itemElem.attribute("type") == "i") {
-            action = new KAction(itemElem.attribute("label").replace("(_","(&"),0);
-            mMapper->setMapping(action,QString("%1/%2").arg(prefix).arg(itemElem.attribute("id")));
                
-            connect(action,SIGNAL(triggered()),mMapper,SLOT(map()));
-            if (itemElem.attribute("sensible") == "0") {
-                action->setEnabled(false);
-            }
-            topMenu->addAction(action);
-        }
-        if (itemElem.attribute("type") == "c") {
-            action = new KAction(itemElem.attribute("label").replace("(_","(&"),0);
+            action = new KAction(menu_tmp,0);
             mMapper->setMapping(action,QString("%1/%2").arg(prefix).arg(itemElem.attribute("id")));
  connect(action,SIGNAL(triggered()),mMapper,SLOT(map()));
-            action->setCheckable(true);
-            action->setChecked(itemElem.attribute("state") == "1");
-            if (itemElem.attribute("sensible") == "0") {
-                action->setEnabled(false);
-            }
-            topMenu->addAction(action);
-        }
-        if (itemElem.attribute("type") == "r") {
-            action = new \
                KSelectAction(itemElem.attribute("label").replace("(_","(&"),0);
-            mMapper->setMapping(action,QString("%1/%2").arg(prefix).arg(itemElem.attribute("id")));
                
-            connect(action,SIGNAL(triggered()),mMapper,SLOT(map()));
-            action->setCheckable(true);
-            action->setChecked(itemElem.attribute("state") == "1");
             if (itemElem.attribute("sensible") == "0") {
                 action->setEnabled(false);
             }
@@ -318,7 +318,7 @@
 
 void GlobalMenu::triggered(const QString &id)
 {
-    kDebug() << id;
+//    kDebug() << id;
 
     mMenu->hide();
 
@@ -328,7 +328,6 @@
 
     QString ctxXML;
     Display *display = QX11Info::display();
-    Status status;
     XTextProperty tp;
 
     XStringListToTextProperty(&data,1,&tp);
@@ -342,9 +341,9 @@
         if (ev->xproperty.atom == mCtxAtom) {
             updateContextMap(ev->xproperty.window);
         }
-        if (ev->xproperty.atom == mEvtAtom) {
-            kDebug() << "Evt:" << QString::number(ev->xproperty.window) << \
                XGetAtomName(QX11Info::display(),ev->xproperty.atom);
-        }
+//        if (ev->xproperty.atom == mEvtAtom) {
+//            kDebug() << "Evt:" << QString::number(ev->xproperty.window) << \
XGetAtomName(QX11Info::display(),ev->xproperty.atom); +//        }
     }
     return false;
 }
@@ -356,7 +355,6 @@
 
 void GlobalMenu::bindGlobalShortcut(const QString &source)
 {
-
     QDomDocument doc;
     QDomElement docElem;
     QDomElement rootElem;
@@ -369,7 +367,7 @@
     for (QDomElement elem = rootElem.firstChildElement(); !elem.isNull(); elem = \
elem.nextSiblingElement()) {  if (elem.attribute("visible") != "0") {
             KShortcut shortcut(elem.attribute("accel"));
-            QString label = elem.attribute("label");
+            QString label = elem.attribute("label").replace("_","&");
             KAction *action = new KAction(label,0);
             mMapper->setMapping(action,QString("/%1").arg(elem.attribute("id")));
             connect(action,SIGNAL(triggered()),mMapper,SLOT(map()));
--- globalmenu.h	2010-08-27 21:58:18.508871633 +0800
+++ globalmenu-my.h	2010-08-27 21:58:33.675987368 +0800
@@ -73,6 +73,7 @@
 
     KMenu *mMenu;
     QSignalMapper *mMapper;
+    WId lastWid;
 
     OrgKdeXBarInterface *mXBarIfce;
 };
--- main.cpp	2010-08-27 21:58:24.178857397 +0800
+++ main-my.cpp	2010-08-27 21:59:17.098837921 +0800
@@ -14,9 +14,11 @@
                           ki18n("Copyright (C) 2009, Wang Hoi")
                           );
     KCmdLineArgs::init(argc,argv,&about_data);
+
     KApplication app;
+    GlobalMenu *menu;
 
-    GlobalMenu *menu = new GlobalMenu();
+	menu = new GlobalMenu();
 
     return app.exec();
 }


["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic