mirror of https://github.com/0intro/wmii
better text offset handling in liblitz (using font->height/2 now)
This commit is contained in:
parent
381e8c7a9c
commit
7d808e3955
11
cmd/wm/bar.c
11
cmd/wm/bar.c
|
@ -52,20 +52,13 @@ destroy_bar(Bar **b_link, Bar *b)
|
|||
free_bars = b;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
height_of_bar()
|
||||
{
|
||||
enum { BAR_PADDING = 4 };
|
||||
return def.font.ascent + def.font.descent + BAR_PADDING;
|
||||
}
|
||||
|
||||
void
|
||||
resize_bar(WMScreen *s)
|
||||
{
|
||||
View *v;
|
||||
|
||||
s->brect = s->rect;
|
||||
s->brect.height = height_of_bar();
|
||||
s->brect.height = blitz_labelh(&def.font);
|
||||
s->brect.y = s->rect.height - s->brect.height;
|
||||
XMoveResizeWindow(blz.dpy, s->barwin, s->brect.x, s->brect.y, s->brect.width, s->brect.height);
|
||||
XSync(blz.dpy, False);
|
||||
|
@ -93,7 +86,7 @@ draw_bar(WMScreen *s)
|
|||
for(b=s->lbar, nb=2 ;nb; --nb && (b = s->rbar))
|
||||
for(; b; b=b->next) {
|
||||
b->brush.rect.x = b->brush.rect.y = 0;
|
||||
b->brush.rect.width = s->brect.height;
|
||||
b->brush.rect.width = def.font.height;
|
||||
if(b->text && strlen(b->text))
|
||||
b->brush.rect.width += blitz_textwidth(b->brush.font, b->text);
|
||||
b->brush.rect.height = s->brect.height;
|
||||
|
|
|
@ -120,7 +120,7 @@ create_client(Window w, XWindowAttributes *wa)
|
|||
|
||||
c->framewin = XCreateWindow(blz.dpy, blz.root, c->rect.x, c->rect.y,
|
||||
c->rect.width + 2 * def.border,
|
||||
c->rect.height + def.border + height_of_bar(), 0,
|
||||
c->rect.height + def.border + blitz_labelh(&def.font), 0,
|
||||
DefaultDepth(blz.dpy, blz.screen), CopyFromParent,
|
||||
DefaultVisual(blz.dpy, blz.screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
|
||||
|
@ -324,12 +324,12 @@ gravitate_client(Client *c, Bool invert)
|
|||
case NorthWestGravity:
|
||||
case NorthGravity:
|
||||
case NorthEastGravity:
|
||||
dy = height_of_bar();
|
||||
dy = blitz_labelh(&def.font);
|
||||
break;
|
||||
case EastGravity:
|
||||
case CenterGravity:
|
||||
case WestGravity:
|
||||
dy = -(c->rect.height / 2) + height_of_bar();
|
||||
dy = -(c->rect.height / 2) + blitz_labelh(&def.font);
|
||||
break;
|
||||
case SouthEastGravity:
|
||||
case SouthGravity:
|
||||
|
@ -448,7 +448,7 @@ match_sizehints(Client *c, XRectangle *r, Bool floating, BlitzAlign sticky)
|
|||
{
|
||||
XSizeHints *s = &c->size;
|
||||
unsigned int dx = 2 * def.border;
|
||||
unsigned int dy = def.border + height_of_bar();
|
||||
unsigned int dy = def.border + blitz_labelh(&def.font);
|
||||
unsigned int hdiff, wdiff;
|
||||
|
||||
if(floating && (s->flags & PMinSize)) {
|
||||
|
@ -532,13 +532,13 @@ resize_client(Client *c, XRectangle *r, Bool ignore_xcall)
|
|||
if((f->area->mode != Colstack) || (f->area->sel == f))
|
||||
match_sizehints(c, &c->sel->rect, floating, stickycorner);
|
||||
|
||||
max_height = screen->rect.height - height_of_bar();
|
||||
max_height = screen->rect.height - blitz_labelh(&def.font);
|
||||
if(!ignore_xcall) {
|
||||
if(floating) {
|
||||
if((c->rect.width == screen->rect.width) &&
|
||||
(c->rect.height == screen->rect.height)) {
|
||||
f->rect.x = -def.border;
|
||||
f->rect.y = -height_of_bar();
|
||||
f->rect.y = -blitz_labelh(&def.font);
|
||||
}else{
|
||||
if(f->rect.height > max_height)
|
||||
f->rect.height = max_height;
|
||||
|
@ -563,10 +563,10 @@ resize_client(Client *c, XRectangle *r, Bool ignore_xcall)
|
|||
}
|
||||
|
||||
c->rect.x = def.border;
|
||||
c->rect.y = height_of_bar();
|
||||
c->rect.y = blitz_labelh(&def.font);
|
||||
if((f->area->sel == f) || (f->area->mode != Colstack)) {
|
||||
c->rect.width = f->rect.width - 2 * def.border;
|
||||
c->rect.height = f->rect.height - def.border - height_of_bar();
|
||||
c->rect.height = f->rect.height - def.border - blitz_labelh(&def.font);
|
||||
}
|
||||
if(!ignore_xcall) {
|
||||
XMoveResizeWindow(blz.dpy, c->win, c->rect.x, c->rect.y,
|
||||
|
|
|
@ -50,12 +50,12 @@ relax_column(Area *a)
|
|||
switch(a->mode) {
|
||||
case Coldefault:
|
||||
h = a->rect.height / frame_size;
|
||||
if(h < 2 * height_of_bar())
|
||||
if(h < 2 * blitz_labelh(&def.font))
|
||||
fallthrough = True;
|
||||
break;
|
||||
case Colstack:
|
||||
h = a->rect.height - (frame_size - 1) * height_of_bar();
|
||||
if(h < 3 * height_of_bar())
|
||||
h = a->rect.height - (frame_size - 1) * blitz_labelh(&def.font);
|
||||
if(h < 3 * blitz_labelh(&def.font))
|
||||
fallthrough = True;
|
||||
default:
|
||||
yoff = a->rect.y;
|
||||
|
@ -113,7 +113,7 @@ scale_column(Area *a, float h)
|
|||
{
|
||||
unsigned int yoff, frame_size = 0;
|
||||
Frame *f;
|
||||
unsigned int min_height = 2 * height_of_bar();
|
||||
unsigned int min_height = 2 * blitz_labelh(&def.font);
|
||||
float scale, dy = 0;
|
||||
int hdiff;
|
||||
|
||||
|
@ -152,7 +152,7 @@ arrange_column(Area *a, Bool dirty)
|
|||
{
|
||||
Frame *f;
|
||||
unsigned int num_frames = 0, yoff = a->rect.y, h;
|
||||
unsigned int min_height = 2 * height_of_bar();
|
||||
unsigned int min_height = 2 * blitz_labelh(&def.font);
|
||||
|
||||
if(a->floating || !a->frame)
|
||||
return;
|
||||
|
@ -179,8 +179,8 @@ arrange_column(Area *a, Bool dirty)
|
|||
}
|
||||
break;
|
||||
case Colstack:
|
||||
h = a->rect.height - (num_frames - 1) * height_of_bar();
|
||||
if(h < 3 * height_of_bar())
|
||||
h = a->rect.height - (num_frames - 1) * blitz_labelh(&def.font);
|
||||
if(h < 3 * blitz_labelh(&def.font))
|
||||
goto Fallthrough;
|
||||
for(f=a->frame; f; f=f->anext) {
|
||||
f->rect = a->rect;
|
||||
|
@ -188,7 +188,7 @@ arrange_column(Area *a, Bool dirty)
|
|||
if(f == a->sel)
|
||||
f->rect.height = h;
|
||||
else
|
||||
f->rect.height = height_of_bar();
|
||||
f->rect.height = blitz_labelh(&def.font);
|
||||
yoff += f->rect.height;
|
||||
//resize_client(f->client, &f->rect, True);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ drop_resize(Frame *f, XRectangle *new)
|
|||
Area *west = nil, *east = nil, *a = f->area;
|
||||
View *v = a->view;
|
||||
Frame *north = nil, *south = nil;
|
||||
unsigned int min_height = 2 * height_of_bar();
|
||||
unsigned int min_height = 2 * blitz_labelh(&def.font);
|
||||
|
||||
for(west=v->area->next; west && west->next != a; west=west->next);
|
||||
/* first managed area is indexed 1, thus (i > 1) ? ... */
|
||||
|
|
|
@ -11,34 +11,34 @@
|
|||
#include "wm.h"
|
||||
|
||||
/* local functions */
|
||||
static void handle_buttonpress(XEvent *e);
|
||||
static void handle_buttonrelease(XEvent *e);
|
||||
static void handle_configurerequest(XEvent *e);
|
||||
static void handle_destroynotify(XEvent *e);
|
||||
static void handle_enternotify(XEvent *e);
|
||||
static void handle_leavenotify(XEvent *e);
|
||||
static void handle_expose(XEvent *e);
|
||||
static void handle_keypress(XEvent *e);
|
||||
static void handle_keymapnotify(XEvent *e);
|
||||
static void handle_maprequest(XEvent *e);
|
||||
static void handle_motionnotify(XEvent *e);
|
||||
static void handle_propertynotify(XEvent *e);
|
||||
static void handle_unmapnotify(XEvent *e);
|
||||
static void buttonpress(XEvent *e);
|
||||
static void buttonrelease(XEvent *e);
|
||||
static void configurerequest(XEvent *e);
|
||||
static void destroynotify(XEvent *e);
|
||||
static void enternotify(XEvent *e);
|
||||
static void leavenotify(XEvent *e);
|
||||
static void expose(XEvent *e);
|
||||
static void keypress(XEvent *e);
|
||||
static void keymapnotify(XEvent *e);
|
||||
static void maprequest(XEvent *e);
|
||||
static void motionnotify(XEvent *e);
|
||||
static void propertynotify(XEvent *e);
|
||||
static void unmapnotify(XEvent *e);
|
||||
|
||||
void (*handler[LASTEvent]) (XEvent *) = {
|
||||
[ButtonPress] = handle_buttonpress,
|
||||
[ButtonRelease] = handle_buttonrelease,
|
||||
[ConfigureRequest]= handle_configurerequest,
|
||||
[DestroyNotify] = handle_destroynotify,
|
||||
[EnterNotify] = handle_enternotify,
|
||||
[LeaveNotify] = handle_leavenotify,
|
||||
[Expose] = handle_expose,
|
||||
[KeyPress] = handle_keypress,
|
||||
[KeymapNotify] = handle_keymapnotify,
|
||||
[MotionNotify] = handle_motionnotify,
|
||||
[MapRequest] = handle_maprequest,
|
||||
[PropertyNotify]= handle_propertynotify,
|
||||
[UnmapNotify] = handle_unmapnotify
|
||||
[ButtonPress] = buttonpress,
|
||||
[ButtonRelease] = buttonrelease,
|
||||
[ConfigureRequest]= configurerequest,
|
||||
[DestroyNotify] = destroynotify,
|
||||
[EnterNotify] = enternotify,
|
||||
[LeaveNotify] = leavenotify,
|
||||
[Expose] = expose,
|
||||
[KeyPress] = keypress,
|
||||
[KeymapNotify] = keymapnotify,
|
||||
[MotionNotify] = motionnotify,
|
||||
[MapRequest] = maprequest,
|
||||
[PropertyNotify]= propertynotify,
|
||||
[UnmapNotify] = unmapnotify
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -62,7 +62,7 @@ flush_masked_events(long even_mask)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_buttonrelease(XEvent *e)
|
||||
buttonrelease(XEvent *e)
|
||||
{
|
||||
Frame *f;
|
||||
Bar *b;
|
||||
|
@ -84,7 +84,7 @@ handle_buttonrelease(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_motionnotify(XEvent *e)
|
||||
motionnotify(XEvent *e)
|
||||
{
|
||||
Frame *f;
|
||||
XMotionEvent *ev = &e->xmotion;
|
||||
|
@ -93,7 +93,7 @@ handle_motionnotify(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_buttonpress(XEvent *e)
|
||||
buttonpress(XEvent *e)
|
||||
{
|
||||
Frame *f;
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
|
@ -119,7 +119,7 @@ handle_buttonpress(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_configurerequest(XEvent *e)
|
||||
configurerequest(XEvent *e)
|
||||
{
|
||||
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||
XWindowChanges wc;
|
||||
|
@ -151,16 +151,16 @@ handle_configurerequest(XEvent *e)
|
|||
frect=&c->sel->revert;
|
||||
|
||||
if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
|
||||
frect->y = wc.y = -height_of_bar();
|
||||
frect->y = wc.y = -blitz_labelh(&def.font);
|
||||
frect->x = wc.x = -def.border;
|
||||
}
|
||||
else {
|
||||
frect->y = wc.y = c->rect.y - height_of_bar();
|
||||
frect->y = wc.y = c->rect.y - blitz_labelh(&def.font);
|
||||
frect->x = wc.x = c->rect.x - def.border;
|
||||
}
|
||||
frect->width = wc.width = c->rect.width + 2 * def.border;
|
||||
frect->height = wc.height = c->rect.height + def.border
|
||||
+ height_of_bar();
|
||||
+ blitz_labelh(&def.font);
|
||||
wc.border_width = 1;
|
||||
wc.sibling = None;
|
||||
wc.stack_mode = ev->detail;
|
||||
|
@ -180,9 +180,9 @@ handle_configurerequest(XEvent *e)
|
|||
|
||||
if(c && c->frame) {
|
||||
wc.x = def.border;
|
||||
wc.y = height_of_bar();
|
||||
wc.y = blitz_labelh(&def.font);
|
||||
wc.width = c->sel->rect.width - 2 * def.border;
|
||||
wc.height = c->sel->rect.height - def.border - height_of_bar();
|
||||
wc.height = c->sel->rect.height - def.border - blitz_labelh(&def.font);
|
||||
}
|
||||
|
||||
wc.border_width = 0;
|
||||
|
@ -196,7 +196,7 @@ handle_configurerequest(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_destroynotify(XEvent *e)
|
||||
destroynotify(XEvent *e)
|
||||
{
|
||||
Client *c;
|
||||
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||
|
@ -206,7 +206,7 @@ handle_destroynotify(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_enternotify(XEvent *e)
|
||||
enternotify(XEvent *e)
|
||||
{
|
||||
XCrossingEvent *ev = &e->xcrossing;
|
||||
Client *c;
|
||||
|
@ -228,7 +228,7 @@ handle_enternotify(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_leavenotify(XEvent *e)
|
||||
leavenotify(XEvent *e)
|
||||
{
|
||||
XCrossingEvent *ev = &e->xcrossing;
|
||||
|
||||
|
@ -239,7 +239,7 @@ handle_leavenotify(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_expose(XEvent *e)
|
||||
expose(XEvent *e)
|
||||
{
|
||||
XExposeEvent *ev = &e->xexpose;
|
||||
static Frame *f;
|
||||
|
@ -253,7 +253,7 @@ handle_expose(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_keypress(XEvent *e)
|
||||
keypress(XEvent *e)
|
||||
{
|
||||
XKeyEvent *ev = &e->xkey;
|
||||
KeySym k = 0;
|
||||
|
@ -273,17 +273,17 @@ handle_keypress(XEvent *e)
|
|||
blitz_kpress_input(&f->tagbar, ev->state, k, buf);
|
||||
}
|
||||
else
|
||||
handle_key(blz.root, ev->state, (KeyCode) ev->keycode);
|
||||
kpress(blz.root, ev->state, (KeyCode) ev->keycode);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_keymapnotify(XEvent *e)
|
||||
keymapnotify(XEvent *e)
|
||||
{
|
||||
update_keys();
|
||||
}
|
||||
|
||||
static void
|
||||
handle_maprequest(XEvent *e)
|
||||
maprequest(XEvent *e)
|
||||
{
|
||||
XMapRequestEvent *ev = &e->xmaprequest;
|
||||
static XWindowAttributes wa;
|
||||
|
@ -302,7 +302,7 @@ handle_maprequest(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_propertynotify(XEvent *e)
|
||||
propertynotify(XEvent *e)
|
||||
{
|
||||
XPropertyEvent *ev = &e->xproperty;
|
||||
Client *c;
|
||||
|
@ -315,7 +315,7 @@ handle_propertynotify(XEvent *e)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_unmapnotify(XEvent *e)
|
||||
unmapnotify(XEvent *e)
|
||||
{
|
||||
Client *c;
|
||||
XUnmapEvent *ev = &e->xunmap;
|
||||
|
|
|
@ -25,7 +25,7 @@ create_frame(Client *c, View *v)
|
|||
else{
|
||||
f->revert = f->rect = c->rect;
|
||||
f->revert.width = f->rect.width += 2 * def.border;
|
||||
f->revert.height = f->rect.height += def.border + height_of_bar();
|
||||
f->revert.height = f->rect.height += def.border + blitz_labelh(&def.font);
|
||||
}
|
||||
f->collapsed = False;
|
||||
|
||||
|
@ -107,7 +107,8 @@ draw_frame(Frame *f)
|
|||
}
|
||||
|
||||
f->grabbox.rect = f->tile.rect;
|
||||
f->grabbox.rect.height = f->grabbox.rect.width = height_of_bar();
|
||||
f->grabbox.rect.height = blitz_labelh(&def.font);
|
||||
f->grabbox.rect.width = def.font.height;
|
||||
|
||||
f->titlebar.rect = f->grabbox.rect;
|
||||
f->titlebar.rect.x = f->grabbox.rect.x + f->grabbox.rect.width;
|
||||
|
|
|
@ -184,7 +184,7 @@ match_keys(Key *k, unsigned long mod, KeyCode keycode, Bool seq)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_key_seq(Window w, Key *done)
|
||||
kpress_seq(Window w, Key *done)
|
||||
{
|
||||
unsigned long mod;
|
||||
KeyCode key;
|
||||
|
@ -202,12 +202,12 @@ handle_key_seq(Window w, Key *done)
|
|||
else if(!found->tnext && !found->next)
|
||||
write_event("Key %s\n", found->name);
|
||||
else
|
||||
handle_key_seq(w, found);
|
||||
kpress_seq(w, found);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_key(Window w, unsigned long mod, KeyCode keycode)
|
||||
kpress(Window w, unsigned long mod, KeyCode keycode)
|
||||
{
|
||||
Key *k;
|
||||
|
||||
|
@ -221,7 +221,7 @@ handle_key(Window w, unsigned long mod, KeyCode keycode)
|
|||
write_event("Key %s\n", found->name);
|
||||
else {
|
||||
XGrabKeyboard(blz.dpy, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
handle_key_seq(w, found);
|
||||
kpress_seq(w, found);
|
||||
XUngrabKeyboard(blz.dpy, CurrentTime);
|
||||
XSync(blz.dpy, False);
|
||||
}
|
||||
|
|
|
@ -367,7 +367,7 @@ main(int argc, char *argv[])
|
|||
| SubstructureRedirectMask | SubstructureNotifyMask;
|
||||
|
||||
s->brect = s->rect;
|
||||
s->brect.height = height_of_bar();
|
||||
s->brect.height = blitz_labelh(&def.font);
|
||||
s->brect.y = s->rect.height - s->brect.height;
|
||||
s->barwin = XCreateWindow(blz.dpy, RootWindow(blz.dpy, blz.screen),
|
||||
s->brect.x, s->brect.y,
|
||||
|
|
|
@ -220,7 +220,6 @@ Bar *create_bar(Bar **b_link, char *name);
|
|||
void destroy_bar(Bar **b_link, Bar *b);
|
||||
void draw_bar(WMScreen *s);
|
||||
void resize_bar();
|
||||
unsigned int height_of_bar();
|
||||
Bar *bar_of_name(Bar *b_link, const char *name);
|
||||
|
||||
/* client.c */
|
||||
|
@ -290,7 +289,7 @@ BlitzAlign quadofcoord(XRectangle *rect, int x, int y);
|
|||
int strtorect(XRectangle *r, const char *val);
|
||||
|
||||
/* key.c */
|
||||
void handle_key(Window w, unsigned long mod, KeyCode keycode);
|
||||
void kpress(Window w, unsigned long mod, KeyCode keycode);
|
||||
void update_keys();
|
||||
void init_lock_keys();
|
||||
unsigned long mod_key_of_str(char *val);
|
||||
|
|
|
@ -50,8 +50,8 @@ static Blitz blz = {0};
|
|||
static BlitzBrush brush = {0};
|
||||
static const int seek = 30; /* 30px */
|
||||
|
||||
static void draw_menu(void);
|
||||
static void handle_kpress(XKeyEvent * e);
|
||||
static void draw_menu();
|
||||
static void kpress(XKeyEvent * e);
|
||||
|
||||
static char version[] = "wmiimenu - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
|
||||
|
||||
|
@ -74,7 +74,7 @@ update_offsets()
|
|||
tw = blitz_textwidth(brush.font, nextoff->text);
|
||||
if(tw > mrect.width / 3)
|
||||
tw = mrect.width / 3;
|
||||
w += tw + mrect.height;
|
||||
w += tw + brush.font->height;
|
||||
if(w > mrect.width)
|
||||
break;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ update_offsets()
|
|||
tw = blitz_textwidth(brush.font, prevoff->left->text);
|
||||
if(tw > mrect.width / 3)
|
||||
tw = mrect.width / 3;
|
||||
w += tw + mrect.height;
|
||||
w += tw + brush.font->height;
|
||||
if(w > mrect.width)
|
||||
break;
|
||||
}
|
||||
|
@ -145,7 +145,6 @@ draw_menu()
|
|||
Item *i;
|
||||
|
||||
brush.align = WEST;
|
||||
|
||||
brush.rect = mrect;
|
||||
brush.rect.x = 0;
|
||||
brush.rect.y = 0;
|
||||
|
@ -169,7 +168,6 @@ draw_menu()
|
|||
}
|
||||
offx += brush.rect.width;
|
||||
|
||||
brush.align = CENTER;
|
||||
if(curroff) {
|
||||
brush.color = normcolor;
|
||||
brush.rect.x = offx;
|
||||
|
@ -185,7 +183,7 @@ draw_menu()
|
|||
brush.rect.width = blitz_textwidth(brush.font, i->text);
|
||||
if(brush.rect.width > mrect.width / 3)
|
||||
brush.rect.width = mrect.width / 3;
|
||||
brush.rect.width += mrect.height;
|
||||
brush.rect.width += brush.font->height;
|
||||
if(sel == i) {
|
||||
brush.color = selcolor;
|
||||
brush.border = True;
|
||||
|
@ -206,7 +204,7 @@ draw_menu()
|
|||
}
|
||||
|
||||
static void
|
||||
handle_kpress(XKeyEvent * e)
|
||||
kpress(XKeyEvent * e)
|
||||
{
|
||||
KeySym ksym;
|
||||
char buf[32];
|
||||
|
@ -423,11 +421,10 @@ main(int argc, char *argv[])
|
|||
|
||||
wa.override_redirect = 1;
|
||||
wa.background_pixmap = ParentRelative;
|
||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask
|
||||
| SubstructureRedirectMask | SubstructureNotifyMask;
|
||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
||||
|
||||
mrect.width = DisplayWidth(blz.dpy, blz.screen);
|
||||
mrect.height = font.ascent + font.descent + 4;
|
||||
mrect.height = blitz_labelh(&font);
|
||||
mrect.y = DisplayHeight(blz.dpy, blz.screen) - mrect.height;
|
||||
mrect.x = 0;
|
||||
|
||||
|
@ -452,12 +449,12 @@ main(int argc, char *argv[])
|
|||
brush.font = &font;
|
||||
|
||||
if(maxname)
|
||||
cwidth = blitz_textwidth(brush.font, maxname) + mrect.height;
|
||||
cwidth = blitz_textwidth(brush.font, maxname) + brush.font->height;
|
||||
if(cwidth > mrect.width / 3)
|
||||
cwidth = mrect.width / 3;
|
||||
|
||||
if(title) {
|
||||
twidth = blitz_textwidth(brush.font, title) + mrect.height;
|
||||
twidth = blitz_textwidth(brush.font, title) + brush.font->height;
|
||||
if(twidth > mrect.width / 3)
|
||||
twidth = mrect.width / 3;
|
||||
}
|
||||
|
@ -474,7 +471,7 @@ main(int argc, char *argv[])
|
|||
while(!XNextEvent(blz.dpy, &ev)) {
|
||||
switch (ev.type) {
|
||||
case KeyPress:
|
||||
handle_kpress(&ev.xkey);
|
||||
kpress(&ev.xkey);
|
||||
break;
|
||||
case Expose:
|
||||
if(ev.xexpose.count == 0) {
|
||||
|
|
|
@ -50,6 +50,7 @@ struct BlitzFont {
|
|||
XFontSet set;
|
||||
int ascent;
|
||||
int descent;
|
||||
unsigned int height;
|
||||
char *fontstr;
|
||||
};
|
||||
|
||||
|
@ -111,6 +112,7 @@ void blitz_drawcursor(Display *dpy, Drawable drawable, GC gc,
|
|||
unsigned int blitz_textwidth(BlitzFont *font, char *text);
|
||||
unsigned int blitz_textwidth_l(BlitzFont *font, char *text, unsigned int len);
|
||||
void blitz_loadfont(Blitz *blitz, BlitzFont *font);
|
||||
unsigned int blitz_labelh(BlitzFont *font);
|
||||
|
||||
/* input.c */
|
||||
void blitz_draw_input(BlitzInput *i);
|
||||
|
|
|
@ -19,42 +19,36 @@ blitz_draw_tile(BlitzBrush *b)
|
|||
void
|
||||
blitz_draw_label(BlitzBrush *b, char *text)
|
||||
{
|
||||
unsigned int x, y, w, h, shortened, len;
|
||||
unsigned int x, y, w, h, len;
|
||||
Bool shortened = False;
|
||||
static char buf[2048];
|
||||
XGCValues gcv;
|
||||
|
||||
blitz_draw_tile(b);
|
||||
|
||||
if (!text)
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
x = y = shortened = 0;
|
||||
w = h = 1;
|
||||
shortened = 0;
|
||||
cext_strlcpy(buf, text, sizeof(buf));
|
||||
len = strlen(buf);
|
||||
gcv.foreground = b->color.fg;
|
||||
gcv.background = b->color.bg;
|
||||
if(b->font->set)
|
||||
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground, &gcv);
|
||||
else {
|
||||
gcv.font = b->font->xfont->fid;
|
||||
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
|
||||
}
|
||||
|
||||
h = b->font->ascent + b->font->descent;
|
||||
y = b->rect.y + b->rect.height / 2 - h / 2 + b->font->ascent;
|
||||
|
||||
/* shorten text if necessary */
|
||||
while (len && (w = blitz_textwidth(b->font, buf)) > b->rect.width - h) {
|
||||
while(len && (w = blitz_textwidth(b->font, buf)) > b->rect.width - h) {
|
||||
buf[--len] = 0;
|
||||
shortened = 1;
|
||||
shortened = True;
|
||||
}
|
||||
|
||||
if (w > b->rect.width)
|
||||
if(w > b->rect.width)
|
||||
return;
|
||||
|
||||
/* mark shortened info in the string */
|
||||
if (shortened) {
|
||||
if(shortened) {
|
||||
if (len > 3)
|
||||
buf[len - 3] = '.';
|
||||
if (len > 2)
|
||||
|
@ -62,24 +56,24 @@ blitz_draw_label(BlitzBrush *b, char *text)
|
|||
if (len > 1)
|
||||
buf[len - 1] = '.';
|
||||
}
|
||||
/* shorten text more if necessary */
|
||||
while (len && (w = blitz_textwidth(b->font, buf)) > b->rect.width - h)
|
||||
buf[--len] = 0;
|
||||
|
||||
switch (b->align) {
|
||||
case EAST:
|
||||
x = b->rect.x + b->rect.width - (h / 2 + w);
|
||||
break;
|
||||
case CENTER:
|
||||
x = b->rect.x + h / 2 + (b->rect.width - h - w) / 2;
|
||||
x = b->rect.x + b->rect.width - (w + (b->font->height / 2));
|
||||
break;
|
||||
default:
|
||||
x = b->rect.x + h / 2;
|
||||
x = b->rect.x + (b->font->height / 2);
|
||||
break;
|
||||
}
|
||||
if(b->font->set)
|
||||
|
||||
if(b->font->set) {
|
||||
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground, &gcv);
|
||||
XmbDrawImageString(b->blitz->dpy, b->drawable, b->font->set, b->gc,
|
||||
x, y, buf, len);
|
||||
else
|
||||
}
|
||||
else {
|
||||
gcv.font = b->font->xfont->fid;
|
||||
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
|
||||
XDrawImageString(b->blitz->dpy, b->drawable, b->gc, x, y, buf, len);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,4 +81,11 @@ blitz_loadfont(Blitz *blitz, BlitzFont *font)
|
|||
font->ascent = font->xfont->ascent;
|
||||
font->descent = font->xfont->descent;
|
||||
}
|
||||
font->height = font->ascent + font->descent;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
blitz_labelh(BlitzFont *font)
|
||||
{
|
||||
return font->height + 4;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ blitz_draw_input(BlitzInput *i)
|
|||
|
||||
h = (i->font->ascent + i->font->descent);
|
||||
yoff = i->rect.y + (i->rect.height - h) / 2 + i->font->ascent;
|
||||
xcursor = xoff = i->rect.x + i->rect.height / 2;
|
||||
xcursor = xoff = i->rect.x + i->font->height / 2;
|
||||
|
||||
start = curstart(i);
|
||||
end = curend(i);
|
||||
|
@ -160,7 +160,7 @@ charof(BlitzInput *i, int x, int y)
|
|||
return nil;
|
||||
|
||||
/* normalize and check x */
|
||||
if((x -= (i->rect.x + i->rect.height / 2)) < 0)
|
||||
if((x -= (i->rect.x + i->font->height / 2)) < 0)
|
||||
return i->text;
|
||||
else if(x > blitz_textwidth_l(i->font, i->text, i->len))
|
||||
return i->text + i->len;
|
||||
|
|
Loading…
Reference in New Issue