An (outdated) collection of plugins for Qtile.
git clone https://github.com/m-col/qtools
Files | Refs | Readme

-rw-r--r-- qtools/borders/cde.py


      1 """
      2 This is the 'CDE' border style.
      3 """
      4 
      5 
      6 import functools
      7 import xcffib
      8 
      9 
     10 def cde(self, colors, borderwidth, width, height):
     11     """
     12     The "CDE" style is based on the window decorations used by the Common Desktop
     13     Environment, and has a 3D bevelled look.
     14 
     15     It accepts one border width and three colours. The colours should be in ascending
     16     brightness to correspond to shadow, normal, and illuminated.
     17 
     18       ______________
     19      |  _|______|_  |
     20      |_|          |_|
     21      | |          | |
     22      | |          | |
     23      |_|          |_|
     24      | |__________| |
     25      |__|________|__|
     26 
     27     """
     28     if not colors or not borderwidth:
     29         return
     30 
     31     if isinstance(colors, str):
     32         self.set_attribute(borderpixel=self.conn.color_pixel(colors))
     33         return
     34 
     35     if len(colors) < 3:
     36         self.set_attribute(borderpixel=self.conn.color_pixel(colors[0]))
     37         return
     38 
     39     colors = [self.conn.color_pixel(c) for c in colors]
     40     core = self.conn.conn.core
     41     outer_w = width + borderwidth * 2
     42     outer_h = height + borderwidth * 2
     43     pixmap = self.conn.conn.generate_id()
     44     gc = self.conn.conn.generate_id()
     45 
     46     try:
     47         core.CreatePixmap(
     48             self.conn.default_screen.root_depth, pixmap, self.wid, outer_w, outer_h
     49         )
     50         core.CreateGC(gc, pixmap, xcffib.xproto.GC.Foreground, [colors[2]])
     51         rect = xcffib.xproto.RECTANGLE.synthetic(0, 0, outer_w, outer_h)
     52         core.PolyFillRectangle(pixmap, gc, 1, [rect])
     53 
     54         core.ChangeGC(gc, xcffib.xproto.GC.Foreground, [colors[1]])
     55         rect = xcffib.xproto.RECTANGLE.synthetic(2, 2, outer_w - 4, outer_h - 4)
     56         core.PolyFillRectangle(pixmap, gc, 1, [rect])
     57 
     58         core.ChangeGC(gc, xcffib.xproto.GC.Foreground, [colors[0]])
     59         rect = xcffib.xproto.RECTANGLE.synthetic(
     60             borderwidth - 1, borderwidth - 1, width + 2, height + 2
     61         )
     62         core.PolyFillRectangle(pixmap, gc, 1, [rect])
     63 
     64         shadows, light = _lines(borderwidth, outer_w, outer_h)
     65         core.PolyLine(0, pixmap, gc, 18, shadows)
     66         core.ChangeGC(gc, xcffib.xproto.GC.Foreground, [colors[2]])
     67         core.PolyLine(0, pixmap, gc, 15, light)
     68         self.set_borderpixmap(pixmap, gc, borderwidth, width, height)
     69 
     70     finally:
     71         core.FreePixmap(pixmap)
     72         core.FreeGC(gc)
     73 
     74 
     75 @functools.lru_cache()
     76 def _lines(borderwidth, outer_w, outer_h):
     77     shadows = [
     78         xcffib.xproto.POINT.synthetic(1, outer_h - 1),
     79         xcffib.xproto.POINT.synthetic(outer_w, outer_h - 1),
     80         xcffib.xproto.POINT.synthetic(outer_w - 1, outer_h - 1),
     81         xcffib.xproto.POINT.synthetic(outer_w - 1, 1),
     82         xcffib.xproto.POINT.synthetic(outer_w - 1, 2),
     83         xcffib.xproto.POINT.synthetic(outer_w - 2, 2),
     84         xcffib.xproto.POINT.synthetic(outer_w - 2, outer_h - 1),
     85         xcffib.xproto.POINT.synthetic(outer_w - 2, outer_h - 2),
     86         xcffib.xproto.POINT.synthetic(2, outer_h - 2),
     87         xcffib.xproto.POINT.synthetic(borderwidth + 19, outer_h - 2),
     88         xcffib.xproto.POINT.synthetic(borderwidth + 19, 1),
     89         xcffib.xproto.POINT.synthetic(borderwidth + 19, borderwidth + 19),
     90         xcffib.xproto.POINT.synthetic(1, borderwidth + 19),
     91         xcffib.xproto.POINT.synthetic(outer_w, borderwidth + 19),
     92         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 21, borderwidth + 19),
     93         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 21, 1),
     94         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 21, outer_h),
     95         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 21, outer_h - borderwidth - 21),
     96         xcffib.xproto.POINT.synthetic(outer_w, outer_h - borderwidth - 21),
     97         xcffib.xproto.POINT.synthetic(1, outer_h - borderwidth - 21),
     98     ]
     99     light = [
    100         xcffib.xproto.POINT.synthetic(borderwidth + 20, outer_h - 1),
    101         xcffib.xproto.POINT.synthetic(borderwidth + 20, 1),
    102         xcffib.xproto.POINT.synthetic(borderwidth + 20, borderwidth + 20),
    103         xcffib.xproto.POINT.synthetic(1, borderwidth + 20),
    104         xcffib.xproto.POINT.synthetic(outer_w - 1, borderwidth + 20),
    105         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 20, borderwidth + 20),
    106         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 20, 1),
    107         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 20, outer_h - 1),
    108         xcffib.xproto.POINT.synthetic(outer_w - borderwidth - 20, outer_h - borderwidth - 20),
    109         xcffib.xproto.POINT.synthetic(outer_w - 1, outer_h - borderwidth - 20),
    110         xcffib.xproto.POINT.synthetic(1, outer_h - borderwidth - 20),
    111         xcffib.xproto.POINT.synthetic(borderwidth, outer_h - borderwidth - 20),
    112         xcffib.xproto.POINT.synthetic(borderwidth, outer_h - borderwidth),
    113         xcffib.xproto.POINT.synthetic(outer_w - borderwidth + 1, outer_h - borderwidth),
    114         xcffib.xproto.POINT.synthetic(outer_w - borderwidth, outer_h - borderwidth),
    115         xcffib.xproto.POINT.synthetic(outer_w - borderwidth, borderwidth),
    116     ]
    117     return shadows, light
    118