re-read device settings when they come back online

This commit is contained in:
Daniel Pavel 2012-12-07 21:00:36 +02:00
parent 5bdacb377c
commit 30fedf418c
4 changed files with 19 additions and 18 deletions

View File

@ -35,8 +35,8 @@ def _process_apply_queue():
value = setting.write(value) value = setting.write(value)
GObject.idle_add(_update_setting_item, sbox, value) GObject.idle_add(_update_setting_item, sbox, value)
elif task[0] == 'read': elif task[0] == 'read':
_, setting, sbox = task _, setting, sbox, cached = task
value = setting.read() value = setting.read(cached)
GObject.idle_add(_update_setting_item, sbox, value) GObject.idle_add(_update_setting_item, sbox, value)
from threading import Thread as _Thread from threading import Thread as _Thread
@ -155,22 +155,23 @@ def update(frame):
box.foreach(lambda x, _: box.remove(x), None) box.foreach(lambda x, _: box.remove(x), None)
return return
items = box.get_children()
if not items and not device.status:
# don't bother adding settings for offline devices,
# they're useless and might not guess all of them anyway
return
if not device.settings: if not device.settings:
# nothing to do here
return return
items = box.get_children() items = box.get_children()
if not items: if not items:
items = _add_settings(box, device) if device.status:
assert len(device.settings) == len(list(items)) items = _add_settings(box, device)
assert len(device.settings) == len(list(items))
else:
# don't bother adding settings for offline devices,
# they're useless and might not guess all of them anyway
return
device_active = bool(device.status) device_active = bool(device.status)
was_inactive = not box.get_sensitive()
box.set_sensitive(device_active) box.set_sensitive(device_active)
if device_active: if device_active:
for sbox, s in zip(items, device.settings): for sbox, s in zip(items, device.settings):
_apply_queue.put(('read', s, sbox)) _apply_queue.put(('read', s, sbox, was_inactive))

View File

@ -72,8 +72,8 @@ class SmoothScroll_Setting(_settings.Setting):
assert register is not None assert register is not None
self.register = register self.register = register
def read(self): def read(self, cached=True):
if self._value is None and self._device: if (self._value is None or not cached) and self._device:
ss = self.read_register() ss = self.read_register()
if ss: if ss:
self._value = (ss[:1] == b'\x40') self._value = (ss[:1] == b'\x40')
@ -96,8 +96,8 @@ class MouseDPI_Setting(_settings.Setting):
assert register is not None assert register is not None
self.register = register self.register = register
def read(self): def read(self, cached=True):
if self._value is None and self._device: if (self._value is None or not cached) and self._device:
dpi = self.read_register() dpi = self.read_register()
if dpi: if dpi:
value = ord(dpi[:1]) value = ord(dpi[:1])

View File

@ -302,8 +302,8 @@ class ToggleFN_Setting(_settings.Setting):
'When unset, the F1..F12 keys will activate their standard function,\n' 'When unset, the F1..F12 keys will activate their standard function,\n'
'and you must hold the FN key to activate their special function.') 'and you must hold the FN key to activate their special function.')
def read(self): def read(self, cached=True):
if self._value is None and self._device: if (self._value is None or not cached) and self._device:
fn = self._device.feature_request(FEATURE.FN_STATUS) fn = self._device.feature_request(FEATURE.FN_STATUS)
if fn: if fn:
self._value = (fn[:1] == b'\x01') self._value = (fn[:1] == b'\x01')

View File

@ -38,7 +38,7 @@ class Setting(object):
def write_register(self, value, value2=0): def write_register(self, value, value2=0):
return self._device.request(0x8000 | (self.register & 0x2FF), int(value) & 0xFF, int(value2) & 0xFF) return self._device.request(0x8000 | (self.register & 0x2FF), int(value) & 0xFF, int(value2) & 0xFF)
def read(self): def read(self, cached=True):
raise NotImplemented raise NotImplemented
def write(self, value): def write(self, value):