Add some new mouse ranges called "control0" to "control9", will be used

for controls on floating panes, from Dane Jensen, with some bits from
Michael Grant.
This commit is contained in:
nicm
2026-04-03 10:13:20 +00:00
parent 0917cd7010
commit 6b056eb53f
8 changed files with 212 additions and 67 deletions

View File

@@ -608,7 +608,8 @@ server_client_check_mouse_in_pane(struct window_pane *wp, u_int px, u_int py,
struct options *wo = w->options;
struct window_pane *fwp;
int pane_status, sb, sb_pos, sb_w, sb_pad;
u_int line, sl_top, sl_bottom;
int pane_status_line, sl_top, sl_bottom;
int bdr_bottom, bdr_top, bdr_right;
sb = options_get_number(wo, "pane-scrollbars");
sb_pos = options_get_number(wo, "pane-scrollbars-position");
@@ -621,35 +622,38 @@ server_client_check_mouse_in_pane(struct window_pane *wp, u_int px, u_int py,
sb_w = 0;
sb_pad = 0;
}
if (pane_status == PANE_STATUS_TOP)
line = wp->yoff - 1;
pane_status_line = wp->yoff - 1;
else if (pane_status == PANE_STATUS_BOTTOM)
line = wp->yoff + wp->sy;
pane_status_line = wp->yoff + wp->sy;
else
pane_status_line = -1; /* not used */
/* Check if point is within the pane or scrollbar. */
if (((pane_status != PANE_STATUS_OFF &&
py != line && py != wp->yoff + wp->sy) ||
(int)py != pane_status_line && py != wp->yoff + wp->sy) ||
(wp->yoff == 0 && py < wp->sy) ||
(py >= wp->yoff && py < wp->yoff + wp->sy)) &&
((sb_pos == PANE_SCROLLBARS_RIGHT &&
px < wp->xoff + wp->sx + sb_pad + sb_w) ||
(int)px < (int)wp->xoff + (int)wp->sx + sb_pad + sb_w) ||
(sb_pos == PANE_SCROLLBARS_LEFT &&
px < wp->xoff + wp->sx - sb_pad - sb_w))) {
(int)px < (int)wp->xoff + (int)wp->sx - sb_pad - sb_w))) {
/* Check if in the scrollbar. */
if ((sb_pos == PANE_SCROLLBARS_RIGHT &&
(px >= wp->xoff + wp->sx + sb_pad &&
px < wp->xoff + wp->sx + sb_pad + sb_w)) ||
((int)px >= (int)wp->xoff + (int)wp->sx + sb_pad &&
(int)px < (int)wp->xoff + (int)wp->sx + sb_pad + sb_w)) ||
(sb_pos == PANE_SCROLLBARS_LEFT &&
(px >= wp->xoff - sb_pad - sb_w &&
px < wp->xoff - sb_pad))) {
((int)px >= (int)wp->xoff - sb_pad - sb_w &&
(int)px < (int)wp->xoff - sb_pad))) {
/* Check where inside the scrollbar. */
sl_top = wp->yoff + wp->sb_slider_y;
sl_bottom = (wp->yoff + wp->sb_slider_y +
wp->sb_slider_h - 1);
if (py < sl_top)
if ((int)py < sl_top)
return (KEYC_MOUSE_LOCATION_SCROLLBAR_UP);
else if (py >= sl_top &&
py <= sl_bottom) {
else if ((int)py >= sl_top &&
(int)py <= sl_bottom) {
*sl_mpos = (py - wp->sb_slider_y - wp->yoff);
return (KEYC_MOUSE_LOCATION_SCROLLBAR_SLIDER);
} else /* py > sl_bottom */
@@ -658,19 +662,30 @@ server_client_check_mouse_in_pane(struct window_pane *wp, u_int px, u_int py,
/* Must be inside the pane. */
return (KEYC_MOUSE_LOCATION_PANE);
}
} else if (~w->flags & WINDOW_ZOOMED) {
/* Try the pane borders if not zoomed. */
} else {
/* Try the pane borders. */
TAILQ_FOREACH(fwp, &w->panes, entry) {
if ((((sb_pos == PANE_SCROLLBARS_RIGHT &&
fwp->xoff + fwp->sx + sb_pad + sb_w == px) ||
(sb_pos == PANE_SCROLLBARS_LEFT &&
fwp->xoff + fwp->sx == px)) &&
fwp->yoff <= 1 + py &&
fwp->yoff + fwp->sy >= py) ||
(fwp->yoff + fwp->sy == py &&
fwp->xoff <= 1 + px &&
fwp->xoff + fwp->sx >= px))
break;
if ((w->flags & WINDOW_ZOOMED) &&
(~fwp->flags & PANE_ZOOMED))
continue;
bdr_top = fwp->yoff - 1;
bdr_bottom = fwp->yoff + (int)fwp->sy;
if (sb_pos == PANE_SCROLLBARS_LEFT)
bdr_right = fwp->xoff + (int)fwp->sx;
else
/* PANE_SCROLLBARS_RIGHT or none. */
bdr_right = fwp->xoff + (int)fwp->sx +
sb_pad + sb_w;
if ((int)py >= (int)fwp->yoff - 1 &&
py <= fwp->yoff + fwp->sy) {
if ((int)px == bdr_right)
break;
}
if ((int)px >= (int)fwp->xoff - 1 &&
px <= fwp->xoff + fwp->sx) {
if ((int)py == bdr_bottom || (int)py == bdr_top)
break;
}
}
if (fwp != NULL)
return (KEYC_MOUSE_LOCATION_BORDER);
@@ -687,7 +702,7 @@ server_client_check_mouse(struct client *c, struct key_event *event)
struct window *w = s->curw->window;
struct winlink *fwl;
struct window_pane *wp, *fwp;
u_int x, y, sx, sy, px, py, sl_mpos = 0;
u_int x, y, sx, sy, px, py, n, sl_mpos = 0;
u_int b, bn;
int ignore = 0;
key_code key;
@@ -825,8 +840,14 @@ have_event:
loc = KEYC_MOUSE_LOCATION_STATUS;
break;
case STYLE_RANGE_USER:
log_debug("mouse range: user");
loc = KEYC_MOUSE_LOCATION_STATUS;
break;
case STYLE_RANGE_CONTROL:
n = sr->argument; /* parsing keeps this < 10 */
log_debug("mouse range: control %u", n);
loc = KEYC_MOUSE_LOCATION_CONTROL0 + n;
break;
}
}
}
@@ -865,9 +886,15 @@ have_event:
if (loc == KEYC_MOUSE_LOCATION_PANE) {
log_debug("mouse %u,%u on pane %%%u", x, y,
wp->id);
} else if (loc == KEYC_MOUSE_LOCATION_BORDER)
} else if (loc == KEYC_MOUSE_LOCATION_BORDER) {
sr = window_pane_border_status_get_range(wp, px,
py);
if (sr != NULL) {
n = sr->argument;
loc = KEYC_MOUSE_LOCATION_CONTROL0 + n;
}
log_debug("mouse on pane %%%u border", wp->id);
else if (loc == KEYC_MOUSE_LOCATION_SCROLLBAR_UP ||
} else if (loc == KEYC_MOUSE_LOCATION_SCROLLBAR_UP ||
loc == KEYC_MOUSE_LOCATION_SCROLLBAR_SLIDER ||
loc == KEYC_MOUSE_LOCATION_SCROLLBAR_DOWN) {
log_debug("mouse on pane %%%u scrollbar",