2 * draw.c - draw functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 extern Client
*clients
, *sel
, *stack
; /* global client list and stack */
29 drawtext(Display
*disp
, DC drawcontext
, const char *text
, unsigned long col
[ColLast
])
33 unsigned int len
, olen
;
34 XRectangle r
= { drawcontext
.x
, drawcontext
.y
, drawcontext
.w
, drawcontext
.h
};
36 XSetForeground(disp
, drawcontext
.gc
, col
[ColBG
]);
37 XFillRectangles(disp
, drawcontext
.drawable
, drawcontext
.gc
, &r
, 1);
41 olen
= len
= a_strlen(text
);
44 memcpy(buf
, text
, len
);
46 h
= drawcontext
.font
.ascent
+ drawcontext
.font
.descent
;
47 y
= drawcontext
.y
+ (drawcontext
.h
/ 2) - (h
/ 2) + drawcontext
.font
.ascent
;
48 x
= drawcontext
.x
+ (h
/ 2);
49 /* shorten text if necessary */
50 while(len
&& (w
= textnw(drawcontext
.font
.set
, drawcontext
.font
.xfont
, buf
, len
)) > drawcontext
.w
- h
)
53 return; /* too long */
63 XSetForeground(disp
, drawcontext
.gc
, col
[ColFG
]);
64 if(drawcontext
.font
.set
)
65 XmbDrawString(disp
, drawcontext
.drawable
, drawcontext
.font
.set
, drawcontext
.gc
, x
, y
, buf
, len
);
67 XDrawString(disp
, drawcontext
.drawable
, drawcontext
.gc
, x
, y
, buf
, len
);
71 drawsquare(Bool filled
, Bool empty
, unsigned long col
[ColLast
], Display
*disp
, DC drawcontext
)
75 XRectangle r
= { drawcontext
.x
, drawcontext
.y
, drawcontext
.w
, drawcontext
.h
};
77 gcv
.foreground
= col
[ColFG
];
78 XChangeGC(disp
, drawcontext
.gc
, GCForeground
, &gcv
);
79 x
= (drawcontext
.font
.ascent
+ drawcontext
.font
.descent
+ 2) / 4;
80 r
.x
= drawcontext
.x
+ 1;
81 r
.y
= drawcontext
.y
+ 1;
84 r
.width
= r
.height
= x
+ 1;
85 XFillRectangles(disp
, drawcontext
.drawable
, drawcontext
.gc
, &r
, 1);
89 r
.width
= r
.height
= x
;
90 XDrawRectangles(disp
, drawcontext
.drawable
, drawcontext
.gc
, &r
, 1);
94 /** Check if at least a client is tagged with tag number t
96 * \return True or False
99 isoccupied(unsigned int t
)
103 for(c
= clients
; c
; c
= c
->next
)
113 textnw(XFontSet set
, XFontStruct
*xfont
, const char *text
, unsigned int len
)
119 XmbTextExtents(set
, text
, len
, NULL
, &r
);
122 return XTextWidth(xfont
, text
, len
);
126 drawstatus(Display
*disp
, DC
*drawcontext
, awesome_config
* awesomeconf
)
129 drawcontext
->x
= drawcontext
->y
= 0;
130 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
132 drawcontext
->w
= textw(drawcontext
->font
.set
, drawcontext
->font
.xfont
, awesomeconf
->tags
[i
], drawcontext
->font
.height
);
133 if(awesomeconf
->selected_tags
[i
])
135 drawtext(disp
, *drawcontext
, awesomeconf
->tags
[i
], drawcontext
->sel
);
136 drawsquare(sel
&& sel
->tags
[i
], isoccupied(i
), drawcontext
->sel
, disp
, *drawcontext
);
140 drawtext(disp
, *drawcontext
, awesomeconf
->tags
[i
], drawcontext
->norm
);
141 drawsquare(sel
&& sel
->tags
[i
], isoccupied(i
), drawcontext
->norm
, disp
, *drawcontext
);
143 drawcontext
->x
+= drawcontext
->w
;
145 drawcontext
->w
= awesomeconf
->statusbar
.width
;
146 drawtext(disp
, *drawcontext
, awesomeconf
->current_layout
->symbol
, drawcontext
->norm
);
147 x
= drawcontext
->x
+ drawcontext
->w
;
148 drawcontext
->w
= textw(drawcontext
->font
.set
, drawcontext
->font
.xfont
, awesomeconf
->statustext
, drawcontext
->font
.height
);
149 drawcontext
->x
= DisplayWidth(disp
, DefaultScreen(disp
)) - drawcontext
->w
;
150 if(drawcontext
->x
< x
)
153 drawcontext
->w
= DisplayWidth(disp
, DefaultScreen(disp
)) - x
;
155 drawtext(disp
, *drawcontext
, awesomeconf
->statustext
, drawcontext
->norm
);
156 if((drawcontext
->w
= drawcontext
->x
- x
) > awesomeconf
->statusbar
.height
)
161 drawtext(disp
, *drawcontext
, sel
->name
, drawcontext
->sel
);
162 drawsquare(sel
->ismax
, sel
->isfloating
, drawcontext
->sel
, disp
, *drawcontext
);
165 drawtext(disp
, *drawcontext
, NULL
, drawcontext
->norm
);
167 XCopyArea(disp
, drawcontext
->drawable
, awesomeconf
->statusbar
.window
, drawcontext
->gc
, 0, 0, DisplayWidth(disp
, DefaultScreen(disp
)), awesomeconf
->statusbar
.height
, 0, 0);