configurable mouse bindings (see README)

svn path=/trunk/kdebase/kwin/; revision=35388
This commit is contained in:
Matthias Ettrich 1999-11-29 02:06:41 +00:00
parent b8a8bf9be2
commit b441f40a7e
10 changed files with 330 additions and 171 deletions

54
README
View file

@ -1,18 +1,52 @@
Fri Aug 20 01:30:50 CEST 1999
This is kwin, kwm next generation.
This is the beginning of kwin, kwm next generation.
Currently supported options in the kwinrc:
WARNING: this thing is hardly usable now, neither ICCCM nor KDE
compliant yet!
[WM]
... general color stuff, usually in kdeglobals ...
[Windows]
MoveMode=Opaque|Transparent
ResizeMode=Opaque|Transparent
Placement=Smart|Random|Cascade
AnimateShade=TRUE|FALSE
AnimSteps=<integer=20>
BorderSnapZone=<integer=10>
WindowSnapZone=<integer=10>
TitlebarDoubleClickCommand=Move|Resize|
Maximize|Iconify|Close|Sticky|Shade|Operations
[MouseBindings]
CommandActiveTitlebar1 |
CommandActiveTitlebar2 |
CommandActiveTitlebar3 |
CommandInactiveTitlebar1 |
CommandInactiveTitlebar2 |
CommandInactiveTitlebar3 |
CommandWindow1 |
CommandWindow2 |
CommandWindow3 |
CommandAll1 |
CommandAll2 |
CommandAll3
=
Raise |
Lower |
Operations Menu |
Toggle raise and lower |
Activate and raise |
Activate and lower |
Activate |
Activate, raise and pass click |
Activate and pass click |
Move |
Resize |
Nothing
All it has is a context menu that allows you to switch between two
decoration styles, KDE classic and an experimental style.
Please don't work on the code, I'll finish it during my summer
vacations (four weeks from now on).
kwin was only commited to allow people like Mosfet to have a look at
the Client API (and StdClient) to write nifty new themable decorations.
Have fun,

View file

@ -197,7 +197,6 @@ void BeClient::mousePressEvent( QMouseEvent * e )
void BeClient::mouseReleaseEvent( QMouseEvent * e )
{
workspace()->makeFullScreen( this );
Client::mouseReleaseEvent( e );
}

View file

