1 /*
2 Helper functions specific to alttab.
3 
4 Copyright 2017-2021 Alexander Kulak.
5 This file is part of alttab program.
6 
7 alttab is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 alttab is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with alttab.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "alttab.h"
22 #include "icon.h"
23 #include <signal.h>
24 #include <utlist.h>
25 #include <uthash.h>
26 extern Globals g;
27 //extern Display* dpy;
28 //extern int scr;
29 //extern Window root;
30 
31 // PUBLIC
32 
33 //
34 // diagnostic message
35 //
msg(int lvl,const char * format,...)36 void msg(int lvl, const char *format, ...)
37 {
38     if (g.debug > lvl) {
39         if (lvl == -1) {
40             fprintf(stderr, MSGPREFIX);
41         }
42         va_list ap;
43         va_start(ap, format);
44         vfprintf(stderr, format, ap);
45         va_end(ap);
46     }
47 }
48 
49 //
50 // fatal exit with explanation
51 //
die(const char * format,...)52 void die(const char *format, ...)
53 {
54     va_list ap;
55     fprintf(stderr, MSGPREFIX);
56     va_start(ap, format);
57     vfprintf(stderr, format, ap);
58     va_end(ap);
59     exit(1);
60 }
61 
62 //
63 // signal handler
64 //
sighandler(int signum)65 void sighandler(int signum)
66 {
67     PermanentWindowInfo *pwi;
68     int sln, in;
69     switch (signum) {
70         case SIGUSR1:
71             fprintf(stderr, "debug information:\n");
72             fprintf(stderr, "winlist: %d elements of %ld bytes, %ld total\n",
73                     g.maxNdx, sizeof(WindowInfo), g.maxNdx*sizeof(WindowInfo) );
74             DL_COUNT(g.sortlist, pwi, sln);
75             fprintf(stderr, "sortlist: %d elements of %ld bytes, %ld total\n",
76                     sln, sizeof(PermanentWindowInfo), sln*sizeof(PermanentWindowInfo) );
77             in = HASH_COUNT(g.ic);
78             fprintf(stderr, "icons: %d elements of %ld bytes, %ld total\n",
79                     in, sizeof(icon_t), in*sizeof(icon_t) );
80             fprintf(stderr, "option_wm: %d, option_desktop: %d, option_screen: %d\n",
81                     g.option_wm, g.option_desktop, g.option_screen);
82             fprintf(stderr, "option_font: '%s'\n", g.option_font);
83             fprintf(stderr, "option_tileW/H: %dx%d, option_iconW/H: %dx%d\n",
84                     g.option_tileW, g.option_tileH, g.option_iconW, g.option_iconH);
85             fprintf(stderr, "option_vp_mode: %d, vp: [%dx%d+%d+%d], has_randr: %d\n",
86                     g.option_vp_mode, g.vp.w, g.vp.h, g.vp.x, g.vp.y, g.has_randr);
87             fprintf(stderr, "option_positioning: %d, option_posX/Y: %d, %d\n",
88                 g.option_positioning, g.option_posX, g.option_posY);
89             fprintf(stderr, "option_iconSrc: %d, option_theme: '%s'\n",
90                 g.option_iconSrc, g.option_theme);
91             fprintf(stderr, "ewmh: wmname '%s', tslf %d, -1du %d\n",
92                 g.ewmh.wmname, g.ewmh.try_stacking_list_first, g.ewmh.minus1_desktop_unusable);
93             break;
94     }
95 }
96 
97