provide more consistent and verbose debug (was used to track down the issue with...
[AROS.git] / arch / all-hosted / hidd / x11 / x11_init.c
blobed0f70c69856c14fdedcba9c25b3ccb365e108b0
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: X11 hidd initialization code.
6 Lang: English.
7 */
9 #include "x11_debug.h"
11 #define __OOP_NOATTRBASES__
13 #include <stddef.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include <exec/types.h>
20 #include <aros/bootloader.h>
21 #include <proto/bootloader.h>
22 #include <proto/exec.h>
23 #include <proto/oop.h>
25 #include <utility/utility.h>
26 #include <oop/oop.h>
27 #include <hidd/graphics.h>
29 #include <aros/symbolsets.h>
31 #include LC_LIBDEFS_FILE
33 #include "x11.h"
34 #include "fullscreen.h"
36 /****************************************************************************************/
38 #undef XSD
40 /****************************************************************************************/
42 static BOOL initclasses(struct x11_staticdata *xsd);
43 static VOID freeclasses(struct x11_staticdata *xsd);
44 struct Task *create_x11task(struct x11task_params *params);
45 VOID x11task_entry(struct x11task_params *xtp);
47 /****************************************************************************************/
49 static OOP_AttrBase HiddPixFmtAttrBase;
51 static struct OOP_ABDescr abd[] =
53 { IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
54 { NULL , NULL }
57 /****************************************************************************************/
59 static BOOL initclasses(struct x11_staticdata *xsd)
61 D(bug("[X11] %s()\n", __PRETTY_FUNCTION__));
63 /* Get some attrbases */
65 if (!OOP_ObtainAttrBases(abd))
66 goto failure;
68 return TRUE;
70 failure: freeclasses(xsd);
72 return FALSE;
75 /****************************************************************************************/
77 static VOID freeclasses(struct x11_staticdata *xsd)
79 D(bug("[X11] %s()\n", __PRETTY_FUNCTION__));
81 OOP_ReleaseAttrBases(abd);
84 /****************************************************************************************/
86 static int MyErrorHandler(Display * display, XErrorEvent * errevent)
88 char buffer[256];
90 #if USE_XSHM
91 extern int xshm_major;
93 if ((xshm_major != 0) && (errevent->request_code == xshm_major) &&
94 (errevent->minor_code == 4) && /* XShmGetImage */
95 (errevent->error_code == BadMatch))
97 /* Ignore this error */
99 return 0;
101 #endif
103 Disable();
104 XCALL(XGetErrorText, display, errevent->error_code, buffer, sizeof (buffer));
105 Enable();
107 bug("XError %d (Major=%d, Minor=%d) task = %s\n%s\n", errevent->error_code, errevent->request_code,
108 errevent->minor_code, FindTask(0)->tc_Node.ln_Name, buffer);
110 return 0;
113 /****************************************************************************************/
115 static int MySysErrorHandler(Display * display)
117 /* This should have been host's perror(), not AROS perror()
118 perror ("X11-Error"); */
119 bug("X11 system error!\n");
121 return 0;
124 /****************************************************************************************/
126 int X11_Init(struct x11_staticdata *xsd)
128 D(bug("[X11] %s()\n", __PRETTY_FUNCTION__));
130 if (xsd->display)
132 D(bug("[X11] %s: already initialized\n", __PRETTY_FUNCTION__));
133 return TRUE;
136 /* Do not need to singlethead this
137 * since no other tasks are using X currently
140 xsd->display = XCALL(XOpenDisplay, NULL);
141 D(bug("[X11] %s: X display @ 0x%p\n", __PRETTY_FUNCTION__, xsd->display));
143 if (xsd->display)
145 struct x11task_params xtp;
146 struct Task *x11task;
147 APTR BootLoaderBase;
149 xsd->options = 0L;
151 #if DEBUG_X11_SYNCHRON
152 XCALL(XSynchronize, xsd->display, True);
153 #endif
154 XCALL(XSetErrorHandler, MyErrorHandler);
155 XCALL(XSetIOErrorHandler, MySysErrorHandler);
157 #if defined(HOST_OS_darwin) || defined(__arm__)
159 * Neither ARM targets nor XQuartz like operations on unmapped window, strange effects occur (bootmenu breaks, for example).
160 * X11 driver needs serious rewrite. For now i hope this will do.
162 #else
163 /* Do not map (show) X window as long as there's no screen */
164 xsd->options |= OPTION_DELAYXWINMAPPING;
165 #endif
167 BootLoaderBase = OpenResource("bootloader.resource");
170 * Argument parsing from bootloader.resource
173 if (BootLoaderBase)
175 struct List *args;
176 struct Node *n;
177 args = GetBootInfo(BL_Args);
178 if (args)
180 for (n = args->lh_Head; n->ln_Succ; n = n->ln_Succ)
182 /* do we have fullscreen flag ? */
183 if (!strcmp("--fullscreen", n->ln_Name))
185 if (x11_fullscreen_supported(xsd->display))
186 xsd->options |= OPTION_FULLSCREEN;
189 if (strcmp("--backingstore", n->ln_Name) == 0)
191 xsd->options |= OPTION_BACKINGSTORE;
194 if (strcmp("--forcestdmodes", n->ln_Name) == 0)
196 xsd->options |= OPTION_FORCESTDMODES;
199 if (strcmp("--forcedelayxwinmapping", n->ln_Name) == 0)
201 xsd->options |= OPTION_DELAYXWINMAPPING;
209 if (xsd->options & OPTION_DELAYXWINMAPPING)
211 D(bug("[X11] %s: option DELAYXWINMAPPING\n", __PRETTY_FUNCTION__));
215 xsd->delete_win_atom = XCALL(XInternAtom, xsd->display, "WM_DELETE_WINDOW", FALSE);
216 xsd->clipboard_atom = XCALL(XInternAtom, xsd->display, "CLIPBOARD", FALSE);
217 xsd->clipboard_property_atom = XCALL(XInternAtom, xsd->display, "AROS_HOSTCLIP", FALSE);
218 xsd->clipboard_incr_atom = XCALL(XInternAtom, xsd->display, "INCR", FALSE);
219 xsd->clipboard_targets_atom = XCALL(XInternAtom, xsd->display, "TARGETS", FALSE);
221 xtp.parent = FindTask(NULL);
222 xtp.ok_signal = SIGBREAKF_CTRL_E;
223 xtp.fail_signal = SIGBREAKF_CTRL_F;
224 xtp.kill_signal = SIGBREAKF_CTRL_C;
225 xtp.xsd = xsd;
227 if ((x11task = create_x11task(&xtp)))
229 if (initclasses(xsd))
231 D(bug("[X11] %s: task & classes initialized\n", __PRETTY_FUNCTION__));
232 return TRUE;
235 Signal(x11task, xtp.kill_signal);
238 XCALL(XCloseDisplay, xsd->display);
242 D(bug("[X11] %s: failed to initialize\n", __PRETTY_FUNCTION__));
244 return FALSE;
247 /****************************************************************************************/