diff options
| -rw-r--r-- | config.h | 13 | ||||
| -rw-r--r-- | dwm.c | 9 | ||||
| -rw-r--r-- | togglemouse.c | 48 |
3 files changed, 64 insertions, 6 deletions
@@ -8,16 +8,14 @@ static const unsigned int borderpx = 3; /* border pixel of windows */ static const unsigned int snap = 12; /* snap pixel */ static const int swallowfloating = 1; /* 1 means swallow floating windows by default */ +static const int mouse_default = 0; /* 1 means enable mouse by default */ static const char col_gray1[] = "#000000"; -static const char col_gray2[] = "#000000"; -static const char col_gray3[] = "#bbbbbb"; -static const char col_gray4[] = "#eeeeee"; +static const char col_gray2[] = "#bbbbbb"; static const char col_float[] = "#770000"; -static const char col_cyan[] = "#bbbbbb"; static const char *colors[][4] = { /* fg bg border float */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2, col_gray2 }, - [SchemeSel] = { col_gray1, col_cyan, col_cyan, col_float }, + [SchemeNorm] = { col_gray2, col_gray1, col_gray1, col_gray1 }, + [SchemeSel] = { col_gray1, col_gray2, col_gray2, col_float }, }; /* tagging */ @@ -74,6 +72,7 @@ static const Layout layouts[] = { static const char *termcmd[] = { TERMINAL, NULL }; #include "quicksearch.c" +#include "togglemouse.c" #include <X11/XF86keysym.h> static const Key keys[] = { /* modifier key function argument */ @@ -132,6 +131,8 @@ static const Key keys[] = { { MODKEY, XK_p, quicksearch, {.i = 0} }, { MODKEY|ShiftMask, XK_p, quicksearch, {.i = 1} }, + + { MODKEY, XK_BackSpace, togglemouse, {0} }, }; /* button definitions */ @@ -234,6 +234,7 @@ static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); +static void togglemouse(const Arg *arg); static pid_t getparentprocess(pid_t p); static int isdescprocess(pid_t p, pid_t c); @@ -1553,6 +1554,12 @@ setup(void) scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); for (i = 0; i < LENGTH(colors); i++) scheme[i] = drw_scm_create(drw, colors[i], 4); + + /* init mouse */ + if (mouse_default == 0) { + togglemouse(0); + } + /* supporting window for NetWMCheck */ wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, @@ -2210,6 +2217,8 @@ zoom(const Arg *arg) if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) return; pop(c); + + XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); } int diff --git a/togglemouse.c b/togglemouse.c new file mode 100644 index 0000000..4642b35 --- /dev/null +++ b/togglemouse.c @@ -0,0 +1,48 @@ +static Window fw = 0; +static int locked = 0; + +void +togglemouse(const Arg *arg) + if (locked) { + XUngrabPointer(dpy, CurrentTime); + XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); + if (fw) { + XDestroyWindow(dpy, fw); + fw = 0; + } + locked = 0; + return; + } + + Window root = RootWindow(dpy, screen); + + XSetWindowAttributes attrs; + attrs.override_redirect = True; + attrs.event_mask = 0; + + fw = XCreateWindow( + dpy, root, 0, sh - 1, 1, 1, 0, + DefaultDepth(dpy, screen), + InputOutput, DefaultVisual(dpy, screen), + CWOverrideRedirect | CWEventMask, &attrs + ); + + XMapRaised(dpy, fw); + XSync(dpy, False); + + XWarpPointer(dpy, None, root, 0, 0, 0, 0, 0, sh - 1); + + if (XGrabPointer(dpy, fw, True, + 0, + GrabModeAsync, + GrabModeAsync, + fw, + None, + CurrentTime) != GrabSuccess) { + XDestroyWindow(dpy, fw); + fw = 0; + return; + } + + locked = 1; +} |
