1 module gui.bar;
2 
3 import cboxapp;
4 import types;
5 import gui.cursor;
6 import window;
7 import old;
8 import legacy;
9 import utils;
10 import config;
11 import kernel;
12 import helper.x11;
13 import monitor;
14 import std.stdio;
15 import theme.manager;
16 
17 import deimos.X11.X;
18 import deimos.X11.Xlib;
19 import deimos.X11.keysymdef;
20 import deimos.X11.Xutil;
21 import deimos.X11.Xatom;
22 
23 void drawbar(Monitor *m) 
24 {
25     uint occ = 0, urg = 0;
26 
27     foreach(c; m.clients.range!"next") {
28         occ |= c.tags;
29         if(c.isurgent) {
30             urg |= c.tags;
31         }
32     }
33 
34     int x = 0, w;
35 
36     ClrScheme sel = ThemeManager.instance().getScheme(SchemeSel);
37     ClrScheme norm = ThemeManager.instance().getScheme(SchemeNorm);
38 
39     foreach(i, tag; tags) {
40         w = TEXTW(tag);
41         drw.setscheme((m.tagset[m.seltags] & (1 << i)) 
42             ? &sel
43             : &norm);
44         drw.text(x, 0, w, bh, tag, urg & 1 << i);
45         drw.rect(x, 0, w, bh, m == selmon && selmon.sel && selmon.sel.tags & 1 << i,
46                  occ & 1 << i, urg & 1 << i);
47         x += w;
48     }
49 
50     w = blw = TEXTW(m.ltsymbol);
51     drw.setscheme(&norm);
52     drw.text(x, 0, w, bh, m.ltsymbol, 0);
53     x += w;
54     int xx = x;
55 
56     if(m == selmon) { /* status is only drawn on selected monitor */
57         w = TEXTW(stext);
58         x = m.ww - w;
59         if(x < xx) {
60             x = xx;
61             w = m.ww - xx;
62         }
63         drw.text(x, 0, w, bh, stext, 0);
64     } else {
65         x = m.ww;
66     }
67 
68     if((w = x - xx) > bh) {
69         x = xx;
70         if(m.sel) {
71             drw.setscheme(m == selmon ? &sel : &norm);
72             drw.text(x, 0, w, bh, m.sel.name, 0);
73             drw.rect(x, 0, w, bh, m.sel.isfixed, m.sel.isfloating, 0);
74         } else {
75             drw.setscheme(&norm);
76             drw.text(x, 0, w, bh, null, 0);
77         }
78     }
79 
80     drw.map(m.barwin, 0, 0, m.ww, bh);
81 }
82 
83 void drawbars()
84 {
85     foreach(m; mons.range) {
86         drawbar(m);
87     }
88 }
89 
90 void updatebars()
91 {
92     Client *c;
93     XSetWindowAttributes wa = {
94 		override_redirect : True,
95 		background_pixmap : ParentRelative,
96 		event_mask :  ButtonPressMask|ExposureMask
97     };
98 
99     foreach(m; mons.range) {
100         if (m.barwin)
101             continue;
102         
103         m.barwin = XCreateWindow(
104         	AppDisplay.instance().dpy, 
105         	rootWin, 
106         	m.wx, 
107         	m.by, 
108         	m.ww, 
109         	bh, 
110         	0, 
111         	DefaultDepth(AppDisplay.instance().dpy, screen),
112             CopyFromParent, 
113             DefaultVisual(AppDisplay.instance().dpy, screen),
114             CWOverrideRedirect|CWBackPixmap|CWEventMask, 
115             &wa
116         );
117 
118         XDefineCursor(AppDisplay.instance().dpy, m.barwin, cursor[CurNormal].cursor);
119 
120         //sendevent(c, XInternAtom(AppDisplay.instance().dpy, cast(char*)("_NET_WM_STATE_ABOVE"), false));
121         XMapRaised(AppDisplay.instance().dpy, m.barwin);
122         //sendevent(c, XInternAtom(AppDisplay.instance().dpy, cast(char*)("_NET_WM_STATE_ABOVE"), false));
123     }
124 }
125 
126 void updatebarpos(Monitor *m) 
127 {
128     
129     m.wy = m.my;
130     m.wh = m.mh;
131     if(m.showbar) {
132         m.wh -= bh;
133         m.by = m.topbar ? m.wy : m.wy + m.wh;
134         m.wy = m.topbar ? m.wy + bh : m.wy;
135     } else
136         m.by = -bh;
137 }
138 
139 void togglebar(const Arg *arg) 
140 {
141     selmon.showbar = !selmon.showbar;
142     updatebarpos(selmon);
143     XMoveResizeWindow(AppDisplay.instance().dpy, selmon.barwin, selmon.wx, selmon.by, selmon.ww, bh);
144     arrange(selmon);
145 }
146 
147 void updatestatus() 
148 {
149     if(!X11Helper.gettextprop(rootWin, XA_WM_NAME, stext)) {
150         stext = "ddwm-"~VERSION;
151     }
152     drawbar(selmon);
153 }
154 
155