root/branches/gajim_0.11.1/src/common/idle.c

Revision 7787, 2.1 kB (checked in by asterix, 23 months ago)

merge changeset from trunk except pyopenssl stuff

Line 
1/*      common/idle.c
2 *
3 * Gajim Team:
4 *      - Yann Le Boulanger <asterix@lagaule.org>
5 *
6 * Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
7 *                         Vincent Hanquez <tab@snarc.org>
8 * Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
9 *                    Nikos Kouremenos <nkour@jabber.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; version 2 only.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19*/
20
21#ifndef _WIN32
22        #include <X11/Xlib.h>
23        #include <X11/Xutil.h>
24        #include <X11/extensions/scrnsaver.h>
25#endif
26
27#include <Python.h>
28
29#ifndef _WIN32
30        Display *display;
31#endif
32
33
34static PyObject * idle_init(PyObject *self, PyObject *args)
35{
36#ifndef _WIN32
37        display = XOpenDisplay(NULL);
38#endif
39        Py_INCREF(Py_None);
40        return Py_None;
41}
42
43static PyObject * idle_getIdleSec(PyObject *self, PyObject *args)
44{
45#ifndef _WIN32
46        static XScreenSaverInfo *mit_info = NULL;
47        int idle_time, event_base, error_base;
48#endif
49
50#ifndef _WIN32
51        if (XScreenSaverQueryExtension(display, &event_base, &error_base))
52        {
53                if (mit_info == NULL)
54                        mit_info = XScreenSaverAllocInfo();
55                XScreenSaverQueryInfo(display, RootWindow(display, 0), mit_info);
56                idle_time = (mit_info->idle) / 1000;
57        }
58        else
59                idle_time = 0;
60#endif
61        return Py_BuildValue("i", idle_time);
62}
63
64static PyObject * idle_close(PyObject *self, PyObject *args)
65{
66#ifndef _WIN32
67        XCloseDisplay(display);
68#endif
69        Py_INCREF(Py_None);
70        return Py_None;
71}
72
73static PyMethodDef idleMethods[] =
74{
75        {"init",  idle_init, METH_VARARGS, "init idle"},
76        {"getIdleSec",  idle_getIdleSec, METH_VARARGS, "Give the idle time in secondes"},
77        {"close",  idle_close, METH_VARARGS, "close idle"},
78        {NULL, NULL, 0, NULL}
79};
80
81PyMODINIT_FUNC
82initidle(void)
83{
84            (void) Py_InitModule("idle", idleMethods);
85}
Note: See TracBrowser for help on using the browser.