2000-03-24 22:23:02 +00:00
|
|
|
/*****************************************************************
|
|
|
|
kwin - the KDE window manager
|
2000-06-08 17:05:51 +00:00
|
|
|
|
2000-03-24 22:23:02 +00:00
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
******************************************************************/
|
2000-06-08 17:05:51 +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>
|
2000-05-14 01:58:13 +00:00
|
|
|
#undef Bool // f**king X11
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kconfig.h>
|
2000-06-01 05:32:06 +00:00
|
|
|
#include <klocale.h>
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
const bool options_traverse_all = FALSE; // TODO
|
|
|
|
|
1999-11-25 12:53:17 +00:00
|
|
|
TabBox::TabBox( Workspace *ws, const char *name )
|
1999-08-19 23:26:42 +00:00
|
|
|
: QWidget( 0, name, WStyle_Customize | WStyle_NoBorder )
|
|
|
|
{
|
2000-06-01 05:32:06 +00:00
|
|
|
no_tasks = i18n("*** No Tasks ***");
|
1999-08-19 23:26:42 +00:00
|
|
|
wspace = ws;
|
|
|
|
reset();
|
2000-05-14 01:58:13 +00:00
|
|
|
connect(&delayedShowTimer, SIGNAL(timeout()), this, SLOT(show()));
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TabBox::~TabBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Sets the current mode to \a mode, either DesktopMode or WindowsMode
|
|
|
|
|
|
|
|
\sa mode()
|
|
|
|
*/
|
|
|
|
void TabBox::setMode( Mode mode )
|
|
|
|
{
|
|
|
|
m = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Resets the tab box to display the active client in WindowsMode, or the
|
|
|
|
current desktop in DesktopMode
|
|
|
|
*/
|
|
|
|
void TabBox::reset()
|
|
|
|
{
|
|
|
|
QFont f = font();
|
|
|
|
f.setBold( TRUE );
|
|
|
|
f.setPointSize( 14 );
|
|
|
|
setFont( f );
|
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
wmax = 0;
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
if ( mode() == WindowsMode ) {
|
|
|
|
client = workspace()->activeClient();
|
1999-11-26 22:10:25 +00:00
|
|
|
clients.clear();
|
|
|
|
Client* c = workspace()->nextClient( client );
|
|
|
|
Client* stop = c;
|
|
|
|
QFontMetrics fm( fontMetrics() );
|
2000-06-01 05:32:06 +00:00
|
|
|
int cw = fm.width(no_tasks)+20;
|
1999-11-26 22:10:25 +00:00
|
|
|
while ( c ) {
|
1999-11-28 20:10:58 +00:00
|
|
|
if ( (options_traverse_all ||c->isOnDesktop(workspace()->currentDesktop()))
|
|
|
|
&& (!c->isIconified() || c->mainClient() == c ) ) {
|
1999-11-26 22:10:25 +00:00
|
|
|
if ( client == c )
|
|
|
|
clients.prepend( c );
|
|
|
|
else
|
|
|
|
clients += c;
|
|
|
|
cw = fm.width( c->caption() ) + 40;
|
|
|
|
if ( cw > wmax )
|
|
|
|
wmax = cw;
|
|
|
|
}
|
|
|
|
c = workspace()->nextClient( c );
|
|
|
|
if ( c == stop )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wmax = QMAX( wmax, int(clients.count())*20 );
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
else { // DesktopMode
|
1999-11-26 22:10:25 +00:00
|
|
|
desk = workspace()->currentDesktop();
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
int w = QMAX( wmax + 20, qApp->desktop()->width()/3 );
|
|
|
|
setGeometry( (qApp->desktop()->width()-w)/2,
|
|
|
|
qApp->desktop()->height()/2-fontMetrics().height()*2-10,
|
|
|
|
w, fontMetrics().height()*4 + 20 );
|
|
|
|
wmax = QMIN( wmax, width() - 12 );
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Shows the next or previous item, depending on \a next
|
|
|
|
*/
|
|
|
|
void TabBox::nextPrev( bool next)
|
|
|
|
{
|
|
|
|
if ( mode() == WindowsMode ) {
|
2000-06-01 05:32:06 +00:00
|
|
|
Client* firstClient = 0;
|
1999-08-19 23:26:42 +00:00
|
|
|
do {
|
|
|
|
if ( next )
|
|
|
|
client = workspace()->nextClient(client);
|
|
|
|
else
|
|
|
|
client = workspace()->previousClient(client);
|
2000-06-01 05:32:06 +00:00
|
|
|
if (!firstClient) {
|
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.
|
|
|
|
firstClient = client;
|
|
|
|
}
|
|
|
|
else if (client == firstClient) {
|
|
|
|
// No candidates found.
|
|
|
|
client = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (client &&
|
2000-03-24 22:23:02 +00:00
|
|
|
(( !options_traverse_all &&
|
|
|
|
!client->isOnDesktop(workspace()->currentDesktop()) ) ||
|
|
|
|
( client->isIconified() && client->mainClient() != client ))
|
1999-11-28 20:10:58 +00:00
|
|
|
);
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
|
|
|
|
if (!options_traverse_all && client
|
|
|
|
&& !client->isOnDesktop(workspace()->currentDesktop()))
|
|
|
|
client = 0;
|
|
|
|
}
|
|
|
|
else { // DesktopMode
|
|
|
|
if ( next ) {
|
|
|
|
desk++;
|
1999-11-26 22:10:25 +00:00
|
|
|
if ( desk > workspace()->numberOfDesktops() )
|
1999-08-19 23:26:42 +00:00
|
|
|
desk = 1;
|
|
|
|
} else {
|
|
|
|
desk--;
|
|
|
|
if ( desk < 1 )
|
1999-11-26 22:10:25 +00:00
|
|
|
desk = workspace()->numberOfDesktops();
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
paintContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the currently displayed client ( only works in WindowsMode ).
|
|
|
|
Returns 0 if no client is displayed.
|
|
|
|
*/
|
|
|
|
Client* TabBox::currentClient()
|
|
|
|
{
|
|
|
|
if ( mode() != WindowsMode )
|
|
|
|
return 0;
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the currently displayed virtual desktop ( only works in
|
|
|
|
DesktopMode )
|
|
|
|
Returns -1 if no desktop is displayed.
|
|
|
|
*/
|
|
|
|
int TabBox::currentDesktop()
|
|
|
|
{
|
|
|
|
if ( mode() != DesktopMode )
|
|
|
|
return -1;
|
|
|
|
return desk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Reimplemented to raise the tab box as well
|
|
|
|
*/
|
|
|
|
void TabBox::showEvent( QShowEvent* )
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
/*!
|
|
|
|
hide the icon box if necessary
|
|
|
|
*/
|
|
|
|
void TabBox::hideEvent( QHideEvent* )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
/*!
|
|
|
|
Paints the tab box
|
|
|
|
*/
|
|
|
|
void TabBox::paintEvent( QPaintEvent* )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QPainter p( this );
|
|
|
|
style().drawPanel( &p, 0, 0, width(), height(), colorGroup(), FALSE );
|
|
|
|
style().drawPanel( &p, 4, 4, width()-8, height()-8, colorGroup(), TRUE );
|
|
|
|
}
|
|
|
|
paintContents();
|
|
|
|
}
|
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
/*!
|
|
|
|
Paints the contents of the tab box. Used in paintEvent() and
|
|
|
|
whenever the contents changes.
|
|
|
|
*/
|
|
|
|
void TabBox::paintContents()
|
|
|
|
{
|
1999-11-26 22:10:25 +00:00
|
|
|
extern QPixmap* kwin_get_menu_pix_hack();
|
|
|
|
QPixmap* menu_pix = kwin_get_menu_pix_hack();
|
1999-08-19 23:26:42 +00:00
|
|
|
QPainter p( this );
|
1999-11-26 22:10:25 +00:00
|
|
|
QRect r( 6, 6, width()-12, height()-32 );
|
1999-08-19 23:26:42 +00:00
|
|
|
p.fillRect( r, colorGroup().brush( QColorGroup::Background ) );
|
|
|
|
if ( mode () == WindowsMode ) {
|
|
|
|
if ( currentClient() ) {
|
|
|
|
QString s;
|
|
|
|
if (!client->isOnDesktop(workspace()->currentDesktop())){
|
|
|
|
s.append(": ");
|
|
|
|
}
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
if (client->isIconified())
|
|
|
|
s += QString("(")+client->caption()+")";
|
|
|
|
else
|
|
|
|
s += client->caption();
|
1999-11-26 22:10:25 +00:00
|
|
|
int textw = fontMetrics().width( s );
|
|
|
|
r.setLeft( r.left() + (r.width() - textw)/2);
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
if ( !client->icon().isNull() ) {
|
|
|
|
int py = r.center().y() - 16;
|
|
|
|
r.setLeft( r.left() + 20 );
|
|
|
|
p.drawPixmap( r.left()-42, py, client->icon() );
|
|
|
|
}
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
p.drawText( r, AlignVCenter, s );
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-11-26 22:10:25 +00:00
|
|
|
r.setBottom( r.bottom() + 20 );
|
2000-06-01 05:32:06 +00:00
|
|
|
p.drawText( r, AlignCenter, no_tasks);
|
1999-11-26 22:10:25 +00:00
|
|
|
}
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-11-26 22:10:25 +00:00
|
|
|
int x = (width() - clients.count() * 20 )/2;
|
|
|
|
int y = height() - 26;
|
|
|
|
for ( ClientList::ConstIterator it = clients.begin(); it != clients.end(); ++it) {
|
|
|
|
if ( workspace()->hasClient( *it ) ) { // safety
|
1999-11-29 02:06:41 +00:00
|
|
|
p.save();
|
1999-11-26 22:10:25 +00:00
|
|
|
if ( !(*it)->miniIcon().isNull() )
|
|
|
|
p.drawPixmap( x, y, (*it)->miniIcon() );
|
|
|
|
else if ( menu_pix )
|
|
|
|
p.drawPixmap( x, y, *menu_pix );
|
|
|
|
p.setPen( (*it)==currentClient()?
|
|
|
|
colorGroup().highlight():colorGroup().background() );
|
|
|
|
p.drawRect( x-2, y-2, 20, 20 );
|
1999-11-29 02:06:41 +00:00
|
|
|
p.setPen( colorGroup().foreground() );
|
1999-11-26 22:10:25 +00:00
|
|
|
x += 20;
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
} else { // DesktopMode
|
2000-07-14 19:56:47 +00:00
|
|
|
p.drawText( r, AlignCenter, workspace()->desktopName(desk) );
|
1999-11-26 22:10:25 +00:00
|
|
|
int x = (width() - workspace()->numberOfDesktops() * 20 )/2;
|
|
|
|
int y = height() - 26;
|
|
|
|
QFont f( font() );
|
|
|
|
f.setPointSize( 12 );
|
|
|
|
f.setBold( FALSE );
|
|
|
|
p.setFont(f );
|
|
|
|
for ( int i = 1; i <= workspace()->numberOfDesktops(); i++ ) {
|
|
|
|
p.setPen( i == desk?
|
|
|
|
colorGroup().highlight():colorGroup().background() );
|
|
|
|
p.drawRect( x-2, y-2, 20, 20 );
|
|
|
|
qDrawWinPanel( &p, QRect( x, y, 16, 16), colorGroup(), FALSE,
|
|
|
|
&colorGroup().brush(QColorGroup::Base ) );
|
|
|
|
p.setPen( colorGroup().text() );
|
|
|
|
p.drawText( x, y, 16, 16, AlignCenter, QString::number(i) );
|
|
|
|
x += 20;
|
|
|
|
}
|
1999-08-19 23:26:42 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-14 01:58:13 +00:00
|
|
|
|
2000-07-08 11:57:38 +00:00
|
|
|
void TabBox::hide()
|
2000-05-14 01:58:13 +00:00
|
|
|
{
|
2000-07-08 11:57:38 +00:00
|
|
|
delayedShowTimer.stop();
|
|
|
|
QWidget::hide();
|
|
|
|
QApplication::syncX();
|
|
|
|
XEvent otherEvent;
|
|
|
|
while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) )
|
|
|
|
;
|
2000-05-14 01:58:13 +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()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2000-07-08 11:57:38 +00:00
|
|
|
if (!delay) {
|
|
|
|
show();
|
|
|
|
return;
|
|
|
|
}
|
2000-05-14 01:58:13 +00:00
|
|
|
|
2000-07-16 10:20:29 +00:00
|
|
|
int delayTime = c->readNumEntry("DelayTime", 75);
|
2000-07-08 11:57:38 +00:00
|
|
|
delayedShowTimer.start(delayTime, true);
|
2000-05-14 01:58:13 +00:00
|
|
|
}
|
|
|
|
|
2000-06-09 00:20:21 +00:00
|
|
|
#include "tabbox.moc"
|