diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-09-16 18:03:44 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-09-16 18:03:44 +0200 |
| commit | 8d2d8848e8ac7117adffe9e1d168c5125934dfcf (patch) | |
| tree | 53d940753d45b9131c32c5b893e89e2bdcd9c5ee /st.c | |
| parent | d5f3d120eae2377b8a2f80c94fbb5e4bd7a6189d (diff) | |
| download | st-8d2d8848e8ac7117adffe9e1d168c5125934dfcf.tar.gz st-8d2d8848e8ac7117adffe9e1d168c5125934dfcf.zip | |
tweak focus to support XEMBED client message and remove focus on EnterNotify. (thx Adrian)
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 26 |
1 files changed, 23 insertions, 3 deletions
| @@ -37,6 +37,10 @@ | |||
| 37 | "st-" VERSION ", (c) 2010-2011 st engineers\n" \ | 37 | "st-" VERSION ", (c) 2010-2011 st engineers\n" \ |
| 38 | "usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n" | 38 | "usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n" |
| 39 | 39 | ||
| 40 | /* XEMBED messages */ | ||
| 41 | #define XEMBED_FOCUS_IN 4 | ||
| 42 | #define XEMBED_FOCUS_OUT 5 | ||
| 43 | |||
| 40 | /* Arbitrary sizes */ | 44 | /* Arbitrary sizes */ |
| 41 | #define ESC_TITLE_SIZ 256 | 45 | #define ESC_TITLE_SIZ 256 |
| 42 | #define ESC_BUF_SIZ 256 | 46 | #define ESC_BUF_SIZ 256 |
| @@ -217,6 +221,7 @@ static void visibility(XEvent *); | |||
| 217 | static void unmap(XEvent *); | 221 | static void unmap(XEvent *); |
| 218 | static char* kmap(KeySym, unsigned int state); | 222 | static char* kmap(KeySym, unsigned int state); |
| 219 | static void kpress(XEvent *); | 223 | static void kpress(XEvent *); |
| 224 | static void cmessage(XEvent *); | ||
| 220 | static void resize(XEvent *); | 225 | static void resize(XEvent *); |
| 221 | static void focus(XEvent *); | 226 | static void focus(XEvent *); |
| 222 | static void brelease(XEvent *); | 227 | static void brelease(XEvent *); |
| @@ -237,12 +242,11 @@ static int isfullutf8(char *, int); | |||
| 237 | 242 | ||
| 238 | static void (*handler[LASTEvent])(XEvent *) = { | 243 | static void (*handler[LASTEvent])(XEvent *) = { |
| 239 | [KeyPress] = kpress, | 244 | [KeyPress] = kpress, |
| 245 | [ClientMessage] = cmessage, | ||
| 240 | [ConfigureNotify] = resize, | 246 | [ConfigureNotify] = resize, |
| 241 | [VisibilityNotify] = visibility, | 247 | [VisibilityNotify] = visibility, |
| 242 | [UnmapNotify] = unmap, | 248 | [UnmapNotify] = unmap, |
| 243 | [Expose] = expose, | 249 | [Expose] = expose, |
| 244 | [EnterNotify] = focus, | ||
| 245 | [LeaveNotify] = focus, | ||
| 246 | [FocusIn] = focus, | 250 | [FocusIn] = focus, |
| 247 | [FocusOut] = focus, | 251 | [FocusOut] = focus, |
| 248 | [MotionNotify] = bmotion, | 252 | [MotionNotify] = bmotion, |
| @@ -264,6 +268,7 @@ static char **opt_cmd = NULL; | |||
| 264 | static char *opt_title = NULL; | 268 | static char *opt_title = NULL; |
| 265 | static char *opt_embed = NULL; | 269 | static char *opt_embed = NULL; |
| 266 | static char *opt_class = NULL; | 270 | static char *opt_class = NULL; |
| 271 | static Atom xembedatom; | ||
| 267 | 272 | ||
| 268 | int | 273 | int |
| 269 | utf8decode(char *s, long *u) { | 274 | utf8decode(char *s, long *u) { |
| @@ -1666,6 +1671,8 @@ xinit(void) { | |||
| 1666 | &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, | 1671 | &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, |
| 1667 | &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); | 1672 | &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); |
| 1668 | 1673 | ||
| 1674 | xembedatom = XInternAtom(xw.dpy, "_XEMBED", False); | ||
| 1675 | |||
| 1669 | XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); | 1676 | XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); |
| 1670 | XMapWindow(xw.dpy, xw.win); | 1677 | XMapWindow(xw.dpy, xw.win); |
| 1671 | xhints(); | 1678 | xhints(); |
| @@ -1822,7 +1829,7 @@ xseturgency(int add) { | |||
| 1822 | 1829 | ||
| 1823 | void | 1830 | void |
| 1824 | focus(XEvent *ev) { | 1831 | focus(XEvent *ev) { |
| 1825 | if(ev->type == FocusIn || ev->type == EnterNotify) { | 1832 | if(ev->type == FocusIn) { |
| 1826 | xw.state |= WIN_FOCUSED; | 1833 | xw.state |= WIN_FOCUSED; |
| 1827 | xseturgency(0); | 1834 | xseturgency(0); |
| 1828 | } else | 1835 | } else |
| @@ -1890,6 +1897,19 @@ kpress(XEvent *ev) { | |||
| 1890 | } | 1897 | } |
| 1891 | 1898 | ||
| 1892 | void | 1899 | void |
| 1900 | cmessage(XEvent *e) { | ||
| 1901 | if (e->xclient.message_type == xembedatom && e->xclient.format == 32) { | ||
| 1902 | if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) { | ||
| 1903 | xw.state |= WIN_FOCUSED; | ||
| 1904 | xseturgency(0); | ||
| 1905 | } else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) { | ||
| 1906 | xw.state &= ~WIN_FOCUSED; | ||
| 1907 | } | ||
| 1908 | draw(); | ||
| 1909 | } | ||
| 1910 | } | ||
| 1911 | |||
| 1912 | void | ||
| 1893 | resize(XEvent *e) { | 1913 | resize(XEvent *e) { |
| 1894 | int col, row; | 1914 | int col, row; |
| 1895 | 1915 | ||
