~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksmserver/logouteffect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
 
3
 *
 
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:
 
10
 *
 
11
 * The above copyright notice and this permission notice shall be included in
 
12
 * all copies or substantial portions of the Software.
 
13
 *
 
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.
 
20
 */
 
21
 
 
22
#include <QWidget>
 
23
#include <QPixmap>
 
24
#include <QX11Info>
 
25
#include <X11/Xlib.h>
 
26
 
 
27
#include "logouteffect.h"
 
28
#include "fadeeffect.h"
 
29
#include "curtaineffect.h"
 
30
 
 
31
#include <unistd.h> // for gethostname()
 
32
 
 
33
 
 
34
static bool localDisplay(Display *dpy)
 
35
{
 
36
    QByteArray display(XDisplayString(dpy));
 
37
    QByteArray hostPart = display.left(display.indexOf(':'));
 
38
 
 
39
    if (hostPart.isEmpty())
 
40
        return true;
 
41
 
 
42
    if (hostPart == "localhost")
 
43
        return true;
 
44
 
 
45
    if (hostPart == "127.0.0.1")
 
46
        return true;
 
47
 
 
48
    char name[2048];
 
49
    gethostname(name, sizeof(name));
 
50
 
 
51
    if (hostPart == name)
 
52
       return true;
 
53
 
 
54
    return false;
 
55
}
 
56
 
 
57
static bool supportedFormat(const QPixmap *pixmap)
 
58
{
 
59
    int depth = pixmap->depth();
 
60
    Visual *visual = (Visual*)pixmap->x11Info().visual();
 
61
 
 
62
    if (ImageByteOrder(pixmap->x11Info().display()) != LSBFirst)
 
63
        return false;
 
64
 
 
65
    // Assume this means the pixmap is ARGB32
 
66
    if (pixmap->hasAlphaChannel())
 
67
        return true;
 
68
 
 
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)
 
74
    {
 
75
        return true;
 
76
    }
 
77
 
 
78
    // 16 bit r5g6b5
 
79
    if (depth == 16 &&
 
80
        visual->red_mask   == 0xf800 &&
 
81
        visual->green_mask == 0x07e0 &&
 
82
        visual->blue_mask  == 0x001f)
 
83
    {
 
84
        return true;
 
85
    }
 
86
 
 
87
    return false;
 
88
}
 
89
 
 
90
 
 
91
 
 
92
// ----------------------------------------------------------------------------
 
93
 
 
94
 
 
95
 
 
96
LogoutEffect::LogoutEffect(QWidget *parent, QPixmap *pixmap)
 
97
    : QObject(parent), parent(parent), pixmap(pixmap)
 
98
{
 
99
}
 
100
 
 
101
LogoutEffect::~LogoutEffect()
 
102
{
 
103
}
 
104
 
 
105
LogoutEffect *LogoutEffect::create(QWidget *parent, QPixmap *pixmap)
 
106
{
 
107
    Display *dpy = parent->x11Info().display();
 
108
 
 
109
    if (!localDisplay(dpy) || !supportedFormat(pixmap))
 
110
        return new CurtainEffect(parent, pixmap);
 
111
    else
 
112
        return new FadeEffect(parent, pixmap);
 
113
}
 
114
 
 
115