summaryrefslogtreecommitdiff
path: root/src/xprops.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xprops.c')
-rw-r--r--src/xprops.c217
1 files changed, 207 insertions, 10 deletions
diff --git a/src/xprops.c b/src/xprops.c
index f60b85e..f5cd838 100644
--- a/src/xprops.c
+++ b/src/xprops.c
@@ -30,7 +30,8 @@ check_type_and_format (MetaDisplay *display,
Window xwindow,
Atom xatom,
int expected_format,
- Atom expected_type,
+ Atom expected_type,
+ int n_items, /* -1 to not check this */
int format,
Atom type)
{
@@ -39,8 +40,9 @@ check_type_and_format (MetaDisplay *display,
char *prop_name;
if (expected_format == format &&
- expected_type == type)
- return TRUE;
+ expected_type == type &&
+ (n_items < 0 || n_items > 0))
+ return TRUE;
meta_error_trap_push (display);
type_name = XGetAtomName (display->xdisplay, type);
@@ -48,13 +50,13 @@ check_type_and_format (MetaDisplay *display,
prop_name = XGetAtomName (display->xdisplay, xatom);
meta_error_trap_pop (display);
- meta_warning (_("Window 0x%lx has property %s that was expected to have type %s format %d and actually has type %s format %d\n"),
+ meta_warning (_("Window 0x%lx has property %s that was expected to have type %s format %d and actually has type %s format %d n_items %d\n"),
xwindow,
prop_name ? prop_name : "(bad atom)",
expected_name ? expected_name : "(bad atom)",
expected_format,
type_name ? type_name : "(bad atom)",
- format);
+ format, n_items);
if (type_name)
XFree (type_name);
@@ -86,7 +88,8 @@ meta_prop_get_atom_list (MetaDisplay *display,
if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
0, G_MAXLONG,
False, XA_ATOM, &type, &format, &n_atoms,
- &bytes_after, (guchar **)&atoms) != Success)
+ &bytes_after, (guchar **)&atoms) != Success ||
+ type == None)
{
meta_error_trap_pop (display);
return FALSE;
@@ -96,7 +99,7 @@ meta_prop_get_atom_list (MetaDisplay *display,
return FALSE;
if (!check_type_and_format (display, xwindow, xatom, 32, XA_ATOM,
- format, type))
+ -1, format, type))
{
XFree (atoms);
return FALSE;
@@ -128,7 +131,8 @@ meta_prop_get_cardinal_list (MetaDisplay *display,
if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
0, G_MAXLONG,
False, XA_CARDINAL, &type, &format, &n_cardinals,
- &bytes_after, (guchar **)&cardinals) != Success)
+ &bytes_after, (guchar **)&cardinals) != Success ||
+ type == None)
{
meta_error_trap_pop (display);
return FALSE;
@@ -138,7 +142,7 @@ meta_prop_get_cardinal_list (MetaDisplay *display,
return FALSE;
if (!check_type_and_format (display, xwindow, xatom, 32, XA_CARDINAL,
- format, type))
+ -1, format, type))
{
XFree (cardinals);
return FALSE;
@@ -170,7 +174,8 @@ meta_prop_get_motif_hints (MetaDisplay *display,
if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
0, EXPECTED_ITEMS,
False, AnyPropertyType, &type, &format, &n_items,
- &bytes_after, (guchar **)&hints) != Success)
+ &bytes_after, (guchar **)&hints) != Success ||
+ type == None)
{
meta_error_trap_pop (display);
return FALSE;
@@ -190,3 +195,195 @@ meta_prop_get_motif_hints (MetaDisplay *display,
return TRUE;
}
+
+gboolean
+meta_prop_get_latin1_string (MetaDisplay *display,
+ Window xwindow,
+ Atom xatom,
+ char **str_p)
+{
+ Atom type;
+ int format;
+ gulong bytes_after;
+ guchar *str;
+ gulong n_items;
+
+ *str_p = NULL;
+
+ meta_error_trap_push (display);
+ if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
+ 0, G_MAXLONG,
+ False, XA_STRING, &type, &format, &n_items,
+ &bytes_after, (guchar **)&str) != Success ||
+ type == None)
+ {
+ meta_error_trap_pop (display);
+ return FALSE;
+ }
+
+ if (meta_error_trap_pop (display) != Success)
+ return FALSE;
+
+ if (!check_type_and_format (display, xwindow, xatom, 8, XA_STRING,
+ -1, format, type))
+ {
+ XFree (str);
+ return FALSE;
+ }
+
+ *str_p = str;
+
+ return TRUE;
+}
+
+gboolean
+meta_prop_get_utf8_string (MetaDisplay *display,
+ Window xwindow,
+ Atom xatom,
+ char **str_p)
+{
+ Atom type;
+ int format;
+ gulong bytes_after;
+ guchar *str;
+ gulong n_items;
+
+ *str_p = NULL;
+
+ meta_error_trap_push (display);
+ if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
+ 0, G_MAXLONG,
+ False, display->atom_utf8_string,
+ &type, &format, &n_items,
+ &bytes_after, (guchar **)&str) != Success ||
+ type == None)
+ {
+ meta_error_trap_pop (display);
+ return FALSE;
+ }
+
+ if (meta_error_trap_pop (display) != Success)
+ return FALSE;
+
+ if (!check_type_and_format (display, xwindow, xatom, 8,
+ display->atom_utf8_string,
+ -1, format, type))
+ {
+ XFree (str);
+ return FALSE;
+ }
+
+ if (!g_utf8_validate (str, n_items, NULL))
+ {
+ char *name;
+
+ name = XGetAtomName (display->xdisplay, xatom);
+ meta_warning (_("Property %s on window 0x%lx contained invalid UTF-8\n"),
+ name, xwindow);
+ XFree (name);
+ XFree (str);
+
+ return FALSE;
+ }
+
+ *str_p = str;
+
+ return TRUE;
+}
+
+gboolean
+meta_prop_get_window (MetaDisplay *display,
+ Window xwindow,
+ Atom xatom,
+ Window *window_p)
+{
+ Atom type;
+ int format;
+ gulong bytes_after;
+ Window *window;
+ gulong n_items;
+
+ *window_p = None;
+
+ meta_error_trap_push (display);
+ if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
+ 0, G_MAXLONG,
+ False, XA_WINDOW, &type, &format, &n_items,
+ &bytes_after, (guchar **)&window) != Success ||
+ type == None)
+ {
+ meta_error_trap_pop (display);
+ return FALSE;
+ }
+
+ if (meta_error_trap_pop (display) != Success)
+ return FALSE;
+
+ if (!check_type_and_format (display, xwindow, xatom, 32, XA_WINDOW,
+ -1, format, type))
+ {
+ XFree (window);
+ return FALSE;
+ }
+
+ *window_p = *window;
+
+ XFree (window);
+
+ return TRUE;
+}
+
+gboolean
+meta_prop_get_cardinal (MetaDisplay *display,
+ Window xwindow,
+ Atom xatom,
+ gulong *cardinal_p)
+
+{
+ return meta_prop_get_cardinal_with_atom_type (display, xwindow, xatom,
+ XA_CARDINAL, cardinal_p);
+}
+
+gboolean
+meta_prop_get_cardinal_with_atom_type (MetaDisplay *display,
+ Window xwindow,
+ Atom xatom,
+ Atom prop_type,
+ gulong *cardinal_p)
+{
+ Atom type;
+ int format;
+ gulong bytes_after;
+ gulong *cardinal;
+ gulong n_items;
+
+ *cardinal_p = 0;
+
+ meta_error_trap_push (display);
+ if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
+ 0, G_MAXLONG,
+ False, prop_type, &type, &format, &n_items,
+ &bytes_after, (guchar **)&cardinal) != Success ||
+ type == None)
+ {
+ meta_error_trap_pop (display);
+ return FALSE;
+ }
+
+ if (meta_error_trap_pop (display) != Success)
+ return FALSE;
+
+ if (!check_type_and_format (display, xwindow, xatom, 32, prop_type,
+ -1, format, type))
+ {
+ XFree (cardinal);
+ return FALSE;
+ }
+
+ *cardinal_p = *cardinal;
+
+ XFree (cardinal);
+
+ return TRUE;
+}
+