diff options
author | scuri <scuri> | 2008-10-17 06:10:33 +0000 |
---|---|---|
committer | scuri <scuri> | 2008-10-17 06:10:33 +0000 |
commit | 7b52cc13af4e85f1ca2deb6b6c77de9c95ea0dcf (patch) | |
tree | d0857278bde2eff784227c57dcaf930346ceb7ac /src/x11/cdxnative.c |
First commit - moving from LuaForge to SourceForge
Diffstat (limited to 'src/x11/cdxnative.c')
-rw-r--r-- | src/x11/cdxnative.c | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/src/x11/cdxnative.c b/src/x11/cdxnative.c new file mode 100644 index 0000000..c708d20 --- /dev/null +++ b/src/x11/cdxnative.c @@ -0,0 +1,165 @@ +/** \file + * \brief X-Windows Native Window Driver + * + * See Copyright Notice in cd.h + */ + +#include <stdlib.h> +#include <stdio.h> + +#include "cdx11.h" +#include "cdnative.h" + + +int cdGetScreenColorPlanes(void) +{ + static int first = 1; + static int bpp; + + if (first) + { + int nitems; + XVisualInfo info; + Display* drv_display = XOpenDisplay(NULL); + + info.depth = 24; + if (XGetVisualInfo(drv_display, VisualDepthMask, &info, &nitems) != NULL) + { + bpp = 24; + XCloseDisplay(drv_display); + return bpp; + } + + info.depth = 16; + if (XGetVisualInfo(drv_display, VisualDepthMask, &info, &nitems) != NULL) + { + bpp = 16; + XCloseDisplay(drv_display); + return bpp; + } + + info.depth = 8; + if (XGetVisualInfo(drv_display, VisualDepthMask, &info, &nitems) != NULL) + { + bpp = 8; + XCloseDisplay(drv_display); + return bpp; + } + + info.depth = 4; + if (XGetVisualInfo(drv_display, VisualDepthMask, &info, &nitems) != NULL) + { + bpp = 4; + XCloseDisplay(drv_display); + return bpp; + } + + bpp = 2; + XCloseDisplay(drv_display); + + first = 0; + } + + return bpp; +} + +void cdGetScreenSize(int *width, int *height, double *width_mm, double *height_mm) +{ + static int first = 1; + static int dpy_width, dpy_height, dpy_width_mm, dpy_height_mm; + + if (first) + { + Display* drv_display = XOpenDisplay(NULL); + int drv_screen = DefaultScreen (drv_display); + + dpy_width = DisplayWidth(drv_display,drv_screen); + dpy_height = DisplayHeight(drv_display,drv_screen); + dpy_width_mm = DisplayWidthMM(drv_display,drv_screen); + dpy_height_mm = DisplayHeightMM(drv_display,drv_screen); + + XCloseDisplay(drv_display); + + first = 0; + } + + if (width) *width = dpy_width; + if (height) *height = dpy_height; + if (width_mm) *width_mm = dpy_width_mm; + if (height_mm) *height_mm = dpy_height_mm; +} + +static void cdkillcanvas(cdCtxCanvas *ctxcanvas) +{ + cdxKillCanvas(ctxcanvas); +} + +static int cdactivate(cdCtxCanvas *ctxcanvas) +{ + Window root; + int x, y; + unsigned int bw, d; + XGetGeometry(ctxcanvas->dpy, ctxcanvas->wnd, &root, &x, &y, + (unsigned int*)&ctxcanvas->canvas->w, (unsigned int*)&ctxcanvas->canvas->h, &bw, &d); + + ctxcanvas->canvas->w_mm = ((double)ctxcanvas->canvas->w) / ctxcanvas->canvas->xres; + ctxcanvas->canvas->h_mm = ((double)ctxcanvas->canvas->h) / ctxcanvas->canvas->yres; + + if (ctxcanvas->canvas->use_matrix) + ctxcanvas->canvas->cxTransform(ctxcanvas, ctxcanvas->canvas->matrix); + + return CD_OK; +} + +static void cdcreatecanvas(cdCanvas* canvas, void *data) +{ + char* data_str = (char*)data; + Window wnd; + Display *dpy; + XWindowAttributes wa; + +#ifdef SunOS_OLD + sscanf(data_str, "%d %lu", &dpy, &wnd); +#else + sscanf(data_str, "%p %lu", &dpy, &wnd); +#endif + + if (!dpy || !wnd) + return; + + XGetWindowAttributes(dpy, wnd, &wa); + cdxCreateCanvas(canvas, dpy, XScreenNumberOfScreen(wa.screen), wnd, wa.visual); +} + +static void cdinittable(cdCanvas* canvas) +{ + cdxInitTable(canvas); + + canvas->cxKillCanvas = cdkillcanvas; + canvas->cxActivate = cdactivate; +} + +/******************************************************/ + +static cdContext cdNativeWindowContext = +{ + CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_FPRIMTIVES ), + 1, + cdcreatecanvas, + cdinittable, + NULL, + NULL, +}; + + +cdContext* cdContextNativeWindow(void) +{ + if (cdUseContextPlus(CD_QUERY)) + { + cdContext* ctx = cdGetContextPlus(CD_CTX_NATIVEWINDOW); + if (ctx != NULL) + return ctx; + } + + return &cdNativeWindowContext; +} |