X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=46490798e9b867821c2b7dfb954c7325e16308f1;hb=d5f3d120eae2377b8a2f80c94fbb5e4bd7a6189d;hp=6ba5c4c6b0308b50378515d2a7aa65386848a7ee;hpb=4736edd469d07685f6ceeb4bfe438ba48335bd81;p=st.git diff --git a/st.c b/st.c index 6ba5c4c..4649079 100644 --- a/st.c +++ b/st.c @@ -35,7 +35,7 @@ #define USAGE \ "st-" VERSION ", (c) 2010-2011 st engineers\n" \ - "usage: st [-t title] [-c class] [-v] [-e command...]\n" + "usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -241,6 +241,8 @@ static void (*handler[LASTEvent])(XEvent *) = { [VisibilityNotify] = visibility, [UnmapNotify] = unmap, [Expose] = expose, + [EnterNotify] = focus, + [LeaveNotify] = focus, [FocusIn] = focus, [FocusOut] = focus, [MotionNotify] = bmotion, @@ -260,6 +262,7 @@ static pid_t pid; static Selection sel; static char **opt_cmd = NULL; static char *opt_title = NULL; +static char *opt_embed = NULL; static char *opt_class = NULL; int @@ -614,7 +617,7 @@ bmotion(XEvent *e) { if(oldey != sel.ey || oldex != sel.ex) { int starty = MIN(oldey, sel.ey); int endy = MAX(oldey, sel.ey); - drawregion(0, (starty > 0 ? starty : 0), term.col, (sel.ey < term.row ? endy+1 : term.row)); + drawregion(0, (starty > 0 ? starty : 0), term.col, (endy < term.row ? endy+1 : term.row)); } } } @@ -1606,6 +1609,7 @@ void xinit(void) { XSetWindowAttributes attrs; Cursor cursor; + Window parent; if(!(xw.dpy = XOpenDisplay(NULL))) die("Can't open display\n"); @@ -1623,8 +1627,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; @@ -1633,10 +1637,12 @@ xinit(void) { attrs.bit_gravity = NorthWestGravity; attrs.event_mask = FocusChangeMask | KeyPressMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask - | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask; + | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask + | EnterWindowMask | LeaveWindowMask; attrs.colormap = xw.cmap; - xw.win = XCreateWindow(xw.dpy, XRootWindow(xw.dpy, xw.scr), 0, 0, + parent = opt_embed ? strtol(opt_embed, NULL, 0) : XRootWindow(xw.dpy, xw.scr); + xw.win = XCreateWindow(xw.dpy, parent, 0, 0, xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput, XDefaultVisual(xw.dpy, xw.scr), CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask @@ -1816,7 +1822,7 @@ xseturgency(int add) { void focus(XEvent *ev) { - if(ev->type == FocusIn) { + if(ev->type == FocusIn || ev->type == EnterNotify) { xw.state |= WIN_FOCUSED; xseturgency(0); } else @@ -1943,6 +1949,9 @@ main(int argc, char *argv[]) { case 'c': if(++i < argc) opt_class = argv[i]; break; + case 'w': + if(++i < argc) opt_embed = argv[i]; + break; case 'e': /* eat every remaining arguments */ if(++i < argc) opt_cmd = &argv[i];