| 1 | #include <X11/Xlib.h> |
|---|
| 2 | #include <X11/Xutil.h> |
|---|
| 3 | #include <X11/extensions/scrnsaver.h> |
|---|
| 4 | #include <gdk/gdkx.h> |
|---|
| 5 | #include <python2.3/Python.h> |
|---|
| 6 | |
|---|
| 7 | #include <gtk/gtk.h> |
|---|
| 8 | |
|---|
| 9 | static PyObject * idle_init(PyObject *self, PyObject *args) |
|---|
| 10 | { |
|---|
| 11 | gtk_init (NULL, NULL); |
|---|
| 12 | Py_INCREF(Py_None); |
|---|
| 13 | return Py_None; |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | static PyObject * idle_getIdleSec(PyObject *self, PyObject *args) |
|---|
| 17 | { |
|---|
| 18 | static XScreenSaverInfo *mit_info = NULL; |
|---|
| 19 | int idle_time, event_base, error_base; |
|---|
| 20 | |
|---|
| 21 | gtk_init (NULL, NULL); |
|---|
| 22 | if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) |
|---|
| 23 | { |
|---|
| 24 | if (mit_info == NULL) |
|---|
| 25 | mit_info = XScreenSaverAllocInfo(); |
|---|
| 26 | XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info); |
|---|
| 27 | idle_time = (mit_info->idle) / 1000; |
|---|
| 28 | } |
|---|
| 29 | else |
|---|
| 30 | idle_time = 0; |
|---|
| 31 | return Py_BuildValue("i", idle_time); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | static PyObject * idle_close(PyObject *self, PyObject *args) |
|---|
| 35 | { |
|---|
| 36 | gtk_main_quit (); |
|---|
| 37 | Py_INCREF(Py_None); |
|---|
| 38 | return Py_None; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | static PyMethodDef idleMethods[] = |
|---|
| 42 | { |
|---|
| 43 | {"init", idle_init, METH_VARARGS, "init gtk"}, |
|---|
| 44 | {"getIdleSec", idle_getIdleSec, METH_VARARGS, "Give the idle time in secondes"}, |
|---|
| 45 | {"close", idle_close, METH_VARARGS, "close gtk"}, |
|---|
| 46 | {NULL, NULL, 0, NULL} |
|---|
| 47 | }; |
|---|
| 48 | |
|---|
| 49 | PyMODINIT_FUNC |
|---|
| 50 | initidle(void) |
|---|
| 51 | { |
|---|
| 52 | (void) Py_InitModule("idle", idleMethods); |
|---|
| 53 | } |
|---|