From 5cc9a8c42437376ccef2fbe578a637f8ab3396b5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 01 Jun 2007 18:38:30 +0000 Subject: Bindings to set activity_id and bundle_id hints --- (limited to 'lib') 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 +#include +#include +#include + +#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 + +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__ */ -- cgit v0.9.1