not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / ksmserver / logouteffect.cpp
bloba2fc06057881dd9ef78d4a01e2cea8bf1a9abfbf
1 /*
2 * Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #include <QWidget>
23 #include <QPixmap>
24 #include <QX11Info>
25 #include <X11/Xlib.h>
27 #include "logouteffect.h"
28 #include "fadeeffect.h"
29 #include "curtaineffect.h"
31 #include <unistd.h> // for gethostname()
34 static bool localDisplay(Display *dpy)
36 QByteArray display(XDisplayString(dpy));
37 QByteArray hostPart = display.left(display.indexOf(':'));
39 if (hostPart.isEmpty())
40 return true;
42 if (hostPart == "localhost")
43 return true;
45 if (hostPart == "127.0.0.1")
46 return true;
48 char name[2048];
49 gethostname(name, sizeof(name));
51 if (hostPart == name)
52 return true;
54 return false;
57 static bool supportedFormat(const QPixmap *pixmap)
59 int depth = pixmap->depth();
60 Visual *visual = (Visual*)pixmap->x11Info().visual();
62 if (ImageByteOrder(pixmap->x11Info().display()) != LSBFirst)
63 return false;
65 // Assume this means the pixmap is ARGB32
66 if (pixmap->hasAlphaChannel())
67 return true;
69 // 24/34 bit x8a8r8g8b8
70 if ((depth == 24 || depth == 32) &&
71 visual->red_mask == 0x00ff0000 &&
72 visual->green_mask == 0x0000ff00 &&
73 visual->blue_mask == 0x000000ff)
75 return true;
78 // 16 bit r5g6b5
79 if (depth == 16 &&
80 visual->red_mask == 0xf800 &&
81 visual->green_mask == 0x07e0 &&
82 visual->blue_mask == 0x001f)
84 return true;
87 return false;
92 // ----------------------------------------------------------------------------
96 LogoutEffect::LogoutEffect(QWidget *parent, QPixmap *pixmap)
97 : QObject(parent), parent(parent), pixmap(pixmap)
101 LogoutEffect::~LogoutEffect()
105 LogoutEffect *LogoutEffect::create(QWidget *parent, QPixmap *pixmap)
107 Display *dpy = parent->x11Info().display();
109 if (!localDisplay(dpy) || !supportedFormat(pixmap))
110 return new CurtainEffect(parent, pixmap);
111 else
112 return new FadeEffect(parent, pixmap);