Hide cursor when you start typing
This commit is contained in:
parent
ccd4794bc4
commit
0a4c2d92d0
32
x.c
32
x.c
@ -96,6 +96,11 @@ typedef struct {
|
|||||||
Draw draw;
|
Draw draw;
|
||||||
Visual *vis;
|
Visual *vis;
|
||||||
XSetWindowAttributes attrs;
|
XSetWindowAttributes attrs;
|
||||||
|
/* Here, we use the term *pointer* to differentiate the cursor
|
||||||
|
* one sees when hovering the mouse over the terminal from, e.g.,
|
||||||
|
* a green rectangle where text would be entered. */
|
||||||
|
Cursor vpointer, bpointer; /* visible and hidden pointers */
|
||||||
|
int pointerisvisible;
|
||||||
int scr;
|
int scr;
|
||||||
int isfixed; /* is fixed geometry? */
|
int isfixed; /* is fixed geometry? */
|
||||||
int l, t; /* left and top offset */
|
int l, t; /* left and top offset */
|
||||||
@ -653,6 +658,13 @@ brelease(XEvent *e)
|
|||||||
void
|
void
|
||||||
bmotion(XEvent *e)
|
bmotion(XEvent *e)
|
||||||
{
|
{
|
||||||
|
if (!xw.pointerisvisible) {
|
||||||
|
XDefineCursor(xw.dpy, xw.win, xw.vpointer);
|
||||||
|
xw.pointerisvisible = 1;
|
||||||
|
if (!IS_SET(MODE_MOUSEMANY))
|
||||||
|
xsetpointermotion(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
|
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
|
||||||
mousereport(e);
|
mousereport(e);
|
||||||
return;
|
return;
|
||||||
@ -998,10 +1010,10 @@ void
|
|||||||
xinit(int cols, int rows)
|
xinit(int cols, int rows)
|
||||||
{
|
{
|
||||||
XGCValues gcvalues;
|
XGCValues gcvalues;
|
||||||
Cursor cursor;
|
|
||||||
Window parent;
|
Window parent;
|
||||||
pid_t thispid = getpid();
|
pid_t thispid = getpid();
|
||||||
XColor xmousefg, xmousebg;
|
XColor xmousefg, xmousebg;
|
||||||
|
Pixmap blankpm;
|
||||||
|
|
||||||
if (!(xw.dpy = XOpenDisplay(NULL)))
|
if (!(xw.dpy = XOpenDisplay(NULL)))
|
||||||
die("Can't open display\n");
|
die("Can't open display\n");
|
||||||
@ -1077,8 +1089,9 @@ xinit(int cols, int rows)
|
|||||||
die("XCreateIC failed. Could not obtain input method.\n");
|
die("XCreateIC failed. Could not obtain input method.\n");
|
||||||
|
|
||||||
/* white cursor, black outline */
|
/* white cursor, black outline */
|
||||||
cursor = XCreateFontCursor(xw.dpy, mouseshape);
|
xw.pointerisvisible = 1;
|
||||||
XDefineCursor(xw.dpy, xw.win, cursor);
|
xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape);
|
||||||
|
XDefineCursor(xw.dpy, xw.win, xw.vpointer);
|
||||||
|
|
||||||
if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
|
if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
|
||||||
xmousefg.red = 0xffff;
|
xmousefg.red = 0xffff;
|
||||||
@ -1092,7 +1105,10 @@ xinit(int cols, int rows)
|
|||||||
xmousebg.blue = 0x0000;
|
xmousebg.blue = 0x0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
|
XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
|
||||||
|
blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
|
||||||
|
xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
|
||||||
|
&xmousefg, &xmousebg, 0, 0);
|
||||||
|
|
||||||
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
|
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
|
||||||
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
|
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
|
||||||
@ -1575,6 +1591,8 @@ unmap(XEvent *ev)
|
|||||||
void
|
void
|
||||||
xsetpointermotion(int set)
|
xsetpointermotion(int set)
|
||||||
{
|
{
|
||||||
|
if (!set && !xw.pointerisvisible)
|
||||||
|
return;
|
||||||
MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
|
MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
|
||||||
XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
|
XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
|
||||||
}
|
}
|
||||||
@ -1693,6 +1711,12 @@ kpress(XEvent *ev)
|
|||||||
Status status;
|
Status status;
|
||||||
Shortcut *bp;
|
Shortcut *bp;
|
||||||
|
|
||||||
|
if (xw.pointerisvisible) {
|
||||||
|
XDefineCursor(xw.dpy, xw.win, xw.bpointer);
|
||||||
|
xsetpointermotion(1);
|
||||||
|
xw.pointerisvisible = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_SET(MODE_KBDLOCK))
|
if (IS_SET(MODE_KBDLOCK))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user