static gboolean
utf8_string_from_results (GetPropertyResults *results,
                          char              **str_p)
{
  *str_p = NULL;
  
  if (!validate_or_free_results (results, 8,
                                 results->display->atom_UTF8_STRING, FALSE))
    return FALSE;

  if (results->n_items > 0 &&
      !g_utf8_validate ((gchar *)results->prop, results->n_items, NULL))
    {
      char *name;

      name = XGetAtomName (results->display->xdisplay, results->xatom);
      meta_warning (_("Property %s on window 0x%lx contained invalid UTF-8\n"),
                    name, results->xwindow);
      meta_XFree (name);
      XFree (results->prop);
      results->prop = NULL;
      
      return FALSE;
    }
  
  *str_p = (char*) results->prop;
  results->prop = NULL;
  
  return TRUE;
}
static gboolean
size_hints_from_results (GetPropertyResults *results,
                         XSizeHints        **hints_p,
                         gulong             *flags_p)
{
  xPropSizeHints *raw;
  XSizeHints *hints;
  
  *hints_p = NULL;
  *flags_p = 0;
  
  if (!validate_or_free_results (results, 32, XA_WM_SIZE_HINTS, FALSE))
    return FALSE;

  if (results->n_items < OldNumPropSizeElements)
    return FALSE;

  raw = (xPropSizeHints*) results->prop;

  hints = ag_Xmalloc (sizeof (XSizeHints));
  
  /* XSizeHints misdeclares these as int instead of long */
  hints->flags = raw->flags;
  hints->x = cvtINT32toInt (raw->x);
  hints->y = cvtINT32toInt (raw->y);
  hints->width = cvtINT32toInt (raw->width);
  hints->height = cvtINT32toInt (raw->height);
  hints->min_width  = cvtINT32toInt (raw->minWidth);
  hints->min_height = cvtINT32toInt (raw->minHeight);
  hints->max_width  = cvtINT32toInt (raw->maxWidth);
  hints->max_height = cvtINT32toInt (raw->maxHeight);
  hints->width_inc  = cvtINT32toInt (raw->widthInc);
  hints->height_inc = cvtINT32toInt (raw->heightInc);
  hints->min_aspect.x = cvtINT32toInt (raw->minAspectX);
  hints->min_aspect.y = cvtINT32toInt (raw->minAspectY);
  hints->max_aspect.x = cvtINT32toInt (raw->maxAspectX);
  hints->max_aspect.y = cvtINT32toInt (raw->maxAspectY);

  *flags_p = (USPosition | USSize | PAllHints);
  if (results->n_items >= NumPropSizeElements)
    {
      hints->base_width= cvtINT32toInt (raw->baseWidth);
      hints->base_height= cvtINT32toInt (raw->baseHeight);
      hints->win_gravity= cvtINT32toInt (raw->winGravity);
      *flags_p |= (PBaseSize | PWinGravity);
    }

  hints->flags &= (*flags_p);	/* get rid of unwanted bits */
  
  XFree (results->prop);
  results->prop = NULL;

  *hints_p = hints;
  
  return TRUE;
}
static gboolean
wm_hints_from_results (GetPropertyResults *results,
                       XWMHints          **hints_p)
{
  XWMHints *hints;
  xPropWMHints *raw;
  
  *hints_p = NULL;
  
  if (!validate_or_free_results (results, 32, XA_WM_HINTS, TRUE))
    return FALSE;  

  /* pre-R3 bogusly truncated window_group, don't fail on them */  
  if (results->n_items < (NumPropWMHintsElements - 1))
    {
      meta_verbose ("WM_HINTS property too short: %d should be %d\n",
                    (int) results->n_items, NumPropWMHintsElements - 1);
      if (results->prop)
        {
          XFree (results->prop);
          results->prop = NULL;
        }
      return FALSE;
    }
  
  hints = ag_Xmalloc0 (sizeof (XWMHints));

  raw = (xPropWMHints*) results->prop;
  
  hints->flags = raw->flags;
  hints->input = (raw->input ? True : False);
  hints->initial_state = cvtINT32toInt (raw->initialState);
  hints->icon_pixmap = raw->iconPixmap;
  hints->icon_window = raw->iconWindow;
  hints->icon_x = cvtINT32toInt (raw->iconX);
  hints->icon_y = cvtINT32toInt (raw->iconY);
  hints->icon_mask = raw->iconMask;
  if (results->n_items >= NumPropWMHintsElements)
    hints->window_group = raw->windowGroup;
  else
    hints->window_group = 0;

  if (results->prop)
    {
      XFree (results->prop);
      results->prop = NULL;
    }

  *hints_p = hints;

  return TRUE;
}
static gboolean
window_from_results (GetPropertyResults *results,
                     Window             *window_p)
{
  if (!validate_or_free_results (results, 32, XA_WINDOW, TRUE))
    return FALSE;  

  *window_p = *(Window*) results->prop;
  XFree (results->prop);
  results->prop = NULL;  
  
  return TRUE;
}
static gboolean
cardinal_with_atom_type_from_results (GetPropertyResults *results,
                                      Atom                prop_type,
                                      gulong             *cardinal_p)
{
  if (!validate_or_free_results (results, 32, prop_type, TRUE))
    return FALSE;  

  *cardinal_p = *(gulong*) results->prop;
  XFree (results->prop);
  results->prop = NULL;  
  
  return TRUE;
}
static gboolean
latin1_string_from_results (GetPropertyResults *results,
                            char              **str_p)
{
  *str_p = NULL;
  
  if (!validate_or_free_results (results, 8, XA_STRING, FALSE))
    return FALSE;

  *str_p = (char*) results->prop;
  results->prop = NULL;
  
  return TRUE;
}
static gboolean
cardinal_list_from_results (GetPropertyResults *results,
                            gulong            **cardinals_p,
                            int                *n_cardinals_p)
{
  if (!validate_or_free_results (results, 32, XA_CARDINAL, FALSE))
    return FALSE;  

  *cardinals_p = (gulong*) results->prop;
  *n_cardinals_p = results->n_items;
  results->prop = NULL;
  
  return TRUE;
}
static gboolean
atom_list_from_results (GetPropertyResults *results,
                        Atom              **atoms_p,
                        int                *n_atoms_p)
{
  if (!validate_or_free_results (results, 32, XA_ATOM, FALSE))
    return FALSE;  

  *atoms_p = (Atom*) results->prop;
  *n_atoms_p = results->n_items;
  results->prop = NULL;  
  
  return TRUE;
}
static gboolean
counter_from_results (GetPropertyResults *results,
                      XSyncCounter       *counter_p)
{
  if (!validate_or_free_results (results, 32,
                                 XA_CARDINAL,
                                 TRUE))
    return FALSE;  

  *counter_p = *(XSyncCounter*) results->prop;
  XFree (results->prop);
  results->prop = NULL;
  
  return TRUE;
}
Esempio n. 10
0
static gboolean
cardinal_with_atom_type_from_results (GetPropertyResults *results,
                                      Atom                prop_type,
                                      gulong             *cardinal_p)
{
    if (!validate_or_free_results (results, 32, prop_type, TRUE))
        return FALSE;

    *cardinal_p = *(gulong*) results->prop;
#if GLIB_SIZEOF_LONG == 8
    /* Xlib sign-extends format=32 items, but we want them unsigned */
    *cardinal_p &= 0xffffffff;
#endif
    XFree (results->prop);
    results->prop = NULL;

    return TRUE;
}
static gboolean
class_hint_from_results (GetPropertyResults *results,
                         XClassHint         *class_hint)
{
  int len_name, len_class;
  
  class_hint->res_class = NULL;
  class_hint->res_name = NULL;
  
  if (!validate_or_free_results (results, 8, XA_STRING, FALSE))
    return FALSE;
  
  len_name = strlen ((char *) results->prop);
  if (! (class_hint->res_name = ag_Xmalloc (len_name+1)))
    {
      XFree (results->prop);
      results->prop = NULL;
      return FALSE;
    }
  
  strcpy (class_hint->res_name, (char *)results->prop);

  if (len_name == (int) results->n_items)
    len_name--;
  
  len_class = strlen ((char *)results->prop + len_name + 1);
  
  if (! (class_hint->res_class = ag_Xmalloc(len_class+1)))
    {
      XFree(class_hint->res_name);
      class_hint->res_name = NULL;
      XFree (results->prop);
      results->prop = NULL;
      return FALSE;
    }
  
  strcpy (class_hint->res_class, (char *)results->prop + len_name + 1);

  XFree (results->prop);
  results->prop = NULL;
  
  return TRUE;
}
Esempio n. 12
0
static gboolean
cardinal_list_from_results (GetPropertyResults *results,
                            gulong            **cardinals_p,
                            int                *n_cardinals_p)
{
    if (!validate_or_free_results (results, 32, XA_CARDINAL, FALSE))
        return FALSE;

    *cardinals_p = (gulong*) results->prop;
    *n_cardinals_p = results->n_items;
    results->prop = NULL;

#if GLIB_SIZEOF_LONG == 8
    /* Xlib sign-extends format=32 items, but we want them unsigned */
    {
        int i;

        for (i = 0; i < *n_cardinals_p; i++)
            (*cardinals_p)[i] = (*cardinals_p)[i] & 0xffffffff;
    }
#endif

    return TRUE;
}
/* this one freakishly returns g_malloc memory */
static gboolean
utf8_list_from_results (GetPropertyResults *results,
                        char             ***str_p,
                        int                *n_str_p)
{
  int i;
  int n_strings;
  char **retval;
  const char *p;
  
  *str_p = NULL;
  *n_str_p = 0;

  if (!validate_or_free_results (results, 8,
                                 results->display->atom_UTF8_STRING, FALSE))
    return FALSE;
  
  /* I'm not sure this is right, but I'm guessing the
   * property is nul-separated
   */
  i = 0;
  n_strings = 0;
  while (i < (int) results->n_items)
    {
      if (results->prop[i] == '\0')
        ++n_strings;
      ++i;
    }

  if (results->prop[results->n_items - 1] != '\0')
    ++n_strings;
 
  /* we're guaranteed that results->prop has a nul on the end
   * by XGetWindowProperty
   */
  
  retval = g_new0 (char*, n_strings + 1);

  p = (char *)results->prop;
  i = 0;
  while (i < n_strings)
    {
      if (!g_utf8_validate (p, -1, NULL))
        {
          char *name;

          meta_error_trap_push (results->display);
          name = XGetAtomName (results->display->xdisplay, results->xatom);
          meta_error_trap_pop (results->display, TRUE);
          meta_warning (_("Property %s on window 0x%lx contained invalid UTF-8 for item %d in the list\n"),
                        name, results->xwindow, i);
          meta_XFree (name);
          meta_XFree (results->prop);
          results->prop = NULL;
          
          g_strfreev (retval);
          return FALSE;
        }

      retval[i] = g_strdup (p);
      
      p = p + strlen (p) + 1;
      ++i;
    }
  
  *str_p = retval;
  *n_str_p = i;

  meta_XFree (results->prop);
  results->prop = NULL;

  return TRUE;
}