merge w3m-img for framebuffer support
* w3mimg/w3mimg.h: created * w3mimg/x11/x11_w3mimg.c: created * w3mimg/fb/fb_w3mimg.c: created * w3mimgsize.c w3mimgdisplay.c: modified * configure: modified * XMakefile: modified * config.h.dist: updated From: Fumitoshi UKAI <ukai@debian.or.jp> w3m-img for framebuffer support * http://homepage3.nifty.com/slokar/fb/ * w3mimg/fb/fb.c w3mimg/fb/fb.h w3mimg/fb/fb_img.c w3mimg/fb/fb_img.h w3mimg/fb/fb_gdkpixbuf.c w3mimg/fb/fb_gdkpixbuf.h w3mimg/fb/fb_imlib2.c w3mimg/fb/fb_imlib.h w3mimg/fb/readme.txt w3mimg/fb/license.txt: added From: Hiroshi Kawashima <kei@sm.sony.co.jp>
This commit is contained in:
233
w3mimgdisplay.c
233
w3mimgdisplay.c
@@ -1,175 +1,49 @@
|
||||
/* $Id: w3mimgdisplay.c,v 1.2 2002/01/31 18:28:24 ukai Exp $ */
|
||||
/* $Id: w3mimgdisplay.c,v 1.3 2002/07/17 20:58:48 ukai Exp $ */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <Imlib.h>
|
||||
#include <ctype.h>
|
||||
#include "config.h"
|
||||
#include "w3mimg/w3mimg.h"
|
||||
|
||||
static Display *display;
|
||||
static Window window, parent;
|
||||
static unsigned long background_pixel;
|
||||
w3mimg_op *w_op;
|
||||
static char *background = NULL;
|
||||
static int offset_x = 2, offset_y = 2;
|
||||
static int offset_x = 0, offset_y = 0;
|
||||
static int defined_bg = 0, defined_x = 0, defined_y = 0, defined_test = 0;
|
||||
static int defined_debug = 0;
|
||||
|
||||
#define MAX_IMAGE 1000
|
||||
typedef struct {
|
||||
Pixmap pixmap;
|
||||
int width;
|
||||
int height;
|
||||
} Image;
|
||||
static Image *imageBuf = NULL;
|
||||
static W3MImage *imageBuf = NULL;
|
||||
static int maxImage = 0;
|
||||
static GC imageGC = NULL;
|
||||
|
||||
static void GetOption(int argc, char **argv);
|
||||
static void DrawImage(char *buf, int redraw);
|
||||
static void ClearImage(void);
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/*
|
||||
xterm/kterm/hanterm/cxterm
|
||||
top window (WINDOWID)
|
||||
+- text window
|
||||
+- scrollbar
|
||||
rxvt/aterm/Eterm/wterm
|
||||
top window (WINDOWID)
|
||||
+- text window
|
||||
+- scrollbar
|
||||
+- menubar (etc.)
|
||||
gnome-terminal
|
||||
top window
|
||||
+- text window (WINDOWID)
|
||||
+- scrollbar
|
||||
+- menubar
|
||||
mlterm (-s)
|
||||
top window
|
||||
+- text window (WINDOWID)
|
||||
+- scrollbar
|
||||
mlterm
|
||||
top window = text window (WINDOWID)
|
||||
|
||||
powershell
|
||||
top window
|
||||
+- window
|
||||
| +- text window
|
||||
| +- scrollbar
|
||||
+- menubar (etc.)
|
||||
dtterm
|
||||
top window
|
||||
+- window
|
||||
+- window
|
||||
| +- window
|
||||
| +- text window
|
||||
| +- scrollbar
|
||||
+- menubar
|
||||
hpterm
|
||||
top window
|
||||
+- window
|
||||
+- text window
|
||||
+- scrollbar
|
||||
+- (etc.)
|
||||
*/
|
||||
/* *INDENT-ON* */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Window root, *children;
|
||||
XWindowAttributes attr;
|
||||
XColor screen_def, exact_def;
|
||||
int revert, nchildren, len, width, height, i;
|
||||
int len;
|
||||
char buf[1024 + 128];
|
||||
char *id;
|
||||
|
||||
GetOption(argc, argv);
|
||||
if (!defined_debug)
|
||||
fclose(stderr);
|
||||
|
||||
display = XOpenDisplay(NULL);
|
||||
if (!display)
|
||||
w_op = w3mimg_open();
|
||||
if (w_op == NULL)
|
||||
exit(1);
|
||||
if ((id = getenv("WINDOWID")) != NULL)
|
||||
window = (Window) atoi(id);
|
||||
else
|
||||
XGetInputFocus(display, &window, &revert);
|
||||
if (!window)
|
||||
exit(1);
|
||||
|
||||
XGetWindowAttributes(display, window, &attr);
|
||||
width = attr.width;
|
||||
height = attr.height;
|
||||
while (1) {
|
||||
Window p_window;
|
||||
|
||||
XQueryTree(display, window, &root, &parent, &children, &nchildren);
|
||||
if (defined_debug)
|
||||
fprintf(stderr,
|
||||
"window=%lx root=%lx parent=%lx nchildren=%d width=%d height=%d\n",
|
||||
(unsigned long)window, (unsigned long)root,
|
||||
(unsigned long)parent, nchildren, width, height);
|
||||
p_window = window;
|
||||
for (i = 0; i < nchildren; i++) {
|
||||
XGetWindowAttributes(display, children[i], &attr);
|
||||
if (defined_debug)
|
||||
fprintf(stderr,
|
||||
"children[%d]=%lx x=%d y=%d width=%d height=%d\n", i,
|
||||
children[i], attr.x, attr.y, attr.width, attr.height);
|
||||
if (attr.width > width * 0.7 && attr.height > height * 0.7) {
|
||||
/* maybe text window */
|
||||
width = attr.width;
|
||||
height = attr.height;
|
||||
window = children[i];
|
||||
}
|
||||
}
|
||||
if (p_window == window)
|
||||
break;
|
||||
}
|
||||
if (!defined_x) {
|
||||
for (i = 0; i < nchildren; i++) {
|
||||
XGetWindowAttributes(display, children[i], &attr);
|
||||
if (attr.x <= 0 && attr.width < 30 && attr.height > height * 0.7) {
|
||||
if (defined_debug)
|
||||
fprintf(stderr,
|
||||
"children[%d]=%lx x=%d y=%d width=%d height=%d\n",
|
||||
i, children[i], attr.x, attr.y, attr.width,
|
||||
attr.height);
|
||||
/* scrollbar of xterm/kterm ? */
|
||||
offset_x += attr.x + attr.width + attr.border_width * 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defined_x)
|
||||
w_op->offset_x = offset_x;
|
||||
if (defined_y)
|
||||
w_op->offset_y = offset_y;
|
||||
|
||||
if (defined_test) {
|
||||
printf("%d %d\n", width - offset_x, height - offset_y);
|
||||
printf("%d %d\n", w_op->width - w_op->offset_x,
|
||||
w_op->height - w_op->offset_y);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (defined_bg && XAllocNamedColor(display, DefaultColormap(display, 0),
|
||||
background, &screen_def, &exact_def))
|
||||
background_pixel = screen_def.pixel;
|
||||
else {
|
||||
Pixmap p;
|
||||
GC gc;
|
||||
XImage *i;
|
||||
|
||||
p = XCreatePixmap(display, window, 1, 1, DefaultDepth(display, 0));
|
||||
gc = XCreateGC(display, window, 0, NULL);
|
||||
if (!p || !gc)
|
||||
exit(1);
|
||||
XCopyArea(display, window, p, gc, (offset_x >= 1) ? (offset_x - 1) : 0,
|
||||
(offset_y >= 1) ? (offset_y - 1) : 0, 1, 1, 0, 0);
|
||||
i = XGetImage(display, p, 0, 0, 1, 1, -1, ZPixmap);
|
||||
if (!i)
|
||||
exit(1);
|
||||
background_pixel = XGetPixel(i, 0, 0);
|
||||
XDestroyImage(i);
|
||||
XFreeGC(display, gc);
|
||||
XFreePixmap(display, p);
|
||||
/*
|
||||
* background_pixel = WhitePixel(display, 0);
|
||||
*/
|
||||
}
|
||||
w_op->set_background(w_op, background);
|
||||
|
||||
while (fgets(buf, sizeof(buf), stdin) != NULL) {
|
||||
if (!(isdigit(buf[0]) && buf[1] == ';')) {
|
||||
@@ -194,18 +68,26 @@ main(int argc, char **argv)
|
||||
ClearImage();
|
||||
break;
|
||||
case '3':
|
||||
XSync(display, False);
|
||||
w_op->sync(w_op);
|
||||
break;
|
||||
case '4':
|
||||
fputs("\n", stdout);
|
||||
fflush(stdout);
|
||||
break;
|
||||
#if 0 /* def USE_W3MIMG_FB */
|
||||
case '5':
|
||||
if (w3mimg_mode == W3MIMG_FB_MODE) {
|
||||
IMAGE *im = fb_load_image(&buf[2], 0, 0);
|
||||
fprintf(stdout, "%d %d\n", im->width, im->height);
|
||||
fflush(stdout);
|
||||
fb_free_image(im);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
ClearImage();
|
||||
/*
|
||||
* XCloseDisplay(display);
|
||||
*/
|
||||
w_op->close(w_op);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -248,8 +130,6 @@ GetOption(int argc, char **argv)
|
||||
void
|
||||
DrawImage(char *buf, int redraw)
|
||||
{
|
||||
static ImlibData *id = NULL;
|
||||
ImlibImage *im;
|
||||
char *p = buf;
|
||||
int n = 0, x = 0, y = 0, w = 0, h = 0, sx = 0, sy = 0, sw = 0, sh = 0;
|
||||
|
||||
@@ -296,20 +176,12 @@ DrawImage(char *buf, int redraw)
|
||||
if (n < 0 || n >= MAX_IMAGE)
|
||||
return;
|
||||
if (redraw) {
|
||||
if (!imageGC || n >= maxImage || !imageBuf[n].pixmap)
|
||||
if (! w_op->active(w_op) || n >= maxImage || !imageBuf[n].pixmap)
|
||||
return;
|
||||
goto draw_image;
|
||||
}
|
||||
if (!id) {
|
||||
id = Imlib_init(display);
|
||||
if (!id)
|
||||
return;
|
||||
}
|
||||
if (!imageGC) {
|
||||
imageGC = XCreateGC(display, parent, 0, NULL);
|
||||
if (!imageGC)
|
||||
return;
|
||||
}
|
||||
w_op->init(w_op);
|
||||
|
||||
if (n >= maxImage) {
|
||||
int i = maxImage;
|
||||
maxImage = i ? (i * 2) : 2;
|
||||
@@ -317,51 +189,30 @@ DrawImage(char *buf, int redraw)
|
||||
maxImage = MAX_IMAGE;
|
||||
else if (n >= maxImage)
|
||||
maxImage = n + 1;
|
||||
imageBuf = (Image *) realloc((void *)imageBuf,
|
||||
sizeof(Image) * maxImage);
|
||||
imageBuf = (W3MImage *) realloc((void *)imageBuf,
|
||||
sizeof(W3MImage) * maxImage);
|
||||
for (; i < maxImage; i++)
|
||||
imageBuf[i].pixmap = (Pixmap) NULL;
|
||||
imageBuf[i].pixmap = NULL;
|
||||
}
|
||||
if (imageBuf[n].pixmap) {
|
||||
XFreePixmap(display, imageBuf[n].pixmap);
|
||||
imageBuf[n].pixmap = (Pixmap) NULL;
|
||||
w_op->free_image(w_op, &imageBuf[n]);
|
||||
imageBuf[n].pixmap = NULL;
|
||||
}
|
||||
|
||||
im = Imlib_load_image(id, p);
|
||||
if (!im)
|
||||
return;
|
||||
if (!w)
|
||||
w = im->rgb_width;
|
||||
if (!h)
|
||||
h = im->rgb_height;
|
||||
imageBuf[n].pixmap = XCreatePixmap(display, parent, w, h,
|
||||
DefaultDepth(display, 0));
|
||||
if (!imageBuf[n].pixmap)
|
||||
return;
|
||||
XSetForeground(display, imageGC, background_pixel);
|
||||
XFillRectangle(display, imageBuf[n].pixmap, imageGC, 0, 0, w, h);
|
||||
Imlib_paste_image(id, im, imageBuf[n].pixmap, 0, 0, w, h);
|
||||
Imlib_kill_image(id, im);
|
||||
imageBuf[n].width = w;
|
||||
imageBuf[n].height = h;
|
||||
w_op->load_image(w_op, &imageBuf[n], p, w, h);
|
||||
|
||||
draw_image:
|
||||
XCopyArea(display, imageBuf[n].pixmap, window, imageGC,
|
||||
sx, sy, (sw ? sw : imageBuf[n].width),
|
||||
(sh ? sh : imageBuf[n].height), x + offset_x, y + offset_y);
|
||||
w_op->show_image(w_op, &imageBuf[n], sx, sy, sw, sh, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
ClearImage(void)
|
||||
{
|
||||
if (imageGC) {
|
||||
XFreeGC(display, imageGC);
|
||||
imageGC = NULL;
|
||||
}
|
||||
w_op->finish(w_op);
|
||||
if (imageBuf) {
|
||||
int i;
|
||||
for (i = 0; i < maxImage; i++) {
|
||||
if (imageBuf[i].pixmap)
|
||||
XFreePixmap(display, imageBuf[i].pixmap);
|
||||
w_op->free_image(w_op, &imageBuf[i]);
|
||||
}
|
||||
free(imageBuf);
|
||||
imageBuf = NULL;
|
||||
|
Reference in New Issue
Block a user