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

List:       kde-devel
Subject:    [patch] Making it harder to accidentially quit a system tray
From:       Esben Mose Hansen <kde () mosehansen ! dk>
Date:       2005-02-15 21:27:26
Message-ID: 200502152226.19855.kde () mosehansen ! dk
[Download RAW message or body]

Hi,

I and others have been annoyed how easy it is to "slip" when clicking a 
systray icon and accidentially quitting the application. The "slip" in slow 
motion:

1. downclick the systray icon
2. drag the mouse pointer slightly to hover over Quit in the popupmenu
3. release the mouse pointer.

User's intention  was to click the systray icon. Instead he quits the 
application. Surprisingly easy to do.

The attached patch fixes this by disabling Quit for a very short period 
(0.3s). 

Please review.



-- 
regards. Esben

["ksystray_delay_quit.patch" (text/x-diff)]

Index: ksystemtray.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ksystemtray.cpp,v
retrieving revision 1.47
diff -u -p -u -w -r1.47 ksystemtray.cpp
--- ksystemtray.cpp	15 Jan 2005 20:26:21 -0000	1.47
+++ ksystemtray.cpp	15 Feb 2005 21:14:53 -0000
@@ -38,11 +38,13 @@
 #include <kconfig.h>
 
 #include <qapplication.h>
+#include <qtimer.h>
 
 class KSystemTrayPrivate
 {
 public:
     KSystemTrayPrivate()
+        : block_quit( false )
     {
         actionCollection = 0;
     }
@@ -54,6 +56,13 @@ public:
 
     KActionCollection* actionCollection;
     bool on_all_desktops; // valid only when the parent widget was hidden
+
+    // When true, quits are ignored.
+    // The purpose is to avoid having the user accidentally close the
+    // application by mousedown on systray icon, slight drag to quit
+    // and release on quit. This is actually quite common... try it!
+    bool block_quit;
+
 };
 
 KSystemTray::KSystemTray( QWidget* parent, const char* name )
@@ -76,6 +85,7 @@ KSystemTray::KSystemTray( QWidget* paren
     menu->insertTitle( kapp->miniIcon(), kapp->caption() );
     move( -1000, -1000 );
     KStdAction::quit(this, SLOT(maybeQuit()), d->actionCollection);
+    connect ( menu, SIGNAL(  aboutToShow () ), this, SLOT( slotAboutToShowPopupMenu() ) );
 
     if (parentWidget())
     {
@@ -189,6 +199,9 @@ void KSystemTray::minimizeRestoreAction(
 
 void KSystemTray::maybeQuit()
 {
+    if ( d->block_quit ) {
+        return;
+    }
     QString query = i18n("<qt>Are you sure you want to quit <b>%1</b>?</qt>")
                         .arg(kapp->caption());
     if (KMessageBox::warningContinueCancel(this, query,
@@ -326,6 +339,15 @@ void KSystemTray::setCaption( const QStr
     QLabel::setCaption( s );
 }
 
+void KSystemTray::slotAboutToShowPopupMenu() {
+    d->block_quit = true;
+    QTimer::singleShot( 300, this, SLOT( slotUnblockQuit() ) );
+}
+
+void KSystemTray::slotUnblockQuit() {
+    d->block_quit = false;
+}
+
 void KSystemTray::virtual_hook( int, void* )
 { /*BASE::virtual_hook( id, data );*/ }
 
Index: ksystemtray.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ksystemtray.h,v
retrieving revision 1.20
diff -u -p -u -w -r1.20 ksystemtray.h
--- ksystemtray.h	15 Jan 2005 20:26:22 -0000	1.20
+++ ksystemtray.h	15 Feb 2005 21:14:53 -0000
@@ -187,6 +187,8 @@ protected:
 private slots:
     void minimizeRestoreAction();
     void maybeQuit();
+    void slotAboutToShowPopupMenu();
+    void slotUnblockQuit();
 
 private:
     void activateOrHide();


>> 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