diff options
| author | Vasiliy Horbachenko <shadowprince47@gmail.com> | 2014-05-19 19:20:40 +0300 |
|---|---|---|
| committer | Vasiliy Horbachenko <shadowprince47@gmail.com> | 2014-05-19 19:20:40 +0300 |
| commit | 16324fdad587750dccdac52cf64c5bf15b5d227f (patch) | |
| tree | d8313b91524cae67352e652a87a71dac2dc913d5 | |
| parent | 26f0294c88adfa4f42baecea97b4ffc40c393ec4 (diff) | |
module for displaying current window\'s title
| -rw-r--r-- | modules/current-title.py | 47 | ||||
| -rw-r--r-- | modules/i3-current-title.py | 48 |
2 files changed, 95 insertions, 0 deletions
diff --git a/modules/current-title.py b/modules/current-title.py new file mode 100644 index 0000000..c9cdde9 --- /dev/null +++ b/modules/current-title.py @@ -0,0 +1,47 @@ +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): + 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:] or window["name"] + + return (0, response) diff --git a/modules/i3-current-title.py b/modules/i3-current-title.py new file mode 100644 index 0000000..6fc05d0 --- /dev/null +++ b/modules/i3-current-title.py @@ -0,0 +1,48 @@ +import i3 +import time +import random + +""" +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): + 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:] or window["name"] + + return (0, response) |
