Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2007-06-01 18:38:30 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2007-06-01 18:38:30 (GMT)
commit5cc9a8c42437376ccef2fbe578a637f8ab3396b5 (patch)
treeb6494791f0382349b04d0605bd3da87469c233f4 /sugar
parentd4bd7a5d05f251cdf90c0f656f0498df05b4e5b1 (diff)
Bindings to set activity_id and bundle_id hints
Diffstat (limited to 'sugar')
-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
5 files changed, 122 insertions, 6 deletions
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)