aewl
diff menu.c @ 26:e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Wed, 12 Jul 2006 15:17:22 +0200 |
parents | 5cc5e55a132d |
children | 386649deb651 |
line diff
1.1 --- a/menu.c Wed Jul 12 00:53:11 2006 +0200 1.2 +++ b/menu.c Wed Jul 12 15:17:22 2006 +0200 1.3 @@ -31,7 +31,6 @@ 1.4 static Display *dpy; 1.5 static Window root; 1.6 static Window win; 1.7 -static XRectangle rect; 1.8 static Bool done = False; 1.9 1.10 static Item *allitem = NULL; /* first of all items */ 1.11 @@ -41,14 +40,14 @@ 1.12 static Item *prevoff = NULL; 1.13 static Item *curroff = NULL; 1.14 1.15 -static int screen; 1.16 +static int screen, mx, my, mw, mh; 1.17 static char *title = NULL; 1.18 static char text[4096]; 1.19 static int ret = 0; 1.20 static int nitem = 0; 1.21 static unsigned int cmdw = 0; 1.22 -static unsigned int twidth = 0; 1.23 -static unsigned int cwidth = 0; 1.24 +static unsigned int tw = 0; 1.25 +static unsigned int cw = 0; 1.26 static const int seek = 30; /* 30px */ 1.27 1.28 static Brush brush = {0}; 1.29 @@ -74,21 +73,21 @@ 1.30 return; 1.31 1.32 for(nextoff = curroff; nextoff; nextoff=nextoff->right) { 1.33 - tw = textwidth(&brush.font, nextoff->text); 1.34 - if(tw > rect.width / 3) 1.35 - tw = rect.width / 3; 1.36 + tw = textw(&brush.font, nextoff->text); 1.37 + if(tw > mw / 3) 1.38 + tw = mw / 3; 1.39 w += tw + brush.font.height; 1.40 - if(w > rect.width) 1.41 + if(w > mw) 1.42 break; 1.43 } 1.44 1.45 w = cmdw + 2 * seek; 1.46 for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) { 1.47 - tw = textwidth(&brush.font, prevoff->left->text); 1.48 - if(tw > rect.width / 3) 1.49 - tw = rect.width / 3; 1.50 + tw = textw(&brush.font, prevoff->left->text); 1.51 + if(tw > mw / 3) 1.52 + tw = mw / 3; 1.53 w += tw + brush.font.height; 1.54 - if(w > rect.width) 1.55 + if(w > mw) 1.56 break; 1.57 } 1.58 } 1.59 @@ -103,9 +102,9 @@ 1.60 return; 1.61 1.62 if(!title || *pattern) 1.63 - cmdw = cwidth; 1.64 + cmdw = cw; 1.65 else 1.66 - cmdw = twidth; 1.67 + cmdw = tw; 1.68 1.69 item = j = NULL; 1.70 nitem = 0; 1.71 @@ -143,42 +142,40 @@ 1.72 static void 1.73 draw_menu() 1.74 { 1.75 - unsigned int offx = 0; 1.76 Item *i; 1.77 1.78 - brush.rect = rect; 1.79 - brush.rect.x = 0; 1.80 - brush.rect.y = 0; 1.81 + brush.x = 0; 1.82 + brush.y = 0; 1.83 + brush.w = mw; 1.84 + brush.h = mh; 1.85 draw(dpy, &brush, False, 0); 1.86 1.87 /* print command */ 1.88 if(!title || text[0]) { 1.89 - cmdw = cwidth; 1.90 + cmdw = cw; 1.91 if(cmdw && item) 1.92 - brush.rect.width = cmdw; 1.93 + brush.w = cmdw; 1.94 draw(dpy, &brush, False, text); 1.95 } 1.96 else { 1.97 - cmdw = twidth; 1.98 - brush.rect.width = cmdw; 1.99 + cmdw = tw; 1.100 + brush.w = cmdw; 1.101 draw(dpy, &brush, False, title); 1.102 } 1.103 - offx += brush.rect.width; 1.104 + brush.x += brush.w; 1.105 1.106 if(curroff) { 1.107 - brush.rect.x = offx; 1.108 - brush.rect.width = seek; 1.109 - offx += brush.rect.width; 1.110 + brush.w = seek; 1.111 draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0); 1.112 + brush.x += brush.w; 1.113 1.114 /* determine maximum items */ 1.115 for(i = curroff; i != nextoff; i=i->right) { 1.116 brush.border = False; 1.117 - brush.rect.x = offx; 1.118 - brush.rect.width = textwidth(&brush.font, i->text); 1.119 - if(brush.rect.width > rect.width / 3) 1.120 - brush.rect.width = rect.width / 3; 1.121 - brush.rect.width += brush.font.height; 1.122 + brush.w = textw(&brush.font, i->text); 1.123 + if(brush.w > mw / 3) 1.124 + brush.w = mw / 3; 1.125 + brush.w += brush.font.height; 1.126 if(sel == i) { 1.127 swap((void **)&brush.fg, (void **)&brush.bg); 1.128 draw(dpy, &brush, True, i->text); 1.129 @@ -186,15 +183,14 @@ 1.130 } 1.131 else 1.132 draw(dpy, &brush, False, i->text); 1.133 - offx += brush.rect.width; 1.134 + brush.x += brush.w; 1.135 } 1.136 1.137 - brush.rect.x = rect.width - seek; 1.138 - brush.rect.width = seek; 1.139 + brush.x = mw - seek; 1.140 + brush.w = seek; 1.141 draw(dpy, &brush, False, nextoff ? ">" : 0); 1.142 } 1.143 - XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width, 1.144 - rect.height, 0, 0); 1.145 + XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0); 1.146 XFlush(dpy); 1.147 } 1.148 1.149 @@ -399,36 +395,35 @@ 1.150 wa.background_pixmap = ParentRelative; 1.151 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; 1.152 1.153 - rect.width = DisplayWidth(dpy, screen); 1.154 - rect.height = labelheight(&brush.font); 1.155 - rect.y = DisplayHeight(dpy, screen) - rect.height; 1.156 - rect.x = 0; 1.157 + mx = my = 0; 1.158 + mw = DisplayWidth(dpy, screen); 1.159 + mh = texth(&brush.font); 1.160 1.161 - win = XCreateWindow(dpy, root, rect.x, rect.y, 1.162 - rect.width, rect.height, 0, DefaultDepth(dpy, screen), 1.163 - CopyFromParent, DefaultVisual(dpy, screen), 1.164 + win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, 1.165 + DefaultDepth(dpy, screen), CopyFromParent, 1.166 + DefaultVisual(dpy, screen), 1.167 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 1.168 XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); 1.169 XFlush(dpy); 1.170 1.171 /* pixmap */ 1.172 brush.gc = XCreateGC(dpy, root, 0, 0); 1.173 - brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height, 1.174 + brush.drawable = XCreatePixmap(dpy, win, mw, mh, 1.175 DefaultDepth(dpy, screen)); 1.176 XFlush(dpy); 1.177 1.178 if(maxname) 1.179 - cwidth = textwidth(&brush.font, maxname) + brush.font.height; 1.180 - if(cwidth > rect.width / 3) 1.181 - cwidth = rect.width / 3; 1.182 + cw = textw(&brush.font, maxname) + brush.font.height; 1.183 + if(cw > mw / 3) 1.184 + cw = mw / 3; 1.185 1.186 if(title) { 1.187 - twidth = textwidth(&brush.font, title) + brush.font.height; 1.188 - if(twidth > rect.width / 3) 1.189 - twidth = rect.width / 3; 1.190 + tw = textw(&brush.font, title) + brush.font.height; 1.191 + if(tw > mw / 3) 1.192 + tw = mw / 3; 1.193 } 1.194 1.195 - cmdw = title ? twidth : cwidth; 1.196 + cmdw = title ? tw : cw; 1.197 1.198 text[0] = 0; 1.199 update_items(text);