Created
March 4, 2013 15:12
-
-
Save jpic/5082894 to your computer and use it in GitHub Desktop.
Dwm-like layout for Qtile ... feels like home ! welcome Qtile B)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Master(SingleWindow): | |
defaults = [ | |
("border_focus", "#ff0000", "Border colour for the focused window."), | |
("border_normal", "#000000", "Border colour for un-focused winows."), | |
("border_width", 2, "Border width."), | |
("name", "xmonad-tall", "Name of this layout."), | |
] | |
_min_ratio = .1 | |
_max_ratio = .9 | |
def __init__(self, **config): | |
super(Master, self).__init__(**config) | |
self.add_defaults(self.__class__.defaults) | |
self._focus = 0 | |
self.clients = [] | |
self.ratio = 0.5 | |
self.previously_maximised = 0 | |
# track client that has 'focus' | |
def _get_focus(self): | |
return self._focus | |
def _set_focus(self, x): | |
if len(self.clients) > 0: | |
self._focus = abs(x % len(self.clients)) | |
else: | |
self._focus = 0 | |
focused = property(_get_focus, _set_focus) | |
def _get_window(self): | |
"Get currently focused client" | |
if self.clients: | |
return self.clients[self.focused] | |
def focus(self, c): | |
"Set focus to specified client" | |
if self.clients: | |
self.focused = self.clients.index(c) | |
def add(self, c): | |
"Add client to layout" | |
self.clients.insert(self.focused + 1, c) | |
def remove(self, c): | |
"Remove client from layout" | |
# get index of removed client | |
idx = self.clients.index(c) | |
# remove the client | |
self.clients.remove(c) | |
# move focus pointer | |
self.focused = max(0, idx - 1) | |
if self.clients: | |
return self.clients[self.focused] | |
def configure(self, c, screen): | |
if not self.clients or not c in self.clients: | |
c.hide() | |
return | |
if len(self.clients) == 1: | |
px = self.group.qtile.colorPixel(self.border_focus) | |
c.place(self.group.screen.dx, | |
self.group.screen.dy, | |
self.group.screen.dwidth, | |
self.group.screen.dheight, | |
0, px) | |
c.unhide() | |
return | |
if self.clients.index(c) == self.focused: | |
px = self.group.qtile.colorPixel(self.border_focus) | |
else: | |
px = self.group.qtile.colorPixel(self.border_normal) | |
# calculate main/secondary column widths | |
width_main = int(self.group.screen.dwidth * self.ratio) | |
width_shared = self.group.screen.dwidth - width_main | |
cidx = self.clients.index(c) | |
if cidx == 0: | |
# main client | |
xpos = self.group.screen.dx | |
width = width_main - 2 * self.border_width | |
c.place(xpos, self.group.screen.dy, width, | |
self.group.screen.dheight - 2 * self.border_width, | |
self.border_width, px) | |
else: | |
# secondary client | |
xpos = self.group.screen.dx + width_main | |
width = width_shared - 2 * self.border_width | |
height = self.group.screen.dheight / (len(self.clients) - 1) | |
# ypos is the sum of all clients above it | |
ypos = self.group.screen.dy + height * (cidx - 1) | |
# place client based on calculated dimensions | |
c.place(xpos, ypos, | |
width, height - 2 * self.border_width, | |
self.border_width, px) | |
c.unhide() | |
def cmd_grow(self): | |
self.ratio += .1 | |
self.ratio = min(self._max_ratio, self.ratio) | |
self.group.layoutAll() | |
def cmd_shrink(self): | |
self.ratio -= .1 | |
self.ratio = max(self._min_ratio, self.ratio) | |
self.group.layoutAll() | |
def cmd_up(self): | |
"Focus on the next more prominent client on the stack" | |
self.focused -= 1 | |
self.group.focus(self.clients[self.focused], False) | |
def cmd_down(self): | |
"Focus on the less prominent client on the stack" | |
self.focused += 1 | |
self.group.focus(self.clients[self.focused], False) | |
def cmd_maximize(self): | |
"Focus on the less prominent client on the stack" | |
maximised = self.clients[0] | |
if self.focused == 0: | |
maximise = self.clients.pop(self.previously_maximised) | |
else: | |
maximise = self.clients.pop(self.focused) | |
self.clients.insert(0, maximise) | |
self.previously_maximised = self.clients.index(maximised) | |
self.focused = 0 | |
self.group.layoutAll() | |
def clone(self, group): | |
"Clone layout for other groups" | |
c = SingleWindow.clone(self, group) | |
c._focus = 0 | |
c.clients = [] | |
c.ratio = 0.5 | |
c.previously_maximised = 0 | |
return c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment