diff options
| author | Ultrabug <ultrabug@ultrabug.net> | 2014-05-30 11:47:00 +0200 |
|---|---|---|
| committer | Ultrabug <ultrabug@ultrabug.net> | 2014-05-30 11:47:00 +0200 |
| commit | 5915d144132b9d4c614cb7d2e3a3610777b4548e (patch) | |
| tree | 734e05cee6d6d9e88255bba61764d6c6856f9ac9 /modules/window-title.py | |
| parent | f1ea709cd33acecc382e56b02d0f36ba747b8892 (diff) | |
| parent | e42f84cb9954942b3b604a05fb1933b54ecef5f4 (diff) | |
Merge pull request #33 from ShadowPrince/master
new modules keyboard-layout, battery-level, mpd_status, scratchpad-counter and window-title by @ShadowPrince
Diffstat (limited to 'modules/window-title.py')
| -rw-r--r-- | modules/window-title.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/modules/window-title.py b/modules/window-title.py new file mode 100644 index 0000000..4f6f062 --- /dev/null +++ b/modules/window-title.py @@ -0,0 +1,58 @@ +import i3 +from time import time + +""" +Py3status plugin - shows current window title. + +Requires: + - i3-py (https://github.com/ziberna/i3-py) + # pip install i3-py + +If payload from server contains wierd utf-8 +(for example one window have something bad in title) - the plugin will +give empty output UNTIL this window is closed. +I can't fix or workaround that in PLUGIN, problem is in i3-py library. + +@author shadowprince +@license Eclipse Public License +""" + +CACHE_TIMEOUT = 0.5 # maximum time to update indicator +MAX_WIDTH = 120 # if width of title is greater, shrink it and add '...' +POSITION = 0 + + +def find_focused(tree): + if type(tree) == list: + for el in tree: + res = find_focused(el) + if res: + return res + + elif type(tree) == dict: + if tree['focused']: + return tree + else: + return find_focused(tree['nodes'] + tree['floating_nodes']) + + +class Py3status: + def __init__(self): + self.text = '' + + def window_title(self, i3_status_output_json, i3status_config): + window = find_focused(i3.get_tree()) + + transformed = False + if window and 'name' in window and window['name'] != self.text: + self.text = len(window['name']) > MAX_WIDTH and "..." + window['name'][-(MAX_WIDTH-3):] or window['name'] + transformed = True + + response = { + 'cached_until': time() + CACHE_TIMEOUT, + 'full_text': self.text, + 'name': 'window-title', + 'transformed': transformed + } + + return (POSITION, response) |
