Arch-Linux

i3 - 綁定程式碼 229 和 230 不工作

  • September 19, 2016

我正在嘗試在 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 -

當我嘗試~/.config/i3/config像這樣(使用者手冊)在我的 i3 配置文件中實現此功能時會出現問題:

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 230``showkey

這個答案的解決方案是這樣的:

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 +

引用自:https://unix.stackexchange.com/questions/310697