working on old repo, merging recent changesets.
authorAurélien Aptel <aurelien.aptel@gmail.com>
Fri, 16 Sep 2011 16:24:13 +0000 (18:24 +0200)
committerAurélien Aptel <aurelien.aptel@gmail.com>
Fri, 16 Sep 2011 16:24:13 +0000 (18:24 +0200)
1  2 
st.c

diff --combined st.c
--- 1/st.c
--- 2/st.c
+++ b/st.c
        "st-" VERSION ", (c) 2010-2011 st engineers\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 */
  #define ESC_TITLE_SIZ 256
  #define ESC_BUF_SIZ   256
  #define ESC_ARG_SIZ   16
  #define DRAW_BUF_SIZ  1024
  #define UTF_SIZ       4
+ #define XK_NO_MOD     UINT_MAX
+ #define XK_ANY_MOD    0
  
  #define SERRNO strerror(errno)
  #define MIN(a, b)  ((a) < (b) ? (a) : (b))
@@@ -124,7 -122,6 +126,7 @@@ typedef struct 
        Colormap cmap;
        Window win;
        Pixmap buf;
 +      Atom xembed;
        XIM xim;
        XIC xic;
        int scr;
@@@ -222,7 -219,6 +224,7 @@@ static void visibility(XEvent *)
  static void unmap(XEvent *);
  static char* kmap(KeySym, unsigned int state);
  static void kpress(XEvent *);
 +static void cmessage(XEvent *);
  static void resize(XEvent *);
  static void focus(XEvent *);
  static void brelease(XEvent *);
@@@ -243,11 -239,12 +245,11 @@@ static int isfullutf8(char *, int)
  
  static void (*handler[LASTEvent])(XEvent *) = {
        [KeyPress] = kpress,
 +      [ClientMessage] = cmessage,
        [ConfigureNotify] = resize,
        [VisibilityNotify] = visibility,
        [UnmapNotify] = unmap,
        [Expose] = expose,
 -      [EnterNotify] = focus,
 -      [LeaveNotify] = focus,
        [FocusIn] = focus,
        [FocusOut] = focus,
        [MotionNotify] = bmotion,
@@@ -1632,8 -1629,8 +1634,8 @@@ xinit(void) 
        xloadcols();
  
        /* window - default size */
 -      xw.bufh = 24 * xw.ch;
 -      xw.bufw = 80 * xw.cw;
 +      xw.bufh = term.row * xw.ch;
 +      xw.bufw = term.col * xw.cw;
        xw.h = xw.bufh + 2*BORDER;
        xw.w = xw.bufw + 2*BORDER;
  
                &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff},
                &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000});
  
 +      xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
 +
        XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st");
        XMapWindow(xw.dpy, xw.win);
        xhints();
@@@ -1829,7 -1824,7 +1831,7 @@@ xseturgency(int add) 
  
  void
  focus(XEvent *ev) {
 -      if(ev->type == FocusIn || ev->type == EnterNotify) {
 +      if(ev->type == FocusIn) {
                xw.state |= WIN_FOCUSED;
                xseturgency(0);
        } else
  char*
  kmap(KeySym k, unsigned int state) {
        int i;
-       for(i = 0; i < LEN(key); i++)
-               if(key[i].k == k && (key[i].mask == 0 || key[i].mask & state))
+       state &= ~Mod2Mask;
+       for(i = 0; i < LEN(key); i++) {
+               unsigned int mask = key[i].mask;
+               if(key[i].k == k && ((state & mask) == mask || (mask == XK_NO_MOD && !state)))
                        return (char*)key[i].s;
+       }
        return NULL;
  }
  
@@@ -1896,21 -1894,6 +1901,21 @@@ kpress(XEvent *ev) 
                }
  }
  
 +void
 +cmessage(XEvent *e) {
 +      /* See xembed specs
 +         http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html */
 +      if (e->xclient.message_type == xw.xembed && 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
  resize(XEvent *e) {
        int col, row;