add more spacing
[personal-kdebase.git] / workspace / kwin / clients / laptop / laptopclient.cpp
blob224847fcbcf0e59fb2517192ffefcf49d20bd29d
1 /********************************************************************
2 Laptop KWin Decoration
4 Copyright (c) 2005 Sandro Giessl <sandro@giessl.com>
5 Port of this decoration to KDE 3.2, accessibility enhancement are
6 Copyright (c) 2003 Luciano Montanaro <mikelima@cirulla.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include <kconfig.h> // up here to avoid X11 header conflict :P
23 #include "laptopclient.h"
24 #include <QPixmap>
25 #include <QPaintEvent>
26 #include <QBitmap>
27 #include <QPainter>
28 #include <kglobal.h>
29 #include <klocale.h>
31 namespace Laptop {
33 static const unsigned char iconify_bits[] = {
34 0xff, 0xff, 0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18};
36 static const unsigned char close_bits[] = {
37 0x42, 0xe7, 0x7e, 0x3c, 0x3c, 0x7e, 0xe7, 0x42};
39 static const unsigned char maximize_bits[] = {
40 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0xff, 0xff };
42 static const unsigned char r_minmax_bits[] = {
43 0x0c, 0x18, 0x33, 0x67, 0xcf, 0x9f, 0x3f, 0x3f};
45 static const unsigned char l_minmax_bits[] = {
46 0x30, 0x18, 0xcc, 0xe6, 0xf3, 0xf9, 0xfc, 0xfc};
48 static const unsigned char question_bits[] = {
49 0x3c, 0x66, 0x60, 0x30, 0x18, 0x00, 0x18, 0x18};
51 static const unsigned char unsticky_bits[] = {
52 0x3c, 0x42, 0x99, 0xbd, 0xbd, 0x99, 0x42, 0x3c};
54 static const unsigned char sticky_bits[] = {
55 0x3c, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3c};
57 static QPixmap *titlePix;
58 static QPixmap *aUpperGradient;
59 static QPixmap *iUpperGradient;
60 // buttons active, inactive, up, down, and 2 sizes :P
61 static QPixmap *btnPix1;
62 static QPixmap *iBtnPix1;
63 static QPixmap *btnDownPix1;
64 static QPixmap *iBtnDownPix1;
65 static QPixmap *btnPix2;
66 static QPixmap *btnDownPix2;
67 static QPixmap *iBtnPix2;
68 static QPixmap *iBtnDownPix2;
69 static QColor btnForeground;
71 static int titleHeight = 14;
72 static int btnWidth1 = 17;
73 static int btnWidth2 = 27;
75 static int handleSize = 8; // the resize handle size in pixels
77 static bool pixmaps_created = false;
79 // =====================================
81 extern "C" KDE_EXPORT KDecorationFactory* create_factory()
83 return new Laptop::LaptopClientFactory();
86 // =====================================
88 static inline const KDecorationOptions* options()
90 return KDecoration::options();
93 static void gradientFill(QPixmap *pixmap, const QColor &color1, const QColor &color2, bool diagonal = false)
95 QPainter p(pixmap);
96 QLinearGradient gradient(0, 0, diagonal ? pixmap->width() : 0, pixmap->height());
97 gradient.setColorAt(0.0, color1);
98 gradient.setColorAt(1.0, color2);
99 QBrush brush(gradient);
100 p.fillRect(pixmap->rect(), brush);
103 static void drawButtonFrame(QPixmap *pix, const QPalette &g, bool sunken)
105 QPainter p;
106 int w = pix->width();
107 int h = pix->height();
108 int x2 = w-1;
109 int y2 = h-1;
110 p.begin(pix);
112 if(sunken){
113 qDrawShadePanel(&p, 0, 0, w, h, g, true, 2);
115 else{
116 p.setPen(g.color(QPalette::Dark ));
117 p.drawRect(0, 0, w-1, h-1);
118 p.setPen(g.color(QPalette::Light));
119 p.drawLine(x2, 0, x2, y2);
120 p.drawLine(0, y2, x2, y2);
121 p.drawLine(1, 1, x2-2, 1);
122 p.drawLine(1, 1, 1, y2-2);
123 p.end();
127 static void create_pixmaps()
129 if(pixmaps_created)
130 return;
131 pixmaps_created = true;
133 titleHeight = QFontMetrics(options()->font(true)).height();
134 if (titleHeight < handleSize) titleHeight = handleSize;
135 titleHeight &= ~1; // Make title height even
136 if (titleHeight < 14) titleHeight = 14;
138 btnWidth1 = titleHeight + 3;
139 btnWidth2 = 3*titleHeight/2 + 6;
141 // titlebar
142 QPainter p;
143 QPainter maskPainter;
144 int i, x, y;
145 titlePix = new QPixmap(33, 12);
146 QBitmap mask(33, 12);
147 mask.fill(Qt::color0);
149 p.begin(titlePix);
150 maskPainter.begin(&mask);
151 maskPainter.setPen(Qt::color1);
152 for(i=0, y=2; i < 3; ++i, y+=4){
153 for(x=1; x <= 33; x+=3){
154 p.setPen(options()->color(KDecoration::ColorTitleBar, true).light(150));
155 p.drawPoint(x, y);
156 maskPainter.drawPoint(x, y);
157 p.setPen(options()->color(KDecoration::ColorTitleBar, true).dark(150));
158 p.drawPoint(x+1, y+1);
159 maskPainter.drawPoint(x+1, y+1);
162 p.end();
163 maskPainter.end();
164 titlePix->setMask(mask);
166 if(QPixmap::defaultDepth() > 8){
167 aUpperGradient = new QPixmap(32, titleHeight+2);
168 iUpperGradient = new QPixmap(32, titleHeight+2);
169 QColor bgColor = options()->color(KDecoration::ColorTitleBar, true);
170 gradientFill(aUpperGradient, bgColor.light(120), bgColor.dark(120));
171 bgColor = options()->color(KDecoration::ColorTitleBar, false);
172 gradientFill(iUpperGradient, bgColor.light(120), bgColor.dark(120));
174 // buttons (active/inactive, sunken/unsunken, 2 sizes each)
175 QPalette g = options()->palette(KDecoration::ColorButtonBg, true);
176 g.setCurrentColorGroup( QPalette::Active );
177 QColor c = g.color( QPalette::Background );
178 btnPix1 = new QPixmap(btnWidth1, titleHeight);
179 btnDownPix1 = new QPixmap(btnWidth1, titleHeight);
180 btnPix2 = new QPixmap(btnWidth2, titleHeight);
181 btnDownPix2 = new QPixmap(btnWidth2, titleHeight);
182 iBtnPix1 = new QPixmap(btnWidth1, titleHeight);
183 iBtnDownPix1 = new QPixmap(btnWidth1, titleHeight);
184 iBtnPix2 = new QPixmap(btnWidth2, titleHeight);
185 iBtnDownPix2 = new QPixmap(btnWidth2, titleHeight);
186 if(QPixmap::defaultDepth() > 8){
187 gradientFill(btnPix1, c.light(120), c.dark(130), true);
188 gradientFill(btnPix2, c.light(120), c.dark(130), true);
189 gradientFill(btnDownPix1, c.light(120), c.dark(130), true);
190 gradientFill(btnDownPix2, c.light(120), c.dark(130), true);
191 g = options()->palette(KDecoration::ColorButtonBg, false);
192 g.setCurrentColorGroup( QPalette::Active );
193 c = g.color(QPalette::Background);
194 gradientFill(iBtnPix1, c.light(120), c.dark(130), true);
195 gradientFill(iBtnPix2, c.light(120), c.dark(130), true);
196 gradientFill(iBtnDownPix1, c.light(120), c.dark(130), true);
197 gradientFill(iBtnDownPix2, c.light(120), c.dark(130), true);
199 else{
200 btnPix1->fill(c.rgb());
201 btnDownPix1->fill(c.rgb());
202 btnPix2->fill(c.rgb());
203 btnDownPix2->fill(c.rgb());
204 g = options()->palette(KDecoration::ColorButtonBg, false);
205 g.setCurrentColorGroup( QPalette::Active );
206 c = g.background().color();
207 iBtnPix1->fill(c.rgb());
208 iBtnDownPix1->fill(c.rgb());
209 iBtnPix2->fill(c.rgb());
210 iBtnDownPix2->fill(c.rgb());
212 g = options()->palette(KDecoration::ColorButtonBg, true);
213 g.setCurrentColorGroup( QPalette::Active );
214 c = g.background().color();
215 drawButtonFrame(btnPix1, g, false);
216 drawButtonFrame(btnDownPix1, g, true);
217 drawButtonFrame(btnPix2, g, false);
218 drawButtonFrame(btnDownPix2, g, true);
219 g = options()->palette(KDecoration::ColorButtonBg, false);
220 g.setCurrentColorGroup( QPalette::Active );
221 c = g.background().color();
222 drawButtonFrame(iBtnPix1, g, false);
223 drawButtonFrame(iBtnDownPix1, g, true);
224 drawButtonFrame(iBtnPix2, g, false);
225 drawButtonFrame(iBtnDownPix2, g, true);
227 if(qGray(options()->color(KDecoration::ColorButtonBg, true).rgb()) > 128)
228 btnForeground = Qt::black;
229 else
230 btnForeground = Qt::white;
233 static void delete_pixmaps()
235 delete titlePix;
236 if(aUpperGradient){
237 delete aUpperGradient;
238 delete iUpperGradient;
239 delete btnPix1;
240 delete btnDownPix1;
241 delete iBtnPix1;
242 delete iBtnDownPix1;
243 delete btnPix2;
244 delete btnDownPix2;
245 delete iBtnPix2;
246 delete iBtnDownPix2;
248 pixmaps_created = false;
251 // =====================================
253 LaptopButton::LaptopButton(ButtonType type, LaptopClient *parent, const char *name)
254 : KCommonDecorationButton(type, parent)
256 setAttribute(Qt::WA_NoSystemBackground, true);
259 void LaptopButton::reset(unsigned long changed)
261 if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
262 switch (type() ) {
263 case CloseButton:
264 setBitmap(close_bits);
265 break;
266 case HelpButton:
267 setBitmap(question_bits);
268 break;
269 case MinButton:
270 setBitmap(iconify_bits);
271 break;
272 case MaxButton:
273 if (isChecked() ) {
274 setBitmap(isLeft() ? l_minmax_bits : r_minmax_bits);
275 } else {
276 setBitmap(maximize_bits);
278 break;
279 case OnAllDesktopsButton:
280 setBitmap( isChecked() ? unsticky_bits : sticky_bits );
281 break;
282 default:
283 setBitmap(0);
284 break;
287 this->update();
291 void LaptopButton::setBitmap(const unsigned char *bitmap)
293 if (bitmap)
294 deco = QBitmap::fromData( QSize(8, 8), bitmap);
295 else {
296 deco = QBitmap(8,8);
297 deco.fill(Qt::color0);
299 deco.setMask(deco);
300 repaint();
303 void LaptopButton::paintEvent(QPaintEvent *)
305 QPainter p(this);
306 drawButton(&p);
309 void LaptopButton::drawButton(QPainter *p)
311 bool smallBtn = width() == btnWidth1;
312 if(btnPix1){
313 if(decoration()->isActive()){
314 if(isDown())
315 p->drawPixmap(0, 0, smallBtn ? *btnDownPix1 : *btnDownPix2);
316 else
317 p->drawPixmap(0, 0, smallBtn ? *btnPix1 : *btnPix2);
319 else{
320 if(isDown())
321 p->drawPixmap(0, 0, smallBtn ? *iBtnDownPix1 : *iBtnDownPix2);
322 else
323 p->drawPixmap(0, 0, smallBtn ? *iBtnPix1 : *iBtnPix2);
326 else{
327 QPalette g = options()->palette(KDecoration::ColorButtonBg, decoration()->isActive());
328 g.setCurrentColorGroup( QPalette::Active );
329 int w = width();
330 int h = height();
331 p->fillRect(1, 1, w-2, h-2, isDown() ? g.color(QPalette::Mid) : g.color(QPalette::Button) );
332 p->setPen(isDown() ? g.color( QPalette::Dark ) : g.color( QPalette::Light ));
333 p->drawLine(0, 0, w-1, 0);
334 p->drawLine(0, 0, 0, w-1);
335 p->setPen(isDown() ? g.color( QPalette::Light ) : g.color( QPalette::Dark ));
336 p->drawLine(w-1, 0, w-1, h-1);
337 p->drawLine(0, h-1, w-1, h-1);
340 p->setPen(btnForeground);
341 int xOff = (width()-8)/2;
342 int yOff = (height()-8)/2;
343 p->drawPixmap(isDown() ? xOff+1: xOff, isDown() ? yOff+1 : yOff, deco);
346 // =====================================
348 void LaptopClient::reset(unsigned long changed)
350 KCommonDecoration::reset(changed);
353 LaptopClient::LaptopClient(KDecorationBridge *b, KDecorationFactory *f)
354 : KCommonDecoration(b, f)
358 LaptopClient::~LaptopClient()
362 QString LaptopClient::visibleName() const
364 return i18n("Laptop");
367 QString LaptopClient::defaultButtonsLeft() const
369 return "X";
372 QString LaptopClient::defaultButtonsRight() const
374 return "HSIA";
377 bool LaptopClient::decorationBehaviour(DecorationBehaviour behaviour) const
379 switch (behaviour) {
380 case DB_MenuClose:
381 return false;
383 case DB_WindowMask:
384 return true;
386 case DB_ButtonHide:
387 return true;
389 default:
390 return KCommonDecoration::decorationBehaviour(behaviour);
394 int LaptopClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
396 switch (lm) {
397 case LM_TitleEdgeLeft:
398 case LM_TitleEdgeRight:
399 case LM_BorderLeft:
400 case LM_BorderRight:
401 return 4;
403 case LM_BorderBottom:
404 return mustDrawHandle() ? handleSize : 4;
406 case LM_TitleEdgeTop:
407 return 3;
409 case LM_TitleEdgeBottom:
410 return 1;
412 case LM_TitleBorderLeft:
413 case LM_TitleBorderRight:
414 return 0;
416 case LM_ButtonWidth:
418 if (btn && (btn->type()==HelpButton||btn->type()==OnAllDesktopsButton) ) {
419 return btnWidth1;
420 } else {
421 return btnWidth2;
425 case LM_ButtonHeight:
426 case LM_TitleHeight:
427 if (isToolWindow() )
428 return titleHeight-2;
429 else
430 return titleHeight;
432 case LM_ButtonSpacing:
433 return 0;
435 default:
436 return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
440 KCommonDecorationButton *LaptopClient::createButton(ButtonType type)
442 switch (type) {
443 case OnAllDesktopsButton:
444 return new LaptopButton(OnAllDesktopsButton, this, "on_all_desktops");
446 case HelpButton:
447 return new LaptopButton(HelpButton, this, "help");
449 case MinButton:
450 return new LaptopButton(MinButton, this, "minimize");
452 case MaxButton:
453 return new LaptopButton(MaxButton, this, "maximize");
455 case CloseButton:
456 return new LaptopButton(CloseButton, this, "close");
458 default:
459 return 0;
463 void LaptopClient::init()
465 bufferDirty = true;
467 KCommonDecoration::init();
470 void LaptopClient::captionChange()
472 bufferDirty = true;
474 KCommonDecoration::captionChange();
477 void LaptopClient::paintEvent( QPaintEvent* )
479 QPainter p(widget());
480 QPalette g = options()->palette(KDecoration::ColorFrame, isActive());
481 g.setCurrentColorGroup( QPalette::Active );
483 QRect r(widget()->rect());
484 p.setPen(Qt::black);
485 p.drawRect(r.adjusted(0, 0, -1, -1));
487 // fill mid frame...
488 p.setPen(g.background().color());
489 p.drawLine(r.x()+2, r.y()+2, r.right()-2, r.y()+2);
490 p.drawLine(r.left()+2, r.y()+3, r.left()+2, r.bottom()-layoutMetric(LM_BorderBottom)+1);
491 p.drawLine(r.right()-2, r.y()+3, r.right()-2, r.bottom()-layoutMetric(LM_BorderBottom)+1);
492 p.drawLine(r.left()+3, r.y()+3, r.left()+3, r.y()+layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeTop) );
493 p.drawLine(r.right()-3, r.y()+3, r.right()-3, r.y()+layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeTop) );
494 if (!mustDrawHandle() )
495 p.drawLine(r.left()+1, r.bottom()-2, r.right()-1, r.bottom()-2);
497 // outer frame
498 p.setPen(g.color(QPalette::Light));
499 p.drawLine(r.x()+1, r.y()+1, r.right()-1, r.y()+1);
500 p.drawLine(r.x()+1, r.y()+1, r.x()+1, r.bottom()-1);
501 p.setPen(g.dark().color());
502 p.drawLine(r.right()-1, r.y()+1, r.right()-1, r.bottom()-1);
503 p.drawLine(r.x()+1, r.bottom()-1, r.right()-1, r.bottom()-1);
505 int th = titleHeight;
506 int bb = handleSize + 2; // Bottom border
507 int bs = handleSize - 2; // inner size of bottom border
508 if (!mustDrawHandle()) {
509 bb = 6;
510 bs = 0;
512 if ( isToolWindow() )
513 th -= 2;
515 // inner rect
516 p.drawRect(r.x() + 3, r.y() + th + 3, r.width() - 7, r.height() - th - bb - 1);
518 // handles
519 if (mustDrawHandle()) {
520 if (r.width() > 3*handleSize + 20) {
521 int range = 8 + 3*handleSize/2;
522 qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, range,
523 handleSize - 2, g, false, 1, &g.brush(QPalette::Mid));
524 qDrawShadePanel(&p, r.x() + range + 1, r.bottom() - bs,
525 r.width() - 2*range - 2, handleSize - 2, g, false, 1,
526 isActive() ? &g.brush(QPalette::Background) :
527 &g.brush(QPalette::Mid));
528 qDrawShadePanel(&p, r.right() - range, r.bottom() - bs,
529 range, bs, g, false, 1, &g.brush(QPalette::Mid));
530 } else {
531 qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs,
532 r.width() - 2, bs, g, false, 1,
533 isActive() ? &g.brush(QPalette::Background) :
534 &g.brush(QPalette::Mid));
538 r = titleRect();
540 if(isActive()){
541 updateActiveBuffer();
542 p.drawPixmap(r.x(), r.y(), activeBuffer);
543 p.setPen(g.background().color());
544 p.drawPoint(r.x(), r.y());
545 p.drawPoint(r.right(), r.y());
546 p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom());
548 else{
549 if(iUpperGradient)
550 p.drawTiledPixmap(r.x(), r.y(), r.width(), r.height()-1,
551 *iUpperGradient);
552 else
553 p.fillRect(r.x(), r.y(), r.width(), r.height()-1,
554 options()->color(KDecoration::ColorTitleBar, false));
556 p.setFont(options()->font(false, isToolWindow() ));
557 QFontMetrics fm(options()->font(false));
558 g = options()->palette(KDecoration::ColorTitleBar, false);
559 g.setCurrentColorGroup( QPalette::Active );
560 if(iUpperGradient)
561 p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4,
562 r.y(), fm.width(caption())+8, r.height()-1,
563 *iUpperGradient);
564 else
565 p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, r.y(),
566 fm.width(caption())+8, r.height()-1,
567 g.brush(QPalette::Background));
568 p.setPen(g.mid().color());
569 p.drawLine(r.x(), r.y(), r.right(), r.y());
570 p.drawLine(r.x(), r.y(), r.x(), r.bottom());
571 p.setPen(g.color(QPalette::Button));
572 p.drawLine(r.right(), r.y(), r.right(), r.bottom());
573 p.drawLine(r.x(), r.bottom(), r.right(), r.bottom());
574 p.setPen(options()->color(KDecoration::ColorFont, false));
575 p.drawText(r.x(), r.y()+1, r.width(), r.height()-1,
576 Qt::AlignCenter, caption() );
577 g = options()->palette(KDecoration::ColorFrame, true);
578 g.setCurrentColorGroup( QPalette::Active );
579 p.setPen(g.background().color());
580 p.drawPoint(r.x(), r.y());
581 p.drawPoint(r.right(), r.y());
582 p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom());
586 QRegion LaptopClient::cornerShape(WindowCorner corner)
588 switch (corner) {
589 case WC_TopLeft:
590 return QRect(0, 0, 1, 1);
592 case WC_TopRight:
593 return QRect(width()-1, 0, 1, 1);
595 case WC_BottomLeft:
596 return QRect(0, height()-1, 1, 1);
598 case WC_BottomRight:
599 return QRect(width()-1, height()-1, 1, 1);
601 default:
602 return QRegion();
607 bool LaptopClient::mustDrawHandle() const
609 bool drawSmallBorders = !options()->moveResizeMaximizedWindows();
610 if (drawSmallBorders && (maximizeMode() & MaximizeVertical)) {
611 return false;
612 } else {
613 return isResizable();
617 void LaptopClient::updateActiveBuffer( )
619 QRect rTitle = titleRect();
620 if( !bufferDirty && (lastBufferWidth == rTitle.width()))
621 return;
622 if ( rTitle.width() <= 0 || rTitle.height() <= 0 )
623 return;
624 lastBufferWidth = rTitle.width();
625 bufferDirty = false;
627 activeBuffer = QPixmap(rTitle.width(), rTitle.height());
628 QPainter p;
629 QRect r(0, 0, activeBuffer.width(), activeBuffer.height());
630 p.begin(&activeBuffer);
631 if(aUpperGradient){
632 p.drawTiledPixmap(r, *aUpperGradient);
634 else{
635 p.fillRect(r, options()->color(KDecoration::ColorTitleBar, true));
637 if(titlePix)
638 p.drawTiledPixmap(r, *titlePix);
640 p.setFont(options()->font(true, isToolWindow() ));
641 QFontMetrics fm(options()->font(true));
642 QPalette g = options()->palette(KDecoration::ColorTitleBar, true);
643 g.setCurrentColorGroup( QPalette::Active );
644 if(aUpperGradient)
645 p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4,
646 r.y(), fm.width(caption())+8, r.height()-1,
647 *aUpperGradient);
648 else
649 p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, 0,
650 fm.width(caption())+8, r.height(),
651 g.brush(QPalette::Background));
652 p.setPen(g.mid().color());
653 p.drawLine(r.x(), r.y(), r.right(), r.y());
654 p.drawLine(r.x(), r.y(), r.x(), r.bottom());
655 p.setPen(g.color(QPalette::Button));
656 p.drawLine(r.right(), r.y(), r.right(), r.bottom());
657 p.drawLine(r.x(), r.bottom(), r.right(), r.bottom());
658 p.setPen(options()->color(KDecoration::ColorFont, true));
659 p.drawText(r.x(), r.y()+1, r.width(), r.height()-1,
660 Qt::AlignCenter, caption() );
661 g = options()->palette(KDecoration::ColorFrame, true);
662 g.setCurrentColorGroup( QPalette::Active );
663 p.setPen(g.background().color());
664 p.drawPoint(r.x(), r.y());
665 p.drawPoint(r.right(), r.y());
666 p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom());
667 p.end();
670 static const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask |
671 NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask |
672 NET::DialogMask | /*NET::OverrideMask |*/ NET::TopMenuMask |
673 NET::UtilityMask | NET::SplashMask;
675 bool LaptopClient::isTransient() const
677 NET::WindowType type = windowType(SUPPORTED_WINDOW_TYPES_MASK);
678 return type == NET::Dialog;
681 // =====================================
683 LaptopClientFactory::LaptopClientFactory()
685 create_pixmaps();
688 LaptopClientFactory::~LaptopClientFactory()
690 delete_pixmaps();
693 KDecoration *LaptopClientFactory::createDecoration(KDecorationBridge *b)
695 findPreferredHandleSize();
696 return (new Laptop::LaptopClient(b, this))->decoration();
699 bool LaptopClientFactory::reset(unsigned long changed)
701 findPreferredHandleSize();
703 // TODO Do not recreate decorations if it is not needed. Look at
704 // ModernSystem for how to do that
705 Laptop::delete_pixmaps();
706 Laptop::create_pixmaps();
708 bool needHardReset = true;
709 if ((changed & ~SettingButtons) == 0) {
710 // handled by KCommonDecoration
711 needHardReset = false;
714 if (needHardReset) {
715 return true;
716 } else {
717 resetDecorations(changed);
718 return false;
722 bool LaptopClientFactory::supports( Ability ability ) const
724 switch( ability )
726 // announce
727 case AbilityAnnounceButtons:
728 case AbilityAnnounceColors:
729 // buttons
730 case AbilityButtonOnAllDesktops:
731 case AbilityButtonHelp:
732 case AbilityButtonMinimize:
733 case AbilityButtonMaximize:
734 case AbilityButtonClose:
735 case AbilityButtonSpacer:
736 // colors
737 case AbilityColorTitleBack:
738 case AbilityColorTitleFore:
739 case AbilityColorButtonBack:
740 return true;
741 default:
742 return false;
746 QList< LaptopClientFactory::BorderSize >
747 LaptopClientFactory::borderSizes() const
749 // the list must be sorted
750 return QList< BorderSize >() << BorderNormal << BorderLarge <<
751 BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
754 void LaptopClientFactory::findPreferredHandleSize()
756 switch (options()->preferredBorderSize(this)) {
757 case KDecoration::BorderLarge:
758 handleSize = 11;
759 break;
760 case KDecoration::BorderVeryLarge:
761 handleSize = 16;
762 break;
763 case KDecoration::BorderHuge:
764 handleSize = 24;
765 break;
766 case KDecoration::BorderVeryHuge:
767 handleSize = 32;
768 break;
769 case KDecoration::BorderOversized:
770 handleSize = 40;
771 break;
772 case KDecoration::BorderTiny:
773 case KDecoration::BorderNormal:
774 default:
775 handleSize = 8;
779 } // Laptop namespace
781 // vim: sw=4