From 57f4808d0f9022554b147bd2b5028c10a6b18c3a Mon Sep 17 00:00:00 2001 From: Waldo Bastian Date: Sun, 22 Apr 2001 05:39:17 +0000 Subject: [PATCH] Make resource management in clients easier with these three functions: init() called after client got loaded deinit() called when client is about to get unloaded reset() called once before Options::resetClients() is emitted svn path=/trunk/kdebase/kwin/; revision=93372 --- clients/b2/b2client.cpp | 65 ++++++++++++++++++++++++----- clients/kde1/kde1client.cpp | 39 +++++++++++------ clients/kstep/nextclient.cpp | 32 +++++++++----- clients/kwmtheme/kwmthemeclient.cpp | 44 +++++++++++-------- clients/laptop/laptopclient.cpp | 62 +++++++++++++++++---------- clients/modernsystem/modernsys.cpp | 32 +++++++++----- clients/mwm/mwmclient.cpp | 35 +++++++++++----- clients/quartz/quartz.cpp | 36 +++++++++------- clients/riscos/Manager.cpp | 14 ++++++- clients/system/systemclient.cpp | 32 +++++++++----- clients/win2k/win2k.cpp | 34 +++++++++------ options.cpp | 1 + options.h | 1 + plugins.cpp | 15 +++++++ plugins.h | 1 + workspace.cpp | 1 + 16 files changed, 312 insertions(+), 132 deletions(-) diff --git a/clients/b2/b2client.cpp b/clients/b2/b2client.cpp index d205aa5aa6..b26e9b4733 100644 --- a/clients/b2/b2client.cpp +++ b/clients/b2/b2client.cpp @@ -15,16 +15,9 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w, int) - { - return(new B2Client(ws, w)); - } -} // TODO: stick all these in an array -static KPixmap *aClosePix=0, *aClosePixDown; +static KPixmap *aClosePix, *aClosePixDown; static KPixmap *iClosePix, *iClosePixDown; static KPixmap *aMaxPix, *aMaxPixDown; static KPixmap *iMaxPix, *iMaxPixDown; @@ -76,7 +69,6 @@ static void redraw_pixmaps(); QPixmap* kwin_get_menu_pix_hack() { - create_pixmaps(); //return menu_pix; FIXME return aMenuPix; } @@ -175,6 +167,40 @@ static void create_pixmaps() redraw_pixmaps(); } +static void delete_pixmaps() +{ + delete aClosePix; + delete aClosePixDown; + delete iClosePix; + delete iClosePixDown; + delete aMaxPix; + delete aMaxPixDown; + delete iMaxPix; + delete iMaxPixDown; + delete aNormalizePix; + delete aNormalizePixDown; + delete iNormalizePix; + delete iNormalizePixDown; + delete aIconifyPix; + delete aIconifyPixDown; + delete iIconifyPix; + delete iIconifyPixDown; + delete aPinupPix; + delete aPinupPixDown; + delete iPinupPix; + delete iPinupPixDown; + delete aMenuPix; + delete aMenuPixDown; + delete iMenuPix; + delete iMenuPixDown; + delete aHelpPix; + delete aHelpPixDown; + delete iHelpPix; + delete iHelpPixDown; + + pixmaps_created = false; +} + B2Button::B2Button(KPixmap *pix, KPixmap *pixDown, KPixmap *iPix, KPixmap *iPixDown, Client *_client, QWidget *parent, const char *name) @@ -436,7 +462,6 @@ B2Client::B2Client( Workspace *ws, WId w, QWidget *parent, bar_x_ofs = 0; in_unobs = 0; - create_pixmaps(); g = new QGridLayout( this, 0, 0); g->addMultiCellWidget(windowWrapper(), 1, 1, 1, 2); @@ -1017,4 +1042,24 @@ void B2Client::positionButtons() titlebar->move(bar_x_ofs, 0); } +extern "C" +{ + Client *allocate(Workspace *ws, WId w, int) + { + return(new B2Client(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + redraw_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} + #include "b2client.moc" diff --git a/clients/kde1/kde1client.cpp b/clients/kde1/kde1client.cpp index 30dc1cb3a4..1767ce09bf 100644 --- a/clients/kde1/kde1client.cpp +++ b/clients/kde1/kde1client.cpp @@ -22,15 +22,6 @@ Copyright (C) 1999, 2000 Matthias Ettrich using namespace KWinInternal; -extern "C" -{ - Client * allocate(Workspace * workSpace, WId winId, int tool ) - { - if ( tool ) - return new StdToolClient( workSpace, winId ); - return new StdClient(workSpace, winId); - } -} static QPixmap* close_pix = 0; @@ -147,7 +138,7 @@ static void create_pixmaps() question_mark_pix->setMask(QBitmap(16, 16, help_mask_bits, true)); } -void StdClient::slotReset() +static void delete_pixmaps() { delete close_pix; delete maximize_pix; @@ -165,8 +156,10 @@ void StdClient::slotReset() delete dis_menu_pix; delete question_mark_pix; pixmaps_created = false; - create_pixmaps(); +} +void StdClient::slotReset() +{ if(miniIcon().isNull()) button[0]->setIconSet(isActive() ? *menu_pix : *dis_menu_pix); button[1]->setIconSet(isSticky() ? isActive() ? *pindown_pix : *dis_pindown_pix : @@ -184,7 +177,6 @@ void StdClient::slotReset() StdClient::StdClient( Workspace *ws, WId w, QWidget *parent, const char *name ) : Client( ws, w, parent, name, WResizeNoErase ) { - create_pixmaps(); setFont(options->font(isActive() )); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); @@ -507,7 +499,6 @@ void StdToolClient::activeChange( bool on ) void StdToolClient::slotReset() { - create_pixmaps(); QImage img = close_pix->convertToImage(); img = img.smoothScale( 12, 12 ); QPixmap pm; @@ -516,6 +507,28 @@ void StdToolClient::slotReset() setFont(options->font(isActive(), true )); } +extern "C" +{ + Client * allocate(Workspace * workSpace, WId winId, int tool ) + { + if ( tool ) + return new StdToolClient( workSpace, winId ); + return new StdClient(workSpace, winId); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} #include "kde1client.moc" diff --git a/clients/kstep/nextclient.cpp b/clients/kstep/nextclient.cpp index 8856463a48..eac411ca34 100644 --- a/clients/kstep/nextclient.cpp +++ b/clients/kstep/nextclient.cpp @@ -13,13 +13,6 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w, int ) - { - return(new NextClient(ws, w)); - } -} static unsigned char close_bits[] = { @@ -160,7 +153,7 @@ static void create_pixmaps() btnForeground = new QColor(Qt::white); } -void delete_pixmaps() +static void delete_pixmaps() { delete aTitlePix; delete iTitlePix; @@ -179,8 +172,6 @@ void delete_pixmaps() void NextClient::slotReset() { - delete_pixmaps(); - create_pixmaps(); button[0]->reset(); button[1]->reset(); button[2]->reset(); @@ -226,7 +217,6 @@ NextClient::NextClient( Workspace *ws, WId w, QWidget *parent, : Client( ws, w, parent, name, WResizeNoErase ) { setBackgroundMode( NoBackground ); - create_pixmaps(); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); QVBoxLayout *mainLayout = new QVBoxLayout(this); @@ -377,5 +367,25 @@ NextClient::mousePosition( const QPoint& p ) const return m; } +extern "C" +{ + Client *allocate(Workspace *ws, WId w, int ) + { + return(new NextClient(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} #include "nextclient.moc" diff --git a/clients/kwmtheme/kwmthemeclient.cpp b/clients/kwmtheme/kwmthemeclient.cpp index f2cdcffeaa..b2b75096d3 100644 --- a/clients/kwmtheme/kwmthemeclient.cpp +++ b/clients/kwmtheme/kwmthemeclient.cpp @@ -20,13 +20,6 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w) - { - return(new KWMThemeClient(ws, w)); - } -} static QPixmap stretchPixmap(QPixmap& src, bool stretchVert){ QPixmap dest; @@ -85,7 +78,7 @@ static bool pixmaps_created = false; static bool titleSunken = false; static bool titleTransparent; -static void init_theme() +static void create_pixmaps() { const char *keys[] = {"wm_top", "wm_bottom", "wm_left", "wm_right", "wm_topleft", "wm_topright", "wm_bottomleft", "wm_bottomright"}; @@ -209,13 +202,9 @@ static void init_theme() } } -void -KWMThemeClient::slotReset() +static void delete_pixmaps() { - if (!pixmaps_created) return; - pixmaps_created = false; - - for(int i=0; i < 8; ++i) + for(int i=0; i < 8; ++i) delete framePixmaps[i]; delete menuPix; @@ -233,8 +222,11 @@ KWMThemeClient::slotReset() titleGradient = true; pixmaps_created = false; titleSunken = false; +} + +void KWMThemeClient::slotReset() +{ - init_theme(); } void MyButton::drawButtonLabel(QPainter *p) @@ -250,7 +242,6 @@ KWMThemeClient::KWMThemeClient( Workspace *ws, WId w, QWidget *parent, : Client( ws, w, parent, name, WResizeNoErase | WNorthWestGravity) { stickyBtn = maxBtn = mnuBtn = 0; - init_theme(); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); QGridLayout *layout = new QGridLayout(this); layout->addColSpacing(0, maxExtent); @@ -797,6 +788,25 @@ void KWMThemeClient::init() // } - +extern "C" +{ + Client *allocate(Workspace *ws, WId w) + { + return(new KWMThemeClient(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} #include "kwmthemeclient.moc" diff --git a/clients/laptop/laptopclient.cpp b/clients/laptop/laptopclient.cpp index c50dc41e1f..47511ebfb0 100644 --- a/clients/laptop/laptopclient.cpp +++ b/clients/laptop/laptopclient.cpp @@ -18,13 +18,6 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w, int) - { - return(new LaptopClient(ws, w)); - } -} static unsigned char iconify_bits[] = { @@ -210,6 +203,24 @@ static void create_pixmaps() btnForeground = Qt::white; } +static void delete_pixmaps() +{ + delete titlePix; + if(aUpperGradient){ + delete aUpperGradient; + delete iUpperGradient; + delete btnPix1; + delete btnDownPix1; + delete iBtnPix1; + delete iBtnDownPix1; + delete btnPix2; + delete btnDownPix2; + delete iBtnPix2; + delete iBtnDownPix2; + } + pixmaps_created = false; +} + LaptopClientButton::LaptopClientButton(int w, int h, Client *parent, const char *name, const unsigned char *bitmap) @@ -280,21 +291,6 @@ void LaptopClientButton::drawButton(QPainter *p) void LaptopClient::slotReset() { - delete titlePix; - if(aUpperGradient){ - delete aUpperGradient; - delete iUpperGradient; - delete btnPix1; - delete btnDownPix1; - delete iBtnPix1; - delete iBtnDownPix1; - delete btnPix2; - delete btnDownPix2; - delete iBtnPix2; - delete iBtnDownPix2; - } - pixmaps_created = false; - create_pixmaps(); int i; for(i=0; i < 5; ++i){ if(button[i]) @@ -310,7 +306,6 @@ LaptopClient::LaptopClient( Workspace *ws, WId w, QWidget *parent, lastButtonWidth = 0; lastBufferWidth = 0; - create_pixmaps(); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); bool help = providesContextHelp(); @@ -685,4 +680,25 @@ LaptopClient::mousePosition( const QPoint& p ) const return m; } +extern "C" +{ + Client *allocate(Workspace *ws, WId w, int) + { + return(new LaptopClient(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} + #include "laptopclient.moc" diff --git a/clients/modernsystem/modernsys.cpp b/clients/modernsystem/modernsys.cpp index 714a4357f1..dc26ea4a81 100644 --- a/clients/modernsystem/modernsys.cpp +++ b/clients/modernsystem/modernsys.cpp @@ -18,13 +18,6 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w, int) - { - return(new ModernSys(ws, w)); - } -} static unsigned char iconify_bits[] = { @@ -249,8 +242,6 @@ void ModernButton::mouseReleaseEvent( QMouseEvent* e ) void ModernSys::slotReset() { - delete_pixmaps(); - create_pixmaps(); titleBuffer.resize(0, 0); recalcTitleBuffer(); button[0]->reset(); @@ -266,7 +257,6 @@ ModernSys::ModernSys( Workspace *ws, WId w, QWidget *parent, const char *name ) : Client( ws, w, parent, name, WResizeNoErase ) { - create_pixmaps(); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); bool help = providesContextHelp(); @@ -568,4 +558,26 @@ Client::MousePosition ModernSys::mousePosition( const QPoint& p) const } return m; } + +extern "C" +{ + Client *allocate(Workspace *ws, WId w, int) + { + return(new ModernSys(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} + #include "modernsys.moc" diff --git a/clients/mwm/mwmclient.cpp b/clients/mwm/mwmclient.cpp index 06738bc423..098e0d0483 100644 --- a/clients/mwm/mwmclient.cpp +++ b/clients/mwm/mwmclient.cpp @@ -13,13 +13,6 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w) - { - return(new MwmClient(ws, w)); - } -} static unsigned char close_bits[] = { @@ -93,7 +86,7 @@ static void create_pixmaps() KPixmapEffect::VerticalGradient); } -void MwmClient::slotReset() +static void delete_pixmaps() { delete aTitlePix; delete iTitlePix; @@ -102,7 +95,10 @@ void MwmClient::slotReset() delete aHandlePix; delete iHandlePix; pixmaps_created = false; - create_pixmaps(); +} + +void MwmClient::slotReset() +{ button[0]->reset(); button[1]->reset(); button[2]->reset(); @@ -194,7 +190,6 @@ MwmClient::MwmClient( Workspace *ws, WId w, QWidget *parent, const char *name ) : Client( ws, w, parent, name, WResizeNoErase ) { - create_pixmaps(); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); QVBoxLayout *mainLayout = new QVBoxLayout(this); @@ -320,5 +315,25 @@ void MwmClient::init() Client::init(); } +extern "C" +{ + Client *allocate(Workspace *ws, WId w) + { + return(new MwmClient(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} #include "mwmclient.moc" diff --git a/clients/quartz/quartz.cpp b/clients/quartz/quartz.cpp index 106aa5fe16..02675ea21d 100644 --- a/clients/quartz/quartz.cpp +++ b/clients/quartz/quartz.cpp @@ -24,13 +24,6 @@ using namespace KWinInternal; -extern "C" -{ - Client *allocate(Workspace *ws, WId w, int) - { - return(new QuartzClient(ws, w)); - } -} static const char *kdelogo[] = { /* columns rows colors chars-per-pixel */ @@ -186,7 +179,7 @@ static void create_pixmaps() drawBlocks( ititleBlocks, *ititleBlocks, c, c2 ); } -void delete_pixmaps() +static void delete_pixmaps() { btnPix1 = new KPixmap; iBtnPix1 = new KPixmap; @@ -328,9 +321,6 @@ QuartzClient::QuartzClient( Workspace *ws, WId w, QWidget *parent, lastButtonWidth = 0; - // Create the button and titlebar pixmaps - create_pixmaps(); - // Pack the windowWrapper() window within a grid QGridLayout* g = new QGridLayout(this, 0, 0, 0); g->setResizeMode(QLayout::FreeResize); @@ -395,9 +385,6 @@ QuartzClient::QuartzClient( Workspace *ws, WId w, QWidget *parent, void QuartzClient::slotReset() { - delete_pixmaps(); - create_pixmaps(); - // ( 4 buttons - Help, Max, Iconify, Close ) for(int i = QuartzClient::BtnHelp; i <= QuartzClient::BtnClose; i++) if(button[i]) @@ -668,4 +655,25 @@ void QuartzClient::menuButtonPressed() tc = this; } +extern "C" +{ + Client *allocate(Workspace *ws, WId w, int) + { + return(new QuartzClient(ws, w)); + } + void init() + { + create_pixmaps(); + } + void reset() + { + delete_pixmaps(); + create_pixmaps(); + } + void deinit() + { + delete_pixmaps(); + } +} + #include "quartz.moc" diff --git a/clients/riscos/Manager.cpp b/clients/riscos/Manager.cpp index 8f3f72ace2..9756420f2b 100644 --- a/clients/riscos/Manager.cpp +++ b/clients/riscos/Manager.cpp @@ -52,6 +52,19 @@ extern "C" else return new RiscOS::Manager(workSpace, winId); } + void init() + { + (void) RiscOS::Static::instance(); + } + void reset() + { + RiscOS::Static::instance()->update(); + } + void deinit() + { + delete RiscOS::Static::instance(); + } + } using namespace KWinInternal; @@ -343,7 +356,6 @@ Manager::slotReset() { for (QDictIterator