From: NeilBrown Date: Fri, 11 Dec 2015 23:21:59 +0000 (+1100) Subject: Discard hx,hy in favour explicit conversion functions. X-Git-Tag: lca2016~47 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=80cce7e3c34f04c3569eb3cb1659cca13c776f33;p=edlib.git Discard hx,hy in favour explicit conversion functions. Less room for conversion, and best to do the work when it is needed. Signed-off-by: NeilBrown --- diff --git a/core-keymap.c b/core-keymap.c index 2170e997..12905640 100644 --- a/core-keymap.c +++ b/core-keymap.c @@ -301,9 +301,6 @@ int key_handle(const struct cmd_info *ci) if (ci->comm) return ci->comm->func(ci); - vci->hx = ci->x; - vci->hy = ci->y; - /* If 'home' is set, search from there, else search * from focus */ @@ -320,10 +317,6 @@ int key_handle(const struct cmd_info *ci) if (ret) /* 'p' might have been destroyed */ break; - if (ci->hx >= 0) { - vci->hx += p->x; - vci->hy += p->y; - } p = p->parent; } return ret; diff --git a/core-pane.c b/core-pane.c index 11eb41dd..64d42076 100644 --- a/core-pane.c +++ b/core-pane.c @@ -620,3 +620,29 @@ struct pane *call_pane(char *key, struct pane *focus, int numeric, return NULL; return cr.p; } + +/* convert pane-relative co-ords to absolute */ +void pane_absxy(struct pane *p, int *x, int *y) +{ + while (p) { + *x += p->x; + *y += p->y; + p = p->parent; + } +} + +/* Convert absolute c-ords to relative */ +void pane_relxy(struct pane *p, int *x, int *y) +{ + while (p) { + *x -= p->x; + *y -= p->y; + p = p->parent; + } +} + +void pane_map_xy(struct pane *orig, struct pane *target, int *x, int *y) +{ + pane_absxy(orig, x, y); + pane_relxy(target, x, y); +} diff --git a/core.h b/core.h index 54785a05..f5b5eb56 100644 --- a/core.h +++ b/core.h @@ -287,7 +287,6 @@ struct cmd_info { struct pane *home, *focus; int numeric, extra; int x,y; /* relative to focus */ - int hx, hy; /* x,y mapped to 'home' */ char *str, *str2; struct mark *mark, *mark2; struct command *comm, *comm2; @@ -351,6 +350,9 @@ void pane_clear(struct pane *p, char *attrs); void pane_text(struct pane *p, wchar_t ch, char *attrs, int x, int y); char *pane_attr_get(struct pane *p, char *key); char *pane_mark_attr(struct pane *p, struct mark *m, int forward, char *key); +void pane_absxy(struct pane *p, int *x, int *y); +void pane_relxy(struct pane *p, int *x, int *y); +void pane_map_xy(struct pane *orig, struct pane *target, int *x, int *y); struct pane *call_pane(char *key, struct pane *focus, int numeric, struct mark *m, int extra); diff --git a/lang-python.c b/lang-python.c index 17dee29a..1c431e92 100644 --- a/lang-python.c +++ b/lang-python.c @@ -156,7 +156,6 @@ REDEF_CMD(python_call) PyDict_SetItemString(kwds, "numeric", Py_BuildValue("i", ci->numeric)); PyDict_SetItemString(kwds, "extra", Py_BuildValue("i", ci->extra)); PyDict_SetItemString(kwds, "xy", Py_BuildValue("ii", ci->x, ci->y)); - PyDict_SetItemString(kwds, "hxy", Py_BuildValue("ii", ci->hx, ci->hy)); if (pc->home_func) PyDict_SetItemString(kwds, "data", ci->home->data); @@ -718,7 +717,7 @@ static int get_cmd_info(struct cmd_info *ci, PyObject *args, PyObject *kwds) PyObject *a; int i; int numeric_set = 0, extra_set = 0; - int xy_set = 0, hxy_set = 0; + int xy_set = 0; if (!PyTuple_Check(args)) return 0; @@ -789,12 +788,8 @@ static int get_cmd_info(struct cmd_info *ci, PyObject *args, PyObject *kwds) ci->x = PyInt_AsLong(n1); ci->y = PyInt_AsLong(n2); xy_set = 1; - } else if (!hxy_set) { - ci->hx = PyInt_AsLong(n1); - ci->hy = PyInt_AsLong(n2); - hxy_set = 1; } else { - PyErr_SetString(PyExc_TypeError, "Only two tuples permitted"); + PyErr_SetString(PyExc_TypeError, "Only one tuple permitted"); return 0; } } else if (Py_TYPE(a) == &CommType) { diff --git a/lib-input.c b/lib-input.c index 0f004308..e6aa88a3 100644 --- a/lib-input.c +++ b/lib-input.c @@ -71,14 +71,15 @@ DEF_CMD(mouse_event) int l; struct cmd_info ci2 = {0}; + l = strlen(im->mode) + strlen(ci->str) + 1; ci2.key = malloc(l); strcat(strcpy(ci2.key, im->mode), ci->str); ci2.focus = ci->home; ci2.numeric = im->numeric; ci2.extra = im->extra; - ci2.x = ci->hx; - ci2.y = ci->hy; + ci2.x = ci->x; ci2.y = ci->y; + pane_map_xy(ci->focus, ci2.focus, &ci2.x, &ci2.y); im->mode = ""; im->numeric = NO_NUMERIC; diff --git a/lib-view.c b/lib-view.c index 94fc381a..a10236ec 100644 --- a/lib-view.c +++ b/lib-view.c @@ -237,8 +237,12 @@ DEF_CMD(view_click) int mid = vd->scroll_bar_y; char *key; int num; + int cihx, cihy; - if (ci->hx != 0) + cihx = ci->x; cihy = ci->y; + pane_map_xy(ci->focus, ci->home, &cihx, &cihy); + + if (cihx != 0) return 0; if (p->h <= 4) return 0; @@ -248,16 +252,16 @@ DEF_CMD(view_click) key = "Move-View-Small"; num = RPT_NUM(ci); - if (ci->hy == mid-1) { + if (cihy == mid-1) { /* scroll up */ num = -num; - } else if (ci->hy < mid-1) { + } else if (cihy < mid-1) { /* big scroll up */ num = -num; key = "Move-View-Large"; - } else if (ci->hy == mid+1) { + } else if (cihy == mid+1) { /* scroll down */ - } else if (ci->hy > mid+1 && ci->hy < p->h-1) { + } else if (cihy > mid+1 && cihy < p->h-1) { key = "Move-View-Large"; } else return 0; diff --git a/render-lines.c b/render-lines.c index ff4470ed..988ec6f8 100644 --- a/render-lines.c +++ b/render-lines.c @@ -744,18 +744,20 @@ DEF_CMD(render_lines_set_cursor) struct mark *m; int y = rl->header_lines - rl->skip_lines; int found = 0; - int cihy; + int cihx, cihy; render_lines_other_move_func(ci); m = vmark_first(p, rl->typenum); - cihy = ci->hy; - if (y > ci->hy) + cihx = ci->x; cihy = ci->y; + pane_map_xy(ci->focus, ci->home, &cihx, &cihy); + + if (y > cihy) /* x,y is in header line - try lower */ cihy = y; - while (y <= ci->hy && m && m->mdata) { - int cx = ci->hx, cy = cihy, o = -1; + while (y <= cihy && m && m->mdata) { + int cx = cihx, cy = cihy, o = -1; render_line(p, m->mdata, &y, 0, &cx, &cy, &o); if (o >= 0) { struct mark *m2 = call_render_line_offset(p, m, o);