st

Mahdi's build of st
git clone git://mahdi.pw/st.git
Log | Files | Refs | README | LICENSE

st-hidecursor-0.8.3.diff (2536B)


      1 diff --git a/x.c b/x.c
      2 index e5f1737..7e759b0 100644
      3 --- a/x.c
      4 +++ b/x.c
      5 @@ -103,6 +103,11 @@ typedef struct {
      6  	Draw draw;
      7  	Visual *vis;
      8  	XSetWindowAttributes attrs;
      9 +	/* Here, we use the term *pointer* to differentiate the cursor
     10 +	 * one sees when hovering the mouse over the terminal from, e.g.,
     11 +	 * a green rectangle where text would be entered. */
     12 +	Cursor vpointer, bpointer; /* visible and hidden pointers */
     13 +	int pointerisvisible;
     14  	int scr;
     15  	int isfixed; /* is fixed geometry? */
     16  	int l, t; /* left and top offset */
     17 @@ -698,6 +703,13 @@ brelease(XEvent *e)
     18  void
     19  bmotion(XEvent *e)
     20  {
     21 +	if (!xw.pointerisvisible) {
     22 +		XDefineCursor(xw.dpy, xw.win, xw.vpointer);
     23 +		xw.pointerisvisible = 1;
     24 +		if (!IS_SET(MODE_MOUSEMANY))
     25 +			xsetpointermotion(0);
     26 +	}
     27 +
     28  	if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
     29  		mousereport(e);
     30  		return;
     31 @@ -1099,10 +1111,10 @@ void
     32  xinit(int cols, int rows)
     33  {
     34  	XGCValues gcvalues;
     35 -	Cursor cursor;
     36  	Window parent;
     37  	pid_t thispid = getpid();
     38  	XColor xmousefg, xmousebg;
     39 +	Pixmap blankpm;
     40  
     41  	if (!(xw.dpy = XOpenDisplay(NULL)))
     42  		die("can't open display\n");
     43 @@ -1166,8 +1178,9 @@ xinit(int cols, int rows)
     44  	}
     45  
     46  	/* white cursor, black outline */
     47 -	cursor = XCreateFontCursor(xw.dpy, mouseshape);
     48 -	XDefineCursor(xw.dpy, xw.win, cursor);
     49 +	xw.pointerisvisible = 1;
     50 +	xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape);
     51 +	XDefineCursor(xw.dpy, xw.win, xw.vpointer);
     52  
     53  	if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
     54  		xmousefg.red   = 0xffff;
     55 @@ -1181,7 +1194,10 @@ xinit(int cols, int rows)
     56  		xmousebg.blue  = 0x0000;
     57  	}
     58  
     59 -	XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
     60 +	XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
     61 +	blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
     62 +	xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
     63 +					  &xmousefg, &xmousebg, 0, 0);
     64  
     65  	xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
     66  	xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
     67 @@ -1673,6 +1689,8 @@ unmap(XEvent *ev)
     68  void
     69  xsetpointermotion(int set)
     70  {
     71 +	if (!set && !xw.pointerisvisible)
     72 +		return;
     73  	MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
     74  	XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
     75  }
     76 @@ -1793,6 +1811,12 @@ kpress(XEvent *ev)
     77  	Status status;
     78  	Shortcut *bp;
     79  
     80 +	if (xw.pointerisvisible) {
     81 +		XDefineCursor(xw.dpy, xw.win, xw.bpointer);
     82 +		xsetpointermotion(1);
     83 +		xw.pointerisvisible = 0;
     84 +	}
     85 +
     86  	if (IS_SET(MODE_KBDLOCK))
     87  		return;
     88