Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorYann Leboulanger <asterix@lagaule.org>2004-05-28 08:20:30 +0400
committerYann Leboulanger <asterix@lagaule.org>2004-05-28 08:20:30 +0400
commit279a060265d9cac9762a4b2c8cf250822b63f74e (patch)
tree89e00d60b58037df75daf0894c69a8c470b591a8 /common
parent1ae38e75689c91e78fdc7bbff3e9272d4d295dbe (diff)
- idle in a C module, auto away / xa feature is back
- no need to store .mo files : they are now created by make
Diffstat (limited to 'common')
-rw-r--r--common/idle.cpp49
-rw-r--r--common/sleepy.py54
2 files changed, 61 insertions, 42 deletions
diff --git a/common/idle.cpp b/common/idle.cpp
new file mode 100644
index 000000000..6cf5f970f
--- /dev/null
+++ b/common/idle.cpp
@@ -0,0 +1,49 @@
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/scrnsaver.h>
+#include <gdk/gdkx.h>
+#include <python2.3/Python.h>
+
+#include <gtk/gtk.h>
+
+static PyObject * idle_init(PyObject *self, PyObject *args) {
+ gtk_init (NULL, NULL);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject * idle_getIdleSec(PyObject *self, PyObject *args) {
+ static XScreenSaverInfo *mit_info = NULL;
+ int idle_time, event_base, error_base;
+
+ gtk_init (NULL, NULL);
+ if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) {
+ if (mit_info == NULL) {
+ mit_info = XScreenSaverAllocInfo();
+ }
+ XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info);
+ idle_time = (mit_info->idle) / 1000;
+ }
+ else
+ idle_time = 0;
+ return Py_BuildValue("i", idle_time);
+}
+
+static PyObject * idle_close(PyObject *self, PyObject *args) {
+ gtk_main_quit ();
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyMethodDef idleMethods[] = {
+ {"init", idle_init, METH_VARARGS, "init gtk"},
+ {"getIdleSec", idle_getIdleSec, METH_VARARGS, "Give the idle time in secondes"},
+ {"close", idle_close, METH_VARARGS, "close gtk"},
+ {NULL, NULL, 0, NULL}
+};
+
+PyMODINIT_FUNC
+initidle(void)
+{
+ (void) Py_InitModule("idle", idleMethods);
+}
diff --git a/common/sleepy.py b/common/sleepy.py
index e5e58442c..23bf19ab3 100644
--- a/common/sleepy.py
+++ b/common/sleepy.py
@@ -2,6 +2,7 @@
"""A Quick class to tell if theres any activity on your machine"""
import time
+import idle
from string import find, lower
@@ -16,45 +17,26 @@ class Sleepy:
def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ):
- self.devices = devices
- self.time_marker = time.time()
- self.interval = self.interval_orig = interval1
- self.interval_orig2 = interval2
- self.last_proc_vals = {}
- for dev in self.devices: self.last_proc_vals[dev] = 0
-
+ self.interval1 = interval1
+ self.interval2 = interval2
self.state = STATE_AWAKE ## assume were awake to stake with
try:
- self.proc_int_fh = open("/proc/interrupts",'r')
+ idle.init()
except:
NOT_SUPPORTED = 1
self.state = STATE_UNKNOWN
- self.proc_int_fh.close()
-
def poll(self):
if NOT_SUPPORTED: return -1
now = time.time()
- changed = 0 ## figure out if we have recieved interupts
- for dev in self.devices: ## any of the selected devices
- proc_val = self._read_proc(dev)
- changed = changed or ( self.last_proc_vals[dev] != proc_val )
- self.last_proc_vals[dev] = proc_val
-
- if changed:
- ## we are awake :)
- self.time_marker = time.time() ## reset marker
- self.state = STATE_AWAKE
- self.interval = self.interval_orig
- else:
- if (now - self.time_marker >= self.interval):
- ## we are asleep
- if self.state == STATE_AWAKE:
- self.state = STATE_AWAY
- self.interval = self.interval_orig2 #second interval
- else:
- self.state = STATE_XAWAY
+ idleTime = idle.getIdleSec()
+ if idleTime > self.interval2:
+ self.state = STATE_XAWAY
+ elif idleTime > self.interval1:
+ self.state = STATE_AWAY
+ else:
+ self.state = STATE_AWAKE
return 1
def getState(self):
@@ -63,20 +45,8 @@ class Sleepy:
def setState(self,val):
self.state = val
- def _read_proc(self, device = 'mouse'):
- proc_int_fh = open("/proc/interrupts",'r')
- info = proc_int_fh.readlines()
- ## ignore first line
- for line in info[1:]:
- cols = line.strip().split()
- if (find(lower(cols[-1]),device) != -1):
- proc_int_fh.close()
- return int(cols[1])
- proc_int_fh.close()
- return 1
-
if __name__ == '__main__':
s = Sleepy(10)
while s.poll():
print "state is %s" % s.getState()
- time.sleep(10)
+ time.sleep(5)