/* * This file is part of firk's window manager for x11 (fwm) * Copyright (C) 2022 firk * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include "fwm-menu.h" #include "xdg_parser.h" #include "dirscan.h" extern void logprint(char const * fmt, ...) { char buf[110]; va_list arg; va_start(arg, fmt); vsnprintf(buf, sizeof(buf), fmt, arg); va_end(arg); fprintf(stderr, "fwm-menu: %s\n", buf); } extern void failprint(char const * fmt, ...) { char buf[110]; va_list arg; va_start(arg, fmt); vsnprintf(buf, sizeof(buf), fmt, arg); va_end(arg); fprintf(stderr, "fwm-menu: (fatal) %s\n", buf); exit(-1); } static void parse_winprops(char const *a, winprops *r) { bzero(r, sizeof(*r)); if(!a || !*a) return; r->o = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->x0 = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->y0 = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->w = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->h = atoi(a); if(!(a = strchr(a,':')) || !*(++a)) return; r->bw = atoi(a); } static void event_loop(void); int main(int argc, char **argv) { winprops wp; int i; if(argc>=2) { if(!strcmp(argv[1],"--help")) { fputs("fwm-menu: firk's window manager for x11 - menu\n" "built "__DATE__"\n" "Copyright (C) 2022 firk \n\n" "Usage:\n" " fwm-menu o:x0:y0:w:h:bw font-name /path/to/menudir [/path/to/menudir2 [...]]\n", stdout); return 0; } if(!strcmp(argv[1],"--version")) { fputs("fwm-menu: firk's window manager for x11 - menu\n" "built "__DATE__"\n" "Copyright (C) 2022 firk \n", stdout); return 0; } if(!strcmp(argv[1],"--license")) { fputs("fwm-menu: firk's window manager for x11 - menu\n" "built "__DATE__"\n" "Copyright (C) 2022 firk \n\n" "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License version 2\n" "as published by the Free Software Foundation.\n\n" "This program is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "GNU General Public License for more details.\n\n" "You should have received a copy of the GNU General Public License along\n" "with this program; if not, write to the Free Software Foundation, Inc.,\n" "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n" "Source and other official downloads here: https://firk.cantconnect.ru/projects/fwmx/\n", stdout); return 0; } } if(argc<4) { fprintf(stderr, "Usage: fwm-menu o:x0:y0:w:h:bw font-name /path/to/menudir [/path/to/menudir2 [...]]\n"); return -1; } parse_winprops(argv[1], &wp); font_name = argv[2]; if(!*font_name) font_name = DEFAULT_FONT_NAME; for(i=3; i0); assert(JMname); if(!me->xdg.command) { fd_idx = menus[JM].e.list[idx].fd_idx; assert(fd_idx < ND); snprintf(path, sizeof(path), "%s/", dirs[fd_idx]); len = strlen(path); if(len>=sizeof(path)-1) { logprint("path too long"); return; } for(j=0,ml=menus; je.sel_stable; assert(sel < ml->e.n); snprintf(path+len, sizeof(path)-len, "%s/", ml->e.list[sel].name); len += strlen(path+len); if(len>=sizeof(path)-1) { logprint("path too long"); return; } } sel = idx; assert(sel < ml->e.n); snprintf(path+len, sizeof(path)-len, "%s", ml->e.list[sel].name); len += strlen(path+len); if(len>=sizeof(path)-1) { logprint("path too long"); return; } } if((fr = fork())<0) { logprint("fork() error %d (%s)", errno, strerror(errno)); return; } if(fr) return; if(me->xdg.path && chdir(me->xdg.path)<0) { logprint("chdir(%s) error %d (%s)", me->xdg.path, errno, strerror(errno)); exit(-1); } if(!me->xdg.command) { args[0] = path; args[1] = NULL; } else if(!me->xdg.use_term) { args[0] = "/bin/sh"; args[1] = "-c"; args[2] = (char*)me->xdg.command; args[3] = NULL; } else { args[0] = "/usr/bin/x-terminal-emulator"; args[1] = "-e"; args[2] = (char*)me->xdg.command; args[3] = NULL; } for(j=3; j<1000; j++) close(j); execve(args[0], args, environ); logprint("execve() error %d (%s)", errno, strerror(errno)); exit(-1); }