diff options
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | st.c | 42 |
2 files changed, 26 insertions, 18 deletions
| @@ -29,8 +29,6 @@ static const char *colorname[] = { | |||
| 29 | #define DefaultFG 7 | 29 | #define DefaultFG 7 |
| 30 | #define DefaultBG 0 | 30 | #define DefaultBG 0 |
| 31 | #define DefaultCS 1 | 31 | #define DefaultCS 1 |
| 32 | #define BellCol DefaultFG | ||
| 33 | #define BellTime 30000 /* microseconds */ | ||
| 34 | 32 | ||
| 35 | /* special keys */ | 33 | /* special keys */ |
| 36 | static Key key[] = { | 34 | static Key key[] = { |
| @@ -108,6 +108,7 @@ typedef struct { | |||
| 108 | int bufh; /* pixmap height */ | 108 | int bufh; /* pixmap height */ |
| 109 | int ch; /* char height */ | 109 | int ch; /* char height */ |
| 110 | int cw; /* char width */ | 110 | int cw; /* char width */ |
| 111 | int hasfocus; | ||
| 111 | } XWindow; | 112 | } XWindow; |
| 112 | 113 | ||
| 113 | typedef struct { | 114 | typedef struct { |
| @@ -161,23 +162,27 @@ static void ttyread(void); | |||
| 161 | static void ttyresize(int, int); | 162 | static void ttyresize(int, int); |
| 162 | static void ttywrite(const char *, size_t); | 163 | static void ttywrite(const char *, size_t); |
| 163 | 164 | ||
| 164 | static void xbell(void); | ||
| 165 | static void xdraws(char *, Glyph, int, int, int); | 165 | static void xdraws(char *, Glyph, int, int, int); |
| 166 | static void xhints(void); | 166 | static void xhints(void); |
| 167 | static void xclear(int, int, int, int); | 167 | static void xclear(int, int, int, int); |
| 168 | static void xdrawcursor(void); | 168 | static void xdrawcursor(void); |
| 169 | static void xinit(void); | 169 | static void xinit(void); |
| 170 | static void xloadcols(void); | 170 | static void xloadcols(void); |
| 171 | static void xseturgency(int); | ||
| 171 | 172 | ||
| 172 | static void expose(XEvent *); | 173 | static void expose(XEvent *); |
| 173 | static char* kmap(KeySym); | 174 | static char* kmap(KeySym); |
| 174 | static void kpress(XEvent *); | 175 | static void kpress(XEvent *); |
| 175 | static void resize(XEvent *); | 176 | static void resize(XEvent *); |
| 177 | static void focus(XEvent *); | ||
| 178 | |||
| 176 | 179 | ||
| 177 | static void (*handler[LASTEvent])(XEvent *) = { | 180 | static void (*handler[LASTEvent])(XEvent *) = { |
| 178 | [KeyPress] = kpress, | 181 | [KeyPress] = kpress, |
| 179 | [Expose] = expose, | 182 | [Expose] = expose, |
| 180 | [ConfigureNotify] = resize | 183 | [ConfigureNotify] = resize, |
| 184 | [FocusIn] = focus, | ||
| 185 | [FocusOut] = focus, | ||
| 181 | }; | 186 | }; |
| 182 | 187 | ||
| 183 | /* Globals */ | 188 | /* Globals */ |
| @@ -187,7 +192,6 @@ static Term term; | |||
| 187 | static CSIEscape escseq; | 192 | static CSIEscape escseq; |
| 188 | static int cmdfd; | 193 | static int cmdfd; |
| 189 | static pid_t pid; | 194 | static pid_t pid; |
| 190 | static int running; | ||
| 191 | 195 | ||
| 192 | #ifdef DEBUG | 196 | #ifdef DEBUG |
| 193 | void | 197 | void |
| @@ -227,15 +231,6 @@ execsh(void) { | |||
| 227 | execvp(args[0], args); | 231 | execvp(args[0], args); |
| 228 | } | 232 | } |
| 229 | 233 | ||
| 230 | void | ||
| 231 | xbell(void) { | ||
| 232 | XSetForeground(xw.dis, dc.gc, dc.col[BellCol]); | ||
| 233 | XFillRectangle(xw.dis, xw.win, dc.gc, BORDER, BORDER, xw.bufw, xw.bufh); | ||
| 234 | XFlush(xw.dis); | ||
| 235 | usleep(BellTime); | ||
| 236 | draw(SCREEN_REDRAW); | ||
| 237 | } | ||
| 238 | |||
| 239 | void | 234 | void |
| 240 | sigchld(int a) { | 235 | sigchld(int a) { |
| 241 | int stat = 0; | 236 | int stat = 0; |
| @@ -930,7 +925,8 @@ tputc(char c) { | |||
| 930 | tnewline(); | 925 | tnewline(); |
| 931 | break; | 926 | break; |
| 932 | case '\a': | 927 | case '\a': |
| 933 | xbell(); | 928 | if(!xw.hasfocus) |
| 929 | xseturgency(1); | ||
| 934 | break; | 930 | break; |
| 935 | case '\033': | 931 | case '\033': |
| 936 | csireset(); | 932 | csireset(); |
| @@ -1208,6 +1204,20 @@ expose(XEvent *ev) { | |||
| 1208 | draw(SCREEN_REDRAW); | 1204 | draw(SCREEN_REDRAW); |
| 1209 | } | 1205 | } |
| 1210 | 1206 | ||
| 1207 | void | ||
| 1208 | xseturgency(int add) { | ||
| 1209 | XWMHints *h = XGetWMHints(xw.dis, xw.win); | ||
| 1210 | h->flags = add ? (h->flags | XUrgencyHint) : (h->flags & ~XUrgencyHint); | ||
| 1211 | XSetWMHints(xw.dis, xw.win, h); | ||
| 1212 | XFree(h); | ||
| 1213 | } | ||
| 1214 | |||
| 1215 | void | ||
| 1216 | focus(XEvent *ev) { | ||
| 1217 | if((xw.hasfocus = ev->type == FocusIn)) | ||
| 1218 | xseturgency(0); | ||
| 1219 | } | ||
| 1220 | |||
| 1211 | char* | 1221 | char* |
| 1212 | kmap(KeySym k) { | 1222 | kmap(KeySym k) { |
| 1213 | int i; | 1223 | int i; |
| @@ -1282,12 +1292,12 @@ run(void) { | |||
| 1282 | XEvent ev; | 1292 | XEvent ev; |
| 1283 | fd_set rfd; | 1293 | fd_set rfd; |
| 1284 | int xfd = XConnectionNumber(xw.dis); | 1294 | int xfd = XConnectionNumber(xw.dis); |
| 1295 | long mask = ExposureMask | KeyPressMask | StructureNotifyMask | FocusChangeMask; | ||
| 1285 | 1296 | ||
| 1286 | running = 1; | 1297 | XSelectInput(xw.dis, xw.win, mask); |
| 1287 | XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask); | ||
| 1288 | XResizeWindow(xw.dis, xw.win, xw.w, xw.h); /* XXX: fix resize bug in wmii (?) */ | 1298 | XResizeWindow(xw.dis, xw.win, xw.w, xw.h); /* XXX: fix resize bug in wmii (?) */ |
| 1289 | 1299 | ||
| 1290 | while(running) { | 1300 | while(1) { |
| 1291 | FD_ZERO(&rfd); | 1301 | FD_ZERO(&rfd); |
| 1292 | FD_SET(cmdfd, &rfd); | 1302 | FD_SET(cmdfd, &rfd); |
| 1293 | FD_SET(xfd, &rfd); | 1303 | FD_SET(xfd, &rfd); |
