Allows the decorations to specify which border sizes they support.
Also added GUI for the border size, not perfect, but it's there. svn path=/trunk/kdebase/kwin/; revision=253572
This commit is contained in:
parent
bfcadaa3de
commit
cefae8f1e4
11 changed files with 177 additions and 29 deletions
|
@ -64,16 +64,16 @@ Decoration::MousePosition Decoration::mousePosition( const QPoint& p ) const
|
|||
|
||||
void Decoration::borders( int& left, int& right, int& top, int& bottom ) const
|
||||
{
|
||||
if( options()->preferredBorderSize() == BorderTiny )
|
||||
if( options()->preferredBorderSize( factory()) == BorderTiny )
|
||||
{
|
||||
left = right = bottom = 1;
|
||||
top = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
left = right = options()->preferredBorderSize() * 5;
|
||||
top = options()->preferredBorderSize() * 10;
|
||||
bottom = options()->preferredBorderSize() * 2;
|
||||
left = right = options()->preferredBorderSize( factory()) * 5;
|
||||
top = options()->preferredBorderSize( factory()) * 10;
|
||||
bottom = options()->preferredBorderSize( factory()) * 2;
|
||||
}
|
||||
if( isShade())
|
||||
bottom = 0;
|
||||
|
|
|
@ -69,7 +69,7 @@ WebClient::init()
|
|||
QFontMetrics fm(options()->font(isActive(), isTool()));
|
||||
|
||||
// border size
|
||||
switch(options()->preferredBorderSize()) {
|
||||
switch(options()->preferredBorderSize( factory())) {
|
||||
case BorderLarge:
|
||||
borderSize_ = 8;
|
||||
break;
|
||||
|
@ -85,7 +85,6 @@ WebClient::init()
|
|||
case BorderOversized:
|
||||
borderSize_ = 40;
|
||||
break;
|
||||
case BorderTiny:
|
||||
case BorderNormal:
|
||||
default:
|
||||
borderSize_ = 4;
|
||||
|
@ -605,6 +604,12 @@ bool WebFactory::reset(unsigned long changed)
|
|||
}
|
||||
}
|
||||
|
||||
QValueList< WebFactory::BorderSize > WebFactory::borderSizes() const
|
||||
{ // the list must be sorted
|
||||
return QValueList< BorderSize >() << BorderNormal << BorderLarge <<
|
||||
BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "Web.moc"
|
||||
|
|
|
@ -120,6 +120,7 @@ namespace Web
|
|||
virtual ~WebFactory() {};
|
||||
virtual KDecoration* createDecoration( KDecorationBridge* );
|
||||
virtual bool reset( unsigned long changed );
|
||||
virtual QValueList< BorderSize > borderSizes() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <qdir.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qlayout.h>
|
||||
|
@ -39,6 +40,7 @@
|
|||
#include <qvbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qfile.h>
|
||||
#include <qslider.h>
|
||||
|
||||
#include <kapplication.h>
|
||||
#include <kcombobox.h>
|
||||
|
@ -55,6 +57,7 @@
|
|||
#include "kwindecoration.h"
|
||||
#include "preview.h"
|
||||
#include <kdecoration_plugins_p.h>
|
||||
#include <kdecorationfactory.h>
|
||||
|
||||
// KCModule plugin interface
|
||||
// =========================
|
||||
|
@ -121,6 +124,13 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const char* name, co
|
|||
i18n( "Enabling this checkbox will show window button tooltips. "
|
||||
"If this checkbox is off, no window button tooltips will be shown."));
|
||||
|
||||
lBorder = new QLabel( buttonPage );
|
||||
slBorder = new QSlider( Horizontal, buttonPage );
|
||||
QWhatsThis::add( slBorder, i18n( "This slider shows all border sizes supported by this decoration." ));
|
||||
lBorder->setBuddy( slBorder );
|
||||
lBorder->hide();
|
||||
slBorder->hide();
|
||||
|
||||
cbUseCustomButtonPositions = new QCheckBox(
|
||||
i18n("Use custom titlebar button &positions"), buttonPage );
|
||||
QWhatsThis::add( cbUseCustomButtonPositions,
|
||||
|
@ -159,6 +169,7 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const char* name, co
|
|||
connect( cbUseCustomButtonPositions, SIGNAL(clicked()), SLOT(slotSelectionChanged()) );
|
||||
connect(cbUseCustomButtonPositions, SIGNAL(toggled(bool)), buttonBox, SLOT(setEnabled(bool)));
|
||||
connect( cbShowToolTips, SIGNAL(clicked()), SLOT(slotSelectionChanged()) );
|
||||
connect( slBorder, SIGNAL( valueChanged( int )), SLOT( slotBorderChanged( int )));
|
||||
// connect( cbUseMiniWindows, SIGNAL(clicked()), SLOT(slotSelectionChanged()) );
|
||||
|
||||
// Allow kwin dcop signal to update our selection list
|
||||
|
@ -239,6 +250,52 @@ void KWinDecorationModule::slotSelectionChanged()
|
|||
setChanged(true);
|
||||
}
|
||||
|
||||
static const char* const border_names[ KDecorationDefines::BordersCount ] =
|
||||
{
|
||||
I18N_NOOP( "Border size: Tiny" ),
|
||||
I18N_NOOP( "Border size: Normal" ),
|
||||
I18N_NOOP( "Border size: Large" ),
|
||||
I18N_NOOP( "Border size: Very Large" ),
|
||||
I18N_NOOP( "Border size: Huge" ),
|
||||
I18N_NOOP( "Border size: Very Huge" ),
|
||||
I18N_NOOP( "Border size: Oversized" )
|
||||
};
|
||||
|
||||
int KWinDecorationModule::borderSizeToIndex( BorderSize size, QValueList< BorderSize > sizes )
|
||||
{
|
||||
int pos = 0;
|
||||
for( QValueList< BorderSize >::ConstIterator it = sizes.begin();
|
||||
it != sizes.end();
|
||||
++it, ++pos )
|
||||
if( size <= *it )
|
||||
break;
|
||||
return pos;
|
||||
}
|
||||
|
||||
KDecorationDefines::BorderSize KWinDecorationModule::indexToBorderSize( int index,
|
||||
QValueList< BorderSize > sizes )
|
||||
{
|
||||
QValueList< BorderSize >::ConstIterator it = sizes.begin();
|
||||
for(;
|
||||
it != sizes.end();
|
||||
++it, --index )
|
||||
if( index == 0 )
|
||||
break;
|
||||
return *it;
|
||||
}
|
||||
|
||||
void KWinDecorationModule::slotBorderChanged( int size )
|
||||
{
|
||||
if( lBorder->isHidden())
|
||||
return;
|
||||
setChanged( true );
|
||||
QValueList< BorderSize > sizes;
|
||||
if( plugins->factory() != NULL )
|
||||
sizes = plugins->factory()->borderSizes();
|
||||
assert( sizes.count() >= 2 );
|
||||
border_size = indexToBorderSize( size, sizes );
|
||||
lBorder->setText( i18n( border_names[ border_size ] ));
|
||||
}
|
||||
|
||||
QString KWinDecorationModule::decorationName( QString& libName )
|
||||
{
|
||||
|
@ -298,7 +355,9 @@ void KWinDecorationModule::resetPlugin( KConfig* conf, const QString& currentDec
|
|||
else
|
||||
preview->disablePreview();
|
||||
plugins->destroyPreviousPlugin();
|
||||
|
||||
|
||||
checkSupportedBorderSizes();
|
||||
|
||||
currentName = styleToConfigLib( currentName );
|
||||
|
||||
// Delete old plugin widget if it exists
|
||||
|
@ -392,6 +451,13 @@ void KWinDecorationModule::readConfig( KConfig* conf )
|
|||
for(i = 0; i < dropSite->buttonsRight.length(); i++)
|
||||
buttonSource->hideButton( dropSite->buttonsRight[i].latin1() );
|
||||
|
||||
int bsize = conf->readNumEntry( "BorderSize", BorderNormal );
|
||||
if( bsize >= BorderTiny && bsize < BordersCount )
|
||||
border_size = static_cast< BorderSize >( bsize );
|
||||
else
|
||||
border_size = BorderNormal;
|
||||
checkSupportedBorderSizes();
|
||||
|
||||
setChanged(false);
|
||||
}
|
||||
|
||||
|
@ -414,6 +480,7 @@ void KWinDecorationModule::writeConfig( KConfig* conf )
|
|||
// Button settings
|
||||
conf->writeEntry("ButtonsOnLeft", dropSite->buttonsLeft );
|
||||
conf->writeEntry("ButtonsOnRight", dropSite->buttonsRight );
|
||||
conf->writeEntry("BorderSize", border_size );
|
||||
|
||||
oldLibraryName = currentLibraryName;
|
||||
currentLibraryName = libName;
|
||||
|
@ -484,11 +551,31 @@ void KWinDecorationModule::defaults()
|
|||
buttonSource->hideButton('I');
|
||||
buttonSource->hideButton('A');
|
||||
buttonSource->hideButton('X');
|
||||
|
||||
border_size = BorderNormal;
|
||||
checkSupportedBorderSizes();
|
||||
|
||||
// Set plugin defaults
|
||||
emit pluginDefaults();
|
||||
}
|
||||
|
||||
void KWinDecorationModule::checkSupportedBorderSizes()
|
||||
{
|
||||
QValueList< BorderSize > sizes;
|
||||
slBorder->hide();
|
||||
lBorder->hide();
|
||||
if( plugins->factory() != NULL )
|
||||
sizes = plugins->factory()->borderSizes();
|
||||
if( sizes.count() < 2 )
|
||||
return;
|
||||
slBorder->setRange( 0, sizes.count() - 1 );
|
||||
int pos = borderSizeToIndex( border_size, sizes );
|
||||
lBorder->show();
|
||||
slBorder->show();
|
||||
slBorder->setValue( pos );
|
||||
slotBorderChanged( pos );
|
||||
}
|
||||
|
||||
QString KWinDecorationModule::styleToConfigLib( QString& styleLib )
|
||||
{
|
||||
if( styleLib.startsWith( "kwin3_" ))
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include <kconfig.h>
|
||||
#include <klibloader.h>
|
||||
|
||||
#include <kdecoration.h>
|
||||
|
||||
#include "kwindecorationIface.h"
|
||||
|
||||
class KComboBox;
|
||||
|
@ -45,6 +47,7 @@ class QCheckBox;
|
|||
class QLabel;
|
||||
class QTabWidget;
|
||||
class QVBox;
|
||||
class QSlider;
|
||||
|
||||
class KDecorationPlugins;
|
||||
class KDecorationPreview;
|
||||
|
@ -57,7 +60,7 @@ struct DecorationInfo
|
|||
};
|
||||
|
||||
|
||||
class KWinDecorationModule : public KCModule, virtual public KWinDecorationIface
|
||||
class KWinDecorationModule : public KCModule, virtual public KWinDecorationIface, public KDecorationDefines
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -83,6 +86,7 @@ class KWinDecorationModule : public KCModule, virtual public KWinDecorationIface
|
|||
// Allows us to turn "save" on
|
||||
void slotSelectionChanged();
|
||||
void slotChangeDecoration( const QString & );
|
||||
void slotBorderChanged( int );
|
||||
|
||||
private:
|
||||
void readConfig( KConfig* conf );
|
||||
|
@ -95,6 +99,9 @@ class KWinDecorationModule : public KCModule, virtual public KWinDecorationIface
|
|||
static QString styleToConfigLib( QString& styleLib );
|
||||
void resetPlugin( KConfig* conf, const QString& currentDecoName = QString::null );
|
||||
void resetKWin();
|
||||
void checkSupportedBorderSizes();
|
||||
static int borderSizeToIndex( BorderSize size, QValueList< BorderSize > sizes );
|
||||
static BorderSize indexToBorderSize( int index, QValueList< BorderSize > sizes );
|
||||
|
||||
QTabWidget* tabWidget;
|
||||
|
||||
|
@ -109,6 +116,9 @@ class KWinDecorationModule : public KCModule, virtual public KWinDecorationIface
|
|||
QCheckBox* cbUseCustomButtonPositions;
|
||||
// QCheckBox* cbUseMiniWindows;
|
||||
QCheckBox* cbShowToolTips;
|
||||
QLabel* lBorder;
|
||||
QSlider* slBorder;
|
||||
BorderSize border_size;
|
||||
|
||||
QObject* pluginObject;
|
||||
QLabel* pluginSettingsLbl;
|
||||
|
|
|
@ -370,9 +370,13 @@ bool KDecorationOptions::showTooltips() const
|
|||
return d->show_tooltips;
|
||||
}
|
||||
|
||||
KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize() const
|
||||
KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
|
||||
{
|
||||
return d->border_size;
|
||||
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
|
||||
|
|
|
@ -122,7 +122,8 @@ public:
|
|||
BorderVeryLarge, ///< Very large borders
|
||||
BorderHuge, ///< Huge borders
|
||||
BorderVeryHuge, ///< Very huge borders
|
||||
BorderOversized ///< Oversized borders
|
||||
BorderOversized, ///< Oversized borders
|
||||
BordersCount ///< @internal
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -208,9 +209,13 @@ public:
|
|||
* The preferred border size selected by the user, e.g. for accessibility
|
||||
* reasons, or when using high resolution displays. It's up to the decoration
|
||||
* to decide which borders or if any borders at all will obey this setting.
|
||||
* It is guaranteed that the returned value will be one of those
|
||||
* returned by KDecorationFactory::borderSizes(), so if that one hasn't been
|
||||
* reimplemented, BorderNormal is always returned.
|
||||
* The changed flags for this setting is SettingBorder.
|
||||
* @param factory the decoration factory used
|
||||
*/
|
||||
BorderSize preferredBorderSize() const;
|
||||
BorderSize preferredBorderSize( KDecorationFactory* factory ) const;
|
||||
|
||||
/*
|
||||
* When this functions returns false, moving and resizing of maximized windows
|
||||
|
|
|
@ -27,23 +27,26 @@ DEALINGS IN THE SOFTWARE.
|
|||
#include <kconfig.h>
|
||||
#include <qpalette.h>
|
||||
#include <qapplication.h>
|
||||
#include <assert.h>
|
||||
|
||||
KDecorationOptionsPrivate::KDecorationOptionsPrivate()
|
||||
{
|
||||
{
|
||||
for(int i=0; i < NUM_COLORS*2; ++i)
|
||||
cg[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
KDecorationOptionsPrivate::~KDecorationOptionsPrivate()
|
||||
{
|
||||
{
|
||||
int i;
|
||||
for(i=0; i < NUM_COLORS*2; ++i){
|
||||
if(cg[i]){
|
||||
for(i=0; i < NUM_COLORS*2; ++i)
|
||||
{
|
||||
if(cg[i])
|
||||
{
|
||||
delete cg[i];
|
||||
cg[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KDecorationOptionsPrivate::defaultKWinSettings()
|
||||
{
|
||||
|
@ -52,11 +55,12 @@ void KDecorationOptionsPrivate::defaultKWinSettings()
|
|||
custom_button_positions = false;
|
||||
show_tooltips = true;
|
||||
border_size = BorderNormal;
|
||||
cached_border_size = BordersCount; // invalid
|
||||
move_resize_maximized_windows = true;
|
||||
}
|
||||
|
||||
unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
|
||||
{
|
||||
{
|
||||
unsigned long changed = 0;
|
||||
QString old_group = config->group();
|
||||
config->setGroup( "WM" );
|
||||
|
@ -161,14 +165,16 @@ unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
|
|||
QString old_title_buttons_right = title_buttons_right;
|
||||
bool old_custom_button_positions = custom_button_positions;
|
||||
custom_button_positions = config->readBoolEntry("CustomButtonPositions", false);
|
||||
if (custom_button_positions) {
|
||||
if (custom_button_positions)
|
||||
{
|
||||
title_buttons_left = config->readEntry("ButtonsOnLeft", "MS");
|
||||
title_buttons_right = config->readEntry("ButtonsOnRight", "HIAX");
|
||||
}
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
title_buttons_left = "MS";
|
||||
title_buttons_right = "HIAX";
|
||||
}
|
||||
}
|
||||
if( old_custom_button_positions != custom_button_positions
|
||||
|| ( custom_button_positions &&
|
||||
( old_title_buttons_left != title_buttons_left
|
||||
|
@ -185,12 +191,13 @@ unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
|
|||
|
||||
BorderSize old_border_size = border_size;
|
||||
int border_size_num = config->readNumEntry( "BorderSize", BorderNormal );
|
||||
if( border_size_num >= BorderTiny && border_size_num <= BorderOversized )
|
||||
if( border_size_num >= 0 && border_size_num < BordersCount )
|
||||
border_size = static_cast< BorderSize >( border_size_num );
|
||||
else
|
||||
border_size = BorderNormal;
|
||||
if( old_border_size != border_size )
|
||||
changed |= SettingBorder;
|
||||
cached_border_size = BordersCount; // invalid
|
||||
|
||||
config->setGroup( "Windows" );
|
||||
bool old_move_resize_maximized_windows = move_resize_maximized_windows;
|
||||
|
@ -200,14 +207,27 @@ unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config )
|
|||
|
||||
// destroy cached values
|
||||
int i;
|
||||
for(i=0; i < NUM_COLORS*2; ++i){
|
||||
if(cg[i]){
|
||||
for(i=0; i < NUM_COLORS*2; ++i)
|
||||
{
|
||||
if(cg[i])
|
||||
{
|
||||
delete cg[i];
|
||||
cg[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config->setGroup( old_group );
|
||||
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
||||
KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize( BorderSize size,
|
||||
QValueList< BorderSize > sizes ) const
|
||||
{
|
||||
for( QValueList< BorderSize >::ConstIterator it = sizes.begin();
|
||||
it != sizes.end();
|
||||
++it )
|
||||
if( size <= *it ) // size is either a supported size, or *it is the closest larger supported
|
||||
return *it;
|
||||
return sizes.last(); // size is larger than all supported ones, return largest
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include "kdecoration.h"
|
||||
#include <qwidget.h>
|
||||
#include <qvaluelist.h>
|
||||
|
||||
class KConfig;
|
||||
|
||||
|
@ -41,6 +42,7 @@ class KDecorationOptionsPrivate : public KDecorationDefines
|
|||
virtual ~KDecorationOptionsPrivate();
|
||||
void defaultKWinSettings(); // shared implementation
|
||||
unsigned long updateKWinSettings( KConfig* ); // shared implementation
|
||||
BorderSize findPreferredBorderSize( BorderSize size, QValueList< BorderSize > ) const; // shared implementation
|
||||
|
||||
QColor colors[NUM_COLORS*2];
|
||||
QColorGroup *cg[NUM_COLORS*2];
|
||||
|
@ -49,7 +51,7 @@ class KDecorationOptionsPrivate : public KDecorationDefines
|
|||
QString title_buttons_right;
|
||||
bool custom_button_positions;
|
||||
bool show_tooltips;
|
||||
BorderSize border_size;
|
||||
BorderSize border_size, cached_border_size;
|
||||
bool move_resize_maximized_windows;
|
||||
};
|
||||
|
||||
|
|
|
@ -45,6 +45,11 @@ bool KDecorationFactory::supports( Ability )
|
|||
return false;
|
||||
}
|
||||
|
||||
QValueList< KDecorationDefines::BorderSize > KDecorationFactory::borderSizes() const
|
||||
{
|
||||
return QValueList< BorderSize >() << BorderNormal;
|
||||
}
|
||||
|
||||
void KDecorationFactory::addDecoration( KDecoration* deco )
|
||||
{
|
||||
_decorations.append( deco );
|
||||
|
|
|
@ -62,6 +62,15 @@ class KDecorationFactory
|
|||
* Note that true should be returned only when really necessary.
|
||||
*/
|
||||
virtual bool reset( unsigned long changed ); // returns true if the decoration needs to be recreated
|
||||
|
||||
/**
|
||||
* Reimplement this function if your decoration supports more border sizes than
|
||||
* the default one (BorderNormal). The returned list must contain all supported
|
||||
* sizes, ordered from the smallest to the largest one. By default, only
|
||||
* BorderNormal is returned.
|
||||
*/
|
||||
virtual QValueList< BorderSize > borderSizes() const;
|
||||
|
||||
virtual bool supports( Ability ability );
|
||||
/**
|
||||
* Returns the KDecorationOptions object, which is used to access
|
||||
|
|
Loading…
Reference in a new issue