annotate src/epoch.c @ 6:27bc7f280385 r19-15b4

Import from CVS: tag r19-15b4
author cvs
date Mon, 13 Aug 2007 08:47:15 +0200
parents 376386a54a3c
children 9ee227acff29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Epoch functionality.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985-1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "console-x.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "objects-x.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 Lisp_Object Qx_property_change, Qx_client_message, Qx_map, Qx_unmap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 Lisp_Object Vepoch_event, Vepoch_event_handler;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 /* X resources */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Lisp_Object Qx_resource_live_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #define XX_RESOURCE(x) XRECORD (x, x_resource, struct Lisp_X_Resource)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #define XSETX_RESOURCE(x, p) XSETRECORD (x, p, x_resource)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #define X_RESOURCEP(x) RECORDP (x, x_resource)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #define GC_X_RESOURCEP(x) GC_RECORDP (x, x_resource)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #define CHECK_X_RESOURCE(x) CHECK_RECORD (x, x_resource)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #define X_RESOURCE_LIVE_P(xr) (DEVICE_LIVE_P (XDEVICE ((xr)->device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #define CHECK_LIVE_X_RESOURCE(x) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 do { CHECK_X_RESOURCE (x); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 if (!X_RESOURCE_LIVE_P (XX_RESOURCE (x))) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 x = wrong_type_argument (Qx_resource_live_p, (x)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 struct Lisp_X_Resource
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 struct lcrecord_header header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 XID xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 Atom type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Lisp_Object Qx_resourcep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 static Lisp_Object mark_x_resource (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static void print_x_resource (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 static void finalize_x_resource (void *, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 static int x_resource_equal (Lisp_Object o1, Lisp_Object o2, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 static unsigned long x_resource_hash (Lisp_Object obj, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 DEFINE_LRECORD_IMPLEMENTATION ("x-resource", x_resource,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 mark_x_resource, print_x_resource,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 finalize_x_resource, x_resource_equal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 x_resource_hash, struct Lisp_X_Resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 mark_x_resource (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 return XX_RESOURCE (obj)->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 print_x_resource (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 char buf[100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 Bufbyte *default_string = "Resource";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 Lisp_Object atom_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 Lisp_Object device = XX_RESOURCE (obj)->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 if (!DEVICE_LIVE_P (XDEVICE (device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 error ("printing unreadable object #<dead x-resource>");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 error ("printing unreadable object #<x-resource 0x%x>",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (unsigned int) XX_RESOURCE (obj)->xid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 if (!DEVICE_LIVE_P (XDEVICE (device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 write_c_string ("#<dead x-resource>", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 atom_symbol = x_atom_to_symbol (XDEVICE (device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 XX_RESOURCE (obj)->type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 sprintf (buf, "#<x-resource %s on ",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (NILP (atom_symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ? default_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 : string_data (XSTRING (Fsymbol_name (atom_symbol)))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 print_internal (device, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 sprintf (buf, " 0x%x>",(unsigned int) XX_RESOURCE (obj)->xid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 finalize_x_resource (void *header, int for_disksave)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 x_resource_equal (Lisp_Object o1, Lisp_Object o2, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 return (XX_RESOURCE (o1)->xid == XX_RESOURCE (o2)->xid &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 EQ (XX_RESOURCE (o1)->device, XX_RESOURCE (o2)->device));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 x_resource_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 return HASH2 (XX_RESOURCE (obj)->xid,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 internal_hash (XX_RESOURCE (obj)->device, depth));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 * Epoch equivalent: epoch::resourcep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 DEFUN ("x-resource-p", Fx_resource_p, Sx_resource_p, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Return non-nil if OBJECT is an X resource object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 Lisp_Object object;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 return (X_RESOURCEP (object) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 DEFUN ("x-resource-live-p", Fx_resource_live_p, Sx_resource_live_p, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Return non-nil if OBJECT is a live X resource object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 That means that the X resource's device is live.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 Lisp_Object object;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 return (X_RESOURCEP (object) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 X_RESOURCE_LIVE_P (XX_RESOURCE (object)) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 DEFUN ("x-resource-device", Fx_resource_device, Sx_resource_device, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Return the device that OBJECT (an X resource object) exists on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 Lisp_Object object;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 CHECK_LIVE_X_RESOURCE (object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 return XX_RESOURCE (object)->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 * Epoch equivalent: epoch::set-resource-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 DEFUN ("set-x-resource-type", Fset_x_resource_type, Sset_x_resource_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Set the type of RESOURCE to TYPE. The new type must be an atom.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (resource, type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 Lisp_Object resource, type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 CHECK_LIVE_X_RESOURCE (resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 CHECK_LIVE_X_RESOURCE (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 if (XX_RESOURCE (type)->type != XA_ATOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 error ("New type must be an atom");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 XX_RESOURCE (resource)->type = XX_RESOURCE (type)->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 return resource;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 make_x_resource (XID xid, Atom type, Lisp_Object device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 struct Lisp_X_Resource *xr =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 alloc_lcrecord (sizeof (struct Lisp_X_Resource), lrecord_x_resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 xr->xid = xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 xr->type = type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 xr->device = device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 XSETX_RESOURCE (val, xr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 get_symbol_or_string_as_symbol (Lisp_Object name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 retry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 if (SYMBOLP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 return name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 else if (STRINGP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 return Fintern (name, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 signal_simple_continuable_error ("Must be symbol or string",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 goto retry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 return Qnil; /* not reached */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 * Epoch equivalent: epoch::intern-atom
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 DEFUN ("x-intern-atom", Fx_intern_atom, Sx_intern_atom, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Convert a string or symbol into an atom and return as an X resource.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 Optional argument DEVICE specifies the display connection and defaults
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 to the selected device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (name, device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 Lisp_Object name, device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 Atom atom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 struct device *d = decode_x_device (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 XSETDEVICE (device, d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 atom = symbol_to_x_atom (d, get_symbol_or_string_as_symbol (name), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 return make_x_resource (atom, XA_ATOM, device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 * Epoch equivalent: epoch::unintern-atom
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 DEFUN ("x-atom-name", Fx_atom_name, Sx_atom_name, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 Return the name of an X atom resource as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (atom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 Lisp_Object atom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 CHECK_LIVE_X_RESOURCE (atom);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (XX_RESOURCE (atom)->type != XA_ATOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 signal_simple_error ("Resource is not an atom", atom);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 val = x_atom_to_symbol (XDEVICE (XX_RESOURCE (atom)->device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 XX_RESOURCE (atom)->xid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 if (NILP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 return Fsymbol_name (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 * Epoch equivalent: epoch::string-to-resource
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 DEFUN ("string-to-x-resource", Fstring_to_x_resource,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 Sstring_to_x_resource, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Convert a numeric STRING to an X-RESOURCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 STRING is assumed to represent a 32-bit numer value. X-RESOURCE must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 an X atom. Optional BASE argument should be a number between 2 and 36,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 specifying the base for converting STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (string, type, base)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 Lisp_Object string, type, base;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 XID xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 struct Lisp_X_Resource *xr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 int b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 CHECK_LIVE_X_RESOURCE (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 if (NILP (base))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 b = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 CHECK_INT (base);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 b = XINT (base);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 check_int_range (b, 2, 36);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 if (XX_RESOURCE (type)->type != XA_ATOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 error ("Resource must be an atom");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 xr = XX_RESOURCE (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 xid = (XID) strtol ((CONST char *) string_data (XSTRING (string)), &ptr, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 return ((ptr == (char *) string_data (XSTRING (string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ? Qnil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 : make_x_resource (xid, xr->xid, xr->device));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 * Epoch equivalent: epoch::resource-to-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 DEFUN ("x-resource-to-type", Fx_resource_to_type, Sx_resource_to_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Return an x-resource of type ATOM whose value is the type of the argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (resource)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 Lisp_Object resource;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 struct Lisp_X_Resource *xr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 CHECK_LIVE_X_RESOURCE (resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 xr = XX_RESOURCE (resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 return make_x_resource (xr->type, XA_ATOM, xr->device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 /* internal crap stolen from Epoch */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 static char LongToStringBuffer[33]; /* can't have statics inside functions! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 static char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 long_to_string (unsigned long n, unsigned int base)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 char *digit = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 char *s = LongToStringBuffer + 32; /* at most 33 characters in binary */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 *s = 0; /* terminate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 while (n) /* something there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 *--s = digit[n % base]; /* store bottom digit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 n /= base; /* shift right */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 if (*s == 0) *--s = '0'; /* in case nothing was put in string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 return s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 * Epoch equivalent: epoch::resource-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 DEFUN ("x-resource-to-string", Fx_resource_to_string, Sx_resource_to_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 Convert the xid of RESOURCE to a numeric string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 Optional BASE specifies the base for the conversion (2..36 inclusive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (resource, base)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 Lisp_Object resource, base;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 int cbase = 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 CHECK_LIVE_X_RESOURCE (resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 if (!NILP (base))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 CHECK_INT (base);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 cbase = XINT (base);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 check_int_range (cbase, 2, 36);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 return build_string (long_to_string (XX_RESOURCE (resource)->xid, cbase));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 * Epoch equivalent: epoch::xid-of-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 DEFUN ("x-id-of-frame", Fx_id_of_frame, Sx_id_of_frame, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 Return the window ID of FRAME as an x-resource.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 This differs from `x-window-id' in that its return value is an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 x-resource rather than a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 Lisp_Object frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 struct frame *f = decode_x_frame (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 return make_x_resource (XtWindow (FRAME_X_SHELL_WIDGET (f)), XA_WINDOW,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 FRAME_DEVICE (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 /* Given a frame or ID X resource, return the X window and device
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 it refers to. If text_p is non-zero, the window returned corresponds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 to the text widget of the frame rather than the shell widget. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 epoch_get_window_and_device (Lisp_Object frame, Window *window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 Lisp_Object *device, int text_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (X_RESOURCEP (frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 CHECK_LIVE_X_RESOURCE (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 if (XX_RESOURCE (frame)->type != XA_WINDOW)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 error ("Frame resource must be of type WINDOW");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 *window = XX_RESOURCE (frame)->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 *device = XX_RESOURCE (frame)->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 struct frame *f = decode_x_frame (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 XSETFRAME (frame, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 if (text_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 *window = XtWindow (FRAME_X_TEXT_WIDGET (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 *window = XX_RESOURCE (Fx_id_of_frame (frame))->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 *device = FRAME_DEVICE (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 * Epoch equivalent: epoch::query-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 DEFUN ("x-query-tree", Fx_query_tree, Sx_query_tree, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 Return the portion of the window tree adjacent to FRAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 Return value is the list ( ROOT PARENT . CHILDREN ). The FRAME arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 can either be a frame object or an x-resource of type window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 Lisp_Object frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Window win;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 Window root, parent, *children;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 unsigned int count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 int retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 epoch_get_window_and_device (frame, &win, &device, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 retval =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 XQueryTree (DEVICE_X_DISPLAY (XDEVICE (device)), win, &root, &parent,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 &children, &count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 /* Thank you, X-Consortium. XQueryTree doesn't return Success like everyone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 * else, it returns 1. (Success is defined to be 0 in the standard header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 * files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 if (!retval) return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 val = Fcons (make_x_resource (children[--count], XA_WINDOW, device), val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 XFree (children);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 return Fcons (make_x_resource (root, XA_WINDOW, device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 Fcons ((parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ? make_x_resource (parent, XA_WINDOW, device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 : Qnil),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 val));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 /* more internal crap stolen from Epoch */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 verify_vector_has_consistent_type (Lisp_Object vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 int i; /* vector index */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 XID rtype; /* X_resource type (if vector of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 X_resources) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 int length; /* vector length */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 struct Lisp_Vector *v = XVECTOR (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 Lisp_Object *element;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 Lisp_Object sample;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 Lisp_Object type_obj; /* base type of vector elements */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 sample = v->contents[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 type_obj = sample;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 if (X_RESOURCEP (sample))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 CHECK_LIVE_X_RESOURCE (sample);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 rtype = XX_RESOURCE (sample)->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 device = XX_RESOURCE (sample)->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 length = v->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 element = v->contents;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 for (i = 1; i < length; ++i, ++element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 if (X_RESOURCEP (type_obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 CHECK_LIVE_X_RESOURCE (type_obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 if ((XTYPE (*element) != XTYPE (type_obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 || (LRECORDP (type_obj) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (XRECORD_LHEADER (*element)->implementation !=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 XRECORD_LHEADER (type_obj)->implementation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 || (X_RESOURCEP (type_obj) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (rtype != XX_RESOURCE (*element)->type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 || !EQ (device, XX_RESOURCE (*element)->device))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 error ("Vector has inconsistent types");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 verify_list_has_consistent_type (Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 Lisp_Object type_obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 XID rtype; /* X_resource type (if vector of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 X_resources) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 Lisp_Object temp = Fcar (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 type_obj = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 if (X_RESOURCEP (temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 CHECK_LIVE_X_RESOURCE (temp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 rtype = XX_RESOURCE (temp)->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 device = XX_RESOURCE (temp)->device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 list = Fcdr (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 for ( ; !NILP (list) ; list = Fcdr (list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 temp = Fcar (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 if (X_RESOURCEP (temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 CHECK_LIVE_X_RESOURCE (temp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if ((XTYPE (temp) != XTYPE (type_obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 || (LRECORDP (type_obj) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (XRECORD_LHEADER (temp)->implementation !=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 XRECORD_LHEADER (type_obj)->implementation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 || (X_RESOURCEP (type_obj) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (rtype != XX_RESOURCE (temp)->type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 || !EQ (device, XX_RESOURCE (temp)->device))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 error ("List has inconsistent types");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 #define BYTESIZE 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 /* 16 bit types */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 typedef short int int16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 typedef short unsigned int uint16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 /* the Calculate functions return allocated memory that must be free'd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 I tried to use alloca, but that fails. Sigh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 calculate_vector_property (Lisp_Object vector, unsigned long *count,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 Atom *type, int *format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 unsigned int size,tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 struct Lisp_Vector *v;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 void *addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 v = XVECTOR (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 *count = length = v->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 switch (XTYPE (v->contents[0]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 case Lisp_Int:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 *type = XA_INTEGER;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 if (*format != 8 && *format != 16) *format = 32;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 size = *format * length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 addr = (void *) xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 for ( i = 0 ; i < length ; ++i )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 switch (*format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 case 32 :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 ((int *)addr)[i] = XINT (v->contents[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 case 16 :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ((int16 *)addr)[i] = XINT (v->contents[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 case 8 :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ((char *)addr)[i] = XINT (v->contents[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 if (X_RESOURCEP (v->contents[0]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 CHECK_LIVE_X_RESOURCE (v->contents[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 size = BYTESIZE * sizeof (XID) * length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 *format = BYTESIZE * sizeof (XID);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 *type = XX_RESOURCE (v->contents[0])->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 addr = (void *) xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 for ( i = 0 ; i < length ; ++i )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ( (XID *) addr) [i] = XX_RESOURCE (v->contents[i])->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 *format = BYTESIZE * sizeof (char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 *type = XA_STRING;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 for ( i=0, size=0 ; i < length ; ++i )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 size += (string_length (XSTRING (v->contents[i])) +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 1); /* include null */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 addr = (void *) xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 *count = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 for ( i = 0 , size = 0 ; i < length ; ++i )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 tsize = string_length (XSTRING (v->contents[i])) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 memmove (((char *) addr), string_data (XSTRING (v->contents[i])),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 tsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 size += tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 error ("Invalid type for conversion");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 return addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 calculate_list_property (Lisp_Object list, unsigned long *count,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 Atom *type, int *format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 unsigned int size, tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 Lisp_Object tlist,temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 void *addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 *count = length = XINT (Flength (list));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 switch (XTYPE (Fcar (list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 case Lisp_Int:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 *type = XA_INTEGER;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 if (*format != 8 && *format != 16) *format = 32;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 size = *format * length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 addr = (void *) xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 for ( i = 0 ; i < length ; ++i, list = Fcdr (list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 switch (*format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 case 32 : ((int *)addr)[i] = XINT (Fcar (list)); break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 case 16 : ((int16 *)addr)[i] = XINT (Fcar (list)); break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 case 8 : ((char *)addr)[i] = XINT (Fcar (list)); break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 if (X_RESOURCEP (Fcar (list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 Lisp_Object car = Fcar (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 CHECK_LIVE_X_RESOURCE (car);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 size = BYTESIZE * sizeof (XID) * length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 *format = BYTESIZE * sizeof (XID);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 *type = XX_RESOURCE (Fcar (list))->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 addr = (void *) xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 for ( i = 0 ; i < length ; ++i, list = Fcdr (list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 Lisp_Object carr = Fcar (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 CHECK_LIVE_X_RESOURCE (carr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ((XID *)addr)[i] = XX_RESOURCE (carr)->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 *format = BYTESIZE * sizeof (char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 *type = XA_STRING;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 for ( i=0, size=0 , tlist=list ; i < length ; ++i, tlist = Fcdr (tlist) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 size += string_length (XSTRING (Fcar (tlist))) + 1; /* include null */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 addr = (void *) xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 *count = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 for ( i=0, size=0, tlist=list ; i < length ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 ++i , tlist = Fcdr (tlist) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 temp = Fcar (tlist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 tsize = string_length (XSTRING (temp)) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 memmove (((char *) addr), string_data (XSTRING (temp)), tsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 size += tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 error ("Invalid type for conversion");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 return addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 /* Returns whether the conversion was successful or not */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 convert_elisp_to_x (Lisp_Object value, void **addr, unsigned long *count,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 Atom *type, int *format, int *free_storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 if (VECTORP (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 verify_vector_has_consistent_type (value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 else if (CONSP (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 verify_list_has_consistent_type (value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 *free_storage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 switch (XTYPE (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 *format = BYTESIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 *type = XA_STRING;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 *count = strlen ((CONST char *) string_data (XSTRING (value))) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 *addr = (void *) string_data (XSTRING (value));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 case Lisp_Int:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 *type = XA_INTEGER;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 *count = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 *free_storage = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 *addr = (void *) xmalloc (sizeof (int));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 /* This is ugly -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 * we have to deal with the possibility of different formats
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 switch (*format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 default :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 case 32 :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 *format = 32;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 *((int *)(*addr)) = XINT (value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 case 16 :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 *((int16 *)(*addr)) = XINT (value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 case 8 :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 *((char *)(*addr)) = XINT (value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 if (X_RESOURCEP (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 CHECK_LIVE_X_RESOURCE (value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 *format = sizeof (XID) * BYTESIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 *type = XX_RESOURCE (value)->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 *count = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 *addr = (void *) & (XX_RESOURCE (value)->xid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 case Lisp_Cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 *addr = calculate_list_property (value, count, type, format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 *free_storage = 1; /* above allocates storage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 case Lisp_Vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 *addr = calculate_vector_property (value, count, type, format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 *free_storage = 1; /* above allocates storage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 default :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 error ("Improper type for conversion");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 format_size_hints (XSizeHints *hints)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 Lisp_Object result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 struct Lisp_Vector *v;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 result = Fmake_vector (make_int (6), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 v = XVECTOR (result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 /* ugly but straightforward - just step through the members and flags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 * and stick in the ones that are there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 if (hints->flags & (PPosition|USPosition))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 v->contents[0] = Fcons (make_int (hints->x), make_int (hints->y));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 if (hints->flags & (PSize|USSize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 v->contents[1] = Fcons (make_int (hints->width),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 make_int (hints->height));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 if (hints->flags & PMinSize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 v->contents[2] = Fcons (make_int (hints->min_width),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 make_int (hints->min_height));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 if (hints->flags & PMaxSize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 v->contents[3] = Fcons (make_int (hints->max_width),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 make_int (hints->max_height));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 if (hints->flags & PResizeInc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 v->contents[4] = Fcons (make_int (hints->width_inc),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 make_int (hints->height_inc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 if (hints->flags & PAspect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 v->contents[5] = Fcons (make_int (hints->min_aspect.x),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 Fcons (make_int (hints->min_aspect.y),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 Fcons (make_int (hints->max_aspect.x),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 make_int (hints->max_aspect.y))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 format_string_property (char *buffer, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 Lisp_Object value = Qnil; /* data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 Lisp_Object temp; /* temp value holder */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 int len; /* length of current string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 char *strend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 strend = memchr (buffer, 0, (int) count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 len = strend ? strend - buffer : count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 if (len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 temp = make_string ((Bufbyte *) buffer, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 value = Fcons (temp, value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 buffer = strend + 1; /* skip null, or leaving loop if no null */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 count -= len + !!strend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 : Fnreverse (value));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 format_integer_32_property (long *buff, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 value = Fcons (make_int (buff[--count]), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 format_integer_16_property (int16 *buff, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 value = Fcons (make_int (buff[--count]), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 format_integer_8_property (char *buff, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 value = Fcons (make_int (buff[--count]), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 format_integer_property (void *buff, unsigned long count, int format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 switch (format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 case 8:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 return format_integer_8_property ((char *) buff, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 case 16:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 return format_integer_16_property ((int16 *) buff, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 case 32:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 return format_integer_32_property ((long *) buff, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 format_cardinal_32_property (unsigned long *buff, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 value = Fcons (make_int (buff[--count]), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 format_cardinal_16_property (uint16 *buff, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 value = Fcons (make_int (buff[--count]), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 format_cardinal_8_property (unsigned char *buff, unsigned long count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 while (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 value = Fcons (make_int (buff[--count]), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 format_cardinal_property (void *buff, unsigned long count, int format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 switch (format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 case 8:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 return format_cardinal_8_property ((unsigned char *) buff, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 case 16:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 return format_cardinal_16_property ((uint16 *) buff, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 case 32:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 return format_cardinal_32_property ((unsigned long *) buff, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 format_unknown_property (struct device *d, void *buff, unsigned long count,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 Atom type, int format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 Lisp_Object value = Qnil; /* return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 Lisp_Object device = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 XSETDEVICE (device, d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 switch (format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 case 32:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 XID *xid = (XID *) buff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 int non_zero = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 while (count--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 if (non_zero || xid[count])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 value = Fcons (make_x_resource (xid[count], type, device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 non_zero = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 return (NILP (Fcdr (value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 ? Fcar (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 : value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 convert_x_to_elisp (struct device *d, void *buffer, unsigned long count,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 Atom type, int format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 Lisp_Object value = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 switch (type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 case None:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 value = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 case XA_STRING:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 value = format_string_property (buffer, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 case XA_INTEGER:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 value = format_integer_property ((long *) buffer, count, format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 case XA_CARDINAL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 value = format_cardinal_property ((unsigned long *) buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 count, format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 case XA_WM_SIZE_HINTS:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 value = format_size_hints ((XSizeHints *) buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 value = format_unknown_property (d, (void *) buffer, count, type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 /* get a property given its atom, device, and window */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 raw_get_property (struct device *d, Window win, Atom prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 Lisp_Object value = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 Atom actual_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 int actual_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 unsigned char *buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 unsigned long count, remaining;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 int zret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 Display *dpy = DEVICE_X_DISPLAY (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 zret = XGetWindowProperty (dpy, win, prop,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 0L, 1024L, False, AnyPropertyType,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 &actual_type, &actual_format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 &count, &remaining, &buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 /* If remaining is set, then there's more of the property to get.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 Let's just do the whole read again, this time with enough space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 to get it all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 if (zret == Success && remaining > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 XFree (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 zret = XGetWindowProperty (dpy, win, prop,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 0L, 1024L + ((remaining + 3) / 4),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 False, AnyPropertyType,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 &actual_type, &actual_format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 &count, &remaining, &buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 if (zret != Success)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 return Qnil; /* failed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 value = convert_x_to_elisp (d, buffer, count, actual_type, actual_format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 XFree (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 * Epoch equivalent: epoch::get-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 DEFUN ("x-get-property", Fx_get_property, Sx_get_property, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 Retrieve the X window property for a frame. Arguments are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 PROPERTY: must be a string or an X-resource of type ATOM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 FRAME: (optional) If present, must be a frame object, a frame id, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 and X-resource of type WINDOW. Defaults to the current frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 Returns the value of the property, or nil if the property couldn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 be retrieved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (name, frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 Lisp_Object name, frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 Atom prop = None;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 Display *dpy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 Window win;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 /* We can't use Fx_id_of_frame because it returns the xid of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 the shell widget. But the property change has to take place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 on the edit widget in order for a PropertyNotify event to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 be generated */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 epoch_get_window_and_device (frame, &win, &device, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 if (STRINGP (name) || SYMBOLP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 prop = symbol_to_x_atom (XDEVICE (device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 get_symbol_or_string_as_symbol (name),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 else if (X_RESOURCEP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 CHECK_LIVE_X_RESOURCE (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 if (XX_RESOURCE (name)->type != XA_ATOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 error ("Property must be an ATOM X-resource");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 prop = XX_RESOURCE (name)->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 error ("Property must be a string or X-resource ATOM");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 if (prop == None)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 /* now we have the atom, let's ask for the property! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 return raw_get_property (XDEVICE (device), win, prop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 raw_set_property (Display *dpy, Window win, Atom prop, Lisp_Object value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 Atom actual_type; /* X type of items */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 int actual_format; /* size of data items (8,16,32) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 unsigned long count; /* Number of data items */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 void* addr; /* address of data item array */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 int zret; /* X call return value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 int free_storage; /* set if addr points at non-malloc'd store */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 actual_format = 0; /* don't force a particular format */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 convert_elisp_to_x (value, &addr, &count, &actual_type, &actual_format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 &free_storage);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 zret = XChangeProperty (dpy, win, prop, actual_type, actual_format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 PropModeReplace, (char *) addr, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 XFlush (dpy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 if (free_storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 xfree (addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 DEFUN ("x-set-property", Fx_set_property, Sx_set_property, 2, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 Set a named property for a frame. The first argument (required)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 is the name of the property. The second is the value to set the propery
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 to. The third (optional) is the frame, default is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 the current frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (name, value, frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 Lisp_Object name, value, frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 Atom prop = None; /* name of the property */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 Display *dpy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 Window win;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 /* We can't use Fx_id_of_frame because it returns the xid of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 the shell widget. But the property change has to take place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 on the edit widget in order for a PropertyNotify event to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 be generated */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 epoch_get_window_and_device (frame, &win, &device, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 /* parse the atom name, either a string or an actual atom */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 if (STRINGP (name) || SYMBOLP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 prop = symbol_to_x_atom (XDEVICE (device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 get_symbol_or_string_as_symbol (name),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 else if (X_RESOURCEP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 CHECK_LIVE_X_RESOURCE (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 if (XX_RESOURCE (name)->type != XA_ATOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 error ("Property must be an X-resource ATOM");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 prop = XX_RESOURCE (name)->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 error ("Property must be a string or X-resource ATOM");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 if (prop == None)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 /* that's it. Now set it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 return raw_set_property (dpy, win, prop, value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 * Epoch equivalent: epoch::send-client-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 DEFUN ("x-send-client-message", Fx_send_client_message, Sx_send_client_message,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 1, 5, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 Send a client message to DEST, marking it as being from SOURCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 The message is DATA of TYPE with FORMAT. If TYPE and FORMAT are omitted,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 they are deduced from DATA. If SOURCE is nil, the current frame is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (dest, source, data, type, format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 Lisp_Object dest, source, data, type, format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 int actual_format = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 Atom actual_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 unsigned long count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 void *addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 int free_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 XEvent ev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 Lisp_Object result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 Window dest_win;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 Lisp_Object dest_device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 Window src_win;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 Lisp_Object src_device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 Display *dpy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 epoch_get_window_and_device (dest, &dest_win, &dest_device, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 if (NILP (source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 /* This catches a return of nil */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 XSETFRAME (source, device_selected_frame (XDEVICE (dest_device)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 epoch_get_window_and_device (source, &src_win, &src_device, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 if (!EQ (src_device, dest_device))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 error ("Destination and source must be on the same device");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 dpy = DEVICE_X_DISPLAY (XDEVICE (dest_device));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ev.xclient.window = src_win;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 /* check format before data, because it can cause the data format to vary */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 if (!NILP (format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 CHECK_INT (format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 actual_format = XINT (format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 if (actual_format != 8 && actual_format != 16 && actual_format != 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 error ("Format must be 8, 16, or 32, or nil");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 /* clear out any cruft */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 memset ((char *) &ev.xclient.data, 0, 20);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 /* look for the data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 if (!NILP (data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 convert_elisp_to_x (data, &addr, &count, &actual_type, &actual_format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 &free_storage);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 if ((count * actual_format) > 20*8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 if (free_storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 xfree (addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 error ("Data is too big to fit in a client message");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 memmove (&ev.xclient.data, (char *)addr, count * (actual_format/8));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 if (free_storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 xfree (addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 if (!NILP (type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 CHECK_LIVE_X_RESOURCE (type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 if (XX_RESOURCE (type)->type != XA_ATOM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 error ("Resource for message type must be an atom");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 actual_type = XX_RESOURCE (type)->xid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 ev.xany.type = ClientMessage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 ev.xclient.message_type = actual_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 ev.xclient.format = actual_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 /* There's no better way to set the mask than to hard code the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 * width bit pattern. 1L<<24 == OwnerGrabButtonMask, is the largest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 * This is the word from the X-consortium.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 result = (XSendEvent (dpy, dest_win, False, (1L<<25)-1L,&ev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ? Qt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 XFlush (dpy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 * These duplicate the needed functionality from the Epoch event handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 read_client_message (struct device *d, XClientMessageEvent *cm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 Lisp_Object result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 Lisp_Object device = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 XSETDEVICE (device, d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 if (!cm->format) /* this is probably a sign of a bug somewhere else */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 result = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 result = Fcons (make_x_resource (cm->message_type, XA_ATOM, device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 Fcons (make_x_resource (cm->window, XA_WINDOW, device),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 convert_x_to_elisp (d, (void *) cm->data.b,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (20*8)/cm->format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 cm->message_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 cm->format)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 read_property_event (XPropertyEvent *pe, Lisp_Object frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 Lisp_Object result, value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 struct frame *f = XFRAME (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 struct device *d = XDEVICE (FRAME_DEVICE (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 Lisp_Object atom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 atom = x_atom_to_symbol (d, pe->atom);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 /* didn't get a name, blow this one off */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 if (NILP (atom))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 /* We can't use Fx_id_of_frame because it returns the xid of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 the shell widget. But the property change has to take place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 on the edit widget in order for a PropertyNotify event to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 be generated */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 value = raw_get_property (d, XtWindow (FRAME_X_TEXT_WIDGET (f)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 pe->atom);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 result = Fcons (Fsymbol_name (atom), value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 void dispatch_epoch_event (struct frame *f, XEvent *event, Lisp_Object type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 dispatch_epoch_event (struct frame *f, XEvent *event, Lisp_Object type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 struct Lisp_Vector *evp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 struct device *d = XDEVICE (FRAME_DEVICE (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 if (NILP (Vepoch_event_handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 if (!VECTORP (Vepoch_event) || XVECTOR (Vepoch_event)->size < 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 Vepoch_event = Fmake_vector (make_int (3), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 evp = XVECTOR (Vepoch_event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 XSETFRAME (evp->contents[2], f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 if (EQ (type, Qx_property_change))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 evp->contents[0] = Qx_property_change;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 evp->contents[1] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 read_property_event (&event->xproperty, evp->contents[2]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 else if (EQ (type, Qx_client_message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 evp->contents[0] = Qx_client_message;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 evp->contents[1] = read_client_message (d, &event->xclient);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 else if (EQ (type, Qx_map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 evp->contents[0] = Qx_map;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 evp->contents[1] = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 else if (EQ (type, Qx_unmap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 evp->contents[0] = Qx_unmap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 evp->contents[1] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 Vepoch_event = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 if (NILP (Vepoch_event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 Ffuncall (1, &Vepoch_event_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 Vepoch_event = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 syms_of_epoch (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 defsubr (&Sx_intern_atom);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 defsubr (&Sx_atom_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 defsubr (&Sstring_to_x_resource);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 defsubr (&Sx_resource_to_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 defsubr (&Sx_resource_to_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 defsubr (&Sx_id_of_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 defsubr (&Sx_query_tree);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 defsubr (&Sx_get_property);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 defsubr (&Sx_set_property);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 defsubr (&Sx_send_client_message);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 defsubr (&Sx_resource_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 defsubr (&Sx_resource_device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 defsubr (&Sx_resource_live_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 defsubr (&Sset_x_resource_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 defsymbol (&Qx_resourcep, "x-resource-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 defsymbol (&Qx_resource_live_p, "x-resource-live-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 defsymbol (&Qx_property_change, "x-property-change");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 defsymbol (&Qx_client_message, "x-client-message");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 defsymbol (&Qx_map, "x-map");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 defsymbol (&Qx_unmap, "x-unmap");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 vars_of_epoch (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 Fprovide (intern ("epoch"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 DEFVAR_LISP ("epoch-event-handler", &Vepoch_event_handler /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 If this variable is not nil, then it is assumed to have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 a function in it. When an epoch event is received for a frame, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 function is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 Vepoch_event_handler = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 DEFVAR_LISP ("epoch-event", &Vepoch_event /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 Bound to the value of the current event when epoch-event-handler is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 Vepoch_event = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 }