X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=28c083adf2b0cc22398b3ebac66c418172db93ac;hb=369734c80c6e5049d704a00f436c59ecf4dafae8;hp=2eb007b6fbd5804e9f756a11eb164cf9f3337c05;hpb=b5144100a59956b5bf69614a077bd4d252d7dc6c;p=st.git diff --git a/st.c b/st.c index 2eb007b..28c083a 100644 --- a/st.c +++ b/st.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -108,7 +109,6 @@ enum term_mode { MODE_CRLF = 16, MODE_MOUSEBTN = 32, MODE_MOUSEMOTION = 64, - MODE_MOUSE = 32|64, MODE_REVERSE = 128, MODE_KBDLOCK = 256, MODE_HIDE = 512, @@ -118,6 +118,11 @@ enum term_mode { MODE_8BIT = 8192, MODE_BLINK = 16384, MODE_FBLINK = 32768, + MODE_FOCUS = 65536, + MODE_MOUSEX10 = 131072, + MODE_MOUSEMANY = 262144, + MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\ + |MODE_MOUSEMANY, }; enum escape_state { @@ -218,6 +223,7 @@ typedef struct { XIC xic; Draw draw; Visual *vis; + XSetWindowAttributes attrs; int scr; bool isfixed; /* is fixed geometry? */ int fx, fy, fw, fh; /* fixed geometry */ @@ -244,7 +250,6 @@ typedef struct { signed char crlf; /* crlf mode */ } Key; -/* TODO: use better name for vars... */ typedef struct { int mode; int type; @@ -372,6 +377,7 @@ static void xloadfonts(char *, int); static int xloadfontset(Font *); static void xsettitle(char *); static void xresettitle(void); +static void xsetpointermotion(int); static void xseturgency(int); static void xsetsel(char*); static void xtermclear(int, int, int, int); @@ -445,6 +451,7 @@ static char *opt_title = NULL; static char *opt_embed = NULL; static char *opt_class = NULL; static char *opt_font = NULL; +static int oldbutton = 3; /* button event on startup: 3 = release */ static char *usedfont = NULL; static int usedfontsize = 0; @@ -780,7 +787,7 @@ getbuttoninfo(XEvent *e) { sel.oe.x = x2col(e->xbutton.x); sel.oe.y = y2row(e->xbutton.y); - if (sel.ob.y < sel.oe.y + if(sel.ob.y < sel.oe.y || (sel.ob.y == sel.oe.y && sel.ob.x < sel.oe.x)) { selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1); selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1); @@ -788,7 +795,6 @@ getbuttoninfo(XEvent *e) { selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1); selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1); } - selsort(); sel.type = SEL_REGULAR; @@ -806,13 +812,19 @@ mousereport(XEvent *e) { button = e->xbutton.button, state = e->xbutton.state, len; char buf[40]; - static int ob, ox, oy; + static int ox, oy; /* from urxvt */ if(e->xbutton.type == MotionNotify) { - if(!IS_SET(MODE_MOUSEMOTION) || (x == ox && y == oy)) + if(x == ox && y == oy) + return; + if(!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY)) + return; + /* MOUSE_MOTION: no reporting if no button is pressed */ + if(IS_SET(MODE_MOUSEMOTION) && oldbutton == 3) return; - button = ob + 32; + + button = oldbutton + 32; ox = x; oy = y; } else if(!IS_SET(MODE_MOUSESGR) @@ -824,15 +836,17 @@ mousereport(XEvent *e) { if(button >= 3) button += 64 - 3; if(e->xbutton.type == ButtonPress) { - ob = button; + oldbutton = button; ox = x; oy = y; } } - button += (state & ShiftMask ? 4 : 0) - + (state & Mod4Mask ? 8 : 0) - + (state & ControlMask ? 16 : 0); + if(!IS_SET(MODE_MOUSEX10)) { + button += (state & ShiftMask ? 4 : 0) + + (state & Mod4Mask ? 8 : 0) + + (state & ControlMask ? 16 : 0); + } len = 0; if(IS_SET(MODE_MOUSESGR)) { @@ -841,7 +855,8 @@ mousereport(XEvent *e) { e->xbutton.type == ButtonRelease ? 'm' : 'M'); } else if(x < 223 && y < 223) { len = snprintf(buf, sizeof(buf), "\033[M%c%c%c", - 32+button, 32+x+1, 32+y+1); + IS_SET(MODE_MOUSEX10)? button-1 : 32+button, + 32+x+1, 32+y+1); } else { return; } @@ -1099,7 +1114,7 @@ brelease(XEvent *e) { selcopy(); } sel.mode = 0; - term.dirty[sel.oe.y] = 1; + tsetdirt(sel.nb.y, sel.ne.y); } } @@ -1775,15 +1790,30 @@ tsetmode(bool priv, bool set, int *args, int narg) { case 25: /* DECTCEM -- Text Cursor Enable Mode */ MODBIT(term.mode, !set, MODE_HIDE); break; - case 1000: /* 1000,1002: enable xterm mouse report */ + case 9: /* X10 mouse compatibility mode */ + xsetpointermotion(0); + MODBIT(term.mode, 0, MODE_MOUSE); + MODBIT(term.mode, set, MODE_MOUSEX10); + break; + case 1000: /* 1000: report button press */ + xsetpointermotion(0); + MODBIT(term.mode, 0, MODE_MOUSE); MODBIT(term.mode, set, MODE_MOUSEBTN); - MODBIT(term.mode, 0, MODE_MOUSEMOTION); break; - case 1002: + case 1002: /* 1002: report motion on button press */ + xsetpointermotion(0); + MODBIT(term.mode, 0, MODE_MOUSE); MODBIT(term.mode, set, MODE_MOUSEMOTION); - MODBIT(term.mode, 0, MODE_MOUSEBTN); break; - case 1006: + case 1003: /* 1003: enable all mouse motions */ + xsetpointermotion(set); + MODBIT(term.mode, 0, MODE_MOUSE); + MODBIT(term.mode, set, MODE_MOUSEMANY); + break; + case 1004: /* 1004: send focus events to tty */ + MODBIT(term.mode, set, MODE_FOCUS); + break; + case 1006: /* 1006: extended reporting mode */ MODBIT(term.mode, set, MODE_MOUSESGR); break; case 1034: @@ -1808,6 +1838,15 @@ tsetmode(bool priv, bool set, int *args, int narg) { case 1048: tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD); break; + /* Not implemented mouse modes. See comments there. */ + case 1001: /* mouse highlight mode; can hang the + terminal by design when implemented. */ + case 1005: /* UTF-8 mouse mode; will confuse + applications not supporting UTF-8 + and luit. */ + case 1015: /* urxvt mangled mouse mode; incompatible + and can be mistaken for other control + codes. */ default: fprintf(stderr, "erresc: unknown private set/reset mode %d\n", @@ -1839,8 +1878,6 @@ tsetmode(bool priv, bool set, int *args, int narg) { } } } -#undef MODBIT - void csihandle(void) { @@ -2783,7 +2820,6 @@ xzoom(const Arg *arg) { void xinit(void) { - XSetWindowAttributes attrs; XGCValues gcvalues; Cursor cursor; Window parent; @@ -2825,22 +2861,20 @@ xinit(void) { } /* Events */ - attrs.background_pixel = dc.col[defaultbg].pixel; - attrs.border_pixel = dc.col[defaultbg].pixel; - attrs.bit_gravity = NorthWestGravity; - attrs.event_mask = FocusChangeMask | KeyPressMask + xw.attrs.background_pixel = dc.col[defaultbg].pixel; + xw.attrs.border_pixel = dc.col[defaultbg].pixel; + xw.attrs.bit_gravity = NorthWestGravity; + xw.attrs.event_mask = FocusChangeMask | KeyPressMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask; - attrs.colormap = xw.cmap; + xw.attrs.colormap = xw.cmap; parent = opt_embed ? strtol(opt_embed, NULL, 0) : \ XRootWindow(xw.dpy, xw.scr); xw.win = XCreateWindow(xw.dpy, parent, xw.fx, xw.fy, xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput, - xw.vis, - CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask - | CWColormap, - &attrs); + xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity + | CWEventMask | CWColormap, &xw.attrs); memset(&gcvalues, 0, sizeof(gcvalues)); gcvalues.graphics_exposures = False; @@ -2855,7 +2889,7 @@ xinit(void) { xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); /* input methods */ - if((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { + if((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { XSetLocaleModifiers("@im=local"); if((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { XSetLocaleModifiers("@im="); @@ -3291,6 +3325,12 @@ unmap(XEvent *ev) { } void +xsetpointermotion(int set) { + MODBIT(xw.attrs.event_mask, set, PointerMotionMask); + XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); +} + +void xseturgency(int add) { XWMHints *h = XGetWMHints(xw.dpy, xw.win); @@ -3310,9 +3350,13 @@ focus(XEvent *ev) { XSetICFocus(xw.xic); xw.state |= WIN_FOCUSED; xseturgency(0); + if(IS_SET(MODE_FOCUS)) + ttywrite("\033[I", 3); } else { XUnsetICFocus(xw.xic); xw.state &= ~WIN_FOCUSED; + if(IS_SET(MODE_FOCUS)) + ttywrite("\033[O", 3); } } @@ -3579,6 +3623,7 @@ int main(int argc, char *argv[]) { int bitm, xr, yr; uint wr, hr; + char *titles; xw.fw = xw.fh = xw.fx = xw.fy = 0; xw.isfixed = False; @@ -3592,8 +3637,13 @@ main(int argc, char *argv[]) { break; case 'e': /* eat all remaining arguments */ - if(argc > 1) + if(argc > 1) { opt_cmd = &argv[1]; + if(argv[1] != NULL) { + titles = strdup(argv[1]); + opt_title = basename(titles); + } + } goto run; case 'f': opt_font = EARGF(usage());