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

List:       kde-core-devel
Subject:    [patch] kwin desktop switching message
From:       Alexander Kellett <kelletta () eidetica ! com>
Date:       2001-09-25 10:30:34
[Download RAW message or body]

This patch and set of files provides a small message on desktop
switching quite like the windowmaker one, but alas i'm as of now
unable to get it to work perftcly.

Problems:

1) when flicking from one desktop to another and back while the 
message is on the screen the message window will take on the colour
of the background. (the "m_hide" _should_ help this but i've commented
it out as its broken... qt + x interactions?)

2) i'm really stuck with regards to getting a fade working, so much so
that the patch inclosed has all the relevant code commented out.
kimageeffect doesn't seem to provide what i need - a blend of one
image with another to a given degree, i thought a "modulate" could do
this?

Quick solution to problem 1 is to switch to using a widget mask,
unfortunately this isn't very portable - requires the shape ext? - 
and also doesn't really help in the answer to 2, therefore: anyone 
got any ideas?

Does Qt3 allow alternative - and thus working :) - implementations of
this sort of transparency stuff? (with render)

Alex

-- 
Eidetica                                           kelletta@eidetica.com
Kruislaan 400                               tel +31 20 888 4090 fax 4001
NL 1098 SM Amsterdam
http://www.eidetica.com/                               Alexander Kellett

vim: tw=70 cindent!

["msgpopup.h" (text/plain)]

/*****************************************************************
kwin - the KDE window manager
								  
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
******************************************************************/
#ifndef MSGPOPUP_H
#define MSGPOPUP_H
#include <qwidget.h>
#include <qtimer.h>

class QLabel;
class KPixmap;

namespace KWinInternal {

class Workspace;
    
class MsgPopup : public QWidget
{
    Q_OBJECT
public:
    MsgPopup( Workspace *ws, const char *name=0 );
    ~MsgPopup();

    // void reset();

    void delayedShow();
    void hide();

    Workspace* workspace() const;

    void reconfigure();

protected:
    void paintEvent( QPaintEvent* );
    void showEvent( QShowEvent* );
    void hideEvent( QHideEvent* );

private:
    QLabel* icon;
    int wmax;
    Workspace* wspace;
    QTimer redrawTimer;
    QTimer delayedHideTimer;
    QImage *image,*image2;
    KPixmap *pix;
    double factor;
    bool m_hide;
};

/*!
  Returns the message popup' workspace
 */
inline Workspace* MsgPopup::workspace() const
{
    return wspace;
}


};

#endif

["msgpopup.cpp" (text/plain)]

/*****************************************************************
kwin - the KDE window manager
								
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
******************************************************************/
//#define QT_CLEAN_NAMESPACE
#include "msgpopup.h"
#include "workspace.h"
#include <qpainter.h>
#include <qlabel.h>
#include <qdrawutil.h>
#include <qpaintdevice.h>
#undef Bool // f**king X11
#include <kpixmap.h>
#include <qimage.h>
#include <kimageeffect.h>
#include <kglobal.h>
#include <kconfig.h>
#include <klocale.h>

// specify externals before namespace

extern QPixmap* kwin_get_menu_pix_hack();

using namespace KWinInternal;

MsgPopup::MsgPopup( Workspace *ws, const char *name )
    : QWidget( 0, name, WStyle_Customize | WStyle_NoBorder )
{
    wspace = ws;
    connect(&delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
    connect(&redrawTimer, SIGNAL(timeout()), this, SLOT(repaint()));
    m_hide = true;
}

MsgPopup::~MsgPopup()
{
}


/*!
  Reimplemented to raise the tab box as well
 */
void MsgPopup::showEvent( QShowEvent* )
{
    // QWidget::hide();
    m_hide = true;
    int w = fontMetrics().width("this is an example") * 4;
    setGeometry( (qApp->desktop()->width()-w)/2,
                 qApp->desktop()->height()/2-fontMetrics().height()*1-10,
                 w, fontMetrics().height()*2 + 20 );
    QRect geo = geometry();
    if (image) delete image;
    if (pix) delete pix;
    pix = new KPixmap;
    QApplication::syncX();
    *pix = QPixmap::grabWindow(qt_xrootwin(),
                               geo.x(), geo.y(), geo.width(), geo.height());
    //image = new QImage(pix->convertToImage());
    this->setBackgroundPixmap(*pix);
    KPixmap* pixmap = new KPixmap(this->size());
    QPainter p( pixmap );
    QRect r( 6, 6, width()-12, height()-32 );
    if (pix) p.drawPixmap(QPoint(0,0),*pix);
    QString s = workspace()->desktopName(workspace()->currentDesktop());
	 r.setBottom( r.bottom() + 20 );
	 QFont f( font() );
	 f.setPointSize( 18 );
	 f.setBold( TRUE );
	 p.setFont(f );
    p.setPen(Qt::white);
	 p.drawText( r, AlignCenter, s);
	 r.setLeft( r.left() + 1 );
	 r.setTop( r.top() + 1 );
	 p.drawText( r, AlignCenter, s);
	 r.setLeft( r.left() - 2 );
	 r.setTop( r.top() - 2 );
	 p.drawText( r, AlignCenter, s);
	 r.setLeft( r.left() + 3 );
	 r.setTop( r.top() + 3 );
    p.setPen(Qt::black);
	 p.drawText( r, AlignCenter, s);
    if (pix) delete pix;
    pix = pixmap;
    //image2 = new QImage(pixmap->convertToImage());
    m_hide = false;
    //QWidget::show();
    raise();
    repaint();

}

/*!
  hide the icon box if necessary
 */
void MsgPopup::hideEvent( QHideEvent* )
{
   m_hide = true;
}


/*!
  Paints the tab box
 */
void MsgPopup::paintEvent( QPaintEvent* )
{
    // if (pix) bitBlt(this,0,0,pix);
    QPixmap* menu_pix = kwin_get_menu_pix_hack();
    /*
    factor = QMAX(0.0,factor-0.1);
    KImageEffect::modulate( *image, *image2, true,
                            KImageEffect::Contrast, factor, KImageEffect::All );
    KPixmap *pix2 = new KPixmap;
    pix2->convertFromImage(*image);
    if (pix2) bitBlt(this,0,0,pix2);
    */
    if (pix /*&& !m_hide*/) bitBlt(this,0,0,pix);
}

void MsgPopup::hide()
{
    m_hide = true;
    delayedHideTimer.stop();
    redrawTimer.stop();
    QWidget::hide();
    QApplication::syncX();
    XEvent otherEvent;
    while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) )
	;
}


