Skip to content

Commit

Permalink
Merge remote-tracking branch 'kenji/layout_change'
Browse files Browse the repository at this point in the history
  • Loading branch information
cortesi committed Aug 18, 2011
2 parents 97963c4 + 4e1cb20 commit da0989b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libqtile/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def client_urgent_hint_changed(self, func):
"""
return self._subscribe("client_urgent_hint_changed", func)

def layout_change(self, func):
"""
Called on layout change.
"""
return self._subscribe("layout_change", func)

subscribe = Subscribe()

class Unsubscribe(Subscribe):
Expand Down
4 changes: 4 additions & 0 deletions libqtile/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def setGroup(self, new_group):
new_group._setScreen(self)
hook.fire("setgroup")
hook.fire("focus_change")
hook.fire("layout_change", self.group.layouts[self.group.currentLayout])

def _items(self, name):
if name == "layout":
Expand Down Expand Up @@ -339,20 +340,23 @@ def layout(self, layout):
for index, obj in enumerate(self.layouts):
if obj.name == layout:
self.currentLayout = index
hook.fire("layout_change", self.layouts[self.currentLayout])
self.layoutAll()
return
raise ValueError("No such layout: %s"%layout)

def nextLayout(self):
self.layout.hide()
self.currentLayout = (self.currentLayout + 1)%(len(self.layouts))
hook.fire("layout_change", self.layouts[self.currentLayout])
self.layoutAll()
screen = self.screen.get_rect()
self.layout.show(screen)

def prevLayout(self):
self.layout.hide()
self.currentLayout = (self.currentLayout - 1)%(len(self.layouts))
hook.fire("layout_change", self.layouts[self.currentLayout])
self.layoutAll()
screen = self.screen.get_rect()
self.layout.show(screen)
Expand Down
1 change: 1 addition & 0 deletions libqtile/widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
pass
from maildir import Maildir
from volume import Volume
from currentlayout import CurrentLayout
26 changes: 26 additions & 0 deletions libqtile/widget/currentlayout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import base
from .. import manager, bar, hook

class CurrentLayout(base._TextBox):
defaults = manager.Defaults(
("font", "Arial", "Text font"),
("fontsize", None, "Font pixel size. Calculated if None."),
("padding", None, "Padding left and right. Calculated if None."),
("background", None, "Background colour."),
("foreground", "#ffffff", "Foreground colour.")
)

def __init__(self, width = bar.CALCULATED, **config):
base._TextBox.__init__(self, "", width, **config)

def _configure(self, qtile, bar):
base._TextBox._configure(self, qtile, bar)
self.text = self.bar.screen.group.layouts[0].name
self.setup_hooks()

def setup_hooks(self):
def hook_response(layout):
self.text = layout.name
self.bar.draw()
hook.subscribe.layout_change(hook_response)

0 comments on commit da0989b

Please sign in to comment.