revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-hosted / hidd / x11 / x11_init.c
blob2a8f1a9b5ac540ba56d400dd068a364bd2ae0d5a
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 single-thread this since no other tasks are using X
122 currently */
124 xsd->display = XCALL(XOpenDisplay, NULL);
125 D(bug("[X11] %s: X display @ 0x%p\n", __PRETTY_FUNCTION__, xsd->display));
127 if (xsd->display)
129 struct x11task_params xtp;
130 struct Task *x11task;
131 APTR BootLoaderBase;
133 xsd->options = 0L;
135 #if DEBUG_X11_SYNCHRON
136 XCALL(XSynchronize, xsd->display, True);
137 #endif
138 XCALL(XSetErrorHandler, MyErrorHandler);
139 XCALL(XSetIOErrorHandler, MySysErrorHandler);
141 #if defined(HOST_OS_darwin) || defined(__arm__)
143 * Neither ARM targets nor XQuartz like operations on unmapped window, strange effects occur (bootmenu breaks, for example).
144 * X11 driver needs serious rewrite. For now i hope this will do.
146 #else
147 /* Do not map (show) X window as long as there's no screen */
148 xsd->options |= OPTION_DELAYXWINMAPPING;
149 #endif
151 BootLoaderBase = OpenResource("bootloader.resource");
154 * Argument parsing from bootloader.resource
157 if (BootLoaderBase)
159 struct List *args;
160 struct Node *n;
161 args = GetBootInfo(BL_Args);
162 if (args)
164 for (n = args->lh_Head; n->ln_Succ; n = n->ln_Succ)
166 /* do we have fullscreen flag ? */
167 if (!strcmp("--fullscreen", n->ln_Name))
169 if (x11_fullscreen_supported(xsd->display))
170 xsd->options |= OPTION_FULLSCREEN;
173 if (strcmp("--backingstore", n->ln_Name) == 0)
175 xsd->options |= OPTION_BACKINGSTORE;
178 if (strcmp("--forcestdmodes", n->ln_Name) == 0)
180 xsd->options |= OPTION_FORCESTDMODES;
183 if (strcmp("--forcedelayxwinmapping", n->ln_Name) == 0)
185 xsd->options |= OPTION_DELAYXWINMAPPING;
193 if (xsd->options & OPTION_DELAYXWINMAPPING)
195 D(bug("[X11] %s: option DELAYXWINMAPPING\n", __PRETTY_FUNCTION__));
199 xsd->delete_win_atom = XCALL(XInternAtom, xsd->display, "WM_DELETE_WINDOW", FALSE);
200 xsd->clipboard_atom = XCALL(XInternAtom, xsd->display, "CLIPBOARD", FALSE);
201 xsd->clipboard_property_atom = XCALL(XInternAtom, xsd->display, "AROS_HOSTCLIP", FALSE);
202 xsd->clipboard_incr_atom = XCALL(XInternAtom, xsd->display, "INCR", FALSE);
203 xsd->clipboard_targets_atom = XCALL(XInternAtom, xsd->display, "TARGETS", FALSE);
205 xtp.parent = FindTask(NULL);
206 xtp.ok_signal = SIGBREAKF_CTRL_E;
207 xtp.fail_signal = SIGBREAKF_CTRL_F;
208 xtp.kill_signal = SIGBREAKF_CTRL_C;
209 xtp.xsd = xsd;
211 if ((x11task = create_x11task(&xtp)))
213 if (initclasses(xsd))
215 D(bug("[X11] %s: task & classes initialized\n", __PRETTY_FUNCTION__));
216 return TRUE;
219 Signal(x11task, xtp.kill_signal);
222 XCALL(XCloseDisplay, xsd->display);
226 D(bug("[X11] %s: failed to initialize\n", __PRETTY_FUNCTION__));
228 return FALSE;
231 /****************************************************************************************/