From 685e1d23611d0a4e801806ca9a20c499fd0a1e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 29 Jan 2008 16:44:41 +0000 Subject: [PATCH] Make it possible to use KDecorationOptions without private headers. svn path=/trunk/KDE/kdebase/workspace/; revision=768271 --- kcmkwin/kwindecoration/preview.cpp | 18 +++--- kcmkwin/kwindecoration/preview.h | 2 +- lib/kcommondecoration_p.h | 4 ++ lib/kdecoration.cpp | 98 ++++++++++++++++++++++-------- lib/kdecoration.h | 23 +++++++ lib/kdecoration_p.cpp | 26 ++++---- lib/kdecoration_p.h | 13 ++-- lib/kdecoration_plugins_p.h | 1 + options.cpp | 11 ++-- options.h | 2 +- tools/decobenchmark/preview.cpp | 6 +- tools/decobenchmark/preview.h | 2 +- 12 files changed, 132 insertions(+), 74 deletions(-) diff --git a/kcmkwin/kwindecoration/preview.cpp b/kcmkwin/kwindecoration/preview.cpp index afb69da544..cf74e9b3fa 100644 --- a/kcmkwin/kwindecoration/preview.cpp +++ b/kcmkwin/kwindecoration/preview.cpp @@ -436,36 +436,32 @@ KDecorationPreviewOptions::KDecorationPreviewOptions() customButtons = true; customTitleButtonsLeft.clear(); // invalid customTitleButtonsRight.clear(); // invalid - - d = new KDecorationOptionsPrivate; - d->defaultKWinSettings(); updateSettings(); } KDecorationPreviewOptions::~KDecorationPreviewOptions() { - delete d; } unsigned long KDecorationPreviewOptions::updateSettings() { KConfig cfg( "kwinrc" ); unsigned long changed = 0; - changed |= d->updateKWinSettings( &cfg ); + changed |= KDecorationOptions::updateSettings( &cfg ); // set custom border size/buttons if (customBorderSize != BordersCount) - d->border_size = customBorderSize; + setBorderSize( customBorderSize ); if (customButtonsChanged) - d->custom_button_positions = customButtons; + setCustomButtonPositions( customButtons ); if (customButtons) { if (!customTitleButtonsLeft.isNull() ) - d->title_buttons_left = customTitleButtonsLeft; + setTitleButtonsLeft( customTitleButtonsLeft ); if (!customTitleButtonsRight.isNull() ) - d->title_buttons_right = customTitleButtonsRight; + setTitleButtonsRight( customTitleButtonsRight ); } else { - d->title_buttons_left = KDecorationOptions::defaultTitleButtonsLeft(); - d->title_buttons_right = KDecorationOptions::defaultTitleButtonsRight(); + setTitleButtonsLeft( KDecorationOptions::defaultTitleButtonsLeft()); + setTitleButtonsRight( KDecorationOptions::defaultTitleButtonsRight()); } return changed; diff --git a/kcmkwin/kwindecoration/preview.h b/kcmkwin/kwindecoration/preview.h index 3cd089a0c0..ee5b03dbca 100644 --- a/kcmkwin/kwindecoration/preview.h +++ b/kcmkwin/kwindecoration/preview.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include diff --git a/lib/kcommondecoration_p.h b/lib/kcommondecoration_p.h index 55a018cd63..39e779114d 100644 --- a/lib/kcommondecoration_p.h +++ b/lib/kcommondecoration_p.h @@ -27,6 +27,10 @@ #include "kdecoration.h" +// +// This header file is internal. I mean it. +// + class KCommonDecoration; class KDecorationBridge; class KDecorationFactory; diff --git a/lib/kdecoration.cpp b/lib/kdecoration.cpp index a12eafdb11..45d173681e 100644 --- a/lib/kdecoration.cpp +++ b/lib/kdecoration.cpp @@ -346,7 +346,7 @@ void KDecoration::ungrabXServer() } KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const -{ + { const int range = 16; int bleft, bright, btop, bbottom; borders( bleft, bright, btop, bbottom ); @@ -378,9 +378,10 @@ KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const else m = PositionCenter; return m; -} + } KDecorationOptions::KDecorationOptions() + : d( new KDecorationOptionsPrivate ) { assert( KDecoration::options_ == NULL ); KDecoration::options_ = this; @@ -390,23 +391,24 @@ KDecorationOptions::~KDecorationOptions() { assert( KDecoration::options_ == this ); KDecoration::options_ = NULL; + delete d; } QColor KDecorationOptions::color(ColorType type, bool active) const -{ + { return(d->colors[type + (active ? 0 : NUM_COLORS)]); -} + } QFont KDecorationOptions::font(bool active, bool small) const -{ + { if ( small ) return(active ? d->activeFontSmall : d->inactiveFontSmall); else return(active ? d->activeFont : d->inactiveFont); -} + } QPalette KDecorationOptions::palette(ColorType type, bool active) const -{ + { int idx = type + (active ? 0 : NUM_COLORS); if(d->pal[idx]) return(*d->pal[idx]); @@ -420,56 +422,98 @@ QPalette KDecorationOptions::palette(ColorType type, bool active) const // base()); d->pal[idx] = new QPalette(d->colors[idx]); return(*d->pal[idx]); -} + } + +unsigned long KDecorationOptions::updateSettings( KConfig* config ) + { + return d->updateSettings( config ); + } bool KDecorationOptions::customButtonPositions() const -{ + { return d->custom_button_positions; -} + } QString KDecorationOptions::titleButtonsLeft() const -{ + { return d->title_buttons_left; -} + } QString KDecorationOptions::defaultTitleButtonsLeft() -{ + { return "MS"; -} + } QString KDecorationOptions::titleButtonsRight() const -{ + { return d->title_buttons_right; -} + } QString KDecorationOptions::defaultTitleButtonsRight() -{ + { return "HIA__X"; -} + } bool KDecorationOptions::showTooltips() const -{ + { return d->show_tooltips; -} + } KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const -{ + { assert( factory != NULL ); if( d->cached_border_size == BordersCount ) // invalid d->cached_border_size = d->findPreferredBorderSize( d->border_size, factory->borderSizes()); return d->cached_border_size; -} + } bool KDecorationOptions::moveResizeMaximizedWindows() const -{ + { return d->move_resize_maximized_windows; -} + } KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::MouseButtons button ) const { - return button == Qt::RightButton? d->OpMaxButtonRightClick : - button == Qt::MidButton? d->OpMaxButtonMiddleClick : - d->OpMaxButtonLeftClick; + return button == Qt::RightButton? d->opMaxButtonRightClick : + button == Qt::MidButton? d->opMaxButtonMiddleClick : + d->opMaxButtonLeftClick; } + +void KDecorationOptions::setOpMaxButtonLeftClick( WindowOperation op ) + { + d->opMaxButtonLeftClick = op; + } + +void KDecorationOptions::setOpMaxButtonRightClick( WindowOperation op ) + { + d->opMaxButtonRightClick = op; + } + +void KDecorationOptions::setOpMaxButtonMiddleClick( WindowOperation op ) + { + d->opMaxButtonMiddleClick = op; + } + +void KDecorationOptions::setBorderSize( BorderSize bs ) + { + d->border_size = bs; + d->cached_border_size = BordersCount; // invalid + } + +void KDecorationOptions::setCustomButtonPositions( bool b ) + { + d->custom_button_positions = b; + } + +void KDecorationOptions::setTitleButtonsLeft( const QString& b ) + { + d->title_buttons_left = b; + } + +void KDecorationOptions::setTitleButtonsRight( const QString& b ) + { + d->title_buttons_right = b; + } + #include "kdecoration.moc" diff --git a/lib/kdecoration.h b/lib/kdecoration.h index 1894208efe..15dec4c2fd 100644 --- a/lib/kdecoration.h +++ b/lib/kdecoration.h @@ -34,6 +34,8 @@ DEALINGS IN THE SOFTWARE. #define KWIN_EXPORT KDE_EXPORT +class KConfig; + /** @defgroup kdecoration KWin decorations library */ /** @addtogroup kdecoration */ @@ -205,6 +207,12 @@ class KWIN_EXPORT KDecorationOptions : public KDecorationDefines public: KDecorationOptions(); virtual ~KDecorationOptions(); + /** + * Call to update settings when the config changes. Return value is + * a combination of Setting* (SettingColors, etc.) that have changed. + * @since 4.0.1 + */ + unsigned long updateSettings( KConfig* config ); /** * Returns the color that should be used for the given part of the decoration. * The changed flags for this setting is SettingColors. @@ -316,6 +324,21 @@ public: virtual unsigned long updateSettings() = 0; // returns SettingXYZ mask protected: + /** @internal */ + void setOpMaxButtonLeftClick( WindowOperation op ); + /** @internal */ + void setOpMaxButtonRightClick( WindowOperation op ); + /** @internal */ + void setOpMaxButtonMiddleClick( WindowOperation op ); + /** @internal */ + void setBorderSize( BorderSize bs ); + /** @internal */ + void setCustomButtonPositions( bool b ); + /** @internal */ + void setTitleButtonsLeft( const QString& b ); + /** @internal */ + void setTitleButtonsRight( const QString& b ); +private: /** * @internal */ diff --git a/lib/kdecoration_p.cpp b/lib/kdecoration_p.cpp index e319a995fa..e36180221a 100644 --- a/lib/kdecoration_p.cpp +++ b/lib/kdecoration_p.cpp @@ -32,6 +32,16 @@ DEALINGS IN THE SOFTWARE. #include KDecorationOptionsPrivate::KDecorationOptionsPrivate() + : title_buttons_left( KDecorationOptions::defaultTitleButtonsLeft()) + , title_buttons_right( KDecorationOptions::defaultTitleButtonsRight()) + , custom_button_positions( false ) + , show_tooltips( true ) + , border_size( BorderNormal ) + , cached_border_size( BordersCount ) // invalid + , move_resize_maximized_windows( true ) + , opMaxButtonRightClick( MaximizeOp ) + , opMaxButtonMiddleClick( VMaximizeOp ) + , opMaxButtonLeftClick( HMaximizeOp ) { for(int i=0; i < NUM_COLORS*2; ++i) pal[i] = NULL; @@ -50,21 +60,7 @@ KDecorationOptionsPrivate::~KDecorationOptionsPrivate() } } -void KDecorationOptionsPrivate::defaultKWinSettings() - { - title_buttons_left = KDecorationOptions::defaultTitleButtonsLeft(); - title_buttons_right = KDecorationOptions::defaultTitleButtonsRight(); - custom_button_positions = false; - show_tooltips = true; - border_size = BorderNormal; - cached_border_size = BordersCount; // invalid - move_resize_maximized_windows = true; - OpMaxButtonRightClick = MaximizeOp; - OpMaxButtonMiddleClick = VMaximizeOp; - OpMaxButtonLeftClick = HMaximizeOp; - } - -unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config ) +unsigned long KDecorationOptionsPrivate::updateSettings( KConfig* config ) { unsigned long changed = 0; KConfigGroup wmConfig(config, "WM"); diff --git a/lib/kdecoration_p.h b/lib/kdecoration_p.h index 030f3a5622..f698d5e794 100644 --- a/lib/kdecoration_p.h +++ b/lib/kdecoration_p.h @@ -34,13 +34,12 @@ DEALINGS IN THE SOFTWARE. class KConfig; -class KWIN_EXPORT KDecorationOptionsPrivate : public KDecorationDefines +class KDecorationOptionsPrivate : public KDecorationDefines { public: KDecorationOptionsPrivate(); - virtual ~KDecorationOptionsPrivate(); - void defaultKWinSettings(); // shared implementation - unsigned long updateKWinSettings( KConfig* ); // shared implementation + ~KDecorationOptionsPrivate(); + unsigned long updateSettings( KConfig* ); // shared implementation BorderSize findPreferredBorderSize( BorderSize size, QList< BorderSize > ) const; // shared implementation QColor colors[NUM_COLORS*2]; @@ -52,9 +51,9 @@ class KWIN_EXPORT KDecorationOptionsPrivate : public KDecorationDefines bool show_tooltips; BorderSize border_size, cached_border_size; bool move_resize_maximized_windows; - WindowOperation OpMaxButtonRightClick; - WindowOperation OpMaxButtonMiddleClick; - WindowOperation OpMaxButtonLeftClick; + WindowOperation opMaxButtonRightClick; + WindowOperation opMaxButtonMiddleClick; + WindowOperation opMaxButtonLeftClick; }; #endif diff --git a/lib/kdecoration_plugins_p.h b/lib/kdecoration_plugins_p.h index 5aa8da04a3..91b7930a97 100644 --- a/lib/kdecoration_plugins_p.h +++ b/lib/kdecoration_plugins_p.h @@ -30,6 +30,7 @@ DEALINGS IN THE SOFTWARE. // This header file is internal. I mean it. // +// This private header is used by KWin core. #include #include diff --git a/options.cpp b/options.cpp index 8509d7aab2..33863b43cb 100644 --- a/options.cpp +++ b/options.cpp @@ -46,21 +46,18 @@ Options::Options() : electric_borders( 0 ), electric_border_delay(0) { - d = new KDecorationOptionsPrivate; - d->defaultKWinSettings(); updateSettings(); } Options::~Options() { - delete d; } unsigned long Options::updateSettings() { KSharedConfig::Ptr _config = KGlobal::config(); unsigned long changed = 0; - changed |= d->updateKWinSettings( _config.data() ); // read decoration settings + changed |= KDecorationOptions::updateSettings( _config.data() ); // read decoration settings KConfigGroup config(_config, "Windows"); moveMode = stringToMoveResizeMode( config.readEntry("MoveMode", "Opaque" )); @@ -145,9 +142,9 @@ unsigned long Options::updateSettings() electric_border_delay = config.readEntry("ElectricBorderDelay", 150); OpTitlebarDblClick = windowOperation( config.readEntry("TitlebarDoubleClickCommand", "Shade"), true ); - d->OpMaxButtonLeftClick = windowOperation( config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true ); - d->OpMaxButtonMiddleClick = windowOperation( config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true ); - d->OpMaxButtonRightClick = windowOperation( config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true ); + setOpMaxButtonLeftClick( windowOperation( config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true )); + setOpMaxButtonMiddleClick( windowOperation( config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true )); + setOpMaxButtonRightClick( windowOperation( config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true )); ignorePositionClasses = config.readEntry("IgnorePositionClasses",QStringList()); ignoreFocusStealingClasses = config.readEntry("IgnoreFocusStealingClasses",QStringList()); diff --git a/options.h b/options.h index de2e062fbd..f159e9a812 100644 --- a/options.h +++ b/options.h @@ -25,7 +25,7 @@ along with this program. If not, see . #include #include #include -#include +#include #include "placement.h" #include "utils.h" diff --git a/tools/decobenchmark/preview.cpp b/tools/decobenchmark/preview.cpp index fbcaae932d..0a173efd4b 100644 --- a/tools/decobenchmark/preview.cpp +++ b/tools/decobenchmark/preview.cpp @@ -384,21 +384,19 @@ void KDecorationPreviewBridge::grabXServer( bool ) KDecorationPreviewOptions::KDecorationPreviewOptions() { - d = new KDecorationOptionsPrivate; - d->defaultKWinSettings(); + defaultKWinSettings(); updateSettings(); } KDecorationPreviewOptions::~KDecorationPreviewOptions() { - delete d; } unsigned long KDecorationPreviewOptions::updateSettings() { KConfig cfg( "kwinrc", true ); unsigned long changed = 0; - changed |= d->updateKWinSettings( &cfg ); + changed |= KDecorationOptions::updateKWinSettings( &cfg ); return changed; } diff --git a/tools/decobenchmark/preview.h b/tools/decobenchmark/preview.h index 1785888b09..c627db0d67 100644 --- a/tools/decobenchmark/preview.h +++ b/tools/decobenchmark/preview.h @@ -21,7 +21,7 @@ #define KWINDECORATION_PREVIEW_H #include -#include +#include #include