diff options
| author | Abhinav <abhinav.prsai@gmail.com> | 2025-06-02 11:27:45 +0100 |
|---|---|---|
| committer | Abhinav <abhinav.prsai@gmail.com> | 2025-06-02 11:27:45 +0100 |
| commit | fd56af29cc5ff5dfe8896508a1baec2fe9b3bd7a (patch) | |
| tree | 3001ef268664a3f627dfc101fcc53376bd3e1663 /src | |
| parent | eaeffa93af07daa50844533e8d9fcb8b8291676c (diff) | |
added cursor warping
Diffstat (limited to 'src')
| -rw-r--r-- | src/defs.h | 1 | ||||
| -rw-r--r-- | src/parser.c | 8 | ||||
| -rw-r--r-- | src/sxwm.c | 27 |
3 files changed, 36 insertions, 0 deletions
@@ -90,6 +90,7 @@ typedef struct { int snap_distance; int bindsn; Bool new_win_focus; + Bool warp_cursor; Binding binds[256]; char **should_float[256]; } Config; diff --git a/src/parser.c b/src/parser.c index f969b1d..ec53cc5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -230,6 +230,14 @@ found:; cfg->new_win_focus = False; } } + else if (!strcmp(key, "warp_cursor")) { + if (!strcmp(rest, "true")) { + cfg->warp_cursor = True; + } + else { + cfg->warp_cursor = False; + } + } else if (!strcmp(key, "master_width")) { float mf = (float)atoi(rest) / 100.0f; for (int i = 0; i < MAX_MONITORS; i++) { @@ -86,6 +86,7 @@ void update_borders(void); void update_monitors(void); void update_net_client_list(void); void update_struts(void); +void warp_cursor(Client *c); int xerr(Display *dpy, XErrorEvent *ee); void xev_case(XEvent *xev); #include "config.h" @@ -233,6 +234,9 @@ void change_workspace(int ws) if (workspaces[current_ws]) { focused = workspaces[current_ws]; XSetInputFocus(dpy, focused->win, RevertToPointerRoot, CurrentTime); + if (user_config.warp_cursor) { + warp_cursor(focused); + } } long cd = current_ws; @@ -295,6 +299,9 @@ void focus_next(void) focused = (focused->next ? focused->next : workspaces[current_ws]); XSetInputFocus(dpy, focused->win, RevertToPointerRoot, CurrentTime); XRaiseWindow(dpy, focused->win); + if (user_config.warp_cursor) { + warp_cursor(focused); + } update_borders(); } @@ -321,6 +328,9 @@ void focus_prev(void) XSetInputFocus(dpy, focused->win, RevertToPointerRoot, CurrentTime); XRaiseWindow(dpy, focused->win); + if (user_config.warp_cursor) { + warp_cursor(focused); + } update_borders(); } @@ -769,6 +779,9 @@ void hdl_map_req(XEvent *xev) focused = c; XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); send_wm_take_focus(c->win); + if (user_config.warp_cursor) { + warp_cursor(c); + } } XMapWindow(dpy, w); @@ -989,6 +1002,7 @@ void init_defaults(void) default_config.snap_distance = 5; default_config.bindsn = 0; default_config.new_win_focus = True; + default_config.warp_cursor = True; for (unsigned long i = 0; i < LENGTH(binds); i++) { default_config.binds[i].mods = binds[i].mods; @@ -1702,6 +1716,19 @@ void update_net_client_list(void) XChangeProperty(dpy, root, prop, XA_WINDOW, 32, PropModeReplace, (unsigned char *)wins, n); } +void warp_cursor(Client *c) +{ + if (!c) { + return; + } + + int center_x = c->x + (c->w / 2); + int center_y = c->y + (c->h / 2); + + XWarpPointer(dpy, None, root, 0, 0, 0, 0, center_x, center_y); + XSync(dpy, False); +} + int xerr(Display *dpy, XErrorEvent *ee) { /* ignore noise & non fatal errors */ |
