not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / clients / modernsystem / modernsys.cpp
blob4210b74c73be2ab4b25f2e57cd7f83a7cb10d791
1 /*
2 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 // Daniel M. DULEY <mosfet@kde.org> original work
21 // Melchior FRANZ <a8603365@unet.univie.ac.at> configuration options
23 #include "modernsys.h"
25 #include <kconfiggroup.h>
26 #include <kglobal.h>
27 #include <klocale.h>
28 #include <QLayout>
29 #include <QtGui/qdrawutil.h>
30 //Added by qt3to4:
31 #include <QPixmap>
32 #include <QPaintEvent>
33 #include <QPainter>
34 #include <QBitmap>
36 #include <QApplication>
37 #include <QLabel>
39 #include "buttondata.h"
40 #include "btnhighcolor.h"
41 #include <QImage>
43 namespace ModernSystem {
45 static unsigned char iconify_bits[] = {
46 0x00, 0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00};
48 static unsigned char close_bits[] = {
49 0x00, 0x66, 0x7e, 0x3c, 0x3c, 0x7e, 0x66, 0x00};
51 static unsigned char maximize_bits[] = {
52 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00};
54 static unsigned char r_minmax_bits[] = {
55 0x0c, 0x18, 0x33, 0x67, 0xcf, 0x9f, 0x3f, 0x3f};
57 static unsigned char l_minmax_bits[] = {
58 0x30, 0x18, 0xcc, 0xe6, 0xf3, 0xf9, 0xfc, 0xfc};
60 static unsigned char unsticky_bits[] = {
61 0x3c, 0x42, 0x99, 0xbd, 0xbd, 0x99, 0x42, 0x3c};
63 static unsigned char sticky_bits[] = {
64 0x3c, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3c};
66 static unsigned char question_bits[] = {
67 0x3c, 0x66, 0x60, 0x30, 0x18, 0x00, 0x18, 0x18};
69 static unsigned char above_on_bits[] = {
70 0x7e, 0x00, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00};
72 static unsigned char above_off_bits[] = {
73 0x18, 0x3c, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00};
75 static unsigned char below_off_bits[] = {
76 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x3c, 0x18};
78 static unsigned char below_on_bits[] = {
79 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x00, 0x7e};
81 static unsigned char shade_off_bits[] = {
82 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00};
84 static unsigned char shade_on_bits[] = {
85 0x00, 0x7e, 0x7e, 0x42, 0x42, 0x42, 0x7e, 0x00};
87 static unsigned char menu_bits[] = {
88 0xff, 0x81, 0x81, 0xff, 0x81, 0xff, 0x81, 0xff};
90 static unsigned char btnhighcolor_mask_bits[] = {
91 0xe0,0x41,0xf8,0x07,0xfc,0x0f,0xfe,0xdf,0xfe,0x1f,0xff,0x3f,0xff,0xff,0xff,
92 0x3f,0xff,0x3f,0xff,0xff,0xff,0xff,0xfe,0x9f,0xfe,0x1f,0xfc,0x0f,0xf0,0x03,
93 0x00,0x40,0x80,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x20,0x99,0x0f,0x08,0xc4,
94 0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x58,0x5f,0x43,0x68,0x61,0x6e,0x67,0x65 };
96 static QPixmap *aUpperGradient=0;
97 static QPixmap *iUpperGradient=0;
98 static QPixmap *buttonPix=0;
99 static QPixmap *buttonPixDown=0;
100 static QPixmap *iButtonPix=0;
101 static QPixmap *iButtonPixDown=0;
103 static QColor *buttonFg;
104 static bool pixmaps_created = false;
106 static QBitmap *lcDark1;
107 static QBitmap *lcDark2;
108 static QBitmap *lcDark3;
109 static QBitmap *lcLight1;
110 static QImage *btnSource;
112 static bool show_handle;
113 static int handle_size;
114 static int handle_width;
115 static int border_width;
116 static int title_height;
118 static inline const KDecorationOptions* options()
120 return KDecoration::options();
123 static void make_button_fx(const QPalette &g, QPixmap *pix, bool light=false)
125 pix->fill(g.background().color());
126 QPainter p(pix);
128 if(QPixmap::defaultDepth() > 8){
129 int i, destH, destS, destV, srcH, srcS, srcV;
130 QColor btnColor = g.background().color();
132 if(btnSource->depth() < 32)
133 *btnSource = btnSource->convertDepth(32);
134 if(light)
135 btnColor = btnColor.light(120);
136 btnColor.getHsv(&destH, &destS, &destV);
137 QImage btnDest(14, 15, 32);
139 unsigned int *srcData = (unsigned int *)btnSource->bits();
140 unsigned int *destData = (unsigned int *)btnDest.bits();
141 QColor srcColor;
142 for(i=0; i < btnSource->width()*btnSource->height(); ++i){
143 srcColor.setRgb(srcData[i]);
144 srcColor.getHsv(&srcH, &srcS, &srcV);
145 srcColor.setHsv(destH, destS, srcV);
146 destData[i] = srcColor.rgb();
148 *pix = QPixmap::fromImage(btnDest);
151 else{
152 if(!lcDark1->mask()){
153 lcDark1->setMask(*lcDark1);
154 lcDark2->setMask(*lcDark2);
155 lcDark3->setMask(*lcDark3);
156 lcLight1->setMask(*lcLight1);
158 p.setPen(g.dark().color());
159 p.drawPixmap(0, 0, *lcDark2);
160 p.drawPixmap(0, 0, *lcDark1);
161 p.setPen(g.mid().color());
162 p.drawPixmap(0, 0, *lcDark3);
163 p.setPen(g.light().color());
164 p.drawPixmap(0, 0, *lcLight1);
168 static void gradientFill(QPixmap *pixmap, const QColor &color1, const QColor &color2)
170 QPainter p(pixmap);
171 QLinearGradient gradient(0, 0, 0, pixmap->height());
172 gradient.setColorAt(0.0, color1);
173 gradient.setColorAt(1.0, color2);
174 QBrush brush(gradient);
175 p.fillRect(pixmap->rect(), brush);
178 static void create_pixmaps()
180 if(pixmaps_created)
181 return;
182 pixmaps_created = true;
184 lcDark1 = new QBitmap(14, 15, lowcolor_6a696a_bits, true);
185 lcDark2 = new QBitmap(14, 15, lowcolor_949194_bits, true);
186 lcDark3 = new QBitmap(14, 15, lowcolor_b4b6b4_bits, true);
187 lcLight1 = new QBitmap(14, 15, lowcolor_e6e6e6_bits, true);
188 btnSource = new QImage(btnhighcolor_xpm);
190 if(QPixmap::defaultDepth() > 8){
191 aUpperGradient = new QPixmap( 32, title_height+2 );
192 iUpperGradient = new QPixmap( 32, title_height+2);;
193 gradientFill(aUpperGradient,
194 options()->color(KDecoration::ColorTitleBar, true).light(130),
195 options()->color(KDecoration::ColorTitleBlend, true));
196 gradientFill(iUpperGradient,
197 options()->color(KDecoration::ColorTitleBar, false).light(130),
198 options()->color(KDecoration::ColorTitleBlend, false));
200 // buttons
201 QPalette btnColor(options()->palette(KDecoration::ColorButtonBg, true) );
202 btnColor.setCurrentColorGroup(QPalette::Active);
203 buttonPix = new QPixmap(14, 15);
204 make_button_fx(btnColor, buttonPix);
205 buttonPixDown = new QPixmap(14, 15);
206 make_button_fx(btnColor, buttonPixDown, true);
208 btnColor = options()->palette(KDecoration::ColorButtonBg, false);
209 btnColor.setCurrentColorGroup(QPalette::Active);
210 iButtonPix = new QPixmap(14, 15);
211 make_button_fx(btnColor, iButtonPix);
212 iButtonPixDown = new QPixmap(14, 15);
213 make_button_fx(btnColor, iButtonPixDown, true);
216 if(qGray(btnColor.background().color().rgb()) < 150)
217 buttonFg = new QColor(Qt::white);
218 else
219 buttonFg = new QColor(Qt::black);
221 delete lcDark1;
222 delete lcDark2;
223 delete lcDark3;
224 delete lcLight1;
225 delete btnSource;
228 static void delete_pixmaps()
230 if(aUpperGradient){
231 delete aUpperGradient;
232 delete iUpperGradient;
234 delete buttonPix;
235 delete buttonPixDown;
236 delete iButtonPix;
237 delete iButtonPixDown;
239 delete buttonFg;
241 pixmaps_created = false;
244 static void draw_button(QPainter &p, int x, int y, int w, int h, const QPalette &pal)
246 if (w > 16 && h > 16){
247 int x2 = x+w, y2 = y+h;
248 QPen oldPen = p.pen();
249 QPolygon hPntArray, lPntArray;
250 hPntArray.putPoints(0, 12, x+4,y+1, x+5,y+1, // top left
251 x+3,y+2, x+2,y+3, x+1,y+4, x+1,y+5,
252 x+1,y2-5, x+1,y2-4, x+2,y2-3, // half corners
253 x2-5,y+1, x2-4,y+1, x2-3,y+2);
255 lPntArray.putPoints(0, 17, x2-5,y2-1, x2-4,y2-1, // btm right
256 x2-3,y2-2, x2-2,y2-3, x2-1,y2-5, x2-1,y2-4,
258 x+3,y2-2, x+4,y2-1, x+5,y2-1, //half corners
259 x2-2,y+3, x2-1,y+4, x2-1,y+5,
261 x2-5,y2-2, x2-4,y2-2, // testing
262 x2-3,y2-3,
263 x2-2,y2-5, x2-2,y2-4);
265 p.setPen(pal.color(QPalette::Light));
266 p.drawLine(x+6, y, x2-6, y);
267 p.drawLine(0, y+6, 0, y2-6);
268 p.drawPoints(hPntArray);
270 p.setPen(pal.color(QPalette::Dark));
271 p.drawLine(x+6, y2, x2-6, y2);
272 p.drawLine(x+6, y2-1, x2-6, y2-1);
273 p.drawLine(x2, y+6, x2, y2-6);
274 p.drawLine(x2-1, y+6, x2-1, y2-6);
275 p.drawPoints(lPntArray);
276 p.setPen(oldPen);
278 else
279 qDrawWinPanel(&p, x, y, w, h, pal, false);
282 void ModernSysFactory::read_config()
284 bool showh;
285 int hsize, hwidth, bwidth, theight;
287 KConfig _c( "kwinmodernsysrc" );
288 KConfigGroup c(&_c, "General");
289 showh = c.readEntry("ShowHandle", true);
291 hwidth = c.readEntry("HandleWidth", 6);
292 hsize = c.readEntry("HandleSize", 30);
293 if (!(showh && hsize && hwidth)) {
294 showh = false;
295 hwidth = hsize = 0;
298 switch(options()->preferredBorderSize( this )) {
299 case BorderLarge:
300 bwidth = 8;
301 hwidth = hwidth * 7/5;
302 hsize = hsize * 7/5;
303 break;
304 case BorderVeryLarge:
305 bwidth = 12;
306 hwidth = hwidth * 17/10 + 2;
307 hsize = hsize * 17/10;
308 break;
309 case BorderHuge:
310 bwidth = 18;
311 hwidth = hwidth * 2 + 6;
312 hsize = hsize * 2;
313 break;
315 // If we allow these large sizes we need to change the
316 // correlation between the border width and the handle size.
317 case BorderVeryHuge:
318 bwidth = 27;
319 hwidth = hwidth * 5/2 + 15;
320 hsize = hsize * 5/2;
321 break;
322 case BorderOversized:
323 bwidth = 40;
324 hwidth = hwidth * 3 + 22;
325 hsize = hsize * 3;
326 break;
328 case BorderNormal:
329 default:
330 bwidth = 4;
333 theight = QFontMetrics(options()->font(true)).height();
334 if (theight < 16)
335 theight = 16;
336 if (theight < bwidth)
337 theight = bwidth;
339 show_handle = showh;
340 handle_width = hwidth;
341 handle_size = hsize;
342 border_width = bwidth;
343 title_height = theight;
346 QList< ModernSysFactory::BorderSize > ModernSysFactory::borderSizes() const
347 { // the list must be sorted
348 return QList< BorderSize >() << BorderNormal << BorderLarge <<
349 BorderVeryLarge << BorderHuge;
350 // as long as the buttons don't scale don't offer the largest two sizes.
351 // BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
354 ModernButton::ModernButton(ButtonType type, ModernSys *parent, const char *name)
355 : KCommonDecorationButton(type, parent)
357 setObjectName( name );
358 setAttribute(Qt::WA_NoSystemBackground, true);
360 QBitmap mask = QBitmap::fromData( QSize(14, 15), QPixmap::defaultDepth() > 8 ? btnhighcolor_mask_bits : lowcolor_mask_bits);
361 resize(14, 15);
363 setMask(mask);
366 void ModernButton::reset(unsigned long changed)
368 if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
369 switch (type() ) {
370 case CloseButton:
371 setBitmap(close_bits);
372 break;
373 case HelpButton:
374 setBitmap(question_bits);
375 break;
376 case MinButton:
377 setBitmap(iconify_bits);
378 break;
379 case MaxButton:
380 setBitmap( isChecked() ? (isLeft()?l_minmax_bits:r_minmax_bits) : maximize_bits );
381 break;
382 case OnAllDesktopsButton:
383 setBitmap( isChecked() ? unsticky_bits : sticky_bits );
384 break;
385 case ShadeButton:
386 setBitmap( isChecked() ? shade_on_bits : shade_off_bits );
387 break;
388 case AboveButton:
389 setBitmap( isChecked() ? above_on_bits : above_off_bits );
390 break;
391 case BelowButton:
392 setBitmap( isChecked() ? below_on_bits : below_off_bits );
393 break;
394 case MenuButton:
395 setBitmap(menu_bits);
396 break;
397 default:
398 setBitmap(0);
399 break;
402 this->update();
406 void ModernButton::setBitmap(const unsigned char *bitmap)
408 if (bitmap)
409 deco = QBitmap::fromData( QSize(8, 8), bitmap);
410 else {
411 deco = QBitmap(8,8);
412 deco.fill(Qt::color0);
414 deco.setMask(deco);
417 void ModernButton::paintEvent(QPaintEvent *)
419 QPainter p(this);
420 drawButton(&p);
423 void ModernButton::drawButton(QPainter *p)
425 if(decoration()->isActive()){
426 if(buttonPix)
427 p->drawPixmap(0, 0, isDown() ? *buttonPixDown : *buttonPix);
429 else{
430 if(iButtonPix)
431 p->drawPixmap(0, 0, isDown() ? *iButtonPixDown : *iButtonPix);
433 if(!deco.isNull()){
434 p->setPen(*buttonFg);
435 p->drawPixmap(isDown() ? 4 : 3, isDown() ? 5 : 4, deco);
439 void ModernSys::reset( unsigned long changed)
441 KCommonDecoration::reset(changed);
443 titleBuffer = QPixmap();
444 recalcTitleBuffer();
445 resetButtons();
446 widget()->update();
449 ModernSys::ModernSys( KDecorationBridge* b, KDecorationFactory* f )
450 : KCommonDecoration( b, f )
454 QString ModernSys::visibleName() const
456 return i18n("Modern System");
459 QString ModernSys::defaultButtonsLeft() const
461 return "X";
464 QString ModernSys::defaultButtonsRight() const
466 return "HSIA";
469 bool ModernSys::decorationBehaviour(DecorationBehaviour behaviour) const
471 switch (behaviour) {
472 case DB_MenuClose:
473 return false;
475 case DB_WindowMask:
476 return true;
478 case DB_ButtonHide:
479 return true;
481 default:
482 return KCommonDecoration::decorationBehaviour(behaviour);
486 int ModernSys::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
488 // bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
490 switch (lm) {
491 case LM_BorderLeft:
492 return border_width + (reverse ? handle_width : 0);
494 case LM_BorderRight:
495 return border_width + (reverse ? 0 : handle_width);
497 case LM_BorderBottom:
498 return border_width + handle_width;
500 case LM_TitleEdgeLeft:
501 return layoutMetric(LM_BorderLeft,respectWindowState)+3;
502 case LM_TitleEdgeRight:
503 return layoutMetric(LM_BorderRight,respectWindowState)+3;
505 case LM_TitleEdgeTop:
506 return 2;
508 case LM_TitleEdgeBottom:
509 return 2;
511 case LM_TitleBorderLeft:
512 case LM_TitleBorderRight:
513 return 4;
515 case LM_TitleHeight:
516 return title_height;
518 case LM_ButtonWidth:
519 return 14;
520 case LM_ButtonHeight:
521 return 15;
523 case LM_ButtonSpacing:
524 return 1;
526 default:
527 return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
531 KCommonDecorationButton *ModernSys::createButton(ButtonType type)
533 switch (type) {
534 case MenuButton:
535 return new ModernButton(MenuButton, this, "menu");
537 case OnAllDesktopsButton:
538 return new ModernButton(OnAllDesktopsButton, this, "on_all_desktops");
540 case HelpButton:
541 return new ModernButton(HelpButton, this, "help");
543 case MinButton:
544 return new ModernButton(MinButton, this, "minimize");
546 case MaxButton:
547 return new ModernButton(MaxButton, this, "maximize");
549 case CloseButton:
550 return new ModernButton(CloseButton, this, "close");
552 case AboveButton:
553 return new ModernButton(AboveButton, this, "above");
555 case BelowButton:
556 return new ModernButton(BelowButton, this, "below");
558 case ShadeButton:
559 return new ModernButton(ShadeButton, this, "shade");
561 default:
562 return 0;
566 void ModernSys::init()
568 reverse = QApplication::isRightToLeft();
570 KCommonDecoration::init();
572 recalcTitleBuffer();
575 void ModernSys::recalcTitleBuffer()
577 if(oldTitle == caption() && width() == titleBuffer.width())
578 return;
580 QFontMetrics fm(options()->font(true));
581 titleBuffer = QPixmap(width(), title_height+2);
582 QPainter p;
583 p.begin(&titleBuffer);
585 QPalette pt = options()->palette(ColorTitleBar, true);
586 pt.setCurrentColorGroup( QPalette::Active );
587 if(aUpperGradient)
588 p.drawTiledPixmap(0, 0, width(), title_height+2, *aUpperGradient);
589 else
590 p.fillRect(0, 0, width(), title_height+2,
591 pt.brush(QPalette::Button));
593 QRect t = titleRect(); // titlebar->geometry();
594 t.setTop( 2 );
595 t.setLeft( t.left() );
596 t.setRight( t.right() - 2 );
598 QRegion r(t.x(), 0, t.width(), title_height+2);
599 r -= QRect(t.x()+((t.width()-fm.width(caption()))/2)-4,
600 0, fm.width(caption())+8, title_height+2);
601 p.setClipRegion(r);
602 int i, ly;
603 ly = (title_height % 3 == 0) ? 3 : 4;
604 for(i=0; i < (title_height-2)/3; ++i, ly+=3){
605 p.setPen(options()->color(ColorTitleBar, true).light(150));
606 p.drawLine(0, ly, width()-1, ly);
607 p.setPen(options()->color(ColorTitleBar, true).dark(120));
608 p.drawLine(0, ly+1, width()-1, ly+1);
610 p.setClipRect(t);
611 p.setPen(options()->color(ColorFont, true));
612 p.setFont(options()->font(true));
614 p.drawText(t.x()+((t.width()-fm.width(caption()))/2)-4,
615 0, fm.width(caption())+8, title_height+2, Qt::AlignCenter, caption());
616 p.setClipping(false);
617 p.end();
618 oldTitle = caption();
621 void ModernSys::updateCaption()
623 widget()->update(titleRect() );
626 void ModernSys::drawRoundFrame(QPainter &p, int x, int y, int w, int h)
628 QPalette pt = options()->palette(ColorFrame, isActive());
629 pt.setCurrentColorGroup( QPalette::Active );
630 draw_button(p, x, y, w, h, pt);
634 void ModernSys::paintEvent( QPaintEvent* )
636 // update title buffer...
637 if (oldTitle != caption() || width() != titleBuffer.width() )
638 recalcTitleBuffer();
640 int hs = handle_size;
641 int hw = handle_width;
643 QPainter p( widget() );
644 QRect t = titleRect(); // titlebar->geometry();
646 QPalette pt = options()->palette(ColorFrame, isActive());
647 pt.setCurrentColorGroup( QPalette::Active );
648 QBrush fillBrush(widget()->palette().brush(QPalette::Background).pixmap() ?
649 widget()->palette().brush(QPalette::Background) :
650 pt.brush(QPalette::Button));
652 p.fillRect(1, title_height+3, width()-2, height()-(title_height+3), fillBrush);
653 p.fillRect(width()-6, 0, width()-1, height(), fillBrush);
655 t.setTop( 2 );
656 t.setLeft( t.left() );
657 t.setRight( t.right() - 2 );
659 int w = width() - hw; // exclude handle
660 int h = height() - hw;
662 // titlebar
663 QPalette g = options()->palette(ColorTitleBar, isActive());
664 g.setCurrentColorGroup( QPalette::Active );
665 if(isActive()){
666 p.drawPixmap(1, 1, titleBuffer, 0, 0, w-2, title_height+2);
668 else{
669 if(iUpperGradient)
670 p.drawTiledPixmap(1, 1, w-2, title_height+2, *iUpperGradient);
671 else
672 p.fillRect(1, 1, w-2, title_height+2, fillBrush);
673 p.setPen(options()->color(ColorFont, isActive()));
674 p.setFont(options()->font(isActive()));
675 p.drawText(t, Qt::AlignCenter, caption() );
678 // titlebar highlight
679 p.setPen(g.light().color());
680 p.drawLine(1, 1, 1, title_height+3);
681 p.drawLine(1, 1, w-3, 1);
682 p.setPen(g.dark().color());
683 p.drawLine(w-2, 1, w-2, title_height+3);
684 p.drawLine(0, title_height+2, w-2, title_height+2);
686 // frame
687 g = options()->palette(ColorFrame, isActive());
688 g.setCurrentColorGroup(QPalette::Active);
689 p.setPen(g.light().color());
690 p.drawLine(1, title_height+3, 1, h-2);
691 p.setPen(g.dark().color());
692 p.drawLine(2, h-2, w-2, h-2);
693 p.drawLine(w-2, title_height+3, w-2, h-2);
694 //p.drawPoint(w-3, title_height+3);
695 //p.drawPoint(2, title_height+3);
697 qDrawShadePanel(&p, border_width-1, title_height+3, w-2*border_width+2, h-title_height-border_width-2, g, true);
699 if (show_handle) {
700 p.setPen(g.dark().color());
701 p.drawLine(width()-3, height()-hs-1, width()-3, height()-3);
702 p.drawLine(width()-hs-1, height()-3, width()-3, height()-3);
704 p.setPen(g.light().color());
705 p.drawLine(width()-hw, height()-hs-1, width()-hw, height()-hw);
706 p.drawLine(width()-hs-1, height()-hw, width()-hw, height()-hw);
707 p.drawLine(width()-hw, height()-hs-1, width()-4, height()-hs-1);
708 p.drawLine(width()-hs-1, height()-hw, width()-hs-1, height()-4);
710 p.setPen(Qt::black);
711 p.drawRect(0, 0, w-1, h-1);
713 // handle outline
714 p.drawLine(width()-hw, height()-hs, width(), height()-hs);
715 p.drawLine(width()-2, height()-hs, width()-2, height()-2);
716 p.drawLine(width()-hs, height()-2, width()-2, height()-2);
717 p.drawLine(width()-hs, height()-hw, width()-hs, height()-2);
718 } else {
719 p.setPen(Qt::black);
720 p.drawRect(0, 0, w-1, h-1);
724 void ModernSys::updateWindowShape()
726 int hs = handle_size;
727 int hw = handle_width;
728 QRegion mask;
729 mask += QRect(0, 0, width()-hw, height()-hw);
730 //single points
731 mask -= QRect(0, 0, 1, 1);
732 mask -= QRect(width()-hw-1, 0, 1, 1);
733 mask -= QRect(0, height()-hw-1, 1, 1);
735 if (show_handle) {
736 mask += QRect(width()-hs, height()-hs, hs-1, hs-1);
737 mask -= QRect(width()-2, height()-2, 1, 1);
738 mask -= QRect(width()-2, height()-hs, 1, 1);
739 mask -= QRect(width()-hs, height()-2, 1, 1);
740 } else
741 mask -= QRect(width()-1, height()-1, 1, 1);
743 setMask(mask);
746 ModernSysFactory::ModernSysFactory()
748 read_config();
749 create_pixmaps();
752 ModernSysFactory::~ModernSysFactory()
754 ModernSystem::delete_pixmaps();
757 KDecoration* ModernSysFactory::createDecoration( KDecorationBridge* b )
759 return(new ModernSys(b, this))->decoration();
762 bool ModernSysFactory::reset( unsigned long changed )
764 read_config();
766 bool needHardReset = true;
767 if( changed & (SettingColors | SettingBorder | SettingFont) )
769 delete_pixmaps();
770 create_pixmaps();
772 if( ( changed & ~(SettingColors | SettingBorder | SettingFont | SettingButtons)) == 0 )
773 needHardReset = false;
775 if( needHardReset )
776 return true;
777 else
779 resetDecorations( changed );
780 return false; // no recreating of decorations
784 bool ModernSysFactory::supports( Ability ability ) const
786 switch( ability )
788 // announce
789 case AbilityAnnounceButtons:
790 case AbilityAnnounceColors:
791 // buttons
792 case AbilityButtonOnAllDesktops:
793 case AbilityButtonSpacer:
794 case AbilityButtonHelp:
795 case AbilityButtonMinimize:
796 case AbilityButtonMaximize:
797 case AbilityButtonClose:
798 case AbilityButtonAboveOthers:
799 case AbilityButtonBelowOthers:
800 case AbilityButtonShade:
801 case AbilityButtonMenu:
802 // colors
803 case AbilityColorTitleBack:
804 case AbilityColorTitleBlend:
805 case AbilityColorTitleFore:
806 return true;
807 default:
808 return false;
814 // KWin extended plugin interface
815 extern "C" KDE_EXPORT KDecorationFactory* create_factory()
817 return new ModernSystem::ModernSysFactory();
820 // vim:ts=4:sw=4