1 /*
2 * Widget for displaying extended information in a separate subindow.
3 */
4 #include "whowatch.h"
5 #include "config.h"
6 #include <dlfcn.h>
7
siglist(void * p)8 static void siglist(void *p)
9 {
10 return;
11 // println("Signal list will be here.");
12 }
13
14 static struct dsource {
15 int key;
16 void (*f)(void *);
17 int want_crsr; /* if data is related to main display cursor */
18 int (*keyh)(int);
19
20 } dss[] = {{'d', euser, 1, 0 }, {'s', esys, 0, 0}, {'p',siglist, 0, 0 } };
21
22 static struct dsource *cur_ds = &dss[0];
23 static struct dsource *mainw = &dss[0]; /* related to main window (proc/user details */
24 struct wdgt *exti; /* for compatibility with pluglib.c */
25 static void *cur_val;
26 static char *ehint = " <- -> [a]up [z]down ";
27
get_crsr(struct wdgt * w)28 static void get_crsr(struct wdgt *w)
29 {
30 if(!cur_ds->want_crsr) return;
31 cur_val = wmsg_send(w, MWANT_CRSR_VAL, 0);
32 WNEED_REDRAW(w);
33 }
34
exti_redraw(struct wdgt * w)35 static void exti_redraw(struct wdgt *w)
36 {
37 scr_werase(w);
38 scr_box(w, ehint, w->color);
39 /*
40 * get current cursor value now, not in keyh because
41 * at the time it is called we don't know which of the
42 * ulist/plist main display is visible
43 */
44 get_crsr(w);
45 if(cur_ds->f) cur_ds->f(cur_val);
46 scr_output_end(w);
47 DBG("EXTI NOW HAS %d lines", w->nlines);
48 }
49
do_exti_keyh(struct wdgt * w,int k)50 static int do_exti_keyh(struct wdgt *w, int k)
51 {
52 if(WIN_HIDDEN(w)) return KEY_SKIPPED;
53 return scr_keyh(w, k);
54 }
55
56 /*
57 * Even if not visible exti has to keep track of ulist/plist changes
58 * to know what extended info should be displyed.
59 */
exti_msgh(struct wdgt * w,int type,struct wdgt * s,void * v)60 static void *exti_msgh(struct wdgt *w, int type, struct wdgt *s, void *v)
61 {
62 if(type == MSND_ESOURCE){
63 DBG("Received data source from '%s'", s->name);
64 w->vx = w->vy = 0;
65 return mainw->f = (void (*)(void*))v;
66 }
67 return 0;
68 }
69
exti_disable(struct wdgt * w)70 static int exti_disable(struct wdgt *w)
71 {
72 DBG("DISABLING EXTI");
73 w->wrefresh = 0;
74 w->redraw = 0;
75 wmsg_send(w, MALL_CRSR_UNREG, 0);
76 return 1;
77 }
78
exti_enable(struct wdgt * w)79 static void exti_enable(struct wdgt *w)
80 {
81 DBG("ENABLING EXTI");
82 scr_werase(w);
83 w->wrefresh = scr_wrefresh;
84 w->redraw = exti_redraw;
85 WNEED_REDRAW(w);
86 }
87
exti_switch(struct wdgt * w,struct dsource * ds,int k,int p)88 static void exti_switch(struct wdgt *w, struct dsource *ds, int k, int p)
89 {
90 cur_ds = ds;
91 if(!WIN_HIDDEN(w)) {
92 if(k == p) {
93 exti_disable(w);
94 return;
95 }
96 /* data source has changed */
97 WNEED_REDRAW(w);
98 w->vy = w->vx = 0;
99 } else exti_enable(w);
100 // if(ds->want_crsr) wmsg_send(w, MALL_CRSR_REG, 0);
101 // else wmsg_send(w, MALL_CRSR_UNREG, 0);
102 }
103
exti_keyh(struct wdgt * w,int key)104 static int exti_keyh(struct wdgt *w, int key)
105 {
106 int i, ret = KEY_SKIPPED;
107 static int pkey;
108
109 for(i = 0; i < sizeof dss/sizeof(struct dsource); i++) {
110 if(dss[i].key != key) continue;
111 exti_switch(w, &dss[i], key, pkey);
112 pkey = key;
113 return KEY_HANDLED;
114 }
115 if(WIN_HIDDEN(w)) return ret;
116 if(cur_ds->keyh) cur_ds->keyh(key);
117 switch(key) {
118 case 'a': return do_exti_keyh(w, KBD_UP);
119 case 'z': return do_exti_keyh(w, KBD_DOWN);
120 case KBD_ESC: exti_disable(w); return KEY_FINAL;
121 case KBD_LEFT:
122 case KBD_RIGHT: scr_keyh(w, key); break;
123 }
124 return ret;
125 }
126
exti_reg(struct wdgt * w)127 void exti_reg(struct wdgt *w)
128 {
129 exti = w;
130 w->keyh = exti_keyh;
131 w->msgh = exti_msgh;
132 mwin_msg_on(w);
133 }
134
135