Added support for a custom action associated with the menu button.
svn path=/trunk/kdebase/kwin/; revision=313377
This commit is contained in:
parent
ef20b9749d
commit
51894257c9
4 changed files with 121 additions and 25 deletions
|
@ -10,6 +10,7 @@
|
|||
*/
|
||||
|
||||
#include "b2client.h"
|
||||
#include <qapplication.h>
|
||||
#include <qlayout.h>
|
||||
#include <qdrawutil.h>
|
||||
#include <kpixmapeffect.h>
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __B2CLIENT_H
|
||||
|
||||
#include <qvariant.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qbutton.h>
|
||||
#include <qbitmap.h>
|
||||
#include <kpixmap.h>
|
||||
|
@ -135,6 +136,7 @@ private:
|
|||
B2Titlebar *titlebar;
|
||||
int bar_x_ofs;
|
||||
int in_unobs;
|
||||
QTime time;
|
||||
};
|
||||
|
||||
class B2ClientFactory : public QObject, public KDecorationFactory
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
#include <qcheckbox.h>
|
||||
#include <qgroupbox.h>
|
||||
#include <qhgroupbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <kconfig.h>
|
||||
|
||||
class B2Config: public QObject
|
||||
|
@ -36,6 +39,8 @@ class B2Config: public QObject
|
|||
private:
|
||||
KConfig* b2Config;
|
||||
QCheckBox* cbColorBorder;
|
||||
QHGroupBox* actionsGB;
|
||||
QComboBox* menuDblClickOp;
|
||||
QWidget* gb;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue