[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/kwin_composite
From: Luboš Luňák <l.lunak () kde ! org>
Date: 2007-04-15 16:31:14
Message-ID: 1176654674.327937.448.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 654259 by lunakl:
Support for effects taking control of the keyboard. Needs recent kdeui change
to work properly.
M +34 -4 effects.cpp
M +5 -0 effects.h
M +14 -1 effects/presentwindows.cpp
M +2 -0 effects/presentwindows.h
M +17 -0 events.cpp
M +4 -0 lib/kwineffects.cpp
M +4 -0 lib/kwineffects.h
M +7 -0 main.cpp
M +1 -0 main.h
M +1 -0 workspace.h
--- branches/work/kwin_composite/effects.cpp #654258:654259
@@ -32,7 +32,9 @@
{
-EffectsHandlerImpl::EffectsHandlerImpl(CompositingType type) : EffectsHandler(type)
+EffectsHandlerImpl::EffectsHandlerImpl(CompositingType type)
+ : EffectsHandler(type)
+ , keyboard_grab_effect( NULL )
{
foreach( const QString& effect, options->defaultEffects )
loadEffect( effect );
@@ -40,11 +42,10 @@
EffectsHandlerImpl::~EffectsHandlerImpl()
{
- // Can't be done in EffectsHandler since it would result in pure virtuals
- // being called
+ if( keyboard_grab_effect != NULL )
+ ungrabKeyboard();
foreach( EffectPair ep, loaded_effects )
unloadEffect( ep.first );
-
foreach( InputWindowPair pos, input_windows )
XDestroyWindow( display(), pos.second );
}
@@ -237,6 +238,35 @@
ep.second->cursorMoved( pos, buttons );
}
+bool EffectsHandlerImpl::grabKeyboard( Effect* effect )
+ {
+ if( keyboard_grab_effect != NULL )
+ return false;
+ bool ret = grabXKeyboard();
+ if( !ret )
+ return false;
+ keyboard_grab_effect = effect;
+ return true;
+ }
+
+void EffectsHandlerImpl::ungrabKeyboard()
+ {
+ assert( keyboard_grab_effect != NULL );
+ ungrabXKeyboard();
+ keyboard_grab_effect = NULL;
+ }
+
+void EffectsHandlerImpl::grabbedKeyboardEvent( QKeyEvent* e )
+ {
+ if( keyboard_grab_effect != NULL )
+ keyboard_grab_effect->grabbedKeyboardEvent( e );
+ }
+
+bool EffectsHandlerImpl::hasKeyboardGrab() const
+ {
+ return keyboard_grab_effect != NULL;
+ }
+
void EffectsHandlerImpl::activateWindow( EffectWindow* c )
{
if( Client* cl = dynamic_cast< Client* >( \
static_cast<EffectWindowImpl*>(c)->window()))
--- branches/work/kwin_composite/effects.h #654258:654259
@@ -43,6 +43,8 @@
virtual int displayWidth() const;
virtual int displayHeight() const;
virtual QPoint cursorPos() const;
+ virtual bool grabKeyboard( Effect* effect );
+ virtual void ungrabKeyboard();
virtual EffectWindowList stackingOrder() const;
virtual void setTabBoxWindow(EffectWindow*);
@@ -92,12 +94,15 @@
void tabBoxUpdated();
bool borderActivated( ElectricBorder border );
void cursorMoved( const QPoint& pos, Qt::MouseButtons buttons );
+ void grabbedKeyboardEvent( QKeyEvent* e );
+ bool hasKeyboardGrab() const;
void loadEffect( const QString& name );
void unloadEffect( const QString& name );
protected:
KLibrary* findEffectLibrary( const QString& effectname );
+ Effect* keyboard_grab_effect;
};
class EffectWindowImpl : public EffectWindow
--- branches/work/kwin_composite/effects/presentwindows.cpp #654258:654259
@@ -31,6 +31,7 @@
, mActivated( false )
, mActiveness( 0.0 )
, mRearranging( 1.0 )
+ , hasKeyboardGrab( false )
, mHoverWindow( NULL )
{
@@ -257,13 +258,16 @@
{
// Create temporary input window to catch mouse events
mInput = effects->createFullScreenInputWindow( this, Qt::PointingHandCursor );
- // TODO: maybe also create a KAction so that ressing Esc would terminate the \
effect? + hasKeyboardGrab = effects->grabKeyboard( this );
}
void PresentWindowsEffect::effectTerminated()
{
// Destroy the temporary input window
effects->destroyInputWindow( mInput );
+ if( hasKeyboardGrab )
+ effects->ungrabKeyboard();
+ hasKeyboardGrab = false;
}
void PresentWindowsEffect::rearrangeWindows()
@@ -625,5 +629,14 @@
return false;
}
+void PresentWindowsEffect::grabbedKeyboardEvent( QKeyEvent* e )
+ {
+ if( e->key() == Qt::Key_Escape )
+ {
+ setActive( false );
+ return;
+ }
+ }
+
} // namespace
#include "presentwindows.moc"
--- branches/work/kwin_composite/effects/presentwindows.h #654258:654259
@@ -38,6 +38,7 @@
virtual void windowClosed( EffectWindow* c );
virtual void windowInputMouseEvent( Window w, QEvent* e );
virtual bool borderActivated( ElectricBorder border );
+ virtual void grabbedKeyboardEvent( QKeyEvent* e );
public slots:
void setActive(bool active);
@@ -76,6 +77,7 @@
float mRearranging;
Window mInput;
+ bool hasKeyboardGrab;
EffectWindowList mWindowsToPresent;
struct WindowData
--- branches/work/kwin_composite/events.cpp #654258:654259
@@ -205,6 +205,9 @@
mouse_emulation = false;
ungrabXKeyboard();
}
+ if( effects && static_cast< EffectsHandlerImpl* >( effects )->hasKeyboardGrab()
+ && ( e->type == KeyPress || e->type == KeyRelease ))
+ return false; // let Qt process it, it'll be intercepted again in \
eventFilter()
if ( e->type == PropertyNotify || e->type == ClientMessage )
{
@@ -501,6 +504,20 @@
return false;
}
+// Used only to filter events that need to be processed by Qt first
+// (e.g. keyboard input to be composed), otherwise events are
+// handle by the XEvent filter above
+bool Workspace::workspaceEvent( QEvent* e )
+ {
+ if(( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease || \
e->type() == QEvent::ShortcutOverride ) + && effects && static_cast< \
EffectsHandlerImpl* >( effects )->hasKeyboardGrab()) + {
+ static_cast< EffectsHandlerImpl* >( effects )->grabbedKeyboardEvent( \
static_cast< QKeyEvent* >( e )); + return true;
+ }
+ return false;
+ }
+
// Some events don't have the actual window which caused the event
// as e->xany.window (e.g. ConfigureRequest), but as some other
// field in the XEvent structure.
--- branches/work/kwin_composite/lib/kwineffects.cpp #654258:654259
@@ -86,6 +86,10 @@
{
}
+void Effect::grabbedKeyboardEvent( QKeyEvent* )
+ {
+ }
+
void Effect::desktopChanged( int )
{
}
--- branches/work/kwin_composite/lib/kwineffects.h #654258:654259
@@ -26,6 +26,7 @@
#include <stdio.h>
class KLibrary;
+class QKeyEvent;
namespace KWin
{
@@ -99,6 +100,7 @@
virtual void windowDamaged( EffectWindow* w, const QRect& r );
virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old \
);
virtual void cursorMoved( const QPoint& pos, Qt::MouseButtons buttons );
+ virtual void grabbedKeyboardEvent( QKeyEvent* e );
virtual void tabBoxAdded( int mode );
virtual void tabBoxClosed();
@@ -172,6 +174,8 @@
virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor \
); virtual void destroyInputWindow( Window w ) = 0;
virtual QPoint cursorPos() const = 0;
+ virtual bool grabKeyboard( Effect* effect ) = 0;
+ virtual void ungrabKeyboard() = 0;
virtual void checkElectricBorder(const QPoint &pos, Time time) = 0;
virtual void reserveElectricBorder( ElectricBorder border ) = 0;
--- branches/work/kwin_composite/main.cpp #654258:654259
@@ -167,6 +167,13 @@
return KApplication::x11EventFilter( e );
}
+bool Application::notify( QObject* o, QEvent* e )
+ {
+ if( Workspace::self()->workspaceEvent( e ))
+ return true;
+ return KApplication::notify( o, e );
+ }
+
static void sighandler(int)
{
QApplication::exit();
--- branches/work/kwin_composite/main.h #654258:654259
@@ -28,6 +28,7 @@
protected:
bool x11EventFilter( XEvent * );
+ bool notify( QObject* o, QEvent* e );
private slots:
void lostSelection();
--- branches/work/kwin_composite/workspace.h #654258:654259
@@ -80,6 +80,7 @@
static Workspace * self() { return _self; }
bool workspaceEvent( XEvent * );
+ bool workspaceEvent( QEvent * );
KDecoration* createDecoration( KDecorationBridge* bridge );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic