wip prep commit in lieu of gfx subsystem update changes.
[AROS.git] / arch / all-hosted / hidd / x11 / x11_init.c
blob892c1b4e28e7f42b199aa958bf3cd0b30c5044af
1 /*
2 Copyright © 1995-2017, 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 <aros/bootloader.h>
14 #include <proto/bootloader.h>
16 #include "x11_types.h"
17 #include LC_LIBDEFS_FILE
18 #include "x11_hostlib.h"
19 #include "x11gfx_fullscreen.h"
21 /****************************************************************************************/
23 #undef XSD
25 /****************************************************************************************/
27 static BOOL initclasses(struct x11_staticdata *xsd);
28 static VOID freeclasses(struct x11_staticdata *xsd);
29 struct Task *create_x11task(struct x11task_params *params);
30 VOID x11task_entry(struct x11task_params *xtp);
32 /****************************************************************************************/
34 static OOP_AttrBase HiddPixFmtAttrBase;
36 static struct OOP_ABDescr abd[] =
38 { IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
39 { NULL , NULL }
42 /****************************************************************************************/
44 static BOOL initclasses(struct x11_staticdata *xsd)
46 D(bug("[X11] %s()\n", __PRETTY_FUNCTION__));
48 /* Get some attrbases */
50 if (!OOP_ObtainAttrBases(abd))
51 goto failure;
53 return TRUE;
55 failure: freeclasses(xsd);
57 return FALSE;
60 /****************************************************************************************/
62 static VOID freeclasses(struct x11_staticdata *xsd)
64 D(bug("[X11] %s()\n", __PRETTY_FUNCTION__));
66 OOP_ReleaseAttrBases(abd);
69 /****************************************************************************************/
71 static int MyErrorHandler(Display * display, XErrorEvent * errevent)
73 char buffer[256];
75 #if USE_XSHM
76 extern int xshm_major;
78 if ((xshm_major != 0) && (errevent->request_code == xshm_major) &&
79 (errevent->minor_code == 4) && /* XShmGetImage */
80 (errevent->error_code == BadMatch))
82 /* Ignore this error */
84 return 0;
86 #endif
88 Disable();
89 XCALL(XGetErrorText, display, errevent->error_code, buffer, sizeof (buffer));
90 Enable();
92 bug("XError %d (Major=%d, Minor=%d) task = %s\n%s\n", errevent->error_code, errevent->request_code,
93 errevent->minor_code, FindTask(0)->tc_Node.ln_Name, buffer);
95 return 0;
98 /****************************************************************************************/
100 static int MySysErrorHandler(Display * display)
102 /* This should have been host's perror(), not AROS perror()
103 perror ("X11-Error"); */
104 bug("X11 system error!\n");
106 return 0;
109 /****************************************************************************************/
111 int X11_Init(struct x11_staticdata *xsd)
113 D(bug("[X11] %s()\n", __PRETTY_FUNCTION__));
115 if (xsd->display)
117 D(bug("[X11] %s: already initialized\n", __PRETTY_FUNCTION__));
118 return TRUE;
121 /* Do not need to singlethead this
122 * since no other tasks are using X currently
125 xsd->display = XCALL(XOpenDisplay, NULL);
126 D(bug("[X11] %s: X display @ 0x%p\n", __PRETTY_FUNCTION__, xsd->display));
128 if (xsd->display)
130 struct x11task_params xtp;
131 struct Task *x11task;
132 APTR BootLoaderBase;
134 xsd->options = 0L;
136 #if DEBUG_X11_SYNCHRON
137 XCALL(XSynchronize, xsd->display, True);
138 #endif
139 XCALL(XSetErrorHandler, MyErrorHandler);
140 XCALL(XSetIOErrorHandler, MySysErrorHandler);
142 #if defined(HOST_OS_darwin) || defined(__arm__)
144 * Neither ARM targets nor XQuartz like operations on unmapped window, strange effects occur (bootmenu breaks, for example).
145 * X11 driver needs serious rewrite. For now i hope this will do.
147 #else
148 /* Do not map (show) X window as long as there's no screen */
149 xsd->options |= OPTION_DELAYXWINMAPPING;
150 #endif
152 BootLoaderBase = OpenResource("bootloader.resource");
155 * Argument parsing from bootloader.resource
158 if (BootLoaderBase)
160 struct List *args;
161 struct Node *n;
162 args = GetBootInfo(BL_Args);
163 if (args)
165 for (n = args->lh_Head; n->ln_Succ; n = n->ln_Succ)
167 /* do we have fullscreen flag ? */
168 if (!strcmp("--fullscreen", n->ln_Name))
170 if (x11_fullscreen_supported(xsd->display))
171 xsd->options |= OPTION_FULLSCREEN;
174 if (strcmp("--backingstore", n->ln_Name) == 0)
176 xsd->options |= OPTION_BACKINGSTORE;
179 if (strcmp("--forcestdmodes", n->ln_Name) == 0)
181 xsd->options |= OPTION_FORCESTDMODES;
184 if (strcmp("--forcedelayxwinmapping", n->ln_Name) == 0)
186 xsd->options |= OPTION_DELAYXWINMAPPING;
194 if (xsd->options & OPTION_DELAYXWINMAPPING)
196 D(bug("[X11] %s: option DELAYXWINMAPPING\n", __PRETTY_FUNCTION__));
200 xsd->delete_win_atom = XCALL(XInternAtom, xsd->display, "WM_DELETE_WINDOW", FALSE);
201 xsd->clipboard_atom = XCALL(XInternAtom, xsd->display, "CLIPBOARD", FALSE);
202 xsd->clipboard_property_atom = XCALL(XInternAtom, xsd->display, "AROS_HOSTCLIP", FALSE);
203 xsd->clipboard_incr_atom = XCALL(XInternAtom, xsd->display, "INCR", FALSE);
204 xsd->clipboard_targets_atom = XCALL(XInternAtom, xsd->display, "TARGETS", FALSE);
206 xtp.parent = FindTask(NULL);
207 xtp.ok_signal = SIGBREAKF_CTRL_E;
208 xtp.fail_signal = SIGBREAKF_CTRL_F;
209 xtp.kill_signal = SIGBREAKF_CTRL_C;
210 xtp.xsd = xsd;
212 if ((x11task = create_x11task(&xtp)))
214 if (initclasses(xsd))
216 D(bug("[X11] %s: task & classes initialized\n", __PRETTY_FUNCTION__));
217 return TRUE;
220 Signal(x11task, xtp.kill_signal);
223 XCALL(XCloseDisplay, xsd->display);
227 D(bug("[X11] %s: failed to initialize\n", __PRETTY_FUNCTION__));
229 return FALSE;
232 /****************************************************************************************/