Skip to content

Instantly share code, notes, and snippets.

@YangKeao
Last active March 18, 2019 15:42
Show Gist options
  • Save YangKeao/fa607ca5e2417c3b28af4c2aaa98d81e to your computer and use it in GitHub Desktop.
Save YangKeao/fa607ca5e2417c3b28af4c2aaa98d81e to your computer and use it in GitHub Desktop.
DWM shake and find cursor
From 4beb792e846212d6eac1b7f7bfe49d91128bbe43 Mon Sep 17 00:00:00 2001
From: Yang Keao <keao.yang@yahoo.com>
Date: Mon, 18 Mar 2019 23:12:01 +0800
Subject: [PATCH 1/2] Map window when shake cursor
---
dwm.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/dwm.c b/dwm.c
index 0362114..bc7cab6 100644
--- a/dwm.c
+++ b/dwm.c
@@ -234,6 +234,9 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static int previous_motion_x = 0;
+static int previous_motion_y = 0;
+
/* variables */
static const char broken[] = "broken";
static char stext[256];
@@ -266,6 +269,8 @@ static Display *dpy;
static Drw *drw;
static Monitor *mons, *selmon;
static Window root;
+static XSetWindowAttributes cur_attr;
+static Window cur_w;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -1070,7 +1075,7 @@ manage(Window w, XWindowAttributes *wa)
updatewindowtype(c);
updatesizehints(c);
updatewmhints(c);
- XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
+ XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask|PointerMotionMask);
grabbuttons(c, 0);
if (!c->isfloating)
c->isfloating = c->oldstate = trans != None || c->isfixed;
@@ -1135,7 +1140,20 @@ motionnotify(XEvent *e)
static Monitor *mon = NULL;
Monitor *m;
XMotionEvent *ev = &e->xmotion;
+
+ if (ev->x_root - previous_motion_x + ev->y_root - previous_motion_y > 30) {
+ printf("Motion %d %d w: %d\n", ev->x_root, ev->y_root, cur_w);
+ XSetWindowAttributes wa;
+
+ XMoveWindow(dpy, cur_w, ev->x_root - cur_w_size / 2, ev->y_root - cur_w_size / 2);
+ XMapWindow(dpy, cur_w);
+ } else {
+ XSetWindowAttributes wa;
+ XUnmapWindow(dpy, cur_w);
+ }
+ previous_motion_x = ev->x_root;
+ previous_motion_y = ev->y_root;
if (ev->window != root)
return;
if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
@@ -1601,6 +1619,12 @@ setup(void)
XSelectInput(dpy, root, wa.event_mask);
grabkeys();
focus(NULL);
+
+ cur_attr.background_pixel = XWhitePixel(dpy, screen);
+ cur_w = XCreateWindow(dpy, root,
+ 0, 0, cur_w_size, cur_w_size, 5, DefaultDepth(dpy, screen), InputOutput,
+ DefaultVisual(dpy, screen) ,CWBackPixel, &cur_attr);
+ XSelectInput(dpy, cur_w, ExposureMask | KeyPressMask);
}
void
--
2.19.2
From 4b31029cb4fc840b11c6fd4d6e87d31da73dd8f1 Mon Sep 17 00:00:00 2001
From: Yang Keao <keao.yang@yahoo.com>
Date: Mon, 18 Mar 2019 23:12:49 +0800
Subject: [PATCH 2/2] remove log
---
dwm.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/dwm.c b/dwm.c
index bc7cab6..7b50338 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1142,7 +1142,6 @@ motionnotify(XEvent *e)
XMotionEvent *ev = &e->xmotion;
if (ev->x_root - previous_motion_x + ev->y_root - previous_motion_y > 30) {
- printf("Motion %d %d w: %d\n", ev->x_root, ev->y_root, cur_w);
XSetWindowAttributes wa;
XMoveWindow(dpy, cur_w, ev->x_root - cur_w_size / 2, ev->y_root - cur_w_size / 2);
--
2.19.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment