Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/sugar-x11-util.c88
-rw-r--r--lib/sugar-x11-util.h36
-rw-r--r--sugar/Makefile.am3
-rw-r--r--sugar/_sugarext.c67
-rw-r--r--sugar/_sugarext.defs18
-rw-r--r--sugar/_sugarext.override2
-rw-r--r--sugar/wm.py38
8 files changed, 249 insertions, 7 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f709c58..cd0d457 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -11,4 +11,6 @@ libsugar_la_LIBADD = \
libsugar_la_SOURCES = \
sugar-address-entry.c \
- sugar-address-entry.h
+ sugar-address-entry.h \
+ sugar-x11-util.c \
+ sugar-x11-util.h
diff --git a/lib/sugar-x11-util.c b/lib/sugar-x11-util.c
new file mode 100644
index 0000000..bc0f693
--- /dev/null
+++ b/lib/sugar-x11-util.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2006, Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gdk/gdkproperty.h>
+#include <X11/Xatom.h>
+#include <glib/gstrfuncs.h>
+#include <string.h>
+
+#include "sugar-x11-util.h"
+
+void
+sugar_x11_util_set_string_property(GdkWindow *window,
+ const char *property,
+ const char *value)
+{
+ Atom prop_atom;
+ Atom utf8_atom;
+ GdkDisplay *display;
+ char *prop_text;
+
+ display = gdk_drawable_get_display(window);
+ prop_atom = gdk_x11_get_xatom_by_name_for_display(display, property);
+ utf8_atom = gdk_x11_get_xatom_by_name_for_display(display, "UTF8_ATOM");
+ prop_text = gdk_utf8_to_string_target(value);
+
+ XChangeProperty(GDK_DISPLAY_XDISPLAY(display),
+ GDK_WINDOW_XID(window),
+ prop_atom,
+ utf8_atom, 8,
+ PropModeReplace, prop_text,
+ strlen(prop_text));
+
+ g_free(prop_text);
+}
+
+char *
+sugar_x11_util_get_string_property(GdkWindow *window,
+ const char *property)
+{
+ Atom type;
+ Atom prop_atom;
+ Atom utf8_atom;
+ int format;
+ int result;
+ unsigned long bytes_after, n_items;
+ unsigned char *str = NULL;
+ char *value = NULL;
+ GdkDisplay *display;
+
+ display = gdk_drawable_get_display(window);
+ prop_atom = gdk_x11_get_xatom_by_name_for_display(display, property);
+ utf8_atom = gdk_x11_get_xatom_by_name_for_display(display, "UTF8_ATOM");
+
+ result = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display),
+ GDK_WINDOW_XID(window),
+ prop_atom,
+ 0, 1024L,
+ False, utf8_atom,
+ &type, &format, &n_items,
+ &bytes_after, (unsigned char **)&str);
+
+ if (result == Success && str != NULL && type == utf8_atom &&
+ format == 8 && n_items > 0) {
+ value = g_strdup(str);
+ }
+
+ if (str) {
+ XFree(str);
+ }
+
+ return value;
+}
diff --git a/lib/sugar-x11-util.h b/lib/sugar-x11-util.h
new file mode 100644
index 0000000..aa61870
--- /dev/null
+++ b/lib/sugar-x11-util.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006, Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __SUGAR_X11_UTIL_H__
+#define __SUGAR_X11_UTIL_H__
+
+#include <gdk/gdkx.h>
+
+G_BEGIN_DECLS
+
+void sugar_x11_util_set_string_property(GdkWindow *window,
+ const char *property,
+ const char *value);
+
+char *sugar_x11_util_get_string_property(GdkWindow *window,
+ const char *property);
+
+G_END_DECLS
+
+#endif /* __SUGAR_ADDRESS_ENTRY_H__ */
diff --git a/sugar/Makefile.am b/sugar/Makefile.am
index d4f91ea..5a1f759 100644
--- a/sugar/Makefile.am
+++ b/sugar/Makefile.am
@@ -8,7 +8,8 @@ sugar_PYTHON = \
logger.py \
ltihooks.py \
profile.py \
- util.py
+ util.py \
+ x11.py
INCLUDES = \
$(LIB_CFLAGS) \
diff --git a/sugar/_sugarext.c b/sugar/_sugarext.c
index be9854c..b895f12 100644
--- a/sugar/_sugarext.c
+++ b/sugar/_sugarext.c
@@ -9,23 +9,26 @@
#include "pygobject.h"
#include "sugar-address-entry.h"
+#include "sugar-x11-util.h"
#include "xdgmime.h"
#include <pygtk/pygtk.h>
#include <glib.h>
-#line 18 "_sugarext.c"
+#line 19 "_sugarext.c"
/* ---------- types from other modules ---------- */
static PyTypeObject *_PyGtkEntry_Type;
#define PyGtkEntry_Type (*_PyGtkEntry_Type)
+static PyTypeObject *_PyGdkWindow_Type;
+#define PyGdkWindow_Type (*_PyGdkWindow_Type)
/* ---------- forward type declarations ---------- */
PyTypeObject G_GNUC_INTERNAL PySugarAddressEntry_Type;
-#line 29 "_sugarext.c"
+#line 32 "_sugarext.c"
@@ -98,7 +101,7 @@ _wrap_sugar_mime_get_mime_type_from_file_name(PyObject *self, PyObject *args, Py
return Py_None;
}
-#line 23 "_sugarext.override"
+#line 25 "_sugarext.override"
static PyObject *
_wrap_sugar_mime_get_mime_type_for_file(PyObject *self, PyObject *args, PyObject *kwargs)
{
@@ -116,14 +119,56 @@ _wrap_sugar_mime_get_mime_type_for_file(PyObject *self, PyObject *args, PyObject
Py_INCREF(Py_None);
return Py_None;
}
-#line 120 "_sugarext.c"
+#line 123 "_sugarext.c"
+static PyObject *
+_wrap_sugar_x11_util_set_string_property(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "window", "property", "value", NULL };
+ PyGObject *window;
+ char *property, *value;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!ss:x11_set_string_property", kwlist, &PyGdkWindow_Type, &window, &property, &value))
+ return NULL;
+
+ sugar_x11_util_set_string_property(GDK_WINDOW(window->obj), property, value);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+_wrap_sugar_x11_util_get_string_property(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "window", "property", NULL };
+ PyGObject *window;
+ char *property;
+ gchar *ret;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!s:x11_get_string_property", kwlist, &PyGdkWindow_Type, &window, &property))
+ return NULL;
+
+ ret = sugar_x11_util_get_string_property(GDK_WINDOW(window->obj), property);
+
+ if (ret) {
+ PyObject *py_ret = PyString_FromString(ret);
+ g_free(ret);
+ return py_ret;
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
const PyMethodDef py_sugarext_functions[] = {
{ "get_mime_type_from_file_name", (PyCFunction)_wrap_sugar_mime_get_mime_type_from_file_name, METH_VARARGS|METH_KEYWORDS,
NULL },
{ "get_mime_type_for_file", (PyCFunction)_wrap_sugar_mime_get_mime_type_for_file, METH_VARARGS|METH_KEYWORDS,
NULL },
+ { "x11_set_string_property", (PyCFunction)_wrap_sugar_x11_util_set_string_property, METH_VARARGS|METH_KEYWORDS,
+ NULL },
+ { "x11_get_string_property", (PyCFunction)_wrap_sugar_x11_util_get_string_property, METH_VARARGS|METH_KEYWORDS,
+ NULL },
{ NULL, NULL, 0, NULL }
};
@@ -145,8 +190,20 @@ py_sugarext_register_classes(PyObject *d)
"could not import gtk");
return ;
}
+ if ((module = PyImport_ImportModule("gtk.gdk")) != NULL) {
+ _PyGdkWindow_Type = (PyTypeObject *)PyObject_GetAttrString(module, "Window");
+ if (_PyGdkWindow_Type == NULL) {
+ PyErr_SetString(PyExc_ImportError,
+ "cannot import name Window from gtk.gdk");
+ return ;
+ }
+ } else {
+ PyErr_SetString(PyExc_ImportError,
+ "could not import gtk.gdk");
+ return ;
+ }
-#line 151 "_sugarext.c"
+#line 208 "_sugarext.c"
pygobject_register_class(d, "SugarAddressEntry", SUGAR_TYPE_ADDRESS_ENTRY, &PySugarAddressEntry_Type, Py_BuildValue("(O)", &PyGtkEntry_Type));
}
diff --git a/sugar/_sugarext.defs b/sugar/_sugarext.defs
index db0c5b3..699f96c 100644
--- a/sugar/_sugarext.defs
+++ b/sugar/_sugarext.defs
@@ -25,3 +25,21 @@
'("const-char*" "filename")
)
)
+
+(define-function x11_set_string_property
+ (c-name "sugar_x11_util_set_string_property")
+ (parameters
+ '("GdkWindow*" "window")
+ '("const-char*" "property")
+ '("const-char*" "value")
+ )
+)
+
+(define-function x11_get_string_property
+ (c-name "sugar_x11_util_get_string_property")
+ (return-type "char*")
+ (parameters
+ '("GdkWindow*" "window")
+ '("const-char*" "property")
+ )
+)
diff --git a/sugar/_sugarext.override b/sugar/_sugarext.override
index 16deb71..2d23bde 100644
--- a/sugar/_sugarext.override
+++ b/sugar/_sugarext.override
@@ -5,6 +5,7 @@ headers
#include "pygobject.h"
#include "sugar-address-entry.h"
+#include "sugar-x11-util.h"
#include "xdgmime.h"
#include <pygtk/pygtk.h>
@@ -14,6 +15,7 @@ headers
modulename _sugarext
%%
import gtk.Entry as PyGtkEntry_Type
+import gtk.gdk.Window as PyGdkWindow_Type
%%
ignore-glob
*_get_type
diff --git a/sugar/wm.py b/sugar/wm.py
new file mode 100644
index 0000000..f5505c3
--- /dev/null
+++ b/sugar/wm.py
@@ -0,0 +1,38 @@
+# Copyright (C) 2007, Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import gtk
+
+import _sugarext
+
+def get_activity_id(wnck_window)
+ window = gtk.gdk.window_foreign_new(window.get_xid())
+ return _sugarext.x11_get_string_property(
+ window, '_SUGAR_ACTIVITY_ID')
+
+def get_bundle_id(wnck_window, prop):
+ window = gtk.gdk.window_foreign_new(window.get_xid())
+ return _sugarext.x11_get_string_property(
+ window, '_SUGAR_BUNDLE_ID')
+
+def set_activity_id(window, activity_id):
+ _sugarext.x11_set_string_property(
+ window, '_SUGAR_ACTIVITY_ID', activity_id)
+
+def set_bundle_id(window, bundle_id):
+ _sugarext.x11_set_string_property(
+ window, '_SUGAR_BUNDLE_ID', activity_id)