105b261ecSmrg/*
235c4bbdfSmrg * Copyright © 1999 Keith Packard
305b261ecSmrg *
405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
605b261ecSmrg * the above copyright notice appear in all copies and that both that
705b261ecSmrg * copyright notice and this permission notice appear in supporting
805b261ecSmrg * documentation, and that the name of Keith Packard not be used in
905b261ecSmrg * advertising or publicity pertaining to distribution of the software without
1005b261ecSmrg * specific, written prior permission.  Keith Packard makes no
1105b261ecSmrg * representations about the suitability of this software for any purpose.  It
1205b261ecSmrg * is provided "as is" without express or implied warranty.
1305b261ecSmrg *
1405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
2105b261ecSmrg */
2205b261ecSmrg
231b5d61b8Smrg#ifdef HAVE_DIX_CONFIG_H
241b5d61b8Smrg#include <dix-config.h>
2505b261ecSmrg#endif
2605b261ecSmrg#include "kdrive.h"
2705b261ecSmrg
2835c4bbdfSmrgKdCardInfo *kdCardInfo;
2905b261ecSmrg
3005b261ecSmrgKdCardInfo *
3135c4bbdfSmrgKdCardInfoAdd(KdCardFuncs * funcs, void *closure)
3205b261ecSmrg{
3335c4bbdfSmrg    KdCardInfo *ci, **prev;
3405b261ecSmrg
3535c4bbdfSmrg    ci = calloc(1, sizeof(KdCardInfo));
3605b261ecSmrg    if (!ci)
3735c4bbdfSmrg        return 0;
3805b261ecSmrg    for (prev = &kdCardInfo; *prev; prev = &(*prev)->next);
3905b261ecSmrg    *prev = ci;
4005b261ecSmrg    ci->cfuncs = funcs;
4105b261ecSmrg    ci->closure = closure;
4205b261ecSmrg    ci->screenList = 0;
4305b261ecSmrg    ci->selected = 0;
4405b261ecSmrg    ci->next = 0;
4505b261ecSmrg    return ci;
4605b261ecSmrg}
4705b261ecSmrg
4805b261ecSmrgKdCardInfo *
4935c4bbdfSmrgKdCardInfoLast(void)
5005b261ecSmrg{
5135c4bbdfSmrg    KdCardInfo *ci;
5205b261ecSmrg
5305b261ecSmrg    if (!kdCardInfo)
5435c4bbdfSmrg        return 0;
5505b261ecSmrg    for (ci = kdCardInfo; ci->next; ci = ci->next);
5605b261ecSmrg    return ci;
5705b261ecSmrg}
5805b261ecSmrg
5905b261ecSmrgvoid
6035c4bbdfSmrgKdCardInfoDispose(KdCardInfo * ci)
6105b261ecSmrg{
6235c4bbdfSmrg    KdCardInfo **prev;
6305b261ecSmrg
6405b261ecSmrg    for (prev = &kdCardInfo; *prev; prev = &(*prev)->next)
6535c4bbdfSmrg        if (*prev == ci) {
6635c4bbdfSmrg            *prev = ci->next;
6735c4bbdfSmrg            free(ci);
6835c4bbdfSmrg            break;
6935c4bbdfSmrg        }
7005b261ecSmrg}
7105b261ecSmrg
7205b261ecSmrgKdScreenInfo *
7335c4bbdfSmrgKdScreenInfoAdd(KdCardInfo * ci)
7405b261ecSmrg{
7535c4bbdfSmrg    KdScreenInfo *si, **prev;
7635c4bbdfSmrg    int n;
7705b261ecSmrg
7835c4bbdfSmrg    si = calloc(1, sizeof(KdScreenInfo));
7905b261ecSmrg    if (!si)
8035c4bbdfSmrg        return 0;
8105b261ecSmrg    for (prev = &ci->screenList, n = 0; *prev; prev = &(*prev)->next, n++);
8205b261ecSmrg    *prev = si;
8305b261ecSmrg    si->next = 0;
8405b261ecSmrg    si->card = ci;
8505b261ecSmrg    si->mynum = n;
8605b261ecSmrg    return si;
8705b261ecSmrg}
8805b261ecSmrg
8905b261ecSmrgvoid
9035c4bbdfSmrgKdScreenInfoDispose(KdScreenInfo * si)
9105b261ecSmrg{
9235c4bbdfSmrg    KdCardInfo *ci = si->card;
9335c4bbdfSmrg    KdScreenInfo **prev;
9405b261ecSmrg
9505b261ecSmrg    for (prev = &ci->screenList; *prev; prev = &(*prev)->next) {
9635c4bbdfSmrg        if (*prev == si) {
9735c4bbdfSmrg            *prev = si->next;
9835c4bbdfSmrg            free(si);
9935c4bbdfSmrg            if (!ci->screenList)
10035c4bbdfSmrg                KdCardInfoDispose(ci);
10135c4bbdfSmrg            break;
10235c4bbdfSmrg        }
10305b261ecSmrg    }
10405b261ecSmrg}
10505b261ecSmrg
10605b261ecSmrgKdPointerInfo *
10735c4bbdfSmrgKdNewPointer(void)
10805b261ecSmrg{
10905b261ecSmrg    KdPointerInfo *pi;
11005b261ecSmrg    int i;
11105b261ecSmrg
11235c4bbdfSmrg    pi = (KdPointerInfo *) calloc(1, sizeof(KdPointerInfo));
11305b261ecSmrg    if (!pi)
11405b261ecSmrg        return NULL;
11505b261ecSmrg
1166747b715Smrg    pi->name = strdup("Generic Pointer");
11705b261ecSmrg    pi->path = NULL;
11805b261ecSmrg    pi->inputClass = KD_MOUSE;
11905b261ecSmrg    pi->driver = NULL;
12005b261ecSmrg    pi->driverPrivate = NULL;
12105b261ecSmrg    pi->next = NULL;
12205b261ecSmrg    pi->options = NULL;
12305b261ecSmrg    pi->nAxes = 3;
12405b261ecSmrg    pi->nButtons = KD_MAX_BUTTON;
12505b261ecSmrg    for (i = 1; i < KD_MAX_BUTTON; i++)
12605b261ecSmrg        pi->map[i] = i;
12705b261ecSmrg
12805b261ecSmrg    return pi;
12905b261ecSmrg}
13005b261ecSmrg
13105b261ecSmrgvoid
13235c4bbdfSmrgKdFreePointer(KdPointerInfo * pi)
13305b261ecSmrg{
1346747b715Smrg    free(pi->name);
1356747b715Smrg    free(pi->path);
13635c4bbdfSmrg    input_option_free_list(&pi->options);
1371b5d61b8Smrg    pi->next = NULL;
1386747b715Smrg    free(pi);
13905b261ecSmrg}
1406747b715Smrg
14105b261ecSmrgvoid
14235c4bbdfSmrgKdFreeKeyboard(KdKeyboardInfo * ki)
14305b261ecSmrg{
1446747b715Smrg    free(ki->name);
1456747b715Smrg    free(ki->path);
1466747b715Smrg    free(ki->xkbRules);
1476747b715Smrg    free(ki->xkbModel);
1486747b715Smrg    free(ki->xkbLayout);
1491b5d61b8Smrg    free(ki->xkbVariant);
1501b5d61b8Smrg    free(ki->xkbOptions);
1511b5d61b8Smrg    input_option_free_list(&ki->options);
15205b261ecSmrg    ki->next = NULL;
1536747b715Smrg    free(ki);
15405b261ecSmrg}
155