commit 66cd6173709747f15a352ad5ae8909fb313e4d7f
parent 8a6b18e24af06a310f961f4acad863e3305723ce
Author: mcol <mcol@posteo.net>
Date: Fri, 1 May 2020 17:09:08 +0100
make window border styles use their own file
Diffstat:
2 files changed, 77 insertions(+), 70 deletions(-)
diff --git a/qtools/borders/borders.py b/qtools/borders/borders.py
@@ -10,82 +10,14 @@ Example usage:
"""
-import functools
-import xcffib
-
from libqtile.log_utils import logger
from libqtile.backend.x11 import xcbq
-
-def _frame(self, inner_w, inner_h, borderwidths, bordercolors):
- """
- The "frame" style accepts one border width and two colours.
-
- The first colour is the sides and the second is top and bottom.
- _________
- |\_______/|
- || ||
- || ||
- || ||
- ||_______||
- |/_______\|
-
- """
- if len(bordercolors) == 1:
- self.set_attribute(borderpixel=bordercolors[0])
- return
-
- core = self.conn.conn.core
- self.borderwidth = sum(borderwidths)
- outer_w = inner_w + self.borderwidth * 2
- outer_h = inner_h + self.borderwidth * 2
-
- pixmap = self.conn.conn.generate_id()
- core.CreatePixmap(
- self.conn.default_screen.root_depth, pixmap, self.wid, outer_w, outer_h
- )
- gc = self.conn.conn.generate_id()
- core.CreateGC(gc, pixmap, xcffib.xproto.GC.Foreground, [bordercolors[0]])
- rect = xcffib.xproto.RECTANGLE.synthetic(0, 0, outer_w, outer_h)
- core.PolyFillRectangle(pixmap, gc, 1, [rect])
-
- core.ChangeGC(gc, xcffib.xproto.GC.Foreground, [bordercolors[1]])
- core.FillPoly(
- pixmap, gc, 2, 0, 4, _frame_trapezium_top(self.borderwidth, outer_w)
- )
- core.FillPoly(
- pixmap, gc, 2, 0, 4, _frame_trapezium_bottom(self.borderwidth, outer_w, outer_h)
- )
-
- self.set_borderpixmap(pixmap, gc, outer_w, outer_h)
- core.FreePixmap(pixmap)
- core.FreeGC(gc)
- return
-
-@functools.lru_cache()
-def _frame_trapezium_top(borderwidth, width):
- points = [
- xcffib.xproto.POINT.synthetic(0, 0),
- xcffib.xproto.POINT.synthetic(borderwidth, borderwidth),
- xcffib.xproto.POINT.synthetic(width - borderwidth, borderwidth),
- xcffib.xproto.POINT.synthetic(width, 0),
- ]
- return points
-
-@functools.lru_cache()
-def _frame_trapezium_bottom(borderwidth, width, bottom):
- points = [
- xcffib.xproto.POINT.synthetic(0, bottom),
- xcffib.xproto.POINT.synthetic(borderwidth, bottom - borderwidth),
- xcffib.xproto.POINT.synthetic(width - borderwidth, bottom - borderwidth),
- xcffib.xproto.POINT.synthetic(width, bottom),
- ]
- return points
-
+from .frame import frame
_style_map = {
- 'frame': _frame,
+ 'frame': frame,
}
diff --git a/qtools/borders/frame.py b/qtools/borders/frame.py
@@ -0,0 +1,75 @@
+"""
+This is the 'frame' border style.
+"""
+
+
+import functools
+import xcffib
+
+
+def frame(self, inner_w, inner_h, borderwidths, bordercolors):
+ """
+ The "frame" style accepts one border width and two colours.
+
+ The first colour is the sides and the second is top and bottom.
+ _________
+ |\_______/|
+ || ||
+ || ||
+ || ||
+ ||_______||
+ |/_______\|
+
+ """
+ if len(bordercolors) == 1:
+ self.set_attribute(borderpixel=bordercolors[0])
+ return
+
+ core = self.conn.conn.core
+ self.borderwidth = sum(borderwidths)
+ outer_w = inner_w + self.borderwidth * 2
+ outer_h = inner_h + self.borderwidth * 2
+
+ pixmap = self.conn.conn.generate_id()
+ core.CreatePixmap(
+ self.conn.default_screen.root_depth, pixmap, self.wid, outer_w, outer_h
+ )
+ gc = self.conn.conn.generate_id()
+ core.CreateGC(gc, pixmap, xcffib.xproto.GC.Foreground, [bordercolors[0]])
+ rect = xcffib.xproto.RECTANGLE.synthetic(0, 0, outer_w, outer_h)
+ core.PolyFillRectangle(pixmap, gc, 1, [rect])
+
+ core.ChangeGC(gc, xcffib.xproto.GC.Foreground, [bordercolors[1]])
+ core.FillPoly(
+ pixmap, gc, 2, 0, 4, _frame_trapezium_top(self.borderwidth, outer_w)
+ )
+ core.FillPoly(
+ pixmap, gc, 2, 0, 4, _frame_trapezium_bottom(self.borderwidth, outer_w, outer_h)
+ )
+
+ self.set_borderpixmap(pixmap, gc, outer_w, outer_h)
+ core.FreePixmap(pixmap)
+ core.FreeGC(gc)
+ return
+
+
+@functools.lru_cache()
+def _frame_trapezium_top(borderwidth, width):
+ points = [
+ xcffib.xproto.POINT.synthetic(0, 0),
+ xcffib.xproto.POINT.synthetic(borderwidth, borderwidth),
+ xcffib.xproto.POINT.synthetic(width - borderwidth, borderwidth),
+ xcffib.xproto.POINT.synthetic(width, 0),
+ ]
+ return points
+
+
+@functools.lru_cache()
+def _frame_trapezium_bottom(borderwidth, width, bottom):
+ points = [
+ xcffib.xproto.POINT.synthetic(0, bottom),
+ xcffib.xproto.POINT.synthetic(borderwidth, bottom - borderwidth),
+ xcffib.xproto.POINT.synthetic(width - borderwidth, bottom - borderwidth),
+ xcffib.xproto.POINT.synthetic(width, bottom),
+ ]
+ return points