Change to the linux kernel coding style
[wmaker-crm.git] / src / xutil.c
1 /*
2 * WindowMaker miscelaneous functions
3 *
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <X11/Xlib.h>
22 #include <stdlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
25 #include <stdio.h>
26 #include <string.h>
27
28 #include "wconfig.h"
29
30 #include "xutil.h"
31
32 #include <WINGs/WUtil.h>
33 #if 0
34 static Atom Clipboard = 0;
35 #endif
36
37 static char *requestCodes[] = {
38 "DUMMY",
39 "X_CreateWindow",
40 "X_ChangeWindowAttributes",
41 "X_GetWindowAttributes",
42 "X_DestroyWindow",
43 "X_DestroySubwindows",
44 "X_ChangeSaveSet",
45 "X_ReparentWindow",
46 "X_MapWindow",
47 "X_MapSubwindows",
48 "X_UnmapWindow",
49 "X_UnmapSubwindows",
50 "X_ConfigureWindow",
51 "X_CirculateWindow",
52 "X_GetGeometry",
53 "X_QueryTree",
54 "X_InternAtom",
55 "X_GetAtomName",
56 "X_ChangeProperty",
57 "X_DeleteProperty",
58 "X_GetProperty",
59 "X_ListProperties",
60 "X_SetSelectionOwner",
61 "X_GetSelectionOwner",
62 "X_ConvertSelection",
63 "X_SendEvent",
64 "X_GrabPointer",
65 "X_UngrabPointer",
66 "X_GrabButton",
67 "X_UngrabButton",
68 "X_ChangeActivePointerGrab",
69 "X_GrabKeyboard",
70 "X_UngrabKeyboard",
71 "X_GrabKey",
72 "X_UngrabKey",
73 "X_AllowEvents",
74 "X_GrabServer",
75 "X_UngrabServer",
76 "X_QueryPointer",
77 "X_GetMotionEvents",
78 "X_TranslateCoords",
79 "X_WarpPointer",
80 "X_SetInputFocus",
81 "X_GetInputFocus",
82 "X_QueryKeymap",
83 "X_OpenFont",
84 "X_CloseFont",
85 "X_QueryFont",
86 "X_QueryTextExtents",
87 "X_ListFonts",
88 "X_ListFontsWithInfo",
89 "X_SetFontPath",
90 "X_GetFontPath",
91 "X_CreatePixmap",
92 "X_FreePixmap",
93 "X_CreateGC",
94 "X_ChangeGC",
95 "X_CopyGC",
96 "X_SetDashes",
97 "X_SetClipRectangles",
98 "X_FreeGC",
99 "X_ClearArea",
100 "X_CopyArea",
101 "X_CopyPlane",
102 "X_PolyPoint",
103 "X_PolyLine",
104 "X_PolySegment",
105 "X_PolyRectangle",
106 "X_PolyArc",
107 "X_FillPoly",
108 "X_PolyFillRectangle",
109 "X_PolyFillArc",
110 "X_PutImage",
111 "X_GetImage",
112 "X_PolyText8",
113 "X_PolyText16",
114 "X_ImageText8",
115 "X_ImageText16",
116 "X_CreateColormap",
117 "X_FreeColormap",
118 "X_CopyColormapAndFree",
119 "X_InstallColormap",
120 "X_UninstallColormap",
121 "X_ListInstalledColormaps",
122 "X_AllocColor",
123 "X_AllocNamedColor",
124 "X_AllocColorCells",
125 "X_AllocColorPlanes",
126 "X_FreeColors",
127 "X_StoreColors",
128 "X_StoreNamedColor",
129 "X_QueryColors",
130 "X_LookupColor",
131 "X_CreateCursor",
132 "X_CreateGlyphCursor",
133 "X_FreeCursor",
134 "X_RecolorCursor",
135 "X_QueryBestSize",
136 "X_QueryExtension",
137 "X_ListExtensions",
138 "X_ChangeKeyboardMapping",
139 "X_GetKeyboardMapping",
140 "X_ChangeKeyboardControl",
141 "X_GetKeyboardControl",
142 "X_Bell",
143 "X_ChangePointerControl",
144 "X_GetPointerControl",
145 "X_SetScreenSaver",
146 "X_GetScreenSaver",
147 "X_ChangeHosts",
148 "X_ListHosts",
149 "X_SetAccessControl",
150 "X_SetCloseDownMode",
151 "X_KillClient",
152 "X_RotateProperties",
153 "X_ForceScreenSaver",
154 "X_SetPointerMapping",
155 "X_GetPointerMapping",
156 "X_SetModifierMapping",
157 "X_GetModifierMapping",
158 "X_NoOperation"
159 };
160
161 void FormatXError(Display * dpy, XErrorEvent * error, char *buffer, int size)
162 {
163 int i, p;
164
165 XGetErrorText(dpy, error->error_code, buffer, size);
166 i = strlen(buffer);
167 if (i > size - 100)
168 return;
169 buffer += i;
170 if (error->request_code >= sizeof(requestCodes) / sizeof(char *)) {
171 sprintf(buffer, "\n Request code: %i\n", error->request_code);
172 } else {
173 sprintf(buffer, "\n Request code: %i %s\n", error->request_code,
174 requestCodes[error->request_code]);
175 }
176 i += p = strlen(buffer);
177 if (i > size - 40)
178 return;
179 buffer += p;
180 sprintf(buffer, " Request minor code: %i\n", error->minor_code);
181 i += p = strlen(buffer);
182 if (i > size - 30)
183 return;
184 buffer += p;
185 sprintf(buffer, " Resource ID: 0x%x\n", (unsigned int)error->resourceid);
186 i += p = strlen(buffer);
187 if (i > size - 30)
188 return;
189 buffer += p;
190 sprintf(buffer, " Error serial: %li\n", error->serial);
191 return;
192 }