From 22c6e31ac61327b879659da4b36e180861e1e947 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 17 Apr 2017 03:09:43 +0200 Subject: [PATCH] Add caps lock indicator to i3status bar. --- bin/i3status_wrapper.py | 26 +++++++++++++++++++++++ dotfiles/user/thinkpad/W530/i3status.conf | 4 ++-- dotfiles/user/thinkpad/minimal/i3 | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 bin/i3status_wrapper.py diff --git a/bin/i3status_wrapper.py b/bin/i3status_wrapper.py new file mode 100755 index 0000000..aa7b7c2 --- /dev/null +++ b/bin/i3status_wrapper.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Inspired by http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.py + +import sys +import json +import subprocess + +def print_nonbuffered(message): + sys.stdout.write(message) + sys.stdout.flush() + +if __name__ == '__main__': + print_nonbuffered(sys.stdin.readline()) + print_nonbuffered(sys.stdin.readline()) + while True: + line, prefix = sys.stdin.readline(), '' + if line.startswith(','): + line, prefix = line[1:], ',' + j = json.loads(line) + if '1' == subprocess.getoutput('xset q | grep LED')[65]: + j.insert(len(j), {'full_text' : 'CAPS', + 'separator_block_width': 40, + 'color': '#FF0000'}) + print_nonbuffered(prefix+json.dumps(j)) diff --git a/dotfiles/user/thinkpad/W530/i3status.conf b/dotfiles/user/thinkpad/W530/i3status.conf index db87c5a..f566ffe 100644 --- a/dotfiles/user/thinkpad/W530/i3status.conf +++ b/dotfiles/user/thinkpad/W530/i3status.conf @@ -2,8 +2,8 @@ # Activate colors; set update interval of one second. general { - colors = true - interval = 1 + colors = true + interval = 1 } # Selection / order of status elements. diff --git a/dotfiles/user/thinkpad/minimal/i3 b/dotfiles/user/thinkpad/minimal/i3 index b7177b2..a0e6c43 100644 --- a/dotfiles/user/thinkpad/minimal/i3 +++ b/dotfiles/user/thinkpad/minimal/i3 @@ -79,5 +79,5 @@ bindsym $mod+Shift+P exit # Select "i3status" as i3 status bar. bar { - status_command i3status + status_command i3status | ~/config/bin/i3status_wrapper.py } -- 2.30.2