From f710a87ba68bdb9bbcaa161f78f38e9ba649f022 Mon Sep 17 00:00:00 2001 From: s-ol Date: Wed, 9 Mar 2016 22:17:31 +0100 Subject: [PATCH] Add segments.i3wm.scratchpad --- powerline/config_files/themes/ascii.json | 9 ++++ powerline/config_files/themes/powerline.json | 9 ++++ .../themes/powerline_unicode7.json | 9 ++++ powerline/config_files/themes/unicode.json | 9 ++++ .../config_files/themes/unicode_terminus.json | 9 ++++ .../themes/unicode_terminus_condensed.json | 9 ++++ powerline/segments/i3wm.py | 44 +++++++++++++++++-- 7 files changed, 95 insertions(+), 3 deletions(-) diff --git a/powerline/config_files/themes/ascii.json b/powerline/config_files/themes/ascii.json index 9e876734..7b12d446 100644 --- a/powerline/config_files/themes/ascii.json +++ b/powerline/config_files/themes/ascii.json @@ -131,6 +131,15 @@ "args": { "text": "+" } + }, + + "powerline.segments.i3wm.scratchpad": { + "args": { + "icons": { + "fresh": "O", + "changed": "X" + } + } } } } diff --git a/powerline/config_files/themes/powerline.json b/powerline/config_files/themes/powerline.json index c33b5c1f..4ca9f0ee 100644 --- a/powerline/config_files/themes/powerline.json +++ b/powerline/config_files/themes/powerline.json @@ -129,6 +129,15 @@ "args": { "text": "+" } + }, + + "powerline.segments.i3wm.scratchpad": { + "args": { + "icons": { + "fresh": "●", + "changed": "○" + } + } } } } diff --git a/powerline/config_files/themes/powerline_unicode7.json b/powerline/config_files/themes/powerline_unicode7.json index bfa86fe0..d470d3a9 100644 --- a/powerline/config_files/themes/powerline_unicode7.json +++ b/powerline/config_files/themes/powerline_unicode7.json @@ -143,6 +143,15 @@ "args": { "text": "🖫⃥" } + }, + + "powerline.segments.i3wm.scratchpad": { + "args": { + "icons": { + "fresh": "●", + "changed": "○" + } + } } } } diff --git a/powerline/config_files/themes/unicode.json b/powerline/config_files/themes/unicode.json index eadfc870..4b52fd3b 100644 --- a/powerline/config_files/themes/unicode.json +++ b/powerline/config_files/themes/unicode.json @@ -129,6 +129,15 @@ "args": { "text": "+" } + }, + + "powerline.segments.i3wm.scratchpad": { + "args": { + "icons": { + "fresh": "●", + "changed": "○" + } + } } } } diff --git a/powerline/config_files/themes/unicode_terminus.json b/powerline/config_files/themes/unicode_terminus.json index 8c1e045a..b7b005e4 100644 --- a/powerline/config_files/themes/unicode_terminus.json +++ b/powerline/config_files/themes/unicode_terminus.json @@ -129,6 +129,15 @@ "args": { "text": "+" } + }, + + "powerline.segments.i3wm.scratchpad": { + "args": { + "icons": { + "fresh": "●", + "changed": "○" + } + } } } } diff --git a/powerline/config_files/themes/unicode_terminus_condensed.json b/powerline/config_files/themes/unicode_terminus_condensed.json index 1c567dc7..fc9e90aa 100644 --- a/powerline/config_files/themes/unicode_terminus_condensed.json +++ b/powerline/config_files/themes/unicode_terminus_condensed.json @@ -130,6 +130,15 @@ "args": { "text": "+" } + }, + + "powerline.segments.i3wm.scratchpad": { + "args": { + "icons": { + "fresh": "●", + "changed": "○" + } + } } } } diff --git a/powerline/segments/i3wm.py b/powerline/segments/i3wm.py index eb0d3c44..3f508ee2 100644 --- a/powerline/segments/i3wm.py +++ b/powerline/segments/i3wm.py @@ -10,7 +10,7 @@ from powerline.bindings.wm import get_i3_connection WORKSPACE_REGEX = re.compile(r'^[0-9]+: ?') -def calcgrp(w): +def workspace_groups(w): group = [] if w['focused']: group.append('w_focused') @@ -53,7 +53,7 @@ def workspaces(pl, segment_info, only_show=None, output=None, strip=0): return [ { 'contents': w['name'][strip:], - 'highlight_groups': calcgrp(w) + 'highlight_groups': workspace_groups(w) } for w in get_i3_connection().get_workspaces() if ((not only_show or any(w[typ] for typ in only_show)) @@ -97,7 +97,7 @@ def workspace(pl, segment_info, workspace=None, strip=False): return [{ 'contents': format_name(w['name'], strip=strip), - 'highlight_groups': calcgrp(w) + 'highlight_groups': workspace_groups(w) }] @@ -115,3 +115,41 @@ def mode(pl, segment_info, names={'default': None}): if mode in names: return names[mode] return mode + + +def scratchpad_groups(w): + group = [] + if w.urgent: + group.append('scratchpad:urgent') + if w.nodes[0].focused: + group.append('scratchpad:focused') + if w.workspace().name != '__i3_scratch': + group.append('scratchpad:visible') + group.append('scratchpad') + return group + + +SCRATCHPAD_ICONS = { + 'fresh': 'O', + 'changed': 'X', +} + + +def scratchpad(pl, icons=SCRATCHPAD_ICONS): + '''Returns the windows currently on the scratchpad + + :param dict icons: + Specifies the strings to show for the different scratchpad window states. Must + contain the keys ``fresh`` and ``changed``. + + Highlight groups used: ``scratchpad`` or ``scratchpad:visible``, ``scratchpad`` or ``scratchpad:focused``, ``scratchpad`` or ``scratchpad:urgent``. + ''' + + return [ + { + 'contents': icons.get(w.scratchpad_state, icons['changed']), + 'highlight_groups': scratchpad_groups(w) + } + for w in get_i3_connection().get_tree().descendents() + if w.scratchpad_state != 'none' + ]