summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEamon Walsh <ewalsh@tycho.nsa.gov>2008-05-28 17:41:51 -0400
committerEamon Walsh <ewalsh@moss-charon.epoch.ncsc.mil>2008-05-28 17:41:51 -0400
commitf01b2a52afa9564ede6221a5fb3cb0520e2bfa77 (patch)
treefdcc8c2abf5f1f8a50ab1beb79be63612fa21903
parentbb0fce870504d0a601d03b38727a00c068b1831b (diff)
Add bindings for more XCB library functions.
-rw-r--r--src/conn.c100
1 files changed, 85 insertions, 15 deletions
diff --git a/src/conn.c b/src/conn.c
index 33b46ab..78c4bf2 100644
--- a/src/conn.c
+++ b/src/conn.c
@@ -18,6 +18,10 @@ xpybConn_invalid(xpybConn *self)
PyErr_SetString(xpybExcept_base, "Invalid connection.");
return 1;
}
+ if (xcb_connection_has_error(self->conn)) {
+ PyErr_SetString(xpybExcept_base, "An error has occurred on the connection.");
+ return 1;
+ }
return 0;
}
@@ -231,22 +235,23 @@ static PyMemberDef xpybConn_members[] = {
*/
static PyObject *
-xpybConn_flush(xpybConn *self, PyObject *args)
+xpybConn_has_error(xpybConn *self, PyObject *args)
{
- if (xpybConn_invalid(self))
+ if (self->conn == NULL) {
+ PyErr_SetString(xpybExcept_base, "Invalid connection.");
return NULL;
+ }
- xcb_flush(self->conn);
- Py_RETURN_NONE;
+ return Py_BuildValue("i", xcb_connection_has_error(self->conn));
}
static PyObject *
-xpybConn_disconnect(xpybConn *self, PyObject *args)
+xpybConn_get_file_descriptor(xpybConn *self, PyObject *args)
{
- if (self->conn)
- xcb_disconnect(self->conn);
- self->conn = NULL;
- Py_RETURN_NONE;
+ if (xpybConn_invalid(self))
+ return NULL;
+
+ return Py_BuildValue("i", xcb_get_file_descriptor(self->conn));
}
static PyObject *
@@ -269,6 +274,15 @@ xpybConn_prefetch_maximum_request_length(xpybConn *self, PyObject *args)
}
static PyObject *
+xpybConn_get_setup(xpybConn *self, PyObject *args)
+{
+ if (xpybConn_invalid(self))
+ return NULL;
+
+ return NULL; /* XXX */
+}
+
+static PyObject *
xpybConn_wait_for_event(xpybConn *self, PyObject *args)
{
xcb_generic_event_t *data;
@@ -314,16 +328,52 @@ xpybConn_poll_for_event(xpybConn *self, PyObject *args)
return xpybEvent_create(self, data);
}
+static PyObject *
+xpybConn_flush(xpybConn *self, PyObject *args)
+{
+ if (xpybConn_invalid(self))
+ return NULL;
+
+ xcb_flush(self->conn);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+xpybConn_generate_id(xpybConn *self)
+{
+ unsigned int xid;
+
+ if (xpybConn_invalid(self))
+ return NULL;
+
+ xid = xcb_generate_id(self->conn);
+ if (xid == (unsigned int)-1) {
+ PyErr_SetString(xpybExcept_base, "No more free XID's available.");
+ return NULL;
+ }
+
+ return Py_BuildValue("I", xid);
+}
+
+static PyObject *
+xpybConn_disconnect(xpybConn *self, PyObject *args)
+{
+ if (self->conn)
+ xcb_disconnect(self->conn);
+ self->conn = NULL;
+ Py_RETURN_NONE;
+}
+
static PyMethodDef xpybConn_methods[] = {
- { "flush",
- (PyCFunction)xpybConn_flush,
+ { "has_error",
+ (PyCFunction)xpybConn_has_error,
METH_NOARGS,
- "Forces any buffered output to be written to the server." },
+ "Test whether the connection has shut down due to a fatal error." },
- { "disconnect",
- (PyCFunction)xpybConn_disconnect,
+ { "get_file_descriptor",
+ (PyCFunction)xpybConn_get_file_descriptor,
METH_NOARGS,
- "Disconnects from the X server." },
+ "Access the file descriptor of the connection." },
{ "get_maximum_request_length",
(PyCFunction)xpybConn_get_maximum_request_length,
@@ -335,6 +385,11 @@ static PyMethodDef xpybConn_methods[] = {
METH_NOARGS,
"Prefetch the maximum request length without blocking." },
+ { "get_setup",
+ (PyCFunction)xpybConn_get_setup,
+ METH_NOARGS,
+ "Accessor for the connection information returned by the server." },
+
{ "wait_for_event",
(PyCFunction)xpybConn_wait_for_event,
METH_NOARGS,
@@ -345,6 +400,21 @@ static PyMethodDef xpybConn_methods[] = {
METH_NOARGS,
"Returns the next event or raises the next error from the server." },
+ { "flush",
+ (PyCFunction)xpybConn_flush,
+ METH_NOARGS,
+ "Forces any buffered output to be written to the server." },
+
+ { "generate_id",
+ (PyCFunction)xpybConn_generate_id,
+ METH_NOARGS,
+ "Allocates an XID for a new object." },
+
+ { "disconnect",
+ (PyCFunction)xpybConn_disconnect,
+ METH_NOARGS,
+ "Disconnects from the X server." },
+
{ NULL } /* terminator */
};