From 51894257c98d833329c80ecf700600b2a297b2c0 Mon Sep 17 00:00:00 2001 From: Luciano Montanaro Date: Sat, 22 May 2004 00:31:07 +0000 Subject: [PATCH] Added support for a custom action associated with the menu button. svn path=/trunk/kdebase/kwin/; revision=313377 --- clients/b2/b2client.cpp | 59 ++++++++++++++++++++++---- clients/b2/b2client.h | 2 + clients/b2/config/config.cpp | 80 ++++++++++++++++++++++++++++-------- clients/b2/config/config.h | 5 +++ 4 files changed, 121 insertions(+), 25 deletions(-) diff --git a/clients/b2/b2client.cpp b/clients/b2/b2client.cpp index c21f68d824..4de127c3db 100644 --- a/clients/b2/b2client.cpp +++ b/clients/b2/b2client.cpp @@ -10,6 +10,7 @@ */ #include "b2client.h" +#include #include #include #include @@ -52,6 +53,15 @@ static KPixmap* titleGradient[2] = {0, 0}; static int thickness = 4; // Frame thickness static int buttonSize = 16; +enum DblClickOperation { + NoOp = 0, + MinimizeOp, + ShadeOp, + CloseOp +}; + +static DblClickOperation menu_dbl_click_op = NoOp; + static bool pixmaps_created = false; static bool colored_frame = false; @@ -81,6 +91,16 @@ static void read_config(B2ClientFactory *f) KConfig conf("kwinb2rc"); conf.setGroup("General"); colored_frame = conf.readBoolEntry( "UseTitleBarBorderColors", false ); + QString opString = conf.readEntry("MenuButtonDoubleClickOperation", "NoOp"); + if (opString == "Close") { + menu_dbl_click_op = B2::CloseOp; + } else if (opString == "Minimize") { + menu_dbl_click_op = B2::MinimizeOp; + } else if (opString == "Shade") { + menu_dbl_click_op = B2::ShadeOp; + } else { + menu_dbl_click_op = B2::NoOp; + } switch (options()->preferredBorderSize(f)) { case KDecoration::BorderTiny: @@ -794,13 +814,36 @@ void B2Client::borders(int &left, int &right, int &top, int &bottom) const void B2Client::menuButtonPressed() { - QPoint menupoint = button[BtnMenu]->mapToGlobal( - button[BtnMenu]->rect().bottomLeft()); - KDecorationFactory* f = factory(); - showWindowMenu(menupoint); - if( !f->exists( this )) // 'this' was destroyed - return; - button[BtnMenu]->setDown(false); + static B2Client *lastClient = NULL; + + bool dbl = (lastClient == this && + time.elapsed() <= QApplication::doubleClickInterval()); + lastClient = this; + time.start(); + if (!dbl) { + QPoint menupoint = button[BtnMenu]->mapToGlobal( + button[BtnMenu]->rect().bottomLeft()); + KDecorationFactory* f = factory(); + showWindowMenu(menupoint); + if (!f->exists(this)) // 'this' was destroyed + return; + button[BtnMenu]->setDown(false); + } else { + switch (menu_dbl_click_op) { + case B2::MinimizeOp: + minimize(); + break; + case B2::ShadeOp: + setShade(!isShade()); + break; + case B2::CloseOp: + closeWindow(); + break; + case B2::NoOp: + default: + break; + } + } } void B2Client::unobscureTitlebar() @@ -848,8 +891,6 @@ static void redraw_pixmaps() QColor color = is_act ? aGrp.button() : iGrp.button(); drawB2Rect(&thinBox, color, is_down); pix->fill(Qt::black); - fprintf(stderr, "thinbox width = %d, height = %d\n", - thinBox.width(), thinBox.height()); bitBlt(pix, 0, 0, &thinBox, 0, 0, thinBox.width(), thinBox.height(), Qt::CopyROP, true); } diff --git a/clients/b2/b2client.h b/clients/b2/b2client.h index 5e214e1770..a4968ca0de 100644 --- a/clients/b2/b2client.h +++ b/clients/b2/b2client.h @@ -10,6 +10,7 @@ #define __B2CLIENT_H #include +#include #include #include #include @@ -135,6 +136,7 @@ private: B2Titlebar *titlebar; int bar_x_ofs; int in_unobs; + QTime time; }; class B2ClientFactory : public QObject, public KDecorationFactory diff --git a/clients/b2/config/config.cpp b/clients/b2/config/config.cpp index 26a42adc61..d0466b6f3d 100644 --- a/clients/b2/config/config.cpp +++ b/clients/b2/config/config.cpp @@ -35,19 +35,34 @@ B2Config::B2Config( KConfig* conf, QWidget* parent ) { KGlobal::locale()->insertCatalogue("kwin_b2_config"); b2Config = new KConfig("kwinb2rc"); - gb = new QVBox( parent ); + gb = new QVBox(parent); cbColorBorder = new QCheckBox( - i18n("Draw window frames using &titlebar colors"), gb ); - QWhatsThis::add( cbColorBorder, - i18n("When selected, the window decoration borders " - "are drawn using the titlebar colors. Otherwise, they are " - "drawn using normal border colors instead.") ); + i18n("Draw window frames using &titlebar colors"), gb); + QWhatsThis::add(cbColorBorder, + i18n("When selected, the window decoration borders " + "are drawn using the titlebar colors. Otherwise, they are " + "drawn using normal border colors instead.")); + // Double click menu option support + actionsGB = new QHGroupBox(i18n("Actions Settings"), gb); + QLabel *menuDblClickLabel = new QLabel(actionsGB); + menuDblClickLabel->setText(i18n("Double Click on Menu Button:")); + menuDblClickOp = new QComboBox(actionsGB); + menuDblClickOp->insertItem(i18n("Do Nothing")); + menuDblClickOp->insertItem(i18n("Minimize Window")); + menuDblClickOp->insertItem(i18n("Shade Window")); + menuDblClickOp->insertItem(i18n("Close Window")); + + QWhatsThis::add(menuDblClickOp, + i18n("An action can be associated to a double click " + "of the menu button. Leave it to none if in doubt.")); // Load configuration options - load( conf ); + load(conf); // Ensure we track user changes properly - connect( cbColorBorder, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()) ); - + connect(cbColorBorder, SIGNAL(clicked()), + this, SLOT(slotSelectionChanged())); + connect(menuDblClickOp, SIGNAL(activated(int)), + this, SLOT(slotSelectionChanged())); // Make the widgets visible in kwindecoration gb->show(); } @@ -55,9 +70,8 @@ B2Config::B2Config( KConfig* conf, QWidget* parent ) B2Config::~B2Config() { - delete cbColorBorder; + delete b2Config; delete gb; - delete b2Config; } @@ -69,19 +83,52 @@ void B2Config::slotSelectionChanged() // Loads the configurable options from the kwinrc config file // It is passed the open config from kwindecoration to improve efficiency -void B2Config::load( KConfig* /*conf*/ ) +void B2Config::load(KConfig * /*conf*/) { b2Config->setGroup("General"); - bool override = b2Config->readBoolEntry( "UseTitleBarBorderColors", false ); - cbColorBorder->setChecked( override ); + bool override = b2Config->readBoolEntry("UseTitleBarBorderColors", false); + cbColorBorder->setChecked(override); + QString returnString = b2Config->readEntry( + "MenuButtonDoubleClickOperation", "NoOp"); + + int op; + if (returnString == "Close") { + op = 3; + } else if (returnString == "Shade") { + op = 2; + } else if (returnString == "Minimize") { + op = 1; + } else { + op = 0; + } + + menuDblClickOp->setCurrentItem(op); + +} + +static QString opToString(int op) +{ + switch (op) { + case 1: + return "Minimize"; + case 2: + return "Shade"; + case 3: + return "Close"; + case 0: + default: + return "NoOp"; + } } // Saves the configurable options to the kwinrc config file -void B2Config::save( KConfig* /*conf*/ ) +void B2Config::save(KConfig * /*conf*/) { b2Config->setGroup("General"); - b2Config->writeEntry( "UseTitleBarBorderColors", cbColorBorder->isChecked() ); + b2Config->writeEntry("UseTitleBarBorderColors", cbColorBorder->isChecked()); + b2Config->writeEntry("MenuButtonDoubleClickOperation", + opToString(menuDblClickOp->currentItem())); // Ensure others trying to read this config get updated b2Config->sync(); } @@ -91,6 +138,7 @@ void B2Config::save( KConfig* /*conf*/ ) void B2Config::defaults() { cbColorBorder->setChecked( false ); + menuDblClickOp->setCurrentItem(0); } #include "config.moc" diff --git a/clients/b2/config/config.h b/clients/b2/config/config.h index cca9b324e6..9cd17314e6 100644 --- a/clients/b2/config/config.h +++ b/clients/b2/config/config.h @@ -11,6 +11,9 @@ #include #include +#include +#include +#include #include class B2Config: public QObject @@ -36,6 +39,8 @@ class B2Config: public QObject private: KConfig* b2Config; QCheckBox* cbColorBorder; + QHGroupBox* actionsGB; + QComboBox* menuDblClickOp; QWidget* gb; };