set charset to utf-8
[wmaker-crm.git] / src / xutil.c
blob1e46d2ea9713dfb6b370e293e3dfc0b2a8858ec0
1 /*
2 * WindowMaker miscelaneous functions
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
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.
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.
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.
22 #include <X11/Xlib.h>
23 #include <stdlib.h>
24 #include <X11/Xutil.h>
25 #include <X11/Xatom.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include "wconfig.h"
31 #include "xutil.h"
33 #include <WINGs/WUtil.h>
34 #if 0
35 static Atom Clipboard=0;
36 #endif
38 static char *requestCodes[] = {
39 "DUMMY",
40 "X_CreateWindow",
41 "X_ChangeWindowAttributes",
42 "X_GetWindowAttributes",
43 "X_DestroyWindow",
44 "X_DestroySubwindows",
45 "X_ChangeSaveSet",
46 "X_ReparentWindow",
47 "X_MapWindow",
48 "X_MapSubwindows",
49 "X_UnmapWindow",
50 "X_UnmapSubwindows",
51 "X_ConfigureWindow",
52 "X_CirculateWindow",
53 "X_GetGeometry",
54 "X_QueryTree",
55 "X_InternAtom",
56 "X_GetAtomName",
57 "X_ChangeProperty",
58 "X_DeleteProperty",
59 "X_GetProperty",
60 "X_ListProperties",
61 "X_SetSelectionOwner",
62 "X_GetSelectionOwner",
63 "X_ConvertSelection",
64 "X_SendEvent",
65 "X_GrabPointer",
66 "X_UngrabPointer",
67 "X_GrabButton",
68 "X_UngrabButton",
69 "X_ChangeActivePointerGrab",
70 "X_GrabKeyboard",
71 "X_UngrabKeyboard",
72 "X_GrabKey",
73 "X_UngrabKey",
74 "X_AllowEvents",
75 "X_GrabServer",
76 "X_UngrabServer",
77 "X_QueryPointer",
78 "X_GetMotionEvents",
79 "X_TranslateCoords",
80 "X_WarpPointer",
81 "X_SetInputFocus",
82 "X_GetInputFocus",
83 "X_QueryKeymap",
84 "X_OpenFont",
85 "X_CloseFont",
86 "X_QueryFont",
87 "X_QueryTextExtents",
88 "X_ListFonts",
89 "X_ListFontsWithInfo",
90 "X_SetFontPath",
91 "X_GetFontPath",
92 "X_CreatePixmap",
93 "X_FreePixmap",
94 "X_CreateGC",
95 "X_ChangeGC",
96 "X_CopyGC",
97 "X_SetDashes",
98 "X_SetClipRectangles",
99 "X_FreeGC",
100 "X_ClearArea",
101 "X_CopyArea",
102 "X_CopyPlane",
103 "X_PolyPoint",
104 "X_PolyLine",
105 "X_PolySegment",
106 "X_PolyRectangle",
107 "X_PolyArc",
108 "X_FillPoly",
109 "X_PolyFillRectangle",
110 "X_PolyFillArc",
111 "X_PutImage",
112 "X_GetImage",
113 "X_PolyText8",
114 "X_PolyText16",
115 "X_ImageText8",
116 "X_ImageText16",
117 "X_CreateColormap",
118 "X_FreeColormap",
119 "X_CopyColormapAndFree",
120 "X_InstallColormap",
121 "X_UninstallColormap",
122 "X_ListInstalledColormaps",
123 "X_AllocColor",
124 "X_AllocNamedColor",
125 "X_AllocColorCells",
126 "X_AllocColorPlanes",
127 "X_FreeColors",
128 "X_StoreColors",
129 "X_StoreNamedColor",
130 "X_QueryColors",
131 "X_LookupColor",
132 "X_CreateCursor",
133 "X_CreateGlyphCursor",
134 "X_FreeCursor",
135 "X_RecolorCursor",
136 "X_QueryBestSize",
137 "X_QueryExtension",
138 "X_ListExtensions",
139 "X_ChangeKeyboardMapping",
140 "X_GetKeyboardMapping",
141 "X_ChangeKeyboardControl",
142 "X_GetKeyboardControl",
143 "X_Bell",
144 "X_ChangePointerControl",
145 "X_GetPointerControl",
146 "X_SetScreenSaver",
147 "X_GetScreenSaver",
148 "X_ChangeHosts",
149 "X_ListHosts",
150 "X_SetAccessControl",
151 "X_SetCloseDownMode",
152 "X_KillClient",
153 "X_RotateProperties",
154 "X_ForceScreenSaver",
155 "X_SetPointerMapping",
156 "X_GetPointerMapping",
157 "X_SetModifierMapping",
158 "X_GetModifierMapping",
159 "X_NoOperation"
163 void
164 FormatXError(Display *dpy, XErrorEvent *error, char *buffer, int size)
166 int i, p;
168 XGetErrorText(dpy, error->error_code, buffer, size);
169 i = strlen(buffer);
170 if (i > size-100)
171 return;
172 buffer += i;
173 if (error->request_code >= sizeof(requestCodes)/sizeof(char*)) {
174 sprintf(buffer, "\n Request code: %i\n",
175 error->request_code);
176 } else {
177 sprintf(buffer, "\n Request code: %i %s\n", error->request_code,
178 requestCodes[error->request_code]);
180 i += p = strlen(buffer);
181 if (i > size - 40)
182 return;
183 buffer += p;
184 sprintf(buffer, " Request minor code: %i\n", error->minor_code);
185 i += p = strlen(buffer);
186 if (i > size - 30)
187 return;
188 buffer += p;
189 sprintf(buffer, " Resource ID: 0x%x\n", (unsigned int)error->resourceid);
190 i += p = strlen(buffer);
191 if (i > size - 30)
192 return;
193 buffer += p;
194 sprintf(buffer, " Error serial: %li\n", error->serial);
195 return;