Summary: | high CPU usage when hovering over tabs with Plastik | ||
---|---|---|---|
Product: | [Frameworks and Libraries] kdelibs | Reporter: | Richard Stellingwerff <remenic> |
Component: | kstyle | Assignee: | Karol Szwed <gallium> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | maksim, sgiessl |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Gentoo Packages | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: |
Description
Richard Stellingwerff
2004-09-17 17:34:31 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; Uhm, Sandro, you never set hoverTab to a non-zero value. > 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;".
That code never runs. For it to run, hoverTab must already be non-zero, due to the outermost if (hoverTab != 0) conditional. Outch, I see... Will be fixed soon. 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) |