mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
fix double free bug, simplify error handling, reduce X11 calls
This commit is contained in:
parent
3e764832bc
commit
846f724983
1 changed files with 58 additions and 63 deletions
|
@ -24,7 +24,6 @@ struct Win {
|
|||
|
||||
XDisplay *dpy;
|
||||
XWindow root;
|
||||
|
||||
Atom net_active_window;
|
||||
Reprog *exclude = nil;
|
||||
Win *win;
|
||||
|
@ -38,8 +37,7 @@ Font *font;
|
|||
Image *lightblue;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
PAD = 3,
|
||||
MARGIN = 5
|
||||
};
|
||||
|
@ -71,7 +69,7 @@ estrdup(char *s)
|
|||
s = strdup(s);
|
||||
if(s==nil)
|
||||
sysfatal("out of memory allocating");
|
||||
return s;
|
||||
return(s);
|
||||
}
|
||||
|
||||
char*
|
||||
|
@ -90,10 +88,10 @@ getproperty(XWindow w, Atom a)
|
|||
|
||||
if(s!=0){
|
||||
XFree(p);
|
||||
return nil;
|
||||
return(nil);
|
||||
}
|
||||
|
||||
return (char*)p;
|
||||
return((char*)p);
|
||||
}
|
||||
|
||||
XWindow
|
||||
|
@ -109,14 +107,14 @@ findname(XWindow w)
|
|||
p = getproperty(w, XA_WM_NAME);
|
||||
if(p){
|
||||
free(p);
|
||||
return w;
|
||||
return(w);
|
||||
}
|
||||
|
||||
net_wm_name = XInternAtom(dpy, "_NET_WM_NAME", FALSE);
|
||||
p = getproperty(w, net_wm_name);
|
||||
if(p){
|
||||
free(p);
|
||||
return w;
|
||||
return(w);
|
||||
}
|
||||
|
||||
rwin = 0;
|
||||
|
@ -144,6 +142,7 @@ wcmp(const void *w1, const void *w2)
|
|||
}
|
||||
|
||||
/* unicode-aware case-insensitive strcmp, taken from golang’s gc/subr.c */
|
||||
|
||||
int
|
||||
_cistrcmp(char *p, char *q)
|
||||
{
|
||||
|
@ -194,7 +193,6 @@ refreshwin(void)
|
|||
XFree(xwin);
|
||||
return;
|
||||
}
|
||||
|
||||
qsort(xwin, nxwin, sizeof(xwin[0]), wcmp);
|
||||
|
||||
nw = 0;
|
||||
|
@ -257,7 +255,6 @@ refreshwin(void)
|
|||
mwin += 8;
|
||||
win = erealloc(win, mwin * sizeof(win[0]));
|
||||
}
|
||||
|
||||
win[nw].n = xwin[i];
|
||||
win[nw].label = estrdup(label);
|
||||
win[nw].dirty = 1;
|
||||
|
@ -455,6 +452,8 @@ main(int argc, char **argv)
|
|||
if(argc)
|
||||
usage();
|
||||
|
||||
einit(Emouse | Ekeyboard);
|
||||
Etimer = etimer(0, 1000);
|
||||
|
||||
dpy = XOpenDisplay("");
|
||||
if(dpy==nil)
|
||||
|
@ -471,14 +470,10 @@ main(int argc, char **argv)
|
|||
if(font==nil)
|
||||
sysfatal("font '%s' not found", fontname);
|
||||
|
||||
einit(Emouse | Ekeyboard);
|
||||
Etimer = etimer(0, 1000);
|
||||
|
||||
XSetErrorHandler(winwatchxerrorhandler);
|
||||
|
||||
refreshwin();
|
||||
redraw(screen, 1);
|
||||
|
||||
for(;;){
|
||||
switch(eread(Emouse|Ekeyboard|Etimer, &e)){
|
||||
case Ekeyboard:
|
||||
|
|
Loading…
Reference in a new issue