class Subtlext::Tag

  1. ../../../../../tmp/subtlext.c
Superclass: Object

Class for interaction with tags

Methods

Public Class

  1. find
  2. first
  3. list
  4. new
  5. visible

Public Instance

  1. <=>
  2. ==
  3. clients
  4. eql?
  5. hash
  6. id
  7. kill
  8. name
  9. save
  10. to_str
  11. views

Public Instance Aliases

to_s -> to_str

Aliases

Attributes

id [R]

Tag id

name [R]

Name of the tag

Public Class methods

find(value) -> Array

Find Tag by a given value which can be of following type:

Fixnum

Array index of the SUBTLE_TAG_LIST property list.

String

Regexp match against name of Tags, returns a Tag on single match or an Array on multiple matches.

Symbol

Either :all for an array of all Tags or any string for an exact match.

Subtlext::Tag.find(1)
=> [#<Subtlext::Tag:xxx>]
Subtlext::Tag.find("subtle")
=> [#<Subtlext::Tag:xxx>]

Subtlext::Tag[".*"]
=> [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]

Subtlext::Tag["subtle"]
=> []

Subtlext::Tag[:terms]
=> [#<Subtlext::Tag:xxx>]
[show source]
VALUE
subextTagSingFind(VALUE self,
  VALUE value)
{
  return TagFind(value, False);
}
first(value) -> Subtlext::Tag or nil

Find first Tag by a given value which can be of following type:

Fixnum

Array index of the SUBTLE_TAG_LIST property list.

String

Regexp match against name of Tags, returns a Tag on single match or an Array on multiple matches.

Symbol

Either :all for an array of all Tags or any string for an exact match.

Subtlext::Tag.first(1)
=> #<Subtlext::Tag:xxx>
Subtlext::Tag.first("subtle")
=> #<Subtlext::Tag:xxx>
[show source]
VALUE
subextTagSingFirst(VALUE self,
  VALUE value)
{
  return TagFind(value, True);
}
list -> Array

Get an array of all Tags based on the SUBTLE_TAG_LIST property list.

Subtlext::Tag.list
=> [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]
Subtlext::Tag.list
=> []
[show source]
VALUE
subextTagSingList(VALUE self)
{
  int i, ntags = 0;
  char **tags = NULL;
  VALUE meth = Qnil, klass = Qnil, array = Qnil;

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

  /* Fetch data */
  meth  = rb_intern("new");
  klass = rb_const_get(mod, rb_intern("Tag"));
  array = rb_ary_new();

  /* Check results */
  if((tags = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
      XInternAtom(display, "SUBTLE_TAG_LIST", False), &ntags)))
    {
      for(i = 0; i < ntags; i++)
        {
          VALUE t = rb_funcall(klass, meth, 1, rb_str_new2(tags[i]));

          rb_iv_set(t, "@id", INT2FIX(i));
          rb_ary_push(array, t);
        }

      XFreeStringList(tags);
    }

  return array;
}
new(name) -> Subtlext::Tag

Create new Tag object locally without calling save automatically.

The Tag won't be useable until save is called.

tag = Subtlext::Tag.new("subtle")
=> #<Subtlext::Tag:xxx>
[show source]
VALUE
subextTagInit(VALUE self,
  VALUE name)
{
  if(T_STRING != rb_type(name))
    rb_raise(rb_eArgError, "Unexpected value-type `%s'",
      rb_obj_classname(name));

  /* Init object */
  rb_iv_set(self, "@id",   Qnil);
  rb_iv_set(self, "@name", name);

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

  return self;
}
visible -> Array

Get an array of all visible Tags on all Views.

Subtlext::Tag.visible
=> [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]
Subtlext::Tag.visible
=> []
[show source]
VALUE
subextTagSingVisible(VALUE self)
{
  int i, ntags = 0;
  char **tags = NULL;
  unsigned long *visible = NULL;
  VALUE meth = Qnil, klass = Qnil, array = Qnil, t = Qnil;

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

  /* Fetch data */
  meth    = rb_intern("new");
  klass   = rb_const_get(mod, rb_intern("Tag"));
  array   = rb_ary_new();
  tags    = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
    XInternAtom(display, "SUBTLE_TAG_LIST", False), &ntags);
  visible = (unsigned long *)subSharedPropertyGet(display,
    DefaultRootWindow(display), XA_CARDINAL, XInternAtom(display,
    "SUBTLE_VISIBLE_TAGS", False), NULL);

  /* Populate array */
  if(tags && visible)
    {
      for(i = 0; i < ntags; i++)
        {
          /* Create tag on match */
          if(*visible & (1L << (i + 1)) &&
              !NIL_P(t = rb_funcall(klass, meth, 1, rb_str_new2(tags[i]))))
            {
              rb_iv_set(t, "@id", INT2FIX(i));
              rb_ary_push(array, t);
            }
        }

    }

  if(tags)    XFreeStringList(tags);
  if(visible) free(visible);

  return array;
}

Public Instance methods

<=>(other) -> -1, 0 or 1

Whether both objects have the same value. Returns -1, 0 or 1 when self is less than, equal to or grater than other. (based on id)

object1 <=> object2
=> 0
[show source]
static VALUE
SubtlextEqualSpaceId(VALUE self,
  VALUE other)
{
  return SubtlextSpaceship(self, other, "@id");
}
==(other) -> True or False

Whether both objects have the same values (based on id)

object1 == object2
=> true
[show source]
static VALUE
SubtlextEqualId(VALUE self,
  VALUE other)
{
  return SubtlextEqual(self, other, "@id", False);
}
clients -> Array

Get an rray of Clients that are tagged with this Tag.

tag.clients
=> [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>]
tag.clients
=> []
[show source]
VALUE
subextTagClients(VALUE self)
{
  int i, nclients = 0;
  Window *clients = NULL;
  unsigned long *tags = NULL;
  VALUE id = Qnil, array = Qnil, klass = Qnil, meth = Qnil, c = Qnil;

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

  /* Fetch data */
  klass   = rb_const_get(mod, rb_intern("Client"));
  meth    = rb_intern("new");
  array   = rb_ary_new();
  clients = subextSubtlextWindowList("_NET_CLIENT_LIST", &nclients);

  /* Check results */
  if(clients)
    {
      for(i = 0; i < nclients; i++)
        {
          if((tags = (unsigned long *)subSharedPropertyGet(display,
              clients[i], XA_CARDINAL, XInternAtom(display,
              "SUBTLE_CLIENT_TAGS", False), NULL)))
            {
              /* Check if tag id matches */
              if(*tags & (1L << (FIX2INT(id) + 1)))
                {
                  /* Create new client */
                  if(!NIL_P(c = rb_funcall(klass, meth, 1,
                      LONG2NUM(clients[i]))))
                    {
                      subextClientUpdate(c);

                      rb_ary_push(array, c);
                    }
                }
            }
        }

      free(clients);
    }

  return array;
}
eql?(other) -> True or False

Whether both objects have the same values and types (based on id)

object1.eql? object2
=> true
[show source]
static VALUE
SubtlextEqualTypedId(VALUE self,
  VALUE other)
{
  return SubtlextEqual(self, other, "@id", True);
}
hash -> Hash

Convert this object to hash.

puts object.hash
=> 1746246187916025425
[show source]
static VALUE
SubtlextHash(VALUE self)
{
  VALUE str = Qnil, id = rb_intern("to_str");

  /* Convert to string */
  if(rb_respond_to(self, id))
    str = rb_funcall(self, id, 0, Qnil);

  return T_STRING == rb_type(str) ? INT2FIX(rb_str_hash(str)) : Qnil;
}
kill -> nil

Remove this Tag from subtle and freeze this object.

tag.kill
=> nil
[show source]
VALUE
subextTagKill(VALUE self)
{
  VALUE id = Qnil;
  SubMessageData data = { { 0, 0, 0, 0, 0 } };

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

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

  /* Send message */
  data.l[0] = FIX2INT(id);

  subSharedMessage(display, DefaultRootWindow(display),
    "SUBTLE_TAG_KILL", data, 32, True);

  rb_obj_freeze(self); ///< Freeze object

  return Qnil;
}
save -> Subtlext::Tag

Save new Tag object.

tag.update
=> #<Subtlext::Tag:xxx>
[show source]
VALUE
subextTagSave(VALUE self)
{
  int id = -1;
  VALUE name = Qnil;

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

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

  /* Create tag if needed */
  if(-1 == (id = subextSubtlextFindString("SUBTLE_TAG_LIST",
      RSTRING_PTR(name), NULL, SUB_MATCH_EXACT)))
    {
      SubMessageData data = { { 0, 0, 0, 0, 0 } };

      snprintf(data.b, sizeof(data.b), "%s", RSTRING_PTR(name));
      subSharedMessage(display, DefaultRootWindow(display),
        "SUBTLE_TAG_NEW", data, 8, True);

      id = subextSubtlextFindString("SUBTLE_TAG_LIST",
        RSTRING_PTR(name), NULL, SUB_MATCH_EXACT);
    }

  /* Guess tag id */
  if(-1 == id)
    {
      int ntags = 0;
      char **tags = NULL;

      /* Get names of tags */
      if((tags = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
          XInternAtom(display, "SUBTLE_TAG_LIST", False), &ntags)))
        {

          id = ntags; ///< New id should be last

          XFreeStringList(tags);
        }
    }

  /* Set properties */
  rb_iv_set(self, "@id", INT2FIX(id));

  return self;
}
to_str -> String