void MsgPopup::reconfigure()
{
    KConfig * c(KGlobal::config());
    c->setGroup("MsgPopup");
    //options_traverse_all = c->readNumEntry("TraverseAll", false );
}

void MsgPopup::delayedShow()
{
    KConfig * c(KGlobal::config());
    c->setGroup("MsgPopup");

    QWidget::hide();
	 show();
    
    m_hide = true;

    // int delayTime = c->readNumEntry("DelayTime", 10);
    // delayedShowTimer.start(delayTime, true);

    int hideDelayTime = c->readNumEntry("HideDelayTime", 600);
    delayedHideTimer.start(hideDelayTime, true);
    //redrawTimer.start(15);

    factor = 1.0;
}

#include "msgpopup.moc"

["msgpopup.diff" (text/plain)]

Index: Makefile.am
===================================================================
RCS file: /home/kde/kdebase/kwin/Makefile.am,v
retrieving revision 1.40
diff -u -3 -p -r1.40 Makefile.am
--- Makefile.am	2001/07/01 10:10:10	1.40
+++ Makefile.am	2001/09/25 10:20:36
@@ -7,7 +7,7 @@ lib_LTLIBRARIES = kwin.la
 
 # workspace.cpp has to be first in order not to break --enable-final
 kwin_la_SOURCES = workspace.cpp atoms.cpp  client.cpp main.cpp \
-	tabbox.cpp options.cpp plugins.cpp events.cpp KWinInterface.skel \
+	tabbox.cpp msgpopup.cpp options.cpp plugins.cpp events.cpp KWinInterface.skel \
 	killwindow.cpp kwinbutton.cpp
 kwin_la_LIBADD = $(LIB_KDEUI) $(LIBXINERAMA)
 kwin_la_LDFLAGS = $(all_libraries) -module -avoid-version
Index: workspace.cpp
===================================================================
RCS file: /home/kde/kdebase/kwin/workspace.cpp,v
retrieving revision 1.269.2.3
diff -u -3 -p -r1.269.2.3 workspace.cpp
--- workspace.cpp	2001/09/06 09:23:38	1.269.2.3
+++ workspace.cpp	2001/09/25 10:20:37
@@ -30,6 +30,7 @@ Copyright (C) 1999, 2000 Matthias Ettric
 #include "workspace.h"
 #include "client.h"
 #include "tabbox.h"
+#include "msgpopup.h"
 #include "atoms.h"
 #include "plugins.h"
 #include "events.h"
@@ -244,6 +245,7 @@ Workspace::Workspace( bool restore )
     mouse_emulation   (false),
     focus_change      (true),
     tab_box           (0),
+    msg_popup         (0),
     popup             (0),
     desk_popup        (0),
     keys              (0),
@@ -321,6 +323,7 @@ Workspace::Workspace( bool restore )
 
     createKeybindings();
     tab_box = new TabBox( this );
+    msg_popup = new MsgPopup( this );
 
     init();
 
@@ -439,6 +442,7 @@ Workspace::~Workspace()
     }
     delete desktop_widget;
     delete tab_box;
+    delete msg_popup;
     delete popup;
     delete keys;
     if ( root == qt_xrootwin() )
@@ -984,7 +988,7 @@ void Workspace::CDEWalkThroughWindows( b
         else
             raiseClient( nc );
     }
-    }
+}
 
 void Workspace::KDEOneStepThroughWindows( bool forward )
 {
@@ -2089,6 +2093,9 @@ void Workspace::raiseClient( Client* c )
 
     propagateClients( TRUE );
 
+    if ( msg_popup->isVisible() )
+        msg_popup->raise();
+
     if ( tab_box->isVisible() )
         tab_box->raise();
 
@@ -2408,6 +2415,9 @@ void Workspace::setCurrentDesktop( int n
     for( uint i = 0; i < desktop_focus_chain.size(); i++ )
         s += QString::number(desktop_focus_chain[i]) + ", ";
 //    kdDebug(1212) << s << "}\n";
+
+    msg_popup->delayedShow();
+
 }
 
 void Workspace::nextDesktop()
Index: workspace.h
===================================================================
RCS file: /home/kde/kdebase/kwin/workspace.h,v
retrieving revision 1.97
diff -u -3 -p -r1.97 workspace.h
--- workspace.h	2001/07/27 12:48:30	1.97
+++ workspace.h	2001/09/25 10:20:37
@@ -31,6 +31,7 @@ namespace KWinInternal {
 
 class Client;
 class TabBox;
+class MsgPopup;
 class RootInfo;
 class PluginMgr;
 
@@ -401,6 +402,7 @@ private:
     bool focus_change;
 
     TabBox* tab_box;
+    MsgPopup* msg_popup;
 
     QPopupMenu *popup;
     QPopupMenu *desk_popup;


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

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