Initial revision
[wmaker-crm.git] / src / xutil.c
blob09a42b7c56b7d4882140af58f27c180616a8ec50
1 /*
2 * WindowMaker miscelaneous functions
3 *
4 * Copyright (c) 1997 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.
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>
28 #include "wconfig.h"
30 #include "xutil.h"
32 #include <WUtil.h>
34 static Atom Clipboard=0;
36 static char *requestCodes[] = {
37 "DUMMY",
38 "X_CreateWindow",
39 "X_ChangeWindowAttributes",
40 "X_GetWindowAttributes",
41 "X_DestroyWindow",
42 "X_DestroySubwindows",
43 "X_ChangeSaveSet",
44 "X_ReparentWindow",
45 "X_MapWindow",
46 "X_MapSubwindows",
47 "X_UnmapWindow",
48 "X_UnmapSubwindows",
49 "X_ConfigureWindow",
50 "X_CirculateWindow",
51 "X_GetGeometry",
52 "X_QueryTree",
53 "X_InternAtom",
54 "X_GetAtomName",
55 "X_ChangeProperty",
56 "X_DeleteProperty",
57 "X_GetProperty",
58 "X_ListProperties",
59 "X_SetSelectionOwner",
60 "X_GetSelectionOwner",
61 "X_ConvertSelection",
62 "X_SendEvent",
63 "X_GrabPointer",
64 "X_UngrabPointer",
65 "X_GrabButton",
66 "X_UngrabButton",
67 "X_ChangeActivePointerGrab",
68 "X_GrabKeyboard",
69 "X_UngrabKeyboard",
70 "X_GrabKey",
71 "X_UngrabKey",
72 "X_AllowEvents",
73 "X_GrabServer",
74 "X_UngrabServer",
75 "X_QueryPointer",
76 "X_GetMotionEvents",
77 "X_TranslateCoords",
78 "X_WarpPointer",
79 "X_SetInputFocus",
80 "X_GetInputFocus",
81 "X_QueryKeymap",
82 "X_OpenFont",
83 "X_CloseFont",
84 "X_QueryFont",
85 "X_QueryTextExtents",
86 "X_ListFonts",
87 "X_ListFontsWithInfo",
88 "X_SetFontPath",
89 "X_GetFontPath",
90 "X_CreatePixmap",
91 "X_FreePixmap",
92 "X_CreateGC",
93 "X_ChangeGC",
94 "X_CopyGC",
95 "X_SetDashes",
96 "X_SetClipRectangles",
97 "X_FreeGC",
98 "X_ClearArea",
99 "X_CopyArea",
100 "X_CopyPlane",
101 "X_PolyPoint",
102 "X_PolyLine",
103 "X_PolySegment",
104 "X_PolyRectangle",
105 "X_PolyArc",
106 "X_FillPoly",
107 "X_PolyFillRectangle",
108 "X_PolyFillArc",
109 "X_PutImage",
110 "X_GetImage",
111 "X_PolyText8",
112 "X_PolyText16",
113 "X_ImageText8",
114 "X_ImageText16",
115 "X_CreateColormap",
116 "X_FreeColormap",
117 "X_CopyColormapAndFree",
118 "X_InstallColormap",
119 "X_UninstallColormap",
120 "X_ListInstalledColormaps",
121 "X_AllocColor",
122 "X_AllocNamedColor",
123 "X_AllocColorCells",
124 "X_AllocColorPlanes",
125 "X_FreeColors",
126 "X_StoreColors",
127 "X_StoreNamedColor",
128 "X_QueryColors",
129 "X_LookupColor",
130 "X_CreateCursor",
131 "X_CreateGlyphCursor",
132 "X_FreeCursor",
133 "X_RecolorCursor",
134 "X_QueryBestSize",
135 "X_QueryExtension",
136 "X_ListExtensions",
137 "X_ChangeKeyboardMapping",
138 "X_GetKeyboardMapping",
139 "X_ChangeKeyboardControl",
140 "X_GetKeyboardControl",
141 "X_Bell",
142 "X_ChangePointerControl",
143 "X_GetPointerControl",
144 "X_SetScreenSaver",
145 "X_GetScreenSaver",
146 "X_ChangeHosts",
147 "X_ListHosts",
148 "X_SetAccessControl",
149 "X_SetCloseDownMode",
150 "X_KillClient",
151 "X_RotateProperties",
152 "X_ForceScreenSaver",
153 "X_SetPointerMapping",
154 "X_GetPointerMapping",
155 "X_SetModifierMapping",
156 "X_GetModifierMapping",
157 "X_NoOperation"
161 void
162 FormatXError(Display *dpy, XErrorEvent *error, char *buffer, int size)
164 int i, p;
166 XGetErrorText(dpy, error->error_code, buffer, size);
167 i = strlen(buffer);
168 if (i > size-100)
169 return;
170 buffer += i;
171 if (error->request_code >= sizeof(requestCodes)/sizeof(char*)) {
172 sprintf(buffer, "\n Unknown request code: %i\n",
173 error->request_code);
174 } else {
175 sprintf(buffer, "\n Request code: %i %s\n", error->request_code,
176 requestCodes[error->request_code]);
178 i += p = strlen(buffer);
179 if (i > size - 40)
180 return;
181 buffer += p;
182 sprintf(buffer, " Request minor code: %i\n", error->minor_code);
183 i += p = strlen(buffer);
184 if (i > size - 30)
185 return;
186 buffer += p;
187 sprintf(buffer, " Resource ID: 0x%x\n", (unsigned int)error->resourceid);
188 i += p = strlen(buffer);
189 if (i > size - 30)
190 return;
191 buffer += p;
192 sprintf(buffer, " Error serial: %li\n", error->serial);
193 return;
198 *----------------------------------------------------------------------
199 * GetSelection--
200 * Request for the current primary selection.
201 *----------------------------------------------------------------------
203 void
204 RequestSelection(Display *dpy, Window requestor, Time timestamp)
206 if (!Clipboard)
207 Clipboard = XInternAtom(dpy, "CLIPBOARD", False);
209 XConvertSelection(dpy, XA_PRIMARY, XA_STRING, Clipboard, requestor,
210 timestamp);
214 char*
215 GetSelection(Display *dpy, Window requestor)
217 Atom rtype;
218 int bits;
219 unsigned long len, bytes;
220 unsigned char *data;
222 XGetWindowProperty(dpy, requestor, Clipboard,
223 0, MAXLINE/4, False, XA_STRING,
224 &rtype, &bits, &len, &bytes, &data);
225 if ((rtype!=XA_STRING) || (bits!=8)) {
226 wwarning(_("invalid data in selection"));
227 if (data) XFree(data);
228 return NULL;
229 } else {
230 return (char*)data;