Add ability to switch windows spatially with alt+meta+<direction>.
Patch based off code by Dominik Kapusta and Lindsay Roberts. FEATURE: 74214 svn path=/trunk/KDE/kdebase/workspace/; revision=1030903
This commit is contained in:
parent
39a68673a4
commit
9f420c13ab
3 changed files with 119 additions and 0 deletions
|
@ -119,6 +119,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
0, slotWindowQuickTileLeft() );
|
||||
DEF2( "Window Quick Tile Right", I18N_NOOP("Quick Tile Window to the Right"),
|
||||
0, slotWindowQuickTileRight() );
|
||||
DEF2( "Switch Window Up", I18N_NOOP("Switch to Window Above"),
|
||||
Qt::META+Qt::ALT+Qt::Key_Up, slotSwitchWindowUp() );
|
||||
DEF2( "Switch Window Down", I18N_NOOP("Switch to Window Below"),
|
||||
Qt::META+Qt::ALT+Qt::Key_Down, slotSwitchWindowDown() );
|
||||
DEF2( "Switch Window Right", I18N_NOOP("Switch to Window to the Right"),
|
||||
Qt::META+Qt::ALT+Qt::Key_Right, slotSwitchWindowRight() );
|
||||
DEF2( "Switch Window Left", I18N_NOOP("Switch to Window to the Left"),
|
||||
Qt::META+Qt::ALT+Qt::Key_Left, slotSwitchWindowLeft() );
|
||||
|
||||
a = actionCollection->addAction( "Group:Window Desktop" );
|
||||
a->setText( i18n("Window & Desktop") );
|
||||
|
|
|
@ -1190,6 +1190,104 @@ void Workspace::slotSendToDesktop( QAction *action )
|
|||
|
||||
}
|
||||
|
||||
/*!
|
||||
Switches to the nearest window in given direction
|
||||
*/
|
||||
void Workspace::switchWindow( Direction direction )
|
||||
{
|
||||
if( !active_client )
|
||||
return;
|
||||
Client *c = active_client;
|
||||
Client *switchTo = 0;
|
||||
int bestScore = 0;
|
||||
int d = c->desktop();
|
||||
// Centre of the active window
|
||||
QPoint curPos( c->pos().x() + c->geometry().width() / 2,
|
||||
c->pos().y() + c->geometry().height() / 2 );
|
||||
|
||||
QList<Client *> clist = stackingOrder();
|
||||
for( QList<Client *>::Iterator i = clist.begin(); i != clist.end(); ++i )
|
||||
{
|
||||
if( (*i)->wantsTabFocus() && *i != c &&
|
||||
(*i)->desktop() == d && ! (*i)->isMinimized() )
|
||||
{
|
||||
// Centre of the other window
|
||||
QPoint other( (*i)->pos().x() + (*i)->geometry().width() / 2,
|
||||
(*i)->pos().y() + (*i)->geometry().height() / 2 );
|
||||
|
||||
int distance;
|
||||
int offset;
|
||||
switch( direction )
|
||||
{
|
||||
case DirectionNorth:
|
||||
distance = curPos.y() - other.y();
|
||||
offset = qAbs(other.x() - curPos.x());
|
||||
break;
|
||||
case DirectionEast:
|
||||
distance = other.x() - curPos.x();
|
||||
offset = qAbs(other.y() - curPos.y());
|
||||
break;
|
||||
case DirectionSouth:
|
||||
distance = other.y() - curPos.y();
|
||||
offset = qAbs(other.x() - curPos.x());
|
||||
break;
|
||||
case DirectionWest:
|
||||
distance = curPos.x() - other.x();
|
||||
offset = qAbs(other.y() - curPos.y());
|
||||
break;
|
||||
default:
|
||||
distance = -1;
|
||||
offset = -1;
|
||||
}
|
||||
|
||||
if( distance > 0 )
|
||||
{
|
||||
// Inverse score
|
||||
int score = distance + offset + ( (offset * offset) / distance );
|
||||
if( score < bestScore || !switchTo )
|
||||
{
|
||||
switchTo = *i;
|
||||
bestScore = score;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( switchTo )
|
||||
activateClient( switchTo );
|
||||
}
|
||||
|
||||
/*!
|
||||
Switches to upper window
|
||||
*/
|
||||
void Workspace::slotSwitchWindowUp()
|
||||
{
|
||||
switchWindow( DirectionNorth );
|
||||
}
|
||||
|
||||
/*!
|
||||
Switches to lower window
|
||||
*/
|
||||
void Workspace::slotSwitchWindowDown()
|
||||
{
|
||||
switchWindow( DirectionSouth );
|
||||
}
|
||||
|
||||
/*!
|
||||
Switches to window on the right
|
||||
*/
|
||||
void Workspace::slotSwitchWindowRight()
|
||||
{
|
||||
switchWindow( DirectionEast );
|
||||
}
|
||||
|
||||
/*!
|
||||
Switches to window on the left
|
||||
*/
|
||||
void Workspace::slotSwitchWindowLeft()
|
||||
{
|
||||
switchWindow( DirectionWest );
|
||||
}
|
||||
|
||||
/*!
|
||||
Shows the window operations popup menu for the activeClient()
|
||||
*/
|
||||
|
|
13
workspace.h
13
workspace.h
|
@ -590,6 +590,11 @@ class Workspace : public QObject, public KDecorationDefines
|
|||
void slotWalkThroughWindowsAlternativeKeyChanged( const QKeySequence& seq );
|
||||
void slotWalkBackThroughWindowsAlternativeKeyChanged( const QKeySequence& seq );
|
||||
|
||||
void slotSwitchWindowUp();
|
||||
void slotSwitchWindowDown();
|
||||
void slotSwitchWindowRight();
|
||||
void slotSwitchWindowLeft();
|
||||
|
||||
void slotWindowOperations();
|
||||
void slotWindowClose();
|
||||
void slotWindowMove();
|
||||
|
@ -671,6 +676,14 @@ class Workspace : public QObject, public KDecorationDefines
|
|||
void setupWindowShortcut( Client* c );
|
||||
void checkCursorPos();
|
||||
|
||||
enum Direction
|
||||
{
|
||||
DirectionNorth,
|
||||
DirectionEast,
|
||||
DirectionSouth,
|
||||
DirectionWest
|
||||
};
|
||||
void switchWindow( Direction direction );
|
||||
bool startKDEWalkThroughWindows( TabBoxMode mode ); // TabBoxWindowsMode | TabBoxWindowsAlternativeMode
|
||||
bool startWalkThroughDesktops( TabBoxMode mode ); // TabBoxDesktopMode | TabBoxDesktopListMode
|
||||
bool startWalkThroughDesktops();
|
||||
|
|
Loading…
Reference in a new issue