2005-04-08 14:31:00 +00:00
|
|
|
/*****************************************************************
|
2003-09-16 19:28:03 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2003-04-22 10:05:58 +00:00
|
|
|
|
2000-03-24 22:23:02 +00:00
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
2003-09-16 19:28:03 +00:00
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
2000-03-24 22:23:02 +00:00
|
|
|
******************************************************************/
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2000-07-29 07:59:24 +00:00
|
|
|
//#define QT_CLEAN_NAMESPACE
|
1999-08-19 23:26:42 +00:00
|
|
|
#include "tabbox.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include <qpainter.h>
|
1999-11-26 22:10:25 +00:00
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qdrawutil.h>
|
2001-08-18 23:06:16 +00:00
|
|
|
#include <qstyle.h>
|
2000-05-14 01:58:13 +00:00
|
|
|
#include <kglobal.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <fixx11h.h>
|
2000-05-14 01:58:13 +00:00
|
|
|
#include <kconfig.h>
|
2000-06-01 05:32:06 +00:00
|
|
|
#include <klocale.h>
|
2002-01-08 10:33:05 +00:00
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qdesktopwidget.h>
|
|
|
|
#include <qcursor.h>
|
2002-03-02 16:03:29 +00:00
|
|
|
#include <kstringhandler.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kglobalaccel.h>
|
|
|
|
#include <kkeynative.h>
|
2003-02-20 05:52:39 +00:00
|
|
|
#include <kglobalsettings.h>
|
2004-11-09 14:32:30 +00:00
|
|
|
#include <kiconeffect.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/keysymdef.h>
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2001-02-22 09:45:19 +00:00
|
|
|
// specify externals before namespace
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
extern Time qt_x_time;
|
2001-02-22 09:45:19 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
extern QPixmap* kwin_get_menu_pix_hack();
|
2001-02-20 01:20:38 +00:00
|
|
|
|
1999-11-25 12:53:17 +00:00
|
|
|
TabBox::TabBox( Workspace *ws, const char *name )
|
2004-02-05 21:58:22 +00:00
|
|
|
: QFrame( 0, name, Qt::WNoAutoErase ), client(0), wspace(ws)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
|
|
|
setLineWidth(2);
|
|
|
|
setMargin(2);
|
|
|
|
|
|
|
|
showMiniIcon = false;
|
|
|
|
|
2004-06-12 20:11:53 +00:00
|
|
|
no_tasks = i18n("*** No Windows ***");
|
2002-02-11 18:25:38 +00:00
|
|
|
m = DesktopMode; // init variables
|
2005-06-22 15:44:24 +00:00
|
|
|
updateKeyMapping();
|
2001-03-19 20:05:36 +00:00
|
|
|
reconfigure();
|
1999-08-19 23:26:42 +00:00
|
|
|
reset();
|
2000-05-14 01:58:13 +00:00
|
|
|
connect(&delayedShowTimer, SIGNAL(timeout()), this, SLOT(show()));
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
TabBox::~TabBox()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2001-06-10 04:10:42 +00:00
|
|
|
Sets the current mode to \a mode, either DesktopListMode or WindowsMode
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
\sa mode()
|
|
|
|
*/
|
|
|
|
void TabBox::setMode( Mode mode )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
1999-08-19 23:26:42 +00:00
|
|
|
m = mode;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
/*!
|
|
|
|
Create list of clients on specified desktop, starting with client c
|
|
|
|
*/
|
|
|
|
void TabBox::createClientList(ClientList &list, int desktop /*-1 = all*/, Client *c, bool chain)
|
|
|
|
{
|
|
|
|
ClientList::size_type idx = 0;
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
Client* start = c;
|
|
|
|
|
|
|
|
if ( chain )
|
|
|
|
c = workspace()->nextFocusChainClient(c);
|
|
|
|
else
|
|
|
|
c = workspace()->stackingOrder().first();
|
|
|
|
|
|
|
|
Client* stop = c;
|
|
|
|
|
|
|
|
while ( c )
|
|
|
|
{
|
|
|
|
if ( ((desktop == -1) || c->isOnDesktop(desktop))
|
2004-10-14 09:15:57 +00:00
|
|
|
&& c->wantsTabFocus() )
|
2004-02-05 21:58:22 +00:00
|
|
|
{
|
|
|
|
if ( start == c )
|
|
|
|
{
|
|
|
|
list.remove( c );
|
|
|
|
list.prepend( c );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // don't add windows that have modal dialogs
|
|
|
|
Client* modal = c->findModal();
|
|
|
|
if( modal == NULL || modal == c )
|
|
|
|
list += c;
|
|
|
|
else if( !list.contains( modal ))
|
|
|
|
list += modal;
|
|
|
|
else
|
|
|
|
; // nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( chain )
|
|
|
|
c = workspace()->nextFocusChainClient( c );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( idx >= (workspace()->stackingOrder().size()-1) )
|
|
|
|
c = 0;
|
|
|
|
else
|
|
|
|
c = workspace()->stackingOrder()[++idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( c == stop )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
/*!
|
|
|
|
Resets the tab box to display the active client in WindowsMode, or the
|
2001-06-10 04:10:42 +00:00
|
|
|
current desktop in DesktopListMode
|
1999-08-19 23:26:42 +00:00
|
|
|
*/
|
|
|
|
void TabBox::reset()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
int w, h, cw = 0, wmax = 0;
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
QRect r = KGlobalSettings::desktopGeometry(QCursor::pos());
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
// calculate height of 1 line
|
|
|
|
// fontheight + 1 pixel above + 1 pixel below, or 32x32 icon + 2 pixel above + below
|
|
|
|
lineHeight = QMAX(fontMetrics().height() + 2, 32 + 4);
|
|
|
|
|
|
|
|
if ( mode() == WindowsMode )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
client = workspace()->activeClient();
|
2004-02-05 21:58:22 +00:00
|
|
|
|
|
|
|
// get all clients to show
|
|
|
|
createClientList(clients, options_traverse_all ? -1 : workspace()->currentDesktop(), client, true);
|
|
|
|
|
|
|
|
// calculate maximum caption width
|
|
|
|
cw = fontMetrics().width(no_tasks)+20;
|
|
|
|
for (ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it)
|
|
|
|
{
|
|
|
|
cw = fontMetrics().width( (*it)->caption() );
|
|
|
|
if ( cw > wmax ) wmax = cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate height for the popup
|
|
|
|
if ( clients.count() == 0 ) // height for the "not tasks" text
|
|
|
|
{
|
|
|
|
QFont f = font();
|
|
|
|
f.setBold( TRUE );
|
|
|
|
f.setPointSize( 14 );
|
|
|
|
|
|
|
|
h = QFontMetrics(f).height()*4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
showMiniIcon = false;
|
|
|
|
h = clients.count() * lineHeight;
|
|
|
|
|
|
|
|
if ( h > (r.height()-(2*frameWidth())) ) // if too high, use mini icons
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
showMiniIcon = true;
|
|
|
|
// fontheight + 1 pixel above + 1 pixel below, or 16x16 icon + 1 pixel above + below
|
|
|
|
lineHeight = QMAX(fontMetrics().height() + 2, 16 + 2);
|
|
|
|
|
|
|
|
h = clients.count() * lineHeight;
|
|
|
|
|
|
|
|
if ( h > (r.height()-(2*frameWidth())) ) // if still too high, remove some clients
|
|
|
|
{
|
|
|
|
// how many clients to remove
|
|
|
|
int howMany = (h - (r.height()-(2*frameWidth())))/lineHeight;
|
|
|
|
for (; howMany; howMany--)
|
|
|
|
clients.remove(clients.last());
|
|
|
|
|
|
|
|
h = clients.count() * lineHeight;
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{ // DesktopListMode
|
2004-02-05 21:58:22 +00:00
|
|
|
showMiniIcon = false;
|
2003-09-16 19:28:03 +00:00
|
|
|
desk = workspace()->currentDesktop();
|
2004-02-05 21:58:22 +00:00
|
|
|
|
|
|
|
for ( int i = 1; i <= workspace()->numberOfDesktops(); i++ )
|
|
|
|
{
|
|
|
|
cw = fontMetrics().width( workspace()->desktopName(i) );
|
|
|
|
if ( cw > wmax ) wmax = cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate height for the popup (max. 16 desktops always fit in a 800x600 screen)
|
|
|
|
h = workspace()->numberOfDesktops() * lineHeight;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
// height, width for the popup
|
|
|
|
h += 2 * frameWidth();
|
2004-07-26 19:14:30 +00:00
|
|
|
w = 2*frameWidth() + 5*2 + ( showMiniIcon ? 16 : 32 ) + 8 + wmax; // 5*2=margins, ()=icon, 8=space between icon+text
|
2004-11-26 16:14:32 +00:00
|
|
|
w = kClamp( w, r.width()/3 , r.width() * 4 / 5 );
|
2002-01-08 10:33:05 +00:00
|
|
|
|
|
|
|
setGeometry( (r.width()-w)/2 + r.x(),
|
2004-02-05 21:58:22 +00:00
|
|
|
(r.height()-h)/2+ r.y(),
|
|
|
|
w, h );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Shows the next or previous item, depending on \a next
|
|
|
|
*/
|
|
|
|
void TabBox::nextPrev( bool next)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( mode() == WindowsMode )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
Client* firstClient = 0;
|
2004-06-12 20:11:53 +00:00
|
|
|
do
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( next )
|
|
|
|
client = workspace()->nextFocusChainClient(client);
|
|
|
|
else
|
|
|
|
client = workspace()->previousFocusChainClient(client);
|
2004-06-12 20:11:53 +00:00
|
|
|
if (!firstClient)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2000-06-08 17:05:51 +00:00
|
|
|
// When we see our first client for the second time,
|
2000-06-01 05:32:06 +00:00
|
|
|
// it's time to stop.
|
2003-09-16 19:28:03 +00:00
|
|
|
firstClient = client;
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else if (client == firstClient)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2000-06-01 05:32:06 +00:00
|
|
|
// No candidates found.
|
2003-09-16 19:28:03 +00:00
|
|
|
client = 0;
|
|
|
|
break;
|
|
|
|
}
|
2003-10-13 16:22:58 +00:00
|
|
|
} while ( client && !clients.contains( client ));
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else if( mode() == DesktopMode )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( next )
|
|
|
|
desk = workspace()->nextDesktopFocusChain( desk );
|
|
|
|
else
|
|
|
|
desk = workspace()->previousDesktopFocusChain( desk );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{ // DesktopListMode
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( next )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
desk++;
|
|
|
|
if ( desk > workspace()->numberOfDesktops() )
|
|
|
|
desk = 1;
|
2000-06-01 05:32:06 +00:00
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
desk--;
|
|
|
|
if ( desk < 1 )
|
|
|
|
desk = workspace()->numberOfDesktops();
|
|
|
|
}
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
update();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the currently displayed client ( only works in WindowsMode ).
|
|
|
|
Returns 0 if no client is displayed.
|
|
|
|
*/
|
|
|
|
Client* TabBox::currentClient()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
1999-08-19 23:26:42 +00:00
|
|
|
if ( mode() != WindowsMode )
|
2003-09-16 19:28:03 +00:00
|
|
|
return 0;
|
2001-11-07 01:09:29 +00:00
|
|
|
if (!workspace()->hasClient( client ))
|
|
|
|
return 0;
|
1999-08-19 23:26:42 +00:00
|
|
|
return client;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the currently displayed virtual desktop ( only works in
|
2001-06-10 04:10:42 +00:00
|
|
|
DesktopListMode )
|
1999-08-19 23:26:42 +00:00
|
|
|
Returns -1 if no desktop is displayed.
|
|
|
|
*/
|
|
|
|
int TabBox::currentDesktop()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2001-06-10 04:10:42 +00:00
|
|
|
if ( mode() == DesktopListMode || mode() == DesktopMode )
|
2003-09-16 19:28:03 +00:00
|
|
|
return desk;
|
2001-06-10 04:10:42 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Reimplemented to raise the tab box as well
|
|
|
|
*/
|
|
|
|
void TabBox::showEvent( QShowEvent* )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
1999-08-19 23:26:42 +00:00
|
|
|
raise();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
/*!
|
|
|
|
hide the icon box if necessary
|
|
|
|
*/
|
|
|
|
void TabBox::hideEvent( QHideEvent* )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
}
|
1999-11-26 22:10:25 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
/*!
|
|
|
|
Paints the tab box
|
|
|
|
*/
|
2004-02-05 21:58:22 +00:00
|
|
|
void TabBox::drawContents( QPainter * )
|
1999-08-19 23:26:42 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
QRect r(contentsRect());
|
|
|
|
QPixmap pix(r.size()); // do double buffering to avoid flickers
|
|
|
|
pix.fill(this, 0, 0);
|
1999-08-19 23:26:42 +00:00
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
QPainter p;
|
|
|
|
p.begin(&pix, this);
|
1999-11-26 22:10:25 +00:00
|
|
|
|
|
|
|
QPixmap* menu_pix = kwin_get_menu_pix_hack();
|
2004-02-05 21:58:22 +00:00
|
|
|
|
|
|
|
int iconWidth = showMiniIcon ? 16 : 32;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( mode () == WindowsMode )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
if ( !currentClient() )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
QFont f = font();
|
|
|
|
f.setBold( TRUE );
|
|
|
|
f.setPointSize( 14 );
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2004-02-05 21:58:22 +00:00
|
|
|
p.setFont(f);
|
2003-09-16 19:28:03 +00:00
|
|
|
p.drawText( r, AlignCenter, no_tasks);
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-06-12 20:11:53 +00:00
|
|
|
for (ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it)
|
2004-02-05 21:58:22 +00:00
|
|
|
{
|
|
|
|
if ( workspace()->hasClient( *it ) ) // safety
|
|
|
|
{
|
|
|
|
// draw highlight background
|
|
|
|
if ( (*it) == currentClient() )
|
|
|
|
p.fillRect(x, y, r.width(), lineHeight, colorGroup().highlight());
|
|
|
|
|
|
|
|
// draw icon
|
2004-11-09 14:32:30 +00:00
|
|
|
QPixmap icon;
|
2004-02-05 21:58:22 +00:00
|
|
|
if ( showMiniIcon )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
if ( !(*it)->miniIcon().isNull() )
|
2004-11-09 14:32:30 +00:00
|
|
|
icon = (*it)->miniIcon();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
else
|
|
|
|
if ( !(*it)->icon().isNull() )
|
2004-11-09 14:32:30 +00:00
|
|
|
icon = (*it)->icon();
|
2004-02-05 21:58:22 +00:00
|
|
|
else if ( menu_pix )
|
2004-11-09 14:32:30 +00:00
|
|
|
icon = *menu_pix;
|
|
|
|
|
|
|
|
if( !icon.isNull())
|
|
|
|
{
|
|
|
|
if( (*it)->isMinimized())
|
|
|
|
KIconEffect::semiTransparent( icon );
|
|
|
|
p.drawPixmap( x+5, y + (lineHeight - iconWidth)/2, icon );
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
|
|
|
|
// generate text to display
|
|
|
|
QString s;
|
|
|
|
|
|
|
|
if ( !(*it)->isOnDesktop(workspace()->currentDesktop()) )
|
|
|
|
s = workspace()->desktopName((*it)->desktop()) + ": ";
|
|
|
|
|
|
|
|
if ( (*it)->isMinimized() )
|
|
|
|
s += QString("(") + (*it)->caption() + ")";
|
|
|
|
else
|
|
|
|
s += (*it)->caption();
|
|
|
|
|
|
|
|
s = KStringHandler::cPixelSqueeze(s, fontMetrics(), r.width() - 5 - iconWidth - 8);
|
|
|
|
|
|
|
|
// draw text
|
|
|
|
if ( (*it) == currentClient() )
|
|
|
|
p.setPen(colorGroup().highlightedText());
|
2004-11-09 14:32:30 +00:00
|
|
|
else if( (*it)->isMinimized())
|
|
|
|
{
|
|
|
|
QColor c1 = colorGroup().text();
|
|
|
|
QColor c2 = colorGroup().background();
|
|
|
|
// from kicker's TaskContainer::blendColors()
|
|
|
|
int r1, g1, b1;
|
|
|
|
int r2, g2, b2;
|
|
|
|
|
|
|
|
c1.rgb( &r1, &g1, &b1 );
|
|
|
|
c2.rgb( &r2, &g2, &b2 );
|
|
|
|
|
|
|
|
r1 += (int) ( .5 * ( r2 - r1 ) );
|
|
|
|
g1 += (int) ( .5 * ( g2 - g1 ) );
|
|
|
|
b1 += (int) ( .5 * ( b2 - b1 ) );
|
|
|
|
|
|
|
|
p.setPen(QColor( r1, g1, b1 ));
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
else
|
|
|
|
p.setPen(colorGroup().text());
|
|
|
|
|
|
|
|
p.drawText(x+5 + iconWidth + 8, y, r.width() - 5 - iconWidth - 8, lineHeight,
|
|
|
|
Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, s);
|
|
|
|
|
|
|
|
y += lineHeight;
|
|
|
|
}
|
|
|
|
if ( y >= r.height() ) break;
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{ // DesktopMode || DesktopListMode
|
2004-02-05 21:58:22 +00:00
|
|
|
int iconHeight = iconWidth;
|
|
|
|
|
|
|
|
// get widest desktop name/number
|
|
|
|
QFont f(font());
|
|
|
|
f.setBold(true);
|
|
|
|
f.setPixelSize(iconHeight - 4); // pixel, not point because I need to know the pixels
|
|
|
|
QFontMetrics fm(f);
|
|
|
|
|
|
|
|
int wmax = 0;
|
2004-06-12 20:11:53 +00:00
|
|
|
for ( int i = 1; i <= workspace()->numberOfDesktops(); i++ )
|
2004-02-05 21:58:22 +00:00
|
|
|
{
|
|
|
|
wmax = QMAX(wmax, fontMetrics().width(workspace()->desktopName(i)));
|
|
|
|
|
|
|
|
// calculate max width of desktop-number text
|
|
|
|
QString num = QString::number(i);
|
|
|
|
iconWidth = QMAX(iconWidth - 4, fm.boundingRect(num).width()) + 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In DesktopMode, start at the current desktop
|
|
|
|
// In DesktopListMode, start at desktop #1
|
2003-09-16 19:28:03 +00:00
|
|
|
int iDesktop = (mode() == DesktopMode) ? workspace()->currentDesktop() : 1;
|
2004-06-12 20:11:53 +00:00
|
|
|
for ( int i = 1; i <= workspace()->numberOfDesktops(); i++ )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
// draw highlight background
|
|
|
|
if ( iDesktop == desk ) // current desktop
|
|
|
|
p.fillRect(x, y, r.width(), lineHeight, colorGroup().highlight());
|
|
|
|
|
|
|
|
p.save();
|
|
|
|
|
|
|
|
// draw "icon" (here: number of desktop)
|
|
|
|
p.fillRect(x+5, y+2, iconWidth, iconHeight, colorGroup().base());
|
|
|
|
p.setPen(colorGroup().text());
|
|
|
|
p.drawRect(x+5, y+2, iconWidth, iconHeight);
|
|
|
|
|
|
|
|
// draw desktop-number
|
|
|
|
p.setFont(f);
|
|
|
|
QString num = QString::number(iDesktop);
|
|
|
|
p.drawText(x+5, y+2, iconWidth, iconHeight, Qt::AlignCenter, num);
|
|
|
|
|
|
|
|
p.restore();
|
|
|
|
|
|
|
|
// draw desktop name text
|
|
|
|
if ( iDesktop == desk )
|
|
|
|
p.setPen(colorGroup().highlightedText());
|
|
|
|
else
|
|
|
|
p.setPen(colorGroup().text());
|
|
|
|
|
|
|
|
p.drawText(x+5 + iconWidth + 8, y, r.width() - 5 - iconWidth - 8, lineHeight,
|
|
|
|
Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine,
|
|
|
|
workspace()->desktopName(iDesktop));
|
|
|
|
|
|
|
|
// show mini icons from that desktop aligned to each other
|
|
|
|
int x1 = x + 5 + iconWidth + 8 + wmax + 5;
|
|
|
|
|
|
|
|
ClientList list;
|
|
|
|
createClientList(list, iDesktop, 0, false);
|
|
|
|
// clients are in reversed stacking order
|
|
|
|
for (ClientList::ConstIterator it = list.fromLast(); it != list.end(); --it)
|
|
|
|
{
|
|
|
|
if ( !(*it)->miniIcon().isNull() )
|
|
|
|
{
|
|
|
|
if ( x1+18 >= x+r.width() ) // only show full icons
|
|
|
|
break;
|
|
|
|
|
|
|
|
p.drawPixmap( x1, y + (lineHeight - 16)/2, (*it)->miniIcon() );
|
|
|
|
x1 += 18;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// next desktop
|
|
|
|
y += lineHeight;
|
|
|
|
if ( y >= r.height() ) break;
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
if( mode() == DesktopMode )
|
|
|
|
iDesktop = workspace()->nextDesktopFocusChain( iDesktop );
|
|
|
|
else
|
|
|
|
iDesktop++;
|
|
|
|
}
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
p.end();
|
|
|
|
bitBlt(this, r.x(), r.y(), &pix);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2000-05-14 01:58:13 +00:00
|
|
|
|
2000-07-08 11:57:38 +00:00
|
|
|
void TabBox::hide()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2000-07-08 11:57:38 +00:00
|
|
|
delayedShowTimer.stop();
|
|
|
|
QWidget::hide();
|
|
|
|
QApplication::syncX();
|
|
|
|
XEvent otherEvent;
|
|
|
|
while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
;
|
|
|
|
}
|
2000-05-14 01:58:13 +00:00
|
|
|
|
|
|
|
|
2001-03-19 20:05:36 +00:00
|
|
|
void TabBox::reconfigure()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2001-03-19 20:05:36 +00:00
|
|
|
KConfig * c(KGlobal::config());
|
|
|
|
c->setGroup("TabBox");
|
|
|
|
options_traverse_all = c->readNumEntry("TraverseAll", false );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2001-03-19 20:05:36 +00:00
|
|
|
|
2000-07-08 11:57:38 +00:00
|
|
|
/*!
|
|
|
|
Rikkus: please document! (Matthias)
|
2000-07-16 10:20:29 +00:00
|
|
|
|
|
|
|
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.
|
2000-07-08 11:57:38 +00:00
|
|
|
*/
|
|
|
|
void TabBox::delayedShow()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2000-07-08 11:57:38 +00:00
|
|
|
KConfig * c(KGlobal::config());
|
|
|
|
c->setGroup("TabBox");
|
2000-07-16 10:20:29 +00:00
|
|
|
bool delay = c->readNumEntry("ShowDelay", true);
|
2000-07-14 19:56:47 +00:00
|
|
|
|
2004-06-12 20:11:53 +00:00
|
|
|
if (!delay)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
show();
|
|
|
|
return;
|
|
|
|
}
|
2000-05-14 01:58:13 +00:00
|
|
|
|
2000-08-07 23:18:48 +00:00
|
|
|
int delayTime = c->readNumEntry("DelayTime", 90);
|
2000-07-08 11:57:38 +00:00
|
|
|
delayedShowTimer.start(delayTime, true);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TabBox::handleMouseEvent( XEvent* e )
|
|
|
|
{
|
|
|
|
XAllowEvents( qt_xdisplay(), AsyncPointer, qt_x_time );
|
|
|
|
if( e->type != ButtonPress )
|
|
|
|
return;
|
|
|
|
QPoint pos( e->xbutton.x_root, e->xbutton.y_root );
|
|
|
|
if( !geometry().contains( pos ))
|
2004-02-10 09:24:57 +00:00
|
|
|
{
|
|
|
|
workspace()->closeTabBox(); // click outside closes tab
|
2003-09-16 19:28:03 +00:00
|
|
|
return;
|
2004-02-10 09:24:57 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
pos.rx() -= x(); // pos is now inside tabbox
|
|
|
|
pos.ry() -= y();
|
2004-02-05 21:58:22 +00:00
|
|
|
int num = (pos.y()-frameWidth()) / lineHeight;
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
if( mode() == WindowsMode )
|
|
|
|
{
|
|
|
|
for( ClientList::ConstIterator it = clients.begin();
|
|
|
|
it != clients.end();
|
|
|
|
++it)
|
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
if( workspace()->hasClient( *it ) && (num == 0) ) // safety
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
client = *it;
|
|
|
|
break;
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
num--;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int iDesktop = (mode() == DesktopMode) ? workspace()->currentDesktop() : 1;
|
|
|
|
for( int i = 1;
|
|
|
|
i <= workspace()->numberOfDesktops();
|
|
|
|
++i )
|
|
|
|
{
|
2004-02-05 21:58:22 +00:00
|
|
|
if( num == 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
desk = iDesktop;
|
|
|
|
break;
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
num--;
|
2003-09-16 19:28:03 +00:00
|
|
|
if( mode() == DesktopMode )
|
|
|
|
iDesktop = workspace()->nextDesktopFocusChain( iDesktop );
|
|
|
|
else
|
|
|
|
iDesktop++;
|
|
|
|
}
|
|
|
|
}
|
2004-02-05 21:58:22 +00:00
|
|
|
update();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//*******************************
|
|
|
|
// Workspace
|
|
|
|
//*******************************
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Handles alt-tab / control-tab
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
2005-06-22 15:16:31 +00:00
|
|
|
bool areKeySymXsDepressed( bool bAll, const uint keySyms[], int nKeySyms )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
char keymap[32];
|
|
|
|
|
|
|
|
kdDebug(125) << "areKeySymXsDepressed: " << (bAll ? "all of " : "any of ") << nKeySyms << endl;
|
|
|
|
|
|
|
|
XQueryKeymap( qt_xdisplay(), keymap );
|
|
|
|
|
2004-06-12 20:11:53 +00:00
|
|
|
for( int iKeySym = 0; iKeySym < nKeySyms; iKeySym++ )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-06-22 15:16:31 +00:00
|
|
|
uint keySymX = keySyms[ iKeySym ];
|
2003-09-16 19:28:03 +00:00
|
|
|
uchar keyCodeX = XKeysymToKeycode( qt_xdisplay(), keySymX );
|
|
|
|
int i = keyCodeX / 8;
|
|
|
|
char mask = 1 << (keyCodeX - (i * 8));
|
|
|
|
|
|
|
|
kdDebug(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;
|
|
|
|
|
|
|
|
// Abort if bad index value,
|
|
|
|
if( i < 0 || i >= 32 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If ALL keys passed need to be depressed,
|
2004-06-12 20:11:53 +00:00
|
|
|
if( bAll )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if( (keymap[i] & mask) == 0 )
|
|
|
|
return false;
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
// If we are looking for ANY key press, and this key is depressed,
|
|
|
|
if( keymap[i] & mask )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
return bAll;
|
|
|
|
}
|
|
|
|
|
2005-06-22 15:44:24 +00:00
|
|
|
static const int MAX_KEYSYMS = 4;
|
|
|
|
static uint alt_keysyms[ MAX_KEYSYMS ];
|
|
|
|
static uint win_keysyms[ MAX_KEYSYMS ];
|
|
|
|
|
2004-08-25 16:54:36 +00:00
|
|
|
static bool areModKeysDepressed( const KKeySequence& seq )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
uint rgKeySyms[10];
|
|
|
|
int nKeySyms = 0;
|
2004-08-25 16:54:36 +00:00
|
|
|
if( seq.isNull())
|
|
|
|
return false;
|
|
|
|
int mod = seq.key(seq.count()-1).modFlags();
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( mod & KKey::SHIFT )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
rgKeySyms[nKeySyms++] = XK_Shift_L;
|
|
|
|
rgKeySyms[nKeySyms++] = XK_Shift_R;
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( mod & KKey::CTRL )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
rgKeySyms[nKeySyms++] = XK_Control_L;
|
|
|
|
rgKeySyms[nKeySyms++] = XK_Control_R;
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
if( mod & KKey::ALT )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-06-22 15:44:24 +00:00
|
|
|
for( int i = 0;
|
|
|
|
i < MAX_KEYSYMS && alt_keysyms[ i ] != NoSymbol;
|
|
|
|
++i )
|
|
|
|
rgKeySyms[nKeySyms++] = alt_keysyms[ i ];
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
if( mod & KKey::WIN )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-06-22 15:44:24 +00:00
|
|
|
for( int i = 0;
|
|
|
|
i < MAX_KEYSYMS && win_keysyms[ i ] != NoSymbol;
|
|
|
|
++i )
|
|
|
|
rgKeySyms[nKeySyms++] = win_keysyms[ i ];
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2005-06-22 15:16:31 +00:00
|
|
|
return areKeySymXsDepressed( false, rgKeySyms, nKeySyms );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2004-08-25 16:54:36 +00:00
|
|
|
static bool areModKeysDepressed( const KShortcut& cut )
|
|
|
|
{
|
2004-08-26 10:27:09 +00:00
|
|
|
for( unsigned int i = 0;
|
2004-08-25 16:54:36 +00:00
|
|
|
i < cut.count();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
if( areModKeysDepressed( cut.seq( i )))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-22 15:44:24 +00:00
|
|
|
void TabBox::updateKeyMapping()
|
|
|
|
{
|
|
|
|
const int size = 6;
|
|
|
|
uint keysyms[ size ] = { XK_Alt_L, XK_Alt_R, XK_Super_L, XK_Super_R, XK_Meta_L, XK_Meta_R };
|
|
|
|
XModifierKeymap* map = XGetModifierMapping( qt_xdisplay() );
|
|
|
|
int altpos = 0;
|
|
|
|
int winpos = 0;
|
|
|
|
int winmodpos = -1;
|
|
|
|
int winmod = KKeyNative::modX( KKey::WIN );
|
|
|
|
while( winmod > 0 ) // get position of the set bit in winmod
|
|
|
|
{
|
|
|
|
winmod >>= 1;
|
|
|
|
++winmodpos;
|
|
|
|
}
|
|
|
|
for( int i = 0;
|
|
|
|
i < MAX_KEYSYMS;
|
|
|
|
++i )
|
|
|
|
alt_keysyms[ i ] = win_keysyms[ i ] = NoSymbol;
|
|
|
|
for( int i = 0;
|
|
|
|
i < size;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
KeyCode keycode = XKeysymToKeycode( qt_xdisplay(), keysyms[ i ] );
|
|
|
|
for( int j = 0;
|
|
|
|
j < map->max_keypermod;
|
|
|
|
++j )
|
|
|
|
{
|
|
|
|
if( map->modifiermap[ 3 * map->max_keypermod + j ] == keycode ) // Alt
|
|
|
|
if( altpos < MAX_KEYSYMS )
|
|
|
|
alt_keysyms[ altpos++ ] = keysyms[ i ];
|
|
|
|
if( winmodpos >= 0 && map->modifiermap[ winmodpos * map->max_keypermod + j ] == keycode )
|
|
|
|
if( winpos < MAX_KEYSYMS )
|
|
|
|
win_keysyms[ winpos++ ] = keysyms[ i ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFreeModifiermap( map );
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void Workspace::slotWalkThroughWindows()
|
|
|
|
{
|
|
|
|
if ( root != qt_xrootwin() )
|
|
|
|
return;
|
|
|
|
if ( tab_grab || control_grab )
|
|
|
|
return;
|
2005-05-09 12:09:24 +00:00
|
|
|
if ( options->altTabStyle == Options::CDE )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
//XUngrabKeyboard(qt_xdisplay(), qt_x_time); // need that because of accelerator raw mode
|
|
|
|
// CDE style raise / lower
|
|
|
|
CDEWalkThroughWindows( true );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( areModKeysDepressed( cutWalkThroughWindows ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( startKDEWalkThroughWindows() )
|
|
|
|
KDEWalkThroughWindows( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// if the shortcut has no modifiers, don't show the tabbox,
|
|
|
|
// don't grab, but simply go to the next window
|
2005-04-08 14:31:00 +00:00
|
|
|
KDEOneStepThroughWindows( true );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWalkBackThroughWindows()
|
|
|
|
{
|
|
|
|
if ( root != qt_xrootwin() )
|
|
|
|
return;
|
|
|
|
if( tab_grab || control_grab )
|
|
|
|
return;
|
2005-05-09 12:09:24 +00:00
|
|
|
if ( options->altTabStyle == Options::CDE )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
// CDE style raise / lower
|
|
|
|
CDEWalkThroughWindows( false );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( areModKeysDepressed( cutWalkThroughWindowsReverse ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( startKDEWalkThroughWindows() )
|
|
|
|
KDEWalkThroughWindows( false );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2005-04-08 14:31:00 +00:00
|
|
|
KDEOneStepThroughWindows( false );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWalkThroughDesktops()
|
|
|
|
{
|
|
|
|
if ( root != qt_xrootwin() )
|
|
|
|
return;
|
|
|
|
if( tab_grab || control_grab )
|
|
|
|
return;
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( areModKeysDepressed( cutWalkThroughDesktops ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( startWalkThroughDesktops() )
|
|
|
|
walkThroughDesktops( true );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
oneStepThroughDesktops( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWalkBackThroughDesktops()
|
|
|
|
{
|
|
|
|
if ( root != qt_xrootwin() )
|
|
|
|
return;
|
|
|
|
if( tab_grab || control_grab )
|
|
|
|
return;
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( areModKeysDepressed( cutWalkThroughDesktopsReverse ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( startWalkThroughDesktops() )
|
|
|
|
walkThroughDesktops( false );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
oneStepThroughDesktops( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWalkThroughDesktopList()
|
|
|
|
{
|
|
|
|
if ( root != qt_xrootwin() )
|
|
|
|
return;
|
|
|
|
if( tab_grab || control_grab )
|
|
|
|
return;
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( areModKeysDepressed( cutWalkThroughDesktopList ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( startWalkThroughDesktopList() )
|
|
|
|
walkThroughDesktops( true );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
oneStepThroughDesktopList( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::slotWalkBackThroughDesktopList()
|
|
|
|
{
|
|
|
|
if ( root != qt_xrootwin() )
|
|
|
|
return;
|
|
|
|
if( tab_grab || control_grab )
|
|
|
|
return;
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( areModKeysDepressed( cutWalkThroughDesktopListReverse ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( startWalkThroughDesktopList() )
|
|
|
|
walkThroughDesktops( false );
|
|
|
|
}
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
oneStepThroughDesktopList( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Workspace::startKDEWalkThroughWindows()
|
|
|
|
{
|
2004-02-10 09:24:57 +00:00
|
|
|
if( !establishTabBoxGrab())
|
|
|
|
return false;
|
2003-09-16 19:28:03 +00:00
|
|
|
tab_grab = TRUE;
|
|
|
|
keys->setEnabled( false );
|
2005-01-10 09:56:21 +00:00
|
|
|
client_keys->setEnabled( false );
|
2003-09-16 19:28:03 +00:00
|
|
|
tab_box->setMode( TabBox::WindowsMode );
|
|
|
|
tab_box->reset();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Workspace::startWalkThroughDesktops( int mode )
|
|
|
|
{
|
2004-02-10 09:24:57 +00:00
|
|
|
if( !establishTabBoxGrab())
|
|
|
|
return false;
|
2003-09-16 19:28:03 +00:00
|
|
|
control_grab = TRUE;
|
|
|
|
keys->setEnabled( false );
|
2005-01-10 09:56:21 +00:00
|
|
|
client_keys->setEnabled( false );
|
2003-09-16 19:28:03 +00:00
|
|
|
tab_box->setMode( (TabBox::Mode) mode );
|
|
|
|
tab_box->reset();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Workspace::startWalkThroughDesktops()
|
|
|
|
{
|
|
|
|
return startWalkThroughDesktops( TabBox::DesktopMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Workspace::startWalkThroughDesktopList()
|
|
|
|
{
|
|
|
|
return startWalkThroughDesktops( TabBox::DesktopListMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::KDEWalkThroughWindows( bool forward )
|
|
|
|
{
|
|
|
|
tab_box->nextPrev( forward );
|
|
|
|
tab_box->delayedShow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::walkThroughDesktops( bool forward )
|
|
|
|
{
|
|
|
|
tab_box->nextPrev( forward );
|
|
|
|
tab_box->delayedShow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::CDEWalkThroughWindows( bool forward )
|
|
|
|
{
|
2005-05-04 12:19:00 +00:00
|
|
|
Client* c = activeClient();
|
2003-09-16 19:28:03 +00:00
|
|
|
Client* nc = c;
|
|
|
|
bool options_traverse_all;
|
|
|
|
{
|
|
|
|
KConfigGroupSaver saver( KGlobal::config(), "TabBox" );
|
|
|
|
options_traverse_all = KGlobal::config()->readNumEntry("TraverseAll", false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !forward )
|
|
|
|
{
|
2004-06-12 20:11:53 +00:00
|
|
|
do
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
nc = previousStaticClient(nc);
|
|
|
|
} while (nc && nc != c &&
|
2005-05-04 12:19:00 +00:00
|
|
|
(( !options_traverse_all && !nc->isOnDesktop(currentDesktop())) ||
|
|
|
|
nc->isMinimized() || !nc->wantsTabFocus() ) );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-12 20:11:53 +00:00
|
|
|
do
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
nc = nextStaticClient(nc);
|
|
|
|
} while (nc && nc != c &&
|
|
|
|
(( !options_traverse_all && !nc->isOnDesktop(currentDesktop())) ||
|
|
|
|
nc->isMinimized() || !nc->wantsTabFocus() ) );
|
|
|
|
}
|
|
|
|
if (c && c != nc)
|
|
|
|
lowerClient( c );
|
2004-06-12 20:11:53 +00:00
|
|
|
if (nc)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if ( options->focusPolicyIsReasonable() )
|
|
|
|
{
|
|
|
|
activateClient( nc );
|
|
|
|
if( nc->isShade())
|
2004-06-18 08:57:42 +00:00
|
|
|
nc->setShade( ShadeActivated );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !nc->isOnDesktop( currentDesktop()))
|
|
|
|
setCurrentDesktop( nc->desktop());
|
|
|
|
raiseClient( nc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::KDEOneStepThroughWindows( bool forward )
|
|
|
|
{
|
|
|
|
tab_box->setMode( TabBox::WindowsMode );
|
|
|
|
tab_box->reset();
|
|
|
|
tab_box->nextPrev( forward );
|
|
|
|
if( Client* c = tab_box->currentClient() )
|
|
|
|
{
|
|
|
|
activateClient( c );
|
|
|
|
if( c->isShade())
|
2004-06-18 08:57:42 +00:00
|
|
|
c->setShade( ShadeActivated );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::oneStepThroughDesktops( bool forward, int mode )
|
|
|
|
{
|
|
|
|
tab_box->setMode( (TabBox::Mode) mode );
|
|
|
|
tab_box->reset();
|
|
|
|
tab_box->nextPrev( forward );
|
|
|
|
if ( tab_box->currentDesktop() != -1 )
|
|
|
|
setCurrentDesktop( tab_box->currentDesktop() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::oneStepThroughDesktops( bool forward )
|
|
|
|
{
|
|
|
|
oneStepThroughDesktops( forward, TabBox::DesktopMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::oneStepThroughDesktopList( bool forward )
|
|
|
|
{
|
|
|
|
oneStepThroughDesktops( forward, TabBox::DesktopListMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Handles holding alt-tab / control-tab
|
|
|
|
*/
|
|
|
|
void Workspace::tabBoxKeyPress( const KKeyNative& keyX )
|
|
|
|
{
|
|
|
|
bool forward = false;
|
|
|
|
bool backward = false;
|
|
|
|
|
|
|
|
if (tab_grab)
|
|
|
|
{
|
|
|
|
forward = cutWalkThroughWindows.contains( keyX );
|
|
|
|
backward = cutWalkThroughWindowsReverse.contains( keyX );
|
|
|
|
if (forward || backward)
|
|
|
|
{
|
|
|
|
kdDebug(125) << "== " << cutWalkThroughWindows.toStringInternal()
|
|
|
|
<< " or " << cutWalkThroughWindowsReverse.toStringInternal() << endl;
|
|
|
|
KDEWalkThroughWindows( forward );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (control_grab)
|
|
|
|
{
|
|
|
|
forward = cutWalkThroughDesktops.contains( keyX ) ||
|
|
|
|
cutWalkThroughDesktopList.contains( keyX );
|
|
|
|
backward = cutWalkThroughDesktopsReverse.contains( keyX ) ||
|
|
|
|
cutWalkThroughDesktopListReverse.contains( keyX );
|
|
|
|
if (forward || backward)
|
|
|
|
walkThroughDesktops(forward);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (control_grab || tab_grab)
|
|
|
|
{
|
|
|
|
uint keyQt = keyX.keyCodeQt();
|
|
|
|
if ( ((keyQt & 0xffff) == Qt::Key_Escape)
|
|
|
|
&& !(forward || backward) )
|
|
|
|
{ // if Escape is part of the shortcut, don't cancel
|
2004-02-10 09:24:57 +00:00
|
|
|
closeTabBox();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-10 09:24:57 +00:00
|
|
|
void Workspace::closeTabBox()
|
|
|
|
{
|
|
|
|
removeTabBoxGrab();
|
|
|
|
tab_box->hide();
|
|
|
|
keys->setEnabled( true );
|
2005-01-10 09:56:21 +00:00
|
|
|
client_keys->setEnabled( true );
|
2004-02-10 09:24:57 +00:00
|
|
|
tab_grab = FALSE;
|
|
|
|
control_grab = FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
/*!
|
|
|
|
Handles alt-tab / control-tab releasing
|
|
|
|
*/
|
|
|
|
void Workspace::tabBoxKeyRelease( const XKeyEvent& ev )
|
|
|
|
{
|
|
|
|
unsigned int mk = ev.state &
|
|
|
|
(KKeyNative::modX(KKey::SHIFT) |
|
|
|
|
KKeyNative::modX(KKey::CTRL) |
|
|
|
|
KKeyNative::modX(KKey::ALT) |
|
|
|
|
KKeyNative::modX(KKey::WIN));
|
|
|
|
// 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;
|
|
|
|
for( int i = ShiftMapIndex;
|
|
|
|
i <= Mod5MapIndex;
|
|
|
|
++i )
|
2004-06-12 20:11:53 +00:00
|
|
|
if(( mk & ( 1 << i )) != 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if( mod_index >= 0 )
|
|
|
|
return;
|
|
|
|
mod_index = i;
|
|
|
|
}
|
|
|
|
bool release = false;
|
|
|
|
if( mod_index == -1 )
|
|
|
|
release = true;
|
2004-06-12 20:11:53 +00:00
|
|
|
else
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
XModifierKeymap* xmk = XGetModifierMapping(qt_xdisplay());
|
|
|
|
for (int i=0; i<xmk->max_keypermod; i++)
|
|
|
|
if (xmk->modifiermap[xmk->max_keypermod * mod_index + i]
|
|
|
|
== ev.keycode)
|
|
|
|
release = true;
|
|
|
|
XFreeModifiermap(xmk);
|
|
|
|
}
|
|
|
|
if( !release )
|
|
|
|
return;
|
|
|
|
if (tab_grab)
|
|
|
|
{
|
2004-02-10 09:24:57 +00:00
|
|
|
removeTabBoxGrab();
|
2003-09-16 19:28:03 +00:00
|
|
|
tab_box->hide();
|
|
|
|
keys->setEnabled( true );
|
2005-01-10 09:56:21 +00:00
|
|
|
client_keys->setEnabled( true );
|
2003-09-16 19:28:03 +00:00
|
|
|
tab_grab = false;
|
|
|
|
if( Client* c = tab_box->currentClient())
|
|
|
|
{
|
|
|
|
activateClient( c );
|
|
|
|
if( c->isShade())
|
2004-06-18 08:57:42 +00:00
|
|
|
c->setShade( ShadeActivated );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (control_grab)
|
|
|
|
{
|
2004-02-10 09:24:57 +00:00
|
|
|
removeTabBoxGrab();
|
2003-09-16 19:28:03 +00:00
|
|
|
tab_box->hide();
|
|
|
|
keys->setEnabled( true );
|
2005-01-10 09:56:21 +00:00
|
|
|
client_keys->setEnabled( true );
|
2003-09-16 19:28:03 +00:00
|
|
|
control_grab = False;
|
2004-06-12 20:11:53 +00:00
|
|
|
if ( tab_box->currentDesktop() != -1 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
setCurrentDesktop( tab_box->currentDesktop() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Workspace::nextDesktopFocusChain( int iDesktop ) const
|
|
|
|
{
|
|
|
|
int i = desktop_focus_chain.find( iDesktop );
|
|
|
|
if( i >= 0 && i+1 < (int)desktop_focus_chain.size() )
|
|
|
|
return desktop_focus_chain[i+1];
|
|
|
|
else if( desktop_focus_chain.size() > 0 )
|
|
|
|
return desktop_focus_chain[ 0 ];
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Workspace::previousDesktopFocusChain( int iDesktop ) const
|
|
|
|
{
|
|
|
|
int i = desktop_focus_chain.find( iDesktop );
|
|
|
|
if( i-1 >= 0 )
|
|
|
|
return desktop_focus_chain[i-1];
|
|
|
|
else if( desktop_focus_chain.size() > 0 )
|
|
|
|
return desktop_focus_chain[desktop_focus_chain.size()-1];
|
|
|
|
else
|
|
|
|
return numberOfDesktops();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
auxiliary functions to travers all clients according the focus
|
2004-06-12 20:11:53 +00:00
|
|
|
order. Useful for kwms Alt-tab feature.
|
2003-09-16 19:28:03 +00:00
|
|
|
*/
|
|
|
|
Client* Workspace::nextFocusChainClient( Client* c ) const
|
|
|
|
{
|
|
|
|
if ( focus_chain.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
ClientList::ConstIterator it = focus_chain.find( c );
|
|
|
|
if ( it == focus_chain.end() )
|
|
|
|
return focus_chain.last();
|
|
|
|
if ( it == focus_chain.begin() )
|
|
|
|
return focus_chain.last();
|
|
|
|
--it;
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
auxiliary functions to travers all clients according the focus
|
2004-06-12 20:11:53 +00:00
|
|
|
order. Useful for kwms Alt-tab feature.
|
2003-09-16 19:28:03 +00:00
|
|
|
*/
|
|
|
|
Client* Workspace::previousFocusChainClient( Client* c ) const
|
|
|
|
{
|
|
|
|
if ( focus_chain.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
ClientList::ConstIterator it = focus_chain.find( c );
|
|
|
|
if ( it == focus_chain.end() )
|
|
|
|
return focus_chain.first();
|
|
|
|
++it;
|
|
|
|
if ( it == focus_chain.end() )
|
|
|
|
return focus_chain.first();
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
auxiliary functions to travers all clients according the static
|
|
|
|
order. Useful for the CDE-style Alt-tab feature.
|
|
|
|
*/
|
|
|
|
Client* Workspace::nextStaticClient( Client* c ) const
|
|
|
|
{
|
|
|
|
if ( !c || clients.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
ClientList::ConstIterator it = clients.find( c );
|
|
|
|
if ( it == clients.end() )
|
|
|
|
return clients.first();
|
|
|
|
++it;
|
|
|
|
if ( it == clients.end() )
|
|
|
|
return clients.first();
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
/*!
|
|
|
|
auxiliary functions to travers all clients according the static
|
|
|
|
order. Useful for the CDE-style Alt-tab feature.
|
|
|
|
*/
|
|
|
|
Client* Workspace::previousStaticClient( Client* c ) const
|
|
|
|
{
|
|
|
|
if ( !c || clients.isEmpty() )
|
|
|
|
return 0;
|
|
|
|
ClientList::ConstIterator it = clients.find( c );
|
|
|
|
if ( it == clients.end() )
|
|
|
|
return clients.last();
|
|
|
|
if ( it == clients.begin() )
|
|
|
|
return clients.last();
|
|
|
|
--it;
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2004-02-10 09:24:57 +00:00
|
|
|
bool Workspace::establishTabBoxGrab()
|
|
|
|
{
|
|
|
|
if( XGrabKeyboard( qt_xdisplay(), root, FALSE,
|
|
|
|
GrabModeAsync, GrabModeAsync, qt_x_time) != GrabSuccess )
|
|
|
|
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.
|
|
|
|
assert( !forced_global_mouse_grab );
|
|
|
|
forced_global_mouse_grab = true;
|
|
|
|
if( active_client != NULL )
|
|
|
|
active_client->updateMouseGrab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Workspace::removeTabBoxGrab()
|
|
|
|
{
|
|
|
|
XUngrabKeyboard(qt_xdisplay(), qt_x_time);
|
|
|
|
assert( forced_global_mouse_grab );
|
|
|
|
forced_global_mouse_grab = false;
|
|
|
|
if( active_client != NULL )
|
|
|
|
active_client->updateMouseGrab();
|
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
} // namespace
|
2000-05-14 01:58:13 +00:00
|
|
|
|
2000-06-09 00:20:21 +00:00
|
|
|
#include "tabbox.moc"
|