Added some debug statements.
[AROS.git] / arch / all-hosted / hidd / x11 / x11_init.c
blob5892b8fbb4c7d5e5c7bb340297dfae6f44c1ec1a
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: X11 hidd initialization code.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <stddef.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
16 #include <exec/types.h>
18 #include <proto/exec.h>
19 #include <proto/oop.h>
21 #include <utility/utility.h>
22 #include <oop/oop.h>
23 #include <hidd/graphics.h>
25 #include <aros/symbolsets.h>
27 #undef SDEBUG
28 #undef DEBUG
29 #define DEBUG 0
30 #include <aros/debug.h>
32 #include LC_LIBDEFS_FILE
34 #include "x11.h"
35 #include "fullscreen.h"
37 /****************************************************************************************/
39 #undef XSD
41 /****************************************************************************************/
43 static BOOL initclasses( struct x11_staticdata *xsd );
44 static VOID freeclasses( struct x11_staticdata *xsd );
45 struct Task *create_x11task( struct x11task_params *params);
46 VOID x11task_entry(struct x11task_params *xtp);
48 /****************************************************************************************/
50 static OOP_AttrBase HiddPixFmtAttrBase;
52 static struct OOP_ABDescr abd[] =
54 { IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
55 { NULL , NULL }
58 /****************************************************************************************/
60 static BOOL initclasses(struct x11_staticdata *xsd)
62 /* Get some attrbases */
64 if (!OOP_ObtainAttrBases(abd))
65 goto failure;
67 return TRUE;
69 failure:
70 freeclasses(xsd);
72 return FALSE;
75 /****************************************************************************************/
77 static VOID freeclasses(struct x11_staticdata *xsd)
79 OOP_ReleaseAttrBases(abd);
82 /****************************************************************************************/
84 static int MyErrorHandler (Display * display, XErrorEvent * errevent)
86 char buffer[256];
88 #if USE_XSHM
89 extern int xshm_major;
91 if ((xshm_major != 0) && (errevent->request_code == xshm_major) &&
92 (errevent->minor_code == 4) && /* XShmGetImage */
93 (errevent->error_code == BadMatch))
95 /* Ignore this error */
97 return 0;
99 #endif
101 XCALL(XGetErrorText, display, errevent->error_code, buffer, sizeof (buffer));
103 kprintf("XError %d (Major=%d, Minor=%d) task = %s\n%s\n",
104 errevent->error_code,
105 errevent->request_code,
106 errevent->minor_code,
107 FindTask(0)->tc_Node.ln_Name,
108 buffer);
110 return 0;
113 /****************************************************************************************/
115 static int MySysErrorHandler (Display * display)
117 perror ("X11-Error");
119 // *((ULONG *)0) = 0;
121 return 0;
124 /****************************************************************************************/
126 static int X11_Init(LIBBASETYPEPTR LIBBASE)
128 struct x11_staticdata *xsd = &LIBBASE->xsd;
130 D(bug("Entering X11_Init\n"));
131 if (LIBBASE->library.lib_OpenCnt) {
132 D(bug("[X11GFX] Already initialized\n"));
133 return TRUE;
136 InitSemaphore( &xsd->sema );
137 InitSemaphore( &xsd->x11sema );
139 /* Do not need to singlethead this
140 * since no other tasks are using X currently
143 xsd->display = XCALL(XOpenDisplay, NULL);
144 D(bug("display(%x)\n", xsd->display));
145 if (xsd->display)
147 struct x11task_params xtp;
148 struct Task *x11task;
150 XCALL(XSetErrorHandler, MyErrorHandler);
151 XCALL(XSetIOErrorHandler, MySysErrorHandler);
154 * XXX on my system, getenv() is declared:
156 * extern char *getenv (__const char *__name) __THROW __nonnull ((1)) * __wur;
158 * the attributes appear to change the calling convention, so a naive
159 * prototype like char *getenv(char *) causes carshes as the returned
160 * address is not a valid pointer.
162 * ideally this configration variable would be brought in via a
163 * bootloader.resource, which hosted doesn't have yet
166 if (getenv, "AROS_X11_FULLSCREEN")
168 xsd->fullscreen = x11_fullscreen_supported(xsd->display);
172 xsd->delete_win_atom = XCALL(XInternAtom, xsd->display, "WM_DELETE_WINDOW", FALSE);
173 xsd->clipboard_atom = XCALL(XInternAtom, xsd->display, "CLIPBOARD", FALSE);
174 xsd->clipboard_property_atom = XCALL(XInternAtom, xsd->display, "AROS_HOSTCLIP", FALSE);
175 xsd->clipboard_incr_atom = XCALL(XInternAtom, xsd->display, "INCR", FALSE);
176 xsd->clipboard_targets_atom = XCALL(XInternAtom, xsd->display, "TARGETS", FALSE);
178 xtp.parent = FindTask(NULL);
179 xtp.ok_signal = SIGBREAKF_CTRL_E;
180 xtp.fail_signal = SIGBREAKF_CTRL_F;
181 xtp.kill_signal = SIGBREAKF_CTRL_C;
182 xtp.xsd = xsd;
184 if ((x11task = create_x11task(&xtp)))
186 if (initclasses(xsd))
188 D(bug("X11_Init succeeded\n"));
189 return TRUE;
192 Signal(x11task, xtp.kill_signal);
195 XCALL(XCloseDisplay, xsd->display);
199 D(bug("X11_Init failed\n"));
201 return FALSE;
204 /****************************************************************************************/
206 ADD2OPENLIB(X11_Init, 0);