mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Try to avoid needless wakeups with the event pumps when not needed:
- Don't activate the Xt pump when not needed; it's not for most commonly used plugins - Don't use our glib pump's timer when Qt's glib event loop is on anyway. This doesn't cover 100% of situations, and doesn't really explain why QT_NO_GLIB works better for some people (never saw this particular case myself), but it should cover the "nspluginviewer wakes up a lot and uses a few% of cpu" case for most people. Hopefully. CCBUG: 182869 I am thinking off holding of on backporting this till 4.4.1, though.... svn path=/trunk/KDE/kdebase/apps/; revision=1075295
This commit is contained in:
parent
d351895578
commit
6ce84cd8c1
5 changed files with 54 additions and 22 deletions
|
@ -1,30 +1,33 @@
|
|||
/*
|
||||
Copyright (c) 2007 Lubos Lunak <l.lunak@suse.cz>
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#include "glibevents.h"
|
||||
|
||||
#ifdef HAVE_GLIB2
|
||||
|
||||
#include <QApplication>
|
||||
#include <QAbstractEventDispatcher>
|
||||
#include <kdebug.h>
|
||||
|
||||
GlibEvents::GlibEvents()
|
||||
{
|
||||
checkedEventLoop = false;
|
||||
g_main_context_ref( g_main_context_default());
|
||||
connect( &timer, SIGNAL( timeout()), SLOT( process()));
|
||||
// TODO Poll for now
|
||||
|
@ -38,6 +41,20 @@ GlibEvents::~GlibEvents()
|
|||
|
||||
void GlibEvents::process()
|
||||
{
|
||||
if( !checkedEventLoop )
|
||||
{
|
||||
// If Qt is already running a Glib event loop, disable our own's timer
|
||||
if (QLatin1String(QAbstractEventDispatcher::instance()->metaObject()->className())
|
||||
== "QGuiEventDispatcherGlib")
|
||||
{
|
||||
kDebug(1430) << "Qt already providing Glib integration, dropping ours";
|
||||
timer.stop();
|
||||
}
|
||||
else
|
||||
kDebug(1430) << "Qt using pure Xlib event loop; keeping Glib integration active";
|
||||
|
||||
checkedEventLoop = true;
|
||||
}
|
||||
if( g_main_depth() > 0 )
|
||||
return; // avoid reentrancy when Qt's Glib integration is used
|
||||
while( g_main_context_pending( g_main_context_default()))
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
/*
|
||||
Copyright (c) 2007 Lubos Lunak <l.lunak@suse.cz>
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#ifndef GLIBEVENTS_H
|
||||
#define GLIBEVENTS_H
|
||||
|
@ -40,6 +40,7 @@ class GlibEvents
|
|||
void process();
|
||||
private:
|
||||
QTimer timer;
|
||||
bool checkedEventLoop;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
#include "xtevents.h"
|
||||
|
||||
// BEGIN Workaround for QX11EmbedWidget silliness --- it maps widgets by default
|
||||
// Most of the code is from Qt 4.3.3, Copyright (C) 1992-2007 Trolltech ASA
|
||||
static unsigned int XEMBED_VERSION = 0;
|
||||
|
@ -53,6 +55,7 @@ static void doNotAskForXEmbedMapping(QX11EmbedWidget* widget)
|
|||
PluginHostXt::PluginHostXt(NSPluginInstance* plugin):
|
||||
_plugin(plugin), _outside(0), _toplevel(0), _form(0)
|
||||
{
|
||||
XtEvents::enable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
/*
|
||||
Copyright (c) 2007 Lubos Lunak <l.lunak@suse.cz>
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#include "xtevents.h"
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
|||
#include <kapplication.h>
|
||||
#include <QX11Info>
|
||||
|
||||
static XtEvents* self;
|
||||
|
||||
XtEvents::XtEvents()
|
||||
{
|
||||
XtToolkitInitialize();
|
||||
|
@ -34,7 +36,14 @@ XtEvents::XtEvents()
|
|||
connect( &timer, SIGNAL( timeout()), SLOT( idleProcess()));
|
||||
kapp->installX11EventFilter( this );
|
||||
// No way to find out when to process Xt events, so poll :(
|
||||
timer.start( 10 );
|
||||
// ... but only after enable() has been called
|
||||
self = this;
|
||||
}
|
||||
|
||||
void XtEvents::enable()
|
||||
{
|
||||
if (!self->timer.isActive())
|
||||
self->timer.start( 10 );
|
||||
}
|
||||
|
||||
XtEvents::~XtEvents()
|
||||
|
@ -48,7 +57,7 @@ bool XtEvents::x11Event( XEvent* e )
|
|||
|
||||
void XtEvents::idleProcess()
|
||||
{
|
||||
for( int i = 0;
|
||||
for( int i = 0;
|
||||
i < 1000; // only up to 1000 iterations, in order to avoid starving
|
||||
++i )
|
||||
{
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
/*
|
||||
Copyright (c) 2007 Lubos Lunak <l.lunak@suse.cz>
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#ifndef XTEVENTS_H
|
||||
#define XTEVENTS_H
|
||||
|
@ -33,6 +33,8 @@ class XtEvents
|
|||
XtEvents();
|
||||
virtual ~XtEvents();
|
||||
virtual bool x11Event( XEvent* );
|
||||
|
||||
static void enable();
|
||||
private slots:
|
||||
void idleProcess();
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue