tweak focus to support XEMBED client message and remove focus on EnterNotify. (thx Adrian)

This commit is contained in:
Aurélien Aptel 2011-09-16 18:03:44 +02:00
parent d5f3d120ea
commit 8d2d8848e8

26
st.c
View file

@ -37,6 +37,10 @@
"st-" VERSION ", (c) 2010-2011 st engineers\n" \ "st-" VERSION ", (c) 2010-2011 st engineers\n" \
"usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n" "usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n"
/* XEMBED messages */
#define XEMBED_FOCUS_IN 4
#define XEMBED_FOCUS_OUT 5
/* Arbitrary sizes */ /* Arbitrary sizes */
#define ESC_TITLE_SIZ 256 #define ESC_TITLE_SIZ 256
#define ESC_BUF_SIZ 256 #define ESC_BUF_SIZ 256
@ -217,6 +221,7 @@ static void visibility(XEvent *);
static void unmap(XEvent *); static void unmap(XEvent *);
static char* kmap(KeySym, unsigned int state); static char* kmap(KeySym, unsigned int state);
static void kpress(XEvent *); static void kpress(XEvent *);
static void cmessage(XEvent *);
static void resize(XEvent *); static void resize(XEvent *);
static void focus(XEvent *); static void focus(XEvent *);
static void brelease(XEvent *); static void brelease(XEvent *);
@ -237,12 +242,11 @@ static int isfullutf8(char *, int);
static void (*handler[LASTEvent])(XEvent *) = { static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress, [KeyPress] = kpress,
[ClientMessage] = cmessage,
[ConfigureNotify] = resize, [ConfigureNotify] = resize,
[VisibilityNotify] = visibility, [VisibilityNotify] = visibility,
[UnmapNotify] = unmap, [UnmapNotify] = unmap,
[Expose] = expose, [Expose] = expose,
[EnterNotify] = focus,
[LeaveNotify] = focus,
[FocusIn] = focus, [FocusIn] = focus,
[FocusOut] = focus, [FocusOut] = focus,
[MotionNotify] = bmotion, [MotionNotify] = bmotion,
@ -264,6 +268,7 @@ static char **opt_cmd = NULL;
static char *opt_title = NULL; static char *opt_title = NULL;
static char *opt_embed = NULL; static char *opt_embed = NULL;
static char *opt_class = NULL; static char *opt_class = NULL;
static Atom xembedatom;
int int
utf8decode(char *s, long *u) { utf8decode(char *s, long *u) {
@ -1666,6 +1671,8 @@ xinit(void) {
&(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff},
&(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000});
xembedatom = XInternAtom(xw.dpy, "_XEMBED", False);
XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st");
XMapWindow(xw.dpy, xw.win); XMapWindow(xw.dpy, xw.win);
xhints(); xhints();
@ -1822,7 +1829,7 @@ xseturgency(int add) {
void void
focus(XEvent *ev) { focus(XEvent *ev) {
if(ev->type == FocusIn || ev->type == EnterNotify) { if(ev->type == FocusIn) {
xw.state |= WIN_FOCUSED; xw.state |= WIN_FOCUSED;
xseturgency(0); xseturgency(0);
} else } else
@ -1889,6 +1896,19 @@ kpress(XEvent *ev) {
} }
} }
void
cmessage(XEvent *e) {
if (e->xclient.message_type == xembedatom && e->xclient.format == 32) {
if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
xw.state |= WIN_FOCUSED;
xseturgency(0);
} else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
xw.state &= ~WIN_FOCUSED;
}
draw();
}
}
void void
resize(XEvent *e) { resize(XEvent *e) {
int col, row; int col, row;