i3 - 绑定代码 229 和 230 不起作用

i3 - 绑定代码 229 和 230 不起作用

我正在尝试在 Arch Linux 上启用键盘 LED,并且这里我发现了这个不错的脚本:

#!/usr/bin/env python3
# coding: utf-8

from sys import argv
import dbus


def kb_light_set(delta):
    bus = dbus.SystemBus()
    kbd_backlight_proxy = bus.get_object('org.freedesktop.UPower', '/org/freedesktop/UPower/KbdBacklight')
    kbd_backlight = dbus.Interface(kbd_backlight_proxy, 'org.freedesktop.UPower.KbdBacklight')

    current = kbd_backlight.GetBrightness()
    maximum = kbd_backlight.GetMaxBrightness()
    new = max(0, current + delta)

    if new >= 0 and new <= maximum:
        current = new
        kbd_backlight.SetBrightness(current)

    # Return current backlight level percentage
    return 100 * current / maximum

if __name__ == '__main__':
    if len(argv[1:]) == 1:
        if argv[1] == "--up" or argv[1] == "+":
            # ./kb-light.py (+|--up) to increment
            print(kb_light_set(1))
        elif argv[1] == "--down" or argv[1] == "-":
            # ./kb-light.py (-|--down) to decrement
            print(kb_light_set(-1))
        else:
            print("Unknown argument:", argv[1])
    else:
        print("Script takes exactly one argument.", len(argv[1:]), "arguments provided.")

如果我将其放入~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/,使其可执行并使用以下命令之一启动它,则它会起作用:

~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py +
~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py -

当我尝试在我的 i3 配置文件中实现此功能时,会出现问题,~/.config/i3/config如下所示(用户手册):

bindcode 229 exec "~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py -"
bindcode 230 exec "~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py +"

如果我退出 i3 窗口管理器,使用命令,然后按我想要绑定命令的键,我可以确认bindcode 229和数字。这两个键没有在其他地方使用过,但这不起作用。 bindcode 230showkey

答案1

这个答案的解决方案是这样的:

bindsym XF86KbdBrightnessDown exec --no-startup-id ~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py -
bindsym XF86KbdBrightnessUp exec --no-startup-id ~/Dropbox/workspace/operacijski/archlinux/keyboard_backlights/kb-light.py +

相关内容