2007-11-27 19:40:25 +00:00
/********************************************************************
2007-04-29 17:35:43 +00:00
KWin - the KDE window manager
This file is part of the KDE project .
Copyright ( C ) 1999 , 2000 Matthias Ettrich < ettrich @ kde . org >
Copyright ( C ) 2003 Lubos Lunak < l . lunak @ kde . org >
2009-03-03 11:45:39 +00:00
Copyright ( C ) 2009 Martin Gräßlin < kde @ martin - graesslin . com >
2007-04-29 17:35:43 +00:00
2007-11-27 19:40:25 +00:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-29 17:35:43 +00:00
//#define QT_CLEAN_NAMESPACE
2009-09-13 11:36:45 +00:00
// own
2007-04-29 17:35:43 +00:00
# include "tabbox.h"
2009-09-13 11:36:45 +00:00
// tabbox
# include "tabbox/clientmodel.h"
# include "tabbox/desktopmodel.h"
# include "tabbox/tabboxconfig.h"
// kwin
2007-04-29 17:35:43 +00:00
# include "client.h"
2009-09-13 11:36:45 +00:00
# include "effects.h"
# include "workspace.h"
// Qt
2007-04-30 00:52:51 +00:00
# include <QAction>
2007-04-29 17:35:43 +00:00
# include <QX11Info>
2011-08-21 08:44:09 +00:00
# include <QtDBus/QDBusConnection>
2009-09-13 11:36:45 +00:00
// KDE
# include <KActionCollection>
# include <KConfig>
# include <KConfigGroup>
2011-06-30 11:02:30 +00:00
# include <KDE/KAction>
2009-09-13 11:36:45 +00:00
# include <KDebug>
2011-02-17 18:35:08 +00:00
# include <KLocale>
2007-04-29 17:35:43 +00:00
# include <kkeyserver.h>
2009-09-13 11:36:45 +00:00
// X11
# include <fixx11h.h>
# include <X11/keysym.h>
# include <X11/keysymdef.h>
2011-04-28 09:16:27 +00:00
# include "outline.h"
2007-04-29 17:35:43 +00:00
// specify externals before namespace
namespace KWin
{
extern QPixmap * kwin_get_menu_pix_hack ( ) ;
2009-09-13 11:36:45 +00:00
namespace TabBox
{
2011-06-25 16:05:07 +00:00
TabBoxHandlerImpl : : TabBoxHandlerImpl ( TabBox * tabBox )
2009-09-13 11:36:45 +00:00
: TabBoxHandler ( )
2011-06-25 16:05:07 +00:00
, m_tabBox ( tabBox )
2011-01-30 14:34:42 +00:00
{
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
TabBoxHandlerImpl : : ~ TabBoxHandlerImpl ( )
2011-01-30 14:34:42 +00:00
{
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxHandlerImpl : : activeScreen ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return Workspace : : self ( ) - > activeScreen ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxHandlerImpl : : currentDesktop ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return Workspace : : self ( ) - > currentDesktop ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
QString TabBoxHandlerImpl : : desktopName ( TabBoxClient * client ) const
{
if ( TabBoxClientImpl * c = static_cast < TabBoxClientImpl * > ( client ) ) {
if ( ! c - > client ( ) - > isOnAllDesktops ( ) )
return Workspace : : self ( ) - > desktopName ( c - > client ( ) - > desktop ( ) ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
return Workspace : : self ( ) - > desktopName ( Workspace : : self ( ) - > currentDesktop ( ) ) ;
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
QString TabBoxHandlerImpl : : desktopName ( int desktop ) const
{
return Workspace : : self ( ) - > desktopName ( desktop ) ;
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
TabBoxClient * TabBoxHandlerImpl : : nextClientFocusChain ( TabBoxClient * client ) const
{
if ( TabBoxClientImpl * c = static_cast < TabBoxClientImpl * > ( client ) ) {
2011-06-25 16:05:07 +00:00
Client * next = Workspace : : self ( ) - > tabBox ( ) - > nextClientFocusChain ( c - > client ( ) ) ;
2011-01-30 14:34:42 +00:00
if ( next )
2009-09-13 13:46:58 +00:00
return next - > tabBoxClient ( ) ;
2009-09-13 11:36:45 +00:00
}
2011-01-30 14:34:42 +00:00
return NULL ;
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
int TabBoxHandlerImpl : : nextDesktopFocusChain ( int desktop ) const
{
2011-06-25 16:05:07 +00:00
return m_tabBox - > nextDesktopFocusChain ( desktop ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxHandlerImpl : : numberOfDesktops ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return Workspace : : self ( ) - > numberOfDesktops ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
TabBoxClient * TabBoxHandlerImpl : : activeClient ( ) const
2011-01-30 14:34:42 +00:00
{
if ( Workspace : : self ( ) - > activeClient ( ) )
2009-09-13 11:36:45 +00:00
return Workspace : : self ( ) - > activeClient ( ) - > tabBoxClient ( ) ;
2007-04-29 17:35:43 +00:00
else
2009-09-13 11:36:45 +00:00
return NULL ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
TabBoxClient * TabBoxHandlerImpl : : clientToAddToList ( TabBoxClient * client , int desktop , bool allDesktops ) const
{
2009-09-13 11:36:45 +00:00
Workspace * workspace = Workspace : : self ( ) ;
Client * ret = NULL ;
2011-01-30 14:34:42 +00:00
Client * current = ( static_cast < TabBoxClientImpl * > ( client ) ) - > client ( ) ;
2009-09-13 11:36:45 +00:00
bool addClient = false ;
2009-10-30 11:22:39 +00:00
bool applications = ( config ( ) . clientListMode ( ) = = TabBoxConfig : : AllDesktopsApplicationList | |
config ( ) . clientListMode ( ) = = TabBoxConfig : : CurrentDesktopApplicationList ) ;
2011-01-30 14:34:42 +00:00
if ( allDesktops )
2009-09-13 11:36:45 +00:00
addClient = true ;
else
2011-01-30 14:34:42 +00:00
addClient = current - > isOnDesktop ( desktop ) ;
2010-05-13 04:30:34 +00:00
addClient = addClient & & current - > isOnCurrentActivity ( ) ;
2010-05-03 20:04:44 +00:00
addClient = addClient & & current - > wantsTabFocus ( ) & & ! current - > skipSwitcher ( ) ;
2011-01-30 14:34:42 +00:00
if ( addClient ) {
// don't add windows that have modal dialogs
2009-09-13 11:36:45 +00:00
Client * modal = current - > findModal ( ) ;
2011-01-30 14:34:42 +00:00
if ( modal = = NULL | | modal = = current )
2009-09-13 11:36:45 +00:00
ret = current ;
2011-01-30 14:34:42 +00:00
else if ( ! clientList ( ) . contains ( modal - > tabBoxClient ( ) ) )
2009-09-13 11:36:45 +00:00
ret = modal ;
2011-01-30 14:34:42 +00:00
else {
2009-09-13 11:36:45 +00:00
// nothing
2011-01-30 14:34:42 +00:00
}
if ( ret & & applications ) {
2009-10-30 11:22:39 +00:00
// check if the list already contains an entry of this application
2011-01-30 14:34:42 +00:00
foreach ( TabBoxClient * tabBoxClient , clientList ( ) ) {
if ( TabBoxClientImpl * c = dynamic_cast < TabBoxClientImpl * > ( tabBoxClient ) ) {
if ( c - > client ( ) - > resourceClass ( ) = = ret - > resourceClass ( ) ) {
2009-10-30 11:22:39 +00:00
ret = NULL ;
break ;
}
}
}
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
if ( options - > separateScreenFocus & & options - > xineramaEnabled ) {
if ( current - > screen ( ) ! = workspace - > activeScreen ( ) )
2009-09-13 11:36:45 +00:00
ret = NULL ;
2011-01-30 14:34:42 +00:00
}
if ( ret )
2009-09-13 11:36:45 +00:00
return ret - > tabBoxClient ( ) ;
else
return NULL ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
TabBoxClientList TabBoxHandlerImpl : : stackingOrder ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
ClientList stacking = Workspace : : self ( ) - > stackingOrder ( ) ;
TabBoxClientList ret ;
2011-01-30 14:34:42 +00:00
foreach ( const Client * client , stacking ) {
ret . append ( client - > tabBoxClient ( ) ) ;
2010-10-17 20:30:33 +00:00
}
2011-01-30 14:34:42 +00:00
return ret ;
}
void TabBoxHandlerImpl : : raiseClient ( TabBoxClient * c ) const
{
Workspace : : self ( ) - > raiseClient ( static_cast < TabBoxClientImpl * > ( c ) - > client ( ) ) ;
}
2010-10-17 20:30:33 +00:00
2011-01-30 14:34:42 +00:00
void TabBoxHandlerImpl : : restack ( TabBoxClient * c , TabBoxClient * under )
2010-10-17 20:30:33 +00:00
{
2011-01-30 14:34:42 +00:00
Workspace : : self ( ) - > restack ( static_cast < TabBoxClientImpl * > ( c ) - > client ( ) ,
static_cast < TabBoxClientImpl * > ( under ) - > client ( ) ) ;
2010-10-17 20:30:33 +00:00
}
2007-04-29 17:35:43 +00:00
2010-03-19 10:15:56 +00:00
TabBoxClient * TabBoxHandlerImpl : : desktopClient ( ) const
2011-01-30 14:34:42 +00:00
{
foreach ( const Client * client , Workspace : : self ( ) - > stackingOrder ( ) ) {
if ( client - > isDesktop ( ) & & client - > isOnCurrentDesktop ( ) & & client - > screen ( ) = = Workspace : : self ( ) - > activeScreen ( ) ) {
2010-03-19 10:15:56 +00:00
return client - > tabBoxClient ( ) ;
}
}
2011-01-30 14:34:42 +00:00
return NULL ;
}
2010-03-19 10:15:56 +00:00
2011-04-28 09:16:27 +00:00
void TabBoxHandlerImpl : : showOutline ( const QRect & outline )
{
Workspace : : self ( ) - > outline ( ) - > show ( outline ) ;
}
void TabBoxHandlerImpl : : hideOutline ( )
{
Workspace : : self ( ) - > outline ( ) - > hide ( ) ;
}
QVector < Window > TabBoxHandlerImpl : : outlineWindowIds ( ) const
{
return Workspace : : self ( ) - > outline ( ) - > windowIds ( ) ;
}
2011-11-27 16:03:35 +00:00
void TabBoxHandlerImpl : : activateAndClose ( )
{
Client * c = NULL ;
if ( TabBoxClientImpl * cl = static_cast < TabBoxClientImpl * > ( client ( currentIndex ( ) ) ) ) {
c = cl - > client ( ) ;
}
m_tabBox - > close ( ) ;
if ( c ) {
Workspace : : self ( ) - > activateClient ( c ) ;
if ( c - > isShade ( ) & & options - > shadeHover )
c - > setShade ( ShadeActivated ) ;
if ( c - > isDesktop ( ) )
Workspace : : self ( ) - > setShowingDesktop ( ! Workspace : : self ( ) - > showingDesktop ( ) ) ;
}
}
2011-04-28 09:16:27 +00:00
2009-09-13 11:36:45 +00:00
/*********************************************************
* TabBoxClientImpl
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
TabBoxClientImpl : : TabBoxClientImpl ( )
: TabBoxClient ( )
2011-01-30 14:34:42 +00:00
{
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
TabBoxClientImpl : : ~ TabBoxClientImpl ( )
2011-01-30 14:34:42 +00:00
{
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
QString TabBoxClientImpl : : caption ( ) const
2011-01-30 14:34:42 +00:00
{
if ( m_client - > isDesktop ( ) )
return i18nc ( " Special entry in alt+tab list for minimizing all windows " ,
" Show Desktop " ) ;
2009-09-13 11:36:45 +00:00
return m_client - > caption ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
QPixmap TabBoxClientImpl : : icon ( const QSize & size ) const
{
return m_client - > icon ( size ) ;
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
WId TabBoxClientImpl : : window ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_client - > window ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
bool TabBoxClientImpl : : isMinimized ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_client - > isMinimized ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxClientImpl : : x ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_client - > x ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxClientImpl : : y ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_client - > y ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxClientImpl : : width ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_client - > width ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
int TabBoxClientImpl : : height ( ) const
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_client - > height ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-11-27 13:15:49 +00:00
bool TabBoxClientImpl : : isCloseable ( ) const
{
return m_client - > isCloseable ( ) ;
}
2011-11-27 14:00:09 +00:00
void TabBoxClientImpl : : close ( )
{
m_client - > closeWindow ( ) ;
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
/*********************************************************
* TabBox
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-06-30 11:02:30 +00:00
TabBox : : TabBox ( QObject * parent )
: QObject ( parent )
2011-06-25 16:05:07 +00:00
, m_displayRefcount ( 0 )
, m_desktopGrab ( false )
, m_tabGrab ( false )
2011-08-21 08:44:09 +00:00
, m_noModifierGrab ( false )
2011-07-08 19:52:56 +00:00
, m_forcedGlobalMouseGrab ( false )
2011-07-09 08:32:26 +00:00
, m_ready ( false )
2011-01-30 14:34:42 +00:00
{
2009-09-13 12:15:04 +00:00
m_isShown = false ;
2009-09-13 11:36:45 +00:00
m_defaultConfig = TabBoxConfig ( ) ;
2011-01-30 14:34:42 +00:00
m_defaultConfig . setTabBoxMode ( TabBoxConfig : : ClientTabBox ) ;
m_defaultConfig . setClientListMode ( TabBoxConfig : : CurrentDesktopClientList ) ;
m_defaultConfig . setClientSwitchingMode ( TabBoxConfig : : FocusChainSwitching ) ;
m_defaultConfig . setLayout ( TabBoxConfig : : VerticalLayout ) ;
2009-09-13 11:36:45 +00:00
m_alternativeConfig = TabBoxConfig ( ) ;
2011-01-30 14:34:42 +00:00
m_alternativeConfig . setTabBoxMode ( TabBoxConfig : : ClientTabBox ) ;
m_alternativeConfig . setClientListMode ( TabBoxConfig : : AllDesktopsClientList ) ;
m_alternativeConfig . setClientSwitchingMode ( TabBoxConfig : : FocusChainSwitching ) ;
m_alternativeConfig . setLayout ( TabBoxConfig : : VerticalLayout ) ;
2009-09-13 11:36:45 +00:00
m_desktopConfig = TabBoxConfig ( ) ;
2011-01-30 14:34:42 +00:00
m_desktopConfig . setTabBoxMode ( TabBoxConfig : : DesktopTabBox ) ;
m_desktopConfig . setShowTabBox ( true ) ;
m_desktopConfig . setShowDesktop ( false ) ;
m_desktopConfig . setDesktopSwitchingMode ( TabBoxConfig : : MostRecentlyUsedDesktopSwitching ) ;
m_desktopConfig . setLayout ( TabBoxConfig : : VerticalLayout ) ;
2009-09-13 11:36:45 +00:00
m_desktopListConfig = TabBoxConfig ( ) ;
2011-01-30 14:34:42 +00:00
m_desktopListConfig . setTabBoxMode ( TabBoxConfig : : DesktopTabBox ) ;
m_desktopListConfig . setShowTabBox ( true ) ;
m_desktopListConfig . setShowDesktop ( false ) ;
m_desktopListConfig . setDesktopSwitchingMode ( TabBoxConfig : : StaticDesktopSwitching ) ;
m_desktopListConfig . setLayout ( TabBoxConfig : : VerticalLayout ) ;
2011-06-25 16:05:07 +00:00
m_tabBox = new TabBoxHandlerImpl ( this ) ;
2011-07-09 08:32:26 +00:00
connect ( m_tabBox , SIGNAL ( ready ( ) ) , SLOT ( handlerReady ( ) ) ) ;
2009-09-13 11:36:45 +00:00
m_tabBoxMode = TabBoxDesktopMode ; // init variables
2011-06-25 16:05:07 +00:00
connect ( & m_delayedShowTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( show ( ) ) ) ;
2011-07-13 10:10:52 +00:00
connect ( Workspace : : self ( ) , SIGNAL ( configChanged ( ) ) , this , SLOT ( reconfigure ( ) ) ) ;
2011-08-21 08:44:09 +00:00
QDBusConnection : : sessionBus ( ) . registerObject ( " /TabBox " , this , QDBusConnection : : ExportScriptableContents ) ;
2011-01-30 14:34:42 +00:00
}
2009-03-03 11:45:39 +00:00
2009-09-13 11:36:45 +00:00
TabBox : : ~ TabBox ( )
2011-01-30 14:34:42 +00:00
{
2011-08-21 08:44:09 +00:00
QDBusConnection : : sessionBus ( ) . unregisterObject ( " /TabBox " ) ;
2011-01-30 14:34:42 +00:00
}
2009-03-03 11:45:39 +00:00
2011-07-09 08:32:26 +00:00
void TabBox : : handlerReady ( )
{
m_tabBox - > setConfig ( m_defaultConfig ) ;
reconfigure ( ) ;
m_ready = true ;
}
2011-06-25 16:05:07 +00:00
void TabBox : : initShortcuts ( KActionCollection * keys )
{
KAction * a = NULL ;
2011-09-10 10:39:10 +00:00
// The setGlobalShortcut(shortcut); shortcut = a->globalShortcut()
// sequence is necessary in the case where the user has defined a
// custom key binding which KAction::setGlobalShortcut autoloads.
2011-06-25 16:05:07 +00:00
# define KEY( name, key, fnSlot, shortcut, shortcutSlot ) \
a = keys - > addAction ( name ) ; \
a - > setText ( i18n ( name ) ) ; \
shortcut = KShortcut ( key ) ; \
qobject_cast < KAction * > ( a ) - > setGlobalShortcut ( shortcut ) ; \
2011-09-10 10:39:10 +00:00
shortcut = a - > globalShortcut ( ) ; \
2011-06-25 16:05:07 +00:00
connect ( a , SIGNAL ( triggered ( bool ) ) , SLOT ( fnSlot ) ) ; \
connect ( a , SIGNAL ( globalShortcutChanged ( QKeySequence ) ) , SLOT ( shortcutSlot ) ) ;
KEY ( I18N_NOOP ( " Walk Through Windows " ) , Qt : : ALT + Qt : : Key_Tab , slotWalkThroughWindows ( ) , m_cutWalkThroughWindows , slotWalkThroughWindowsKeyChanged ( QKeySequence ) )
KEY ( I18N_NOOP ( " Walk Through Windows (Reverse) " ) , Qt : : ALT + Qt : : SHIFT + Qt : : Key_Backtab , slotWalkBackThroughWindows ( ) , m_cutWalkThroughWindowsReverse , slotWalkBackThroughWindowsKeyChanged ( QKeySequence ) )
KEY ( I18N_NOOP ( " Walk Through Windows Alternative " ) , 0 , slotWalkThroughWindowsAlternative ( ) , m_cutWalkThroughWindowsAlternative , slotWalkThroughWindowsAlternativeKeyChanged ( QKeySequence ) )
KEY ( I18N_NOOP ( " Walk Through Windows Alternative (Reverse) " ) , 0 , slotWalkBackThroughWindowsAlternative ( ) , m_cutWalkThroughWindowsAlternativeReverse , slotWalkBackThroughWindowsAlternativeKeyChanged ( QKeySequence ) )
2011-09-10 10:39:10 +00:00
KEY ( I18N_NOOP ( " Walk Through Desktops " ) , 0 , slotWalkThroughDesktops ( ) , m_cutWalkThroughDesktops , slotWalkThroughDesktopsKeyChanged ( QKeySequence ) )
2011-06-25 16:05:07 +00:00
KEY ( I18N_NOOP ( " Walk Through Desktops (Reverse) " ) , 0 , slotWalkBackThroughDesktops ( ) , m_cutWalkThroughDesktopsReverse , slotWalkBackThroughDesktopsKeyChanged ( QKeySequence ) )
KEY ( I18N_NOOP ( " Walk Through Desktop List " ) , 0 , slotWalkThroughDesktopList ( ) , m_cutWalkThroughDesktopList , slotWalkThroughDesktopListKeyChanged ( QKeySequence ) )
KEY ( I18N_NOOP ( " Walk Through Desktop List (Reverse) " ) , 0 , slotWalkBackThroughDesktopList ( ) , m_cutWalkThroughDesktopListReverse , slotWalkBackThroughDesktopListKeyChanged ( QKeySequence ) )
# undef KEY
}
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
/*!
Sets the current mode to \ a mode , either TabBoxDesktopListMode or TabBoxWindowsMode
2007-04-29 17:35:43 +00:00
2009-09-13 11:36:45 +00:00
\ sa mode ( )
*/
2011-01-30 14:34:42 +00:00
void TabBox : : setMode ( TabBoxMode mode )
{
2009-09-13 11:36:45 +00:00
m_tabBoxMode = mode ;
2011-01-30 14:34:42 +00:00
switch ( mode ) {
case TabBoxWindowsMode :
m_tabBox - > setConfig ( m_defaultConfig ) ;
break ;
case TabBoxWindowsAlternativeMode :
m_tabBox - > setConfig ( m_alternativeConfig ) ;
break ;
case TabBoxDesktopMode :
m_tabBox - > setConfig ( m_desktopConfig ) ;
break ;
case TabBoxDesktopListMode :
m_tabBox - > setConfig ( m_desktopListConfig ) ;
break ;
2009-09-13 11:36:45 +00:00
}
2011-01-30 14:34:42 +00:00
}
2009-06-19 21:22:45 +00:00
2009-09-13 11:36:45 +00:00
/*!
Resets the tab box to display the active client in TabBoxWindowsMode , or the
current desktop in TabBoxDesktopListMode
*/
2011-01-30 14:34:42 +00:00
void TabBox : : reset ( bool partial_reset )
{
switch ( m_tabBox - > config ( ) . tabBoxMode ( ) ) {
case TabBoxConfig : : ClientTabBox :
m_tabBox - > createModel ( partial_reset ) ;
if ( ! partial_reset ) {
2011-06-25 16:05:07 +00:00
if ( Workspace : : self ( ) - > activeClient ( ) )
setCurrentClient ( Workspace : : self ( ) - > activeClient ( ) ) ;
2011-01-30 14:34:42 +00:00
// it's possible that the active client is not part of the model
// in that case the index is invalid
2011-10-31 13:34:37 +00:00
if ( ! m_tabBox - > currentIndex ( ) . isValid ( ) )
2011-01-30 14:34:42 +00:00
setCurrentIndex ( m_tabBox - > first ( ) ) ;
} else {
2011-10-31 13:34:37 +00:00
if ( ! m_tabBox - > currentIndex ( ) . isValid ( ) | | ! m_tabBox - > client ( m_tabBox - > currentIndex ( ) ) )
2011-01-30 14:34:42 +00:00
setCurrentIndex ( m_tabBox - > first ( ) ) ;
2009-03-03 11:45:39 +00:00
}
2011-01-30 14:34:42 +00:00
break ;
case TabBoxConfig : : DesktopTabBox :
m_tabBox - > createModel ( ) ;
2009-03-03 11:45:39 +00:00
2011-01-30 14:34:42 +00:00
if ( ! partial_reset )
2011-06-25 16:05:07 +00:00
setCurrentDesktop ( Workspace : : self ( ) - > currentDesktop ( ) ) ;
2011-01-30 14:34:42 +00:00
break ;
2009-03-03 11:45:39 +00:00
}
2011-03-06 11:15:16 +00:00
emit tabBoxUpdated ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Shows the next or previous item , depending on \ a next
*/
2011-01-30 14:34:42 +00:00
void TabBox : : nextPrev ( bool next )
{
setCurrentIndex ( m_tabBox - > nextPrev ( next ) , false ) ;
2011-03-06 11:15:16 +00:00
emit tabBoxUpdated ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Returns the currently displayed client ( only works in TabBoxWindowsMode ) .
Returns 0 if no client is displayed .
*/
Client * TabBox : : currentClient ( )
2011-01-30 14:34:42 +00:00
{
2011-10-31 13:34:37 +00:00
if ( TabBoxClientImpl * client = static_cast < TabBoxClientImpl * > ( m_tabBox - > client ( m_tabBox - > currentIndex ( ) ) ) ) {
2011-06-25 16:05:07 +00:00
if ( ! Workspace : : self ( ) - > hasClient ( client - > client ( ) ) )
2009-09-13 11:36:45 +00:00
return NULL ;
return client - > client ( ) ;
2011-01-30 14:34:42 +00:00
} else
2009-09-13 11:36:45 +00:00
return NULL ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Returns the list of clients potentially displayed ( only works in
TabBoxWindowsMode ) .
Returns an empty list if no clients are available .
*/
ClientList TabBox : : currentClientList ( )
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
TabBoxClientList list = m_tabBox - > clientList ( ) ;
ClientList ret ;
2011-01-30 14:34:42 +00:00
foreach ( const TabBoxClient * client , list ) {
if ( const TabBoxClientImpl * c = static_cast < const TabBoxClientImpl * > ( client ) )
ret . append ( c - > client ( ) ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
return ret ;
}
2007-04-29 17:35:43 +00:00
/*!
Returns the currently displayed virtual desktop ( only works in
TabBoxDesktopListMode )
Returns - 1 if no desktop is displayed .
*/
int TabBox : : currentDesktop ( )
2011-01-30 14:34:42 +00:00
{
2011-10-31 13:34:37 +00:00
return m_tabBox - > desktop ( m_tabBox - > currentIndex ( ) ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Returns the list of desktops potentially displayed ( only works in
TabBoxDesktopListMode )
2009-09-13 11:36:45 +00:00
Returns an empty list if no are available .
2007-04-29 17:35:43 +00:00
*/
QList < int > TabBox : : currentDesktopList ( )
2011-01-30 14:34:42 +00:00
{
2009-09-13 11:36:45 +00:00
return m_tabBox - > desktopList ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Change the currently selected client , and notify the effects .
\ sa setCurrentDesktop ( )
*/
2011-01-30 14:34:42 +00:00
void TabBox : : setCurrentClient ( Client * newClient )
{
setCurrentIndex ( m_tabBox - > index ( newClient - > tabBoxClient ( ) ) ) ;
}
2007-04-29 17:35:43 +00:00
/*!
Change the currently selected desktop , and notify the effects .
\ sa setCurrentClient ( )
*/
2011-01-30 14:34:42 +00:00
void TabBox : : setCurrentDesktop ( int newDesktop )
{
setCurrentIndex ( m_tabBox - > desktopIndex ( newDesktop ) ) ;
}
2007-04-29 17:35:43 +00:00
2011-09-10 10:39:10 +00:00
void TabBox : : setCurrentIndex ( QModelIndex index , bool notifyEffects )
2011-01-30 14:34:42 +00:00
{
if ( ! index . isValid ( ) )
2009-09-13 11:36:45 +00:00
return ;
2011-01-30 14:34:42 +00:00
m_tabBox - > setCurrentIndex ( index ) ;
2011-03-06 11:15:16 +00:00
if ( notifyEffects ) {
emit tabBoxUpdated ( ) ;
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Notify effects that the tab box is being shown , and only display the
default tab box QFrame if no effect has referenced the tab box .
*/
void TabBox : : show ( )
2011-01-30 14:34:42 +00:00
{
2011-03-06 11:15:16 +00:00
emit tabBoxAdded ( m_tabBoxMode ) ;
2011-01-30 14:34:42 +00:00
if ( isDisplayed ( ) ) {
2009-09-13 11:36:45 +00:00
m_isShown = false ;
2009-03-21 19:16:44 +00:00
return ;
2011-01-30 14:34:42 +00:00
}
2011-06-25 16:05:07 +00:00
reference ( ) ;
2009-09-13 11:36:45 +00:00
m_isShown = true ;
m_tabBox - > show ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Notify effects that the tab box is being hidden .
*/
2010-10-17 20:30:33 +00:00
void TabBox : : hide ( bool abort )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_delayedShowTimer . stop ( ) ;
2011-01-30 14:34:42 +00:00
if ( m_isShown ) {
2009-09-13 11:36:45 +00:00
m_isShown = false ;
2011-06-25 16:05:07 +00:00
unreference ( ) ;
2011-01-30 14:34:42 +00:00
}
2011-03-06 11:15:16 +00:00
emit tabBoxClosed ( ) ;
2011-01-30 14:34:42 +00:00
if ( isDisplayed ( ) )
kDebug ( 1212 ) < < " Tab box was not properly closed by an effect " ;
m_tabBox - > hide ( abort ) ;
2007-04-29 17:35:43 +00:00
QApplication : : syncX ( ) ;
XEvent otherEvent ;
2011-01-30 14:34:42 +00:00
while ( XCheckTypedEvent ( display ( ) , EnterNotify , & otherEvent ) )
2007-04-29 17:35:43 +00:00
;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
void TabBox : : reconfigure ( )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
KSharedConfigPtr c ( KGlobal : : config ( ) ) ;
2011-01-30 14:34:42 +00:00
KConfigGroup config = c - > group ( " TabBox " ) ;
2009-09-13 11:36:45 +00:00
2011-01-30 14:34:42 +00:00
loadConfig ( c - > group ( " TabBox " ) , m_defaultConfig ) ;
loadConfig ( c - > group ( " TabBoxAlternative " ) , m_alternativeConfig ) ;
2009-09-13 11:36:45 +00:00
2011-01-30 14:34:42 +00:00
m_tabBox - > setConfig ( m_defaultConfig ) ;
2009-09-13 11:36:45 +00:00
2011-01-30 14:34:42 +00:00
m_delayShow = config . readEntry < bool > ( " ShowDelay " , true ) ;
m_delayShowTime = config . readEntry < int > ( " DelayTime " , 90 ) ;
}
2009-09-13 11:36:45 +00:00
2011-01-30 14:34:42 +00:00
void TabBox : : loadConfig ( const KConfigGroup & config , TabBoxConfig & tabBoxConfig )
{
tabBoxConfig . setClientListMode ( TabBoxConfig : : ClientListMode (
config . readEntry < int > ( " ListMode " , TabBoxConfig : : defaultListMode ( ) ) ) ) ;
tabBoxConfig . setClientSwitchingMode ( TabBoxConfig : : ClientSwitchingMode (
config . readEntry < int > ( " SwitchingMode " , TabBoxConfig : : defaultSwitchingMode ( ) ) ) ) ;
tabBoxConfig . setShowOutline ( config . readEntry < bool > ( " ShowOutline " ,
TabBoxConfig : : defaultShowOutline ( ) ) ) ;
tabBoxConfig . setShowTabBox ( config . readEntry < bool > ( " ShowTabBox " ,
TabBoxConfig : : defaultShowTabBox ( ) ) ) ;
tabBoxConfig . setHighlightWindows ( config . readEntry < bool > ( " HighlightWindows " ,
TabBoxConfig : : defaultHighlightWindow ( ) ) ) ;
tabBoxConfig . setShowDesktop ( config . readEntry < bool > ( " ShowDesktop " ,
TabBoxConfig : : defaultShowDesktop ( ) ) ) ;
tabBoxConfig . setLayoutName ( config . readEntry < QString > ( " LayoutName " , TabBoxConfig : : defaultLayoutName ( ) ) ) ;
}
2007-04-29 17:35:43 +00:00
/*!
Rikkus : please document ! ( Matthias )
Ok , here ' s the docs : )
You call delayedShow ( ) instead of show ( ) directly .
If the ' ShowDelay ' setting is false , show ( ) is simply called .
Otherwise , we start a timer for the delay given in the settings and only
do a show ( ) when it times out .
This means that you can alt - tab between windows and you don ' t see the
tab box immediately . Not only does this make alt - tabbing faster , it gives
less ' flicker ' to the eyes . You don ' t need to see the tab box if you ' re
just quickly switching between 2 or 3 windows . It seems to work quite
nicely .
*/
void TabBox : : delayedShow ( )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
if ( isDisplayed ( ) | | m_delayedShowTimer . isActive ( ) )
2009-09-13 11:36:45 +00:00
// already called show - no need to call it twice
return ;
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
if ( ! m_delayShowTime ) {
2007-04-29 17:35:43 +00:00
show ( ) ;
return ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
m_delayedShowTimer . setSingleShot ( true ) ;
m_delayedShowTimer . start ( m_delayShowTime ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-10-31 13:34:37 +00:00
bool TabBox : : handleMouseEvent ( XEvent * e )
2011-01-30 14:34:42 +00:00
{
XAllowEvents ( display ( ) , AsyncPointer , xTime ( ) ) ;
if ( ! m_isShown & & isDisplayed ( ) ) {
// tabbox has been replaced, check effects
if ( effects & & static_cast < EffectsHandlerImpl * > ( effects ) - > checkInputWindowEvent ( e ) )
2011-10-31 13:34:37 +00:00
return true ;
2011-01-30 14:34:42 +00:00
}
2011-10-31 13:34:37 +00:00
if ( e - > type = = ButtonPress ) {
// press outside Tabbox?
QPoint pos ( e - > xbutton . x_root , e - > xbutton . y_root ) ;
if ( ( ! m_isShown & & isDisplayed ( ) )
| | ( ! m_tabBox - > containsPos ( pos ) & &
( e - > xbutton . button = = Button1 | | e - > xbutton . button = = Button2 | | e - > xbutton . button = = Button3 ) ) ) {
close ( ) ; // click outside closes tab
return true ;
}
}
if ( m_tabBoxMode = = TabBoxWindowsMode | | m_tabBoxMode = = TabBoxWindowsAlternativeMode ) {
// pass to declarative view
return false ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-10-31 13:34:37 +00:00
// not declarative view
if ( e - > type ! = ButtonPress ) {
return true ;
}
QPoint pos ( e - > xbutton . x_root , e - > xbutton . y_root ) ;
2009-09-13 11:36:45 +00:00
QModelIndex index ;
2011-01-30 14:34:42 +00:00
if ( e - > xbutton . button = = Button1 | | e - > xbutton . button = = Button2 | | e - > xbutton . button = = Button3 ) {
index = m_tabBox - > indexAt ( pos ) ;
if ( e - > xbutton . button = = Button2 & & index . isValid ( ) ) {
if ( TabBoxClientImpl * client = static_cast < TabBoxClientImpl * > ( m_tabBox - > client ( index ) ) ) {
2011-06-25 16:05:07 +00:00
if ( Workspace : : self ( ) - > hasClient ( client - > client ( ) ) ) {
2009-09-13 11:36:45 +00:00
client - > client ( ) - > closeWindow ( ) ;
2011-10-31 13:34:37 +00:00
return true ;
2007-04-29 17:35:43 +00:00
}
2009-03-03 11:45:39 +00:00
}
}
2011-01-30 14:34:42 +00:00
} else {
2009-09-13 11:36:45 +00:00
// mouse wheel event
2011-01-30 14:34:42 +00:00
index = m_tabBox - > nextPrev ( e - > xbutton . button = = Button5 ) ;
2009-03-03 11:45:39 +00:00
}
2011-01-30 14:34:42 +00:00
if ( index . isValid ( ) )
setCurrentIndex ( index ) ;
2011-10-31 13:34:37 +00:00
return true ;
2011-01-30 14:34:42 +00:00
}
2011-06-25 16:05:07 +00:00
void TabBox : : grabbedKeyEvent ( QKeyEvent * event )
2011-01-30 14:34:42 +00:00
{
2011-03-06 11:15:16 +00:00
emit tabBoxKeyEvent ( event ) ;
2011-01-30 14:34:42 +00:00
if ( ! m_isShown & & isDisplayed ( ) ) {
// tabbox has been replaced, check effects
2009-09-13 11:36:45 +00:00
return ;
2009-03-03 11:45:39 +00:00
}
2011-08-21 08:44:09 +00:00
if ( m_noModifierGrab ) {
if ( event - > key ( ) = = Qt : : Key_Enter | | event - > key ( ) = = Qt : : Key_Return | | event - > key ( ) = = Qt : : Key_Space ) {
Client * c = currentClient ( ) ;
close ( ) ;
if ( c ) {
Workspace : : self ( ) - > activateClient ( c ) ;
if ( c - > isShade ( ) & & options - > shadeHover )
c - > setShade ( ShadeActivated ) ;
if ( c - > isDesktop ( ) )
Workspace : : self ( ) - > setShowingDesktop ( ! Workspace : : self ( ) - > showingDesktop ( ) ) ;
}
}
}
2011-01-30 14:34:42 +00:00
setCurrentIndex ( m_tabBox - > grabbedKeyEvent ( event ) ) ;
}
2009-03-03 11:45:39 +00:00
2007-04-29 17:35:43 +00:00
/*!
Handles alt - tab / control - tab
*/
2011-06-25 16:05:07 +00:00
static bool areKeySymXsDepressed ( bool bAll , const uint keySyms [ ] , int nKeySyms ) {
2007-04-29 17:35:43 +00:00
char keymap [ 32 ] ;
2007-08-03 06:59:24 +00:00
kDebug ( 125 ) < < " areKeySymXsDepressed: " < < ( bAll ? " all of " : " any of " ) < < nKeySyms ;
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
XQueryKeymap ( display ( ) , keymap ) ;
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
for ( int iKeySym = 0 ; iKeySym < nKeySyms ; iKeySym + + ) {
2007-04-29 17:35:43 +00:00
uint keySymX = keySyms [ iKeySym ] ;
2011-01-30 14:34:42 +00:00
uchar keyCodeX = XKeysymToKeycode ( display ( ) , keySymX ) ;
2007-04-29 17:35:43 +00:00
int i = keyCodeX / 8 ;
char mask = 1 < < ( keyCodeX - ( i * 8 ) ) ;
2011-01-30 14:34:42 +00:00
// Abort if bad index value,
if ( i < 0 | | i > = 32 )
return false ;
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
kDebug ( 125 ) < < iKeySym < < " : keySymX=0x " < < QString : : number ( keySymX , 16 )
< < " i= " < < i < < " mask=0x " < < QString : : number ( mask , 16 )
< < " keymap[i]=0x " < < QString : : number ( keymap [ i ] , 16 ) < < endl ;
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
// If ALL keys passed need to be depressed,
if ( bAll ) {
if ( ( keymap [ i ] & mask ) = = 0 )
return false ;
} else {
// If we are looking for ANY key press, and this key is depressed,
if ( keymap [ i ] & mask )
return true ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
// If we were looking for ANY key press, then none was found, return false,
// If we were looking for ALL key presses, then all were found, return true.
2007-04-29 17:35:43 +00:00
return bAll ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
static bool areModKeysDepressed ( const QKeySequence & seq ) {
2007-04-29 17:35:43 +00:00
uint rgKeySyms [ 10 ] ;
int nKeySyms = 0 ;
2011-01-30 14:34:42 +00:00
if ( seq . isEmpty ( ) )
2007-04-29 17:35:43 +00:00
return false ;
int mod = seq [ seq . count ( ) - 1 ] & Qt : : KeyboardModifierMask ;
2011-01-30 14:34:42 +00:00
if ( mod & Qt : : SHIFT ) {
2007-04-29 17:35:43 +00:00
rgKeySyms [ nKeySyms + + ] = XK_Shift_L ;
rgKeySyms [ nKeySyms + + ] = XK_Shift_R ;
2011-01-30 14:34:42 +00:00
}
if ( mod & Qt : : CTRL ) {
2007-04-29 17:35:43 +00:00
rgKeySyms [ nKeySyms + + ] = XK_Control_L ;
rgKeySyms [ nKeySyms + + ] = XK_Control_R ;
2011-01-30 14:34:42 +00:00
}
if ( mod & Qt : : ALT ) {
2007-04-30 11:36:55 +00:00
rgKeySyms [ nKeySyms + + ] = XK_Alt_L ;
rgKeySyms [ nKeySyms + + ] = XK_Alt_R ;
2011-01-30 14:34:42 +00:00
}
if ( mod & Qt : : META ) {
2007-04-30 11:36:55 +00:00
// It would take some code to determine whether the Win key
// is associated with Super or Meta, so check for both.
// See bug #140023 for details.
rgKeySyms [ nKeySyms + + ] = XK_Super_L ;
rgKeySyms [ nKeySyms + + ] = XK_Super_R ;
rgKeySyms [ nKeySyms + + ] = XK_Meta_L ;
rgKeySyms [ nKeySyms + + ] = XK_Meta_R ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
return areKeySymXsDepressed ( false , rgKeySyms , nKeySyms ) ;
}
static bool areModKeysDepressed ( const KShortcut & cut )
{
if ( areModKeysDepressed ( cut . primary ( ) ) | | areModKeysDepressed ( cut . alternate ( ) ) )
2007-04-29 17:35:43 +00:00
return true ;
return false ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : navigatingThroughWindows ( bool forward , const KShortcut & shortcut , TabBoxMode mode )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
if ( isGrabbed ( ) )
2007-04-29 17:35:43 +00:00
return ;
2011-01-30 14:34:42 +00:00
if ( ! options - > focusPolicyIsReasonable ( ) ) {
2007-04-29 17:35:43 +00:00
//ungrabXKeyboard(); // need that because of accelerator raw mode
// CDE style raise / lower
2011-01-30 14:34:42 +00:00
CDEWalkThroughWindows ( forward ) ;
} else {
if ( areModKeysDepressed ( shortcut ) ) {
if ( startKDEWalkThroughWindows ( mode ) )
KDEWalkThroughWindows ( forward ) ;
} else
2007-04-29 17:35:43 +00:00
// if the shortcut has no modifiers, don't show the tabbox,
// don't grab, but simply go to the next window
2011-01-30 14:34:42 +00:00
KDEOneStepThroughWindows ( forward , mode ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughWindows ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
navigatingThroughWindows ( true , m_cutWalkThroughWindows , TabBoxWindowsMode ) ;
2011-01-30 14:34:42 +00:00
}
2009-09-13 11:36:45 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughWindows ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
navigatingThroughWindows ( false , m_cutWalkThroughWindowsReverse , TabBoxWindowsMode ) ;
2011-01-30 14:34:42 +00:00
}
2009-09-13 11:36:45 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughWindowsAlternative ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
navigatingThroughWindows ( true , m_cutWalkThroughWindowsAlternative , TabBoxWindowsAlternativeMode ) ;
2011-01-30 14:34:42 +00:00
}
2009-09-13 11:36:45 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughWindowsAlternative ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
navigatingThroughWindows ( false , m_cutWalkThroughWindowsAlternativeReverse , TabBoxWindowsAlternativeMode ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughDesktops ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
if ( isGrabbed ( ) )
2007-04-29 17:35:43 +00:00
return ;
2011-06-25 16:05:07 +00:00
if ( areModKeysDepressed ( m_cutWalkThroughDesktops ) ) {
2011-01-30 14:34:42 +00:00
if ( startWalkThroughDesktops ( ) )
walkThroughDesktops ( true ) ;
} else {
oneStepThroughDesktops ( true ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughDesktops ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
if ( isGrabbed ( ) )
2007-04-29 17:35:43 +00:00
return ;
2011-06-25 16:05:07 +00:00
if ( areModKeysDepressed ( m_cutWalkThroughDesktopsReverse ) ) {
2011-01-30 14:34:42 +00:00
if ( startWalkThroughDesktops ( ) )
walkThroughDesktops ( false ) ;
} else {
oneStepThroughDesktops ( false ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughDesktopList ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
if ( isGrabbed ( ) )
2007-04-29 17:35:43 +00:00
return ;
2011-06-25 16:05:07 +00:00
if ( areModKeysDepressed ( m_cutWalkThroughDesktopList ) ) {
2011-01-30 14:34:42 +00:00
if ( startWalkThroughDesktopList ( ) )
walkThroughDesktops ( true ) ;
} else {
oneStepThroughDesktopList ( true ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughDesktopList ( )
2011-01-30 14:34:42 +00:00
{
2011-07-09 08:32:26 +00:00
if ( ! m_ready ) {
return ;
}
2011-06-25 16:05:07 +00:00
if ( isGrabbed ( ) )
2007-04-29 17:35:43 +00:00
return ;
2011-06-25 16:05:07 +00:00
if ( areModKeysDepressed ( m_cutWalkThroughDesktopListReverse ) ) {
2011-01-30 14:34:42 +00:00
if ( startWalkThroughDesktopList ( ) )
walkThroughDesktops ( false ) ;
} else {
oneStepThroughDesktopList ( false ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughDesktopsKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughDesktops = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-05-25 08:35:48 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughDesktopsKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughDesktopsReverse = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-05-25 08:35:48 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughDesktopListKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughDesktopList = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-05-25 08:35:48 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughDesktopListKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughDesktopListReverse = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-05-25 08:35:48 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughWindowsKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughWindows = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-05-25 08:35:48 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughWindowsKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughWindowsReverse = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-05-25 08:35:48 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotMoveToTabLeftKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughGroupWindows = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2011-06-25 16:05:07 +00:00
void TabBox : : slotMoveToTabRightKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughGroupWindowsReverse = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-11-15 03:24:04 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkThroughWindowsAlternativeKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughWindowsAlternative = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-09-13 11:36:45 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : slotWalkBackThroughWindowsAlternativeKeyChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
m_cutWalkThroughWindowsAlternativeReverse = KShortcut ( seq ) ;
2011-01-30 14:34:42 +00:00
}
2009-09-13 11:36:45 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : modalActionsSwitch ( bool enabled )
2011-01-30 14:34:42 +00:00
{
2007-04-30 00:52:51 +00:00
QList < KActionCollection * > collections ;
2011-06-25 16:05:07 +00:00
collections . append ( Workspace : : self ( ) - > actionCollection ( ) ) ;
collections . append ( Workspace : : self ( ) - > disableShortcutsKeys ( ) ) ;
collections . append ( Workspace : : self ( ) - > clientKeys ( ) ) ;
2011-01-30 14:34:42 +00:00
foreach ( KActionCollection * collection , collections )
foreach ( QAction * action , collection - > actions ( ) )
action - > setEnabled ( enabled ) ;
}
2007-04-30 00:52:51 +00:00
2011-11-29 06:05:41 +00:00
void TabBox : : open ( bool modal )
2011-08-21 08:44:09 +00:00
{
if ( isDisplayed ( ) ) {
return ;
}
2011-08-21 09:14:34 +00:00
if ( modal ) {
if ( ! establishTabBoxGrab ( ) ) {
return ;
}
m_tabGrab = true ;
} else {
m_tabGrab = false ;
2011-08-21 08:44:09 +00:00
}
m_noModifierGrab = true ;
setMode ( TabBoxWindowsMode ) ;
reset ( ) ;
show ( ) ;
}
2011-06-25 16:05:07 +00:00
bool TabBox : : startKDEWalkThroughWindows ( TabBoxMode mode )
2011-01-30 14:34:42 +00:00
{
if ( ! establishTabBoxGrab ( ) )
2007-04-29 17:35:43 +00:00
return false ;
2011-06-25 16:05:07 +00:00
m_tabGrab = true ;
2011-08-21 08:44:09 +00:00
m_noModifierGrab = false ;
2011-01-30 14:34:42 +00:00
modalActionsSwitch ( false ) ;
2011-06-25 16:05:07 +00:00
setMode ( mode ) ;
reset ( ) ;
2007-04-29 17:35:43 +00:00
return true ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
bool TabBox : : startWalkThroughDesktops ( TabBoxMode mode )
2011-01-30 14:34:42 +00:00
{
if ( ! establishTabBoxGrab ( ) )
2007-04-29 17:35:43 +00:00
return false ;
2011-06-25 16:05:07 +00:00
m_desktopGrab = true ;
2011-08-21 08:44:09 +00:00
m_noModifierGrab = false ;
2011-01-30 14:34:42 +00:00
modalActionsSwitch ( false ) ;
2011-06-25 16:05:07 +00:00
setMode ( mode ) ;
reset ( ) ;
2007-04-29 17:35:43 +00:00
return true ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
bool TabBox : : startWalkThroughDesktops ( )
2011-01-30 14:34:42 +00:00
{
return startWalkThroughDesktops ( TabBoxDesktopMode ) ;
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
bool TabBox : : startWalkThroughDesktopList ( )
2011-01-30 14:34:42 +00:00
{
return startWalkThroughDesktops ( TabBoxDesktopListMode ) ;
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : KDEWalkThroughWindows ( bool forward )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
nextPrev ( forward ) ;
delayedShow ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : walkThroughDesktops ( bool forward )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
nextPrev ( forward ) ;
delayedShow ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : CDEWalkThroughWindows ( bool forward )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
Client * c = NULL ;
// this function find the first suitable client for unreasonable focus
// policies - the topmost one, with some exceptions (can't be keepabove/below,
// otherwise it gets stuck on them)
2011-06-25 16:05:07 +00:00
// Q_ASSERT(Workspace::self()->block_stacking_updates == 0);
for ( int i = Workspace : : self ( ) - > stackingOrder ( ) . size ( ) - 1 ;
2011-01-30 14:34:42 +00:00
i > = 0 ;
- - i ) {
2011-06-25 16:05:07 +00:00
Client * it = Workspace : : self ( ) - > stackingOrder ( ) . at ( i ) ;
2011-01-30 14:34:42 +00:00
if ( it - > isOnCurrentActivity ( ) & & it - > isOnCurrentDesktop ( ) & & ! it - > isSpecialWindow ( )
& & it - > isShown ( false ) & & it - > wantsTabFocus ( )
& & ! it - > keepAbove ( ) & & ! it - > keepBelow ( ) ) {
2007-04-29 17:35:43 +00:00
c = it ;
break ;
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
Client * nc = c ;
bool options_traverse_all ;
2011-01-30 14:34:42 +00:00
{
KConfigGroup group ( KGlobal : : config ( ) , " TabBox " ) ;
options_traverse_all = group . readEntry ( " TraverseAll " , false ) ;
}
2007-04-29 17:35:43 +00:00
Client * firstClient = 0 ;
2011-01-30 14:34:42 +00:00
do {
2007-04-29 17:35:43 +00:00
nc = forward ? nextClientStatic ( nc ) : previousClientStatic ( nc ) ;
2011-01-30 14:34:42 +00:00
if ( ! firstClient ) {
2007-04-29 17:35:43 +00:00
// When we see our first client for the second time,
// it's time to stop.
firstClient = nc ;
2011-01-30 14:34:42 +00:00
} else if ( nc = = firstClient ) {
2007-04-29 17:35:43 +00:00
// No candidates found.
nc = 0 ;
break ;
2011-01-30 14:34:42 +00:00
}
} while ( nc & & nc ! = c & &
( ( ! options_traverse_all & & ! nc - > isOnDesktop ( currentDesktop ( ) ) ) | |
nc - > isMinimized ( ) | | ! nc - > wantsTabFocus ( ) | | nc - > keepAbove ( ) | | nc - > keepBelow ( ) | | ! nc - > isOnCurrentActivity ( ) ) ) ;
if ( nc ) {
2007-04-29 17:35:43 +00:00
if ( c & & c ! = nc )
2011-06-25 16:05:07 +00:00
Workspace : : self ( ) - > lowerClient ( c ) ;
2011-01-30 14:34:42 +00:00
if ( options - > focusPolicyIsReasonable ( ) ) {
2011-06-25 16:05:07 +00:00
Workspace : : self ( ) - > activateClient ( nc ) ;
2011-01-30 14:34:42 +00:00
if ( nc - > isShade ( ) & & options - > shadeHover )
nc - > setShade ( ShadeActivated ) ;
} else {
if ( ! nc - > isOnDesktop ( currentDesktop ( ) ) )
setCurrentDesktop ( nc - > desktop ( ) ) ;
2011-06-25 16:05:07 +00:00
Workspace : : self ( ) - > raiseClient ( nc ) ;
2007-04-29 17:35:43 +00:00
}
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : KDEOneStepThroughWindows ( bool forward , TabBoxMode mode )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
setMode ( mode ) ;
reset ( ) ;
nextPrev ( forward ) ;
if ( Client * c = currentClient ( ) ) {
Workspace : : self ( ) - > activateClient ( c ) ;
2011-01-30 14:34:42 +00:00
if ( c - > isShade ( ) & & options - > shadeHover )
c - > setShade ( ShadeActivated ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : oneStepThroughDesktops ( bool forward , TabBoxMode mode )
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
setMode ( mode ) ;
reset ( ) ;
nextPrev ( forward ) ;
if ( currentDesktop ( ) ! = - 1 )
setCurrentDesktop ( currentDesktop ( ) ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : oneStepThroughDesktops ( bool forward )
2011-01-30 14:34:42 +00:00
{
oneStepThroughDesktops ( forward , TabBoxDesktopMode ) ;
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : oneStepThroughDesktopList ( bool forward )
2011-01-30 14:34:42 +00:00
{
oneStepThroughDesktops ( forward , TabBoxDesktopListMode ) ;
}
2007-04-29 17:35:43 +00:00
/*!
Handles holding alt - tab / control - tab
*/
2011-06-25 16:05:07 +00:00
void TabBox : : keyPress ( int keyQt )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
bool forward = false ;
bool backward = false ;
2011-06-25 16:05:07 +00:00
if ( m_tabGrab ) {
2009-09-13 11:36:45 +00:00
KShortcut forwardShortcut ;
KShortcut backwardShortcut ;
2011-06-25 16:05:07 +00:00
if ( mode ( ) = = TabBoxWindowsMode ) {
forwardShortcut = m_cutWalkThroughWindows ;
backwardShortcut = m_cutWalkThroughWindowsReverse ;
2011-01-30 14:34:42 +00:00
} else {
2011-06-25 16:05:07 +00:00
forwardShortcut = m_cutWalkThroughWindowsAlternative ;
backwardShortcut = m_cutWalkThroughWindowsAlternativeReverse ;
2011-01-30 14:34:42 +00:00
}
forward = forwardShortcut . contains ( keyQt ) ;
backward = backwardShortcut . contains ( keyQt ) ;
if ( forward | | backward ) {
2009-09-13 11:36:45 +00:00
kDebug ( 125 ) < < " == " < < forwardShortcut . toString ( )
2011-01-30 14:34:42 +00:00
< < " or " < < backwardShortcut . toString ( ) < < endl ;
KDEWalkThroughWindows ( forward ) ;
2007-04-29 17:35:43 +00:00
}
2011-06-25 16:05:07 +00:00
} else if ( m_desktopGrab ) {
forward = m_cutWalkThroughDesktops . contains ( keyQt ) | |
m_cutWalkThroughDesktopList . contains ( keyQt ) ;
backward = m_cutWalkThroughDesktopsReverse . contains ( keyQt ) | |
m_cutWalkThroughDesktopListReverse . contains ( keyQt ) ;
2007-04-29 17:35:43 +00:00
if ( forward | | backward )
walkThroughDesktops ( forward ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
if ( m_desktopGrab | | m_tabGrab ) {
2011-01-30 14:34:42 +00:00
if ( ( ( keyQt & ~ Qt : : KeyboardModifierMask ) = = Qt : : Key_Escape )
& & ! ( forward | | backward ) ) {
// if Escape is part of the shortcut, don't cancel
2011-06-25 16:05:07 +00:00
close ( true ) ;
2011-01-30 14:34:42 +00:00
} else if ( ! ( forward | | backward ) ) {
QKeyEvent * event = new QKeyEvent ( QEvent : : KeyPress , keyQt & ~ Qt : : KeyboardModifierMask , Qt : : NoModifier ) ;
2011-06-25 16:05:07 +00:00
grabbedKeyEvent ( event ) ;
2007-04-29 17:35:43 +00:00
}
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : close ( bool abort )
2011-01-30 14:34:42 +00:00
{
2011-08-21 09:14:34 +00:00
if ( isGrabbed ( ) ) {
removeTabBoxGrab ( ) ;
2011-08-21 08:44:09 +00:00
}
2011-06-25 16:05:07 +00:00
hide ( abort ) ;
2011-01-30 14:34:42 +00:00
modalActionsSwitch ( true ) ;
2011-06-25 16:05:07 +00:00
m_tabGrab = false ;
m_desktopGrab = false ;
2011-08-21 08:44:09 +00:00
m_noModifierGrab = false ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
Handles alt - tab / control - tab releasing
*/
2011-06-25 16:05:07 +00:00
void TabBox : : keyRelease ( const XKeyEvent & ev )
2011-01-30 14:34:42 +00:00
{
2011-08-21 08:44:09 +00:00
if ( m_noModifierGrab ) {
return ;
}
2007-04-29 17:35:43 +00:00
unsigned int mk = ev . state &
2011-01-30 14:34:42 +00:00
( KKeyServer : : modXShift ( ) |
KKeyServer : : modXCtrl ( ) |
KKeyServer : : modXAlt ( ) |
KKeyServer : : modXMeta ( ) ) ;
2007-04-29 17:35:43 +00:00
// ev.state is state before the key release, so just checking mk being 0 isn't enough
// using XQueryPointer() also doesn't seem to work well, so the check that all
// modifiers are released: only one modifier is active and the currently released
// key is this modifier - if yes, release the grab
int mod_index = - 1 ;
2011-01-30 14:34:42 +00:00
for ( int i = ShiftMapIndex ;
i < = Mod5MapIndex ;
+ + i )
if ( ( mk & ( 1 < < i ) ) ! = 0 ) {
if ( mod_index > = 0 )
return ;
mod_index = i ;
2007-04-29 17:35:43 +00:00
}
bool release = false ;
2011-01-30 14:34:42 +00:00
if ( mod_index = = - 1 )
2007-04-29 17:35:43 +00:00
release = true ;
2011-01-30 14:34:42 +00:00
else {
2007-04-29 17:35:43 +00:00
XModifierKeymap * xmk = XGetModifierMapping ( display ( ) ) ;
2011-01-30 14:34:42 +00:00
for ( int i = 0 ; i < xmk - > max_keypermod ; i + + )
2007-04-29 17:35:43 +00:00
if ( xmk - > modifiermap [ xmk - > max_keypermod * mod_index + i ]
2011-01-30 14:34:42 +00:00
= = ev . keycode )
2007-04-29 17:35:43 +00:00
release = true ;
XFreeModifiermap ( xmk ) ;
2011-01-30 14:34:42 +00:00
}
if ( ! release )
return ;
2011-06-25 16:05:07 +00:00
if ( m_tabGrab ) {
bool old_control_grab = m_desktopGrab ;
Client * c = currentClient ( ) ;
close ( ) ;
m_desktopGrab = old_control_grab ;
2011-01-30 14:34:42 +00:00
if ( c ) {
2011-06-25 16:05:07 +00:00
Workspace : : self ( ) - > activateClient ( c ) ;
2011-01-30 14:34:42 +00:00
if ( c - > isShade ( ) & & options - > shadeHover )
c - > setShade ( ShadeActivated ) ;
if ( c - > isDesktop ( ) )
2011-06-25 16:05:07 +00:00
Workspace : : self ( ) - > setShowingDesktop ( ! Workspace : : self ( ) - > showingDesktop ( ) ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2011-06-25 16:05:07 +00:00
if ( m_desktopGrab ) {
bool old_tab_grab = m_tabGrab ;
int desktop = currentDesktop ( ) ;
close ( ) ;
m_tabGrab = old_tab_grab ;
2011-01-30 14:34:42 +00:00
if ( desktop ! = - 1 ) {
setCurrentDesktop ( desktop ) ;
2011-09-10 10:39:10 +00:00
Workspace : : self ( ) - > setCurrentDesktop ( desktop ) ;
2007-04-29 17:35:43 +00:00
}
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
int TabBox : : nextDesktopFocusChain ( int iDesktop ) const
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
const QVector < int > & desktopFocusChain = Workspace : : self ( ) - > desktopFocusChain ( ) ;
int i = desktopFocusChain . indexOf ( iDesktop ) ;
if ( i > = 0 & & i + 1 < desktopFocusChain . size ( ) )
return desktopFocusChain [ i + 1 ] ;
else if ( desktopFocusChain . size ( ) > 0 )
return desktopFocusChain [ 0 ] ;
2007-04-29 17:35:43 +00:00
else
2011-01-30 14:34:42 +00:00
return 1 ;
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
int TabBox : : previousDesktopFocusChain ( int iDesktop ) const
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
const QVector < int > & desktopFocusChain = Workspace : : self ( ) - > desktopFocusChain ( ) ;
int i = desktopFocusChain . indexOf ( iDesktop ) ;
2011-01-30 14:34:42 +00:00
if ( i - 1 > = 0 )
2011-06-25 16:05:07 +00:00
return desktopFocusChain [ i - 1 ] ;
else if ( desktopFocusChain . size ( ) > 0 )
return desktopFocusChain [ desktopFocusChain . size ( ) - 1 ] ;
2007-04-29 17:35:43 +00:00
else
2011-06-25 16:05:07 +00:00
return Workspace : : self ( ) - > numberOfDesktops ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
int TabBox : : nextDesktopStatic ( int iDesktop ) const
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
int i = + + iDesktop ;
2011-06-25 16:05:07 +00:00
if ( i > Workspace : : self ( ) - > numberOfDesktops ( ) )
2007-04-29 17:35:43 +00:00
i = 1 ;
return i ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
int TabBox : : previousDesktopStatic ( int iDesktop ) const
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
int i = - - iDesktop ;
2011-01-30 14:34:42 +00:00
if ( i < 1 )
2011-06-25 16:05:07 +00:00
i = Workspace : : self ( ) - > numberOfDesktops ( ) ;
2007-04-29 17:35:43 +00:00
return i ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
2008-09-25 17:51:35 +00:00
auxiliary functions to travers all clients according to the focus
2007-04-29 17:35:43 +00:00
order . Useful for kwms Alt - tab feature .
*/
2011-06-25 16:05:07 +00:00
Client * TabBox : : nextClientFocusChain ( Client * c ) const
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
const ClientList & globalFocusChain = Workspace : : self ( ) - > globalFocusChain ( ) ;
if ( globalFocusChain . isEmpty ( ) )
2007-04-29 17:35:43 +00:00
return 0 ;
2011-06-25 16:05:07 +00:00
int pos = globalFocusChain . indexOf ( c ) ;
2011-01-30 14:34:42 +00:00
if ( pos = = - 1 )
2011-06-25 16:05:07 +00:00
return globalFocusChain . last ( ) ;
2011-01-30 14:34:42 +00:00
if ( pos = = 0 )
2011-06-25 16:05:07 +00:00
return globalFocusChain . last ( ) ;
2007-04-29 17:35:43 +00:00
pos - - ;
2011-06-25 16:05:07 +00:00
return globalFocusChain [ pos ] ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
2008-09-25 17:51:35 +00:00
auxiliary functions to travers all clients according to the focus
2007-04-29 17:35:43 +00:00
order . Useful for kwms Alt - tab feature .
*/
2011-06-25 16:05:07 +00:00
Client * TabBox : : previousClientFocusChain ( Client * c ) const
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
const ClientList & globalFocusChain = Workspace : : self ( ) - > globalFocusChain ( ) ;
if ( globalFocusChain . isEmpty ( ) )
2007-04-29 17:35:43 +00:00
return 0 ;
2011-06-25 16:05:07 +00:00
int pos = globalFocusChain . indexOf ( c ) ;
2011-01-30 14:34:42 +00:00
if ( pos = = - 1 )
2011-06-25 16:05:07 +00:00
return globalFocusChain . first ( ) ;
2007-04-29 17:35:43 +00:00
pos + + ;
2011-06-25 16:05:07 +00:00
if ( pos = = globalFocusChain . count ( ) )
return globalFocusChain . first ( ) ;
return globalFocusChain [ pos ] ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
/*!
2008-09-25 17:51:35 +00:00
auxiliary functions to travers all clients according to the static
2007-04-29 17:35:43 +00:00
order . Useful for the CDE - style Alt - tab feature .
*/
2011-06-25 16:05:07 +00:00
Client * TabBox : : nextClientStatic ( Client * c ) const
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
if ( ! c | | Workspace : : self ( ) - > clientList ( ) . isEmpty ( ) )
2007-04-29 17:35:43 +00:00
return 0 ;
2011-06-25 16:05:07 +00:00
int pos = Workspace : : self ( ) - > clientList ( ) . indexOf ( c ) ;
2011-01-30 14:34:42 +00:00
if ( pos = = - 1 )
2011-06-25 16:05:07 +00:00
return Workspace : : self ( ) - > clientList ( ) . first ( ) ;
2007-04-29 17:35:43 +00:00
+ + pos ;
2011-06-25 16:05:07 +00:00
if ( pos = = Workspace : : self ( ) - > clientList ( ) . count ( ) )
return Workspace : : self ( ) - > clientList ( ) . first ( ) ;
return Workspace : : self ( ) - > clientList ( ) [ pos ] ;
2011-01-30 14:34:42 +00:00
}
2011-06-25 16:05:07 +00:00
2007-04-29 17:35:43 +00:00
/*!
2008-09-25 17:51:35 +00:00
auxiliary functions to travers all clients according to the static
2007-04-29 17:35:43 +00:00
order . Useful for the CDE - style Alt - tab feature .
*/
2011-06-25 16:05:07 +00:00
Client * TabBox : : previousClientStatic ( Client * c ) const
2011-01-30 14:34:42 +00:00
{
2011-06-25 16:05:07 +00:00
if ( ! c | | Workspace : : self ( ) - > clientList ( ) . isEmpty ( ) )
2007-04-29 17:35:43 +00:00
return 0 ;
2011-06-25 16:05:07 +00:00
int pos = Workspace : : self ( ) - > clientList ( ) . indexOf ( c ) ;
2011-01-30 14:34:42 +00:00
if ( pos = = - 1 )
2011-06-25 16:05:07 +00:00
return Workspace : : self ( ) - > clientList ( ) . last ( ) ;
2011-01-30 14:34:42 +00:00
if ( pos = = 0 )
2011-06-25 16:05:07 +00:00
return Workspace : : self ( ) - > clientList ( ) . last ( ) ;
2007-04-29 17:35:43 +00:00
- - pos ;
2011-06-25 16:05:07 +00:00
return Workspace : : self ( ) - > clientList ( ) [ pos ] ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
bool TabBox : : establishTabBoxGrab ( )
2011-01-30 14:34:42 +00:00
{
if ( ! grabXKeyboard ( ) )
2007-04-29 17:35:43 +00:00
return false ;
// Don't try to establish a global mouse grab using XGrabPointer, as that would prevent
// using Alt+Tab while DND (#44972). However force passive grabs on all windows
// in order to catch MouseRelease events and close the tabbox (#67416).
// All clients already have passive grabs in their wrapper windows, so check only
// the active client, which may not have it.
2011-06-25 16:05:07 +00:00
assert ( ! m_forcedGlobalMouseGrab ) ;
m_forcedGlobalMouseGrab = true ;
if ( Workspace : : self ( ) - > activeClient ( ) ! = NULL )
Workspace : : self ( ) - > activeClient ( ) - > updateMouseGrab ( ) ;
2007-04-29 17:35:43 +00:00
return true ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-06-25 16:05:07 +00:00
void TabBox : : removeTabBoxGrab ( )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
ungrabXKeyboard ( ) ;
2011-06-25 16:05:07 +00:00
assert ( m_forcedGlobalMouseGrab ) ;
m_forcedGlobalMouseGrab = false ;
if ( Workspace : : self ( ) - > activeClient ( ) ! = NULL )
Workspace : : self ( ) - > activeClient ( ) - > updateMouseGrab ( ) ;
2011-01-30 14:34:42 +00:00
}
2011-06-25 16:05:07 +00:00
} // namespace TabBox
2007-04-29 17:35:43 +00:00
} // namespace
# include "tabbox.moc"