From 5187e696fdafee436aced2a54524445a58ff6ada Mon Sep 17 00:00:00 2001 From: Nikita Langer Date: Wed, 27 May 2026 21:52:45 +0200 Subject: links --- x.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'x.c') diff --git a/x.c b/x.c index 3541d20..181f8c9 100644 --- a/x.c +++ b/x.c @@ -211,6 +211,7 @@ static void usage(void); static void (*handler[LASTEvent])(XEvent *) = { [KeyPress] = kpress, + [KeyRelease] = kpress, [ClientMessage] = cmessage, [ConfigureNotify] = resize, [VisibilityNotify] = visibility, @@ -476,6 +477,15 @@ mouseaction(XEvent *e, uint release) /* ignore Buttonmask for Button - it's set on release */ uint state = e->xbutton.state & ~buttonmask(e->xbutton.button); + if (release == 0 && + e->xbutton.button == Button1 && + (match(ControlMask, state) || + match(ControlMask, state & ~forcemousemod))) { + followurl(evrow(e), evcol(e)); + return 1; + } + + for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { if (ms->release == release && ms->button == e->xbutton.button && @@ -1771,7 +1781,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i XftDrawGlyphFontSpec(xw.draw, fg, specs, len); /* Render underline and strikethrough. */ - if (base.mode & ATTR_UNDERLINE) { + if (base.mode & ATTR_UNDERLINE || base.mode & ATTR_URL) { XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent * chscale + 1, width, 1); } @@ -2179,6 +2189,18 @@ kpress(XEvent *ev) } else { len = XLookupString(e, buf, sizeof buf, &ksym, NULL); } + + /* 0. highlight URLs when control held */ + if (ksym == XK_Control_L) { + highlighturls(); + } else if (ev->type == KeyRelease && e->keycode == XKeysymToKeycode(e->display, XK_Control_L)) { + unhighlighturls(); + } + + /* KeyRelease not relevant to shortcuts */ + if (ev->type == KeyRelease) + return; + /* 1. shortcuts */ for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) { if (ksym == bp->keysym && match(bp->mod, e->state)) { -- cgit