~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to cutestuff/idle/idle_x11.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2006-03-28 11:11:02 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20060328111102-v1diqpbwqr4yijoy
Tags: 0.10-2build1
Manual sync from Debian. No Ubuntu-specific changes.

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
 
#ifdef NO_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
 
 
34
 
#include<X11/Xlib.h>
35
 
#include<X11/Xutil.h>
36
 
#include<X11/extensions/scrnsaver.h>
37
 
 
38
 
static XErrorHandler old_handler = 0;
39
 
extern "C" int xerrhandler(Display* dpy, XErrorEvent* err)
40
 
{
41
 
        if(err->error_code == BadDrawable)
42
 
                return 0;
43
 
 
44
 
        return (*old_handler)(dpy, err);
45
 
}
46
 
 
47
 
class IdlePlatform::Private
48
 
{
49
 
public:
50
 
        Private() {}
51
 
 
52
 
        XScreenSaverInfo *ss_info;
53
 
};
54
 
 
55
 
IdlePlatform::IdlePlatform()
56
 
{
57
 
        d = new Private;
58
 
        d->ss_info = 0;
59
 
}
60
 
 
61
 
IdlePlatform::~IdlePlatform()
62
 
{
63
 
        if(d->ss_info)
64
 
                XFree(d->ss_info);
65
 
        if(old_handler) {
66
 
                XSetErrorHandler(old_handler);
67
 
                old_handler = 0;
68
 
        }
69
 
        delete d;
70
 
}
71
 
 
72
 
bool IdlePlatform::init()
73
 
{
74
 
        if(d->ss_info)
75
 
                return true;
76
 
 
77
 
        old_handler = XSetErrorHandler(xerrhandler);
78
 
 
79
 
        int event_base, error_base;
80
 
        if(XScreenSaverQueryExtension(QApplication::desktop()->screen()->x11Display(), &event_base, &error_base)) {
81
 
                d->ss_info = XScreenSaverAllocInfo();
82
 
                return true;
83
 
        }
84
 
        return false;
85
 
}
86
 
 
87
 
int IdlePlatform::secondsIdle()
88
 
{
89
 
        if(!d->ss_info)
90
 
                return 0;
91
 
        if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), qt_xrootwin(), d->ss_info))
92
 
                return 0;
93
 
        return d->ss_info->idle / 1000;
94
 
}
95
 
 
96
 
#endif