pike.git / lib / modules / Protocols.pmod / X.pmod / Xlib.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:16:    * 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    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    */      #pike __REAL_VERSION__    - // #define DEBUG + // #define XDEBUG    -  + //! Implementations of various X11 calls. +    constant XPORT = 6000;    -  +    class rec_buffer   {    string buffer;    int expected;    int pad;       void create()    {    buffer = "";    expected = pad = 0;
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:120:    }       void forget_id(int id)    {    m_delete(resources, id);    /* Could make id available for reallocation */    }   }      class Display + //! The representation of a X display. + //! + //! Keeps the connection to the X server and various other information + //! needed to use X11.   {    import ._Xlib;       inherit Stdio.File;    inherit id_manager;    inherit .Atom.atom_manager;    -  -  +     void close_callback(mixed id);    void read_callback(mixed id, string data);       // FIXME! Should use some sort of (global) db.    mapping compose_patterns;    -  program Struct = ADT.struct; +  program(Stdio.Buffer) Struct = Stdio.Buffer;       constant STATE_WAIT_CONNECT = 0;    constant STATE_WAIT_CONNECT_DATA = 1;    constant STATE_WAIT_CONNECT_FAILURE = 2;    constant STATE_WAIT_HEADER = 3;    constant STATE_WAIT_REPLY = 4;    constant STATE_CLOSED = 4711;       constant ACTION_CONNECT = 0;    constant ACTION_CONNECT_FAILED = 1;    constant ACTION_EVENT = 2;    constant ACTION_REPLY = 3;    constant ACTION_ERROR = 4;    -  + //!    int screen_number;       string buffer;    object received;    int state;    int sequence_number;       function io_error_handler;    function error_handler;    function close_handler;    function connect_handler;    function event_handler;    function misc_event_handler;    function reply_handler;       /* Information about the X server */    int majorVersion, minorVersion; /* Servers protocol version */ -  +  //! The protocol major and minor version reported by the server +     int release; -  +  //! Server release number +     int ridBase, ridMask; -  +     int motionBufferSize; -  +  //! +     string vendor; -  +  //! +     int maxRequestSize; -  +  //! +     array roots; -  +  //! +     array formats; -  +  //! +     int imageByteOrder, bitmapBitOrder; -  +  //! +     int bitmapScanlineUnit, bitmapScanlinePad; -  +  //! +     int minKeyCode, maxKeyCode; -  +  //!       array key_mapping ; -  +  //!    -  mapping extensions = ([]); // all available extensions. +  mapping(string:.Extensions.Extension) extensions = ([]); +  //! All extensions supported by the server and this module       mapping pending_requests; /* Pending requests */ -  +     object pending_actions; /* Actions awaiting handling */    - #ifdef DEBUG + #ifdef XDEBUG    mapping debug_requests = ([ ]);   # define DEBUGREQ(X) ((X)&0xfff)   #endif       void create()    { /* Delay initialization of id_manager */    compose_patterns = ([]);    catch {    compose_patterns = decode_value(Stdio.read_bytes("db/compose.db"));    };
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:237: Inside #if 0
   set_write_callback(write_callback);    /* Socket is most likely non-blocking,    * and write_callback() expects to be be able to write    * at least one character. So don't call it yet. */   #endif    write_callback( );    }    }       /* This function leaves the socket in blocking mode */ +     int flush()    { /* FIXME: Not thread-safe */    set_blocking();    int written = write(buffer);    if (written < sizeof(buffer))    return 0;    buffer = "";       // werror(sprintf("flush: result = %d\n", result));    // trace(0);
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:318:    break;    }    case STATE_WAIT_CONNECT_FAILURE:    return ({ ACTION_CONNECT_FAILED, msg });    close();    state = STATE_CLOSED;    break;    case STATE_WAIT_CONNECT_DATA:    {    int nbytesVendor, numRoots, numFormats; -  object struct = Struct(msg); +  Stdio.Buffer struct = Struct(msg);    -  release = struct->get_uint(4); -  ridBase = struct->get_uint(4); -  ridMask = struct->get_uint(4); +  release = struct->read_int(4); +  ridBase = struct->read_int(4); +  ridMask = struct->read_int(4);    id_manager::create(ridBase, ridMask);    -  motionBufferSize = struct->get_uint(4); -  nbytesVendor = struct->get_uint(2); -  maxRequestSize = struct->get_uint(2); -  numRoots = struct->get_uint(1); -  numFormats = struct->get_uint(1); -  imageByteOrder = struct->get_uint(1); -  bitmapBitOrder = struct->get_uint(1); -  bitmapScanlineUnit = struct->get_uint(1); -  bitmapScanlinePad = struct->get_uint(1); -  minKeyCode = struct->get_uint(1); -  maxKeyCode = struct->get_uint(1); -  /* pad2 */ struct->get_fix_string(4); +  motionBufferSize = struct->read_int(4); +  nbytesVendor = struct->read_int(2); +  maxRequestSize = struct->read_int(2); +  numRoots = struct->read_int(1); +  numFormats = struct->read_int(1); +  imageByteOrder = struct->read_int(1); +  bitmapBitOrder = struct->read_int(1); +  bitmapScanlineUnit = struct->read_int(1); +  bitmapScanlinePad = struct->read_int(1); +  minKeyCode = struct->read_int(1); +  maxKeyCode = struct->read_int(1); +  /* pad2 */ struct->read(4);    -  vendor = struct->get_fix_string(nbytesVendor); -  /* pad */ struct->get_fix_string( (- nbytesVendor) % 4); +  vendor = struct->read(nbytesVendor); +  /* pad */ struct->read( (- nbytesVendor) % 4);       int i;    formats = allocate(numFormats);    for(i=0; i<numFormats; i++)    {    mapping m = ([]); -  m->depth = struct->get_uint(1); -  m->bitsPerPixel = struct->get_uint(1); -  m->scanLinePad = struct->get_uint(1); -  /* pad */ struct->get_fix_string(5); +  m->depth = struct->read_int(1); +  m->bitsPerPixel = struct->read_int(1); +  m->scanLinePad = struct->read_int(1); +  /* pad */ struct->read(5);    formats[i] = m;    }       roots = allocate(numRoots);    for(i=0; i<numRoots; i++)    { -  int wid = struct->get_uint(4); +  int wid = struct->read_int(4);    object r = .Types.RootWindow(this, wid); -  int cm = struct->get_uint(4); +  int cm = struct->read_int(4);    r->colormap = r->defaultColorMap = .Types.Colormap(this, cm, 0);    r->colormap->autofree=0; -  r->whitePixel = struct->get_uint(4); -  r->blackPixel = struct->get_uint(4); -  r->currentInputMask = struct->get_uint(4); -  r->pixWidth = struct->get_uint(2); -  r->pixHeight = struct->get_uint(2); -  r->mmWidth = struct->get_uint(2); -  r->mmHeight = struct->get_uint(2); -  r->minInstalledMaps = struct->get_uint(2); -  r->maxInstalledMaps = struct->get_uint(2); -  int rootVisualID = struct->get_uint(4); -  r->backingStore = struct->get_uint(1); -  r->saveUnders = struct->get_uint(1); -  r->rootDepth = struct->get_uint(1); -  int nDepths = struct->get_uint(1); +  r->whitePixel = struct->read_int(4); +  r->blackPixel = struct->read_int(4); +  r->currentInputMask = struct->read_int(4); +  r->pixWidth = struct->read_int(2); +  r->pixHeight = struct->read_int(2); +  r->mmWidth = struct->read_int(2); +  r->mmHeight = struct->read_int(2); +  r->minInstalledMaps = struct->read_int(2); +  r->maxInstalledMaps = struct->read_int(2); +  int rootVisualID = struct->read_int(4); +  r->backingStore = struct->read_int(1); +  r->saveUnders = struct->read_int(1); +  r->rootDepth = struct->read_int(1); +  int nDepths = struct->read_int(1);       r->depths = ([ ]);    for (int j=0; j<nDepths; j++)    {    mapping d = ([]); -  int depth = struct->get_uint(1); -  /* pad */ struct->get_fix_string(1); -  int nVisuals = struct->get_uint(2); -  /* pad */ struct->get_fix_string(4); +  int depth = struct->read_int(1); +  /* pad */ struct->read(1); +  int nVisuals = struct->read_int(2); +  /* pad */ struct->read(4);       array visuals = allocate(nVisuals);    for(int k=0; k<nVisuals; k++)    { -  int visualID = struct->get_uint(4); +  int visualID = struct->read_int(4);    object v = .Types.Visual(this, visualID);       v->depth = depth; -  v->c_class = struct->get_uint(1); -  v->bitsPerRGB = struct->get_uint(1); -  v->colorMapEntries = struct->get_uint(2); -  v->redMask = struct->get_uint(4); -  v->greenMask = struct->get_uint(4); -  v->blueMask = struct->get_uint(4); -  /* pad */ struct->get_fix_string(4); +  v->c_class = struct->read_int(1); +  v->bitsPerRGB = struct->read_int(1); +  v->colorMapEntries = struct->read_int(2); +  v->redMask = struct->read_int(4); +  v->greenMask = struct->read_int(4); +  v->blueMask = struct->read_int(4); +  /* pad */ struct->read(4);    visuals[k] = v;    }    r->depths[depth] = visuals;    }    r->visual = lookup_id(rootVisualID);    roots[i] = r;    }    if (screen_number >= numRoots)    werror("Xlib.Display->process: screen_number too large.\n");    state = STATE_WAIT_HEADER;
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:434:    received->expect(32); /* Correct for most of the cases */    string type = ._Xlib.event_types[msg[0] & 0x3f];    if (type == "Error")    {    mapping m = ([]);    int errorCode;    sscanf(msg, "%*c%c%2c%4c%2c%c",    errorCode, m->sequenceNumber, m->resourceID,    m->minorCode, m->majorCode);    m->errorCode = ._Xlib.error_codes[errorCode]; - #ifdef DEBUG + #ifdef XDEBUG    m->failed_request = debug_requests[DEBUGREQ(m->sequenceNumber)];   #endif   #if 0    if (m->errorCode == "Success")    {    werror("Xlib.Display->process: Error 'Success' ignored.\n");    break;    }   #endif   // werror(sprintf("Xlib: Received error %O\n", m));
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:676:    }    else    (error_handler || default_error_handler)(this, a[1]);    break;    }    default:    error("Xlib.Display->handle_action: internal error\n");    break;    }    } +     void read_callback(mixed id, string data)    {    // werror(sprintf("Xlib: received '%s'\n", data));    received->add_data(data);    array a;    while(a = process())    handle_action(a);    }       void close_callback(mixed id)
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:705:    }       void process_pending_actions()    {    array a;    while(a = pending_actions->get())    handle_action(a);    set_nonblocking(read_callback, write_callback, close_callback);    }    +  //! Connect to the specified display. The default is to use the +  //! value of the environment variable DISPLAY    int open(string|void display)    {    int async = !!connect_handler;    int is_local;    int display_number;       display = display || getenv("DISPLAY");    if (!display)    error("Xlib.pmod: $DISPLAY not set!\n");   
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:832:    default:    error("Xlib.Display->open: Internal error!\n");    }    }    }       int send_request(object req, mixed|void handler)    {    string data = req->to_string();    send(data); - #ifdef DEBUG + #ifdef XDEBUG    debug_requests[DEBUGREQ(sequence_number)] = data;   #endif    return (sequence_number++)&0xffff; // sequence number is just 2 bytes    }    -  array blocking_request(object req) +  //! +  array blocking_request(.Requests.request req)    {    int success;    mixed result = 0;    int done = 0;       int n = send_request(req);    flush();       while(!done)    {
pike.git/lib/modules/Protocols.pmod/X.pmod/Xlib.pmod:887:    }       if (!pending_actions->is_empty())    call_out(process_pending_actions, 0);    else    set_nonblocking(read_callback,write_callback,close_callback);       return ({ success, result });    }    -  void send_async_request(object req, function callback) +  //! +  void send_async_request(.Requests.request req, function callback)    {    int n = send_request(req);    pending_requests[n] = async_request(req, callback);    }       void got_mapping(int ok, array foo)    {    key_mapping = foo;    }       void get_keyboard_mapping()    {    object r = .Requests.GetKeyboardMapping();    r->first = minKeyCode;    r->num = maxKeyCode - minKeyCode + 1;    send_async_request(r, got_mapping);    }    -  +  //!    object DefaultRootWindow()    {    return roots[screen_number];    }    -  +  //!    object OpenFont_req(string name)    {    object req = .Requests.OpenFont();    req->fid = alloc_id();    req->name = name;    return req;    }       mapping (string:object) fonts = ([]);    -  +  //!    object OpenFont(string name)    {    if(fonts[name]) return fonts[name];    object req = OpenFont_req(name);    send_request(req);    fonts[name] = .Types.Font(this, req->fid);    return fonts[name];    }    -  +  //!    object CreateGlyphCursor_req(object sourcefont, object maskfont,    int sourcechar, int maskchar,    array(int) foreground, array(int) background)    {    object req = .Requests.CreateGlyphCursor();    req->cid = alloc_id();    req->sourcefont = sourcefont->id;    req->maskfont = maskfont->id;    req->sourcechar = sourcechar;    req->maskchar = maskchar;    req->forered = foreground[0];    req->foregreen = foreground[1];    req->foreblue = foreground[2];    req->backred = background[0];    req->backgreen = background[1];    req->backblue = background[2];    return req;    }    -  +  //!    object CreateGlyphCursor(object sourcefont, int sourcechar,    object|void maskfont, int|void maskchar,    array(int)|void foreground,    array(int)|void background)    {    if(!maskfont) {    maskfont = sourcefont;    if(!maskchar)    maskchar = sourcechar + 1;    }    object req = CreateGlyphCursor_req(sourcefont, maskfont,    sourcechar, maskchar,    foreground||({0,0,0}),    background||({0xffff,0xffff,0xffff}));    send_request(req);    return .Types.Cursor(this, req->cid);    }    -  +  //!    object Bell_req(int volume)    {    object req=.Requests.Bell();    req->percent=volume;    return req;    }    -  +  //!    void Bell(int volume)    {    send_request(Bell_req(volume));    }   }