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