15dfecf96Smrg/*
25dfecf96Smrg * Copyright (c) 2001 by The XFree86 Project, Inc.
35dfecf96Smrg *
45dfecf96Smrg * Permission is hereby granted, free of charge, to any person obtaining a
55dfecf96Smrg * copy of this software and associated documentation files (the "Software"),
65dfecf96Smrg * to deal in the Software without restriction, including without limitation
75dfecf96Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
85dfecf96Smrg * and/or sell copies of the Software, and to permit persons to whom the
95dfecf96Smrg * Software is furnished to do so, subject to the following conditions:
105dfecf96Smrg *
115dfecf96Smrg * The above copyright notice and this permission notice shall be included in
125dfecf96Smrg * all copies or substantial portions of the Software.
135dfecf96Smrg *
145dfecf96Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155dfecf96Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
165dfecf96Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
175dfecf96Smrg * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
185dfecf96Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
195dfecf96Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
205dfecf96Smrg * SOFTWARE.
215dfecf96Smrg *
225dfecf96Smrg * Except as contained in this notice, the name of the XFree86 Project shall
235dfecf96Smrg * not be used in advertising or otherwise to promote the sale, use or other
245dfecf96Smrg * dealings in this Software without prior written authorization from the
255dfecf96Smrg * XFree86 Project.
265dfecf96Smrg *
275dfecf96Smrg * Author: Paulo César Pereira de Andrade
285dfecf96Smrg */
295dfecf96Smrg
305dfecf96Smrg/* $XFree86: xc/programs/xedit/lisp/modules/x11.c,v 1.11tsi Exp $ */
315dfecf96Smrg
325dfecf96Smrg#include <stdlib.h>
335dfecf96Smrg#include <string.h>
345dfecf96Smrg#include "lisp/internal.h"
355dfecf96Smrg#include "lisp/private.h"
365dfecf96Smrg#include <X11/Xlib.h>
375dfecf96Smrg
385dfecf96Smrg/*
395dfecf96Smrg * Prototypes
405dfecf96Smrg */
415dfecf96Smrgint x11LoadModule(void);
425dfecf96Smrg
435dfecf96SmrgLispObj *Lisp_XOpenDisplay(LispBuiltin *builtin);
445dfecf96SmrgLispObj *Lisp_XCloseDisplay(LispBuiltin *builtin);
455dfecf96SmrgLispObj *Lisp_XDefaultRootWindow(LispBuiltin *builtin);
465dfecf96SmrgLispObj *Lisp_XDefaultScreen(LispBuiltin *builtin);
475dfecf96SmrgLispObj *Lisp_XDefaultScreenOfDisplay(LispBuiltin *builtin);
485dfecf96SmrgLispObj *Lisp_XBlackPixel(LispBuiltin *builtin);
495dfecf96SmrgLispObj *Lisp_XBlackPixelOfScreen(LispBuiltin *builtin);
505dfecf96SmrgLispObj *Lisp_XWidthOfScreen(LispBuiltin *builtin);
515dfecf96SmrgLispObj *Lisp_XHeightOfScreen(LispBuiltin *builtin);
525dfecf96SmrgLispObj *Lisp_XWhitePixel(LispBuiltin *builtin);
535dfecf96SmrgLispObj *Lisp_XWhitePixelOfScreen(LispBuiltin *builtin);
545dfecf96SmrgLispObj *Lisp_XDefaultGC(LispBuiltin *builtin);
555dfecf96SmrgLispObj *Lisp_XDefaultGCOfScreen(LispBuiltin *builtin);
565dfecf96SmrgLispObj *Lisp_XCreateSimpleWindow(LispBuiltin *builtin);
575dfecf96SmrgLispObj *Lisp_XMapWindow(LispBuiltin *builtin);
585dfecf96SmrgLispObj *Lisp_XDestroyWindow(LispBuiltin *builtin);
595dfecf96SmrgLispObj *Lisp_XFlush(LispBuiltin *builtin);
605dfecf96SmrgLispObj *Lisp_XRaiseWindow(LispBuiltin *builtin);
615dfecf96SmrgLispObj *Lisp_XBell(LispBuiltin *builtin);
625dfecf96Smrg
635dfecf96SmrgLispObj *Lisp_XDrawLine(LispBuiltin *builtin);
645dfecf96Smrg
655dfecf96Smrg/*
665dfecf96Smrg * Initialization
675dfecf96Smrg */
685dfecf96Smrgstatic LispBuiltin lispbuiltins[] = {
695dfecf96Smrg    {LispFunction, Lisp_XOpenDisplay, "x-open-display &optional display-name"},
705dfecf96Smrg    {LispFunction, Lisp_XCloseDisplay, "x-close-display display"},
715dfecf96Smrg    {LispFunction, Lisp_XDefaultRootWindow, "x-default-root-window display"},
725dfecf96Smrg    {LispFunction, Lisp_XDefaultScreen, "x-default-screen display"},
735dfecf96Smrg    {LispFunction, Lisp_XDefaultScreenOfDisplay, "x-default-screen-of-display display"},
745dfecf96Smrg    {LispFunction, Lisp_XBlackPixel, "x-black-pixel display &optional screen"},
755dfecf96Smrg    {LispFunction, Lisp_XBlackPixelOfScreen, "x-black-pixel-of-screen screen"},
765dfecf96Smrg    {LispFunction, Lisp_XWhitePixel, "x-white-pixel display &optional screen"},
775dfecf96Smrg    {LispFunction, Lisp_XWhitePixelOfScreen, "x-white-pixel-of-screen screen"},
785dfecf96Smrg    {LispFunction, Lisp_XDefaultGC, "x-default-gc display &optional screen"},
795dfecf96Smrg    {LispFunction, Lisp_XDefaultGCOfScreen, "x-default-gc-of-screen screen"},
805dfecf96Smrg    {LispFunction, Lisp_XCreateSimpleWindow, "x-create-simple-window display parent x y width height &optional border-width border background"},
815dfecf96Smrg    {LispFunction, Lisp_XMapWindow, "x-map-window display window"},
825dfecf96Smrg    {LispFunction, Lisp_XDestroyWindow, "X-DESTROY-WINDOW"},
835dfecf96Smrg    {LispFunction, Lisp_XFlush, "x-flush display"},
845dfecf96Smrg    {LispFunction, Lisp_XDrawLine, "x-draw-line display drawable gc x1 y1 x2 y2"},
855dfecf96Smrg    {LispFunction, Lisp_XBell, "x-bell display &optional percent"},
865dfecf96Smrg    {LispFunction, Lisp_XRaiseWindow, "x-raise-window display window"},
875dfecf96Smrg    {LispFunction, Lisp_XWidthOfScreen, "x-width-of-screen screen"},
885dfecf96Smrg    {LispFunction, Lisp_XHeightOfScreen, "x-height-of-screen screen"},
895dfecf96Smrg};
905dfecf96Smrg
915dfecf96SmrgLispModuleData x11LispModuleData = {
925dfecf96Smrg    LISP_MODULE_VERSION,
935dfecf96Smrg    x11LoadModule
945dfecf96Smrg};
955dfecf96Smrg
965dfecf96Smrgstatic int x11Display_t, x11Screen_t, x11Window_t, x11GC_t;
975dfecf96Smrg
985dfecf96Smrg/*
995dfecf96Smrg * Implementation
1005dfecf96Smrg */
1015dfecf96Smrgint
1025dfecf96Smrgx11LoadModule(void)
1035dfecf96Smrg{
1045dfecf96Smrg    int i;
1055dfecf96Smrg
1065dfecf96Smrg    x11Display_t = LispRegisterOpaqueType("Display*");
1075dfecf96Smrg    x11Screen_t = LispRegisterOpaqueType("Screen*");
1085dfecf96Smrg    x11Window_t = LispRegisterOpaqueType("Window");
1095dfecf96Smrg    x11GC_t = LispRegisterOpaqueType("GC");
1105dfecf96Smrg
1115dfecf96Smrg    for (i = 0; i < sizeof(lispbuiltins) / sizeof(lispbuiltins[0]); i++)
1125dfecf96Smrg	LispAddBuiltinFunction(&lispbuiltins[i]);
1135dfecf96Smrg
1145dfecf96Smrg    return (1);
1155dfecf96Smrg}
1165dfecf96Smrg
1175dfecf96SmrgLispObj *
1185dfecf96SmrgLisp_XOpenDisplay(LispBuiltin *builtin)
1195dfecf96Smrg/*
1205dfecf96Smrgx-open-display &optional display-name
1215dfecf96Smrg */
1225dfecf96Smrg{
1235dfecf96Smrg    LispObj *display_name;
1245dfecf96Smrg    char *dname;
1255dfecf96Smrg
1265dfecf96Smrg    display_name = ARGUMENT(0);
1275dfecf96Smrg
1285dfecf96Smrg    if (display_name == UNSPEC)
1295dfecf96Smrg	dname = NULL;
1305dfecf96Smrg    else {
1315dfecf96Smrg	CHECK_STRING(display_name);
1325dfecf96Smrg	dname = THESTR(display_name);
1335dfecf96Smrg    }
1345dfecf96Smrg
1355dfecf96Smrg    return (OPAQUE(XOpenDisplay(dname), x11Display_t));
1365dfecf96Smrg}
1375dfecf96Smrg
1385dfecf96SmrgLispObj *
1395dfecf96SmrgLisp_XCloseDisplay(LispBuiltin *builtin)
1405dfecf96Smrg/*
1415dfecf96Smrg x-close-display display
1425dfecf96Smrg */
1435dfecf96Smrg{
1445dfecf96Smrg    LispObj *display;
1455dfecf96Smrg
1465dfecf96Smrg    display = ARGUMENT(0);
1475dfecf96Smrg
1485dfecf96Smrg    if (!CHECKO(display, x11Display_t))
1495dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
1505dfecf96Smrg		    STRFUN(builtin), STROBJ(display));
1515dfecf96Smrg
1525dfecf96Smrg    XCloseDisplay((Display*)(display->data.opaque.data));
1535dfecf96Smrg
1545dfecf96Smrg    return (NIL);
1555dfecf96Smrg}
1565dfecf96Smrg
1575dfecf96SmrgLispObj *
1585dfecf96SmrgLisp_XDefaultRootWindow(LispBuiltin *builtin)
1595dfecf96Smrg/*
1605dfecf96Smrg x-default-root-window display
1615dfecf96Smrg */
1625dfecf96Smrg{
1635dfecf96Smrg    LispObj *display;
1645dfecf96Smrg
1655dfecf96Smrg    display = ARGUMENT(0);
1665dfecf96Smrg
1675dfecf96Smrg    if (!CHECKO(display, x11Display_t))
1685dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
1695dfecf96Smrg		    STRFUN(builtin), STROBJ(display));
1705dfecf96Smrg
1715dfecf96Smrg    return (OPAQUE(DefaultRootWindow((Display*)(display->data.opaque.data)),
1725dfecf96Smrg		   x11Window_t));
1735dfecf96Smrg}
1745dfecf96Smrg
1755dfecf96SmrgLispObj *
1765dfecf96SmrgLisp_XDefaultScreen(LispBuiltin *builtin)
1775dfecf96Smrg/*
1785dfecf96Smrg x-default-screen display
1795dfecf96Smrg */
1805dfecf96Smrg{
1815dfecf96Smrg    LispObj *display;
1825dfecf96Smrg
1835dfecf96Smrg    display = ARGUMENT(0);
1845dfecf96Smrg
1855dfecf96Smrg    if (!CHECKO(display, x11Display_t))
1865dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
1875dfecf96Smrg		    STRFUN(builtin), STROBJ(display));
1885dfecf96Smrg
1895dfecf96Smrg    return (INTEGER(DefaultScreen((Display*)(display->data.opaque.data))));
1905dfecf96Smrg}
1915dfecf96Smrg
1925dfecf96SmrgLispObj *
1935dfecf96SmrgLisp_XDefaultScreenOfDisplay(LispBuiltin *builtin)
1945dfecf96Smrg/*
1955dfecf96Smrg x-default-screen-of-display display
1965dfecf96Smrg */
1975dfecf96Smrg{
1985dfecf96Smrg    LispObj *display;
1995dfecf96Smrg
2005dfecf96Smrg    display = ARGUMENT(0);
2015dfecf96Smrg
2025dfecf96Smrg    if (!CHECKO(display, x11Display_t))
2035dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
2045dfecf96Smrg		    STRFUN(builtin), STROBJ(display));
2055dfecf96Smrg
2065dfecf96Smrg    return (OPAQUE(DefaultScreenOfDisplay((Display*)(display->data.opaque.data)),
2075dfecf96Smrg		   x11Screen_t));
2085dfecf96Smrg}
2095dfecf96Smrg
2105dfecf96SmrgLispObj *
2115dfecf96SmrgLisp_XBlackPixel(LispBuiltin *builtin)
2125dfecf96Smrg/*
2135dfecf96Smrg x-black-pixel display &optional screen
2145dfecf96Smrg */
2155dfecf96Smrg{
2165dfecf96Smrg    Display *display;
2175dfecf96Smrg    int screen;
2185dfecf96Smrg
2195dfecf96Smrg    LispObj *odisplay, *oscreen;
2205dfecf96Smrg
2215dfecf96Smrg    oscreen = ARGUMENT(1);
2225dfecf96Smrg    odisplay = ARGUMENT(0);
2235dfecf96Smrg
2245dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
2255dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
2265dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
2275dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
2285dfecf96Smrg
2295dfecf96Smrg    if (oscreen == UNSPEC)
2305dfecf96Smrg	screen = DefaultScreen(display);
2315dfecf96Smrg    else {
2325dfecf96Smrg	CHECK_INDEX(oscreen);
2335dfecf96Smrg	screen = FIXNUM_VALUE(oscreen);
2345dfecf96Smrg    }
2355dfecf96Smrg
2365dfecf96Smrg    if (screen >= ScreenCount(display))
2375dfecf96Smrg	LispDestroy("%s: screen index %d too large, %d screens available",
2385dfecf96Smrg		    STRFUN(builtin), screen, ScreenCount(display));
2395dfecf96Smrg
2405dfecf96Smrg    return (INTEGER(BlackPixel(display, screen)));
2415dfecf96Smrg}
2425dfecf96Smrg
2435dfecf96SmrgLispObj *
2445dfecf96SmrgLisp_XBlackPixelOfScreen(LispBuiltin *builtin)
2455dfecf96Smrg/*
2465dfecf96Smrg x-black-pixel-of-screen screen
2475dfecf96Smrg */
2485dfecf96Smrg{
2495dfecf96Smrg    LispObj *screen;
2505dfecf96Smrg
2515dfecf96Smrg    screen = ARGUMENT(0);
2525dfecf96Smrg
2535dfecf96Smrg    if (!CHECKO(screen, x11Screen_t))
2545dfecf96Smrg	LispDestroy("%s: cannot convert %s to Screen*",
2555dfecf96Smrg		    STRFUN(builtin), STROBJ(screen));
2565dfecf96Smrg
2575dfecf96Smrg    return (INTEGER(XBlackPixelOfScreen((Screen*)(screen->data.opaque.data))));
2585dfecf96Smrg}
2595dfecf96Smrg
2605dfecf96SmrgLispObj *
2615dfecf96SmrgLisp_XWhitePixel(LispBuiltin *builtin)
2625dfecf96Smrg/*
2635dfecf96Smrg x-white-pixel display &optional screen
2645dfecf96Smrg */
2655dfecf96Smrg{
2665dfecf96Smrg    Display *display;
2675dfecf96Smrg    int screen;
2685dfecf96Smrg
2695dfecf96Smrg    LispObj *odisplay, *oscreen;
2705dfecf96Smrg
2715dfecf96Smrg    oscreen = ARGUMENT(1);
2725dfecf96Smrg    odisplay = ARGUMENT(0);
2735dfecf96Smrg
2745dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
2755dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
2765dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
2775dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
2785dfecf96Smrg
2795dfecf96Smrg    if (oscreen == UNSPEC)
2805dfecf96Smrg	screen = DefaultScreen(display);
2815dfecf96Smrg    else {
2825dfecf96Smrg	CHECK_FIXNUM(oscreen);
2835dfecf96Smrg	screen = FIXNUM_VALUE(oscreen);
2845dfecf96Smrg    }
2855dfecf96Smrg
2865dfecf96Smrg    if (screen >= ScreenCount(display))
2875dfecf96Smrg	LispDestroy("%s: screen index %d too large, %d screens available",
2885dfecf96Smrg		    STRFUN(builtin), screen, ScreenCount(display));
2895dfecf96Smrg
2905dfecf96Smrg    return (INTEGER(WhitePixel(display, screen)));
2915dfecf96Smrg}
2925dfecf96Smrg
2935dfecf96SmrgLispObj *
2945dfecf96SmrgLisp_XWhitePixelOfScreen(LispBuiltin *builtin)
2955dfecf96Smrg/*
2965dfecf96Smrg x-white-pixel-of-screen screen
2975dfecf96Smrg */
2985dfecf96Smrg{
2995dfecf96Smrg    LispObj *screen;
3005dfecf96Smrg
3015dfecf96Smrg    screen = ARGUMENT(0);
3025dfecf96Smrg
3035dfecf96Smrg    if (!CHECKO(screen, x11Screen_t))
3045dfecf96Smrg	LispDestroy("%s: cannot convert %s to Screen*",
3055dfecf96Smrg		    STRFUN(builtin), STROBJ(screen));
3065dfecf96Smrg
3075dfecf96Smrg    return (INTEGER(WhitePixelOfScreen((Screen*)(screen->data.opaque.data))));
3085dfecf96Smrg}
3095dfecf96Smrg
3105dfecf96SmrgLispObj *
3115dfecf96SmrgLisp_XDefaultGC(LispBuiltin *builtin)
3125dfecf96Smrg/*
3135dfecf96Smrg x-default-gc display &optional screen
3145dfecf96Smrg */
3155dfecf96Smrg{
3165dfecf96Smrg    Display *display;
3175dfecf96Smrg    int screen;
3185dfecf96Smrg
3195dfecf96Smrg    LispObj *odisplay, *oscreen;
3205dfecf96Smrg
3215dfecf96Smrg    oscreen = ARGUMENT(1);
3225dfecf96Smrg    odisplay = ARGUMENT(0);
3235dfecf96Smrg
3245dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
3255dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
3265dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
3275dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
3285dfecf96Smrg
3295dfecf96Smrg    if (oscreen == UNSPEC)
3305dfecf96Smrg	screen = DefaultScreen(display);
3315dfecf96Smrg    else {
3325dfecf96Smrg	CHECK_FIXNUM(oscreen);
3335dfecf96Smrg	screen = FIXNUM_VALUE(oscreen);
3345dfecf96Smrg    }
3355dfecf96Smrg
3365dfecf96Smrg    if (screen >= ScreenCount(display))
3375dfecf96Smrg	LispDestroy("%s: screen index %d too large, %d screens available",
3385dfecf96Smrg		    STRFUN(builtin), screen, ScreenCount(display));
3395dfecf96Smrg
3405dfecf96Smrg    return (OPAQUE(DefaultGC(display, screen), x11GC_t));
3415dfecf96Smrg}
3425dfecf96Smrg
3435dfecf96SmrgLispObj *
3445dfecf96SmrgLisp_XDefaultGCOfScreen(LispBuiltin *builtin)
3455dfecf96Smrg/*
3465dfecf96Smrg x-default-gc-of-screen screen
3475dfecf96Smrg */
3485dfecf96Smrg{
3495dfecf96Smrg    LispObj *screen;
3505dfecf96Smrg
3515dfecf96Smrg    screen = ARGUMENT(0);
3525dfecf96Smrg
3535dfecf96Smrg    if (!CHECKO(screen, x11Screen_t))
3545dfecf96Smrg	LispDestroy("%s: cannot convert %s to Screen*",
3555dfecf96Smrg		    STRFUN(builtin), STROBJ(screen));
3565dfecf96Smrg
3575dfecf96Smrg    return (OPAQUE(DefaultGCOfScreen((Screen*)(screen->data.opaque.data)),
3585dfecf96Smrg		   x11GC_t));
3595dfecf96Smrg}
3605dfecf96Smrg
3615dfecf96SmrgLispObj *
3625dfecf96SmrgLisp_XCreateSimpleWindow(LispBuiltin *builtin)
3635dfecf96Smrg/*
3645dfecf96Smrg x-create-simple-window display parent x y width height &optional border-width border background
3655dfecf96Smrg */
3665dfecf96Smrg{
3675dfecf96Smrg    Display *display;
3685dfecf96Smrg    Window parent;
3695dfecf96Smrg    int x, y;
3705dfecf96Smrg    unsigned int width, height, border_width;
3715dfecf96Smrg    unsigned long border, background;
3725dfecf96Smrg
3735dfecf96Smrg    LispObj *odisplay, *oparent, *ox, *oy, *owidth, *oheight,
3745dfecf96Smrg	    *oborder_width, *oborder, *obackground;
3755dfecf96Smrg
3765dfecf96Smrg    obackground = ARGUMENT(8);
3775dfecf96Smrg    oborder = ARGUMENT(7);
3785dfecf96Smrg    oborder_width = ARGUMENT(6);
3795dfecf96Smrg    oheight = ARGUMENT(5);
3805dfecf96Smrg    owidth = ARGUMENT(4);
3815dfecf96Smrg    oy = ARGUMENT(3);
3825dfecf96Smrg    ox = ARGUMENT(2);
3835dfecf96Smrg    oparent = ARGUMENT(1);
3845dfecf96Smrg    odisplay = ARGUMENT(0);
3855dfecf96Smrg
3865dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
3875dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
3885dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
3895dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
3905dfecf96Smrg
3915dfecf96Smrg    if (!CHECKO(oparent, x11Window_t))
3925dfecf96Smrg	LispDestroy("%s: cannot convert %s to Window",
3935dfecf96Smrg		    STRFUN(builtin), STROBJ(oparent));
3945dfecf96Smrg    parent = (Window)(oparent->data.opaque.data);
3955dfecf96Smrg
3965dfecf96Smrg    CHECK_FIXNUM(ox);
3975dfecf96Smrg    x = FIXNUM_VALUE(ox);
3985dfecf96Smrg
3995dfecf96Smrg    CHECK_FIXNUM(oy);
4005dfecf96Smrg    y = FIXNUM_VALUE(oy);
4015dfecf96Smrg
4025dfecf96Smrg    CHECK_INDEX(owidth);
4035dfecf96Smrg    width = FIXNUM_VALUE(owidth);
4045dfecf96Smrg
4055dfecf96Smrg    CHECK_INDEX(oheight);
4065dfecf96Smrg    height = FIXNUM_VALUE(oheight);
4075dfecf96Smrg
4085dfecf96Smrg    /* check &OPTIONAL parameters */
4095dfecf96Smrg    if (oborder_width == UNSPEC)
4105dfecf96Smrg	border_width = 1;
4115dfecf96Smrg    else {
4125dfecf96Smrg	CHECK_INDEX(oborder_width);
4135dfecf96Smrg	border_width = FIXNUM_VALUE(oborder_width);
4145dfecf96Smrg    }
4155dfecf96Smrg
4165dfecf96Smrg    if (oborder == UNSPEC)
4175dfecf96Smrg	border = BlackPixel(display, DefaultScreen(display));
4185dfecf96Smrg    else {
4195dfecf96Smrg	CHECK_LONGINT(oborder);
4205dfecf96Smrg	border = LONGINT_VALUE(oborder);
4215dfecf96Smrg    }
4225dfecf96Smrg
4235dfecf96Smrg    if (obackground == UNSPEC)
4245dfecf96Smrg	background = WhitePixel(display, DefaultScreen(display));
4255dfecf96Smrg    else {
4265dfecf96Smrg	CHECK_LONGINT(obackground);
4275dfecf96Smrg	background = LONGINT_VALUE(obackground);
4285dfecf96Smrg    }
4295dfecf96Smrg
4305dfecf96Smrg    return (OPAQUE(
4315dfecf96Smrg	    XCreateSimpleWindow(display, parent, x, y, width, height,
4325dfecf96Smrg				border_width, border, background),
4335dfecf96Smrg	    x11Window_t));
4345dfecf96Smrg}
4355dfecf96Smrg
4365dfecf96SmrgLispObj *
4375dfecf96SmrgLisp_XMapWindow(LispBuiltin *builtin)
4385dfecf96Smrg/*
4395dfecf96Smrg x-map-window display window
4405dfecf96Smrg */
4415dfecf96Smrg{
4425dfecf96Smrg    Display *display;
4435dfecf96Smrg    Window window;
4445dfecf96Smrg
4455dfecf96Smrg    LispObj *odisplay, *owindow;
4465dfecf96Smrg
4475dfecf96Smrg    owindow = ARGUMENT(1);
4485dfecf96Smrg    odisplay = ARGUMENT(0);
4495dfecf96Smrg
4505dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
4515dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
4525dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
4535dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
4545dfecf96Smrg
4555dfecf96Smrg    if (!CHECKO(owindow, x11Window_t))
4565dfecf96Smrg	LispDestroy("%s: cannot convert %s to Window",
4575dfecf96Smrg		    STRFUN(builtin), STROBJ(owindow));
4585dfecf96Smrg    window = (Window)(owindow->data.opaque.data);
4595dfecf96Smrg
4605dfecf96Smrg    XMapWindow(display, window);
4615dfecf96Smrg
4625dfecf96Smrg    return (owindow);
4635dfecf96Smrg}
4645dfecf96Smrg
4655dfecf96SmrgLispObj *
4665dfecf96SmrgLisp_XDestroyWindow(LispBuiltin *builtin)
4675dfecf96Smrg/*
4685dfecf96Smrg x-destroy-window display window
4695dfecf96Smrg */
4705dfecf96Smrg{
4715dfecf96Smrg    Display *display;
4725dfecf96Smrg    Window window;
4735dfecf96Smrg
4745dfecf96Smrg    LispObj *odisplay, *owindow;
4755dfecf96Smrg
4765dfecf96Smrg    owindow = ARGUMENT(1);
4775dfecf96Smrg    odisplay = ARGUMENT(0);
4785dfecf96Smrg
4795dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
4805dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
4815dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
4825dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
4835dfecf96Smrg
4845dfecf96Smrg    if (!CHECKO(owindow, x11Window_t))
4855dfecf96Smrg	LispDestroy("%s: cannot convert %s to Window",
4865dfecf96Smrg		    STRFUN(builtin), STROBJ(owindow));
4875dfecf96Smrg    window = (Window)(owindow->data.opaque.data);
4885dfecf96Smrg
4895dfecf96Smrg    XDestroyWindow(display, window);
4905dfecf96Smrg
4915dfecf96Smrg    return (NIL);
4925dfecf96Smrg}
4935dfecf96Smrg
4945dfecf96SmrgLispObj *
4955dfecf96SmrgLisp_XFlush(LispBuiltin *builtin)
4965dfecf96Smrg/*
4975dfecf96Smrg x-flush display
4985dfecf96Smrg */
4995dfecf96Smrg{
5005dfecf96Smrg    Display *display;
5015dfecf96Smrg
5025dfecf96Smrg    LispObj *odisplay;
5035dfecf96Smrg
5045dfecf96Smrg    odisplay = ARGUMENT(0);
5055dfecf96Smrg
5065dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
5075dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
5085dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
5095dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
5105dfecf96Smrg
5115dfecf96Smrg    XFlush(display);
5125dfecf96Smrg
5135dfecf96Smrg    return (odisplay);
5145dfecf96Smrg}
5155dfecf96Smrg
5165dfecf96SmrgLispObj *
5175dfecf96SmrgLisp_XDrawLine(LispBuiltin *builtin)
5185dfecf96Smrg/*
5195dfecf96Smrg x-draw-line display drawable gc x1 y1 x2 y2
5205dfecf96Smrg */
5215dfecf96Smrg{
5225dfecf96Smrg    Display *display;
5235dfecf96Smrg    Drawable drawable;
5245dfecf96Smrg    GC gc;
5255dfecf96Smrg    int x1, y1, x2, y2;
5265dfecf96Smrg
5275dfecf96Smrg    LispObj *odisplay, *odrawable, *ogc, *ox1, *oy1, *ox2, *oy2;
5285dfecf96Smrg
5295dfecf96Smrg    oy2 = ARGUMENT(6);
5305dfecf96Smrg    ox2 = ARGUMENT(5);
5315dfecf96Smrg    oy1 = ARGUMENT(4);
5325dfecf96Smrg    ox1 = ARGUMENT(3);
5335dfecf96Smrg    ogc = ARGUMENT(2);
5345dfecf96Smrg    odrawable = ARGUMENT(1);
5355dfecf96Smrg    odisplay = ARGUMENT(0);
5365dfecf96Smrg
5375dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
5385dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
5395dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
5405dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
5415dfecf96Smrg
5425dfecf96Smrg    /* XXX correct check when drawing to pixmaps implemented */
5435dfecf96Smrg    if (!CHECKO(odrawable, x11Window_t))
5445dfecf96Smrg	LispDestroy("%s: cannot convert %s to Drawable",
5455dfecf96Smrg		    STRFUN(builtin), STROBJ(odrawable));
5465dfecf96Smrg    drawable = (Drawable)(odrawable->data.opaque.data);
5475dfecf96Smrg
5485dfecf96Smrg    if (!CHECKO(ogc, x11GC_t))
5495dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
5505dfecf96Smrg		    STRFUN(builtin), STROBJ(ogc));
5515dfecf96Smrg    gc = (GC)(ogc->data.opaque.data);
5525dfecf96Smrg
5535dfecf96Smrg    CHECK_FIXNUM(ox1);
5545dfecf96Smrg    x1 = FIXNUM_VALUE(ox1);
5555dfecf96Smrg
5565dfecf96Smrg    CHECK_FIXNUM(oy1);
5575dfecf96Smrg    y1 = FIXNUM_VALUE(oy1);
5585dfecf96Smrg
5595dfecf96Smrg    CHECK_FIXNUM(ox2);
5605dfecf96Smrg    x2 = FIXNUM_VALUE(ox2);
5615dfecf96Smrg
5625dfecf96Smrg    CHECK_FIXNUM(oy2);
5635dfecf96Smrg    y2 = FIXNUM_VALUE(oy2);
5645dfecf96Smrg
5655dfecf96Smrg    XDrawLine(display, drawable, gc, x1, y1, x2, y2);
5665dfecf96Smrg
5675dfecf96Smrg    return (odrawable);
5685dfecf96Smrg}
5695dfecf96Smrg
5705dfecf96SmrgLispObj *
5715dfecf96SmrgLisp_XBell(LispBuiltin *builtin)
5725dfecf96Smrg/*
5735dfecf96Smrg x-bell &optional percent
5745dfecf96Smrg */
5755dfecf96Smrg{
5765dfecf96Smrg    Display *display;
5775dfecf96Smrg    int percent;
5785dfecf96Smrg
5795dfecf96Smrg    LispObj *odisplay, *opercent;
5805dfecf96Smrg
5815dfecf96Smrg    opercent = ARGUMENT(1);
5825dfecf96Smrg    odisplay = ARGUMENT(0);
5835dfecf96Smrg
5845dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
5855dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
5865dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
5875dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
5885dfecf96Smrg
5895dfecf96Smrg    if (opercent == UNSPEC)
5905dfecf96Smrg	percent = 0;
5915dfecf96Smrg    else {
5925dfecf96Smrg	CHECK_FIXNUM(opercent);
5935dfecf96Smrg	percent = FIXNUM_VALUE(opercent);
5945dfecf96Smrg    }
5955dfecf96Smrg
5965dfecf96Smrg    if (percent < -100 || percent > 100)
5975dfecf96Smrg	LispDestroy("%s: percent value %d out of range -100 to 100",
5985dfecf96Smrg		    STRFUN(builtin), percent);
5995dfecf96Smrg
6005dfecf96Smrg    XBell(display, percent);
6015dfecf96Smrg
6025dfecf96Smrg    return (odisplay);
6035dfecf96Smrg}
6045dfecf96Smrg
6055dfecf96SmrgLispObj *
6065dfecf96SmrgLisp_XRaiseWindow(LispBuiltin *builtin)
6075dfecf96Smrg/*
6085dfecf96Smrg x-raise-window display window
6095dfecf96Smrg */
6105dfecf96Smrg{
6115dfecf96Smrg    Display *display;
6125dfecf96Smrg    Window window;
6135dfecf96Smrg
6145dfecf96Smrg    LispObj *odisplay, *owindow;
6155dfecf96Smrg
6165dfecf96Smrg    owindow = ARGUMENT(1);
6175dfecf96Smrg    odisplay = ARGUMENT(0);
6185dfecf96Smrg
6195dfecf96Smrg    if (!CHECKO(odisplay, x11Display_t))
6205dfecf96Smrg	LispDestroy("%s: cannot convert %s to Display*",
6215dfecf96Smrg		    STRFUN(builtin), STROBJ(odisplay));
6225dfecf96Smrg    display = (Display*)(odisplay->data.opaque.data);
6235dfecf96Smrg
6245dfecf96Smrg    if (!CHECKO(owindow, x11Window_t))
6255dfecf96Smrg	LispDestroy("%s: cannot convert %s to Window",
6265dfecf96Smrg		    STRFUN(builtin), STROBJ(owindow));
6275dfecf96Smrg    window = (Window)(owindow->data.opaque.data);
6285dfecf96Smrg
6295dfecf96Smrg    XRaiseWindow(display, window);
6305dfecf96Smrg
6315dfecf96Smrg    return (owindow);
6325dfecf96Smrg}
6335dfecf96Smrg
6345dfecf96SmrgLispObj *
6355dfecf96SmrgLisp_XWidthOfScreen(LispBuiltin *builtin)
6365dfecf96Smrg/*
6375dfecf96Smrg x-width-of-screen screen
6385dfecf96Smrg */
6395dfecf96Smrg{
6405dfecf96Smrg    LispObj *screen;
6415dfecf96Smrg
6425dfecf96Smrg    screen = ARGUMENT(0);
6435dfecf96Smrg
6445dfecf96Smrg    if (!CHECKO(screen, x11Screen_t))
6455dfecf96Smrg	LispDestroy("%s: cannot convert %s to Screen*",
6465dfecf96Smrg		    STRFUN(builtin), STROBJ(screen));
6475dfecf96Smrg
6485dfecf96Smrg    return (FIXNUM(WidthOfScreen((Screen*)(screen->data.opaque.data))));
6495dfecf96Smrg}
6505dfecf96Smrg
6515dfecf96SmrgLispObj *
6525dfecf96SmrgLisp_XHeightOfScreen(LispBuiltin *builtin)
6535dfecf96Smrg/*
6545dfecf96Smrg x-height-of-screen screen
6555dfecf96Smrg */
6565dfecf96Smrg{
6575dfecf96Smrg    LispObj *screen;
6585dfecf96Smrg
6595dfecf96Smrg    screen = ARGUMENT(0);
6605dfecf96Smrg
6615dfecf96Smrg    if (!CHECKO(screen, x11Screen_t))
6625dfecf96Smrg	LispDestroy("%s: cannot convert %s to Screen*",
6635dfecf96Smrg		    STRFUN(builtin), STROBJ(screen));
6645dfecf96Smrg
6655dfecf96Smrg    return (FIXNUM(HeightOfScreen((Screen*)(screen->data.opaque.data))));
6665dfecf96Smrg}
667