Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:redwil:15.4
ihu
0003-proper-tray.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-proper-tray.patch of Package ihu
diff -aur a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -49,7 +49,7 @@ SUBDIRS = doc icon ihu_CXXFLAGS = @QT_CFLAGS@ -Wall -ihu_LDADD = @QT_LIBS@ @OGG_LIBS@ -lSoundTouch -lgmp -lgmpxx -lX11 +ihu_LDADD = @QT_LIBS@ @OGG_LIBS@ -lSoundTouch -lgmp -lgmpxx moc_%.cpp: %.hpp $(QT_MOC) $< -o $@ diff -aur a/src/Ihu.cpp b/src/Ihu.cpp --- a/src/Ihu.cpp +++ b/src/Ihu.cpp @@ -425,16 +425,17 @@ { icon_status = IHU_ICON_NORMAL; trayIcon = new TrayIcon( this, "trayIcon", qPixmapFromMimeSource( "ihu_tray.png" ), "IHU" ); + trayIcon->setContextMenu(appendTrayMenu()); trayIcon->show(); - connect( trayIcon, SIGNAL( clicked() ), this, SLOT( toggleVisibility() ) ); - connect( trayIcon, SIGNAL( contextMenuRequested( const QPoint& ) ), this, SLOT( trayMenuRequested( const QPoint& ) ) ); + connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(trayIconActionActivated(QSystemTrayIcon::ActivationReason))); } } else { if (trayIcon) { - trayIcon->close(); + trayIcon->hide(); delete trayIcon; trayIcon = NULL; } @@ -1108,7 +1109,7 @@ changeTrayIcon(IHU_ICON_WAIT); else changeTrayIcon(IHU_ICON_NORMAL); - QToolTip::add( trayIcon, QString ("IHU: %1 active calls - %2").arg(phone->getCalls()).arg(statTraffic) ); + trayIcon->setToolTip( QString ("IHU: %1 active calls - %2").arg(phone->getCalls()).arg(statTraffic) ); } } @@ -1137,12 +1138,10 @@ show(); } -void Ihu::trayMenuRequested( const QPoint& pos ) +QMenu *Ihu::appendTrayMenu() { QMenu* trayMenu = new QMenu(this); trayMenu->setCheckable(TRUE); - trayMenu->insertItem( isVisible() ? "Hide IHU" : "Show IHU" , this, SLOT( toggleVisibility() ), 0, 0 ); - trayMenu->insertSeparator(); for (int i=0; i<maxcalls; i++) { @@ -1163,8 +1162,7 @@ trayMenu->insertSeparator(); trayMenu->insertItem( tr("&Quit"), this, SLOT( quit() ) ); - trayMenu->exec(pos); - delete trayMenu; + return trayMenu; } void Ihu::changeTrayIcon(icon_type newicon) @@ -1174,26 +1172,37 @@ if (newicon != icon_status) { icon_status = newicon; - trayIcon->erase(); switch(icon_status) { case IHU_ICON_NORMAL: - trayIcon->setPixmap( qPixmapFromMimeSource( "ihu_tray.png" ) ); + trayIcon->setIcon( QIcon( qPixmapFromMimeSource( "ihu_tray.png" ) ) ); break; case IHU_ICON_WAIT: - trayIcon->setPixmap( qPixmapFromMimeSource( "ihu_wait.png" ) ); + trayIcon->setIcon( QIcon( qPixmapFromMimeSource( "ihu_wait.png" ) ) ); break; case IHU_ICON_ALARM: - trayIcon->setPixmap( qPixmapFromMimeSource( "ihu_alarm.png" ) ); + trayIcon->setIcon( QIcon( qPixmapFromMimeSource( "ihu_alarm.png" ) ) ); break; case IHU_ICON_TALK: - trayIcon->setPixmap( qPixmapFromMimeSource( "ihu_talk.png" ) ); + trayIcon->setIcon( QIcon( qPixmapFromMimeSource( "ihu_talk.png" ) ) ); break; } } } } +void Ihu::trayIconActionActivated(const QSystemTrayIcon::ActivationReason &reason) +{ + switch( reason ) + { + case QSystemTrayIcon::Trigger: + toggleVisibility(); + break; + default: + ; + } +} + void Ihu::receivedNewKey(int callId, QString text) { if (showkey) diff -aur a/src/Ihu.hpp b/src/Ihu.hpp --- a/src/Ihu.hpp +++ b/src/Ihu.hpp @@ -100,9 +100,10 @@ public slots: virtual void initIhu(); virtual void closeEvent(QCloseEvent *); - virtual void toggleVisibility(); - virtual void trayMenuRequested( const QPoint& ); + virtual void toggleVisibility(); + virtual QMenu *appendTrayMenu(); virtual void changeTrayIcon(icon_type); + virtual void trayIconActionActivated(const QSystemTrayIcon::ActivationReason &); virtual void quit(); virtual void helpContents(); virtual void helpAbout(); diff -aur a/src/trayicon.cpp b/src/trayicon.cpp --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -19,73 +19,20 @@ #include "trayicon.hpp" -#include <QX11Info> +#include <QtGui> #include <Qt3Support> -#include <X11/Xatom.h> -#include <X11/Xlib.h> -// System Tray Protocol Specification opcodes. -#define SYSTEM_TRAY_REQUEST_DOCK 0 -#define SYSTEM_TRAY_BEGIN_MESSAGE 1 -#define SYSTEM_TRAY_CANCEL_MESSAGE 2 - //---------------------------------------------------------------------------- // TrayIcon -- Custom system tray widget. // Constructor. TrayIcon::TrayIcon ( QWidget *pParent, const char *pszName, const QPixmap &pm, const char *pszLabel = NULL) - : QLabel(QString(pszName), pParent, Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) + : QSystemTrayIcon(pParent) { - QLabel::setAttribute(Qt::WA_MouseNoMask); - QLabel::setMinimumSize(22, 22); - QLabel::setBackgroundMode(Qt::X11ParentRelative); - QLabel::setBackgroundOrigin(QWidget::WindowOrigin); - - Display *dpy = QX11Info::display(); - WId trayWin = winId(); - - // System Tray Protocol Specification. - Screen *screen = XDefaultScreenOfDisplay(dpy); - int iScreen = XScreenNumberOfScreen(screen); - char szAtom[32]; - snprintf(szAtom, sizeof(szAtom), "_NET_SYSTEM_TRAY_S%d", iScreen); - Atom selectionAtom = XInternAtom(dpy, szAtom, false); - XGrabServer(dpy); - Window managerWin = XGetSelectionOwner(dpy, selectionAtom); - if (managerWin != None) - XSelectInput(dpy, managerWin, StructureNotifyMask); - XUngrabServer(dpy); - XFlush(dpy); - if (managerWin != None) { - XEvent ev; - memset(&ev, 0, sizeof(ev)); - ev.xclient.type = ClientMessage; - ev.xclient.window = managerWin; - ev.xclient.message_type = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", false); - ev.xclient.format = 32; - ev.xclient.data.l[0] = CurrentTime; - ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK; - ev.xclient.data.l[2] = trayWin; - ev.xclient.data.l[3] = 0; - ev.xclient.data.l[4] = 0; - XSendEvent(dpy, managerWin, false, NoEventMask, &ev); - XSync(dpy, false); - } - - Atom trayAtom; - // For older KDE's (hopefully)... - int data = 1; - trayAtom = XInternAtom(dpy, "KWM_DOCKWINDOW", false); - XChangeProperty(dpy, trayWin, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char *) &data, 1); - // For not so older KDE's... - WId forWin = pParent ? pParent->topLevelWidget()->winId() : QApplication::desktop()->winId(); - trayAtom = XInternAtom(dpy, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false); - XChangeProperty(dpy, trayWin, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char *) &forWin, 1); - - setPixmap(pm); - if (pszLabel) { - QToolTip::add(this, pszLabel); + if ( QSystemTrayIcon::isSystemTrayAvailable() ) { + this->setIcon(QIcon(pm)); + this->setToolTip(QString(pszLabel)); } } @@ -94,26 +41,3 @@ TrayIcon::~TrayIcon (void) { } - -// Inherited mouse event. -void TrayIcon::mousePressEvent ( QMouseEvent *pMouseEvent ) -{ - if (!QLabel::rect().contains(pMouseEvent->pos())) - return; - - switch (pMouseEvent->button()) { - - case Qt::LeftButton: - // Toggle parent widget visibility. - emit clicked(); - break; - - case Qt::RightButton: - // Just signal we're on to context menu. - emit contextMenuRequested(pMouseEvent->globalPos()); - break; - - default: - break; - } -} diff -aur a/src/trayicon.hpp b/src/trayicon.hpp --- a/src/trayicon.hpp +++ b/src/trayicon.hpp @@ -26,7 +26,7 @@ //---------------------------------------------------------------------------- // TrayIcon -- Custom system tray widget. -class TrayIcon : public QLabel +class TrayIcon : public QSystemTrayIcon { Q_OBJECT @@ -42,12 +42,7 @@ // Clicked signal. void clicked(); // Context menu signal. - void contextMenuRequested(const QPoint& pos); - -protected: - - // Overriden mouse event method. - void mousePressEvent(QMouseEvent *); + void contextMenuRequested(); };
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor