- Use KDecorationFactory::resetDecorations() instead of a custom signal/slot.

- Fixed the crashes reported on the kwin mailing list.
- Various cleanups.

svn path=/trunk/kdebase/kwin/; revision=252169
This commit is contained in:
Fredrik Höglund 2003-09-18 17:07:49 +00:00
parent 5f6bd80480
commit c6390bdf4c
2 changed files with 110 additions and 115 deletions

View file

@ -21,9 +21,6 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include <config.h>
#include <kconfig.h> #include <kconfig.h>
#include <klocale.h> #include <klocale.h>
#include <kiconeffect.h> #include <kiconeffect.h>
@ -36,13 +33,13 @@
#include <qwidget.h> #include <qwidget.h>
#include <qlabel.h> #include <qlabel.h>
#include "keramik.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "keramik.h"
#include "keramik.moc" #include "keramik.moc"
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
@ -127,7 +124,6 @@ namespace Keramik
KeramikHandler::KeramikHandler() KeramikHandler::KeramikHandler()
: QObject( NULL, NULL )
{ {
for ( int i = 0; i < NumTiles; i++ ) { for ( int i = 0; i < NumTiles; i++ ) {
activeTiles[i] = NULL; activeTiles[i] = NULL;
@ -139,14 +135,14 @@ KeramikHandler::KeramikHandler()
imageDb = KeramikImageDb::instance(); imageDb = KeramikImageDb::instance();
// Create the button deco bitmaps // Create the button deco bitmaps
buttonDecos[ Menu ] = new QBitmap( 17, 17, menu_bits, true ); buttonDecos[ Menu ] = new QBitmap( 17, 17, menu_bits, true );
buttonDecos[ OnAllDesktops ] = new QBitmap( 17, 17, on_all_desktops_bits, true ); buttonDecos[ OnAllDesktops ] = new QBitmap( 17, 17, on_all_desktops_bits, true );
buttonDecos[ NotOnAllDesktops ] = new QBitmap( 17, 17, not_on_all_desktops_bits, true ); buttonDecos[ NotOnAllDesktops ] = new QBitmap( 17, 17, not_on_all_desktops_bits, true );
buttonDecos[ Help ] = new QBitmap( 17, 17, help_bits, true ); buttonDecos[ Help ] = new QBitmap( 17, 17, help_bits, true );
buttonDecos[ Minimize ] = new QBitmap( 17, 17, minimize_bits, true ); buttonDecos[ Minimize ] = new QBitmap( 17, 17, minimize_bits, true );
buttonDecos[ Maximize ] = new QBitmap( 17, 17, maximize_bits, true ); buttonDecos[ Maximize ] = new QBitmap( 17, 17, maximize_bits, true );
buttonDecos[ Restore ] = new QBitmap( 17, 17, restore_bits, true ); buttonDecos[ Restore ] = new QBitmap( 17, 17, restore_bits, true );
buttonDecos[ Close ] = new QBitmap( 17, 17, close_bits, true ); buttonDecos[ Close ] = new QBitmap( 17, 17, close_bits, true );
// Selfmask the bitmaps // Selfmask the bitmaps
for ( int i = 0; i < NumButtonDecos; i++ ) for ( int i = 0; i < NumButtonDecos; i++ )
@ -176,8 +172,7 @@ KeramikHandler::~KeramikHandler()
for ( int i = 0; i < NumButtonDecos; i++ ) for ( int i = 0; i < NumButtonDecos; i++ )
delete buttonDecos[i]; delete buttonDecos[i];
if ( settings_cache ) delete settings_cache;
delete settings_cache;
KeramikImageDb::release(); KeramikImageDb::release();
imageDb = NULL; imageDb = NULL;
@ -342,15 +337,10 @@ void KeramikHandler::createPixmaps()
void KeramikHandler::destroyPixmaps() void KeramikHandler::destroyPixmaps()
{ {
for ( int i = 0; i < NumTiles; i++ ) { for ( int i = 0; i < NumTiles; i++ ) {
if ( activeTiles[i] ) { delete activeTiles[i];
delete activeTiles[i]; delete inactiveTiles[i];
activeTiles[i] = NULL; activeTiles[i] = NULL;
} inactiveTiles[i] = NULL;
if ( inactiveTiles[i] ) {
delete inactiveTiles[i];
inactiveTiles[i] = NULL;
}
} }
delete titleButtonRound; delete titleButtonRound;
@ -532,7 +522,7 @@ bool KeramikHandler::reset( unsigned long changed )
// Do we need to "hit the wooden hammer" ? // Do we need to "hit the wooden hammer" ?
if ( !needHardReset ) if ( !needHardReset )
emit softReset(); resetDecorations( changed );
return needHardReset; return needHardReset;
} }
@ -685,12 +675,14 @@ KeramikClient::KeramikClient( KDecorationBridge* bridge, KDecorationFactory* fac
void KeramikClient::init() void KeramikClient::init()
{ {
createMainWidget( WStaticContents | WResizeNoErase | WRepaintNoErase ); createMainWidget( WStaticContents | WResizeNoErase | WRepaintNoErase );
// Minimize flicker
widget()->installEventFilter( this ); widget()->installEventFilter( this );
// Minimize flicker
widget()->setBackgroundMode( NoBackground ); widget()->setBackgroundMode( NoBackground );
for ( int i=0; i < NumButtons; i++ ) for ( int i=0; i < NumButtons; i++ )
button[i] = NULL; button[i] = NULL;
createLayout(); createLayout();
} }
@ -733,24 +725,19 @@ void KeramikClient::createLayout()
windowLayout->addSpacing( 3 ); // Left border windowLayout->addSpacing( 3 ); // Left border
windowLayout->addWidget( new QLabel( i18n( "<center><b>Keramik</b></center>" ), widget())); // Window wrapper FRAME windowLayout->addWidget( new QLabel( i18n( "<center><b>Keramik</b></center>" ), widget())); // Window wrapper FRAME
windowLayout->addSpacing( 4 ); // Right border windowLayout->addSpacing( 4 ); // Right border
connect( clientHandler, SIGNAL(softReset()), SLOT(reset()) );
} }
KeramikClient::~KeramikClient() KeramikClient::~KeramikClient()
{ {
if ( activeIcon ) delete activeIcon;
delete activeIcon; delete inactiveIcon;
if ( inactiveIcon )
delete inactiveIcon;
activeIcon = inactiveIcon = NULL; activeIcon = inactiveIcon = NULL;
} }
void KeramikClient::reset() void KeramikClient::reset( unsigned long )
{ {
if ( clientHandler->largeCaptionBubbles() && !largeTitlebar ) if ( clientHandler->largeCaptionBubbles() && !largeTitlebar )
{ {
@ -815,7 +802,8 @@ void KeramikClient::addButtons( QBoxLayout *layout, const QString &s )
// OnAllDesktops button // OnAllDesktops button
case 'S' : case 'S' :
if ( !button[OnAllDesktopsButton] ) { if ( !button[OnAllDesktopsButton] ) {
button[OnAllDesktopsButton] = new KeramikButton( this, "on_all_desktops", OnAllDesktopsButton, i18n("On All Desktops") ); button[OnAllDesktopsButton] = new KeramikButton( this, "on_all_desktops",
OnAllDesktopsButton, i18n("On All Desktops") );
connect( button[OnAllDesktopsButton], SIGNAL( clicked() ), SLOT( toggleOnAllDesktops() ) ); connect( button[OnAllDesktopsButton], SIGNAL( clicked() ), SLOT( toggleOnAllDesktops() ) );
layout->addWidget( button[OnAllDesktopsButton] ); layout->addWidget( button[OnAllDesktopsButton] );
} }
@ -876,7 +864,7 @@ void KeramikClient::updateMask()
// pixmap, paint the mask on it and then have the X server iterate // pixmap, paint the mask on it and then have the X server iterate
// over the pixels to compute the bounding rects from it. // over the pixels to compute the bounding rects from it.
QRegion rect; QRegion r;
register int w, y = 0; register int w, y = 0;
int nrects; int nrects;
@ -886,9 +874,9 @@ void KeramikClient::updateMask()
if ( largeCaption && captionRect.width() >= 25 ) { if ( largeCaption && captionRect.width() >= 25 ) {
register int x = captionRect.left(); register int x = captionRect.left();
w = captionRect.width(); w = captionRect.width();
setRectangle( rect, x + 11, y++, w - 19, 1 ); r += QRegion( x + 11, y++, w - 19, 1 );
setRectangle( rect, x + 9, y++, w - 15, 1 ); r += QRegion( x + 9, y++, w - 15, 1 );
setRectangle( rect, x + 7, y++, w - 12, 1 ); r += QRegion( x + 7, y++, w - 12, 1 );
} else { } else {
nrects = 8; nrects = 8;
@ -902,13 +890,13 @@ void KeramikClient::updateMask()
w = width(); // FRAME w = width(); // FRAME
// The rounded titlebar corners // The rounded titlebar corners
setRectangle( rect, 9, y++, w - 17, 1 ); r += QRegion( 9, y++, w - 17, 1 );
setRectangle( rect, 7, y++, w - 13, 1 ); r += QRegion( 7, y++, w - 13, 1 );
setRectangle( rect, 5, y++, w - 9, 1 ); r += QRegion( 5, y++, w - 9, 1 );
setRectangle( rect, 4, y++, w - 7, 1 ); r += QRegion( 4, y++, w - 7, 1 );
setRectangle( rect, 3, y++, w - 5, 1 ); r += QRegion( 3, y++, w - 5, 1 );
setRectangle( rect, 2, y++, w - 4, 1 ); r += QRegion( 2, y++, w - 4, 1 );
setRectangle( rect, 1, y++, w - 2, 2 ); r += QRegion( 1, y++, w - 2, 2 );
} else { } else {
// If the caption bubble is visible and extends above the titlebar // If the caption bubble is visible and extends above the titlebar
@ -916,9 +904,9 @@ void KeramikClient::updateMask()
nrects = 11; nrects = 11;
register int x = captionRect.left(); register int x = captionRect.left();
w = captionRect.width(); w = captionRect.width();
setRectangle( rect, x + 8, y++, w - 19, 1 ); r += QRegion( x + 8, y++, w - 19, 1 );
setRectangle( rect, x + 6, y++, w - 15, 1 ); r += QRegion( x + 6, y++, w - 15, 1 );
setRectangle( rect, x + 5, y++, w - 12, 1 ); r += QRegion( x + 5, y++, w - 12, 1 );
} else { } else {
nrects = 8; nrects = 8;
@ -932,21 +920,21 @@ void KeramikClient::updateMask()
w = width(); // FRAME w = width(); // FRAME
// The rounded titlebar corners // The rounded titlebar corners
setRectangle( rect, 8, y++, w - 17, 1 ); r += QRegion( 8, y++, w - 17, 1 );
setRectangle( rect, 6, y++, w - 13, 1 ); r += QRegion( 6, y++, w - 13, 1 );
setRectangle( rect, 4, y++, w - 9, 1 ); r += QRegion( 4, y++, w - 9, 1 );
setRectangle( rect, 3, y++, w - 7, 1 ); r += QRegion( 3, y++, w - 7, 1 );
setRectangle( rect, 2, y++, w - 5, 1 ); r += QRegion( 2, y++, w - 5, 1 );
setRectangle( rect, 2, y++, w - 4, 1 ); r += QRegion( 2, y++, w - 4, 1 );
setRectangle( rect, 1, y++, w - 2, 2 ); r += QRegion( 1, y++, w - 2, 2 );
} }
y++; y++;
// The part of the window below the titlebar // The part of the window below the titlebar
setRectangle( rect, 0, y, w, height() - y ); r += QRegion( 0, y, w, height() - y );
setMask( rect, YXBanded ); setMask( r, YXBanded );
maskDirty = false; maskDirty = false;
} }
@ -963,6 +951,9 @@ void KeramikClient::updateCaptionBuffer()
if ( captionBuffer.size() != captionRect.size() ) if ( captionBuffer.size() != captionRect.size() )
captionBuffer.resize( captionRect.size() ); captionBuffer.resize( captionRect.size() );
if ( captionBuffer.isNull() )
return;
QPainter p( &captionBuffer ); QPainter p( &captionBuffer );
// Draw the caption bubble // Draw the caption bubble
@ -1181,14 +1172,20 @@ void KeramikClient::menuButtonPressed()
void KeramikClient::slotMaximize() void KeramikClient::slotMaximize()
{ {
if ( button[ MaxButton ]->lastButton() == MidButton ) switch ( button[ MaxButton ]->lastButton() )
maximize( maximizeMode() ^ MaximizeVertical ); {
case MidButton:
maximize( maximizeMode() ^ MaximizeVertical );
break;
else if ( button[ MaxButton ]->lastButton() == RightButton ) case RightButton:
maximize( maximizeMode() ^ MaximizeHorizontal ); maximize( maximizeMode() ^ MaximizeHorizontal );
break;
else case LeftButton:
maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull ); maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull );
break;
}
} }
@ -1428,57 +1425,67 @@ KeramikClient::MousePosition KeramikClient::mousePosition( const QPoint &p ) con
return Nowhere; return Nowhere;
} }
void KeramikClient::resize( const QSize& s ) void KeramikClient::resize( const QSize& s )
{ {
widget()->resize( s ); widget()->resize( s );
} }
void KeramikClient::borders( int& left, int& right, int& top, int& bottom ) const void KeramikClient::borders( int& left, int& right, int& top, int& bottom ) const
{ {
bool active = isActive(); int titleBarHeight = clientHandler->titleBarHeight( largeTitlebar );
int titleBarHeight = clientHandler->titleBarHeight( largeTitlebar ); int grabBarHeight = clientHandler->grabBarHeight();
int grabBarHeight = clientHandler->grabBarHeight(); int leftBorderWidth = clientHandler->tile( BorderLeft, isActive() )->width();
int leftBorderWidth = clientHandler->tile( BorderLeft, active )->width(); int rightBorderWidth = clientHandler->tile( BorderRight, isActive() )->width();
int rightBorderWidth = clientHandler->tile( BorderRight, active )->width();
left = leftBorderWidth; left = leftBorderWidth;
right = rightBorderWidth; right = rightBorderWidth;
top = titleBarHeight; top = titleBarHeight;
bottom = grabBarHeight; bottom = grabBarHeight;
if( isShade())
bottom = 0; if ( isShade())
if( ( maximizeMode() & MaximizeHorizontal ) && !options()->moveResizeMaximizedWindows()) bottom = 0;
left = right = 0;
if( ( maximizeMode() & MaximizeVertical ) && !options()->moveResizeMaximizedWindows()) if ( ( maximizeMode() & MaximizeHorizontal ) && !options()->moveResizeMaximizedWindows())
bottom = 0; left = right = 0;
if( ( maximizeMode() & MaximizeVertical ) && !options()->moveResizeMaximizedWindows())
bottom = 0;
} }
QSize KeramikClient::minimumSize() const QSize KeramikClient::minimumSize() const
{ {
return QSize( 200, 50 ); // FRAME return widget()->minimumSize();
} }
bool KeramikClient::eventFilter( QObject* o, QEvent* e ) bool KeramikClient::eventFilter( QObject* o, QEvent* e )
{ {
if( o != widget()) if ( o != widget() )
return false; return false;
switch( e->type())
switch ( e->type() )
{ {
case QEvent::Resize: case QEvent::Resize:
resizeEvent( static_cast< QResizeEvent* >( e )); resizeEvent( static_cast< QResizeEvent* >( e ) );
return true; return true;
case QEvent::Paint:
paintEvent( static_cast< QPaintEvent* >( e )); case QEvent::Paint:
return true; paintEvent( static_cast< QPaintEvent* >( e ) );
case QEvent::MouseButtonDblClick: return true;
mouseDoubleClickEvent( static_cast< QMouseEvent* >( e ));
return true; case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonPress: mouseDoubleClickEvent( static_cast< QMouseEvent* >( e ) );
processMousePressEvent( static_cast< QMouseEvent* >( e )); return true;
return true;
default: case QEvent::MouseButtonPress:
break; processMousePressEvent( static_cast< QMouseEvent* >( e ) );
return true;
default:
return false;
} }
return false;
} }
} // namespace Keramik } // namespace Keramik

