1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/* xmove
* -----
* A Pseudoserver For Client Mobility
*
* Copyright (c) 1994 Ethan Solomita
*
* The X Consortium, and any party obtaining a copy of these files from
* the X Consortium, directly or indirectly, is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and
* documentation files (the "Software"), including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons who receive
* copies from any such party to do so. This license includes without
* limitation a license to do the foregoing actions under any patents of
* the party supplying this software to the X Consortium.
*/
#define NEED_REPLIES
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "xmove.h"
void GetWindowPropsState P((Window curwin, u_int *XGetPRep_cnt, xGetPropertyReply **XGetPRep));
Global void
XMOVEGetSetProps (Window oldwin,
Window newwin,
WindowMoveInfo *move_info,
Bool ForceWindowPosition,
int x,
int y,
int width,
int height)
{
u_int nGetPRep;
xGetPropertyReply *XGetPRep, *curGetPRep;
xChangePropertyReq XChaPReq;
unsigned char my_normal_hints[72];
unsigned char *PropValue;
Bool FoundNormalHints = False;
if (move_info) {
nGetPRep = move_info->nGetPRep;
XGetPRep = move_info->XGetPRep;
} else {
GetWindowPropsState(oldwin, &nGetPRep, &XGetPRep);
}
/* set-up XChaPReq constants */
XChaPReq.reqType = X_ChangeProperty;
XChaPReq.mode = 0;
ISetLong((unsigned char *)&XChaPReq.window, newwin);
curGetPRep = XGetPRep;
while (nGetPRep--) {
AtomPtr atom_ptr;
Atom atom, new_atom, map_atom, new_type, map_type;
Window map_win, conv_win;
void (*map_func)() = (void (*)())NULL;
atom = new_atom = (Atom)curGetPRep->pad1;
map_atom = MapAtom(atom, Server2Server);
atom_ptr = FindServerAtom(atom);
/* if atom_ptr is NULL, that means this property has neither been
created by this client nor has it been examined by this client.
Don't recreate a property created by others and never used by
this client! */
if (atom_ptr == NULL) {
if (!move_info)
free(*((char **)&curGetPRep->pad2));
curGetPRep++;
continue;
}
PropValue = *((u_char **)&curGetPRep->pad2);
new_type = ILong((unsigned char *)&curGetPRep->propertyType);
map_type = MapAtom(new_type, Server2Server);
/* if this is the NORMAL_HINTS property, and we need to force the
window's position, change the flags in the property to say that
the window's position was chosen by the user and not by the
client. The window manager SHOULD place the window as specified
if this is set. */
if (atom == XA_WM_NORMAL_HINTS && ForceWindowPosition) {
/* ISetLong(&PropValue[0], (ILong(&PropValue[0]) | USPosition) & ~(PPosition));*/
ISetLong(&PropValue[0], ILong(&PropValue[0]) | PPosition | USPosition);
ISetLong(&PropValue[4], x);
ISetLong(&PropValue[8], y);
ISetLong(&PropValue[12], width);
ISetLong(&PropValue[16], height);
FoundNormalHints = True;
}
map_win = newwin;
if (atom_ptr->property_map_func)
map_func = atom_ptr->property_map_func->MapProperty;
else {
atom_ptr = FindServerAtom(new_type);
if (atom_ptr && atom_ptr->type_map_func)
map_func = atom_ptr->type_map_func->MapProperty;
}
if (map_func) {
conv_win = oldwin;
(map_func)(MapMoveClientProps, &new_atom, &new_type, NULL,
atom_ptr, False, &conv_win, PropValue,
curGetPRep->format / 8 * ILong((unsigned char *)&curGetPRep->nItems));
if (new_atom != atom) /* if new_atom was changed */
map_atom = new_atom; /* use it instead of MapAtom() */
if (new_type != curGetPRep->propertyType)
map_type = new_type;
if (conv_win != oldwin)
map_win = conv_win;
}
XMOVEChangeProperty(new_fd, new_seqno, map_win, map_atom, map_type,
curGetPRep->format, PropModeReplace, PropValue,
ILong((unsigned char *)&curGetPRep->nItems));
if (!move_info)
free(PropValue);
curGetPRep++;
}
if (ForceWindowPosition && !FoundNormalHints) {
ISetLong(&my_normal_hints[0], USPosition);
ISetLong(&my_normal_hints[4], x);
ISetLong(&my_normal_hints[8], y);
ISetLong(&my_normal_hints[12], width);
ISetLong(&my_normal_hints[16], height);
XMOVEChangeProperty(new_fd, new_seqno, newwin,
XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32,
PropModeReplace, &my_normal_hints[0], 18);
}
if (!move_info)
free((char *) XGetPRep);
}
void
GetWindowPropsState(Window curwin, u_int *XGetPRep_cnt,
xGetPropertyReply **XGetPRep)
{
xResourceReq XListReq;
int PropCnt;
Atom *PropList;
xGetPropertyReply *curgprep;
xListPropertiesReply XListRep;
xGetPropertyReq XGetPReq;
/* First, a note. We use the XGetPRep.pad1 to hold the
* atom whose info is in XGetPRep, because the reply doesn't
* actually hold the atom. In XGetPRep.pad2 we place a
* pointer to the property's data. Both pad1 and pad2 are
* stored in xmove's native byte ordering. This isn't "proper"
* programming practice. So sue me!
*/
XListReq.reqType = X_ListProperties;
ISetShort((u_char *)&XListReq.length, 2);
ISetLong((u_char *)&XListReq.id, curwin);
/* send the XListProperties request to the server */
SendBuffer(cur_fd,
(unsigned char *) &XListReq,
sizeof(xResourceReq));
/* read back the reply header */
ReceiveReply(cur_fd, (unsigned char *) &XListRep,
sizeof(xListPropertiesReply), ++(*cur_seqno));
/* allocate space for the properties list and retrieve list */
*XGetPRep_cnt = PropCnt = IShort((u_char *)&XListRep.nProperties);
PropList = (Atom *) malloc(PropCnt * sizeof(Atom));
curgprep = *XGetPRep = (xGetPropertyReply *)
malloc(PropCnt * sizeof(**XGetPRep));
ReceiveBuffer(cur_fd, (u_char *)PropList,
IShort((u_char *)&XListRep.nProperties) * sizeof(Atom));
/* set-up XGetPReq constants*/
XGetPReq.reqType = X_GetProperty;
ISetShort((unsigned char *)&XGetPReq.length, 6);
XGetPReq.delete = False;
ISetLong((unsigned char *)&XGetPReq.window, curwin);
ISetLong((unsigned char *)&XGetPReq.type, 0);
ISetLong((unsigned char *)&XGetPReq.longOffset, 0);
ISetLong((unsigned char *)&XGetPReq.longLength, 1000000000); /* n, where n is VERY large */
while (PropCnt--) {
unsigned char *CurValue;
Atom atom;
atom = PropList[PropCnt];
ISetLong((unsigned char *)&XGetPReq.property, atom);
SendBuffer(cur_fd,
(unsigned char *) &XGetPReq,
sizeof(xGetPropertyReq));
ReceiveReply(cur_fd, (unsigned char *) curgprep, 32, ++(*cur_seqno));
CurValue = (u_char *) malloc(ILong((u_char *)&curgprep->length) << 2);
curgprep->pad1 = (u_long) atom;
*((u_char **)&curgprep->pad2) = CurValue;
ReceiveBuffer(cur_fd, CurValue, ILong((u_char *)&curgprep->length) << 2);
curgprep++;
}
free(PropList);
}
|