~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to src/tools/idle/idle_x11.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2010-02-19 09:37:12 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100219093712-e225xvm1wjcf1cgi
Tags: 0.14-2
* comment out only function which uses va_list to work around build
  problems on armel
* Set Standards-Version to 3.8.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * idle_x11.cpp - detect desktop idle time
3
 
 * Copyright (C) 2003  Justin Karneges
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2.1 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Lesser General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 *
19
 
 */
20
 
 
21
 
#include "idle.h"
22
 
 
23
 
#ifndef HAVE_XSS
24
 
 
25
 
IdlePlatform::IdlePlatform() {}
26
 
IdlePlatform::~IdlePlatform() {}
27
 
bool IdlePlatform::init() { return false; }
28
 
int IdlePlatform::secondsIdle() { return 0; }
29
 
 
30
 
#else
31
 
 
32
 
#include <qapplication.h>
33
 
#include <QDesktopWidget>
34
 
#include <QX11Info>
35
 
 
36
 
#include <X11/Xlib.h>
37
 
#include <X11/Xutil.h>
38
 
#include <X11/extensions/scrnsaver.h>
39
 
 
40
 
static XErrorHandler old_handler = 0;
41
 
extern "C" int xerrhandler(Display* dpy, XErrorEvent* err)
42
 
{
43
 
        if(err->error_code == BadDrawable)
44
 
                return 0;
45
 
 
46
 
        return (*old_handler)(dpy, err);
47
 
}
48
 
 
49
 
class IdlePlatform::Private
50
 
{
51
 
public:
52
 
        Private() {}
53
 
 
54
 
        XScreenSaverInfo *ss_info;
55
 
};
56
 
 
57
 
IdlePlatform::IdlePlatform()
58
 
{
59
 
        d = new Private;
60
 
        d->ss_info = 0;
61
 
}
62
 
 
63
 
IdlePlatform::~IdlePlatform()
64
 
{
65
 
        if(d->ss_info)
66
 
                XFree(d->ss_info);
67
 
        if(old_handler) {
68
 
                XSetErrorHandler(old_handler);
69
 
                old_handler = 0;
70
 
        }
71
 
        delete d;
72
 
}
73
 
 
74
 
bool IdlePlatform::init()
75
 
{
76
 
        if(d->ss_info)
77
 
                return true;
78
 
 
79
 
        old_handler = XSetErrorHandler(xerrhandler);
80
 
 
81
 
        int event_base, error_base;
82
 
        if(XScreenSaverQueryExtension(QApplication::desktop()->screen()->x11Display(), &event_base, &error_base)) {
83
 
                d->ss_info = XScreenSaverAllocInfo();
84
 
                return true;
85
 
        }
86
 
        return false;
87
 
}
88
 
 
89
 
int IdlePlatform::secondsIdle()
90
 
{
91
 
        if(!d->ss_info)
92
 
                return 0;
93
 
        if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), QX11Info::appRootWindow(), d->ss_info))
94
 
                return 0;
95
 
        return d->ss_info->idle / 1000;
96
 
}
97
 
 
98
 
#endif