View file

@ -31,8 +31,6 @@
#include "tiles.h" #include "tiles.h"
#include <X11/Xlib.h>
class QSpacerItem; class QSpacerItem;
namespace Keramik { namespace Keramik {
@ -54,10 +52,8 @@ namespace Keramik {
bool largeGrabBars:1; bool largeGrabBars:1;
}; };
class KeramikHandler : public QObject, public KDecorationFactory { class KeramikHandler : public KDecorationFactory
{
Q_OBJECT
public: public:
KeramikHandler(); KeramikHandler();
~KeramikHandler(); ~KeramikHandler();
@ -84,9 +80,6 @@ namespace Keramik {
inline const QPixmap *tile( TilePixmap tilePix, bool active ) const; inline const QPixmap *tile( TilePixmap tilePix, bool active ) const;
signals:
void softReset();
private: private:
void readConfig(); void readConfig();
void createPixmaps(); void createPixmaps();
@ -99,7 +92,6 @@ namespace Keramik {
QImage *loadImage( const QString &, const QColor & ); QImage *loadImage( const QString &, const QColor & );
QPixmap *loadPixmap( const QString &, const QColor & ); QPixmap *loadPixmap( const QString &, const QColor & );
private:
bool showIcons:1, shadowedText:1, bool showIcons:1, shadowedText:1,
smallCaptionBubbles:1, largeGrabBars:1; smallCaptionBubbles:1, largeGrabBars:1;
SettingsCache *settings_cache; SettingsCache *settings_cache;
@ -139,13 +131,14 @@ namespace Keramik {
class KeramikClient : public KDecoration class KeramikClient : public KDecoration
{ {
Q_OBJECT Q_OBJECT
public: public:
KeramikClient( KDecorationBridge* bridge, KDecorationFactory* factory ); KeramikClient( KDecorationBridge* bridge, KDecorationFactory* factory );
~KeramikClient(); ~KeramikClient();
virtual void init(); virtual void init();
virtual void reset( unsigned long changed );
virtual MousePosition mousePosition( const QPoint& p ) const; virtual MousePosition mousePosition( const QPoint& p ) const;
virtual void borders( int& left, int& right, int& top, int& bottom ) const; virtual void borders( int& left, int& right, int& top, int& bottom ) const;
virtual void resize( const QSize& s ); virtual void resize( const QSize& s );
@ -175,14 +168,9 @@ namespace Keramik {
return ( maximizeMode() & MaximizeVertical ); return ( maximizeMode() & MaximizeVertical );
} }
inline void setRectangle( QRegion& r, int x, int y, int w, int h ) {
r |= QRegion( x, y, w, h );
}
private slots: private slots:
void menuButtonPressed(); void menuButtonPressed();
void slotMaximize(); void slotMaximize();
void reset();
private: private:
QSpacerItem *topSpacer, *titlebar; QSpacerItem *topSpacer, *titlebar;