diff options
| author | Vasiliy Horbachenko <shadowprince47@gmail.com> | 2014-05-19 19:34:51 +0300 |
|---|---|---|
| committer | Vasiliy Horbachenko <shadowprince47@gmail.com> | 2014-05-19 19:34:51 +0300 |
| commit | 1ff108ea4931ccf31da7d724298c52de9a839913 (patch) | |
| tree | ecb800bc960deeb373bfc8dc155069695064e1c4 /modules | |
| parent | 3c4b686cabc4c48325b09f158b65f5adf61bb3a6 (diff) | |
module for displaying current window\'s title
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/current-title.py | 13 | ||||
| -rw-r--r-- | modules/x/current-title.py | 44 |
2 files changed, 49 insertions, 8 deletions
diff --git a/modules/current-title.py b/modules/current-title.py index f995752..16248d1 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -33,15 +33,12 @@ def find_focused(tree): class Py3status: def currentTitle(self, json, i3status_config): - response = { - 'full_text': 'error', - 'name': 'current-title', - 'cached_until': time.time() + CACHED_TIME - } - window = find_focused(i3.get_tree()) if window and "name" in window: - response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] + text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] - return (0, response) + return (0, {'full_text': text, + 'name': 'current-title', + 'cached_until': time.time() + CACHED_TIME, + }) diff --git a/modules/x/current-title.py b/modules/x/current-title.py new file mode 100644 index 0000000..16248d1 --- /dev/null +++ b/modules/x/current-title.py @@ -0,0 +1,44 @@ +import i3 +import time + +""" +Shows current window title. + +DEPENDENCIES: + Depends on i3-py! + pip install i3-py + +CONFIG: + MAX_WIDTH - max title width + CACHED_TIME - in seconds + +If payload from server contains wierd utf-8 (for example one window have something bad in title) - plugin will give empty output UNTIL this window will be closed. I can't fix or workaround that in PLUGIN, problem is in i3-py library. +""" + +MAX_WIDTH = 120 +CACHED_TIME = 0.5 + +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 currentTitle(self, json, i3status_config): + window = find_focused(i3.get_tree()) + + if window and "name" in window: + text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] + + return (0, {'full_text': text, + 'name': 'current-title', + 'cached_until': time.time() + CACHED_TIME, + }) |
