Class Subtlext::Tag < Object

Class for interaction with tags

Methods

public class

  1. find
    [value]
  2. first
  3. list
  4. new
  5. visible

public instance

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

Attributes

id [R] Gravity id
name [R] WM_NAME

Public class methods

find(value) → Array
[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.
 1 Subtlext::Tag.find(1)
 2 => [#<Subtlext::Tag:xxx>]
 3 
 4 Subtlext::Tag.find("subtle")
 5 => [#<Subtlext::Tag:xxx>]
 6 
 7 Subtlext::Tag[".*"]
 8 => [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]
 9 
10 Subtlext::Tag["subtle"]
11 => []
12 
13 Subtlext::Tag[:terms]
14 => [#<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.
1 Subtlext::Tag.first(1)
2 => #<Subtlext::Tag:xxx>
3 
4 Subtlext::Tag.first("subtle")
5 => #<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.

1 Subtlext::Tag.list
2 => [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]
3 
4 Subtlext::Tag.list
5 => []
[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.

1 tag = Subtlext::Tag.new("subtle")
2 => #<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.

1 Subtlext::Tag.visible
2 => [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]
3 
4 Subtlext::Tag.visible
5 => []
[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)

1 object1 <=> object2
2 => 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)

1 object1 == object2
2 => 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.

1 tag.clients
2 => [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>]
3 
4 tag.clients
5 => []
[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)

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

Convert this object to hash.

1 puts object.hash
2 => 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.

1 tag.kill
2 => 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.

1 tag.update
2 => #<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_s ()

Alias for to_str

to_str → String

Convert this Tag object to string.

1 puts tag
2 => "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.

1 tag.views
2 => [#<Subtlext::Views:xxx>, #<Subtlext::Views:xxx>]
3 
4 tag.views
5 => []
[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;
}