Class for interaction with tags
Methods
Public Class
Public Instance
Public Instance Aliases
| to_s | -> | to_str |
Aliases |
Public Class methods
Find Tag by a given value which can be of following type:
| Fixnum |
Array index of the |
| 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>]
VALUE
subextTagSingFind(VALUE self,
VALUE value)
{
return TagFind(value, False);
}
Find first Tag by a given value which can be of following type:
| Fixnum |
Array index of the |
| 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>
VALUE
subextTagSingFirst(VALUE self,
VALUE value)
{
return TagFind(value, True);
}
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 => []
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;
}
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>
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;
}
Get an array of all visible Tags on all Views.
Subtlext::Tag.visible => [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>] Subtlext::Tag.visible => []
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
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
static VALUE
SubtlextEqualSpaceId(VALUE self,
VALUE other)
{
return SubtlextSpaceship(self, other, "@id");
}
Whether both objects have the same values (based on id)
object1 == object2 => true
static VALUE
SubtlextEqualId(VALUE self,
VALUE other)
{
return SubtlextEqual(self, other, "@id", False);
}
Get an rray of Clients that are tagged with this Tag.
tag.clients => [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>] tag.clients => []
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;
}
Whether both objects have the same values and types (based on id)
object1.eql? object2 => true
static VALUE
SubtlextEqualTypedId(VALUE self,
VALUE other)
{
return SubtlextEqual(self, other, "@id", True);
}
Convert this object to hash.
puts object.hash => 1746246187916025425
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;
}
Remove this Tag from subtle and freeze this object.
tag.kill => nil
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 new Tag object.
tag.update => #<Subtlext::Tag:xxx>
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;
}
Convert this Tag object to string.
puts tag => "subtle"
VALUE
subextTagToString(VALUE self)
{
VALUE name = Qnil;
/* Check ruby object */
GET_ATTR(self, "@name", name);
return name;
}
Get an rray of Views that are tagged with this Tag.
tag.views => [#<Subtlext::Views:xxx>, #<Subtlext::Views:xxx>] tag.views => []
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;
}