/* * This file is part of firk's window manager for x11 (fwm) * Copyright (C) 2016-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 "main.h" #include "base.h" #include "config.h" #include "winlist.h" #include "taskbar.h" #include "error.h" static volatile int got_sighup = 0; static void hup_sig_handle(int signum) { got_sighup = 1; } static void init_signals(void) { struct sigaction sa; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sa.sa_handler = hup_sig_handle; sigaction(SIGHUP, &sa, NULL); } time_t now; 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: %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: (fatal) %s\n", buf); exit(-1); } int main(int argc, char const * const * argv) { int status; XEvent ev; if(argc>=2) { if(!strcmp(argv[1],"--help")) { fputs("fwm: firk's window manager for x11\n" "built "__DATE__"\n" "Copyright (C) 2016-2022 firk \n\n" "Usage:\n" " fwm (without args)\n" " fwm /path/to/config [/path/to/config2 ...]\n", stdout); return 0; } if(!strcmp(argv[1],"--version")) { fputs("fwm: firk's window manager for x11\n" "built "__DATE__"\n" "Copyright (C) 2016-2022 firk \n", stdout); return 0; } if(!strcmp(argv[1],"--license")) { fputs("fwm: firk's window manager for x11\n" "built "__DATE__"\n" "Copyright (C) 2016-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<2) load_configs(0,NULL); else load_configs(argc-1, argv+1); base_init(NULL); taskbar_update(); error_init(); XSync(display, False); run_startup(); init_signals(); check_holidays_file(1); while(1) { XSync(display, False); time(&now); waitpid(-1, &status, WNOHANG); taskbar_periodic(); if(got_sighup) { got_sighup = 0; check_holidays_file(1); taskbar_timer_update(1); } if(!base_get_event(&ev)) { usleep(10000); continue; } if(taskbar_created) { if(ev.type==Expose && ev.xexpose.window==taskbar_window || (ev.type==ButtonPress || ev.type==ButtonRelease) && ev.xbutton.window==taskbar_window || ev.type==MotionNotify && ev.xmotion.window==taskbar_window || ev.type==LeaveNotify && ev.xcrossing.window==taskbar_window) { taskbar_handle_event(&ev); continue; } } if(base_handle_event(&ev)) { if(ev.type==ConfigureNotify) taskbar_update(); continue; } logprint("got unhandled event %d", ev.type); } }