1 /*
2 * Copyright © 2004 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
13 *
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22 #ifdef HAVE_DIX_CONFIG_H
23 #include <dix-config.h>
24 #endif
25
26 #include "arcan.h"
27 #include "glx_extinit.h"
28
29 extern Bool kdHasPointer;
30 extern Bool kdHasKbd;
31
trace(const char * msg,...)32 static inline void trace(const char* msg, ...)
33 {
34 #ifdef ARCAN_TRACE
35 va_list args;
36 va_start( args, msg );
37 vfprintf(stderr, msg, args );
38 fprintf(stderr, "\n");
39 va_end( args);
40 fflush(stderr);
41 #endif
42 }
43
44 void
InitCard(char * name)45 InitCard(char *name)
46 {
47 trace("ArcanInit:InitCard");
48 KdCardInfoAdd(&arcanFuncs, 0);
49 }
50
51 static const ExtensionModule arcanExtensions[] = {
52 #ifdef GLXEXT
53 { GlxExtensionInit, "GLX", &noGlxExtension }
54 #endif
55 };
56
57 void
InitOutput(ScreenInfo * pScreenInfo,int argc,char ** argv)58 InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
59 {
60 /*
61 int depths[] = {1, 4, 8, 15, 16, 24, 32};
62 int bpp[] = {1, 8, 8, 16, 16, 32, 32};
63 trace("ArcanInit:InitOutput");
64 for (int i = 0; i < 7; i++){
65 pScreenInfo->formats[i].depth = depths[i];
66 pScreenInfo->formats[i].bitsPerPixel = bpp[i];
67 pScreenInfo->formats[i].scanlinePad = BITMAP_SCANLINE_PAD;
68 }
69 pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
70 pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
71 pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
72 pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
73 pScreenInfo->numPixmapFormats = ARRAY_SIZE(depths);
74 */
75 static bool gotext;
76 if (!gotext){
77 LoadExtensionList(arcanExtensions, ARRAY_SIZE(arcanExtensions), TRUE);
78 gotext = true;
79 }
80 KdInitOutput(pScreenInfo, argc, argv);
81 }
82
83 void
InitInput(int argc,char ** argv)84 InitInput(int argc, char **argv)
85 {
86 struct arcan_shmif_cont* con;
87 KdPointerInfo* pi;
88 KdKeyboardInfo* ki;
89 if (!SeatId) {
90 trace("ArcanInit:InitInput");
91 KdAddPointerDriver(&arcanPointerDriver);
92 if (!kdHasPointer){
93 pi = KdNewPointer();
94 if (!pi)
95 FatalError("Couldn't create Xarcan keyboard\n");
96 pi->driver = &arcanPointerDriver;
97 KdAddPointer(pi);
98 }
99
100 if (!kdHasKbd){
101 ki = KdNewKeyboard();
102 if (!ki)
103 FatalError("Couldn't create Xarcan keyboard\n");
104 ki->driver = &arcanKeyboardDriver;
105 KdAddKeyboard(ki);
106 }
107 }
108
109 KdInitInput();
110
111 /*
112 * DEBUGGING - enable this help somewhat
113 LogInit("yeahlog", ".old");
114 LogSetParameter(XLOG_FILE_VERBOSITY, 100000);
115 */
116
117 /* Register won't work unless we're in init input state */
118 con = arcan_shmif_primary(SHMIF_INPUT);
119 if (con){
120 InputThreadRegisterDev(con->epipe, (void*) arcanFlushEvents, con);
121 }
122 else {
123 ErrorF("kdrive:arcan - No Primary Segment during InitInput\n");
124 }
125 }
126
127 void
CloseInput(void)128 CloseInput(void)
129 {
130 struct arcan_shmif_cont* con = arcan_shmif_primary(SHMIF_INPUT);
131 trace("ArcanInit:CloseInput");
132 if (con){
133 InputThreadUnregisterDev(con->epipe);
134 }
135 KdCloseInput();
136 }
137
138 #ifdef DDXBEFORERESET
139 void
ddxBeforeReset(void)140 ddxBeforeReset(void)
141 {
142 }
143 #endif
144
145 void
ddxUseMsg(void)146 ddxUseMsg(void)
147 {
148 KdUseMsg();
149 ErrorF("\nXarcan Option Usage:\n");
150 ErrorF("-nodynamic Disable connection-controlled resize\n");
151 ErrorF("-aident [str] Set window dynamic identity\n");
152 ErrorF("-atitle [str] Set window static identity\n");
153 #ifdef GLAMOR
154 ErrorF("-glamor Enable glamor rendering\n");
155 #endif
156 ErrorF("-nodri3 Disable DRI3- support\n");
157 ErrorF("-accel_cursor Enable accelerated cursor\n");
158 }
159
160 int
ddxProcessArgument(int argc,char ** argv,int i)161 ddxProcessArgument(int argc, char **argv, int i)
162 {
163 #ifdef GLAMOR
164 if (strcmp(argv[i], "-glamor") == 0){
165 arcanGlamor = 1;
166 arcanFuncs.initAccel = arcanGlamorInit;
167 arcanFuncs.enableAccel = arcanGlamorEnable;
168 arcanFuncs.disableAccel = arcanGlamorDisable;
169 arcanFuncs.finiAccel = arcanGlamorFini;
170 return 1;
171 }
172 else
173 #endif
174 if (strcmp(argv[i], "-nodri3") == 0){
175 arcanConfigPriv.no_dri3 = true;
176 return 1;
177 }
178 else if (strcmp(argv[i], "-aident") == 0){
179 if ((i+1) < argc){
180 return 2;
181 }
182 arcanConfigPriv.ident = strdup(argv[i+1]);
183 ddxUseMsg();
184 exit(1);
185 }
186 else if (strcmp(argv[i], "-atitle") == 0){
187 if ((i+1) < argc){
188 return 2;
189 }
190 arcanConfigPriv.title = strdup(argv[i+1]);
191 ddxUseMsg();
192 exit(1);
193 }
194 else if (strcmp(argv[i], "-nodynamic") == 0){
195 arcanConfigPriv.no_dynamic_resize = true;
196 return 1;
197 }
198 else if (strcmp(argv[i], "-accel_cursor") == 0){
199 arcanConfigPriv.accel_cursor = true;
200 }
201 return KdProcessArgument(argc, argv, i);
202 }
203
204 void
OsVendorInit(void)205 OsVendorInit(void)
206 {
207 arcanInit();
208 }
209
210 KdCardFuncs arcanFuncs = {
211 arcanCardInit, /* cardinit */
212 arcanScreenInit, /* scrinit */
213 arcanInitScreen, /* initScreen */
214 arcanFinishInitScreen, /* finishInitScreen */
215 arcanCreateResources, /* createRes */
216 arcanScreenFini, /* scrfini */
217 arcanCardFini, /* cardfini */
218
219 0, /* initCursor */
220
221 0, /* initAccel */
222 0, /* enableAccel */
223 0, /* disableAccel */
224 0, /* finiAccel */
225
226 arcanGetColors, /* getColors */
227 arcanPutColors, /* putColors */
228 arcanCloseScreen /* close Screen */
229 };
230