148f151997-12-25Niels Möller /* Requests.pike */
8569ae1998-04-06Niels Möller /*
01ba811998-04-19Henrik Grubbström (Grubba)  * Protocols.X, a Pike interface to the X Window System
8569ae1998-04-06Niels Möller  *
c092662002-01-15Martin Nilsson  * See COPYRIGHT for copyright information.
8569ae1998-04-06Niels Möller  * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software
3524712015-05-26Martin Nilsson  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8569ae1998-04-06Niels Möller  */
a095812014-08-06Per Hedbor  //! Varios X11 on-wire requests
a580e12000-09-27Fredrik Hübinette (Hubbe) #pike __REAL_VERSION__
a20af62000-09-26Fredrik Hübinette (Hubbe) 
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller class request {
a319071998-01-08Niels Möller  constant reqType = 0;
e045f11997-12-30Per Hedbor // constant expect_reply = 0;
148f151997-12-25Niels Möller 
67fb321997-12-29Niels Möller  array build_value_list(mapping m, array(string) fields)
148f151997-12-25Niels Möller  { int mask = 0; int bit = 1; array v = ({ }); foreach(fields, string f) {
65340d2014-08-15Martin Nilsson  if (has_index(m, f))
148f151997-12-25Niels Möller  {
8df2d81997-12-27Niels Möller  v += ({ objectp(m[f]) ? m[f]->id : m[f] });
148f151997-12-25Niels Möller  mask |= bit;
e045f11997-12-30Per Hedbor // werror(sprintf("Request->build_value_list: field %s, mask = %x\n", // f, mask));
148f151997-12-25Niels Möller  } bit <<= 1; }
67fb321997-12-29Niels Möller  return ({ mask, sprintf("%@4c", v) });
148f151997-12-25Niels Möller  } string build_request(string req, void|int data) {
aeed4f1998-04-21Per Hedbor  req = ._Xlib.pad(req);
3524712015-05-26Martin Nilsson 
89ed8c1998-01-04Per Hedbor  // Big requests extension. Will not work // if this extension is not present.
ead9722003-01-20Martin Nilsson  if((sizeof(req)+1) > (65535*4)) return sprintf("%c%c\0\0%4c%s", reqType, data, 1 + sizeof(req) / 4, req); return sprintf("%c%c%2c%s", reqType, data, 1 + sizeof(req) / 4, req);
148f151997-12-25Niels Möller  }
a319071998-01-08Niels Möller  mixed handle_reply(mapping reply)
148f151997-12-25Niels Möller  { error("Xlib.request: unexpected reply!\n"); return 0; }
e045f11997-12-30Per Hedbor 
a319071998-01-08Niels Möller  mixed handle_error(mapping reply)
e045f11997-12-30Per Hedbor  { error("Xlib.request: unexpected reply!\n"); return 0; }
148f151997-12-25Niels Möller }
e1a0bf1998-02-12Per Hedbor class FreeRequest
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit request;
a095812014-08-06Per Hedbor 
e1a0bf1998-02-12Per Hedbor  int id;
a095812014-08-06Per Hedbor  //!
e1a0bf1998-02-12Per Hedbor  string to_string() { return build_request(sprintf("%4c", id)); } } class CloseFont
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit FreeRequest; constant reqType=46; } class FreePixmap
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit FreeRequest; constant reqType=54; } class FreeGC
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit FreeRequest; constant reqType=60; } class FreeColormap
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit FreeRequest; constant reqType=79; } class FreeCursor
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit FreeRequest; constant reqType=95; } class FreeColors
a095812014-08-06Per Hedbor //!
e1a0bf1998-02-12Per Hedbor { inherit request; constant reqType=79;
a095812014-08-06Per Hedbor 
e1a0bf1998-02-12Per Hedbor  array colors; int colormap; int plane_mask;
a095812014-08-06Per Hedbor  //!
e1a0bf1998-02-12Per Hedbor  string to_string() { return sprintf("%4c%4c%{%4c%}", colormap,plane_mask,colors); } }
148f151997-12-25Niels Möller class ResourceReq
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller { inherit request; int id; string to_string() { return build_request(sprintf("%4c", id)); } } class CreateWindow
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 1;
148f151997-12-25Niels Möller  int depth;
a095812014-08-06Per Hedbor  //!
3524712015-05-26Martin Nilsson 
148f151997-12-25Niels Möller  int wid; int parent;
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  int x, y; int width, height, borderWidth;
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  int c_class; int visual;
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  mapping attributes = ([ ]);
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  string to_string() { return build_request
67fb321997-12-29Niels Möller  (sprintf("%4c%4c" "%2c%2c" "%2c%2c%2c" "%2c%4c" "%4c%s",
148f151997-12-25Niels Möller  wid, parent, x, y, width, height, borderWidth, c_class, visual,
aeed4f1998-04-21Per Hedbor  @build_value_list(attributes, ._Xlib.window_attributes) ),
148f151997-12-25Niels Möller  depth); } } class ChangeWindowAttributes
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 2;
148f151997-12-25Niels Möller  int window; mapping attributes = ([ ]);
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  string to_string() { return build_request
67fb321997-12-29Niels Möller  (sprintf("%4c%4c%s", window, @build_value_list(attributes,
aeed4f1998-04-21Per Hedbor  ._Xlib.window_attributes)));
148f151997-12-25Niels Möller  } } class MapWindow
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller { inherit ResourceReq;
a319071998-01-08Niels Möller  constant reqType = 8;
148f151997-12-25Niels Möller }
a24db61997-12-26Niels Möller 
c285b71998-02-05Marcus Comstedt class UnmapWindow
a095812014-08-06Per Hedbor //!
c285b71998-02-05Marcus Comstedt { inherit ResourceReq; constant reqType = 10; }
e045f11997-12-30Per Hedbor class GetKeyboardMapping
a095812014-08-06Per Hedbor //!
e045f11997-12-30Per Hedbor { inherit request;
a319071998-01-08Niels Möller  constant reqType = 101;
a095812014-08-06Per Hedbor 
e045f11997-12-30Per Hedbor  int first=0; int num=0;
a095812014-08-06Per Hedbor  //!
e045f11997-12-30Per Hedbor  string to_string() { return build_request( sprintf("%c%c\0\0", first, num) ); } mixed handle_reply(mapping reply) { int nkc = (reply->data1-4)*4; string format; if(nkc>0) format = "%4c%4c%4c%4c%*"+nkc+"c%s"; else if(!nkc) format = "%4c%4c%4c%4c%s"; else if(nkc==-4) format = "%4c%4c%4c%s"; else if(nkc==-8) format = "%4c%4c%s"; else if(nkc==-16) format = "%4c%s"; array res = allocate(256); reply->rest = reply->rest[24..]; // ? for(int i=first; i<num+first; i++) { array foo = allocate(4); sscanf(reply->rest, format, foo[0],foo[1],foo[2],foo[3],reply->rest); if(foo[3]==foo[2] && !foo[2]) foo = foo[..1]+foo[..1]; res[i]=replace(foo, 0,((foo-({0}))+({0}))[0]); } return res; } mixed handle_error(string reply) { error("Xlib.request: unexpected reply!\n"); return 0; } }
67fb321997-12-29Niels Möller class ConfigureWindow
a095812014-08-06Per Hedbor //!
67fb321997-12-29Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 12;
67fb321997-12-29Niels Möller  int window;
a095812014-08-06Per Hedbor 
67fb321997-12-29Niels Möller  mapping attributes;
a095812014-08-06Per Hedbor  //!
67fb321997-12-29Niels Möller  string to_string() { return build_request (sprintf("%4c%2c\0\0%s", window, @build_value_list(attributes,
aeed4f1998-04-21Per Hedbor  ._Xlib.window_configure_attributes)));
67fb321997-12-29Niels Möller  } }
a319071998-01-08Niels Möller class InternAtom
a095812014-08-06Per Hedbor //!
a319071998-01-08Niels Möller { inherit request; constant reqType = 16; int onlyIfExists; string name;
a095812014-08-06Per Hedbor  //!
a319071998-01-08Niels Möller  string to_string() {
ead9722003-01-20Martin Nilsson  return build_request(sprintf("%2c\0\0%s", sizeof(name), name),
a319071998-01-08Niels Möller  onlyIfExists); } mixed handle_reply(mapping reply) { int id; sscanf(reply->rest, "%4c", id); return id; } mixed handle_error(mapping reply) { switch(reply->errorCode) { case "Value": case "Alloc": return reply; default: error(sprintf("Requests.InternAtom->handle_error: " "Unexpected error '%s'\n", reply->errorCode)); } } } class GetAtomName
a095812014-08-06Per Hedbor //!
a319071998-01-08Niels Möller { inherit request; constant reqType = 17; int atom;
a095812014-08-06Per Hedbor  //!
a319071998-01-08Niels Möller  string to_string() { return build_request(sprintf("%4c", atom)); } string handle_reply(mapping reply) { int length; sscanf(reply->rest, "%2c", length); return reply->rest[24..23+length]; } mapping handle_error(mapping reply) { if (reply->errorCode != "Atom") error(sprintf("Requests.GetAtomName->handle_error: " "Unexpected error '%s'\n", reply->errorCode)); return reply; } } class ChangeProperty
a095812014-08-06Per Hedbor //!
a319071998-01-08Niels Möller { inherit request; constant reqType = 18; int mode = 0; int window; int property; int type; int format; string|array(int) data;
a095812014-08-06Per Hedbor  //!
a319071998-01-08Niels Möller  string to_string() { string p; switch(format) { case 8: p = data; break; case 16: p = sprintf("%@2c", data); break; case 32: p = sprintf("%@4c", data); break; default: error(sprintf("Requests.ChangeProperty: Unexpected format %d\n", format)); } return build_request(sprintf("%4c%4c%4c" "%c\0\0\0" "%4c%s", window, property, type, format, sizeof(data), p), mode); } } class DeleteProperty
a095812014-08-06Per Hedbor //!
a319071998-01-08Niels Möller { inherit request; constant reqType = 19; int window; int property;
a095812014-08-06Per Hedbor  //!
a319071998-01-08Niels Möller  string to_string() { return build_request(sprintf("%4c%4c", window, property)); } } class GetProperty
a095812014-08-06Per Hedbor //!
a319071998-01-08Niels Möller { inherit request; constant reqType = 20; int delete; int window; int property; int type;
22f32a1998-01-10Niels Möller  int longOffset = 0; int longLength = 1024;
a095812014-08-06Per Hedbor  //!
a319071998-01-08Niels Möller  string to_string() {
22f32a1998-01-10Niels Möller  return build_request(sprintf("%4c%4c%4c" "%4c%4c",
a319071998-01-08Niels Möller  window, property, type, longOffset, longLength), delete); } mapping handle_reply(mapping reply) { mapping m = ([ "format" : reply->data1 ]); int length;
3524712015-05-26Martin Nilsson 
a319071998-01-08Niels Möller  sscanf(reply->rest, "%4c%4c%4c", m->type, m->bytesAfter, length);
3524712015-05-26Martin Nilsson 
14ba431998-01-12Niels Möller  /* Match and Property errors (as in rfc-1013) are not used, * according to the official specification. For non-existent * properties, format == 0 is returned. * * If types doesn't match, format is non-zero, the actual type is * returned, but the data is empty (length = 0). */
3524712015-05-26Martin Nilsson 
14ba431998-01-12Niels Möller  if ( (!m->format) || (type && (type != m->type))) return 0;
a319071998-01-08Niels Möller  switch(m->format) { case 8: m->data = reply->rest[24..23+length]; break; case 16: { m->data = allocate(length); for (int i = 0; i<length; i++) sscanf(reply->rest[24+2*i..25+2*i], "%2c", m->data[i]); break; } case 32: { m->data = allocate(length); for (int i = 0; i<length; i++)
22f32a1998-01-10Niels Möller  sscanf(reply->rest[24+4*i..27+4*i], "%4c", m->data[i]);
a319071998-01-08Niels Möller  break; } default: error(sprintf("Requests.GetProperty->handle_reply: " "Unexpected format %d\n", reply->data1)); } return m; } mixed handle_error(mapping reply) { /* If the propert is non-existant, of * unexpected type, or too short, return 0 */ switch (reply->errorCode) { case "Value": return 0; case "Atom": case "Window": return reply; default: error(sprintf("Requests.GetProperty->handle_error: " "Unexpected error '%s'\n", reply->errorCode));
3524712015-05-26Martin Nilsson 
a319071998-01-08Niels Möller  } } } class ListProperties
a095812014-08-06Per Hedbor //!
a319071998-01-08Niels Möller { inherit request; constant reqType = 21; int window;
a095812014-08-06Per Hedbor  //!
a319071998-01-08Niels Möller  string to_string() { return build_request(sprintf("%4c", window)); } array handle_reply(mapping reply) { int length; sscanf(reply->rest, "%2c", length); array a = allocate(length); for (int i = 0; i<length; i++) sscanf(reply->rest[24+4*i..27+4*i], "%4c", a[i]); return a; } mapping handle_error(mapping reply) { switch (reply->errorCode) { case "Window": return reply; default: error(sprintf("Requests.ListProperties->handle_reply: " "Unexpected error '%s'\n", reply->errorCode)); } } }
4765ee1998-01-11Niels Möller #if 0 class GrabPointer { inherit request; constant reqType = 26; } class UnGrabPointer { inherit request; constant reqType = 27; } #endif class GrabButton
a095812014-08-06Per Hedbor //!
4765ee1998-01-11Niels Möller { inherit request; constant reqType = 28; int ownerEvents; int grabWindow; int eventMask; int pointerMode; int keyboardMode; int confineTo; int cursor; int button; int modifiers;
a095812014-08-06Per Hedbor  //!
4765ee1998-01-11Niels Möller  string to_string() { return build_request(sprintf("%4c%2c" "%c%c" "%4c%4c%c\0%2c", grabWindow, eventMask, pointerMode, keyboardMode, confineTo, cursor, button, modifiers), ownerEvents); } } #if 0 class UnGrabButton { inherit request; constant reqType = 29; } #endif
c285b71998-02-05Marcus Comstedt class OpenFont
a095812014-08-06Per Hedbor //!
c285b71998-02-05Marcus Comstedt { inherit request; constant reqType = 45; int fid; string name;
a095812014-08-06Per Hedbor  //!
c285b71998-02-05Marcus Comstedt  string to_string() { return build_request(sprintf("%4c%2c\0\0%s", fid, sizeof(name), name)); } } class QueryTextExtents
a095812014-08-06Per Hedbor //!
c285b71998-02-05Marcus Comstedt { inherit request; constant reqType = 48; int font; string str;
a095812014-08-06Per Hedbor  //!
c285b71998-02-05Marcus Comstedt  string to_string() { return build_request(sprintf("%4c%s", font, str), (sizeof(str)/2)&1); } mapping(string:int) handle_reply(mapping reply) { mapping(string:int) res = (["DrawDirection":reply->data1]); sscanf(reply->rest, "%2c%2c%2c%2c%4c%4c%4c", res->FontAscent, res->FontDescent, res->OverallAscent, res->OverallDescent, res->OverallWidth, res->OverallLeft, res->OverallRight); return res; } } class CreatePixmap
a095812014-08-06Per Hedbor  //!
c285b71998-02-05Marcus Comstedt { inherit request; constant reqType = 53; int depth;
a095812014-08-06Per Hedbor  //!
3524712015-05-26Martin Nilsson 
c285b71998-02-05Marcus Comstedt  int pid; int drawable;
a095812014-08-06Per Hedbor  //!
c285b71998-02-05Marcus Comstedt  int width, height;
a095812014-08-06Per Hedbor  //!
c285b71998-02-05Marcus Comstedt  string to_string() { return build_request (sprintf("%4c%4c" "%2c%2c", pid, drawable, width, height), depth); } }
a24db61997-12-26Niels Möller class CreateGC
a095812014-08-06Per Hedbor //!
a24db61997-12-26Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 55;
a24db61997-12-26Niels Möller 
8df2d81997-12-27Niels Möller  int gc;
a24db61997-12-26Niels Möller  int drawable; mapping attributes = ([ ]);
a095812014-08-06Per Hedbor  //!
a24db61997-12-26Niels Möller  string to_string() {
67fb321997-12-29Niels Möller  return build_request(sprintf("%4c%4c%4c%s", gc, drawable, @build_value_list(attributes,
aeed4f1998-04-21Per Hedbor  ._Xlib.gc_attributes)));
a24db61997-12-26Niels Möller  } }
8df2d81997-12-27Niels Möller class ChangeGC
a095812014-08-06Per Hedbor //!
8df2d81997-12-27Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 56;
8df2d81997-12-27Niels Möller  int gc; mapping attributes;
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  string to_string() {
3524712015-05-26Martin Nilsson  return build_request(sprintf("%4c%4c%s", gc,
67fb321997-12-29Niels Möller  @build_value_list(attributes,
aeed4f1998-04-21Per Hedbor  ._Xlib.gc_attributes)));
8df2d81997-12-27Niels Möller  } }
a06feb1998-01-12Niels Möller class ClearArea
a095812014-08-06Per Hedbor //!
a06feb1998-01-12Niels Möller { inherit request; constant reqType = 61; int exposures; int window; int x, y; int width, height;
a095812014-08-06Per Hedbor  //!
a06feb1998-01-12Niels Möller  string to_string() { return build_request(sprintf("%4c%2c%2c%2c%2c", window, x, y, width, height), exposures); } }
67fb321997-12-29Niels Möller class PolyPoint
a095812014-08-06Per Hedbor //!
67fb321997-12-29Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 64;
67fb321997-12-29Niels Möller  int coordMode; int drawable; int gc; array(object) points;
a095812014-08-06Per Hedbor  //!
3524712015-05-26Martin Nilsson 
67fb321997-12-29Niels Möller  string to_string() { return build_request(sprintf("%4c%4c%@s", drawable, gc, points->to_string()), coordMode); } } class PolyLine
a095812014-08-06Per Hedbor //!
67fb321997-12-29Niels Möller { inherit PolyPoint;
a319071998-01-08Niels Möller  constant reqType = 65;
67fb321997-12-29Niels Möller }
8df2d81997-12-27Niels Möller class FillPoly
a095812014-08-06Per Hedbor //!
8df2d81997-12-27Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 69;
8df2d81997-12-27Niels Möller  int drawable; int gc; int shape; int coordMode;
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  array points;
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  string to_string() { return build_request(sprintf("%4c%4c%c%c%2c%@s", drawable, gc, shape, coordMode, 0, points->to_string())); } }
a24db61997-12-26Niels Möller  class PolyFillRectangle
a095812014-08-06Per Hedbor //!
a24db61997-12-26Niels Möller { inherit request;
a319071998-01-08Niels Möller  constant reqType = 70;
a24db61997-12-26Niels Möller  int drawable;
8df2d81997-12-27Niels Möller  int gc;
a095812014-08-06Per Hedbor  //!
a24db61997-12-26Niels Möller  array rectangles;
a095812014-08-06Per Hedbor  //!
a24db61997-12-26Niels Möller  string to_string() {
3827d31998-01-10Per Hedbor  return build_request(sprintf("%4c%4c%s", drawable, gc, rectangles->to_string()*""));
a24db61997-12-26Niels Möller  } }
8f90db1998-01-01Per Hedbor  class PutImage
a095812014-08-06Per Hedbor //!
8f90db1998-01-01Per Hedbor { inherit request;
a319071998-01-08Niels Möller  constant reqType = 72;
a095812014-08-06Per Hedbor 
8f90db1998-01-01Per Hedbor  int drawable; int gc;
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  int depth; int width; int height; int dst_x; int dst_y; int left_pad = 0; int format = 2; // Bitmap XYPixmap ZPixmap
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  string data;
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  string to_string() {
52b62b1998-02-05Marcus Comstedt  // werror(sprintf("PutImage>to_string: %d, %d, %d, %d\n", // dst_x, dst_y, width, height));
3827d31998-01-10Per Hedbor  string pad="";
ead9722003-01-20Martin Nilsson  while(((sizeof(data)+sizeof(pad))%4)) pad += "\0";
8f90db1998-01-01Per Hedbor  pad = build_request(sprintf("%4c" "%4c"
e150f21998-01-12Niels Möller  "%2c" "%2c" "%2c" "%2c" "%c" "%c" "\0\0" "%s%s",
8f90db1998-01-01Per Hedbor  drawable, gc, width, height, dst_x, dst_y, left_pad, depth, data,pad), format); data=0; return pad; }
3524712015-05-26Martin Nilsson 
8f90db1998-01-01Per Hedbor }
c285b71998-02-05Marcus Comstedt class ImageText8
a095812014-08-06Per Hedbor //!
c285b71998-02-05Marcus Comstedt { inherit request; constant reqType = 76; int drawable; int gc; int x, y; string str;
a095812014-08-06Per Hedbor  //!
c285b71998-02-05Marcus Comstedt  string to_string() { return build_request(sprintf("%4c%4c%2c%2c%s", drawable, gc, x, y, str), sizeof(str)); } }
f34aac1998-02-09Marcus Comstedt class ImageText16
a095812014-08-06Per Hedbor //!
f34aac1998-02-09Marcus Comstedt { inherit request; constant reqType = 77; int drawable; int gc; int x, y; string str;
a095812014-08-06Per Hedbor  //!
f34aac1998-02-09Marcus Comstedt  string to_string() { return build_request(sprintf("%4c%4c%2c%2c%s", drawable, gc, x, y, str), sizeof(str)/2); } }
8f90db1998-01-01Per Hedbor class CreateColormap
a095812014-08-06Per Hedbor //!
8f90db1998-01-01Per Hedbor { inherit request;
a319071998-01-08Niels Möller  constant reqType = 78;
8f90db1998-01-01Per Hedbor  int cid; int alloc;
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  int window; int visual;
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  string to_string() { return build_request(sprintf("%4c%4c%4c", cid, window, visual), alloc); } }
a095812014-08-06Per Hedbor class Bell //! {
f4b9641998-02-11David Hedbor  inherit request; constant reqType = 104;
a095812014-08-06Per Hedbor 
8f72df1998-02-12Niels Möller  int percent;
a095812014-08-06Per Hedbor  //!
f4b9641998-02-11David Hedbor 
8f72df1998-02-12Niels Möller  string to_string() { return build_request("", percent); }
f4b9641998-02-11David Hedbor }
abec7c1998-02-28Per Hedbor class CopyArea
a095812014-08-06Per Hedbor //!
abec7c1998-02-28Per Hedbor { inherit request; constant reqType = 62;
a095812014-08-06Per Hedbor 
abec7c1998-02-28Per Hedbor  object gc; object area; object src, dst;
3524712015-05-26Martin Nilsson  int x,y;
a095812014-08-06Per Hedbor  //!
abec7c1998-02-28Per Hedbor  string to_string() { return build_request(sprintf("%4c" "%4c" "%4c" "%2c%2c" "%2c%2c" "%2c%2c", src->id, dst->id, gc->id, area->x, area->y, x, y, area->width, area->height)); } } class CopyPlane
a095812014-08-06Per Hedbor //!
abec7c1998-02-28Per Hedbor { inherit CopyArea; constant reqType = 63;
a095812014-08-06Per Hedbor 
abec7c1998-02-28Per Hedbor  int plane;
a095812014-08-06Per Hedbor  //!
abec7c1998-02-28Per Hedbor  string to_string() { return ::to_string()+sprintf("%4c", plane); } }
8f90db1998-01-01Per Hedbor class AllocColor
a095812014-08-06Per Hedbor //!
8f90db1998-01-01Per Hedbor { inherit request;
a319071998-01-08Niels Möller  constant reqType = 84;
a095812014-08-06Per Hedbor 
8f90db1998-01-01Per Hedbor  int red, green, blue; int colormap;
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  string to_string() {
3524712015-05-26Martin Nilsson  return build_request(sprintf("%4c%2c%2c%2c\0\0",
8f90db1998-01-01Per Hedbor  colormap, red, green, blue )); } mixed handle_reply(mapping reply) { int pixel, r, g, b; sscanf(reply->rest, "%2c%2c%2c%*2c%4c", r, g, b, pixel); return ([ "pixel":pixel, "red":r, "green":g, "blue":b ]); } mixed handle_error(string reply) { return 0; } }
89ed8c1998-01-04Per Hedbor 
f2a9a21998-02-09Marcus Comstedt class CreateGlyphCursor
a095812014-08-06Per Hedbor //!
f2a9a21998-02-09Marcus Comstedt { inherit request; constant reqType = 94; int cid; int sourcefont, maskfont; int sourcechar, maskchar; int forered, foregreen, foreblue; int backred, backgreen, backblue;
a095812014-08-06Per Hedbor  //!
f2a9a21998-02-09Marcus Comstedt  string to_string() { return build_request(sprintf("%4c%4c%4c%2c%2c%2c%2c%2c%2c%2c%2c", cid, sourcefont, maskfont, sourcechar, maskchar, forered, foregreen, foreblue, backred, backgreen, backblue)); } }
89ed8c1998-01-04Per Hedbor class QueryExtension
a095812014-08-06Per Hedbor //!
89ed8c1998-01-04Per Hedbor { inherit request;
a319071998-01-08Niels Möller  constant reqType = 98;
a095812014-08-06Per Hedbor 
89ed8c1998-01-04Per Hedbor  string name;
a095812014-08-06Per Hedbor  //!
89ed8c1998-01-04Per Hedbor  void create(string n) { name = n; }
a095812014-08-06Per Hedbor 
89ed8c1998-01-04Per Hedbor  string to_string() { string pad="";
ead9722003-01-20Martin Nilsson  while(((sizeof(name)+sizeof(pad))%4)) pad += "\0"; return build_request(sprintf("%2c\0\0%s%s", sizeof(name),name,pad));
89ed8c1998-01-04Per Hedbor  } mapping handle_reply(mapping reply) { int present, major, event, error_code; sscanf(reply->rest, "%c%c%c%c", present, major, event, error_code); if(present) return ([ "major":major, "event":event, "error":error_code ]); } mixed handle_error(string reply) { return 0; } } class ExtensionRequest
a095812014-08-06Per Hedbor //! Base class used by extensions
89ed8c1998-01-04Per Hedbor { int type; int code; string data; function handle_reply; function handle_error;
a095812014-08-06Per Hedbor  //!
89ed8c1998-01-04Per Hedbor  array build_value_list(mapping m, array(string) fields) { int mask = 0; int bit = 1; array v = ({ }); foreach(fields, string f) {
65340d2014-08-15Martin Nilsson  if (has_index(m, f))
89ed8c1998-01-04Per Hedbor  { v += ({ objectp(m[f]) ? m[f]->id : m[f] }); mask |= bit; } bit <<= 1; } return ({ mask, sprintf("%@4c", v) }); } string build_request(string req, void|int data) {
ead9722003-01-20Martin Nilsson  return sprintf("%c%c%2c%s", type, data, 1 + sizeof(req) / 4, req);
89ed8c1998-01-04Per Hedbor  } // End preamble..
52b62b1998-02-05Marcus Comstedt  void create( int|void m, function|void reply_handler, function|void error_handler )
89ed8c1998-01-04Per Hedbor  { type = m; handle_reply = reply_handler; handle_error = error_handler; } string to_string() { string pad =""; if(!data) data = "";
ead9722003-01-20Martin Nilsson  else while((sizeof(data)+sizeof(pad))%4) pad += "\0";
89ed8c1998-01-04Per Hedbor  return build_request(data+pad, code); }
3524712015-05-26Martin Nilsson 
89ed8c1998-01-04Per Hedbor }