Support remote image by OSC 5379 show_picture sequence.
This commit is contained in:
committed by
Tatsuya Kinoshita
parent
6ef08c68f1
commit
f4268d8d18
@@ -487,7 +487,7 @@ displayBuffer(Buffer *buf, int mode)
|
||||
term_title(conv_to_system(buf->buffername));
|
||||
refresh();
|
||||
#ifdef USE_IMAGE
|
||||
if (activeImage && displayImage && buf->img) {
|
||||
if (activeImage && displayImage && buf->img && buf->image_loaded) {
|
||||
drawImage();
|
||||
}
|
||||
#endif
|
||||
@@ -521,7 +521,10 @@ drawAnchorCursor0(Buffer *buf, AnchorList *al, int hseq, int prevhseq,
|
||||
break;
|
||||
}
|
||||
if (hseq >= 0 && an->hseq == hseq) {
|
||||
int hasImage = 0;
|
||||
for (i = an->start.pos; i < an->end.pos; i++) {
|
||||
if (l->propBuf[i] & PE_IMAGE)
|
||||
hasImage = 1 ;
|
||||
if (l->propBuf[i] & (PE_IMAGE | PE_ANCHOR | PE_FORM)) {
|
||||
if (active)
|
||||
l->propBuf[i] |= PE_ACTIVE;
|
||||
@@ -529,7 +532,8 @@ drawAnchorCursor0(Buffer *buf, AnchorList *al, int hseq, int prevhseq,
|
||||
l->propBuf[i] &= ~PE_ACTIVE;
|
||||
}
|
||||
}
|
||||
if (active)
|
||||
if (active &&
|
||||
(! support_remote_image || ! hasImage))
|
||||
redrawLineRegion(buf, l, l->linenumber - tline + buf->rootY,
|
||||
an->start.pos, an->end.pos);
|
||||
}
|
||||
@@ -855,14 +859,16 @@ redrawLineImage(Buffer *buf, Line *l, int i)
|
||||
y = (int)(i * pixel_per_line);
|
||||
sx = (int)((rcol - COLPOS(l, a->start.pos)) * pixel_per_char);
|
||||
sy = (int)((l->linenumber - image->y) * pixel_per_line);
|
||||
if (sx == 0 && x + image->xoffset >= 0)
|
||||
x += image->xoffset;
|
||||
else
|
||||
sx -= image->xoffset;
|
||||
if (sy == 0 && y + image->yoffset >= 0)
|
||||
y += image->yoffset;
|
||||
else
|
||||
sy -= image->yoffset;
|
||||
if (! support_remote_image) {
|
||||
if (sx == 0 && x + image->xoffset >= 0)
|
||||
x += image->xoffset;
|
||||
else
|
||||
sx -= image->xoffset;
|
||||
if (sy == 0 && y + image->yoffset >= 0)
|
||||
y += image->yoffset;
|
||||
else
|
||||
sy -= image->yoffset;
|
||||
}
|
||||
if (image->width > 0)
|
||||
w = image->width - sx;
|
||||
else
|
||||
|
||||
@@ -373,6 +373,8 @@ typedef struct _imageCache {
|
||||
int index;
|
||||
short width;
|
||||
short height;
|
||||
short a_width;
|
||||
short a_height;
|
||||
} ImageCache;
|
||||
|
||||
typedef struct _image {
|
||||
@@ -919,6 +921,7 @@ global char *CurrentKeyData;
|
||||
global char *CurrentCmdData;
|
||||
global char *w3m_reqlog;
|
||||
extern char *w3m_version;
|
||||
extern int support_remote_image;
|
||||
|
||||
#define DUMP_BUFFER 0x01
|
||||
#define DUMP_HEAD 0x02
|
||||
|
||||
@@ -52,6 +52,18 @@ getCharSize()
|
||||
int w = 0, h = 0;
|
||||
|
||||
set_environ("W3M_TTY", ttyname_tty());
|
||||
|
||||
if (support_remote_image) {
|
||||
int ppc, ppl;
|
||||
|
||||
if (get_pixel_per_cell(&ppc,&ppl)) {
|
||||
pixel_per_char = (double)ppc;
|
||||
pixel_per_line = (double)ppl;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
tmp = Strnew();
|
||||
if (!strchr(Imgdisplay, '/'))
|
||||
Strcat_m_charp(tmp, w3m_auxbin_dir(), "/", NULL);
|
||||
@@ -156,6 +168,10 @@ addImage(ImageCache * cache, int x, int y, int sx, int sy, int w, int h)
|
||||
static void
|
||||
syncImage(void)
|
||||
{
|
||||
if (support_remote_image) {
|
||||
return;
|
||||
}
|
||||
|
||||
fputs("3;\n", Imgdisplay_wf); /* XSync() */
|
||||
fputs("4;\n", Imgdisplay_wf); /* put '\n' */
|
||||
while (fflush(Imgdisplay_wf) != 0) {
|
||||
@@ -177,6 +193,7 @@ drawImage()
|
||||
static char buf[64];
|
||||
int j, draw = FALSE;
|
||||
TerminalImage *i;
|
||||
struct stat st ;
|
||||
|
||||
if (!activeImage)
|
||||
return;
|
||||
@@ -184,6 +201,50 @@ drawImage()
|
||||
return;
|
||||
for (j = 0; j < n_terminal_image; j++) {
|
||||
i = &terminal_image[j];
|
||||
|
||||
if (support_remote_image) {
|
||||
#if 0
|
||||
fprintf(stderr,"file %s x %d y %d w %d h %d sx %d sy %d sw %d sh %d (ppc %d ppl %d)\n",
|
||||
getenv("WINDOWID") ? i->cache->file : i->cache->url,
|
||||
i->x, i->y,
|
||||
i->cache->width > 0 ? i->cache->width : 0,
|
||||
i->cache->height > 0 ? i->cache->height : 0,
|
||||
i->sx, i->sy, i->width, i->height,
|
||||
(int)pixel_per_char, (int)pixel_per_line);
|
||||
#endif
|
||||
put_image(
|
||||
#if 1
|
||||
/* XXX I don't know why but sometimes i->cache->file doesn't exist. */
|
||||
getenv("WINDOWID") && (stat(i->cache->file,&st) == 0) ?
|
||||
/* local */ i->cache->file : /* remote */ i->cache->url,
|
||||
#else
|
||||
i->cache->url,
|
||||
#endif
|
||||
(int)(i->x / pixel_per_char),
|
||||
(int)(i->y / pixel_per_line),
|
||||
#if 1
|
||||
i->cache->a_width > 0 ?
|
||||
(int)((i->cache->width + i->x % (int)pixel_per_char +
|
||||
pixel_per_char - 1) / pixel_per_char) :
|
||||
#endif
|
||||
0,
|
||||
|
||||
#if 1
|
||||
i->cache->a_height > 0 ?
|
||||
(int)((i->cache->height + i->y % (int)pixel_per_line +
|
||||
pixel_per_line - 1) / pixel_per_line) :
|
||||
#endif
|
||||
0,
|
||||
(int)(i->sx / pixel_per_char),
|
||||
(int)(i->sy / pixel_per_line),
|
||||
(int)((i->width + i->sx % (int)pixel_per_char +
|
||||
pixel_per_char - 1) / pixel_per_char),
|
||||
(int)((i->height + i->sy % (int)pixel_per_line +
|
||||
pixel_per_line - 1) / pixel_per_line));
|
||||
|
||||
continue ;
|
||||
}
|
||||
|
||||
if (!(i->cache->loaded & IMG_FLAG_LOADED &&
|
||||
i->width > 0 && i->height > 0))
|
||||
continue;
|
||||
@@ -207,9 +268,15 @@ drawImage()
|
||||
fputs("\n", Imgdisplay_wf);
|
||||
draw = TRUE;
|
||||
}
|
||||
if (!draw)
|
||||
return;
|
||||
syncImage();
|
||||
|
||||
if (!support_remote_image) {
|
||||
if (!draw)
|
||||
return;
|
||||
syncImage();
|
||||
}
|
||||
else
|
||||
n_terminal_image = 0;
|
||||
|
||||
touch_cursor();
|
||||
refresh();
|
||||
}
|
||||
@@ -221,6 +288,10 @@ clearImage()
|
||||
int j;
|
||||
TerminalImage *i;
|
||||
|
||||
if (support_remote_image) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!activeImage)
|
||||
return;
|
||||
if (!n_terminal_image)
|
||||
@@ -321,6 +392,8 @@ showImageProgress(Buffer *buf)
|
||||
}
|
||||
}
|
||||
if (n) {
|
||||
if (support_remote_image && n == l)
|
||||
drawImage();
|
||||
message(Sprintf("%d/%d images loaded", l, n)->ptr,
|
||||
buf->cursorX + buf->rootX, buf->cursorY + buf->rootY);
|
||||
refresh();
|
||||
@@ -407,7 +480,8 @@ loadImage(Buffer *buf, int flag)
|
||||
}
|
||||
|
||||
if (draw && image_buffer) {
|
||||
drawImage();
|
||||
if (!support_remote_image)
|
||||
drawImage();
|
||||
showImageProgress(image_buffer);
|
||||
}
|
||||
|
||||
@@ -521,6 +595,8 @@ getImage(Image * image, ParsedURL *current, int flag)
|
||||
cache->loaded = IMG_FLAG_UNLOADED;
|
||||
cache->width = image->width;
|
||||
cache->height = image->height;
|
||||
cache->a_width = image->width;
|
||||
cache->a_height = image->height;
|
||||
putHash_sv(image_hash, key->ptr, (void *)cache);
|
||||
}
|
||||
if (flag != IMG_FLAG_SKIP) {
|
||||
@@ -581,11 +657,11 @@ getImageSize(ImageCache * cache)
|
||||
}
|
||||
else if (cache->width < 0) {
|
||||
int tmp = (int)((double)cache->height * w / h + 0.5);
|
||||
cache->width = (tmp > MAX_IMAGE_SIZE) ? MAX_IMAGE_SIZE : tmp;
|
||||
cache->a_width = cache->width = (tmp > MAX_IMAGE_SIZE) ? MAX_IMAGE_SIZE : tmp;
|
||||
}
|
||||
else if (cache->height < 0) {
|
||||
int tmp = (int)((double)cache->width * h / w + 0.5);
|
||||
cache->height = (tmp > MAX_IMAGE_SIZE) ? MAX_IMAGE_SIZE : tmp;
|
||||
cache->a_height = cache->height = (tmp > MAX_IMAGE_SIZE) ? MAX_IMAGE_SIZE : tmp;
|
||||
}
|
||||
if (cache->width == 0)
|
||||
cache->width = 1;
|
||||
|
||||
@@ -122,6 +122,42 @@ static int searchKeyNum(void);
|
||||
#define help() fusage(stdout, 0)
|
||||
#define usage() fusage(stderr, 1)
|
||||
|
||||
int support_remote_image;
|
||||
|
||||
static void
|
||||
check_support_remote_image(void)
|
||||
{
|
||||
char *env;
|
||||
|
||||
if ((env = getenv("MLTERM"))) {
|
||||
char *p;
|
||||
int major;
|
||||
int minor;
|
||||
int micro;
|
||||
|
||||
if (!(p = strchr(env,'.')))
|
||||
return;
|
||||
*p = '\0';
|
||||
major = atoi(env);
|
||||
env = p + 1;
|
||||
|
||||
if (!(p = strchr(env,'.')))
|
||||
return;
|
||||
*p = '\0';
|
||||
minor = atoi(env);
|
||||
env = p + 1;
|
||||
micro = atoi(env) ;
|
||||
|
||||
if (major > 3 ||
|
||||
(major == 3 && (minor > 1 || (minor == 1 && micro >= 7)))) {
|
||||
support_remote_image = 1 ;
|
||||
set_environ( "W3M_USE_REMOTE_IMAGE","1"); /* for w3mimgdisplay */
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
fversion(FILE * f)
|
||||
{
|
||||
@@ -409,7 +445,7 @@ main(int argc, char **argv, char **envp)
|
||||
#if defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE)
|
||||
char **getimage_args = NULL;
|
||||
#endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */
|
||||
|
||||
check_support_remote_image();
|
||||
GC_INIT();
|
||||
#if defined(ENABLE_NLS) || (defined(USE_M17N) && defined(HAVE_LANGINFO_CODESET))
|
||||
setlocale(LC_ALL, "");
|
||||
@@ -679,6 +715,10 @@ main(int argc, char **argv, char **envp)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (!strcmp("-ri" , argv[i])) {
|
||||
support_remote_image = 1;
|
||||
set_environ( "W3M_USE_REMOTE_IMAGE","1"); /* for w3mimgdisplay */
|
||||
}
|
||||
else if (!strcmp("-num", argv[i]))
|
||||
showLineNum = TRUE;
|
||||
else if (!strcmp("-no-proxy", argv[i]))
|
||||
|
||||
@@ -466,6 +466,56 @@ writestr(char *s)
|
||||
|
||||
#define MOVE(line,column) writestr(tgoto(T_cm,column,line));
|
||||
|
||||
void
|
||||
put_image(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh)
|
||||
{
|
||||
Str buf;
|
||||
char *size ;
|
||||
|
||||
if (w > 0 && h > 0)
|
||||
size = Sprintf("%dx%d",w,h)->ptr;
|
||||
else
|
||||
size = "";
|
||||
|
||||
MOVE(y,x);
|
||||
buf = Sprintf("\x1b]5379;show_picture %s %s %dx%d+%d+%d\x07",url,size,sw,sh,sx,sy);
|
||||
writestr(buf->ptr);
|
||||
MOVE(Currentbuf->cursorY,Currentbuf->cursorX);
|
||||
}
|
||||
|
||||
int
|
||||
get_pixel_per_cell(int *ppc, int *ppl)
|
||||
{
|
||||
fd_set rfd;
|
||||
struct timeval tval;
|
||||
char buf[100];
|
||||
ssize_t len;
|
||||
int wp,hp,wc,hc;
|
||||
|
||||
fputs("\x1b[14t\x1b[18t",ttyf); flush_tty();
|
||||
|
||||
tval.tv_usec = 10000; /* 0.1 sec */
|
||||
tval.tv_sec = 0;
|
||||
FD_SET(tty,&rfd);
|
||||
if (select(tty+1,&rfd,NULL,NULL,&tval) < 0 || ! FD_ISSET(tty,&rfd)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((len = read(tty,buf,sizeof(buf)-1)) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
|
||||
if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) != 4) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*ppc = wp / wc;
|
||||
*ppl = hp / hc;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef USE_MOUSE
|
||||
#define W3M_TERM_INFO(name, title, mouse) name, title, mouse
|
||||
#define NEED_XTERM_ON (1)
|
||||
|
||||
+14
-3
@@ -121,16 +121,21 @@ x11_init(w3mimg_op * self)
|
||||
if (self == NULL)
|
||||
return 0;
|
||||
xi = (struct x11_info *)self->priv;
|
||||
#if defined(USE_IMLIB)
|
||||
if (xi == NULL)
|
||||
return 0;
|
||||
#if defined(USE_IMLIB)
|
||||
if (!xi->id) {
|
||||
xi->id = Imlib_init(xi->display);
|
||||
if (!xi->id)
|
||||
return 0;
|
||||
}
|
||||
#elif defined(USE_GDKPIXBUF)
|
||||
if (!xi->init_flag) {
|
||||
if (!xi) {
|
||||
#if defined(USE_GTK2)
|
||||
g_type_init();
|
||||
#endif
|
||||
}
|
||||
else if (!xi->init_flag) {
|
||||
#if defined(USE_GTK2)
|
||||
g_type_init();
|
||||
#endif
|
||||
@@ -138,7 +143,7 @@ x11_init(w3mimg_op * self)
|
||||
xi->init_flag = TRUE;
|
||||
}
|
||||
#endif
|
||||
if (!xi->imageGC) {
|
||||
if (xi && !xi->imageGC) {
|
||||
xi->imageGC = XCreateGC(xi->display, xi->parent, 0, NULL);
|
||||
if (!xi->imageGC)
|
||||
return 0;
|
||||
@@ -653,9 +658,11 @@ x11_get_image_size(w3mimg_op * self, W3MImage * img, char *fname, int *w,
|
||||
|
||||
if (self == NULL)
|
||||
return 0;
|
||||
#if defined(USE_IMLIB) && defined(USE_IMLIB2)
|
||||
xi = (struct x11_info *)self->priv;
|
||||
if (xi == NULL)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
#if defined(USE_IMLIB)
|
||||
im = Imlib_load_image(xi->id, fname);
|
||||
@@ -755,6 +762,9 @@ w3mimg_x11open()
|
||||
return NULL;
|
||||
memset(wop, 0, sizeof(w3mimg_op));
|
||||
|
||||
if (getenv("W3M_USE_REMOTE_IMAGE"))
|
||||
goto end;
|
||||
|
||||
xi = (struct x11_info *)malloc(sizeof(struct x11_info));
|
||||
if (xi == NULL)
|
||||
goto error;
|
||||
@@ -807,6 +817,7 @@ w3mimg_x11open()
|
||||
|
||||
wop->priv = xi;
|
||||
|
||||
end:
|
||||
wop->init = x11_init;
|
||||
wop->finish = x11_finish;
|
||||
wop->active = x11_active;
|
||||
|
||||
Reference in New Issue
Block a user