summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Frank Erikson <kristian@kristian-desktop.(none)>2009-01-11 11:46:52 +1300
committerKristian Frank Erikson <kristian@kristian-desktop.(none)>2009-01-11 11:46:52 +1300
commita8a697fe25aa508e3dc06e9bbca62f4a3d93294b (patch)
treeea289d446a1c1a638ced4dc109d25d7f8fa0918d
parentad3453119d039d5b59afe94d76fd095e13c3dea4 (diff)
downloadpython-compiz-manager-a8a697fe25aa508e3dc06e9bbca62f4a3d93294b.tar.gz
python-compiz-manager-a8a697fe25aa508e3dc06e9bbca62f4a3d93294b.tar.bz2
Fixed missing windows by applying Debian patch wmctrl-1.07-6 to original source and copying to this source code. Seems very close to complete now.
-rw-r--r--CompizPyWindowList-setup.py19
-rw-r--r--CompizPyWindowList.c72
2 files changed, 60 insertions, 31 deletions
diff --git a/CompizPyWindowList-setup.py b/CompizPyWindowList-setup.py
index 082a134..32ad552 100644
--- a/CompizPyWindowList-setup.py
+++ b/CompizPyWindowList-setup.py
@@ -1,9 +1,12 @@
-# To rebuild this module the command is: python CompizPyWindowList-setup.py build_ext -i
+# To rebuild this module the command is: ~$ python CompizPyWindowList-setup.py build_ext -i
from distutils.core import setup, Extension
module = Extension("CompizPyWindowList",
libraries = ['glib-2.0','X11','Xmu','X11-xcb','xcb'],
+ # Where these libraries are located on a particular distubution
+ # can be located by issueing command:
+ # ~$ pkg-config glib-2.0 x11 xmu x11-xcb xcb --cflags --libs
include_dirs = ['/usr/include/glib-2.0','/usr/lib/glib-2.0/include','/usr/local/lib' \
'/usr/local/include/glib-2.0','/usr/local/lib/glib-2.0/include','/usr/include'],
sources = ["CompizPyWindowList.c"])
@@ -19,17 +22,3 @@ This C extension queries X11 for information on active windows.
''',
ext_modules=[module])
-
- """
- WHAT WMCTRL with debian patch compiled with:
-
- gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/local/lib/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/include -I/usr/include/python2.5 -c CompizPyWindowList.c -o build/temp.linux-x86_64-2.5/CompizPyWindowList.o
-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.5/CompizPyWindowList.o -lglib-2.0 -lX11 -lXmu -lX11-xcb -lxcb -o CompizPyWindowList.so
- """
-
- """
- WHAT THIS ONE CURRENTLY COMPILES WITH:
-
- gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/local/lib/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/include -I/usr/include/python2.5 -c CompizPyWindowList.c -o build/temp.linux-x86_64-2.5/CompizPyWindowList.o
-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.5/CompizPyWindowList.o -lglib-2.0 -lX11 -lXmu -lX11-xcb -lxcb -o CompizPyWindowList.so
- """
diff --git a/CompizPyWindowList.c b/CompizPyWindowList.c
index 894f183..41fc21b 100644
--- a/CompizPyWindowList.c
+++ b/CompizPyWindowList.c
@@ -24,6 +24,7 @@ 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,
Atom xa_prop_type, gchar *prop_name, unsigned long *size);
+static void init_charset(void);
static struct {
int verbose;
@@ -47,6 +48,13 @@ CompizPyWindowList_listWindows(PyObject *self, PyObject *args)
PyObject *returnValue;
Display *disp;
+
+ memset(&options, 0, sizeof(options)); /* just for sure */
+
+ /* necessary to make g_get_charset() and g_locale_*() work */
+ setlocale(LC_ALL, "");
+
+ init_charset();
if (! (disp = XOpenDisplay(NULL))) {
fputs("Cannot open display.\n", stderr);
@@ -82,6 +90,31 @@ initCompizPyWindowList(void)
Py_InitModule3("CompizPyWindowList", CompizPyWindowList_methods, CompizPyWindowList_doc);
}
+static void init_charset (void) {/*{{{*/
+ const gchar *charset; /* unused */
+ gchar *lang = getenv("LANG") ? g_ascii_strup(getenv("LANG"), -1) : NULL;
+ gchar *lc_ctype = getenv("LC_CTYPE") ? g_ascii_strup(getenv("LC_CTYPE"), -1) : NULL;
+
+ /* this glib function doesn't work on my system ... */
+ envir_utf8 = g_get_charset(&charset);
+
+ /* ... therefore we will examine the environment variables */
+ if (lc_ctype && (strstr(lc_ctype, "UTF8") || strstr(lc_ctype, "UTF-8"))) {
+ envir_utf8 = TRUE;
+ }
+ else if (lang && (strstr(lang, "UTF8") || strstr(lang, "UTF-8"))) {
+ envir_utf8 = TRUE;
+ }
+
+ g_free(lang);
+ g_free(lc_ctype);
+
+ if (options.force_utf8) {
+ envir_utf8 = TRUE;
+ }
+ p_verbose("envir_utf8: %d\n", envir_utf8);
+}/*}}}*/
+
static gchar *get_output_str (gchar *str, gboolean is_utf8) {
gchar *out;
@@ -144,7 +177,7 @@ static PyObject *list_windows (Display *disp) {
return NULL;
}
- // find the longest client_machine name
+ /* find the longest client_machine name */
for (i = 0; i < client_list_size / sizeof(Window); i++) {
gchar *client_machine;
if ((client_machine = get_property(disp, client_list[i],
@@ -156,46 +189,41 @@ static PyObject *list_windows (Display *disp) {
windowInfoList = Py_BuildValue("[]"); //Create a blank list we'll append to
- // print the list
+ /* print the list */
for (i = 0; i < client_list_size / sizeof(Window); i++) {
- gchar *title_utf8 = get_window_title(disp, client_list[i]); // UTF8
+ gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
gchar *title_out = get_output_str(title_utf8, TRUE);
gchar *client_machine;
- gchar *class_out = get_window_class(disp, client_list[i]); // UTF8
+ gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */
unsigned long *pid;
unsigned long *desktop;
int x, y, junkx, junky;
unsigned int wwidth, wheight, bw, depth;
Window junkroot;
- PyObject *windowInfo;
-
- // desktop ID
+ PyObject *windowInfo; //Information for this particular window
+
+ /* desktop ID */
if ((desktop = (unsigned long *)get_property(disp, client_list[i],
XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
desktop = (unsigned long *)get_property(disp, client_list[i],
XA_CARDINAL, "_WIN_WORKSPACE", NULL);
}
- // client machine
+ /* client machine */
client_machine = get_property(disp, client_list[i],
XA_STRING, "WM_CLIENT_MACHINE", NULL);
-
- // pid
+
+ /* pid */
pid = (unsigned long *)get_property(disp, client_list[i],
XA_CARDINAL, "_NET_WM_PID", NULL);
- // geometry
+ /* geometry */
XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky,
&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
@@ -304,6 +332,16 @@ static gchar *get_property (Display *disp, Window win,
*
* long_length = Specifies the length in 32-bit multiples of the
* data to be retrieved.
+ *
+ * NOTE: see
+ * http://mail.gnome.org/archives/wm-spec-list/2003-March/msg00067.html
+ * In particular:
+ *
+ * When the X window system was ported to 64-bit architectures, a
+ * rather peculiar design decision was made. 32-bit quantities such
+ * as Window IDs, atoms, etc, were kept as longs in the client side
+ * APIs, even when long was changed to 64 bits.
+ *
*/
if (XGetWindowProperty(disp, win, xa_prop_name, 0, MAX_PROPERTY_VALUE_LEN / 4, False,
xa_prop_type, &xa_ret_type, &ret_format,
@@ -320,6 +358,8 @@ static gchar *get_property (Display *disp, Window win,
/* null terminate the result to make string handling easier */
tmp_size = (ret_format / 8) * ret_nitems;
+ /* Correct 64 Architecture implementation of 32 bit data */
+ if(ret_format==32) tmp_size *= sizeof(long)/4;
ret = g_malloc(tmp_size + 1);
memcpy(ret, ret_prop, tmp_size);
ret[tmp_size] = '\0';