diff --git a/kcmkwin/kwinoptions/mouse.cpp b/kcmkwin/kwinoptions/mouse.cpp index a375993ad3..312b210c98 100644 --- a/kcmkwin/kwinoptions/mouse.cpp +++ b/kcmkwin/kwinoptions/mouse.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include #include @@ -43,6 +46,92 @@ #include "mouse.moc" +namespace { + +char const * const cnf_Max[] = { + "MaximizeButtonLeftClickCommand", + "MaximizeButtonMiddleClickCommand", + "MaximizeButtonRightClickCommand", +}; + +char const * const tbl_Max[] = { + "Maximize", + "Maximize (vertical only)", + "Maximize (horizontal only)", + "" }; + +QPixmap maxButtonPixmaps[3]; + +void createMaxButtonPixmaps() +{ + char const * maxButtonXpms[][3 + 13] = { + {0, 0, 0, + "...............", + ".......#.......", + "......###......", + ".....#####.....", + "..#....#....#..", + ".##....#....##.", + "###############", + ".##....#....##.", + "..#....#....#..", + ".....#####.....", + "......###......", + ".......#.......", + "..............."}, + {0, 0, 0, + "...............", + ".......#.......", + "......###......", + ".....#####.....", + ".......#.......", + ".......#.......", + ".......#.......", + ".......#.......", + ".......#.......", + ".....#####.....", + "......###......", + ".......#.......", + "..............."}, + {0, 0, 0, + "...............", + "...............", + "...............", + "...............", + "..#.........#..", + ".##.........##.", + "###############", + ".##.........##.", + "..#.........#..", + "...............", + "...............", + "...............", + "..............."}, + }; + + QString baseColor(". c " + KGlobalSettings::baseColor().name()); + QString textColor("# c " + KGlobalSettings::textColor().name()); + for (int t = 0; t < 3; ++t) + { + maxButtonXpms[t][0] = "15 13 2 1"; + maxButtonXpms[t][1] = baseColor.ascii(); + maxButtonXpms[t][2] = textColor.ascii(); + maxButtonPixmaps[t] = QPixmap(maxButtonXpms[t]); + maxButtonPixmaps[t].setMask(maxButtonPixmaps[t].createHeuristicMask()); + } +} + +} // namespace + +void KActionsConfig::paletteChanged() +{ + createMaxButtonPixmaps(); + for (int b = 0; b < 3; ++b) + for (int t = 0; t < 3; ++t) + coMax[b]->changeItem(maxButtonPixmaps[t], t); + +} + KActionsConfig::KActionsConfig (bool _standAlone, KConfig *_config, QWidget * parent, const char *) : KCModule(parent, "kcmkwm"), config(_config), standAlone(_standAlone) { @@ -211,6 +300,50 @@ KActionsConfig::KActionsConfig (bool _standAlone, KConfig *_config, QWidget * pa coTiInAct3 = combo; QWhatsThis::add(combo, txtButton3); +/** Maximize Button ******************/ + + box = new QHGroupBox(i18n("Maximize Button"), this, "Maximize Button"); + box->layout()->setMargin(KDialog::marginHint()); + box->layout()->setSpacing(KDialog::spacingHint()); + layout->addWidget(box); + QWhatsThis::add( box, + i18n("Here you can customize behavior when clicking on the maximize button.") ); + + QString strMouseButton[] = { + i18n("Left button:"), + i18n("Middle button:"), + i18n("Right button:")}; + + QString txtButton[] = { + i18n("Behavior on left click onto the maximize button." ), + i18n("Behavior on middle click onto the maximize button." ), + i18n("Behavior on right click onto the maximize button." )}; + + if ( leftHandedMouse ) // Be nice to lefties + { + qSwap(strMouseButton[0], strMouseButton[2]); + qSwap(txtButton[0], txtButton[2]); + } + + createMaxButtonPixmaps(); + for (int b = 0; b < 3; ++b) + { + if (b != 0) new QWidget(box); // Spacer + + QLabel * label = new QLabel(strMouseButton[b], box); + QWhatsThis::add( label, txtButton[b] ); + label ->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum )); + + coMax[b] = new ToolTipComboBox(box, tbl_Max); + for (int t = 0; t < 3; ++t) coMax[b]->insertItem(maxButtonPixmaps[t]); + connect(coMax[b], SIGNAL(activated(int)), SLOT(changed())); + connect(coMax[b], SIGNAL(activated(int)), coMax[b], SLOT(changed())); + QWhatsThis::add( coMax[b], txtButton[b] ); + coMax[b]->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum )); + } + + connect(kapp, SIGNAL(kdisplayPaletteChanged()), SLOT(paletteChanged())); + /** Inactive inner window ******************/ box = new QVGroupBox(i18n("Inactive Inner Window"), this, "Inactive Inner Window"); @@ -375,7 +508,7 @@ KActionsConfig::~KActionsConfig() // do NOT change the texts below, they are written to config file // and are not shown in the GUI // they have to match the order of items in GUI elements though -const char* tbl_TiDbl[] = { +const char* const tbl_TiDbl[] = { "Maximize", "Maximize (vertical only)", "Maximize (horizontal only)", @@ -386,7 +519,7 @@ const char* tbl_TiDbl[] = { "Nothing", "" }; -const char* tbl_TiAc[] = { +const char* const tbl_TiAc[] = { "Raise", "Lower", "Operations menu", @@ -395,7 +528,7 @@ const char* tbl_TiAc[] = { "Shade", "" }; -const char* tbl_TiInAc[] = { +const char* const tbl_TiInAc[] = { "Activate and raise", "Activate and lower", "Activate", @@ -406,19 +539,19 @@ const char* tbl_TiInAc[] = { "Nothing", "" }; -const char* tbl_Win[] = { +const char* const tbl_Win[] = { "Activate, raise and pass click", "Activate and pass click", "Activate", "Activate and raise", "" }; -const char* tbl_AllKey[] = { +const char* const tbl_AllKey[] = { "Meta", "Alt", "" }; -const char* tbl_All[] = { +const char* const tbl_All[] = { "Move", "Activate, raise and move", "Toggle raise and lower", @@ -429,7 +562,7 @@ const char* tbl_All[] = { "Nothing", "" }; -static const char* tbl_num_lookup( const char* arr[], int pos ) +static const char* tbl_num_lookup( const char* const arr[], int pos ) { for( int i = 0; arr[ i ][ 0 ] != '\0' && pos >= 0; @@ -442,7 +575,7 @@ static const char* tbl_num_lookup( const char* arr[], int pos ) abort(); // should never happen this way } -static int tbl_txt_lookup( const char* arr[], const char* txt ) +static int tbl_txt_lookup( const char* const arr[], const char* txt ) { int pos = 0; for( int i = 0; @@ -470,6 +603,11 @@ void KActionsConfig::setComboText( QComboBox* combo, const char*txt ) combo->setCurrentItem( tbl_txt_lookup( tbl_AllKey, txt )); else if( combo == coAll1 || combo == coAll2 || combo == coAll3 ) combo->setCurrentItem( tbl_txt_lookup( tbl_All, txt )); + else if( combo == coMax[0] || combo == coMax[1] || combo == coMax[2] ) + { + combo->setCurrentItem( tbl_txt_lookup( tbl_Max, txt )); + static_cast(combo)->changed(); + } else abort(); } @@ -504,10 +642,17 @@ const char* KActionsConfig::functionAll( int i ) return tbl_num_lookup( tbl_All, i ); } +const char* KActionsConfig::functionMax( int i ) +{ + return tbl_num_lookup( tbl_Max, i ); +} + void KActionsConfig::load() { config->setGroup("Windows"); setComboText(coTiDbl, config->readEntry("TitlebarDoubleClickCommand","Shade").ascii()); + for (int t = 0; t < 3; ++t) + setComboText(coMax[t],config->readEntry(cnf_Max[t], tbl_Max[t]).ascii()); config->setGroup( "MouseBindings"); setComboText(coTiAct1,config->readEntry("CommandActiveTitlebar1","Raise").ascii()); @@ -529,6 +674,8 @@ void KActionsConfig::save() { config->setGroup("Windows"); config->writeEntry("TitlebarDoubleClickCommand", functionTiDbl( coTiDbl->currentItem() ) ); + for (int t = 0; t < 3; ++t) + config->writeEntry(cnf_Max[t], functionMax(coMax[t]->currentItem())); config->setGroup("MouseBindings"); config->writeEntry("CommandActiveTitlebar1", functionTiAc(coTiAct1->currentItem())); @@ -570,4 +717,6 @@ void KActionsConfig::defaults() setComboText (coAll1,"Move"); setComboText(coAll2,"Toggle raise and lower"); setComboText(coAll3,"Resize"); + for (int t = 0; t < 3; ++t) + setComboText(coMax[t], tbl_Max[t]); } diff --git a/kcmkwin/kwinoptions/mouse.h b/kcmkwin/kwinoptions/mouse.h index 658894d153..35ae0ce048 100644 --- a/kcmkwin/kwinoptions/mouse.h +++ b/kcmkwin/kwinoptions/mouse.h @@ -22,11 +22,31 @@ #ifndef __KKWMMOUSECONFIG_H__ #define __KKWMMOUSECONFIG_H__ -class QComboBox; class KConfig; #include #include +#include +#include + + +class ToolTipComboBox: public QComboBox +{ + Q_OBJECT + +public: + ToolTipComboBox(QWidget * owner, char const * const * toolTips_) + : QComboBox(owner) + , toolTips(toolTips_) {} + +public slots: + void changed() {QToolTip::add( this, i18n(toolTips[currentItem()]) );} + +protected: + char const * const * toolTips; +}; + + class KActionsConfig : public KCModule { @@ -54,6 +74,8 @@ private: QComboBox* coTiInAct2; QComboBox* coTiInAct3; + ToolTipComboBox * coMax[3]; + QComboBox* coWin1; QComboBox* coWin2; QComboBox* coWin3; @@ -72,10 +94,14 @@ private: const char* functionWin(int); const char* functionAllKey(int); const char* functionAll(int); + const char* functionMax(int); void setComboText(QComboBox* combo, const char* text); const char* fixup( const char* s ); +private slots: + void paletteChanged(); + }; #endif diff --git a/lib/kdecoration.cpp b/lib/kdecoration.cpp index 72ffc9c99a..faba138643 100644 --- a/lib/kdecoration.cpp +++ b/lib/kdecoration.cpp @@ -233,13 +233,7 @@ void KDecoration::closeWindow() void KDecoration::maximize( ButtonState button ) { - // This can be made configurable if needed. - if( button == MidButton ) - maximize( maximizeMode() ^ MaximizeVertical ); - else if ( button == RightButton ) - maximize( maximizeMode() ^ MaximizeHorizontal ); - else - maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull ); + performWindowOperation( options()->operationMaxButtonClick( button )); } void KDecoration::maximize( MaximizeMode mode ) @@ -430,4 +424,11 @@ bool KDecorationOptions::moveResizeMaximizedWindows() const return d->move_resize_maximized_windows; } +KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::ButtonState button ) const + { + return button == Qt::RightButton? d->OpMaxButtonRightClick : + button == Qt::MidButton? d->OpMaxButtonMiddleClick : + d->OpMaxButtonLeftClick; + } + #include "kdecoration.moc" diff --git a/lib/kdecoration.h b/lib/kdecoration.h index 6ba029664b..683507c1b8 100644 --- a/lib/kdecoration.h +++ b/lib/kdecoration.h @@ -257,6 +257,11 @@ public: */ bool moveResizeMaximizedWindows() const; + /** + * @internal + */ + WindowOperation operationMaxButtonClick( Qt::ButtonState button ) const; + /** * @internal */ diff --git a/lib/kdecoration_p.cpp b/lib/kdecoration_p.cpp index df27603b70..94291dd497 100644 --- a/lib/kdecoration_p.cpp +++ b/lib/kdecoration_p.cpp @@ -58,6 +58,9 @@ void KDecorationOptionsPrivate::defaultKWinSettings() 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 ) diff --git a/lib/kdecoration_p.h b/lib/kdecoration_p.h index ba59e3d5e4..9e3d29b014 100644 --- a/lib/kdecoration_p.h +++ b/lib/kdecoration_p.h @@ -53,6 +53,9 @@ class KDecorationOptionsPrivate : public KDecorationDefines bool show_tooltips; BorderSize border_size, cached_border_size; bool move_resize_maximized_windows; + WindowOperation OpMaxButtonRightClick; + WindowOperation OpMaxButtonMiddleClick; + WindowOperation OpMaxButtonLeftClick; }; class KDecorationBridge : public KDecorationDefines diff --git a/options.cpp b/options.cpp index 45d39a6978..d19ef1c56f 100644 --- a/options.cpp +++ b/options.cpp @@ -133,6 +133,9 @@ unsigned long Options::updateSettings() electric_border_delay = config->readNumEntry("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 ); ignorePositionClasses = config->readListEntry("IgnorePositionClasses"); ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses");