1706f2543Smrg/*
2706f2543Smrg * Copyright � 1999 Keith Packard
3706f2543Smrg *
4706f2543Smrg * Permission to use, copy, modify, distribute, and sell this software and its
5706f2543Smrg * documentation for any purpose is hereby granted without fee, provided that
6706f2543Smrg * the above copyright notice appear in all copies and that both that
7706f2543Smrg * copyright notice and this permission notice appear in supporting
8706f2543Smrg * documentation, and that the name of Keith Packard not be used in
9706f2543Smrg * advertising or publicity pertaining to distribution of the software without
10706f2543Smrg * specific, written prior permission.  Keith Packard makes no
11706f2543Smrg * representations about the suitability of this software for any purpose.  It
12706f2543Smrg * is provided "as is" without express or implied warranty.
13706f2543Smrg *
14706f2543Smrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15706f2543Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16706f2543Smrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17706f2543Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18706f2543Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19706f2543Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20706f2543Smrg * PERFORMANCE OF THIS SOFTWARE.
21706f2543Smrg */
22706f2543Smrg
23706f2543Smrg#ifdef HAVE_CONFIG_H
24706f2543Smrg#include <kdrive-config.h>
25706f2543Smrg#endif
26706f2543Smrg#include "kdrive.h"
27706f2543Smrg
28706f2543SmrgKdCardInfo  *kdCardInfo;
29706f2543Smrg
30706f2543SmrgKdCardInfo *
31706f2543SmrgKdCardInfoAdd (KdCardFuncs  *funcs,
32706f2543Smrg	       void	    *closure)
33706f2543Smrg{
34706f2543Smrg    KdCardInfo	*ci, **prev;
35706f2543Smrg
36706f2543Smrg    ci = calloc(1, sizeof (KdCardInfo));
37706f2543Smrg    if (!ci)
38706f2543Smrg	return 0;
39706f2543Smrg    for (prev = &kdCardInfo; *prev; prev = &(*prev)->next);
40706f2543Smrg    *prev = ci;
41706f2543Smrg    ci->cfuncs = funcs;
42706f2543Smrg    ci->closure = closure;
43706f2543Smrg    ci->screenList = 0;
44706f2543Smrg    ci->selected = 0;
45706f2543Smrg    ci->next = 0;
46706f2543Smrg    return ci;
47706f2543Smrg}
48706f2543Smrg
49706f2543SmrgKdCardInfo *
50706f2543SmrgKdCardInfoLast (void)
51706f2543Smrg{
52706f2543Smrg    KdCardInfo	*ci;
53706f2543Smrg
54706f2543Smrg    if (!kdCardInfo)
55706f2543Smrg	return 0;
56706f2543Smrg    for (ci = kdCardInfo; ci->next; ci = ci->next);
57706f2543Smrg    return ci;
58706f2543Smrg}
59706f2543Smrg
60706f2543Smrgvoid
61706f2543SmrgKdCardInfoDispose (KdCardInfo *ci)
62706f2543Smrg{
63706f2543Smrg    KdCardInfo	**prev;
64706f2543Smrg
65706f2543Smrg    for (prev = &kdCardInfo; *prev; prev = &(*prev)->next)
66706f2543Smrg	if (*prev == ci)
67706f2543Smrg	{
68706f2543Smrg	    *prev = ci->next;
69706f2543Smrg	    free(ci);
70706f2543Smrg	    break;
71706f2543Smrg	}
72706f2543Smrg}
73706f2543Smrg
74706f2543SmrgKdScreenInfo *
75706f2543SmrgKdScreenInfoAdd (KdCardInfo *ci)
76706f2543Smrg{
77706f2543Smrg    KdScreenInfo    *si, **prev;
78706f2543Smrg    int		    n;
79706f2543Smrg
80706f2543Smrg    si = calloc(1, sizeof (KdScreenInfo));
81706f2543Smrg    if (!si)
82706f2543Smrg	return 0;
83706f2543Smrg    for (prev = &ci->screenList, n = 0; *prev; prev = &(*prev)->next, n++);
84706f2543Smrg    *prev = si;
85706f2543Smrg    si->next = 0;
86706f2543Smrg    si->card = ci;
87706f2543Smrg    si->mynum = n;
88706f2543Smrg    return si;
89706f2543Smrg}
90706f2543Smrg
91706f2543Smrgvoid
92706f2543SmrgKdScreenInfoDispose (KdScreenInfo *si)
93706f2543Smrg{
94706f2543Smrg    KdCardInfo	    *ci = si->card;
95706f2543Smrg    KdScreenInfo    **prev;
96706f2543Smrg
97706f2543Smrg    for (prev = &ci->screenList; *prev; prev = &(*prev)->next) {
98706f2543Smrg	if (*prev == si)
99706f2543Smrg	{
100706f2543Smrg	    *prev = si->next;
101706f2543Smrg	    free(si);
102706f2543Smrg	    if (!ci->screenList)
103706f2543Smrg		KdCardInfoDispose (ci);
104706f2543Smrg	    break;
105706f2543Smrg	}
106706f2543Smrg    }
107706f2543Smrg}
108706f2543Smrg
109706f2543SmrgKdPointerInfo *
110706f2543SmrgKdNewPointer (void)
111706f2543Smrg{
112706f2543Smrg    KdPointerInfo *pi;
113706f2543Smrg    int i;
114706f2543Smrg
115706f2543Smrg    pi = (KdPointerInfo *)calloc(1, sizeof(KdPointerInfo));
116706f2543Smrg    if (!pi)
117706f2543Smrg        return NULL;
118706f2543Smrg
119706f2543Smrg    pi->name = strdup("Generic Pointer");
120706f2543Smrg    pi->path = NULL;
121706f2543Smrg    pi->inputClass = KD_MOUSE;
122706f2543Smrg    pi->driver = NULL;
123706f2543Smrg    pi->driverPrivate = NULL;
124706f2543Smrg    pi->next = NULL;
125706f2543Smrg    pi->options = NULL;
126706f2543Smrg    pi->nAxes = 3;
127706f2543Smrg    pi->nButtons = KD_MAX_BUTTON;
128706f2543Smrg    for (i = 1; i < KD_MAX_BUTTON; i++)
129706f2543Smrg        pi->map[i] = i;
130706f2543Smrg
131706f2543Smrg    return pi;
132706f2543Smrg}
133706f2543Smrg
134706f2543Smrgvoid
135706f2543SmrgKdFreePointer(KdPointerInfo *pi)
136706f2543Smrg{
137706f2543Smrg    InputOption *option, *prev = NULL;
138706f2543Smrg
139706f2543Smrg    free(pi->name);
140706f2543Smrg    free(pi->path);
141706f2543Smrg
142706f2543Smrg    for (option = pi->options; option; option = option->next) {
143706f2543Smrg        free(prev);
144706f2543Smrg        free(option->key);
145706f2543Smrg        free(option->value);
146706f2543Smrg        prev = option;
147706f2543Smrg    }
148706f2543Smrg
149706f2543Smrg    free(prev);
150706f2543Smrg    free(pi);
151706f2543Smrg}
152706f2543Smrg
153706f2543Smrgvoid
154706f2543SmrgKdFreeKeyboard(KdKeyboardInfo *ki)
155706f2543Smrg{
156706f2543Smrg    free(ki->name);
157706f2543Smrg    free(ki->path);
158706f2543Smrg    free(ki->xkbRules);
159706f2543Smrg    free(ki->xkbModel);
160706f2543Smrg    free(ki->xkbLayout);
161706f2543Smrg    ki->next = NULL;
162706f2543Smrg    free(ki);
163706f2543Smrg}
164