Convert this Tag object to string.

puts tag
=> "subtle"
[show source]
VALUE
subextTagToString(VALUE self)
{
  VALUE name = Qnil;

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

  return name;
}
views -> Array

Get an rray of Views that are tagged with this Tag.

tag.views
=> [#<Subtlext::Views:xxx>, #<Subtlext::Views:xxx>]
tag.views
=> []
[show source]
VALUE
subextTagViews(VALUE self)
{
  int i, nnames = 0;
  char **names = NULL;
  unsigned long *tags = NULL;
  VALUE id = Qnil, array = Qnil, klass = Qnil, meth = Qnil, v = Qnil;

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

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

  /* Fetch data */
  klass  = rb_const_get(mod, rb_intern("View"));
  meth   = rb_intern("new");
  array  = rb_ary_new();
  names  = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
    XInternAtom(display, "_NET_DESKTOP_NAMES", False), &nnames);
  tags   = (unsigned long *)subSharedPropertyGet(display,
    DefaultRootWindow(display), XA_CARDINAL,
    XInternAtom(display, "SUBTLE_VIEW_TAGS", False), NULL);

  /* Check results */
  if(names && tags)
    {
      for(i = 0; i < nnames; i++)
        {
          /* Check if tag id matches */
          if(tags[i] & (1L << (FIX2INT(id) + 1)))
            {
              /* Create new view */
              if(!NIL_P(v = rb_funcall(klass, meth, 1, rb_str_new2(names[i]))))
                {
                  rb_iv_set(v, "@id",  INT2FIX(i));
                  rb_ary_push(array, v);
                }
            }
        }
    }

  if(names) XFreeStringList(names);
  if(tags)  free(tags);

  return array;
}