Exemplo n.º 1
0
/* ViewFind {{{ */
static VALUE
ViewFind(VALUE value,
  int first)
{
  int flags = 0;
  VALUE parsed = Qnil;
  char buf[50] = { 0 };

  subextSubtlextConnect(NULL); ///< Implicit open connection

  /* Check object type */
  switch(rb_type(parsed = subextSubtlextParse(
      value, buf, sizeof(buf), &flags)))
    {
      case T_SYMBOL:
        if(CHAR2SYM("visible") == parsed)
          return subextViewSingVisible(Qnil);
        else if(CHAR2SYM("all") == parsed)
          return subextViewSingList(Qnil);
        else if(CHAR2SYM("current") == parsed)
          return subextViewSingCurrent(Qnil);
        break;
      case T_OBJECT:
        if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("View"))))
          return parsed;
    }

  return subextSubtlextFindObjects("_NET_DESKTOP_NAMES", "View",
    buf, flags, first);
} /* }}} */
Exemplo n.º 2
0
/* SubletFind {{{ */
static VALUE
SubletFind(VALUE value,
  int first)
{
  int flags = 0;
  VALUE parsed = Qnil;
  char buf[50] = { 0 };

  subextSubtlextConnect(NULL); ///< Implicit open connection

  /* Check object type */
  switch(rb_type(parsed = subextSubtlextParse(
      value, buf, sizeof(buf), &flags)))
    {
      case T_SYMBOL:
        if(CHAR2SYM("all") == parsed)
          return subextSubletSingList(Qnil);
        break;
      case T_OBJECT:
        if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("Sublet"))))
          return parsed;
    }

  return subextSubtlextFindObjectsGeometry("SUBTLE_SUBLET_LIST",
    "Sublet", buf, flags, first);
} /* }}} */
Exemplo n.º 3
0
VALUE
subGravitySingFind(VALUE self,
  VALUE value)
{
  int flags = 0;
  VALUE parsed = Qnil;
  char buf[50] = { 0 };

  subSubtlextConnect(NULL); ///< Implicit open connection

  /* Check object type */
  switch(rb_type(parsed = subSubtlextParse(
      value, buf, sizeof(buf), &flags)))
    {
      case T_SYMBOL:
        if(CHAR2SYM("all") == parsed)
          return subGravitySingAll(Qnil);
        break;
      case T_OBJECT:
        if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("Gravity"))))
          return parsed;
    }

  return GravityFind(buf, flags);
} /* }}} */
Exemplo n.º 4
0
VALUE
subGravityToSym(VALUE self)
{
  VALUE name = Qnil;

  /* Check ruby object */
  GET_ATTR(self, "@name", name);

  return CHAR2SYM(RSTRING_PTR(name));
} /* }}} */
Exemplo n.º 5
0
VALUE
subColorToHash(VALUE self)
{
  VALUE klass = Qnil, hash = Qnil, red = Qnil, green = Qnil, blue = Qnil;

  /* Check ruby object */
  GET_ATTR(self, "@red",   red);
  GET_ATTR(self, "@green", green);
  GET_ATTR(self, "@blue",  blue);

  /* Create new hash */
  klass = rb_const_get(rb_mKernel, rb_intern("Hash"));
  hash  = rb_funcall(klass, rb_intern("new"), 0, NULL);

  /* Set values */
  rb_hash_aset(hash, CHAR2SYM("red"),   red);
  rb_hash_aset(hash, CHAR2SYM("green"), green);
  rb_hash_aset(hash, CHAR2SYM("blue"),  blue);

  return hash;
} /* }}} */
Exemplo n.º 6
0
Arquivo: subtle.c Projeto: guns/subtle
VALUE
subSubtleSingColors(VALUE self)
{
  int i;
  unsigned long ncolors = 0, *colors = NULL;
  VALUE meth = Qnil, klass = Qnil, hash = Qnil;
  const char *names[] = {
    "title_fg",            "title_bg",             "title_bo_top",
    "title_bo_right",      "title_bo_bottom",      "title_bo_left",
    "view_fg",             "view_bg",              "view_bo_top",
    "view_bo_right",       "view_bo_bottom",       "view_bo_left",
    "focus_fg",            "focus_bg",             "focus_bo_top",
    "focus_bo_right",      "focus_bo_bottom",      "focus_bo_left",
    "urgent_fg",           "urgent_bg",            "urgent_bo_top",
    "urgent_bo_right",     "urgent_bo_bottom",     "urgent_bo_left",
    "occupied_fg",         "occupied_bg",          "occupied_bo_top",
    "occupied_bo_right",   "occupied_bo_bottom",   "occupied_bo_left",
    "unoccupied_fg",       "unoccupied_bg",        "unoccupied_bo_top",
    "unoccupied_bo_right", "unoccupied_bo_bottom", "unoccupied_bo_left",
    "sublets_fg",         "sublets_bg",            "sublets_bo_top",
    "sublets_bo_right",   "sublets_bo_bottom",     "sublets_bo_left",
    "separator_fg",       "separator_bg",          "separator_bo_top",
    "separator_bo_right", "separator_bo_bottom",   "separator_bo_left",
    "client_active",      "client_inactive",
    "panel_top",          "panel_bottom",
    "stipple",            "background"
  };

  subSubtlextConnect(NULL); ///< Implicit open connection

  /* Fetch data */
  meth  = rb_intern("new");
  klass = rb_const_get(mod, rb_intern("Color"));
  hash  = rb_hash_new();

  /* Check result */
  if((colors = (unsigned long *)subSharedPropertyGet(display,
      DefaultRootWindow(display), XA_CARDINAL,
      XInternAtom(display, "SUBTLE_COLORS", False), &ncolors)))
    {
      for(i = 0; i < ncolors && i < LENGTH(names); i++)
        {
          VALUE c = rb_funcall(klass, meth, 1, LONG2NUM(colors[i]));

          rb_hash_aset(hash, CHAR2SYM(names[i]), c);
        }

      free(colors);
    }

  return hash;
} /* }}} */
Exemplo n.º 7
0
/* subColorPixel {{{ */
unsigned long
subColorPixel(VALUE red,
  VALUE green,
  VALUE blue,
  XColor *xcolor)
{
  XColor xcol = { 0 };

  /* Check object type */
  switch(rb_type(red))
    {
      case T_FIXNUM:
      case T_BIGNUM:
        if(NIL_P(green) && NIL_P(blue))
          {
            xcol.pixel = NUM2LONG(red);

            ColorPixelToRGB(&xcol);
          }
        else
          {
            xcol.red   = NUM2INT(red);
            xcol.green = NUM2INT(green);
            xcol.blue  = NUM2INT(blue);

            ColorRGBToPixel(&xcol);
          }
        break;
      case T_STRING:
        xcol.pixel = subSharedParseColor(display, RSTRING_PTR(red));

        ColorPixelToRGB(&xcol);
        break;
      case T_ARRAY:
        if(3 == FIX2INT(rb_funcall(red, rb_intern("size"), 0, NULL)))
          {
            xcol.red   = NUM2INT(rb_ary_entry(red, 0));
            xcol.green = NUM2INT(rb_ary_entry(red, 1));
            xcol.blue  = NUM2INT(rb_ary_entry(red, 2));

            ColorRGBToPixel(&xcol);
          }
        break;
      case T_HASH:
          {
            xcol.red   = NUM2INT(rb_hash_lookup(red, CHAR2SYM("red")));
            xcol.green = NUM2INT(rb_hash_lookup(red, CHAR2SYM("green")));
            xcol.blue  = NUM2INT(rb_hash_lookup(red, CHAR2SYM("blue")));

            ColorRGBToPixel(&xcol);
          }
        break;
      case T_OBJECT:
          {
            VALUE klass = rb_const_get(mod, rb_intern("Color"));

            /* Check object instance */
            if(rb_obj_is_instance_of(red, klass))
              {
                xcol.red   = NUM2INT(rb_iv_get(red, "@red"));
                xcol.green = NUM2INT(rb_iv_get(red, "@green"));
                xcol.blue  = NUM2INT(rb_iv_get(red, "@blue"));
                xcol.pixel = NUM2LONG(rb_iv_get(red, "@pixel"));
              }
          }
        break;
      default:
        rb_raise(rb_eArgError, "Unexpected value-type `%s'",
          rb_obj_classname(red));
    }

  if(xcolor)
    {
      xcolor->red   = xcol.red;
      xcolor->green = xcol.green;
      xcolor->blue  = xcol.blue;
      xcolor->pixel = xcol.pixel;
    }


  return xcol.pixel;
} /* }}} */