Adding titlebar button autoshow/autohide when the title width
increases/decreases. This makes small apps like the GIMP look much better, and allows small windows to be shrunk much smaller than previously allowed. svn path=/trunk/kdebase/kwin/; revision=93712icc-effect-5.14.5
parent
5e2c5ec7be
commit
09141d02c3
|
@ -700,12 +700,6 @@ IceWMClient::IceWMClient( Workspace *ws, WId w, QWidget *parent, const char *nam
|
||||||
grid->addLayout ( hb, 1, 1 );
|
grid->addLayout ( hb, 1, 1 );
|
||||||
else
|
else
|
||||||
grid->addLayout ( hb, 2, 1 );
|
grid->addLayout ( hb, 2, 1 );
|
||||||
|
|
||||||
// Hide buttons which are not required
|
|
||||||
if ( !isMinimizable() && button[BtnMinimize] )
|
|
||||||
button[BtnMinimize]->hide();
|
|
||||||
if ( !isMaximizable() && button[BtnMaximize] )
|
|
||||||
button[BtnMaximize]->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -755,7 +749,7 @@ void IceWMClient::addClientButtons( const QString& s )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if ( validPixmaps(maximizePix) && !button[BtnMaximize] )
|
if ( validPixmaps(maximizePix) && !button[BtnMaximize] && isMaximizable() )
|
||||||
{
|
{
|
||||||
button[BtnMaximize] = new IceWMButton(this, "maximize", &maximizePix);
|
button[BtnMaximize] = new IceWMButton(this, "maximize", &maximizePix);
|
||||||
hb->addWidget( button[BtnMaximize] );
|
hb->addWidget( button[BtnMaximize] );
|
||||||
|
@ -764,7 +758,7 @@ void IceWMClient::addClientButtons( const QString& s )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
if ( validPixmaps(minimizePix) && !button[BtnMinimize] )
|
if ( validPixmaps(minimizePix) && !button[BtnMinimize] && isMinimizable() )
|
||||||
{
|
{
|
||||||
button[BtnMinimize] = new IceWMButton(this, "minimize", &minimizePix);
|
button[BtnMinimize] = new IceWMButton(this, "minimize", &minimizePix);
|
||||||
hb->addWidget( button[BtnMinimize] );
|
hb->addWidget( button[BtnMinimize] );
|
||||||
|
@ -772,13 +766,13 @@ void IceWMClient::addClientButtons( const QString& s )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Not yet implemented - how's hide useful anyway?
|
/* Not yet implemented - how's hide useful anyway?
|
||||||
// case 'h':
|
case 'h':
|
||||||
// if ( button[BtnHide] && !button[BtnHide] )
|
if ( button[BtnHide] && !button[BtnHide] )
|
||||||
// hb->addWidget( button[BtnHide] );
|
hb->addWidget( button[BtnHide] );
|
||||||
// break;
|
break; */
|
||||||
|
|
||||||
/* Re-enable this when kwin has void shadeChange(bool s) in clients.cpp
|
/* Re-enable this when kwin has void shadeChange(bool s) in clients.cpp
|
||||||
case 'r':
|
case 'r':
|
||||||
// NOTE: kwin doesn't have toggleShade() in clients.h !
|
// NOTE: kwin doesn't have toggleShade() in clients.h !
|
||||||
if ( validPixmaps(rollupPix) && !button[BtnRollup] )
|
if ( validPixmaps(rollupPix) && !button[BtnRollup] )
|
||||||
|
@ -872,6 +866,7 @@ int IceWMClient::titleTextWidth( const QString& s )
|
||||||
void IceWMClient::resizeEvent( QResizeEvent* e )
|
void IceWMClient::resizeEvent( QResizeEvent* e )
|
||||||
{
|
{
|
||||||
Client::resizeEvent( e );
|
Client::resizeEvent( e );
|
||||||
|
calcHiddenButtons();
|
||||||
|
|
||||||
if (isVisibleToTLW())
|
if (isVisibleToTLW())
|
||||||
{
|
{
|
||||||
|
@ -1098,6 +1093,7 @@ void IceWMClient::paintEvent( QPaintEvent* )
|
||||||
|
|
||||||
void IceWMClient::showEvent(QShowEvent *ev)
|
void IceWMClient::showEvent(QShowEvent *ev)
|
||||||
{
|
{
|
||||||
|
calcHiddenButtons();
|
||||||
titlebar->changeSize( titleTextWidth(caption()), titleBarHeight,
|
titlebar->changeSize( titleTextWidth(caption()), titleBarHeight,
|
||||||
QSizePolicy::Preferred, QSizePolicy::Fixed );
|
QSizePolicy::Preferred, QSizePolicy::Fixed );
|
||||||
grid->activate();
|
grid->activate();
|
||||||
|
@ -1134,7 +1130,7 @@ void IceWMClient::iconChange()
|
||||||
// Please don't modify the following unless you want layout problems
|
// Please don't modify the following unless you want layout problems
|
||||||
void IceWMClient::captionChange( const QString& s )
|
void IceWMClient::captionChange( const QString& s )
|
||||||
{
|
{
|
||||||
QRect r( borderSizeX, borderSizeY, geometry().width()-(2*borderSizeX),
|
QRect r( 0, borderSizeY, geometry().width(),
|
||||||
titleBarHeight);
|
titleBarHeight);
|
||||||
|
|
||||||
titlebar->changeSize( titleTextWidth(s), titleBarHeight,
|
titlebar->changeSize( titleTextWidth(s), titleBarHeight,
|
||||||
|
@ -1174,6 +1170,47 @@ void IceWMClient::activeChange(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This does the showing / hiding button magic
|
||||||
|
// for variable positioned buttons.
|
||||||
|
void IceWMClient::calcHiddenButtons()
|
||||||
|
{
|
||||||
|
const int minwidth = 220; // Minimum width where all buttons are shown
|
||||||
|
const int btn_width = 20; // Average width
|
||||||
|
|
||||||
|
// Show/Hide buttons in this order - Sticky, Maximize, Menu, Minimize, Close.
|
||||||
|
IceWMButton* btnArray[] = { button[BtnDepth], button[BtnMaximize], button[BtnSysMenu],
|
||||||
|
button[BtnMinimize], button[BtnClose] };
|
||||||
|
|
||||||
|
int current_width = width();
|
||||||
|
int count = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Find out how many buttons we have to hide.
|
||||||
|
while (current_width < minwidth)
|
||||||
|
{
|
||||||
|
current_width += btn_width;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bound the number of buttons to hide
|
||||||
|
if (count > 5) count = 5;
|
||||||
|
|
||||||
|
// Hide the required buttons...
|
||||||
|
for(i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
if (btnArray[i] && btnArray[i]->isVisible() )
|
||||||
|
btnArray[i]->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the rest of the buttons...
|
||||||
|
for(i = count; i < 5; i++)
|
||||||
|
{
|
||||||
|
if (btnArray[i] && (!btnArray[i]->isVisible()) )
|
||||||
|
btnArray[i]->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Mouse position code modified from that in workspace.cpp
|
// Mouse position code modified from that in workspace.cpp
|
||||||
Client::MousePosition IceWMClient::mousePosition( const QPoint& p ) const
|
Client::MousePosition IceWMClient::mousePosition( const QPoint& p ) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,8 +95,6 @@ class IceWMClient : public KWinInternal::Client
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
// These are all the icewm button types :)
|
|
||||||
enum Buttons{ BtnSysMenu=0, BtnClose, BtnMaximize, BtnMinimize, BtnHide, BtnRollup, BtnDepth, BtnCount };
|
|
||||||
IceWMClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 );
|
IceWMClient( Workspace *ws, WId w, QWidget *parent=0, const char *name=0 );
|
||||||
~IceWMClient();
|
~IceWMClient();
|
||||||
|
|
||||||
|
@ -118,6 +116,10 @@ class IceWMClient : public KWinInternal::Client
|
||||||
void menuButtonPressed();
|
void menuButtonPressed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// These are all the icewm button types :)
|
||||||
|
enum Buttons{ BtnSysMenu=0, BtnClose, BtnMaximize, BtnMinimize, BtnHide, BtnRollup, BtnDepth, BtnCount };
|
||||||
|
|
||||||
|
void calcHiddenButtons();
|
||||||
int titleTextWidth( const QString& s );
|
int titleTextWidth( const QString& s );
|
||||||
void addClientButtons( const QString& s );
|
void addClientButtons( const QString& s );
|
||||||
QSpacerItem* addPixmapSpacer( QPixmap* p[], QSizePolicy::SizeType = QSizePolicy::Maximum,
|
QSpacerItem* addPixmapSpacer( QPixmap* p[], QSizePolicy::SizeType = QSizePolicy::Maximum,
|
||||||
|
|
Loading…
Reference in New Issue