summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Frank Erikson <kristian@kristian-desktop.(none)>2009-01-10 16:09:16 +1300
committerKristian Frank Erikson <kristian@kristian-desktop.(none)>2009-01-10 16:09:16 +1300
commit57a7a0b7eac537fd2428865048c1de9a2dadc5e6 (patch)
treea1148dfd0080454523599dcd74ed588de307c1db
parent8bfbe01f25a1c4711a240271179f91dcb33c4368 (diff)
downloadpython-compiz-manager-57a7a0b7eac537fd2428865048c1de9a2dadc5e6.tar.gz
python-compiz-manager-57a7a0b7eac537fd2428865048c1de9a2dadc5e6.tar.bz2
New C extension module now works as intended but seems to be missing windows on the list.
-rw-r--r--CompizPyWindowList.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/CompizPyWindowList.c b/CompizPyWindowList.c
index a8e231d..7a57626 100644
--- a/CompizPyWindowList.c
+++ b/CompizPyWindowList.c
@@ -16,10 +16,10 @@
}
static char CompizPyWindowList_doc[] =
-"This module is just a simple example. It provides one function: func().";
+"This module is useful for seeing which windows are active in X11.";
static Window *get_client_list (Display *disp, unsigned long *size);
-static int list_windows (Display *disp);
+static PyObject *list_windows (Display *disp);
static gchar *get_window_title (Display *disp, Window win);
static gchar *get_window_class (Display *disp, Window win);
static gchar *get_property (Display *disp, Window win,
@@ -44,7 +44,7 @@ static gboolean envir_utf8;
static PyObject*
CompizPyWindowList_func(PyObject *self, PyObject *args)
{
- int ret = 1;
+ PyObject *returnValue;
Display *disp;
@@ -54,19 +54,22 @@ CompizPyWindowList_func(PyObject *self, PyObject *args)
}
// Should now have disp
- ret = list_windows(disp);
+ returnValue = list_windows(disp);
// All done so close display
XCloseDisplay(disp);
// Here we should return a list
- return ret;
+ return returnValue;
}
static char CompizPyWindowList_func_doc[] =
- "func(a, b)\n\
+ "listWindows()\n\
\n\
- Return the sum of a and b.";
+ Returns a list of tuples containing information\n\
+ on each window in the form:\n\
+ \n\
+ [{'title':'<window_title>','id':'<window_id>'},{...},...,{...}]";
static PyMethodDef CompizPyWindowList_methods[] = {
{"func", CompizPyWindowList_func, METH_VARARGS, CompizPyWindowList_func_doc},
@@ -129,14 +132,16 @@ static Window *get_client_list (Display *disp, unsigned long *size) {
return client_list;
}
-static int list_windows (Display *disp) {
+static PyObject *list_windows (Display *disp) {
Window *client_list;
unsigned long client_list_size;
int i;
int max_client_machine_len = 0;
+ PyObject *windowInfoList; //This is the python object we'll return
+
if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
- return EXIT_FAILURE;
+ return NULL;
}
// find the longest client_machine name
@@ -149,6 +154,8 @@ static int list_windows (Display *disp) {
g_free(client_machine);
}
+ windowInfoList = Py_BuildValue("[]"); //Create a blank list we'll append to
+
// print the list
for (i = 0; i < client_list_size / sizeof(Window); i++) {
gchar *title_utf8 = get_window_title(disp, client_list[i]); // UTF8
@@ -160,6 +167,8 @@ static int list_windows (Display *disp) {
int x, y, junkx, junky;
unsigned int wwidth, wheight, bw, depth;
Window junkroot;
+
+ PyObject *windowInfo;
// desktop ID
if ((desktop = (unsigned long *)get_property(disp, client_list[i],
@@ -181,9 +190,21 @@ static int list_windows (Display *disp) {
&wwidth, &wheight, &bw, &depth);
XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky,
&x, &y, &junkroot);
-
+
+
+ //TODO: Looks like it's here I should be building values using:
+ //http://docs.python.org/extending/extending.html#building-arbitrary-values
+
+
// special desktop ID -1 means "all desktops", so we
// have to convert the desktop value to signed long
+
+ //Build tuple of window information for this window
+ windowInfo = Py_BuildValue("{s:i,s:s}", "id", client_list[i],
+ "title", title_out ? title_out : "N/A");
+ PyList_Append(windowInfoList, windowInfo); // Append to the list
+
+ /*
printf("0x%.8lx %2ld", client_list[i],
desktop ? (signed long)*desktop : 0);
if (options.show_pid) {
@@ -201,6 +222,7 @@ static int list_windows (Display *disp) {
client_machine ? client_machine : "N/A",
title_out ? title_out : "N/A"
);
+ */
g_free(title_utf8);
g_free(title_out);
g_free(desktop);
@@ -209,8 +231,10 @@ static int list_windows (Display *disp) {
g_free(pid);
}
g_free(client_list);
+
+// returnObject = Py_BuildValue("iii", windowIds[0],windowIds[1],windowIds[2]);
- return EXIT_SUCCESS;
+ return windowInfoList;
}
static gchar *get_window_class (Display *disp, Window win) {