mirror of
https://github.com/powerline/powerline.git
synced 2025-07-28 16:24:57 +02:00
Use updated i3ipc syntax in i3 segments/listers (#2062)
Close #2046 Co-authored-by: s-ol <s-ol@users.noreply.github.com>
This commit is contained in:
parent
c31f83f831
commit
1869cc8bed
@ -528,10 +528,10 @@ i3wm
|
||||
in lemonbar bindings.
|
||||
|
||||
``workspace``
|
||||
dictionary containing the workspace name under the key ``"name"`` and
|
||||
boolean values for the ``"visible"``, ``"urgent"`` and ``"focused"``
|
||||
keys, indicating the state of the workspace. Currently only provided by
|
||||
the :py:func:`powerline.listers.i3wm.workspace_lister` lister.
|
||||
the `i3-ipc` workspace object corresponding to this workspace.
|
||||
Contains string attributes ``name`` and ``output``, as well as boolean
|
||||
attributes for ``visible``, ``urgent`` and ``focused``. Currently only
|
||||
provided by the :py:func:`powerline.listers.i3wm.workspace_lister` lister.
|
||||
|
||||
Segment class
|
||||
=============
|
||||
|
@ -77,8 +77,7 @@ to run with i3, simply ``exec`` this in the i3 config file and set the ``--i3``
|
||||
|
||||
exec python /path/to/powerline/bindings/lemonbar/powerline-lemonbar.py --i3
|
||||
|
||||
Running the binding in i3-mode will require `i3ipc <https://github.com/acrisci/i3ipc-python>`_
|
||||
(or the outdated `i3-py <https://github.com/ziberna/i3-py>`_).
|
||||
Running the binding in i3-mode will require `i3ipc <https://github.com/acrisci/i3ipc-python>`_.
|
||||
|
||||
See the `lemonbar documentation <https://github.com/LemonBoy/bar>`_ for more
|
||||
information and options.
|
||||
|
@ -24,15 +24,6 @@ def i3_subscribe(conn, event, callback):
|
||||
:param func callback:
|
||||
Function to run on event.
|
||||
'''
|
||||
try:
|
||||
import i3ipc
|
||||
except ImportError:
|
||||
import i3
|
||||
conn.Subscription(callback, event)
|
||||
return
|
||||
else:
|
||||
pass
|
||||
|
||||
conn.on(event, callback)
|
||||
|
||||
from threading import Thread
|
||||
@ -57,12 +48,8 @@ def get_i3_connection():
|
||||
'''
|
||||
global conn
|
||||
if not conn:
|
||||
try:
|
||||
import i3ipc
|
||||
except ImportError:
|
||||
import i3 as conn
|
||||
else:
|
||||
conn = i3ipc.Connection()
|
||||
import i3ipc
|
||||
conn = i3ipc.Connection()
|
||||
return conn
|
||||
|
||||
|
||||
|
@ -50,19 +50,14 @@ def workspace_lister(pl, segment_info, only_show=None, output=None):
|
||||
(
|
||||
updated(
|
||||
segment_info,
|
||||
output=w['output'],
|
||||
workspace={
|
||||
'name': w['name'],
|
||||
'visible': w['visible'],
|
||||
'urgent': w['urgent'],
|
||||
'focused': w['focused'],
|
||||
},
|
||||
output=w.output,
|
||||
workspace=w,
|
||||
),
|
||||
{
|
||||
'draw_inner_divider': None
|
||||
}
|
||||
)
|
||||
for w in get_i3_connection().get_workspaces()
|
||||
if (((not only_show or any(w[typ] for typ in only_show))
|
||||
and (not output or w['output'] == output)))
|
||||
if (((not only_show or any(getattr(w, typ) for typ in only_show))
|
||||
and (not output or w.output == output)))
|
||||
)
|
||||
|
@ -12,11 +12,11 @@ WORKSPACE_REGEX = re.compile(r'^[0-9]+: ?')
|
||||
|
||||
def workspace_groups(w):
|
||||
group = []
|
||||
if w['focused']:
|
||||
if w.focused:
|
||||
group.append('w_focused')
|
||||
if w['urgent']:
|
||||
if w.urgent:
|
||||
group.append('w_urgent')
|
||||
if w['visible']:
|
||||
if w.visible:
|
||||
group.append('w_visible')
|
||||
group.append('workspace')
|
||||
return group
|
||||
@ -52,12 +52,12 @@ def workspaces(pl, segment_info, only_show=None, output=None, strip=0):
|
||||
|
||||
return [
|
||||
{
|
||||
'contents': w['name'][strip:],
|
||||
'contents': w.name[strip:],
|
||||
'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))
|
||||
and (not output or w['output'] == output))
|
||||
if ((not only_show or any(getattr(w, typ) for typ in only_show))
|
||||
and (not output or w.output == output))
|
||||
]
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ def workspace(pl, segment_info, workspace=None, strip=False):
|
||||
try:
|
||||
w = next((
|
||||
w for w in get_i3_connection().get_workspaces()
|
||||
if w['name'] == workspace
|
||||
if w.name == workspace
|
||||
))
|
||||
except StopIteration:
|
||||
return None
|
||||
@ -90,13 +90,13 @@ def workspace(pl, segment_info, workspace=None, strip=False):
|
||||
try:
|
||||
w = next((
|
||||
w for w in get_i3_connection().get_workspaces()
|
||||
if w['focused']
|
||||
if w.focused
|
||||
))
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
return [{
|
||||
'contents': format_name(w['name'], strip=strip),
|
||||
'contents': format_name(w.name, strip=strip),
|
||||
'highlight_groups': workspace_groups(w)
|
||||
}]
|
||||
|
||||
@ -150,6 +150,6 @@ def scratchpad(pl, icons=SCRATCHPAD_ICONS):
|
||||
'contents': icons.get(w.scratchpad_state, icons['changed']),
|
||||
'highlight_groups': scratchpad_groups(w)
|
||||
}
|
||||
for w in get_i3_connection().get_tree().descendents()
|
||||
for w in get_i3_connection().get_tree().descendants()
|
||||
if w.scratchpad_state != 'none'
|
||||
]
|
||||
|
@ -8,14 +8,16 @@ from tests.modules import TestCase
|
||||
|
||||
|
||||
class TestI3WM(TestCase):
|
||||
workspaces = [
|
||||
Args(name='1: w1', output='LVDS1', focused=False, urgent=False, visible=False),
|
||||
Args(name='2: w2', output='LVDS1', focused=False, urgent=False, visible=True),
|
||||
Args(name='3: w3', output='HDMI1', focused=False, urgent=True, visible=True),
|
||||
Args(name='4: w4', output='DVI01', focused=True, urgent=True, visible=True),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def get_workspaces():
|
||||
return iter([
|
||||
{'name': '1: w1', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': False},
|
||||
{'name': '2: w2', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': True},
|
||||
{'name': '3: w3', 'output': 'HDMI1', 'focused': False, 'urgent': True, 'visible': True},
|
||||
{'name': '4: w4', 'output': 'DVI01', 'focused': True, 'urgent': True, 'visible': True},
|
||||
])
|
||||
return iter(TestI3WM.workspaces)
|
||||
|
||||
@staticmethod
|
||||
def get_outputs(pl):
|
||||
@ -46,42 +48,22 @@ class TestI3WM(TestCase):
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '1: w1',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': False
|
||||
}
|
||||
'workspace': self.workspaces[0],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '2: w2',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[1],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'HDMI1',
|
||||
'workspace': {
|
||||
'name': '3: w3',
|
||||
'focused': False,
|
||||
'urgent': True,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[2],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'DVI01',
|
||||
'workspace': {
|
||||
'name': '4: w4',
|
||||
'focused': True,
|
||||
'urgent': True,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[3],
|
||||
}, {'draw_inner_divider': None}),
|
||||
]
|
||||
)
|
||||
@ -92,22 +74,12 @@ class TestI3WM(TestCase):
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '1: w1',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': False
|
||||
}
|
||||
'workspace': self.workspaces[0],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '2: w2',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[1],
|
||||
}, {'draw_inner_divider': None}),
|
||||
]
|
||||
)
|
||||
@ -121,22 +93,12 @@ class TestI3WM(TestCase):
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '1: w1',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': False
|
||||
}
|
||||
'workspace': self.workspaces[0],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '2: w2',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[1],
|
||||
}, {'draw_inner_divider': None}),
|
||||
]
|
||||
)
|
||||
@ -151,42 +113,22 @@ class TestI3WM(TestCase):
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '1: w1',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': False
|
||||
}
|
||||
'workspace': self.workspaces[0],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'LVDS1',
|
||||
'workspace': {
|
||||
'name': '2: w2',
|
||||
'focused': False,
|
||||
'urgent': False,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[1],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'HDMI1',
|
||||
'workspace': {
|
||||
'name': '3: w3',
|
||||
'focused': False,
|
||||
'urgent': True,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[2],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'DVI01',
|
||||
'workspace': {
|
||||
'name': '4: w4',
|
||||
'focused': True,
|
||||
'urgent': True,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[3],
|
||||
}, {'draw_inner_divider': None}),
|
||||
]
|
||||
)
|
||||
@ -201,22 +143,12 @@ class TestI3WM(TestCase):
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'HDMI1',
|
||||
'workspace': {
|
||||
'name': '3: w3',
|
||||
'focused': False,
|
||||
'urgent': True,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[2],
|
||||
}, {'draw_inner_divider': None}),
|
||||
({
|
||||
'a': 1,
|
||||
'output': 'DVI01',
|
||||
'workspace': {
|
||||
'name': '4: w4',
|
||||
'focused': True,
|
||||
'urgent': True,
|
||||
'visible': True
|
||||
}
|
||||
'workspace': self.workspaces[3],
|
||||
}, {'draw_inner_divider': None}),
|
||||
]
|
||||
)
|
||||
|
@ -1004,10 +1004,10 @@ class TestI3WM(TestCase):
|
||||
@staticmethod
|
||||
def get_workspaces():
|
||||
return iter([
|
||||
{'name': '1: w1', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': False},
|
||||
{'name': '2: w2', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': True},
|
||||
{'name': '3: w3', 'output': 'HDMI1', 'focused': False, 'urgent': True, 'visible': True},
|
||||
{'name': '4: w4', 'output': 'DVI01', 'focused': True, 'urgent': True, 'visible': True},
|
||||
Args(name='1: w1', output='LVDS1', focused = False, urgent = False, visible = False),
|
||||
Args(name='2: w2', output='LVDS1', focused = False, urgent = False, visible = True),
|
||||
Args(name='3: w3', output='HDMI1', focused = False, urgent = True, visible = True),
|
||||
Args(name='4: w4', output='DVI01', focused = True, urgent = True, visible = True),
|
||||
])
|
||||
|
||||
def test_workspaces(self):
|
||||
@ -1093,7 +1093,7 @@ class TestI3WM(TestCase):
|
||||
def get_tree(self):
|
||||
return self
|
||||
|
||||
def descendents(self):
|
||||
def descendants(self):
|
||||
nodes_unfocused = [Args(focused = False)]
|
||||
nodes_focused = [Args(focused = True)]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user