diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 2d296dac..9cc11527 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -142,6 +142,8 @@ int32_t focusdir(const Arg *arg) { focusclient(c, 1); if (config.warpcursor) warp_cursor(c); + if (selmon && is_canvas_layout(selmon)) + canvas_pan_to_client(selmon, c); } else { if (config.focus_cross_tag) { if (arg->i == LEFT || arg->i == UP) diff --git a/src/layout/canvas.h b/src/layout/canvas.h index 07a49201..714d1cea 100644 --- a/src/layout/canvas.h +++ b/src/layout/canvas.h @@ -119,3 +119,31 @@ static void canvas(Monitor *m) { apply_visual_zoom(c, effective_zoom); } } + +static void canvas_pan_to_client(Monitor *m, Client *c) { + if (!m || !c || !is_canvas_layout(m)) + return; + + uint32_t tag = m->pertag->curtag; + if (c->canvas_geom[tag].width <= 0 || c->canvas_geom[tag].height <= 0) + return; + + float zoom = m->pertag->canvas_zoom[tag]; + float pan_x = m->pertag->canvas_pan_x[tag]; + float pan_y = m->pertag->canvas_pan_y[tag]; + float vp_w = m->w.width / zoom; + float vp_h = m->w.height / zoom; + + float cx = c->canvas_geom[tag].x; + float cy = c->canvas_geom[tag].y; + float cw = c->canvas_geom[tag].width; + float ch = c->canvas_geom[tag].height; + + if (cx >= pan_x && cy >= pan_y && + cx + cw <= pan_x + vp_w && cy + ch <= pan_y + vp_h) + return; + + m->pertag->canvas_pan_x[tag] = cx + cw / 2.0f - vp_w / 2.0f; + m->pertag->canvas_pan_y[tag] = cy + ch / 2.0f - vp_h / 2.0f; + canvas_reposition(m); +} diff --git a/src/mango.c b/src/mango.c index 425150c4..a2325ede 100644 --- a/src/mango.c +++ b/src/mango.c @@ -1036,6 +1036,7 @@ static struct wl_event_source *sync_keymap; #include "animation/layer.h" #include "animation/tag.h" static void canvas_reposition(Monitor *m); +static void canvas_pan_to_client(Monitor *m, Client *c); #include "dispatch/bind_define.h" #include "ext-protocol/all.h" #include "fetch/fetch.h"