148f151997-12-25Niels Möller /* Types.pmod */
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  */
a580e12000-09-27Fredrik Hübinette (Hubbe) #pike __REAL_VERSION__
a20af62000-09-26Fredrik Hübinette (Hubbe) 
148f151997-12-25Niels Möller class XResource
a095812014-08-06Per Hedbor //! A resorce in the X-server //! Most will automatically free the resource in the server when all //! references is gone in your application
148f151997-12-25Niels Möller {
a095812014-08-06Per Hedbor 
148f151997-12-25Niels Möller  object display; int id;
e1a0bf1998-02-12Per Hedbor  int autofree = 1;
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  void create(object d, int i) { display = d; id = i;
563bd72004-01-11Martin Nilsson  display->remember_id(id, this);
148f151997-12-25Niels Möller  }
e1a0bf1998-02-12Per Hedbor 
ad25fd1998-04-18Per Hedbor  object FreeRequest() {}
a095812014-08-06Per Hedbor  //!
e1a0bf1998-02-12Per Hedbor  void Free() {
ad25fd1998-04-18Per Hedbor  object req = FreeRequest();
1450c31998-03-04Niels Möller  if (req)
ad25fd1998-04-18Per Hedbor  { req->id = id; display->send_request( req ); }
e1a0bf1998-02-12Per Hedbor  }
c071bc2017-11-05Henrik Grubbström (Grubba)  protected void _destruct()
e1a0bf1998-02-12Per Hedbor  { if(autofree) Free(); }
148f151997-12-25Niels Möller }
a2716c1998-02-05Marcus Comstedt class Font
a095812014-08-06Per Hedbor //!
a2716c1998-02-05Marcus Comstedt {
aeed4f1998-04-21Per Hedbor  import ".";
a2716c1998-02-05Marcus Comstedt  inherit XResource;
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  object QueryTextExtents_req(string str) { object req = Requests.QueryTextExtents(); req->font = id; req->str = str; return req; }
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  mapping(string:int) QueryTextExtents16(string str) { object req = QueryTextExtents_req(str); return display->blocking_request(req)[1]; }
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  mapping(string:int) QueryTextExtents(string str) { return QueryTextExtents16("\0"+str/""*"\0"); } object CloseFont_req() { object req = Requests.CloseFont(); req->id = id; return req; } void CloseFont() { object req = CloseFont_req(); display->send_request(req); }
a095812014-08-06Per Hedbor  //!
f2a9a21998-02-09Marcus Comstedt  object CreateGlyphCursor(int sourcechar, array(int)|void foreground, array(int)|void background) {
563bd72004-01-11Martin Nilsson  return display->CreateGlyphCursor(this, sourcechar, 0, 0,
f2a9a21998-02-09Marcus Comstedt  foreground, background); } } class Cursor
a095812014-08-06Per Hedbor //!
f2a9a21998-02-09Marcus Comstedt { inherit XResource;
aeed4f1998-04-21Per Hedbor  constant FreeRequest = .Requests.FreeCursor;
a2716c1998-02-05Marcus Comstedt }
148f151997-12-25Niels Möller class Visual
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller { inherit XResource;
3827d31998-01-10Per Hedbor  int depth;
a095812014-08-06Per Hedbor  //!
3827d31998-01-10Per Hedbor 
148f151997-12-25Niels Möller  int c_class; int bitsPerRGB; int colorMapEntries; int redMask; int greenMask; int blueMask;
a095812014-08-06Per Hedbor  //!
e1a0bf1998-02-12Per Hedbor  void create(mixed ... args) { ::create(@args); autofree=0; }
148f151997-12-25Niels Möller }
9046d11997-12-26Niels Möller  class GC
a095812014-08-06Per Hedbor //!
9046d11997-12-26Niels Möller { inherit XResource;
aeed4f1998-04-21Per Hedbor  constant FreeRequest = .Requests.FreeGC;
8df2d81997-12-27Niels Möller 
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  mapping(string:mixed) values;
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  object ChangeGC_req(mapping attributes) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ChangeGC();
8df2d81997-12-27Niels Möller  req->gc = id; req->attributes = attributes; return req; }
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  void ChangeGC(mapping attributes) { object req = ChangeGC_req(attributes); display->send_request(req);
a2716c1998-02-05Marcus Comstedt  values |= attributes; }
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  mapping(string:mixed) GetGCValues() { return values; } void create(mixed ... args) { ::create(@args);
aeed4f1998-04-21Per Hedbor  values = mkmapping(._Xlib.gc_attributes,
a2716c1998-02-05Marcus Comstedt  ({ 3, -1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 4, 1 }));
8df2d81997-12-27Niels Möller  }
9046d11997-12-26Niels Möller } class Rectangle
a095812014-08-06Per Hedbor //!
9046d11997-12-26Niels Möller { int x, y;
a095812014-08-06Per Hedbor  //!
9046d11997-12-26Niels Möller  int width, height;
a095812014-08-06Per Hedbor  //!
9046d11997-12-26Niels Möller  void create(int ... args) { switch(sizeof(args)) { case 0: x = y = width = height = 0; break; case 4: x = args[0]; y = args[1]; width = args[2]; height = args[3]; break; default: error("Types.Rectangle(): To many arguments.\n"); } }
e1a0bf1998-02-12Per Hedbor 
9046d11997-12-26Niels Möller  string to_string() { return sprintf("%2c%2c%2c%2c", x, y, width, height); } }
8df2d81997-12-27Niels Möller class Point
a095812014-08-06Per Hedbor //!
8df2d81997-12-27Niels Möller { int x, y;
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  void create(int ... args) { switch(sizeof(args)) { case 0: x = y = 0; break; case 2: x = args[0]; y = args[1]; break; default: error("Types.Point(): To many arguments.\n"); } } string to_string() { return sprintf("%2c%2c", x, y); } }
8f90db1998-01-01Per Hedbor class Colormap
a095812014-08-06Per Hedbor //!
8f90db1998-01-01Per Hedbor { inherit XResource;
aeed4f1998-04-21Per Hedbor  constant FreeRequest = .Requests.FreeColormap;
a095812014-08-06Per Hedbor  object visual;
8f90db1998-01-01Per Hedbor  mapping alloced = ([]);
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor 
e1a0bf1998-02-12Per Hedbor  object FreeColors_req(int pixel) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.FreeColors();
e1a0bf1998-02-12Per Hedbor  req->colormap = id; req->plane_mask=0; req->colors = ({ pixel }); return req; }
a095812014-08-06Per Hedbor  //!
e1a0bf1998-02-12Per Hedbor  void FreeColor( int pixel ) { display->send_request( FreeColors_req( pixel ) ); } void Free() { foreach(values(alloced), mapping f) FreeColor( f->pixel ); ::Free(); }
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  int AllocColor(int r, int g, int b) { if(alloced[sprintf("%2c%2c%2c", r, g, b)]) return alloced[sprintf("%2c%2c%2c", r, g, b)];
aeed4f1998-04-21Per Hedbor  object req = .Requests.AllocColor();
8f90db1998-01-01Per Hedbor  req->colormap = id; req->red = r; req->green = g; req->blue = b;
c1c2441998-01-08Niels Möller  array a = display->blocking_request( req );
3827d31998-01-10Per Hedbor  return a[0] && (alloced[sprintf("%2c%2c%2c", r, g, b)]=a[1]);
c1c2441998-01-08Niels Möller  }
8f90db1998-01-01Per Hedbor 
3827d31998-01-10Per Hedbor 
8f90db1998-01-01Per Hedbor  void create(object disp, int i, object vis) { display = disp; id = i; visual = vis; } }
1450c31998-03-04Niels Möller /* Kludge */ #define PIXMAP (_Types.get_pixmap_class())
8f90db1998-01-01Per Hedbor 
9046d11997-12-26Niels Möller class Drawable
a095812014-08-06Per Hedbor //!
148f151997-12-25Niels Möller { inherit XResource;
e1a0bf1998-02-12Per Hedbor  int depth; object colormap, parent, visual;
eef1161998-02-10Per Hedbor 
a095812014-08-06Per Hedbor  //!
abec7c1998-02-28Per Hedbor  object CopyArea_req(object gc, object src, object area, int x, int y) {
aeed4f1998-04-21Per Hedbor  object r= .Requests.CopyArea();
abec7c1998-02-28Per Hedbor  r->gc = gc; r->src = src; r->area = area;
563bd72004-01-11Martin Nilsson  r->dst = this;
abec7c1998-02-28Per Hedbor  r->x = x; r->y = y; return r; }
a095812014-08-06Per Hedbor  //!
abec7c1998-02-28Per Hedbor  object CopyArea(object gc, object src, object area, int x, int y) { display->send_request( CopyArea_req( gc,src,area,x,y )); }
a095812014-08-06Per Hedbor  //!
9046d11997-12-26Niels Möller  object CreateGC_req() {
aeed4f1998-04-21Per Hedbor  object req = .Requests.CreateGC();
9046d11997-12-26Niels Möller  req->drawable = id;
8df2d81997-12-27Niels Möller  req->gc = display->alloc_id();
9046d11997-12-26Niels Möller  return req; }
a095812014-08-06Per Hedbor  //!
9046d11997-12-26Niels Möller  object CreateGC(mapping|void attributes) { object req = CreateGC_req(); if (attributes) req->attributes = attributes; display->send_request(req);
8df2d81997-12-27Niels Möller  return GC(display, req->gc);
9046d11997-12-26Niels Möller  }
a095812014-08-06Per Hedbor  //!
52b62b1998-02-05Marcus Comstedt  object CreatePixmap_req(int width, int height, int depth) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.CreatePixmap();
52b62b1998-02-05Marcus Comstedt  req->pid = display->alloc_id(); req->drawable = id; req->width = width; req->height = height; req->depth = depth; return req; }
a095812014-08-06Per Hedbor  //!
52b62b1998-02-05Marcus Comstedt  object CreatePixmap(int width, int height, int depth) { object req = CreatePixmap_req(width, height, depth);
e1a0bf1998-02-12Per Hedbor  display->send_request( req );
563bd72004-01-11Martin Nilsson  object p = Pixmap(display, req->pid, this, colormap );
e1a0bf1998-02-12Per Hedbor  p->depth = depth; return p;
52b62b1998-02-05Marcus Comstedt  }
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  object FillPoly_req(int gc, int shape, int coordMode, array(object) p) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.FillPoly();
8df2d81997-12-27Niels Möller  req->drawable = id; req->gc = gc; req->shape = shape; req->coordMode = coordMode; req->points = p; return req; }
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  void FillPoly(object gc, int shape, int coordMode, array(object) points) { object req = FillPoly_req(gc->id, shape, coordMode, points); display->send_request(req); }
a2716c1998-02-05Marcus Comstedt 
a095812014-08-06Per Hedbor  //!
9046d11997-12-26Niels Möller  object FillRectangles_req(int gc, array(object) r) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.PolyFillRectangle();
9046d11997-12-26Niels Möller  req->drawable = id;
8df2d81997-12-27Niels Möller  req->gc = gc;
9046d11997-12-26Niels Möller  req->rectangles = r; return req; }
a095812014-08-06Per Hedbor  //!
9046d11997-12-26Niels Möller  void FillRectangles(object gc, object ... r) { object req = FillRectangles_req(gc->id, r); display->send_request(req); }
99b4901997-12-29Niels Möller 
a095812014-08-06Per Hedbor  //!
99b4901997-12-29Niels Möller  object DrawLine_req(int gc, int coordMode, array(object) points) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.PolyLine();
99b4901997-12-29Niels Möller  req->drawable = id; req->gc = gc; req->coordMode = coordMode; req->points = points; return req; }
a095812014-08-06Per Hedbor  //!
99b4901997-12-29Niels Möller  void DrawLine(object gc, int coordMode, object ... points) { display->send_request(DrawLine_req(gc->id, coordMode, points)); }
8f90db1998-01-01Per Hedbor 
a095812014-08-06Per Hedbor  //!
db95191998-01-12Niels Möller  object PutImage_req(object gc, int depth, int tx, int ty, int width, int height, string data)
8f90db1998-01-01Per Hedbor  {
aeed4f1998-04-21Per Hedbor  object r = .Requests.PutImage();
8f90db1998-01-01Per Hedbor  r->drawable = id; r->gc = gc->id; r->depth = depth; r->dst_x = tx; r->dst_y = ty; r->width = width; r->height = height; r->data = data;
db95191998-01-12Niels Möller  return r; }
3524712015-05-26Martin Nilsson 
a095812014-08-06Per Hedbor  //!
db95191998-01-12Niels Möller  void PutImage(object gc, int depth,
52b62b1998-02-05Marcus Comstedt  int tx, int ty, int width, int height, string data, int|void format)
db95191998-01-12Niels Möller  {
52b62b1998-02-05Marcus Comstedt  object req = PutImage_req(gc, depth, tx, ty, width, height, data); req->format = format;
eef1161998-02-10Per Hedbor  display->send_request( req );
8f90db1998-01-01Per Hedbor  }
a2716c1998-02-05Marcus Comstedt 
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  object ImageText8_req(int gc, int x, int y, string str) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ImageText8();
a2716c1998-02-05Marcus Comstedt  req->drawable = id; req->gc = gc; req->x = x; req->y = y; req->str = str; return req; }
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  void ImageText8(object gc, int x, int y, string str) { if(sizeof(str)>255) error("ImageText8: string to long\n"); object req = ImageText8_req(gc->id, x, y, str);
3524712015-05-26Martin Nilsson  display->send_request(req);
a2716c1998-02-05Marcus Comstedt  }
f34aac1998-02-09Marcus Comstedt 
a095812014-08-06Per Hedbor  //!
f34aac1998-02-09Marcus Comstedt  object ImageText16_req(int gc, int x, int y, string str) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ImageText16();
f34aac1998-02-09Marcus Comstedt  req->drawable = id; req->gc = gc; req->x = x; req->y = y; req->str = str; return req; }
a095812014-08-06Per Hedbor  //!
f34aac1998-02-09Marcus Comstedt  void ImageText16(object gc, int x, int y, string str) { if(sizeof(str)>510) error("ImageText16: string to long\n"); object req = ImageText16_req(gc->id, x, y, str);
3524712015-05-26Martin Nilsson  display->send_request(req);
f34aac1998-02-09Marcus Comstedt  }
9046d11997-12-26Niels Möller }
8f90db1998-01-01Per Hedbor 
89ed8c1998-01-04Per Hedbor class Pixmap
a095812014-08-06Per Hedbor //!
89ed8c1998-01-04Per Hedbor { inherit Drawable;
aeed4f1998-04-21Per Hedbor  constant FreeRequest = .Requests.FreePixmap;
52b62b1998-02-05Marcus Comstedt  // Init function. void create(mixed ... args) { ::create( @args ); if(sizeof(args)>2 && objectp(args[2])) parent = args[2];
eef1161998-02-10Per Hedbor  if(sizeof(args)>3 && objectp(args[3])) colormap = args[3];
52b62b1998-02-05Marcus Comstedt  }
89ed8c1998-01-04Per Hedbor }
9046d11997-12-26Niels Möller class Window
a095812014-08-06Per Hedbor //!
9046d11997-12-26Niels Möller {
12bfd42002-06-13H. William Welliver III  inherit .KeySyms;
9046d11997-12-26Niels Möller  inherit Drawable;
a095812014-08-06Per Hedbor 
148f151997-12-25Niels Möller  int currentInputMask;
a095812014-08-06Per Hedbor  //!
4cc73f1998-02-12Niels Möller  /* Keys are event names, values are arrays of ({ priority, function }) */
a095812014-08-06Per Hedbor  //!
4cc73f1998-02-12Niels Möller  mapping(string:array(array)) event_callbacks = ([ ]);
e045f11997-12-30Per Hedbor  string handle_keys(mapping evnt) { int code=evnt->detail, keysym; evnt->keycode = code; array keysymopts = display->key_mapping[ code ]; keysym = keysymopts[ alt_gr*2+shift ]; if( keysym )
dd0c951997-12-30Per Hedbor  {
e045f11997-12-30Per Hedbor  if(evnt->type == "KeyPress")
12bfd42002-06-13H. William Welliver III  evnt->data = LookupKeysym( keysym, display );
e045f11997-12-30Per Hedbor  else foreach(keysymopts, int k) ReleaseKey( k );
dd0c951997-12-30Per Hedbor  evnt->keysym = keysym; }
e045f11997-12-30Per Hedbor  }
3524712015-05-26Martin Nilsson 
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  object CreateWindow_req(int x, int y, int width, int height,
8f90db1998-01-01Per Hedbor  int border_width, int depth, object visual)
148f151997-12-25Niels Möller  {
aeed4f1998-04-21Per Hedbor  object req = .Requests.CreateWindow();
8f90db1998-01-01Per Hedbor  req->depth = depth; /* CopyFromParent */
148f151997-12-25Niels Möller  req->wid = display->alloc_id(); req->parent = id; req->x = x; req->y = y; req->width = width; req->height = height; req->borderWidth = border_width; req->c_class = 0 ; /* CopyFromParent */
8f90db1998-01-01Per Hedbor  req->visual = visual && visual->id;
148f151997-12-25Niels Möller  return req; }
563bd72004-01-11Martin Nilsson  this_program new(mixed ... args) /* Kludge */
148f151997-12-25Niels Möller  {
563bd72004-01-11Martin Nilsson  return this_program(@args);
148f151997-12-25Niels Möller  }
8df2d81997-12-27Niels Möller 
a095812014-08-06Per Hedbor  //!
8f90db1998-01-01Per Hedbor  object CreateColormap(object visual, int|void alloc) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.CreateColormap();
8f90db1998-01-01Per Hedbor  req->cid = display->alloc_id(); req->alloc = alloc; req->visual = visual->id; req->window = id; display->send_request(req); return Colormap(display, req->cid, visual); }
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  object CreateWindow(int x, int y, int width, int height,
4cc73f1998-02-12Niels Möller  int border_width, mapping|void attributes,
e1a0bf1998-02-12Per Hedbor  object|void visual, int|void d,
8f90db1998-01-01Per Hedbor  int|void c_class)
8df2d81997-12-27Niels Möller  { object req = CreateWindow_req(x, y, width, height,
e1a0bf1998-02-12Per Hedbor  border_width,d,visual);
eef1161998-02-10Per Hedbor  object c = colormap||parent->defaultColorMap;
8f90db1998-01-01Per Hedbor 
8df2d81997-12-27Niels Möller  if (attributes)
eef1161998-02-10Per Hedbor  {
8df2d81997-12-27Niels Möller  req->attributes = attributes;
eef1161998-02-10Per Hedbor  if(attributes->Colormap) c= attributes->Colormap;
ad25fd1998-04-18Per Hedbor  }
8f90db1998-01-01Per Hedbor 
8df2d81997-12-27Niels Möller  // object w = Window(display, req->wid);
4cc73f1998-02-12Niels Möller  // werror(sprintf("CreateWindowRequest: %s\n", // Crypto.string_to_hex(req->to_string())));
3524712015-05-26Martin Nilsson 
8f90db1998-01-01Per Hedbor  display->send_request(req);
563bd72004-01-11Martin Nilsson  object w = new(display, req->wid, visual, this); w->depth = d||depth||this->rootDepth;
eef1161998-02-10Per Hedbor  w->colormap = c;
8df2d81997-12-27Niels Möller  w->currentInputMask = req->attributes->EventMask;
1450c31998-03-04Niels Möller  w->attributes = attributes || ([]);
8df2d81997-12-27Niels Möller  return w; }
3524712015-05-26Martin Nilsson 
a095812014-08-06Per Hedbor  //!
8df2d81997-12-27Niels Möller  object CreateSimpleWindow(int x, int y, int width, int height,
eef1161998-02-10Per Hedbor  int border_width,int border, int background)
148f151997-12-25Niels Möller  {
8df2d81997-12-27Niels Möller  object req = CreateWindow_req(x, y, width, height,
8f90db1998-01-01Per Hedbor  border_width,0,0);
8df2d81997-12-27Niels Möller  req->attributes->BackPixel = background; req->attributes->BorderPixel = border;
148f151997-12-25Niels Möller  display->send_request(req);
3524712015-05-26Martin Nilsson 
148f151997-12-25Niels Möller  // object w = Window(display, req->wid);
563bd72004-01-11Martin Nilsson  object w = new(display, req->wid, 0, this);
3524712015-05-26Martin Nilsson 
148f151997-12-25Niels Möller  w->visual = visual; w->currentInputMask = 0; return w; }
a095812014-08-06Per Hedbor  //!
99b4901997-12-29Niels Möller  object ChangeAttributes_req(mapping m) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ChangeWindowAttributes();
99b4901997-12-29Niels Möller  req->window = id; req->attributes = m; return req; }
a095812014-08-06Per Hedbor  //!
99b4901997-12-29Niels Möller  void ChangeAttributes(mapping m) {
e1a0bf1998-02-12Per Hedbor  attributes |= m;
99b4901997-12-29Niels Möller  display->send_request(ChangeAttributes_req(m)); }
a095812014-08-06Per Hedbor  //!
99b4901997-12-29Niels Möller  object Configure_req(mapping m) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ConfigureWindow();
99b4901997-12-29Niels Möller  req->window = id; req->attributes = m;
4cc73f1998-02-12Niels Möller  // werror(sprintf("ConfigureRequest: %s\n", // Crypto.string_to_hex(req->to_string())));
99b4901997-12-29Niels Möller  return req; }
a095812014-08-06Per Hedbor  //!
99b4901997-12-29Niels Möller  void Configure(mapping m) { display->send_request(Configure_req(m)); }
a095812014-08-06Per Hedbor  //!
17f68b1998-02-08Marcus Comstedt  void Raise() { Configure((["StackMode":0])); }
a095812014-08-06Per Hedbor  //!
17f68b1998-02-08Marcus Comstedt  void Lower() { Configure((["StackMode":1])); }
4cc73f1998-02-12Niels Möller  /* Keep callbacks sorted by decreasing priority */
a095812014-08-06Per Hedbor  //!
4cc73f1998-02-12Niels Möller  void set_event_callback(string type, function f, int|void priority)
148f151997-12-25Niels Möller  {
4cc73f1998-02-12Niels Möller  event_callbacks[type] = reverse(sort((event_callbacks[type] || ({ }) ) + ({ ({ priority, f }) }) ));
148f151997-12-25Niels Möller  }
3524712015-05-26Martin Nilsson 
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  object SelectInput_req() {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ChangeWindowAttributes();
148f151997-12-25Niels Möller  req->window = id;
9046d11997-12-26Niels Möller  req->attributes->EventMask = currentInputMask;
e1a0bf1998-02-12Per Hedbor  attributes->EventMask = currentInputMask;
148f151997-12-25Niels Möller  return req; } int event_mask_to_int(array(string) masks) { int mask = 0;
3524712015-05-26Martin Nilsson 
148f151997-12-25Niels Möller  foreach(masks, string type) mask
aeed4f1998-04-21Per Hedbor  |= ._Xlib.event_masks[type];
148f151997-12-25Niels Möller  return mask; }
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  int SelectInput(string ... types) { // int old_mask = currentInputMask; currentInputMask |= event_mask_to_int(types); display->send_request(SelectInput_req()); return currentInputMask; }
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  int DeselectInput(string ... types) { // int old_mask = currentInputMask; currentInputMask &= ~event_mask_to_int(types); display->send_request(SelectInput_req()); return currentInputMask; }
a095812014-08-06Per Hedbor  //!
5603491998-01-11Niels Möller  object GrabButton_req(int button, int modifiers, array(string) types) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.GrabButton();
5603491998-01-11Niels Möller  req->ownerEvents = 1; req->grabWindow = id; req->eventMask = event_mask_to_int(types);
e531091998-01-11Niels Möller  // req->pointerMode = 1; // req->keyboardMode = 1;
5603491998-01-11Niels Möller  req->button = button; req->modifiers = modifiers || 0x8000;
3524712015-05-26Martin Nilsson 
5603491998-01-11Niels Möller  return req; }
a095812014-08-06Per Hedbor  //!
5603491998-01-11Niels Möller  void GrabButton(int button, int modifiers, string ... types) { object req = GrabButton_req(button, modifiers, types); display->send_request(req); }
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  object Map_req() {
aeed4f1998-04-21Per Hedbor  object req = .Requests.MapWindow();
148f151997-12-25Niels Möller  req->id = id; return req; }
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller  void Map() { display->send_request(Map_req()); }
e045f11997-12-30Per Hedbor 
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  object Unmap_req() {
aeed4f1998-04-21Per Hedbor  object req = .Requests.UnmapWindow();
a2716c1998-02-05Marcus Comstedt  req->id = id; return req; }
a095812014-08-06Per Hedbor  //!
a2716c1998-02-05Marcus Comstedt  void Unmap() { display->send_request(Unmap_req()); }
a095812014-08-06Per Hedbor  //!
c1c2441998-01-08Niels Möller  object ListProperties_req() {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ListProperties();
c1c2441998-01-08Niels Möller  req->window = id; return req; }
a095812014-08-06Per Hedbor  //!
c1c2441998-01-08Niels Möller  array ListProperties() { object req = ListProperties_req(); array a = display->blocking_request(req);
e045f11997-12-30Per Hedbor 
c1c2441998-01-08Niels Möller  if (!a[0]) return 0;
3524712015-05-26Martin Nilsson 
c1c2441998-01-08Niels Möller  a = a[1]; for(int i = 0; i<sizeof(a); i++) { object atom = display->lookup_atom(a[i]); if (!atom) return 0; a[i] = atom; } return a; }
27af0d1998-01-10Niels Möller 
a095812014-08-06Per Hedbor  //!
2b22011998-01-12Niels Möller  object ChangeProperty_req(object property, object type, int format, array(int)|string data) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ChangeProperty();
2b22011998-01-12Niels Möller  req->window = id; req->property = property->id; req->type = type->id; req->format = format; req->data = data; return req; }
a095812014-08-06Per Hedbor  //!
2b22011998-01-12Niels Möller  void ChangeProperty(object property, object type, int format, array(int)|string data) { display->send_request(ChangeProperty_req(property, type, format, data)); }
3524712015-05-26Martin Nilsson 
a095812014-08-06Per Hedbor  //!
27af0d1998-01-10Niels Möller  object GetProperty_req(object property, object|void type) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.GetProperty();
27af0d1998-01-10Niels Möller  req->window = id; req->property = property->id; if (type) req->type = type->id;
3524712015-05-26Martin Nilsson 
27af0d1998-01-10Niels Möller  return req; }
a095812014-08-06Per Hedbor  //!
27af0d1998-01-10Niels Möller  mapping GetProperty(object property, object|void type) { object req = GetProperty_req(property, type); array a = display->blocking_request(req); if (!a[0]) return 0; mapping m = a[1]; if (type && (m->type == type->id)) m->type = type; else m->type = display->lookup_atom(m->type); return m; }
a77d271998-01-12Niels Möller 
a095812014-08-06Per Hedbor  //!
a77d271998-01-12Niels Möller  object ClearArea_req(int x, int y, int width, int height, int exposures) {
aeed4f1998-04-21Per Hedbor  object req = .Requests.ClearArea();
a77d271998-01-12Niels Möller  req->window = id; req->exposures = exposures; req->x = x; req->y = y; req->width = width; req->height = height; return req; }
a095812014-08-06Per Hedbor  //!
a77d271998-01-12Niels Möller  void ClearArea(int x, int y, int width, int height, int|void exposures) { display->send_request(ClearArea_req(x, y, width, height, exposures)); }
3524712015-05-26Martin Nilsson 
89ed8c1998-01-04Per Hedbor  // Shape extension
a095812014-08-06Per Hedbor  //!
89ed8c1998-01-04Per Hedbor  void ShapeRectangles( string kind, int xo, int yo, string operation, array (object(Rectangle)) rectangles ) { if(kind == "both") { ShapeRectangles( "clip", xo, yo, operation, rectangles); ShapeRectangles( "bounding", xo, yo, operation, rectangles); return; } if(!display->extensions["SHAPE"]) error("No shape extension available.\n"); display->extensions["SHAPE"]->
563bd72004-01-11Martin Nilsson  ShapeRectangles( this, xo, yo, kind, operation, rectangles );
89ed8c1998-01-04Per Hedbor  }
a095812014-08-06Per Hedbor  //!
89ed8c1998-01-04Per Hedbor  void ShapeMask( string kind, int xo, int yo, string operation, object (Pixmap) mask ) {
3827d31998-01-10Per Hedbor  if(kind == "both") { ShapeMask( "clip", xo, yo, operation, mask); ShapeMask( "bounding", xo, yo, operation, mask); return; }
89ed8c1998-01-04Per Hedbor  if(!display->extensions["SHAPE"]) error("No shape extension available.\n"); display->extensions["SHAPE"]->
563bd72004-01-11Martin Nilsson  ShapeMask( this, xo, yo, kind, operation, mask );
89ed8c1998-01-04Per Hedbor  }
a095812014-08-06Per Hedbor  //!
89ed8c1998-01-04Per Hedbor  void ShapeOffset( string kind, int xo, int yo ) {
3827d31998-01-10Per Hedbor  if(kind == "both") { ShapeOffset( "clip", xo, yo ); ShapeOffset( "bounding", xo, yo ); return; }
89ed8c1998-01-04Per Hedbor  if(!display->extensions["SHAPE"]) error("No shape extension available.\n");
563bd72004-01-11Martin Nilsson  display->extensions["SHAPE"]->ShapeOffset( this, kind, xo, yo );
89ed8c1998-01-04Per Hedbor  } // Init function.
e045f11997-12-30Per Hedbor  void create(mixed ... args) { ::create( @args );
8f90db1998-01-01Per Hedbor  if(sizeof(args)>2 && objectp(args[2])) visual = args[2]; if(sizeof(args)>3 && objectp(args[3])) parent = args[3];
e045f11997-12-30Per Hedbor  set_event_callback("_KeyPress", handle_keys); set_event_callback("_KeyRelease", handle_keys); }
148f151997-12-25Niels Möller } class RootWindow
a095812014-08-06Per Hedbor  //!
148f151997-12-25Niels Möller { inherit Window; object defaultColorMap; int whitePixel; int blackPixel; int pixWidth; int pixHeight; int mmWidth; int mmHeight; int minInstalledMaps; int maxInstalledMaps; int backingStore; int saveUnders; int rootDepth; mapping depths;
a095812014-08-06Per Hedbor  //!
e1a0bf1998-02-12Per Hedbor  void create(mixed ... args) { ::create(@args); autofree=0; }
3524712015-05-26Martin Nilsson 
148f151997-12-25Niels Möller  object new(mixed ... args) /* Kludge */ { return Window(@args); } }
1450c31998-03-04Niels Möller /* Kludge */ void create() {
aeed4f1998-04-21Per Hedbor  ._Types.set_pixmap_class(Pixmap);
1450c31998-03-04Niels Möller }