📄 scr_x11.c
字号:
name = ":0";
if ((x11_dpy = XOpenDisplay(name)) == NULL)
return -1;
XSetErrorHandler(x11_error);
x11_scr = XDefaultScreen(x11_dpy);
x11_vis = select_visual(x11_dpy, x11_scr);
x11_gc = XDefaultGC(x11_dpy, x11_scr);
for (i = 0; i < COLOR_CACHE_SIZE; i++)
ccache[i].init = 1;
set_mode(gr_mode);
setup_needed = 0;
return 0;
}
return 0;
}
/* Note: only single screen */
static PSD
X11_open(PSD psd)
{
XSetWindowAttributes attr;
Pixmap cur_empty;
unsigned long valuemask;
unsigned int event_mask;
XColor color;
Cursor cursor;
/*XEvent ev;*/
PSUBDRIVER subdriver;
int size, linelen;
if (x11_setup_display() < 0)
return NULL;
x11_event_mask = ColormapChangeMask | FocusChangeMask;
/*x11_event_mask |= EnterWindowMask | LeaveWindowMask;*/
event_mask = x11_event_mask |
ExposureMask |
KeyPressMask | /* handled by kbd_x11 */
KeyReleaseMask | /* handled by kbd_x11 */
ButtonPressMask | /* handled by mou_x11 */
ButtonReleaseMask | /* handled by mou_x11 */
PointerMotionMask; /* handled by mou_x11 */
#ifdef USE_EXPOSURE
valuemask = CWSaveUnder |
CWEventMask;
#else
valuemask = CWSaveUnder |
CWEventMask |
CWBackingStore;
#endif
attr.backing_store = Always; /* auto expose */
attr.save_under = True; /* popups ... */
attr.event_mask = event_mask;
x11_win = XCreateWindow(x11_dpy,
XDefaultRootWindow(x11_dpy),
100, /* x */
100, /* y */
SCREEN_WIDTH, /* width */
SCREEN_HEIGHT, /* height */
2, /* border */
CopyFromParent, /* depth */
CopyFromParent, /* depth */
x11_vis, /* Visual */
valuemask, /* valuemask */
&attr /* attributes */
);
/* Create a new empty colormap, the colormap will be
** filled by lookup_color in the case of
** GrayScale, PseduoColor and DirectColor,
** or looked up in the case of
** StaticGray, StaticColor and TrueColor
*/
x11_colormap = XDefaultColormap(x11_dpy, x11_scr);
if (x11_vis->class & 1)
x11_colormap = XCopyColormapAndFree(x11_dpy, x11_colormap);
/* If you need more colors, create it from scratch
*
* x11_colormap = XCreateColormap(x11_dpy, x11_win, x11_vis,
* AllocNone);
*
* or: for same visual etc.
* x11_colormap = XCopyColormapAndFree(x11_dpy, x11_colormap);
*/
/* Create an empty (invisible) cursor */
cur_empty = XCreateBitmapFromData(x11_dpy, x11_win, "\0", 1, 1);
cursor = XCreatePixmapCursor(x11_dpy, cur_empty, cur_empty,
&color, &color, 0, 0);
XDefineCursor(x11_dpy, x11_win, cursor);
XStoreName(x11_dpy, x11_win, "Microwindows");
XMapWindow(x11_dpy, x11_win);
XFlush(x11_dpy);
/*
* The following code insures that the colormap
* is installed before display
*/
#if 0
XMaskEvent(x11_dpy, x11_event_mask, &ev);
XPutBackEvent(x11_dpy, &ev);
#endif
XInstallColormap(x11_dpy, x11_colormap);
psd->xres = psd->xvirtres = SCREEN_WIDTH;
psd->yres = psd->yvirtres = SCREEN_HEIGHT;
psd->linelen = SCREEN_WIDTH;
psd->planes = 1;
psd->pixtype = x11_pixtype = MWPIXEL_FORMAT;
switch(psd->pixtype) {
case MWPF_PALETTE:
psd->bpp = SCREEN_DEPTH;
break;
case MWPF_TRUECOLOR0888:
default:
psd->bpp = 32;
break;
case MWPF_TRUECOLOR888:
psd->bpp = 24;
break;
case MWPF_TRUECOLOR565:
case MWPF_TRUECOLOR555:
psd->bpp = 16;
break;
case MWPF_TRUECOLOR332:
psd->bpp = 8;
break;
}
/* Calculate the correct linelen here */
GdCalcMemGCAlloc(psd, psd->xres, psd->yres, psd->planes,
psd->bpp, &size, &psd->linelen);
psd->ncolors = psd->bpp >= 24? (1 << 24): (1 << psd->bpp);
psd->flags = PSF_SCREEN | PSF_HAVEBLIT;
psd->size = 0;
psd->addr = NULL;
psd->portrait = MWPORTRAIT_NONE;
/* create permanent savebits memory device from screen device*/
savebits = *psd;
savebits.flags = PSF_MEMORY | PSF_HAVEBLIT;
/* select a fb subdriver matching our planes and bpp*/
subdriver = select_fb_subdriver(&savebits);
if (!subdriver)
return NULL;
/* calc size and linelen of savebits alloc*/
/* JHC - Is this redundant now?? */
GdCalcMemGCAlloc(&savebits, savebits.xvirtres, savebits.yvirtres, 0, 0,
&size, &linelen);
savebits.linelen = linelen;
savebits.size = size;
if ((savebits.addr = malloc(size)) == NULL)
return NULL;
set_subdriver(&savebits, subdriver, TRUE);
/* set X11 psd to savebits memaddr for screen->offscreen blits...*/
psd->addr = savebits.addr;
return psd;
}
static void
X11_close(PSD psd)
{
/* free savebits memory*/
free(savebits.addr);
XCloseDisplay(x11_dpy);
}
static void
X11_getscreeninfo(PSD psd,PMWSCREENINFO psi)
{
psi->rows = psd->yvirtres;
psi->cols = psd->xvirtres;
psi->planes = psd->planes;
psi->bpp = psd->bpp;
psi->ncolors = psd->ncolors;
psi->portrait = psd->portrait;
psi->fonts = NUMBER_FONTS;
psi->xdpcm = (DisplayWidth(x11_dpy,x11_scr)*10)/
DisplayWidthMM(x11_dpy,x11_scr);
psi->ydpcm = (DisplayHeight(x11_dpy,x11_scr)*10)/
DisplayHeightMM(x11_dpy,x11_scr);
psi->fbdriver = FALSE; /* not running fb driver, no direct map*/
psi->pixtype = psd->pixtype;
switch (psd->pixtype) {
case MWPF_TRUECOLOR0888:
case MWPF_TRUECOLOR888:
psi->rmask = 0xff0000;
psi->gmask = 0x00ff00;
psi->bmask = 0x0000ff;
break;
case MWPF_TRUECOLOR565:
psi->rmask = 0xf800;
psi->gmask = 0x07e0;
psi->bmask = 0x001f;
break;
case MWPF_TRUECOLOR555:
psi->rmask = 0x7c00;
psi->gmask = 0x03e0;
psi->bmask = 0x001f;
break;
case MWPF_TRUECOLOR332:
psi->rmask = 0xe0;
psi->gmask = 0x1c;
psi->bmask = 0x03;
break;
case MWPF_PALETTE:
default:
psi->rmask = 0xff;
psi->gmask = 0xff;
psi->bmask = 0xff;
break;
}
}
static void
X11_setpalette(PSD psd, int first, int count, MWPALENTRY *pal)
{
int i;
int n;
for (i = 0; i < count; i++) {
char spec[20];
unsigned short r, g, b;
XColor exact;
XColor def;
r = pal[i].r;
g = pal[i].g;
b = pal[i].b;
sprintf(spec, "#%02x%02x%02x", r, g, b);
XLookupColor(x11_dpy, x11_colormap, spec, &exact, &def);
XAllocColor(x11_dpy, x11_colormap, &def);
/* DPRINTF("lookup: exact(%d,%d,%d) = %d, def(%d,%d,%d)=%d\n",
exact.red, exact.green, exact.blue, exact.pixel,
def.red, def.green, def.blue, def.pixel); */
x11_palette[first+i] = def;
}
n = first + count - 1;
if (n > x11_pal_max)
x11_pal_max = n;
}
static void
X11_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
{
set_color(c);
set_mode(gr_mode);
XDrawPoint(x11_dpy, x11_win, x11_gc, x, y);
/* draw savebits for readpixel or blit*/
savebits.DrawPixel(&savebits, x, y, c);
}
static MWPIXELVAL
X11_readpixel(PSD psd, MWCOORD x, MWCOORD y)
{
/* read savebits for pixel value, rather than ask X11*/
return savebits.ReadPixel(&savebits,x,y);
}
static void
X11_drawhline(PSD psd,MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
{
set_color(c);
set_mode(gr_mode);
XDrawLine(x11_dpy, x11_win, x11_gc, x1, y, x2, y);
/* draw savebits for readpixel or blit*/
savebits.DrawHorzLine(&savebits, x1, x2, y, c);
}
static void
X11_drawvline(PSD psd,MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
{
set_color(c);
set_mode(gr_mode);
XDrawLine(x11_dpy, x11_win, x11_gc, x, y1, x, y2);
savebits.DrawVertLine(&savebits, x, y1, y2, c);
}
static void
X11_fillrect(PSD psd,MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2, MWPIXELVAL c)
{
set_color(c);
set_mode(gr_mode);
XFillRectangle(x11_dpy, x11_win, x11_gc, x1, y1, (x2-x1)+1, (y2-y1)+1);
/* draw savebits for readpixel or blit*/
savebits.FillRect(&savebits, x1, y1, x2, y2, c);
}
static void
X11_srccopyblit_screen_to_screen(PMWBLITARGS pb)
{
}
static void
X11_blendconstantblit_screen_to_mem(PMWBLITARGS pb)
{
}
static void
X11_blit(PSD dstpsd,MWCOORD destx,MWCOORD desty,MWCOORD w,MWCOORD h,
PSD srcpsd,MWCOORD srcx,MWCOORD srcy, long op)
{
#if ALPHABLEND
unsigned int alpha;
#endif
set_mode(gr_mode);
if (dstpsd == srcpsd) {
if (dstpsd->flags & PSF_SCREEN) {
XCopyArea(x11_dpy, x11_win, x11_win, x11_gc,
srcx, srcy, w, h, destx, desty);
/* update screen savebits as well*/
savebits.Blit(&savebits, destx, desty, w, h,
&savebits, srcx, srcy, op);
}
else
/* memory to memory blit, use offscreen blitter*/
dstpsd->Blit(dstpsd, destx, desty, w, h, srcpsd, srcx, srcy, op);
}
else if (dstpsd->flags & PSF_SCREEN) {
XImage* img;
int depth = XDefaultDepth(x11_dpy, x11_scr);
int x, y;
char* data;
/* allocate buffer */
if (depth >= 24)
data = malloc(w*4*h);
else if (depth > 8) /* 15, 16 */
data = malloc(w*2*h);
else /* 1,2,4,8 */
data = malloc((w*depth+7)/8 * h);
/* copy from offscreen to screen */
img = XCreateImage(x11_dpy, x11_vis, depth, ZPixmap,
0, data, w, h, 8, 0);
#if ALPHABLEND && (MWPIXEL_FORMAT != MWPF_PALETTE)
if ((op & MWROP_EXTENSION) == MWROP_BLENDCONSTANT) {
alpha = op & 0xff;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
MWPIXELVAL c = srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y);
MWPIXELVAL cd = dstpsd->ReadPixel(dstpsd,destx+x,desty+y);
unsigned char nred = ALPHAPIXELRED(c, cd, alpha);
unsigned char ngreen = ALPHAPIXELGREEN(c, cd, alpha);
unsigned char nblue = ALPHAPIXELBLUE(c, cd, alpha);
unsigned long pixel = PIXELVAL_to_pixel(RGB2PIXEL(nred, ngreen, nblue), srcpsd->pixtype);
XPutPixel(img, x, y, pixel);
/* update screen savebits*/
savebits.DrawPixel(&savebits, destx+x, desty+y, RGB2PIXEL(nred, ngreen, nblue));
}
}
}
else {
MWPIXELVAL c = 0;
unsigned long pixel;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
if (op == MWROP_COPY)
c = srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y);
else {
c = applyOpR(op,
srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y),
dstpsd->ReadPixel(dstpsd,destx+x,desty+y));
pixel = PIXELVAL_to_pixel(c, srcpsd->pixtype);
XPutPixel(img, x, y, pixel);
}
pixel = PIXELVAL_to_pixel(c, srcpsd->pixtype);
XPutPixel(img, x, y, pixel);
/* update screen savebits*/
savebits.DrawPixel(&savebits, destx+x, desty+y, c);
}
}
}
#else
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
MWPIXELVAL c = srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y);
unsigned long pixel = PIXELVAL_to_pixel(c, srcpsd->pixtype);
XPutPixel(img, x, y, pixel);
/* update screen savebits*/
savebits.DrawPixel(&savebits, destx+x, desty+y, c);
}
}
#endif
XPutImage(x11_dpy, x11_win, x11_gc, img, 0, 0, destx, desty, w, h);
XDestroyImage(img);
}
else if (srcpsd->flags & PSF_SCREEN) {
int x, y;
#if ALPHABLEND && (MWPIXEL_FORMAT != MWPF_PALETTE)
if ((op & MWROP_EXTENSION) == MWROP_BLENDCONSTANT) {
alpha = op & 0xff;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
MWPIXELVAL c = srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y);
MWPIXELVAL cd = dstpsd->ReadPixel(dstpsd,destx+x,desty+y);
unsigned char nred = ALPHAPIXELRED(c, cd, alpha);
unsigned char ngreen = ALPHAPIXELGREEN(c, cd, alpha);
unsigned char nblue = ALPHAPIXELBLUE(c, cd, alpha);
dstpsd->DrawPixel(dstpsd, destx+x, desty+y, RGB2PIXEL(nred, ngreen, nblue));
}
}
}
else {
/* copy from screen to offscreen,
* emulated by copy from offscreen bits, no alpha
*/
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
MWPIXELVAL c = srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y);
dstpsd->DrawPixel(dstpsd, destx+x, desty+y, c);
}
}
}
#else
/* copy from screen to offscreen, emulated by copy from offscreen bits*/
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
MWPIXELVAL c = srcpsd->ReadPixel(srcpsd,srcx+x,srcy+y);
dstpsd->DrawPixel(dstpsd, destx+x, desty+y, c);
}
}
#endif
}
}
/* perform pre-select() duties*/
static void
X11_preselect(PSD psd)
{
XFlush(x11_dpy);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -