On Sun, Dec 22, 2019 at 11:27:16AM -0600, Devin J. Pohly wrote:
> Not too aggressive, stuck to changes that should be uncontroversial:
> - XFree, like free, is specified to do nothing when passed NULL, so no
>   need to duplicate that check ourselves
> - Flip if conditions to save lines in enternotify and maprequest
> - No need for the "exists" variable in sendevent when "n" will suffice
> ---
>  dwm.c | 50 ++++++++++++++++++++++----------------------------
>  1 file changed, 22 insertions(+), 28 deletions(-)
> 
> diff --git a/dwm.c b/dwm.c
> index 4465af1..7fa5055 100644
> --- a/dwm.c
> +++ b/dwm.c
> @@ -304,10 +304,8 @@ applyrules(Client *c)
>                               c->mon = m;
>               }
>       }
> -     if (ch.res_class)
> -             XFree(ch.res_class);
> -     if (ch.res_name)
> -             XFree(ch.res_name);
> +     XFree(ch.res_class);
> +     XFree(ch.res_name);
>       c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : 
> c->mon->tagset[c->mon->seltags];
>  }
>  
> @@ -765,9 +763,8 @@ enternotify(XEvent *e)
>       if (m != selmon) {
>               unfocus(selmon->sel, 1);
>               selmon = m;
> -     } else if (!c || c == selmon->sel)
> -             return;
> -     focus(c);
> +     } else if (c && c != selmon->sel)
> +             focus(c);
>  }
>  
>  void
> @@ -1094,10 +1091,9 @@ maprequest(XEvent *e)
>  
>       if (!XGetWindowAttributes(dpy, ev->window, &wa))
>               return;
> -     if (wa.override_redirect)
> +     if (wa.override_redirect || wintoclient(ev->window))
>               return;
> -     if (!wintoclient(ev->window))
> -             manage(ev->window, &wa);
> +     manage(ev->window, &wa);
>  }
>  
>  void
> @@ -1402,8 +1398,7 @@ scan(void)
>                       && (wa.map_state == IsViewable || getstate(wins[i]) == 
> IconicState))
>                               manage(wins[i], &wa);
>               }
> -             if (wins)
> -                     XFree(wins);
> +             XFree(wins);
>       }
>  }
>  
> @@ -1437,24 +1432,23 @@ sendevent(Client *c, Atom proto)
>  {
>       int n;
>       Atom *protocols;
> -     int exists = 0;
>       XEvent ev;
>  
> -     if (XGetWMProtocols(dpy, c->win, &protocols, &n)) {
> -             while (!exists && n--)
> -                     exists = protocols[n] == proto;
> -             XFree(protocols);
> -     }
> -     if (exists) {
> -             ev.type = ClientMessage;
> -             ev.xclient.window = c->win;
> -             ev.xclient.message_type = wmatom[WMProtocols];
> -             ev.xclient.format = 32;
> -             ev.xclient.data.l[0] = proto;
> -             ev.xclient.data.l[1] = CurrentTime;
> -             XSendEvent(dpy, c->win, False, NoEventMask, &ev);
> -     }
> -     return exists;
> +     if (!XGetWMProtocols(dpy, c->win, &protocols, &n))
> +             return 0;
> +     while (n-- && protocols[n] != proto);
> +     XFree(protocols);
> +     if (n < 0)
> +             return 0;
> +
> +     ev.type = ClientMessage;
> +     ev.xclient.window = c->win;
> +     ev.xclient.message_type = wmatom[WMProtocols];
> +     ev.xclient.format = 32;
> +     ev.xclient.data.l[0] = proto;
> +     ev.xclient.data.l[1] = CurrentTime;
> +     XSendEvent(dpy, c->win, False, NoEventMask, &ev);
> +     return 1;
>  }
>  
>  void
> -- 
> 2.24.1
> 
> 

Hi,

Regarding XFree():
https://www.x.org/releases/current/doc/libX11/libX11/libX11.txt

"A NULL pointer cannot be passed to this function."

Where is it specified it can be NULL?


I think the current sendevent() code is more readable.

-- 
Kind regards,
Hiltjo

Reply via email to