Compare commits
3 Commits
98a2dd55b0
...
9e0c60a428
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e0c60a428 | |||
|
|
91f0a5a008 | ||
| 6dd2af8162 |
11
config.def.h
11
config.def.h
@@ -511,3 +511,14 @@ static char ascii_printable[] =
|
||||
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
|
||||
/*
|
||||
* Open urls starting with urlprefixes, contatining urlchars
|
||||
* by passing as ARG1 to urlhandler.
|
||||
*/
|
||||
char* urlhandler = "xdg-open";
|
||||
char urlchars[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789-._~:/?#@!$&'*+,;=%";
|
||||
char* urlprefixes[] = {"http://", "https://", NULL};
|
||||
|
||||
91
st.c
91
st.c
@@ -652,6 +652,97 @@ getsel(void)
|
||||
return str;
|
||||
}
|
||||
|
||||
char *
|
||||
strstrany(char* s, char** strs) {
|
||||
char *match;
|
||||
for (int i = 0; strs[i]; i++) {
|
||||
if ((match = strstr(s, strs[i]))) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
highlighturls(void)
|
||||
{
|
||||
char *match;
|
||||
char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
|
||||
for (int i = term.top; i < term.bot; i++) {
|
||||
int url_start = -1;
|
||||
for (int j = 0; j < term.col; j++) {
|
||||
if (TLINE(i)[j].u < 127) {
|
||||
linestr[j] = TLINE(i)[j].u;
|
||||
}
|
||||
linestr[term.col] = '\0';
|
||||
}
|
||||
while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
|
||||
url_start = match - linestr;
|
||||
for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
|
||||
TLINE(i)[c].mode |= ATTR_URL;
|
||||
tsetdirt(i, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(linestr);
|
||||
}
|
||||
|
||||
void
|
||||
unhighlighturls(void)
|
||||
{
|
||||
for (int i = term.top; i < term.bot; i++) {
|
||||
for (int j = 0; j < term.col; j++) {
|
||||
Glyph* g = &TLINE(i)[j];
|
||||
if (g->mode & ATTR_URL) {
|
||||
g->mode &= ~ATTR_URL;
|
||||
tsetdirt(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
followurl(int x, int y) {
|
||||
char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
|
||||
char *match;
|
||||
for (int i = 0; i < term.col; i++) {
|
||||
if (TLINE(x)[i].u < 127) {
|
||||
linestr[i] = TLINE(x)[i].u;
|
||||
}
|
||||
linestr[term.col] = '\0';
|
||||
}
|
||||
int url_start = -1;
|
||||
while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
|
||||
url_start = match - linestr;
|
||||
int url_end = url_start;
|
||||
for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
|
||||
url_end++;
|
||||
}
|
||||
if (url_start <= y && y < url_end) {
|
||||
linestr[url_end] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (url_start == -1) {
|
||||
free(linestr);
|
||||
return;
|
||||
}
|
||||
|
||||
pid_t chpid;
|
||||
if ((chpid = fork()) == 0) {
|
||||
if (fork() == 0)
|
||||
execlp(urlhandler, urlhandler, linestr + url_start, NULL);
|
||||
exit(1);
|
||||
}
|
||||
/* // handled by sigchld()
|
||||
if (chpid > 0)
|
||||
waitpid(chpid, NULL, 0);
|
||||
*/
|
||||
free(linestr);
|
||||
unhighlighturls();
|
||||
}
|
||||
|
||||
void
|
||||
selclear(void)
|
||||
{
|
||||
|
||||
99
st.h
99
st.h
@@ -4,54 +4,45 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
/* macros */
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
|
||||
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
||||
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
|
||||
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
|
||||
(a).bg != (b).bg)
|
||||
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
|
||||
(t1.tv_nsec-t2.tv_nsec)/1E6)
|
||||
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
|
||||
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
||||
#define LIMIT(x, a, b) (x) = (x)<(a) ? (a) : (x)>(b) ? (b) : (x)
|
||||
#define ATTRCMP(a, b) \
|
||||
((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
|
||||
#define TIMEDIFF(t1, t2) \
|
||||
((t1.tv_sec - t2.tv_sec) * 1000 + (t1.tv_nsec - t2.tv_nsec) / 1E6)
|
||||
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
|
||||
|
||||
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
||||
#define IS_TRUECOL(x) (1 << 24 & (x))
|
||||
#define HISTSIZE 2000
|
||||
#define TRUECOLOR(r, g, b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
||||
#define IS_TRUECOL(x) (1 << 24 & (x))
|
||||
#define HISTSIZE 2000
|
||||
|
||||
enum glyph_attribute {
|
||||
ATTR_NULL = 0,
|
||||
ATTR_BOLD = 1 << 0,
|
||||
ATTR_FAINT = 1 << 1,
|
||||
ATTR_ITALIC = 1 << 2,
|
||||
ATTR_UNDERLINE = 1 << 3,
|
||||
ATTR_BLINK = 1 << 4,
|
||||
ATTR_REVERSE = 1 << 5,
|
||||
ATTR_INVISIBLE = 1 << 6,
|
||||
ATTR_STRUCK = 1 << 7,
|
||||
ATTR_WRAP = 1 << 8,
|
||||
ATTR_WIDE = 1 << 9,
|
||||
ATTR_WDUMMY = 1 << 10,
|
||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||
ATTR_NULL = 0,
|
||||
ATTR_BOLD = 1 << 0,
|
||||
ATTR_FAINT = 1 << 1,
|
||||
ATTR_ITALIC = 1 << 2,
|
||||
ATTR_UNDERLINE = 1 << 3,
|
||||
ATTR_BLINK = 1 << 4,
|
||||
ATTR_REVERSE = 1 << 5,
|
||||
ATTR_INVISIBLE = 1 << 6,
|
||||
ATTR_STRUCK = 1 << 7,
|
||||
ATTR_WRAP = 1 << 8,
|
||||
ATTR_WIDE = 1 << 9,
|
||||
ATTR_WDUMMY = 1 << 10,
|
||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||
ATTR_URL = 1 << 14,
|
||||
};
|
||||
|
||||
enum selection_mode {
|
||||
SEL_IDLE = 0,
|
||||
SEL_EMPTY = 1,
|
||||
SEL_READY = 2
|
||||
};
|
||||
enum selection_mode { SEL_IDLE = 0, SEL_EMPTY = 1, SEL_READY = 2 };
|
||||
|
||||
enum selection_type {
|
||||
SEL_REGULAR = 1,
|
||||
SEL_RECTANGULAR = 2
|
||||
};
|
||||
enum selection_type { SEL_REGULAR = 1, SEL_RECTANGULAR = 2 };
|
||||
|
||||
enum selection_snap {
|
||||
SNAP_WORD = 1,
|
||||
SNAP_LINE = 2
|
||||
};
|
||||
enum selection_snap { SNAP_WORD = 1, SNAP_LINE = 2 };
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned int uint;
|
||||
@@ -62,20 +53,20 @@ typedef uint_least32_t Rune;
|
||||
|
||||
#define Glyph Glyph_
|
||||
typedef struct {
|
||||
Rune u; /* character code */
|
||||
ushort mode; /* attribute flags */
|
||||
uint32_t fg; /* foreground */
|
||||
uint32_t bg; /* background */
|
||||
Rune u; /* character code */
|
||||
ushort mode; /* attribute flags */
|
||||
uint32_t fg; /* foreground */
|
||||
uint32_t bg; /* background */
|
||||
} Glyph;
|
||||
|
||||
typedef Glyph *Line;
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
uint ui;
|
||||
float f;
|
||||
const void *v;
|
||||
const char *s;
|
||||
int i;
|
||||
uint ui;
|
||||
float f;
|
||||
const void *v;
|
||||
const char *s;
|
||||
} Arg;
|
||||
|
||||
void die(const char *, ...);
|
||||
@@ -109,6 +100,10 @@ void selextend(int, int, int, int);
|
||||
int selected(int, int);
|
||||
char *getsel(void);
|
||||
|
||||
void highlighturls(void);
|
||||
void unhighlighturls(void);
|
||||
void followurl(int, int);
|
||||
|
||||
size_t utf8encode(Rune, char *);
|
||||
|
||||
void *xmalloc(size_t);
|
||||
@@ -129,6 +124,10 @@ extern unsigned int tabspaces;
|
||||
extern unsigned int defaultfg;
|
||||
extern unsigned int defaultbg;
|
||||
extern unsigned int defaultcs;
|
||||
extern char *urlhandler;
|
||||
extern char urlchars[];
|
||||
extern char *urlprefixes[];
|
||||
extern int nurlprefixes;
|
||||
|
||||
char **externalcopycmd();
|
||||
char **externalpastecmd();
|
||||
|
||||
28
x.c
28
x.c
@@ -204,6 +204,7 @@ static void usage(void);
|
||||
|
||||
static void (*handler[LASTEvent])(XEvent *) = {
|
||||
[KeyPress] = kpress,
|
||||
[KeyRelease] = kpress,
|
||||
[ClientMessage] = cmessage,
|
||||
[ConfigureNotify] = resize,
|
||||
[VisibilityNotify] = visibility,
|
||||
@@ -465,6 +466,15 @@ mouseaction(XEvent *e, uint release)
|
||||
/* ignore Button<N>mask for Button<N> - 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 &&
|
||||
@@ -882,8 +892,8 @@ xhints(void)
|
||||
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
|
||||
sizeh->height = win.h;
|
||||
sizeh->width = win.w;
|
||||
sizeh->height_inc = win.ch;
|
||||
sizeh->width_inc = win.cw;
|
||||
sizeh->height_inc = 1;
|
||||
sizeh->width_inc = 1;
|
||||
sizeh->base_height = 2 * borderpx;
|
||||
sizeh->base_width = 2 * borderpx;
|
||||
sizeh->min_height = win.ch + 2 * borderpx;
|
||||
@@ -1508,7 +1518,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);
|
||||
}
|
||||
@@ -1872,6 +1882,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)) {
|
||||
|
||||
Reference in New Issue
Block a user