Add 'output' option to segments.i3wm.workspaces

This commit is contained in:
S0lll0s 2015-08-21 17:50:27 +02:00
parent ab9c2bd840
commit 918dd957cf
2 changed files with 21 additions and 6 deletions

View File

@ -19,7 +19,7 @@ def calcgrp(w):
return group return group
def workspaces(pl, only_show=None, strip=0): def workspaces(pl, only_show=None, output=None, strip=0):
'''Return list of used workspaces '''Return list of used workspaces
:param list only_show: :param list only_show:
@ -27,6 +27,9 @@ def workspaces(pl, only_show=None, strip=0):
``"urgent"`` and ``"focused"``. If omitted or ``null`` all workspaces ``"urgent"`` and ``"focused"``. If omitted or ``null`` all workspaces
are shown. are shown.
:param str output:
If specified, only workspaces on this output are shown.
:param int strip: :param int strip:
Specifies how many characters from the front of each workspace name Specifies how many characters from the front of each workspace name
should be stripped (e.g. to remove workspace numbers). Defaults to zero. should be stripped (e.g. to remove workspace numbers). Defaults to zero.
@ -45,7 +48,10 @@ def workspaces(pl, only_show=None, strip=0):
return [{ return [{
'contents': w['name'][min(len(w['name']), strip):], 'contents': w['name'][min(len(w['name']), strip):],
'highlight_groups': calcgrp(w) 'highlight_groups': calcgrp(w)
} for w in conn.get_workspaces() if not only_show or any((w[typ] for typ in only_show))] } for w in conn.get_workspaces()
if (not only_show or any(w[typ] for typ in only_show))
and (not output or w['output'] == output)
]
@requires_segment_info @requires_segment_info

View File

@ -819,10 +819,10 @@ class TestI3WM(TestCase):
def test_workspaces(self): def test_workspaces(self):
pl = Pl() pl = Pl()
with replace_attr(i3wm, 'conn', Args(get_workspaces=lambda: iter([ with replace_attr(i3wm, 'conn', Args(get_workspaces=lambda: iter([
{'name': '1: w1', 'focused': False, 'urgent': False, 'visible': False}, {'name': '1: w1', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': False},
{'name': '2: w2', 'focused': False, 'urgent': False, 'visible': True}, {'name': '2: w2', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': True},
{'name': '3: w3', 'focused': False, 'urgent': True, 'visible': True}, {'name': '3: w3', 'output': 'HDMI1', 'focused': False, 'urgent': True, 'visible': True},
{'name': '4: w4', 'focused': True, 'urgent': True, 'visible': True}, {'name': '4: w4', 'output': 'DVI01', 'focused': True, 'urgent': True, 'visible': True},
]))): ]))):
self.assertEqual(i3wm.workspaces(pl=pl), [ self.assertEqual(i3wm.workspaces(pl=pl), [
{'contents': '1: w1', 'highlight_groups': ['workspace']}, {'contents': '1: w1', 'highlight_groups': ['workspace']},
@ -850,6 +850,15 @@ class TestI3WM(TestCase):
{'contents': 'w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']}, {'contents': 'w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
{'contents': 'w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']}, {'contents': 'w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
]) ])
self.assertEqual(i3wm.workspaces(pl=pl, only_show=['focused', 'urgent'], output='DVI01'), [
{'contents': '4: w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']},
])
self.assertEqual(i3wm.workspaces(pl=pl, only_show=['visible'], output='HDMI1'), [
{'contents': '3: w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']},
])
self.assertEqual(i3wm.workspaces(pl=pl, only_show=['visible'], strip=3, output='LVDS1'), [
{'contents': 'w2', 'highlight_groups': ['w_visible', 'workspace']},
])
def test_mode(self): def test_mode(self):
pl = Pl() pl = Pl()