]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/hw/vnc/cmap.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / hw / vnc / cmap.c
1 /*
2  * cmap.c
3  */
4
5 /*
6  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
7  *
8  *  This is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This software is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this software; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
21  *  USA.
22  */
23
24 /*
25
26 Copyright (c) 1993  X Consortium
27
28 Permission is hereby granted, free of charge, to any person obtaining
29 a copy of this software and associated documentation files (the
30 "Software"), to deal in the Software without restriction, including
31 without limitation the rights to use, copy, modify, merge, publish,
32 distribute, sublicense, and/or sell copies of the Software, and to
33 permit persons to whom the Software is furnished to do so, subject to
34 the following conditions:
35
36 The above copyright notice and this permission notice shall be included
37 in all copies or substantial portions of the Software.
38
39 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
40 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
43 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
44 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
45 OTHER DEALINGS IN THE SOFTWARE.
46
47 Except as contained in this notice, the name of the X Consortium shall
48 not be used in advertising or otherwise to promote the sale, use or
49 other dealings in this Software without prior written authorization
50 from the X Consortium.
51
52 */
53
54 #include <stdio.h>
55 #include "scrnintstr.h"
56 #include "resource.h"
57 #include "colormapst.h"
58 #include "rfb.h"
59
60 ColormapPtr rfbInstalledColormap;
61
62 int
63 rfbListInstalledColormaps(pScreen, pmaps)
64     ScreenPtr   pScreen;
65     Colormap    *pmaps;
66 {
67     /* By the time we are processing requests, we can guarantee that there
68      * is always a colormap installed */
69     *pmaps = rfbInstalledColormap->mid;
70     return (1);
71 }
72
73
74 void
75 rfbInstallColormap(pmap)
76     ColormapPtr pmap;
77 {
78     ColormapPtr oldpmap = rfbInstalledColormap;
79
80     if (pmap != oldpmap) {
81
82         if(oldpmap != (ColormapPtr)None)
83             WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
84         /* Install pmap */
85         rfbInstalledColormap = pmap;
86         WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
87
88         rfbSetClientColourMaps(0, 0);
89     }
90 }
91
92 void
93 rfbUninstallColormap(pmap)
94     ColormapPtr pmap;
95 {
96     ColormapPtr curpmap = rfbInstalledColormap;
97
98     if(pmap == curpmap)
99     {
100         if (pmap->mid != pmap->pScreen->defColormap)
101         {
102             curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
103                                                    RT_COLORMAP);
104             (*pmap->pScreen->InstallColormap)(curpmap);
105         }
106     }
107 }
108
109
110 /*
111  * rfbStoreColors.  We have a set of pixels but they may be in any order.
112  * If some of them happen to be in continuous ascending order then we can
113  * group them together into a single call to rfbSetClientColourMaps.
114  */
115
116 void
117 rfbStoreColors(pmap, ndef, pdefs)
118     ColormapPtr pmap;
119     int         ndef;
120     xColorItem  *pdefs;
121 {
122     int i;
123     int first = -1;
124     int n = 0;
125
126     if (pmap == rfbInstalledColormap) {
127         for (i = 0; i < ndef; i++) {
128             if ((first != -1) && (first + n == pdefs[i].pixel)) {
129                 n++;
130             } else {
131                 if (first != -1) {
132                     rfbSetClientColourMaps(first, n);
133                 }
134                 first = pdefs[i].pixel;
135                 n = 1;
136             }
137         }
138         rfbSetClientColourMaps(first, n);
139     }
140 }