Skip to content

Commit

Permalink
Implement command for most recent window
Browse files Browse the repository at this point in the history
  • Loading branch information
numirias committed Dec 12, 2017
1 parent e8222b5 commit 68dd301
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ The layout exposes the following commands:
<td><code>previous()</code></td>
<td>Focus previous window.</td>
</tr>
<tr>
<td><code>recent()</code></td>
<td>Focus most recently focused window.<br>
(Toggles between the two latest active windows.)</td>
</tr>
<tr>
<td><code>left()</code></td>
<td>Focus window to the left.</td>
Expand Down Expand Up @@ -156,9 +161,8 @@ window.</td>
</tr>
<tr>
<td><code>size(val)</code></td>
<td>Change size of current window.

(It's recommended to use `width()`/`height()` instead.)</td>
<td>Change size of current window.<br>
(It's recommended to use <code>width()</code>/<code>height()</code> instead.)</td>
</tr>
<tr>
<td><code>width(val)</code></td>
Expand All @@ -174,9 +178,8 @@ window.</td>
</tr>
<tr>
<td><code>grow(amt)</code></td>
<td>Grow size of current window.

(It's recommended to use `grow_width()`/`grow_height()` instead.)</td>
<td>Grow size of current window.<br>
(It's recommended to use <code>grow_width()</code>/<code>grow_height()</code> instead.)</td>
</tr>
<tr>
<td><code>grow_width(amt)</code></td>
Expand Down
9 changes: 9 additions & 0 deletions plasma/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def cmd_previous(self):
"""Focus previous window."""
self.focus_node(self.focused_node.prev_leaf)

def cmd_recent(self):
"""Focus most recently focused window.
(Toggles between the two latest active windows.)
"""
nodes = [n for n in self.root.all_leafs if n is not self.focused_node]
most_recent = max(nodes, key=lambda n: n.last_accessed)
self.focus_node(most_recent)

def cmd_left(self):
"""Focus window to the left."""
self.focus_node(self.focused_node.close_left)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='qtile-plasma',
packages=['plasma'],
version='1.2.0',
version='1.3.0',
description='An advanced, flexible layout for Qtile',
author='numirias',
author_email='[email protected]',
Expand Down
15 changes: 15 additions & 0 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,18 @@ def test_split_mode(self, qtile):
qtile.c.layout.mode_vertical_split()
qtile.testWindow('f')
assert qtile.c.window.info()['height'] == 100 - 2

@plasma_config
def test_recent(self, qtile):
qtile.testWindow('a')
qtile.testWindow('b')
qtile.testWindow('c')
assertFocused(qtile, 'c')
qtile.c.layout.recent()
assertFocused(qtile, 'b')
qtile.c.layout.recent()
assertFocused(qtile, 'c')
qtile.c.layout.next()
assertFocused(qtile, 'a')
qtile.c.layout.recent()
assertFocused(qtile, 'c')
24 changes: 19 additions & 5 deletions tools/make_readme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"""Insert documentation for layout commands into readme file."""
"""Update documentation in readme.
This tool extracts the documentation (docstrings) for all layout commands
(startings with "cmd_") from the layout class and inserts them as a table into
the readme file, in the marked area.
It should be run with every API change.
"""

import ast
import re


readme_path = 'README.md'
Expand All @@ -18,12 +26,15 @@ def row(text):
def col(text):
return ' <td>%s</td>\n' % text

def function(name, args):
return '%s(%s)' % (name, ', '.join(args))

def code(text):
return '<code>%s</code>' % text

def function_name(name, args):
return '%s(%s)' % (name, ', '.join(args))

def function_desc(text):
return re.sub('`([^`]*)`', code('\\1'), text.replace('\n\n', '<br>\n'))

def main():
with open(readme_path) as f:
text = f.read()
Expand All @@ -42,7 +53,10 @@ def main():
name = node.name[4:]
args = [a.arg for a in node.args.args[1:]]
docstring = ast.get_docstring(node)
rows += row(col(code(function(name, args))) + col(docstring))
rows += row(
col(code(function_name(name, args))) +
col(function_desc(docstring))
)
text_table = table(rows)

with open(readme_path, 'w') as f:
Expand Down

0 comments on commit 68dd301

Please sign in to comment.