- make maximized windows

- adjust to workarea changes
	- not movable or resizable
	- not show vertical borders if not necessary

 - new default style: middle mouse and right mouse for maximize button

 - now resize mouse cursors if the window is not resizable

svn path=/trunk/kdebase/kwin/; revision=61240
This commit is contained in:
Matthias Ettrich 2000-08-16 12:18:56 +00:00
parent 49bb12bd95
commit 078b8b3ff4
5 changed files with 100 additions and 24 deletions

View file

@ -492,7 +492,7 @@ bool Client::manage( bool isMapped, bool doNotShow )
if ( isMapped || session || isTransient() ) { if ( isMapped || session || isTransient() ) {
placementDone = TRUE; placementDone = TRUE;
if ( geom == QApplication::desktop()->geometry() ) if ( geom == workspace()->geometry() )
may_move = FALSE; // don't let fullscreen windows be moved around may_move = FALSE; // don't let fullscreen windows be moved around
} else { } else {
QRect area = workspace()->clientArea(); QRect area = workspace()->clientArea();
@ -1105,6 +1105,16 @@ bool Client::isResizable() const
( xSizeHint.min_height != xSizeHint.max_height ); ( xSizeHint.min_height != xSizeHint.max_height );
} }
/*
Returns whether the window is maximizable or not
*/
bool Client::isMaximizable() const
{
if ( isMaximized() )
return TRUE;
return isResizable() && !isTransient();
}
/*! /*!
Reimplemented to provide move/resize Reimplemented to provide move/resize
@ -1208,6 +1218,11 @@ void Client::mouseMoveEvent( QMouseEvent * e)
QPoint p( e->pos() - moveOffset ); QPoint p( e->pos() - moveOffset );
if (p.manhattanLength() >= 6) { if (p.manhattanLength() >= 6) {
moveResizeMode = TRUE; moveResizeMode = TRUE;
if ( isMaximized() ) {
// in case we were maximized, reset state
geom_restore = QRect();
maximizeChange(FALSE );
}
workspace()->setFocusChangeEnabled(false); workspace()->setFocusChangeEnabled(false);
Events::raise( isResize() ? Events::ResizeStart : Events::MoveStart ); Events::raise( isResize() ? Events::ResizeStart : Events::MoveStart );
grabMouse( cursor() ); // to keep the right cursor grabMouse( cursor() ); // to keep the right cursor
@ -1534,20 +1549,24 @@ void Client::killWindow()
void Client::maximize( MaximizeMode m) void Client::maximize( MaximizeMode m)
{ {
if (!isMovable() || !isResizable() ) if ( !isMaximizable() )
return; return;
QRect clientArea = workspace()->clientArea(); QRect clientArea = workspace()->clientArea();
if (isShade()) if (isShade())
setShade( FALSE ); setShade( FALSE );
if ( !geom_restore.isNull() ) if ( m == MaximizeAdjust ) {
m = MaximizeRestore; m = max_mode;
} else {
if ( !geom_restore.isNull() )
m = MaximizeRestore;
if ( m != MaximizeRestore ) { if ( m != MaximizeRestore ) {
Events::raise( Events::Maximize ); Events::raise( Events::Maximize );
geom_restore = geometry(); geom_restore = geometry();
}
} }
switch (m) { switch (m) {
@ -1573,19 +1592,28 @@ void Client::maximize( MaximizeMode m)
case MaximizeRestore: { case MaximizeRestore: {
Events::raise( Events::UnMaximize ); Events::raise( Events::UnMaximize );
setGeometry(geom_restore); setGeometry(geom_restore);
QRect invalid; geom_restore = QRect();
geom_restore = invalid;
info->setState( 0, NET::Max ); info->setState( 0, NET::Max );
} break; } break;
case MaximizeFull: case MaximizeFull: {
QRect r = QRect(clientArea.topLeft(), adjustedSize(clientArea.size()));
setGeometry(
QRect(clientArea.topLeft(), adjustedSize(clientArea.size())) // hide right and left border of maximized windows
); if ( r.left() == 0 )
r.setLeft( r.left() - windowWrapper()->x() );
if ( r.right() == workspace()->geometry().right() )
r.setRight( r.right() + width() - windowWrapper()->geometry().right() );
setGeometry( r );
info->setState( NET::Max, NET::Max ); info->setState( NET::Max, NET::Max );
} break;
default:
break;
} }
max_mode = m;
maximizeChange( m != MaximizeRestore ); maximizeChange( m != MaximizeRestore );
} }
@ -1703,7 +1731,7 @@ bool Client::x11Event( XEvent * e)
workspace()->requestFocus( this ); workspace()->requestFocus( this );
return TRUE; return TRUE;
} }
if ( e->type == LeaveNotify && e->xcrossing.mode == NotifyNormal ) { if ( e->type == LeaveNotify && e->xcrossing.mode == NotifyNormal ) {
if ( !buttonDown ) if ( !buttonDown )
setCursor( arrowCursor ); setCursor( arrowCursor );
@ -1717,7 +1745,7 @@ bool Client::x11Event( XEvent * e)
workspace()->requestFocus( 0 ) ; workspace()->requestFocus( 0 ) ;
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
@ -1767,6 +1795,11 @@ Client::MousePosition Client::mousePosition( const QPoint& p ) const
*/ */
void Client::setMouseCursor( MousePosition m ) void Client::setMouseCursor( MousePosition m )
{ {
if ( !isResizable() ) {
setCursor( arrowCursor );
return;
}
switch ( m ) { switch ( m ) {
case TopLeft: case TopLeft:
case BottomRight: case BottomRight:
@ -2082,6 +2115,11 @@ bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPo
break; break;
mode = Center; mode = Center;
moveResizeMode = TRUE; moveResizeMode = TRUE;
if ( isMaximized() ) {
// in case we were maximized, reset state
geom_restore = QRect();
maximizeChange(FALSE );
}
workspace()->setFocusChangeEnabled(false); workspace()->setFocusChangeEnabled(false);
buttonDown = TRUE; buttonDown = TRUE;
moveOffset = mapFromGlobal( globalPos ); moveOffset = mapFromGlobal( globalPos );
@ -2095,6 +2133,11 @@ bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPo
if (!isMovable()) if (!isMovable())
break; break;
moveResizeMode = TRUE; moveResizeMode = TRUE;
if ( isMaximized() ) {
// in case we were maximized, reset state
geom_restore = QRect();
maximizeChange(FALSE );
}
workspace()->setFocusChangeEnabled(false); workspace()->setFocusChangeEnabled(false);
buttonDown = TRUE; buttonDown = TRUE;
moveOffset = mapFromGlobal( globalPos ); moveOffset = mapFromGlobal( globalPos );
@ -2303,7 +2346,9 @@ bool Client::wantsTabFocus() const
*/ */
bool Client::isMovable() const bool Client::isMovable() const
{ {
return may_move && ( windowType() == NET::Normal || windowType() == NET::Toolbar ); return may_move &&
( windowType() == NET::Normal || windowType() == NET::Toolbar ) &&
( !isMaximized() || max_mode != MaximizeFull );
} }
bool Client::isDesktop() const bool Client::isDesktop() const

View file

@ -113,7 +113,8 @@ public:
void giveUpShade(); void giveUpShade();
bool isMaximized() const; bool isMaximized() const;
enum MaximizeMode { MaximizeVertical, MaximizeHorizontal, MaximizeFull, MaximizeRestore }; enum MaximizeMode { MaximizeVertical, MaximizeHorizontal, MaximizeFull, MaximizeRestore, MaximizeAdjust };
bool isMaximizable() const;
bool isSticky() const; bool isSticky() const;
void setSticky( bool ); void setSticky( bool );
@ -264,6 +265,7 @@ private:
QPixmap icon_pix; QPixmap icon_pix;
QPixmap miniicon_pix; QPixmap miniicon_pix;
QRect geom_restore; QRect geom_restore;
MaximizeMode max_mode;
QRegion mask; QRegion mask;
WinInfo* info; WinInfo* info;
QTimer* autoRaiseTimer; QTimer* autoRaiseTimer;
@ -364,7 +366,6 @@ inline bool Client::shape() const
return is_shape; return is_shape;
} }
inline const QRegion& Client::getMask() const inline const QRegion& Client::getMask() const
{ {
return mask; return mask;

View file

@ -342,7 +342,7 @@ KDEClient::KDEClient( Workspace *ws, WId w, QWidget *parent,
connect( button[BtnClose], SIGNAL( clicked() ), this, ( SLOT( closeWindow() ) ) ); connect( button[BtnClose], SIGNAL( clicked() ), this, ( SLOT( closeWindow() ) ) );
connect( button[BtnSticky], SIGNAL( clicked() ), this, ( SLOT( toggleSticky() ) ) ); connect( button[BtnSticky], SIGNAL( clicked() ), this, ( SLOT( toggleSticky() ) ) );
connect( button[BtnIconify], SIGNAL( clicked() ), this, ( SLOT( iconify() ) ) ); connect( button[BtnIconify], SIGNAL( clicked() ), this, ( SLOT( iconify() ) ) );
connect( button[BtnMax], SIGNAL( clicked() ), this, ( SLOT( maximize() ) ) ); connect( button[BtnMax], SIGNAL( clicked() ), this, ( SLOT( slotMaximize() ) ) );
hb = new QHBoxLayout(); hb = new QHBoxLayout();
hb->setResizeMode(QLayout::FreeResize); hb->setResizeMode(QLayout::FreeResize);
@ -359,7 +359,7 @@ KDEClient::KDEClient( Workspace *ws, WId w, QWidget *parent,
hb->addWidget( button[BtnSticky]); hb->addWidget( button[BtnSticky]);
hb->addWidget( button[BtnIconify]); hb->addWidget( button[BtnIconify]);
hb->addWidget( button[BtnMax]); hb->addWidget( button[BtnMax]);
if ( isTransient() ) { if ( isTransient() ) {
button[BtnSticky]->hide(); button[BtnSticky]->hide();
button[BtnIconify]->hide(); button[BtnIconify]->hide();
@ -369,6 +369,16 @@ KDEClient::KDEClient( Workspace *ws, WId w, QWidget *parent,
hiddenItems = false; hiddenItems = false;
} }
void KDEClient::slotMaximize()
{
if ( button[BtnMax]->last_button == MidButton )
maximize( MaximizeVertical );
else if ( button[BtnMax]->last_button == RightButton )
maximize( MaximizeHorizontal );
else
maximize();
}
void KDEClient::resizeEvent( QResizeEvent* e) void KDEClient::resizeEvent( QResizeEvent* e)
{ {
Client::resizeEvent( e ); Client::resizeEvent( e );

View file

@ -19,7 +19,21 @@ public:
void setBitmap(const unsigned char *bitmap); void setBitmap(const unsigned char *bitmap);
void reset(); void reset();
QSize sizeHint() const; QSize sizeHint() const;
int last_button;
protected: protected:
void mousePressEvent( QMouseEvent* e )
{
last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() );
QButton::mousePressEvent( &me );
}
void mouseReleaseEvent( QMouseEvent* e )
{
last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() );
QButton::mouseReleaseEvent( &me );
}
virtual void drawButton(QPainter *p); virtual void drawButton(QPainter *p);
void drawButtonLabel(QPainter *){;} void drawButtonLabel(QPainter *){;}
QSize defaultSize; QSize defaultSize;
@ -51,13 +65,14 @@ protected:
void updateActiveBuffer(); void updateActiveBuffer();
protected slots: protected slots:
void slotReset(); void slotReset();
void slotMaximize();
private: private:
SystemButton* button[5]; SystemButton* button[5];
QSpacerItem* titlebar; QSpacerItem* titlebar;
bool hiddenItems; bool hiddenItems;
QHBoxLayout *hb; QHBoxLayout *hb;
KPixmap activeBuffer; KPixmap activeBuffer;
}; };

View file

@ -2158,7 +2158,7 @@ void Workspace::clientPopupAboutToShow()
return; return;
popup->setItemEnabled( Options::ResizeOp, popup_client->isResizable() ); popup->setItemEnabled( Options::ResizeOp, popup_client->isResizable() );
popup->setItemEnabled( Options::MoveOp, popup_client->isMovable() ); popup->setItemEnabled( Options::MoveOp, popup_client->isMovable() );
popup->setItemEnabled( Options::MaximizeOp, popup_client->isResizable() && !popup_client->isTransient() ); popup->setItemEnabled( Options::MaximizeOp, popup_client->isMaximizable() );
popup->setItemChecked( Options::MaximizeOp, popup_client->isMaximized() ); popup->setItemChecked( Options::MaximizeOp, popup_client->isMaximized() );
popup->setItemChecked( Options::ShadeOp, popup_client->isShade() ); popup->setItemChecked( Options::ShadeOp, popup_client->isShade() );
popup->setItemChecked( Options::StaysOnTopOp, popup_client->staysOnTop() ); popup->setItemChecked( Options::StaysOnTopOp, popup_client->staysOnTop() );
@ -2700,6 +2700,11 @@ void Workspace::updateClientArea()
r.size.height = area.height(); r.size.height = area.height();
for( int i = 1; i <= numberOfDesktops(); i++) for( int i = 1; i <= numberOfDesktops(); i++)
rootInfo->setWorkArea( i, r ); rootInfo->setWorkArea( i, r );
for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it) {
if ( (*it)->isMaximized() )
(*it)->maximize( Client::MaximizeAdjust );
}
} }
} }