X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=mod_statusbar%2Fmain.c;h=777e0b31fe37b3802d8ce7c066e96689d89abd19;hp=bf0e1d0034c101fe1ef823d7a2dc24976945a6b8;hb=e3aec18706513a87eaa7839dfdaf7e0fcd0d8d2a;hpb=803afbc1cd633f6c025bcd9537e9b7e9aedadd0d diff --git a/mod_statusbar/main.c b/mod_statusbar/main.c index bf0e1d0..777e0b3 100644 --- a/mod_statusbar/main.c +++ b/mod_statusbar/main.c @@ -1,35 +1,22 @@ /* * ion/mod_statusbar/main.c * - * Copyright (c) Tuomo Valkonen 1999-2007. + * Copyright (c) Tuomo Valkonen 1999-2009. * - * Ion is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. + * See the included file LICENSE for details. */ -#include -#include -#include -#include -#include - #include #include -#include -#include #include #include #include +#include #include "statusbar.h" #include "exports.h" -#define CF_STATUSD_TIMEOUT_SEC 5 - - /*{{{ Module information */ @@ -50,159 +37,6 @@ WBindmap *mod_statusbar_statusbar_bindmap=NULL; /*}}}*/ -/*{{{ Statusd launch helper */ - - -#define BL 1024 - - -static bool process_pipe(int fd, ExtlFn fn, - bool *doneseen, bool *eagain) -{ - char buf[BL]; - int n; - bool fnret; - - *eagain=FALSE; - - n=read(fd, buf, BL-1); - - if(n<0){ - if(errno==EAGAIN || errno==EINTR){ - *eagain=(errno==EAGAIN); - return TRUE; - } - warn_err_obj(TR("reading a pipe")); - return FALSE; - }else if(n>0){ - buf[n]='\0'; - *doneseen=FALSE; - return extl_call(fn, "s", "b", &buf, doneseen); - } - - return FALSE; -} - - -#define USEC 1000000 - - -static bool wait_statusd_init(int outfd, int errfd, ExtlFn dh, ExtlFn eh) -{ - fd_set rfds; - struct timeval tv, endtime, now; - int nfds=maxof(outfd, errfd); - int retval; - bool dummy, doneseen, eagain=FALSE; - - if(gettimeofday(&endtime, NULL)!=0){ - warn_err(); - return FALSE; - } - - now=endtime; - endtime.tv_sec+=CF_STATUSD_TIMEOUT_SEC; - - while(1){ - FD_ZERO(&rfds); - - /* Calculate remaining time */ - if(now.tv_sec>endtime.tv_sec){ - goto timeout; - }else if(now.tv_sec==endtime.tv_sec){ - if(now.tv_usec>=endtime.tv_usec) - goto timeout; - tv.tv_sec=0; - tv.tv_usec=endtime.tv_usec-now.tv_usec; - }else{ - tv.tv_usec=USEC+endtime.tv_usec-now.tv_usec; - tv.tv_sec=-1+endtime.tv_sec-now.tv_sec; - /* Kernel lameness tuner: */ - tv.tv_sec+=tv.tv_usec/USEC; - tv.tv_usec%=USEC; - } - - FD_SET(outfd, &rfds); - FD_SET(errfd, &rfds); - - retval=select(nfds+1, &rfds, NULL, NULL, &tv); - if(retval>0){ - if(FD_ISSET(errfd, &rfds)){ - if(!process_pipe(errfd, eh, &dummy, &eagain)) - return FALSE; - } - if(FD_ISSET(outfd, &rfds)){ - if(!process_pipe(outfd, dh, &doneseen, &eagain)) - return FALSE; - if(doneseen){ - /* Read rest of errors. */ - bool ok; - do{ - ok=process_pipe(errfd, eh, &dummy, &eagain); - }while(ok && !eagain); - return TRUE; - } - } - }else if(retval==0){ - goto timeout; - } - - if(gettimeofday(&now, NULL)!=0){ - warn_err(); - return FALSE; - } - } - - return TRUE; - -timeout: - warn(TR("ion-statusd timed out.")); - return FALSE; -} - - -EXTL_EXPORT -int mod_statusbar__launch_statusd(const char *cmd, - ExtlFn initdatahandler, - ExtlFn initerrhandler, - ExtlFn datahandler, - ExtlFn errhandler) -{ - pid_t pid; - int outfd=-1, errfd=-1; - - if(cmd==NULL) - return -1; - - pid=mainloop_do_spawn(cmd, NULL, NULL, - NULL, &outfd, &errfd); - - if(pid<0) - return -1; - - if(!wait_statusd_init(outfd, errfd, initdatahandler, initerrhandler)) - goto err; - - if(!mainloop_register_input_fd_extlfn(outfd, datahandler)) - goto err; - - if(!mainloop_register_input_fd_extlfn(errfd, errhandler)) - goto err2; - - return pid; - -err2: - mainloop_unregister_input_fd(outfd); -err: - close(outfd); - close(errfd); - return -1; -} - - -/*}}}*/ - - /*{{{ Systray */ @@ -254,7 +88,7 @@ static bool clientwin_do_manage_hook(WClientWin *cwin, const WManageParams *para return FALSE; return region_manage_clientwin((WRegion*)sb, cwin, param, - MANAGE_REDIR_PREFER_NO); + MANAGE_PRIORITY_NONE); }