From c3d3c81d648803c93474f064a370254dc13f40b1 Mon Sep 17 00:00:00 2001 From: Waldo Bastian Date: Tue, 30 May 2000 05:52:11 +0000 Subject: [PATCH] WABA: Keep focus with same window after switching desktops svn path=/trunk/kdebase/kwin/; revision=51128 --- client.h | 8 +++++++ workspace.cpp | 60 +++++++++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/client.h b/client.h index 94cb7d800a..bc1786acf6 100644 --- a/client.h +++ b/client.h @@ -122,6 +122,13 @@ public: bool mayMove() const { return may_move; } void setMayMove( bool m) { may_move = m; } + /** + * A window with passive focus will only get focus when + * the user explicitly selects the window. + **/ + bool passiveFocus() const { return passive_focus; } + void setPassiveFocus( bool p) { passive_focus = p; } + void takeFocus(); void setMask( const QRegion & ); @@ -238,6 +245,7 @@ private: bool is_sticky; bool is_shape; bool may_move; + bool passive_focus; void getWMHints(); void getWindowProtocols(); uint Pdeletewindow :1; // does the window understand the DeleteWindow protocol? diff --git a/workspace.cpp b/workspace.cpp index d75bf23194..f500710703 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -126,18 +126,21 @@ Client* Workspace::clientFactory( Workspace *ws, WId w ) c->setSticky( TRUE ); c->setMayMove( FALSE ); ws->setDesktopClient( c ); + c->setPassiveFocus( TRUE ); return c; } if ( s.lower().right(6) == "kicker" ) { Client * c = new NoBorderClient( ws, w); c->setSticky( TRUE ); c->setMayMove( FALSE ); + c->setPassiveFocus( TRUE ); return c; } if ( s == "MAC MENU [menu]" ) { Client * c = new NoBorderClient( ws, w); c->setSticky( TRUE ); c->setMayMove( FALSE ); + c->setPassiveFocus( TRUE ); return c; } if ( ( s.right(6) == "[menu]" ) || ( s.right(7) == "[tools]" ) ) { @@ -1537,29 +1540,28 @@ void Workspace::setDesktopClient( Client* c) propages the new desktop to the world */ void Workspace::setCurrentDesktop( int new_desktop ){ - if (new_desktop == current_desktop || new_desktop < 1 || new_desktop > number_of_desktops ) + if (new_desktop < 1 || new_desktop > number_of_desktops ) return; - active_client = 0; block_focus = TRUE; - /* - optimized Desktop switching: unmapping done from back to front - mapping done from front to back => less exposure events - */ + if (new_desktop != current_desktop) { + /* + optimized Desktop switching: unmapping done from back to front + mapping done from front to back => less exposure events + */ - for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it) { - if ( (*it)->isVisible() && !(*it)->isOnDesktop( new_desktop ) ) { - (*it)->hide(); - } + for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it) { + if ( (*it)->isVisible() && !(*it)->isOnDesktop( new_desktop ) ) { + (*it)->hide(); + } + } + for ( ClientList::ConstIterator it = stacking_order.fromLast(); it != stacking_order.end(); --it) { + if ( (*it)->isOnDesktop( new_desktop ) && !(*it)->isIconified() ) { + (*it)->show(); + } + } } - for ( ClientList::ConstIterator it = stacking_order.fromLast(); it != stacking_order.end(); --it) { - if ( (*it)->isOnDesktop( new_desktop ) && !(*it)->isIconified() ) { - (*it)->show(); - } - } - - current_desktop = new_desktop; XChangeProperty(qt_xdisplay(), qt_xrootwin(), @@ -1569,25 +1571,31 @@ void Workspace::setCurrentDesktop( int new_desktop ){ // restore the focus on this desktop block_focus = FALSE; - Client* c = active_client?active_client:previousClient(0); - Client* stop = c; - while ( c && !c->isVisible() ) { - c = previousClient( c ); - if ( c == stop ) - break; + Client* c = active_client; + + if ( !c || !c->isVisible() || c->passiveFocus()) { + c = nextClient(0); + Client* stop = c; + while ( c && (!c->isVisible() || c->passiveFocus()) ) { + c = nextClient( c ); + if ( c == stop ) + break; + } } - if ( !c || !c->isVisible() ) { + if ( !c || !c->isVisible() || c->passiveFocus()) { // there's no suitable client in the focus chain. Try to find any other client then. for ( ClientList::ConstIterator it = stacking_order.begin(); it != stacking_order.end(); ++it) { - if ( (*it)->isVisible() ) { + if ( (*it)->isVisible() && !(*it)->passiveFocus() ) { c = *it; break; } } } - if ( c && c->isVisible() ) + if ( c && c->isVisible() && !c->passiveFocus()) requestFocus( c ); + else + focusToNull(); QApplication::syncX(); KWM::switchToDesktop( current_desktop ); // ### compatibility