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