Bug 89712 - high CPU usage when hovering over tabs with Plastik
Summary: high CPU usage when hovering over tabs with Plastik
Status: RESOLVED FIXED
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: kstyle (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Karol Szwed
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-17 17:34 UTC by Richard Stellingwerff
Modified: 2004-11-17 16:17 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Stellingwerff 2004-09-17 17:34:31 UTC
Version:            (using KDE KDE 3.3.0)
Installed from:    Gentoo Packages
Compiler:          gcc version 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)
 
OS:                Linux

It's not really a big issue, but I noticed that CPU is pretty high when just hovering the mouse cursor over the tabs in konqueror or any other app that uses tabs. Even when staying within the same tab, just moving the cursor causes high CPU load.

It's probably easy to fix, but it's not high priority at all. But I guess it never hurts to let you know.

Other styles like Bluecurve do not exhibit this behaviour.
Comment 1 Sandro Giessl 2004-09-24 18:24:33 UTC
CVS commit by giessl:

Don't update the tabbar on every(!) MouseMove event but smartly try to
 avoid unnecessary repaints...
...helps a bit, but it is still causing high cpu load, so I'm probably
 going to disable tabbar highlighting as it's IMHO just not worth it.


  M +39 -2     plastik.cpp   1.100
  M +3 -0      plastik.h   1.32


--- kdelibs/kstyles/plastik/plastik.cpp  #1.99:1.100
@@ -3496,15 +3496,52 @@ bool PlastikStyle::eventFilter(QObject *
             QWidget* tabbar = static_cast<QWidget*>(obj);
             hoverWidget = tabbar;
+            hoverTab = 0;
             tabbar->repaint(false);
         }
         else if (ev->type() == QEvent::MouseMove)
         {
-            QWidget* tabbar = static_cast<QWidget*>(obj);
+            QTabBar *tabbar = dynamic_cast<QTabBar*>(obj);
+            QMouseEvent *me = dynamic_cast<QMouseEvent*>(ev);
+
+            if (tabbar && me) {
+                // avoid unnecessary repaints (which otherwise would
 occour on every +                // MouseMove event causing high cpu
 load).
+
+                bool repaint = true;
+
+                // if hoverTab is 0, we can simply skip this...
+                if (hoverTab != 0) {
+                    // go through the tabbar and see which tabs are
 hovered by the mouse. +                    // tabs are overlapping 1
 px, so it's possible that 2 tabs are under the mouse. +               
     int tabCount = 0;
+                    for (int i = 0; i < tabbar->count(); ++i) {
+                        QTab *tab = tabbar->tab(i);
+                        if (tab && tab->rect().contains(me->pos() ) )
 { +                            ++ tabCount;
+
+                            if (tabCount < 2) {
+                                // good, only one tab under the mouse.
+                                if (hoverTab==tab)
+                                    repaint = false; // has been
 updated before, no repaint necessary +                               
 hoverTab = tab;
+                            } else {
+                                // uhh! there's another tab under the
 mouse, repaint... +                                repaint = true;
+                                hoverTab = 0; // make sure the tabbar
 is repainted next time too. +                            }
+
+                        }
+                    }
+                }
+
+                if (repaint)
             tabbar->repaint(false);
         }
+        }
         else if (ev->type() == QEvent::Leave)
         {
             QWidget* tabbar = static_cast<QWidget*>(obj);
             hoverWidget = 0;
+            hoverTab = 0;
             tabbar->repaint(false);
         }

--- kdelibs/kstyles/plastik/plastik.h  #1.31:1.32
@@ -52,4 +52,5 @@

 class QSettings;
+class QTab;

 class PlastikStyle : public KStyle
@@ -289,4 +290,6 @@ private:
     QColor _checkMarkColor;

+    QTab *hoverTab;
+
     // track khtml widgets.
     QMap<const QWidget*,bool> khtmlWidgets;

Comment 2 Maksim Orlovich 2004-11-15 18:27:52 UTC
Uhm, Sandro, you never set hoverTab to a non-zero value.
Comment 3 Sandro Giessl 2004-11-17 12:51:41 UTC
> Uhm, Sandro, you never set hoverTab to a non-zero value.
Thanks for trying to help. But I think I'm acutally doing: in the line "hoverTab = tab;".
Comment 4 Maksim Orlovich 2004-11-17 15:18:40 UTC
That code never runs. For it to run, hoverTab must already be non-zero, due to the outermost if (hoverTab != 0) conditional. 
Comment 5 Sandro Giessl 2004-11-17 15:23:55 UTC
Outch, I see... Will be fixed soon.
Comment 6 Sandro Giessl 2004-11-17 16:17:31 UTC
CVS commit by giessl: 

Ok, this finally reduces the cpu load when hovering Plastik tabs. Thanks maksim!

BUG:89712


  M +0 -3      plastik.cpp   1.103


--- kdelibs/kstyles/plastik/plastik.cpp  #1.102:1.103
@@ -3540,6 +3540,4 @@ bool PlastikStyle::eventFilter(QObject *
                 bool repaint = true;
 
-                // if hoverTab is 0, we can simply skip this...
-                if (hoverTab != 0) {
                     // go through the tabbar and see which tabs are hovered by the mouse.
                     // tabs are overlapping 1 px, so it's possible that 2 tabs are under the mouse.
@@ -3563,5 +3561,4 @@ bool PlastikStyle::eventFilter(QObject *
                         }
                     }
-                }
 
                 if (repaint)