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:;<=>?"
|
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||||
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||||
"`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;
|
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
|
void
|
||||||
selclear(void)
|
selclear(void)
|
||||||
{
|
{
|
||||||
|
|||||||
99
st.h
99
st.h
@@ -4,54 +4,45 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
/* macros */
|
/* macros */
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||||
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
||||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||||
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
|
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
|
||||||
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
||||||
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
|
#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 || \
|
#define ATTRCMP(a, b) \
|
||||||
(a).bg != (b).bg)
|
((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
|
||||||
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
|
#define TIMEDIFF(t1, t2) \
|
||||||
(t1.tv_nsec-t2.tv_nsec)/1E6)
|
((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 MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
|
||||||
|
|
||||||
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
#define TRUECOLOR(r, g, b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
||||||
#define IS_TRUECOL(x) (1 << 24 & (x))
|
#define IS_TRUECOL(x) (1 << 24 & (x))
|
||||||
#define HISTSIZE 2000
|
#define HISTSIZE 2000
|
||||||
|
|
||||||
enum glyph_attribute {
|
enum glyph_attribute {
|
||||||
ATTR_NULL = 0,
|
ATTR_NULL = 0,
|
||||||
ATTR_BOLD = 1 << 0,
|
ATTR_BOLD = 1 << 0,
|
||||||
ATTR_FAINT = 1 << 1,
|
ATTR_FAINT = 1 << 1,
|
||||||
ATTR_ITALIC = 1 << 2,
|
ATTR_ITALIC = 1 << 2,
|
||||||
ATTR_UNDERLINE = 1 << 3,
|
ATTR_UNDERLINE = 1 << 3,
|
||||||
ATTR_BLINK = 1 << 4,
|
ATTR_BLINK = 1 << 4,
|
||||||
ATTR_REVERSE = 1 << 5,
|
ATTR_REVERSE = 1 << 5,
|
||||||
ATTR_INVISIBLE = 1 << 6,
|
ATTR_INVISIBLE = 1 << 6,
|
||||||
ATTR_STRUCK = 1 << 7,
|
ATTR_STRUCK = 1 << 7,
|
||||||
ATTR_WRAP = 1 << 8,
|
ATTR_WRAP = 1 << 8,
|
||||||
ATTR_WIDE = 1 << 9,
|
ATTR_WIDE = 1 << 9,
|
||||||
ATTR_WDUMMY = 1 << 10,
|
ATTR_WDUMMY = 1 << 10,
|
||||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||||
|
ATTR_URL = 1 << 14,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum selection_mode {
|
enum selection_mode { SEL_IDLE = 0, SEL_EMPTY = 1, SEL_READY = 2 };
|
||||||
SEL_IDLE = 0,
|
|
||||||
SEL_EMPTY = 1,
|
|
||||||
SEL_READY = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum selection_type {
|
enum selection_type { SEL_REGULAR = 1, SEL_RECTANGULAR = 2 };
|
||||||
SEL_REGULAR = 1,
|
|
||||||
SEL_RECTANGULAR = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum selection_snap {
|
enum selection_snap { SNAP_WORD = 1, SNAP_LINE = 2 };
|
||||||
SNAP_WORD = 1,
|
|
||||||
SNAP_LINE = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
@@ -62,20 +53,20 @@ typedef uint_least32_t Rune;
|
|||||||
|
|
||||||
#define Glyph Glyph_
|
#define Glyph Glyph_
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Rune u; /* character code */
|
Rune u; /* character code */
|
||||||
ushort mode; /* attribute flags */
|
ushort mode; /* attribute flags */
|
||||||
uint32_t fg; /* foreground */
|
uint32_t fg; /* foreground */
|
||||||
uint32_t bg; /* background */
|
uint32_t bg; /* background */
|
||||||
} Glyph;
|
} Glyph;
|
||||||
|
|
||||||
typedef Glyph *Line;
|
typedef Glyph *Line;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
int i;
|
int i;
|
||||||
uint ui;
|
uint ui;
|
||||||
float f;
|
float f;
|
||||||
const void *v;
|
const void *v;
|
||||||
const char *s;
|
const char *s;
|
||||||
} Arg;
|
} Arg;
|
||||||
|
|
||||||
void die(const char *, ...);
|
void die(const char *, ...);
|
||||||
@@ -109,6 +100,10 @@ void selextend(int, int, int, int);
|
|||||||
int selected(int, int);
|
int selected(int, int);
|
||||||
char *getsel(void);
|
char *getsel(void);
|
||||||
|
|
||||||
|
void highlighturls(void);
|
||||||
|
void unhighlighturls(void);
|
||||||
|
void followurl(int, int);
|
||||||
|
|
||||||
size_t utf8encode(Rune, char *);
|
size_t utf8encode(Rune, char *);
|
||||||
|
|
||||||
void *xmalloc(size_t);
|
void *xmalloc(size_t);
|
||||||
@@ -129,6 +124,10 @@ extern unsigned int tabspaces;
|
|||||||
extern unsigned int defaultfg;
|
extern unsigned int defaultfg;
|
||||||
extern unsigned int defaultbg;
|
extern unsigned int defaultbg;
|
||||||
extern unsigned int defaultcs;
|
extern unsigned int defaultcs;
|
||||||
|
extern char *urlhandler;
|
||||||
|
extern char urlchars[];
|
||||||
|
extern char *urlprefixes[];
|
||||||
|
extern int nurlprefixes;
|
||||||
|
|
||||||
char **externalcopycmd();
|
char **externalcopycmd();
|
||||||
char **externalpastecmd();
|
char **externalpastecmd();
|
||||||
|
|||||||
28
x.c
28
x.c
@@ -204,6 +204,7 @@ static void usage(void);
|
|||||||
|
|
||||||
static void (*handler[LASTEvent])(XEvent *) = {
|
static void (*handler[LASTEvent])(XEvent *) = {
|
||||||
[KeyPress] = kpress,
|
[KeyPress] = kpress,
|
||||||
|
[KeyRelease] = kpress,
|
||||||
[ClientMessage] = cmessage,
|
[ClientMessage] = cmessage,
|
||||||
[ConfigureNotify] = resize,
|
[ConfigureNotify] = resize,
|
||||||
[VisibilityNotify] = visibility,
|
[VisibilityNotify] = visibility,
|
||||||
@@ -465,6 +466,15 @@ mouseaction(XEvent *e, uint release)
|
|||||||
/* ignore Button<N>mask for Button<N> - it's set on release */
|
/* ignore Button<N>mask for Button<N> - it's set on release */
|
||||||
uint state = e->xbutton.state & ~buttonmask(e->xbutton.button);
|
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++) {
|
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
|
||||||
if (ms->release == release &&
|
if (ms->release == release &&
|
||||||
ms->button == e->xbutton.button &&
|
ms->button == e->xbutton.button &&
|
||||||
@@ -882,8 +892,8 @@ xhints(void)
|
|||||||
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
|
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
|
||||||
sizeh->height = win.h;
|
sizeh->height = win.h;
|
||||||
sizeh->width = win.w;
|
sizeh->width = win.w;
|
||||||
sizeh->height_inc = win.ch;
|
sizeh->height_inc = 1;
|
||||||
sizeh->width_inc = win.cw;
|
sizeh->width_inc = 1;
|
||||||
sizeh->base_height = 2 * borderpx;
|
sizeh->base_height = 2 * borderpx;
|
||||||
sizeh->base_width = 2 * borderpx;
|
sizeh->base_width = 2 * borderpx;
|
||||||
sizeh->min_height = win.ch + 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);
|
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
|
||||||
|
|
||||||
/* Render underline and strikethrough. */
|
/* 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,
|
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent * chscale + 1,
|
||||||
width, 1);
|
width, 1);
|
||||||
}
|
}
|
||||||
@@ -1872,6 +1882,18 @@ kpress(XEvent *ev)
|
|||||||
} else {
|
} else {
|
||||||
len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
|
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 */
|
/* 1. shortcuts */
|
||||||
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
|
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
|
||||||
if (ksym == bp->keysym && match(bp->mod, e->state)) {
|
if (ksym == bp->keysym && match(bp->mod, e->state)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user