[~] Refactor
This commit is contained in:
parent
068b24649f
commit
8da6332743
@ -1292,6 +1292,22 @@ def player_v1(folder_url, item_id):
|
|||||||
assert p.returncode == 0
|
assert p.returncode == 0
|
||||||
progress_bar.update(1)
|
progress_bar.update(1)
|
||||||
|
|
||||||
|
def numpy_linspace(a, b, count):
|
||||||
|
pos = a
|
||||||
|
step = (b - a) / count
|
||||||
|
steps = []
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
if i == 0:
|
||||||
|
pos = a
|
||||||
|
elif i == count - 1:
|
||||||
|
pos = b
|
||||||
|
else:
|
||||||
|
pos = a + i * step
|
||||||
|
steps.append(pos)
|
||||||
|
|
||||||
|
return steps
|
||||||
|
|
||||||
def desktop_services(argv):
|
def desktop_services(argv):
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
@ -1321,6 +1337,13 @@ def desktop_services(argv):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='increase keyboard backlight',
|
help='increase keyboard backlight',
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
'--backlight-type',
|
||||||
|
dest='backlight_type',
|
||||||
|
default=[],
|
||||||
|
action='append',
|
||||||
|
help='backlight type, like keyboard, output',
|
||||||
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'--backlight-decrease',
|
'--backlight-decrease',
|
||||||
dest='backlight_decrease',
|
dest='backlight_decrease',
|
||||||
@ -1469,6 +1492,14 @@ def desktop_services(argv):
|
|||||||
self.state = Backlight.change(
|
self.state = Backlight.change(
|
||||||
Backlight.Direction.get_state,
|
Backlight.Direction.get_state,
|
||||||
)
|
)
|
||||||
|
logging.info(json.dumps(dict(
|
||||||
|
state=pprint.pformat(
|
||||||
|
self.state,
|
||||||
|
width=1e+8,
|
||||||
|
compact=True,
|
||||||
|
),
|
||||||
|
action='disable',
|
||||||
|
)))
|
||||||
Backlight.disable()
|
Backlight.disable()
|
||||||
self.dpms = new_dpms
|
self.dpms = new_dpms
|
||||||
except:
|
except:
|
||||||
@ -1484,7 +1515,10 @@ def desktop_services(argv):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def disable(cls):
|
def disable(cls):
|
||||||
return cls.change(cls.Direction.absolute, 0)
|
return cls.change(
|
||||||
|
cls.Direction.absolute,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enable(cls, state,):
|
def enable(cls, state,):
|
||||||
@ -1500,28 +1534,81 @@ def desktop_services(argv):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def change(cls, direction, value=None, device_name=None,):
|
def change(
|
||||||
|
cls,
|
||||||
|
direction,
|
||||||
|
value=None,
|
||||||
|
devices=None,
|
||||||
|
device_name=None,
|
||||||
|
types=None,
|
||||||
|
):
|
||||||
assert isinstance(direction, Backlight.Direction)
|
assert isinstance(direction, Backlight.Direction)
|
||||||
|
|
||||||
state = []
|
state = []
|
||||||
devices = dict(
|
devices_all = dict(
|
||||||
smc_kbd='sysfs/leds/smc::kbd_backlight',
|
smc_kbd=dict(
|
||||||
|
sysfs_path='sysfs/leds/smc::kbd_backlight',
|
||||||
|
),
|
||||||
|
intel_backlight=dict(
|
||||||
|
sysfs_path='sysfs/backlight/intel_backlight',
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if devices is None:
|
||||||
|
devices = []
|
||||||
|
|
||||||
|
if not device_name is None:
|
||||||
|
devices.append(device_name)
|
||||||
|
|
||||||
|
if len(devices) == 0:
|
||||||
|
if types is None:
|
||||||
|
types = [
|
||||||
|
'keyboard',
|
||||||
|
'output',
|
||||||
|
]
|
||||||
|
|
||||||
|
for current_type in types:
|
||||||
|
if current_type == 'keyboard':
|
||||||
|
devices.extend([
|
||||||
|
'smc_kbd'
|
||||||
|
])
|
||||||
|
elif current_type == 'output':
|
||||||
|
devices.extend([
|
||||||
|
'intel_backlight',
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
else:
|
||||||
|
assert types is None
|
||||||
|
|
||||||
|
devices2 = list(set(devices))
|
||||||
|
|
||||||
if sys.platform == 'linux':
|
if sys.platform == 'linux':
|
||||||
if device_name is None:
|
assert all([
|
||||||
device_name = 'smc_kbd'
|
o in devices_all
|
||||||
|
for o in devices2
|
||||||
|
])
|
||||||
|
|
||||||
leds = \
|
leds = \
|
||||||
[
|
[
|
||||||
o.strip()
|
o.strip()
|
||||||
for o in subprocess.check_output(['light', '-L'])\
|
for o in subprocess.check_output(
|
||||||
|
['light', '-L'],
|
||||||
|
timeout=1,
|
||||||
|
)\
|
||||||
.decode('utf-8')\
|
.decode('utf-8')\
|
||||||
.splitlines()[1:]
|
.splitlines()[1:]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
if devices['smc_kbd'] in leds:
|
for current_device_name in devices2:
|
||||||
|
device = devices_all[current_device_name]
|
||||||
|
|
||||||
|
sysfs_path = device['sysfs_path']
|
||||||
|
|
||||||
|
if not sysfs_path in leds:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
extra_args = []
|
extra_args = []
|
||||||
if value is None:
|
if value is None:
|
||||||
value = 20.0
|
value = 20.0
|
||||||
@ -1535,32 +1622,69 @@ def desktop_services(argv):
|
|||||||
elif direction == cls.Direction.decrease:
|
elif direction == cls.Direction.decrease:
|
||||||
extra_args.extend(['-U', '%f' % value2])
|
extra_args.extend(['-U', '%f' % value2])
|
||||||
elif direction == cls.Direction.absolute:
|
elif direction == cls.Direction.absolute:
|
||||||
extra_args.extend(['-S', '%f' % float(value)])
|
extra_args.extend(['-S', '%f' % value2])
|
||||||
elif direction == cls.Direction.get_state:
|
elif direction == cls.Direction.get_state:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
get_current = lambda : float(subprocess.check_output([
|
||||||
|
'light', '-G',
|
||||||
|
'-s', sysfs_path,
|
||||||
|
], timeout=1).decode('utf-8'))
|
||||||
|
|
||||||
if not (direction == cls.Direction.get_state):
|
if not (direction == cls.Direction.get_state):
|
||||||
subprocess.check_call([
|
old_value = get_current()
|
||||||
'light', '-v', '3',
|
|
||||||
'-s', devices['smc_kbd'],
|
value_steps = None
|
||||||
*extra_args,
|
|
||||||
], stdout=subprocess.PIPE)
|
if direction == cls.Direction.decrease:
|
||||||
|
value_steps = numpy_linspace(
|
||||||
|
old_value,
|
||||||
|
max(old_value - value2, 0),
|
||||||
|
10,
|
||||||
|
)
|
||||||
|
elif direction == cls.Direction.increase:
|
||||||
|
value_steps = numpy_linspace(
|
||||||
|
old_value,
|
||||||
|
min(old_value + value2, 100),
|
||||||
|
10,
|
||||||
|
)
|
||||||
|
elif direction == cls.Direction.absolute:
|
||||||
|
value_steps = numpy_linspace(
|
||||||
|
old_value,
|
||||||
|
min(
|
||||||
|
max(
|
||||||
|
0,
|
||||||
|
value2,
|
||||||
|
),
|
||||||
|
100
|
||||||
|
),
|
||||||
|
10,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
for current_value in value_steps:
|
||||||
|
subprocess.check_call(
|
||||||
|
[
|
||||||
|
'light', '-v', '3',
|
||||||
|
'-s', sysfs_path,
|
||||||
|
'-S', '%f' % current_value,
|
||||||
|
],
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE
|
||||||
|
)
|
||||||
|
time.sleep(0.05)
|
||||||
|
|
||||||
state.append(
|
state.append(
|
||||||
dict(
|
dict(
|
||||||
mode=cls.Mode.light,
|
mode=cls.Mode.light,
|
||||||
device_path=devices['smc_kbd'],
|
device_path=sysfs_path,
|
||||||
device_name='smc_kbd',
|
device_name=current_device_name,
|
||||||
value=float(subprocess.check_output([
|
value=get_current(),
|
||||||
'light', '-G',
|
|
||||||
'-s', devices['smc_kbd'],
|
|
||||||
]).decode('utf-8')),
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise NotImplementedError
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -1576,6 +1700,7 @@ def desktop_services(argv):
|
|||||||
|
|
||||||
Backlight.change(
|
Backlight.change(
|
||||||
direction=direction,
|
direction=direction,
|
||||||
|
types=options.backlight_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -73,8 +73,30 @@ input type:touchpad {
|
|||||||
#
|
#
|
||||||
bindsym $mod+Shift+l exec loginctl list-sessions | tail '-n' +2 | head -n -2 | awk '{print $1}' | xargs loginctl lock-session
|
bindsym $mod+Shift+l exec loginctl list-sessions | tail '-n' +2 | head -n -2 | awk '{print $1}' | xargs loginctl lock-session
|
||||||
|
|
||||||
bindsym XF86KbdBrightnessDown exec bash -c "commands desktop-services --backlight-decrease"
|
bindsym XF86KbdBrightnessDown \
|
||||||
bindsym XF86KbdBrightnessUp exec bash -c "commands desktop-services --backlight-increase"
|
exec commands \
|
||||||
|
desktop-services \
|
||||||
|
--backlight-decrease \
|
||||||
|
--backlight-type keyboard
|
||||||
|
|
||||||
|
bindsym XF86KbdBrightnessUp \
|
||||||
|
exec commands \
|
||||||
|
desktop-services \
|
||||||
|
--backlight-increase \
|
||||||
|
--backlight-type keyboard
|
||||||
|
|
||||||
|
bindsym XF86MonBrightnessDown \
|
||||||
|
exec commands \
|
||||||
|
desktop-services \
|
||||||
|
--backlight-decrease \
|
||||||
|
--backlight-type output
|
||||||
|
|
||||||
|
bindsym XF86MonBrightnessUp \
|
||||||
|
exec commands \
|
||||||
|
desktop-services \
|
||||||
|
--backlight-increase \
|
||||||
|
--backlight-type output
|
||||||
|
|
||||||
bindsym XF86AudioPlay exec bash -c "commands media-play-pause"
|
bindsym XF86AudioPlay exec bash -c "commands media-play-pause"
|
||||||
bindsym XF86AudioNext exec bash -c "commands media-next"
|
bindsym XF86AudioNext exec bash -c "commands media-next"
|
||||||
bindsym XF86AudioPrev exec bash -c "commands media-prev"
|
bindsym XF86AudioPrev exec bash -c "commands media-prev"
|
||||||
|
Loading…
Reference in New Issue
Block a user