mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
Merge pull request #1542 from s-ol/i3-scratch
Add segments.i3wm.scratchpad
This commit is contained in:
commit
a44c9a8ec9
@ -131,6 +131,15 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"text": "+"
|
"text": "+"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"powerline.segments.i3wm.scratchpad": {
|
||||||
|
"args": {
|
||||||
|
"icons": {
|
||||||
|
"fresh": "O",
|
||||||
|
"changed": "X"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,15 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"text": "+"
|
"text": "+"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"powerline.segments.i3wm.scratchpad": {
|
||||||
|
"args": {
|
||||||
|
"icons": {
|
||||||
|
"fresh": "●",
|
||||||
|
"changed": "○"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,15 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"text": "🖫⃥"
|
"text": "🖫⃥"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"powerline.segments.i3wm.scratchpad": {
|
||||||
|
"args": {
|
||||||
|
"icons": {
|
||||||
|
"fresh": "●",
|
||||||
|
"changed": "○"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,15 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"text": "+"
|
"text": "+"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"powerline.segments.i3wm.scratchpad": {
|
||||||
|
"args": {
|
||||||
|
"icons": {
|
||||||
|
"fresh": "●",
|
||||||
|
"changed": "○"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,15 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"text": "+"
|
"text": "+"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"powerline.segments.i3wm.scratchpad": {
|
||||||
|
"args": {
|
||||||
|
"icons": {
|
||||||
|
"fresh": "●",
|
||||||
|
"changed": "○"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,15 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"text": "+"
|
"text": "+"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"powerline.segments.i3wm.scratchpad": {
|
||||||
|
"args": {
|
||||||
|
"icons": {
|
||||||
|
"fresh": "●",
|
||||||
|
"changed": "○"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ from powerline.bindings.wm import get_i3_connection
|
|||||||
WORKSPACE_REGEX = re.compile(r'^[0-9]+: ?')
|
WORKSPACE_REGEX = re.compile(r'^[0-9]+: ?')
|
||||||
|
|
||||||
|
|
||||||
def calcgrp(w):
|
def workspace_groups(w):
|
||||||
group = []
|
group = []
|
||||||
if w['focused']:
|
if w['focused']:
|
||||||
group.append('w_focused')
|
group.append('w_focused')
|
||||||
@ -53,7 +53,7 @@ def workspaces(pl, segment_info, only_show=None, output=None, strip=0):
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'contents': w['name'][strip:],
|
'contents': w['name'][strip:],
|
||||||
'highlight_groups': calcgrp(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(w[typ] for typ in only_show))
|
||||||
@ -97,7 +97,7 @@ def workspace(pl, segment_info, workspace=None, strip=False):
|
|||||||
|
|
||||||
return [{
|
return [{
|
||||||
'contents': format_name(w['name'], strip=strip),
|
'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:
|
if mode in names:
|
||||||
return names[mode]
|
return names[mode]
|
||||||
return 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'
|
||||||
|
]
|
||||||
|
@ -892,14 +892,6 @@ class TestI3WM(TestCase):
|
|||||||
{'name': '4: w4', 'output': 'DVI01', 'focused': True, 'urgent': True, 'visible': True},
|
{'name': '4: w4', 'output': 'DVI01', 'focused': True, 'urgent': True, 'visible': True},
|
||||||
])
|
])
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_outputs(pl):
|
|
||||||
return iter([
|
|
||||||
{'name': 'LVDS1'},
|
|
||||||
{'name': 'HDMI1'},
|
|
||||||
{'name': 'DVI01'},
|
|
||||||
])
|
|
||||||
|
|
||||||
def test_workspaces(self):
|
def test_workspaces(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
with replace_attr(i3wm, 'get_i3_connection', lambda: Args(get_workspaces=self.get_workspaces)):
|
with replace_attr(i3wm, 'get_i3_connection', lambda: Args(get_workspaces=self.get_workspaces)):
|
||||||
@ -978,6 +970,45 @@ class TestI3WM(TestCase):
|
|||||||
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'default'}, names={'default': 'test'}), 'test')
|
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'default'}, names={'default': 'test'}), 'test')
|
||||||
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'test'}, names={'default': 'test', 'test': 't'}), 't')
|
self.assertEqual(i3wm.mode(pl=pl, segment_info={'mode': 'test'}, names={'default': 'test', 'test': 't'}), 't')
|
||||||
|
|
||||||
|
def test_scratchpad(self):
|
||||||
|
class Conn(object):
|
||||||
|
def get_tree(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def descendents(self):
|
||||||
|
nodes_unfocused = [Args(focused = False)]
|
||||||
|
nodes_focused = [Args(focused = True)]
|
||||||
|
|
||||||
|
workspace_scratch = lambda: Args(name='__i3_scratch')
|
||||||
|
workspace_noscratch = lambda: Args(name='2: www')
|
||||||
|
return [
|
||||||
|
Args(scratchpad_state='fresh', urgent=False, workspace=workspace_scratch, nodes=nodes_unfocused),
|
||||||
|
Args(scratchpad_state='changed', urgent=True, workspace=workspace_noscratch, nodes=nodes_focused),
|
||||||
|
Args(scratchpad_state='fresh', urgent=False, workspace=workspace_scratch, nodes=nodes_unfocused),
|
||||||
|
Args(scratchpad_state=None, urgent=False, workspace=workspace_noscratch, nodes=nodes_unfocused),
|
||||||
|
Args(scratchpad_state='fresh', urgent=False, workspace=workspace_scratch, nodes=nodes_focused),
|
||||||
|
Args(scratchpad_state=None, urgent=True, workspace=workspace_noscratch, nodes=nodes_unfocused),
|
||||||
|
]
|
||||||
|
|
||||||
|
pl = Pl()
|
||||||
|
with replace_attr(i3wm, 'get_i3_connection', lambda: Conn()):
|
||||||
|
self.assertEqual(i3wm.scratchpad(pl=pl), [
|
||||||
|
{'contents': 'O', 'highlight_groups': ['scratchpad']},
|
||||||
|
{'contents': 'X', 'highlight_groups': ['scratchpad:urgent', 'scratchpad:focused', 'scratchpad:visible', 'scratchpad']},
|
||||||
|
{'contents': 'O', 'highlight_groups': ['scratchpad']},
|
||||||
|
{'contents': 'X', 'highlight_groups': ['scratchpad:visible', 'scratchpad']},
|
||||||
|
{'contents': 'O', 'highlight_groups': ['scratchpad:focused', 'scratchpad']},
|
||||||
|
{'contents': 'X', 'highlight_groups': ['scratchpad:urgent', 'scratchpad:visible', 'scratchpad']},
|
||||||
|
])
|
||||||
|
self.assertEqual(i3wm.scratchpad(pl=pl, icons={'changed': '-', 'fresh': 'o'}), [
|
||||||
|
{'contents': 'o', 'highlight_groups': ['scratchpad']},
|
||||||
|
{'contents': '-', 'highlight_groups': ['scratchpad:urgent', 'scratchpad:focused', 'scratchpad:visible', 'scratchpad']},
|
||||||
|
{'contents': 'o', 'highlight_groups': ['scratchpad']},
|
||||||
|
{'contents': '-', 'highlight_groups': ['scratchpad:visible', 'scratchpad']},
|
||||||
|
{'contents': 'o', 'highlight_groups': ['scratchpad:focused', 'scratchpad']},
|
||||||
|
{'contents': '-', 'highlight_groups': ['scratchpad:urgent', 'scratchpad:visible', 'scratchpad']},
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestMail(TestCommon):
|
class TestMail(TestCommon):
|
||||||
module_name = 'mail'
|
module_name = 'mail'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user