@ -211,36 +211,50 @@ void WindowWrapper::releaseWindow()
void WindowWrapper::mousePressEvent( QMouseEvent* )
{
XAllowEvents( qt_xdisplay(), ReplayPointer, lastMouseEventTime );
}
void WindowWrapper::mouseReleaseEvent( QMouseEvent* )
{
XAllowEvents( qt_xdisplay(), ReplayPointer, lastMouseEventTime );
}
void WindowWrapper::mouseMoveEvent( QMouseEvent* )
{
//#### we sometimes get these but shouldn't..... Maybe a Qt problem
//XAllowEvents( qt_xdisplay(), ReplayPointer, lastMouseEventTime );
}
bool WindowWrapper::x11Event( XEvent * e)
{
switch ( e->type ) {
case ButtonPress:
case ButtonRelease:
lastMouseEventTime = e->xbutton.time;
if ( e->xbutton.button > 3 ) {
XAllowEvents( qt_xdisplay(), ReplayPointer, lastMouseEventTime );
{
bool mod1 = (e->xbutton.state & Mod1Mask) == Mod1Mask;
Options::MouseCommand com = Options::MouseNothing;
if ( mod1){
switch (e->xbutton.button) {
case Button1:
com = options->commandAll1();
break;
case Button2:
com = options->commandAll2();
break;
case Button3:
com = options->commandAll3();
break;
}
} else {
switch (e->xbutton.button) {
case Button1:
com = options->commandWindow1();
break;
case Button2:
com = options->commandWindow2();
break;
case Button3:
com = options->commandWindow3();
break;
default:
com = Options::MouseActivateAndPassClick;
}
}
bool replay = ( (Client*)parentWidget() )->performMouseCommand( com,
QPoint( e->xbutton.x_root, e->xbutton.y_root) );
XAllowEvents(qt_xdisplay(), replay? ReplayPointer : SyncPointer, kwin_time);
return TRUE;
}
break;
case MotionNotify:
lastMouseEventTime = e->xmotion.time;
case ButtonRelease:
XAllowEvents(qt_xdisplay(), SyncPointer, kwin_time);
break;
default:
break;
@ -478,7 +492,6 @@ bool Client::windowEvent( XEvent * e)
return propertyNotify( e->xproperty );
case ButtonPress:
case ButtonRelease:
XAllowEvents( qt_xdisplay(), e->xbutton.time, ReplayPointer );
break;
case FocusIn:
if ( e->xfocus.mode == NotifyUngrab )
@ -765,6 +778,9 @@ QSize Client::sizeForWindowSize( const QSize& wsize, bool ignore_height) const
h = QMAX( xSizeHint.min_height, h );
}
w = QMAX( minimumWidth(), w );
h = QMAX( minimumHeight(), h );
int ww = wwrap->width();
int wh = 0;
if ( !wwrap->testWState( WState_ForceHide ) )
@ -774,11 +790,6 @@ QSize Client::sizeForWindowSize( const QSize& wsize, bool ignore_height) const
h = 0;
return QSize( width() - ww + w, height()-wh+h );
// return QSize( QMIN( QMAX( width() - ww + w, minimumWidth() ),
// maximumWidth() ),
// ignore_height? height()-wh+h : (QMIN( QMAX( height() - wh + h, minimumHeight() ),
// maximumHeight() ) ) );
}
@ -806,7 +817,7 @@ void Client::mousePressEvent( QMouseEvent * e)
*/
void Client::mouseReleaseEvent( QMouseEvent * e)
{
if ( e->button() == LeftButton ) {
if ( (e->stateAfter() & MouseButtonMask) == 0 ) {
buttonDown = FALSE;
if ( moveResizeMode ) {
clearbound();
@ -906,8 +917,8 @@ void Client::mouseMoveEvent( QMouseEvent * e)
}
if ( isResize() && geom.size() != size() ) {
geom.setSize( adjustedSize( geom.size() ) );
if (options->resizeMode == Options::Opaque ) {
geom.setSize( adjustedSize( geom.size() ) );
setGeometry( geom );
} else if ( options->resizeMode == Options::Transparent ) {
clearbound();
@ -1085,72 +1096,6 @@ void Client::invalidateWindow()
windowWrapper()->invalidateWindow();
}
/*!
Returns the minimum size. This function differs from QWidget::minimumSize()
and is to be preferred
*/
QSize Client::minimumSize() const
{
return QSize( minimumWidth(), minimumHeight() );
}
/*!
Returns the minimum width. This function differs from QWidget::minimumWidth()
and is to be preferred
*/
int Client::minimumWidth() const
{
// if (xSizeHint.flags & PMinSize)
// return QMAX( width() - wwrap->width() + xSizeHint.min_width,
// QWidget::minimumWidth() );
// else
return QWidget::minimumWidth();
}
/*!
Returns the minimum height. This function differs from QWidget::minimumHeight()
and is to be preferred
*/
int Client::minimumHeight() const
{
// if (xSizeHint.flags & PMinSize)
// return QMAX( height() - wwrap->height() + xSizeHint.min_height,
// QWidget::minimumHeight() );
// else
return QWidget::minimumHeight();
}
/*!
Returns the maximum size. This function differs from QWidget::maximumSize()
and is to be preferred
*/
QSize Client::maximumSize() const
{
return QSize( maximumWidth(), maximumHeight() );
}
/*!
Returns the maximum width. This function differs from QWidget::maximumWidth()
and is to be preferred
*/
int Client::maximumWidth() const
{
// if (xSizeHint.flags & PMaxSize)
// return QMIN( width() - wwrap->width() + xSizeHint.max_width,
// QWidget::maximumWidth() );
// else
return QWidget::maximumWidth();
}
/*!
Returns the maximum height. This function differs from QWidget::maximumHeight()
and is to be preferred
*/
int Client::maximumHeight() const
{
// if (xSizeHint.flags & PMaxSize)
// return QMIN( height() - wwrap->height() + xSizeHint.max_height,
// QWidget::maximumHeight() );
// else
return QWidget::maximumHeight();
}
void Client::iconify()
{
@ -1221,11 +1166,6 @@ void Client::maximize()
}
void Client::fullScreen()
{
workspace()->makeFullScreen( this );
}
/*!
@ -1236,11 +1176,6 @@ bool Client::eventFilter( QObject *o, QEvent * e)
if ( o != wwrap )
return FALSE;
switch ( e->type() ) {
case QEvent::MouseButtonPress:
if ( options->focusPolicyIsReasonable() )
workspace()->requestFocus( this );
workspace()->raiseClient( this );
break;
case QEvent::MouseButtonRelease:
break;
case QEvent::Show:
@ -1576,6 +1511,81 @@ Client* Client::mainClient()
}
bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPos)
{
bool replay = FALSE;
switch (command) {
case Options::MouseRaise:
break;
case Options::MouseLower:
break;
case Options::MouseOperationsMenu:
break;
case Options::MouseToggleRaiseAndLower:
break;
case Options::MouseActivateAndRaise:
workspace()->requestFocus( this );
workspace()->raiseClient( this );
break;
case Options::MouseActivateAndLower:
workspace()->requestFocus( this );
workspace()->raiseClient( this );
break;
case Options::MouseActivate:
workspace()->requestFocus( this );
break;
case Options::MouseActivateRaiseAndPassClick:
workspace()->requestFocus( this );
workspace()->raiseClient( this );
replay = TRUE;
break;
case Options::MouseActivateAndPassClick:
workspace()->requestFocus( this );
workspace()->raiseClient( this );
replay = TRUE;
break;
case Options::MouseMove:
mode = Center;
moveResizeMode = TRUE;
buttonDown = TRUE;
moveOffset = mapFromGlobal( globalPos );
invertedMoveOffset = rect().bottomRight() - moveOffset;
grabMouse( arrowCursor );
if ( options->moveMode != Options::Opaque )
XGrabServer( qt_xdisplay() );
break;
case Options::MouseResize:
moveResizeMode = TRUE;
buttonDown = TRUE;
moveOffset = mapFromGlobal( globalPos );
if ( moveOffset.x() < width()/2) {
if ( moveOffset.y() < height()/2)
mode = TopLeft;
else
mode = BottomLeft;
} else {
if ( moveOffset.y() < height()/2)
mode = TopRight;
else
mode = BottomRight;
}
invertedMoveOffset = rect().bottomRight() - moveOffset;
setMouseCursor( mode );
grabMouse( cursor() );
if ( options->resizeMode != Options::Opaque )
XGrabServer( qt_xdisplay() );
break;
case Options::MouseNothing:
// fall through
default:
replay = TRUE;
break;
}
return replay;
}
NoBorderClient::NoBorderClient( Workspace *ws, WId w, QWidget *parent, const char *name )
: Client( ws, w, parent, name )
{

View file

@ -32,9 +32,6 @@ protected:
void resizeEvent( QResizeEvent * );
void showEvent( QShowEvent* );
void hideEvent( QHideEvent* );
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
void mouseMoveEvent( QMouseEvent* );
bool x11Event( XEvent * ); // X11 event
private:
@ -76,12 +73,6 @@ public:
void withdraw();
QSize adjustedSize( const QSize& ) const;
QSize minimumSize() const;
int minimumWidth() const;
int minimumHeight() const;
QSize maximumSize() const;
int maximumWidth() const;
int maximumHeight() const;
QPixmap icon() const;
QPixmap miniIcon() const;
@ -139,13 +130,13 @@ public:
virtual bool wantsTabFocus() const { return TRUE;} //### just for now
bool performMouseCommand( Options::MouseCommand, QPoint globalPos );
public slots:
void iconify();
void closeWindow();
void maximize( MaximizeMode );
void maximize();
void fullScreen();
void toggleSticky();
protected:

View file

@ -57,8 +57,6 @@ const QColorGroup& Options::colorGroup(ColorType type, bool active)
void Options::reload()
{
focusPolicy = ClickToFocus;
resizeMode = Opaque;
moveMode = Opaque;// Transparent;
QPalette pal = QApplication::palette();
KConfig *config = KGlobal::config();
@ -143,9 +141,10 @@ void Options::reload()
}
}
//CT well, what this costs us?
config->setGroup("Actions");
config->setGroup( "Windows" );
moveMode = config->readEntry("MoveMode", "Opaque" ) == "Opaque"?Opaque:Transparent;
resizeMode = config->readEntry("ResizeMode", "Opaque" ) == "Opaque"?Opaque:Transparent;
QString val;
val = config->readEntry("Placement","Smart");
if (val == "Smart") placement = Smart;
@ -158,5 +157,61 @@ void Options::reload()
border_snap_zone = config->readNumEntry("BorderSnapZone", 10);
window_snap_zone = config->readNumEntry("WindowSnapZone", 10);
OpTitlebarDblClick = windowOperation( config->readEntry("TitlebarDoubleClickCommand", "winShade") );
// Mouse bindings
config->setGroup( "MouseBindings");
CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1","Raise"));
CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2","Lower"));
CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3","Operations menu"));
CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1","Activate and raise"));
CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2","Activate and lower"));
CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3","Activate"));
CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1","Activate, raise and pass click"));
CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2","Activate and pass click"));
CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3","Activate and pass click"));
CmdAll1 = mouseCommand(config->readEntry("CommandAll1","Move"));
CmdAll2 = mouseCommand(config->readEntry("CommandAll2","Toggle raise and lower"));
CmdAll3 = mouseCommand(config->readEntry("CommandAll3","Resize"));
}
Options::WindowOperation Options::windowOperation(const QString &name){
if (name == "Move")
return MoveOp;
else if (name == "Resize")
return ResizeOp;
else if (name == "Maximize")
return MaximizeOp;
else if (name == "Iconify")
return IconifyOp;
else if (name == "Close")
return CloseOp;
else if (name == "Sticky")
return StickyOp;
else if (name == "Shade")
return ShadeOp;
else if (name == "Operations")
return OperationsOp;
return NoOp;
}
Options::MouseCommand Options::mouseCommand(const QString &name)
{
if (name == "Raise") return MouseRaise;
if (name == "Lower") return MouseLower;
if (name == "Operations menu") return MouseOperationsMenu;
if (name == "Toggle raise and lower") return MouseToggleRaiseAndLower;
if (name == "Activate and raise") return MouseActivateAndRaise;
if (name == "Activate and lower") return MouseActivateAndLower;
if (name == "Activate") return MouseActivate;
if (name == "Activate, raise and pass click") return MouseActivateRaiseAndPassClick;
if (name == "Activate and pass click") return MouseActivateAndPassClick;
if (name == "Move") return MouseMove;
if (name == "Resize") return MouseResize;
if (name == "Nothing") return MouseNothing;
return MouseNothing;
}

View file

@ -98,6 +98,50 @@ public:
* Return the number of animation steps (would this be general?)
*/
const int windowSnapZone() { return window_snap_zone; };
// mouse bindings
enum WindowOperation{
MaximizeOp = 5000,
RestoreOp,
IconifyOp,
MoveOp,
ResizeOp,
CloseOp,
StickyOp,
ShadeOp,
OperationsOp,
NoOp
};
WindowOperation operationTitlebarDblClick() { return OpTitlebarDblClick; }
enum MouseCommand {
MouseRaise, MouseLower, MouseOperationsMenu, MouseToggleRaiseAndLower,
MouseActivateAndRaise, MouseActivateAndLower, MouseActivate,
MouseActivateRaiseAndPassClick, MouseActivateAndPassClick,
MouseMove, MouseResize, MouseNothing
};
MouseCommand commandActiveTitlebar1() { return CmdActiveTitlebar1; }
MouseCommand commandActiveTitlebar2() { return CmdActiveTitlebar2; }
MouseCommand commandActiveTitlebar3() { return CmdActiveTitlebar3; }
MouseCommand commandInactiveTitlebar1() { return CmdInactiveTitlebar1; }
MouseCommand commandInactiveTitlebar2() { return CmdInactiveTitlebar2; }
MouseCommand commandInactiveTitlebar3() { return CmdInactiveTitlebar3; }
MouseCommand commandWindow1() { return CmdWindow1; }
MouseCommand commandWindow2() { return CmdWindow2; }
MouseCommand commandWindow3() { return CmdWindow3; }
MouseCommand commandAll1() { return CmdAll1; }
MouseCommand commandAll2() { return CmdAll2; }
MouseCommand commandAll3() { return CmdAll3; }
static WindowOperation windowOperation(const QString &name );
static MouseCommand mouseCommand(const QString &name);
public slots:
void reload();
@ -108,9 +152,26 @@ protected:
QColorGroup *cg[KWINCOLORS*2];
private:
bool animate_shade;
int anim_steps;
int border_snap_zone, window_snap_zone;
bool animate_shade;
int anim_steps;
int border_snap_zone, window_snap_zone;
WindowOperation OpTitlebarDblClick;
// mouse bindings
MouseCommand CmdActiveTitlebar1;
MouseCommand CmdActiveTitlebar2;
MouseCommand CmdActiveTitlebar3;
MouseCommand CmdInactiveTitlebar1;
MouseCommand CmdInactiveTitlebar2;
MouseCommand CmdInactiveTitlebar3;
MouseCommand CmdWindow1;
MouseCommand CmdWindow2;
MouseCommand CmdWindow3;
MouseCommand CmdAll1;
MouseCommand CmdAll2;
MouseCommand CmdAll3;
};
extern Options* options;

View file

@ -346,7 +346,7 @@ void StdClient::paintEvent( QPaintEvent* )
void StdClient::mouseDoubleClickEvent( QMouseEvent * e )
{
if ( titlebar->geometry().contains( e->pos() ) )
setShade( !isShade() );
workspace()->performWindowOperation( this, options->operationTitlebarDblClick() );
workspace()->requestFocus( this );
}

View file

@ -221,6 +221,7 @@ void TabBox::paintContents()
int y = height() - 26;
for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it) {
if ( workspace()->hasClient( *it ) ) { // safety
p.save();
if ( !(*it)->miniIcon().isNull() )
p.drawPixmap( x, y, (*it)->miniIcon() );
else if ( menu_pix )
@ -228,6 +229,7 @@ void TabBox::paintContents()
p.setPen( (*it)==currentClient()?
colorGroup().highlight():colorGroup().background() );
p.drawRect( x-2, y-2, 20, 20 );
p.setPen( colorGroup().foreground() );
x += 20;
}
}

View file

@ -73,7 +73,7 @@ static Client* clientFactory( Workspace *ws, WId w )
}
KConfig *config = KGlobal::config();
config->setGroup("style");
config->setGroup("Style");
// well, it will be soon ;-)
QString tmpStr = config->readEntry("Plugin", "standard");
if(tmpStr == "system")
@ -805,6 +805,9 @@ void Workspace::requestFocus( Client* c)
focusToNull();
return;
}
if ( !popup || !popup->isVisible() )
popup_client = c;
if ( c->isVisible() && !c->isShade() ) {
c->takeFocus();
@ -866,13 +869,11 @@ QPopupMenu* Workspace::clientPopup( Client* c )
connect( desk_popup, SIGNAL( activated(int) ), this, SLOT( sendToDesktop(int) ) );
connect( desk_popup, SIGNAL( aboutToShow() ), this, SLOT( desktopPopupAboutToShow() ) );
popupIdMove = popup->insertItem( i18n("&Move") );
popupIdSize = popup->insertItem( i18n("&Size") );
popupIdMinimize = popup->insertItem( i18n("&Mi&nimize") );
popupIdMaximize = popup->insertItem( i18n("Ma&ximize") );
// popupIdFullscreen = popup->insertItem( i18n("&Fullscreen") );
popupIdFullscreen = 0;
popupIdShade = popup->insertItem( i18n("Sh&ade") );
popup->insertItem( i18n("&Move"), Options::MoveOp );
popup->insertItem( i18n("&Size"), Options::ResizeOp );
popup->insertItem( i18n("&Mi&nimize"), Options::IconifyOp );
popup->insertItem( i18n("Ma&ximize"), Options::MaximizeOp );
popup->insertItem( i18n("Sh&ade"), Options::ShadeOp );
popup->insertSeparator();
@ -882,25 +883,37 @@ QPopupMenu* Workspace::clientPopup( Client* c )
popup->insertSeparator();
QString k = KAccel::keyToString( keys->currentKey( "Window close" ), true );
popupIdClose = popup->insertItem(i18n("&Close")+'\t'+k );
popup->insertItem(i18n("&Close")+'\t'+k, Options::CloseOp );
}
return popup;
}
void Workspace::clientPopupActivated( int id )
{
if ( !popup_client )
void Workspace::performWindowOperation( Client* c, Options::WindowOperation op ) {
if ( !c )
return;
if ( id == popupIdClose )
popup_client->closeWindow();
else if ( id == popupIdMaximize )
popup_client->maximize();
else if ( id == popupIdMinimize )
popup_client->iconify();
else if ( id == popupIdFullscreen )
popup_client->fullScreen();
else if ( id == popupIdShade )
popup_client->setShade( !popup_client->isShade() );
switch ( op ) {
case Options::CloseOp:
c->closeWindow();
break;
case Options::MaximizeOp:
c->maximize();
break;
case Options::IconifyOp:
c->iconify();
break;
case Options::ShadeOp:
c->setShade( !c->isShade() );
break;
default:
break;
}
}
void Workspace::clientPopupActivated( int id )
{
if ( popup_client )
performWindowOperation( popup_client, (Options::WindowOperation) id );
}
/*!
@ -1320,11 +1333,6 @@ void Workspace::setCurrentDesktop( int new_desktop ){
}
void Workspace::makeFullScreen( Client* )
{
// not yet implemented
}
// experimental
void Workspace::setDecorationStyle( int deco )
@ -1536,8 +1544,8 @@ void Workspace::clientPopupAboutToShow()
{
if ( !popup_client || !popup )
return;
popup->setItemChecked( popupIdMaximize, popup_client->isMaximized() );
popup->setItemChecked( popupIdShade, popup_client->isShade() );
popup->setItemChecked( Options::MaximizeOp, popup_client->isMaximized() );
popup->setItemChecked( Options::ShadeOp, popup_client->isShade() );
}
void Workspace::sendToDesktop( int desk )

View file

@ -7,7 +7,7 @@
#include <qguardedptr.h>
#include <qvaluelist.h>
#include <X11/Xlib.h>
#include "options.h"
class Client;
class TabBox;
@ -95,13 +95,14 @@ public:
void setDesktopClient( Client* );
void makeFullScreen( Client* );
bool iconifyMeansWithdraw( Client* );
void iconifyOrDeiconifyTransientsOf( Client* );
bool hasCaption( const QString& caption );
void performWindowOperation( Client* c, Options::WindowOperation op );
public slots:
void setCurrentDesktop( int new_desktop );
// keybindings
@ -116,7 +117,7 @@ public slots:
void slotWindowOperations();
void slotWindowClose();
private slots:
void setDecorationStyle( int );
@ -145,8 +146,6 @@ private:
void freeKeyboard(bool pass);
QGuardedPtr<Client> popup_client;
QPopupMenu *popup;
int popupIdMove, popupIdSize, popupIdMinimize,popupIdMaximize,
popupIdShade, popupIdFullscreen,popupIdClose;
QPopupMenu *desk_popup;
Client* should_get_focus;