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

List:       kde-commits
Subject:    branches/work/soc-kwin-cube/effects
From:       Martin Gräßlin <ubuntu () martin-graesslin ! com>
Date:       2008-06-14 9:51:00
Message-ID: 1213437060.654253.11283.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 820434 by graesslin:

sync current state:
- added keyboard grabbing
- cube is now more or less calculated (still some issues)

 M  +131 -52   cube.cpp  
 M  +4 -0      cube.h  


--- branches/work/soc-kwin-cube/effects/cube.cpp #820433:820434
@@ -29,6 +29,8 @@
 
 #include <QRect>
 #include <QList>
+#include <QEvent>
+#include <QKeyEvent>
 
 #include <math.h>
 
@@ -42,6 +44,7 @@
 CubeEffect::CubeEffect()
     : activated( false )
     , cube_painting( false )
+    , keyboard_grab( false )
     , schedule_close( false )
     {
     KConfigGroup conf = effects->effectConfig("Cube");
@@ -64,7 +67,7 @@
     {
     if( activated )
         {
-        kDebug();
+        //kDebug();
         data.mask |= PAINT_SCREEN_TRANSFORMED | Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
         }
     effects->prePaintScreen( data, time );
@@ -74,7 +77,7 @@
     {
     if( activated )
         {
-        kDebug();
+        //kDebug();
         QRect rect = effects->clientArea( FullArea, effects->activeScreen(), effects->currentDesktop());
         QList<GLTexture*> textures;
 
@@ -137,12 +140,13 @@
         xmin =  ymin * aspect;
         xmax = ymax * aspect;
         glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
+        //kDebug() << xmin << "/" << xmax << "/" << ymin << "/" << ymax;
         
         glMatrixMode( GL_MODELVIEW );
         glLoadIdentity();
 
         glPushMatrix();
-        glTranslatef( 0.0, 0.0, -zNear*2);
+        glTranslatef( 0.0, 0.0, -zNear*2-1);
 
         glClear( GL_COLOR_BUFFER_BIT );
         glEnable( GL_BLEND );
@@ -151,59 +155,68 @@
         // this has to be calculated - at the moment for faster results hard wired
         int textureIndices[4] = {2, 3, 1, 0};
 
+        float zValue = -1.0f;
+        float scaleFactor = ( zNear*2+1 - zValue * 0.8f ) * tan( fovy * M_PI / 360.0f )/ymax;
+        glColor4f(1.0, 0.0, 0.0, 0.8);
+        int oddCounter = 1;
+        int evenCounter = 0;
         for( int i=0; i<effects->numberOfDesktops(); i++ )
             {
-            // this code is not nice and will be changed
-            // it is only a proof of concept and very hackish
-            float zTranslate = -2.0;
-            if( i == effects->numberOfDesktops() -1 )
-                {
-                zTranslate = 0.0;
-                }
-            float leftScaleFactor = ( zNear*2 - zTranslate * 0.8 ) * tan( fovy * M_PI / 360.0f )/ymax;
-            float rightScaleFactor = leftScaleFactor;
-            kDebug() << "ScaleFactor: " << leftScaleFactor << "/" << rightScaleFactor;
-            glPushMatrix();
+            float angle = 0.0f;
+            float xTranslate = 0.0f;
+            float yTranslate = 0.0f;
+            float xLeft = 0.0f;
+            float xRight = 0.0f;
+            float yBottom = 0.0f;
+            float yTop = 0.0f;
+            float leftTexCoord = 1.0;
+            float rightTexCoord = 0.0;
             if( i == 0 )
                 {
-                glScalef(-1.0, 1.0, 1.0);
+                // does not yet work correctly - don't paint
+                evenCounter++;
+                continue;
                 }
-            mTexture = textures[textureIndices[i]];
-            mTexture->bind();
-            glBegin( GL_QUADS );
-            // front
-            kDebug() << "zTranslate: " << zTranslate;
-            if( i == 0 || i == 3 )
+            if( i%2 == 0 )
                 {
-                glTexCoord2f( 0.0, 0.0 );
-                glVertex3f( xmin*leftScaleFactor, ymin*leftScaleFactor, zTranslate);
-                glTexCoord2f( 1.0, 0.0 );
-                glVertex3f( xmax*rightScaleFactor, ymin*rightScaleFactor, zTranslate);
-                glTexCoord2f( 1.0, 1.0 );
-                glVertex3f( xmax*rightScaleFactor, ymax*rightScaleFactor, zTranslate);
-                glTexCoord2f( 0.0, 1.0 );
-                glVertex3f( xmin*leftScaleFactor, ymax*leftScaleFactor, zTranslate);
+                // desktops on the right (including back)
+                xTranslate = xmax*scaleFactor;
+                yTranslate = ymax*scaleFactor;
+                xLeft = (xmin-xmax)*scaleFactor;
+                yBottom = (ymin-ymax)*scaleFactor;
+                angle = -90.0 * evenCounter;
+                evenCounter++;
                 }
             else
                 {
-                float x = xmin;
-                float leftTextureCoord = 0.0;
-                float rightTextureCoord = 1.0;
-                if( i >= effects->numberOfDesktops()/2 )
-                    {
-                    x = xmax;
-                    leftTextureCoord = 1.0;
-                    rightTextureCoord = 0.0;
-                    }
-                glTexCoord2f( leftTextureCoord, 0.0 );
-                glVertex3f( x*leftScaleFactor, ymin*leftScaleFactor, zTranslate);
-                glTexCoord2f( rightTextureCoord, 0.0 );
-                glVertex3f( x*rightScaleFactor, ymin*rightScaleFactor, 0.0);
-                glTexCoord2f( rightTextureCoord, 1.0 );
-                glVertex3f( x*rightScaleFactor, ymax*rightScaleFactor, 0.0);
-                glTexCoord2f( leftTextureCoord, 1.0 );
-                glVertex3f( x*leftScaleFactor, ymax*leftScaleFactor, zTranslate);
+                // desktops on the left (including front)
+                xTranslate = xmin*scaleFactor;
+                yTranslate = ymin*scaleFactor;
+                xRight = (xmax-xmin)*scaleFactor;
+                yTop = (ymax-ymin)*scaleFactor;
+                angle = 90.0f * oddCounter;
+                oddCounter++;
                 }
+            glPushMatrix();
+            glTranslatef( xTranslate, yTranslate, zValue );
+            glRotatef( angle, 0.0, 1.0, 0.0 );
+            if( angle > 90.0 )
+                {
+                glScalef( -1.0, 1.0, 1.0 );
+                leftTexCoord = 0.0;
+                rightTexCoord = 1.0;
+                }
+            mTexture = textures[textureIndices[i]];
+            mTexture->bind();
+            glBegin(GL_QUADS);
+                glTexCoord2f( leftTexCoord, 0.0 );
+                glVertex3f( xLeft, yBottom, 0.0);
+                glTexCoord2f( rightTexCoord, 0.0 );
+                glVertex3f( xRight, yBottom, 0.0);
+                glTexCoord2f( rightTexCoord, 1.0 );
+                glVertex3f( xRight, yTop, 0.0);
+                glTexCoord2f( leftTexCoord, 1.0 );
+                glVertex3f( xLeft, yTop, 0.0);
             glEnd();
             mTexture->unbind();
             glPopMatrix();
@@ -236,9 +249,13 @@
     effects->postPaintScreen();
     if( activated && schedule_close )
         {
-        kDebug();
+        //kDebug();
         schedule_close = false;
         activated = false;
+        if( keyboard_grab )
+            effects->ungrabKeyboard();
+        keyboard_grab = false;
+        effects->destroyInputWindow( input );
         effects->setActiveFullScreenEffect( 0 );
         effects->addRepaintFull();
         }
@@ -248,7 +265,7 @@
     {
     if( activated )
         {
-        kDebug();
+        //kDebug();
         if( cube_painting )
             {
             if( w->isOnDesktop( painting_desktop ))
@@ -296,8 +313,8 @@
     {
     if( activated && cube_painting )
         {
-        kDebug() << w->caption();
-        data.opacity *= 0.8;
+        //kDebug() << w->caption();
+        data.opacity *= 0.6;
         // check for windows belonging to the previous desktop
         int prev_desktop = painting_desktop -1;
         if( prev_desktop == 0 )
@@ -325,7 +342,7 @@
         {
         // a window was updated which has not been handled by cube_painting.
         // trigger full repaint, so that this window will be updated
-        effects->addRepaintFull();
+        //effects->addRepaintFull();
         }
     effects->postPaintWindow( w );
     }
@@ -355,7 +372,68 @@
             kDebug() << "GL_EXT_framebuffer_object is not supported. Cube cannot be activated";
             return;
             }
+        setActive( true );
+        }
+    else
+        {
+        setActive( false );
+        }
+    }
+
+void CubeEffect::grabbedKeyboardEvent( QKeyEvent* e )
+    {
+    // taken from desktopgrid.cpp
+    if( e->type() == QEvent::KeyPress )
+        {
+        int desktop = -1;
+        // switch by F<number> or just <number>
+        if( e->key() >= Qt::Key_F1 && e->key() <= Qt::Key_F35 )
+            desktop = e->key() - Qt::Key_F1 + 1;
+        else if( e->key() >= Qt::Key_0 && e->key() <= Qt::Key_9 )
+            desktop = e->key() == Qt::Key_0 ? 10 : e->key() - Qt::Key_0;
+        if( desktop != -1 )
+            {
+            if( desktop <= effects->numberOfDesktops())
+                {
+                // we have to rotate to chosen desktop
+                // and end effect when rotation finished
+                kDebug() << desktop;
+                }
+            return;
+            }
+        switch( e->key())
+            { // wrap only on autorepeat
+            case Qt::Key_Left:
+                // rotate to previous desktop
+                kDebug() << left;
+                break;
+            case Qt::Key_Right:
+                // rotate to next desktop
+                kDebug() << right;
+                break;
+            case Qt::Key_Escape:
+                setActive( false );
+                return;
+            case Qt::Key_Enter:
+            case Qt::Key_Return:
+            case Qt::Key_Space:
+                //effects->setCurrentDesktop( highlighted_desktop );
+                setActive( false );
+                return;
+            default:
+                break;
+            }
+        }
+    }
+
+void CubeEffect::setActive( bool active )
+    {
+    if( active )
+        {
         activated = true;
+        keyboard_grab = effects->grabKeyboard( this );
+        input = effects->createInputWindow( this, 0, 0, displayWidth(), displayHeight(),
+            Qt::PointingHandCursor );
         effects->setActiveFullScreenEffect( this );
         kDebug() << "Cube is activated";
         effects->addRepaintFull();
@@ -363,7 +441,8 @@
     else
         {
         schedule_close = true;
-        kDebug() << "Cube is deactivated";
+        // we have to add a repaint, to start the deactivating
+        effects->addRepaintFull();
         }
     }
 
--- branches/work/soc-kwin-cube/effects/cube.h #820433:820434
@@ -41,14 +41,18 @@
         virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
         virtual void postPaintWindow( EffectWindow* w);
         virtual bool borderActivated( ElectricBorder border );
+        virtual void grabbedKeyboardEvent( QKeyEvent* e );
     private slots:
         void toggle();
     private:
+        void setActive( bool active );
         bool activated;
         bool cube_painting;
+        bool keyboard_grab;
         bool schedule_close;
         ElectricBorder borderActivate;
         int painting_desktop;
+        Window input;
     };
 
 } // namespace
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic