- idle in a C module, auto away / xa feature is back
- no need to store .mo files : they are now created by make
This commit is contained in:
parent
1ae38e7568
commit
279a060265
|
@ -0,0 +1,4 @@
|
||||||
|
all:
|
||||||
|
python setup.py build_ext -i
|
||||||
|
mv idle.so common/
|
||||||
|
msgfmt Messages/fr/LC_MESSAGES/gajim.po -o Messages/fr/LC_MESSAGES/gajim.mo
|
Binary file not shown.
|
@ -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);
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
"""A Quick class to tell if theres any activity on your machine"""
|
"""A Quick class to tell if theres any activity on your machine"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import idle
|
||||||
from string import find, lower
|
from string import find, lower
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,45 +17,26 @@ class Sleepy:
|
||||||
|
|
||||||
def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ):
|
def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ):
|
||||||
|
|
||||||
self.devices = devices
|
self.interval1 = interval1
|
||||||
self.time_marker = time.time()
|
self.interval2 = interval2
|
||||||
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.state = STATE_AWAKE ## assume were awake to stake with
|
self.state = STATE_AWAKE ## assume were awake to stake with
|
||||||
try:
|
try:
|
||||||
self.proc_int_fh = open("/proc/interrupts",'r')
|
idle.init()
|
||||||
except:
|
except:
|
||||||
NOT_SUPPORTED = 1
|
NOT_SUPPORTED = 1
|
||||||
self.state = STATE_UNKNOWN
|
self.state = STATE_UNKNOWN
|
||||||
self.proc_int_fh.close()
|
|
||||||
|
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
if NOT_SUPPORTED: return -1
|
if NOT_SUPPORTED: return -1
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
|
||||||
changed = 0 ## figure out if we have recieved interupts
|
idleTime = idle.getIdleSec()
|
||||||
for dev in self.devices: ## any of the selected devices
|
if idleTime > self.interval2:
|
||||||
proc_val = self._read_proc(dev)
|
self.state = STATE_XAWAY
|
||||||
changed = changed or ( self.last_proc_vals[dev] != proc_val )
|
elif idleTime > self.interval1:
|
||||||
self.last_proc_vals[dev] = proc_val
|
self.state = STATE_AWAY
|
||||||
|
else:
|
||||||
if changed:
|
self.state = STATE_AWAKE
|
||||||
## 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
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def getState(self):
|
def getState(self):
|
||||||
|
@ -63,20 +45,8 @@ class Sleepy:
|
||||||
def setState(self,val):
|
def setState(self,val):
|
||||||
self.state = 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__':
|
if __name__ == '__main__':
|
||||||
s = Sleepy(10)
|
s = Sleepy(10)
|
||||||
while s.poll():
|
while s.poll():
|
||||||
print "state is %s" % s.getState()
|
print "state is %s" % s.getState()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import gtk
|
||||||
from gtk import TRUE, FALSE
|
from gtk import TRUE, FALSE
|
||||||
import gtk.glade,gobject
|
import gtk.glade,gobject
|
||||||
import os,string
|
import os,string
|
||||||
|
import common.sleepy
|
||||||
from common import i18n
|
from common import i18n
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
APP = i18n.APP
|
APP = i18n.APP
|
||||||
|
@ -216,7 +217,8 @@ class preference_Window:
|
||||||
self.plugin.config['autoxatime'] = axt
|
self.plugin.config['autoxatime'] = axt
|
||||||
if self.plugin.sleeper:
|
if self.plugin.sleeper:
|
||||||
self.plugin.sleeper = common.sleepy.Sleepy(\
|
self.plugin.sleeper = common.sleepy.Sleepy(\
|
||||||
self.plugin['autoawaytime']*60, self.plugin['autoxatime']*60)
|
self.plugin.config['autoawaytime']*60, \
|
||||||
|
self.plugin.config['autoxatime']*60)
|
||||||
self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config))
|
self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config))
|
||||||
self.plugin.roster.draw_roster()
|
self.plugin.roster.draw_roster()
|
||||||
|
|
||||||
|
@ -306,28 +308,24 @@ class preference_Window:
|
||||||
if self.plugin.config.has_key('autoaway'):
|
if self.plugin.config.has_key('autoaway'):
|
||||||
st = self.plugin.config['autoaway']
|
st = self.plugin.config['autoaway']
|
||||||
self.chk_autoaway.set_active(st)
|
self.chk_autoaway.set_active(st)
|
||||||
self.chk_autoaway.set_sensitive(0)
|
|
||||||
|
|
||||||
#Autoawaytime
|
#Autoawaytime
|
||||||
st = 10
|
st = 10
|
||||||
if self.plugin.config.has_key('autoawaytime'):
|
if self.plugin.config.has_key('autoawaytime'):
|
||||||
st = self.plugin.config['autoawaytime']
|
st = self.plugin.config['autoawaytime']
|
||||||
self.spin_autoawaytime.set_value(st)
|
self.spin_autoawaytime.set_value(st)
|
||||||
self.spin_autoawaytime.set_sensitive(0)
|
|
||||||
|
|
||||||
#Autoxa
|
#Autoxa
|
||||||
st = 1
|
st = 1
|
||||||
if self.plugin.config.has_key('autoxa'):
|
if self.plugin.config.has_key('autoxa'):
|
||||||
st = self.plugin.config['autoxa']
|
st = self.plugin.config['autoxa']
|
||||||
self.chk_autoxa.set_active(st)
|
self.chk_autoxa.set_active(st)
|
||||||
self.chk_autoxa.set_sensitive(0)
|
|
||||||
|
|
||||||
#Autoxatime
|
#Autoxatime
|
||||||
st = 20
|
st = 20
|
||||||
if self.plugin.config.has_key('autoxatime'):
|
if self.plugin.config.has_key('autoxatime'):
|
||||||
st = self.plugin.config['autoxatime']
|
st = self.plugin.config['autoxatime']
|
||||||
self.spin_autoxatime.set_value(st)
|
self.spin_autoxatime.set_value(st)
|
||||||
self.spin_autoxatime.set_sensitive(0)
|
|
||||||
|
|
||||||
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
|
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
|
||||||
self.xml.signal_connect('on_but_col_clicked', \
|
self.xml.signal_connect('on_but_col_clicked', \
|
||||||
|
|
|
@ -785,6 +785,8 @@ class roster_Window:
|
||||||
else:
|
else:
|
||||||
txt = status
|
txt = status
|
||||||
self.plugin.send('STATUS', account, (status, txt))
|
self.plugin.send('STATUS', account, (status, txt))
|
||||||
|
if status == 'online':
|
||||||
|
self.plugin.sleeper_state[account] = 1
|
||||||
|
|
||||||
def on_optionmenu_changed(self, widget):
|
def on_optionmenu_changed(self, widget):
|
||||||
"""When we change our status"""
|
"""When we change our status"""
|
||||||
|
@ -805,6 +807,8 @@ class roster_Window:
|
||||||
return
|
return
|
||||||
for acct in accounts:
|
for acct in accounts:
|
||||||
self.plugin.send('STATUS', acct, (status, txt))
|
self.plugin.send('STATUS', acct, (status, txt))
|
||||||
|
if status == 'online':
|
||||||
|
self.plugin.sleeper_state[acct] = 1
|
||||||
|
|
||||||
def set_optionmenu(self):
|
def set_optionmenu(self):
|
||||||
#table to change index in plugin.connected to index in optionmenu
|
#table to change index in plugin.connected to index in optionmenu
|
||||||
|
@ -833,9 +837,10 @@ class roster_Window:
|
||||||
for user in luser:
|
for user in luser:
|
||||||
self.chg_user_status(user, 'offline', 'Disconnected', account)
|
self.chg_user_status(user, 'offline', 'Disconnected', account)
|
||||||
elif self.plugin.connected[account] == 0:
|
elif self.plugin.connected[account] == 0:
|
||||||
self.plugin.sleeper = None#common.sleepy.Sleepy(\
|
if (self.plugin.config['autoaway'] or self.plugin.config['autoxa']):
|
||||||
#self.plugin.config['autoawaytime']*60, \
|
self.plugin.sleeper = common.sleepy.Sleepy(\
|
||||||
#self.plugin.config['autoxatime']*60)
|
self.plugin.config['autoawaytime']*60, \
|
||||||
|
self.plugin.config['autoxatime']*60)
|
||||||
self.plugin.connected[account] = statuss.index(status)
|
self.plugin.connected[account] = statuss.index(status)
|
||||||
self.set_optionmenu()
|
self.set_optionmenu()
|
||||||
|
|
||||||
|
@ -1349,25 +1354,25 @@ class plugin:
|
||||||
|
|
||||||
def read_sleepy(self):
|
def read_sleepy(self):
|
||||||
"""Check if we are idle"""
|
"""Check if we are idle"""
|
||||||
if self.sleeper and (self.config['autoaway'] or self.config['autoxa'])\
|
if self.sleeper:
|
||||||
and (self.roster.optionmenu.get_history()==0 or \
|
|
||||||
self.sleeper_state!=common.sleepy.STATE_AWAKE):
|
|
||||||
self.sleeper.poll()
|
self.sleeper.poll()
|
||||||
state = self.sleeper.getState()
|
state = self.sleeper.getState()
|
||||||
if state != self.sleeper_state:
|
for account in self.accounts.keys():
|
||||||
if state == common.sleepy.STATE_AWAKE:
|
if self.sleeper_state[account]:
|
||||||
#we go online
|
if state == common.sleepy.STATE_AWAKE and \
|
||||||
self.roster.optionmenu.set_history(0)
|
self.connected[account] > 1:
|
||||||
self.send('STATUS', None, ('online', ''))
|
#we go online
|
||||||
elif state == common.sleepy.STATE_AWAY and self.config['autoaway']:
|
self.send('STATUS', account, ('online', ''))
|
||||||
#we go away
|
elif state == common.sleepy.STATE_AWAY and \
|
||||||
self.roster.optionmenu.set_history(1)
|
self.connected[account] == 1 and \
|
||||||
self.send('STATUS', None, ('away', 'auto away (idle)'))
|
self.config['autoaway']:
|
||||||
elif state == common.sleepy.STATE_XAWAY and self.config['autoxa']:
|
#we go away
|
||||||
#we go extended away
|
self.send('STATUS', account, ('away', 'auto away (idle)'))
|
||||||
self.roster.optionmenu.set_history(2)
|
elif state == common.sleepy.STATE_XAWAY and \
|
||||||
self.send('STATUS',('xa', 'auto away (idel)'))
|
self.connected[account] == 2 and \
|
||||||
self.sleeper_state = state
|
self.config['autoxa']:
|
||||||
|
#we go extended away
|
||||||
|
self.send('STATUS', account, ('xa', 'auto away (idle)'))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def __init__(self, quIN, quOUT):
|
def __init__(self, quIN, quOUT):
|
||||||
|
@ -1392,6 +1397,7 @@ class plugin:
|
||||||
self.queues = {}
|
self.queues = {}
|
||||||
self.connected = {}
|
self.connected = {}
|
||||||
self.nicks = {}
|
self.nicks = {}
|
||||||
|
self.sleeper_state = {} #whether we pass auto away / xa or not
|
||||||
for a in self.accounts.keys():
|
for a in self.accounts.keys():
|
||||||
self.windows[a] = {}
|
self.windows[a] = {}
|
||||||
self.windows[a]['infos'] = {}
|
self.windows[a]['infos'] = {}
|
||||||
|
@ -1399,11 +1405,11 @@ class plugin:
|
||||||
self.queues[a] = {}
|
self.queues[a] = {}
|
||||||
self.connected[a] = 0
|
self.connected[a] = 0
|
||||||
self.nicks[a] = self.accounts[a]['name']
|
self.nicks[a] = self.accounts[a]['name']
|
||||||
|
self.sleeper_state[a] = 0
|
||||||
self.roster = roster_Window(self)
|
self.roster = roster_Window(self)
|
||||||
gtk.timeout_add(100, self.read_queue)
|
gtk.timeout_add(100, self.read_queue)
|
||||||
gtk.timeout_add(1000, self.read_sleepy)
|
gtk.timeout_add(1000, self.read_sleepy)
|
||||||
self.sleeper = None
|
self.sleeper = None
|
||||||
self.sleeper_state = None
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
gtk.threads_leave()
|
gtk.threads_leave()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
from distutils.core import setup, Extension
|
||||||
|
|
||||||
|
module1 = Extension( 'idle',
|
||||||
|
sources = ['common/idle.cpp'],
|
||||||
|
# extra_compile_args = ['-W'],
|
||||||
|
libraries = ['gtk-x11-2.0','gdk-x11-2.0','glib-2.0','X11','Xext','Xss','atk-1.0'],
|
||||||
|
library_dirs = ['/usr/X11R6/lib'],
|
||||||
|
include_dirs = ['/usr/include/gtk-2.0', '/usr/include/glib-2.0','/usr/lib/gtk-2.0/include','/usr/lib/glib-2.0/include','/usr/include/pango-1.0','/usr/include/atk-1.0']
|
||||||
|
)
|
||||||
|
|
||||||
|
setup (name = 'idle', version = '1.0', description = 'interface to X11/scrnserver.h', ext_modules = [module1])
|
Loading…
Reference in New Issue