"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
Colormap cmap;
Window win;
Pixmap buf;
+ Atom xembed;
XIM xim;
XIC xic;
int scr;
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 *);
static inline int selected(int, int);
static void selcopy(void);
static void selpaste();
+static void selscroll(int, int);
static int utf8decode(char *, long *);
static int utf8encode(long *, char *);
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,
term.line[i] = term.line[i-n];
term.line[i-n] = temp;
}
+
+ selscroll(orig, n);
}
void
term.line[i] = term.line[i+n];
term.line[i+n] = temp;
}
+
+ selscroll(orig, -n);
+}
+
+void
+selscroll(int orig, int n) {
+ if(sel.bx == -1)
+ return;
+
+ if(BETWEEN(sel.by, orig, term.bot) || BETWEEN(sel.ey, orig, term.bot)) {
+ if((sel.by += n) > term.bot || (sel.ey += n) < term.top) {
+ sel.bx = -1;
+ return;
+ }
+ if(sel.by < term.top) {
+ sel.by = term.top;
+ sel.bx = 0;
+ }
+ if(sel.ey > term.bot) {
+ sel.ey = term.bot;
+ sel.ex = term.col;
+ }
+ sel.b.y = sel.by, sel.b.x = sel.bx;
+ sel.e.y = sel.ey, sel.e.x = sel.ex;
+ }
}
void
break;
/* XXX: (CSI n I) CHT -- Cursor Forward Tabulation <n> tab stops */
case 'J': /* ED -- Clear screen */
+ sel.bx = -1;
switch(escseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
}
}
} else {
+ if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey)) sel.bx = -1;
switch(ascii) {
case '\t':
tputtab();
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();
void
focus(XEvent *ev) {
- if(ev->type == FocusIn || ev->type == EnterNotify) {
+ if(ev->type == FocusIn) {
xw.state |= WIN_FOCUSED;
xseturgency(0);
} else
}
}
+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;