aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--st.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/st.c b/st.c
index 36ff43c..436533c 100644
--- a/st.c
+++ b/st.c
@@ -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
113typedef struct { 114typedef struct {
@@ -161,23 +162,27 @@ static void ttyread(void);
161static void ttyresize(int, int); 162static void ttyresize(int, int);
162static void ttywrite(const char *, size_t); 163static void ttywrite(const char *, size_t);
163 164
164static void xbell(void);
165static void xdraws(char *, Glyph, int, int, int); 165static void xdraws(char *, Glyph, int, int, int);
166static void xhints(void); 166static void xhints(void);
167static void xclear(int, int, int, int); 167static void xclear(int, int, int, int);
168static void xdrawcursor(void); 168static void xdrawcursor(void);
169static void xinit(void); 169static void xinit(void);
170static void xloadcols(void); 170static void xloadcols(void);
171static void xseturgency(int);
171 172
172static void expose(XEvent *); 173static void expose(XEvent *);
173static char* kmap(KeySym); 174static char* kmap(KeySym);
174static void kpress(XEvent *); 175static void kpress(XEvent *);
175static void resize(XEvent *); 176static void resize(XEvent *);
177static void focus(XEvent *);
178
176 179
177static void (*handler[LASTEvent])(XEvent *) = { 180static 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;
187static CSIEscape escseq; 192static CSIEscape escseq;
188static int cmdfd; 193static int cmdfd;
189static pid_t pid; 194static pid_t pid;
190static int running;
191 195
192#ifdef DEBUG 196#ifdef DEBUG
193void 197void
@@ -227,15 +231,6 @@ execsh(void) {
227 execvp(args[0], args); 231 execvp(args[0], args);
228} 232}
229 233
230void
231xbell(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
239void 234void
240sigchld(int a) { 235sigchld(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
1207void
1208xseturgency(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
1215void
1216focus(XEvent *ev) {
1217 if((xw.hasfocus = ev->type == FocusIn))
1218 xseturgency(0);
1219}
1220
1211char* 1221char*
1212kmap(KeySym k) { 1222kmap(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);