Class Subtlext::Gravity < Object

Class for Client placement

Attributes

geometry [R] Geometry
id [R] Gravity id
name [R] WM_NAME

Public class methods

find(value) → Array
[value] → Array

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

Fixnum
Array index of the SUBTLE_GRAVITY_LIST property list.
String
Regexp match against name of Gravities, returns a Gravity on single match or an Array on multiple matches.
Symbol
Either :all for an array of all Views or any string for an exact match.
 1 Subtlext::Gravity.find(1)
 2 => [#<Subtlext::Gravity:xxx>]
 3 
 4 Subtlext::Gravity.find("subtle")
 5 => [#<Subtlext::Gravity:xxx>]
 6 
 7 Subtlext::Gravity[".*"]
 8 => [#<Subtlext::Gravity:xxx>, #<Subtlext::Gravity:xxx>]
 9 
10 Subtlext::Gravity["subtle"]
11 => []
12 
13 Subtlext::Gravity[:center]
14 => [#<Subtlext::Gravity:xxx>]
[show source]
VALUE
subextGravitySingFind(VALUE self,
  VALUE value)
{
  return GravityFind(value, False);
}
first(value) → Subtlext::Gravity or nil

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

Fixnum
Array index of the SUBTLE_GRAVITY_LIST property list.
String
Regexp match against name of Gravities, returns a Gravity on single match or an Array on multiple matches.
Symbol
Either :all for an array of all Views or any string for an exact match.
1 Subtlext::Gravity.first(1)
2 => #<Subtlext::Gravity:xxx>
3 
4 Subtlext::Gravity.first("subtle")
5 => #<Subtlext::Gravity:xxx>
[show source]
VALUE
subextGravitySingFirst(VALUE self,
  VALUE value)
{
  return GravityFind(value, True);
}
list → Array

Get an array of all Gravities based on the SUBTLE_GRAVITIY_LIST property list.

1 Subtlext::Gravity.list
2 => [#<Subtlext::Gravity:xxx>, #<Subtlext::Gravity:xxx>]
3 
4 Subtlext::Gravity.list
5 => []
[show source]
VALUE
subextGravitySingList(VALUE self)
{
  return subextSubtlextFindObjectsGeometry("SUBTLE_GRAVITY_LIST",
    "Gravity", NULL, 0, False);
}
new(name, x, y, width, height) → Subtlext::Gravity
new(name, array) → Subtlext::Gravity
new(name, hash) → Subtlext::Gravity
new(name, string) → Subtlext::Gravity
new(name, geometry) → Subtlext::Gravity

Create a new Gravity object locally without calling save automatically.

The Gravity won’t be useable until save is called.

1 gravity = Subtlext::Gravity.new("center", 0, 0, 100, 100)
2 => #<Subtlext::Gravity:xxx>
[show source]
VALUE
subextGravityInit(int argc,
  VALUE *argv,
  VALUE self)
{
  VALUE data[5] = { Qnil }, geom = Qnil;

  rb_scan_args(argc, argv, "14", &data[0], &data[1], &data[2],
    &data[3], &data[4]);

  /* Check gravity name */
  if(T_STRING != rb_type(data[0]))
    rb_raise(rb_eArgError, "Invalid value type");

  /* Delegate arguments */
  if(RTEST(data[1]))
    {
      VALUE klass = Qnil;

      klass = rb_const_get(mod, rb_intern("Geometry"));
      geom  = rb_funcall2(klass, rb_intern("new"), argc - 1, argv + 1);
    }

  /* Init object */
  rb_iv_set(self, "@id",       Qnil);
  rb_iv_set(self, "@name",     data[0]);
  rb_iv_set(self, "@geometry", geom);

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

  return self;
}

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 array of Clients that have this Gravity.

1 gravity.clients
2 => [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>]
3 
4 tag.clients
5 => []
[show source]
VALUE
subextGravityClients(VALUE self)
{
  int i, nclients = 0;
  Window *clients = NULL;
  VALUE id = Qnil, klass = Qnil, meth = Qnil, array = Qnil, c = 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("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++)
        {
          unsigned long *gravity = NULL;

          /* Get window gravity */
          gravity = (unsigned long *)subSharedPropertyGet(display,
            clients[i], XA_CARDINAL, XInternAtom(display,
            "SUBTLE_CLIENT_GRAVITY", False), NULL);

          /* Check if there are common tags or window is stick */
          if(gravity && FIX2INT(id) == *gravity &&
              !NIL_P(c = rb_funcall(klass, meth, 1, INT2FIX(i))))
            {
              rb_iv_set(c, "@win", LONG2NUM(clients[i]));

              subextClientUpdate(c);

              rb_ary_push(array, c);
            }

          if(gravity) free(gravity);
        }

      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);
}
geometry → Subtlext::Geometry

Get the Gravity Geometry

1 gravity.geometry
2 => #<Subtlext::Geometry:xxx>
[show source]
VALUE
subextGravityGeometryReader(VALUE self)
{
  VALUE geometry = Qnil, name = Qnil;

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

  /* Load on demand */
  if(NIL_P((geometry = rb_iv_get(self, "@geometry"))))
    {
      XRectangle geom = { 0 };

      GravityFindId(RSTRING_PTR(name), NULL, &geom);

      geometry = subextGeometryInstantiate(geom.x, geom.y,
        geom.width, geom.height);
      rb_iv_set(self, "@geometry", geometry);
    }

  return geometry;
}
geometry=(x, y, width, height) → Fixnum
geometry=(array) → Array
geometry=(hash) → Hash
geometry=(string) → String
geometry=(geometry) → Subtlext::Geometry

Set the Gravity Geometry

 1 gravity.geometry = 0, 0, 100, 100
 2 => 0
 3 
 4 gravity.geometry = [ 0, 0, 100, 100 ]
 5 => [ 0, 0, 100, 100 ]
 6 
 7 gravity.geometry = { x: 0, y: 0, width: 100, height: 100 }
 8 => { x: 0, y: 0, width: 100, height: 100 }
 9 
10 gravity.geometry = "0x0+100+100"
11 => "0x0+100+100"
12 
13 gravity.geometry = Subtlext::Geometry(0, 0, 100, 100)
14 => #<Subtlext::Geometry:xxx>
[show source]
VALUE
subextGravityGeometryWriter(int argc,
  VALUE *argv,
  VALUE self)
{
  VALUE klass = Qnil, geom = Qnil;

  /* Check ruby object */
  rb_check_frozen(self);
  subextSubtlextConnect(NULL); ///< Implicit open connection

  /* Delegate arguments */
  klass = rb_const_get(mod, rb_intern("Geometry"));
  geom  = rb_funcall2(klass, rb_intern("new"), argc, argv);

  /* Update geometry */
  if(RTEST(geom)) rb_iv_set(self, "@geometry", geom);

  return geom;
}
geometry_for(screen) → Subtlext::Geometry

Get the Gravity Geometry for given Screen in pixel values.

1 gravity.geometry_for(screen)
2 => #<Subtlext::Geometry:xxx>
[show source]
VALUE
subextGravityGeometryFor(VALUE self,
  VALUE value)
{
  VALUE geom = Qnil;

  /* Check object instance */
  if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("Screen"))))
    {
      XRectangle real = { 0 }, geom_grav = { 0 }, geom_screen = { 0 };

      GravityToRect(self,  &geom_grav);
      GravityToRect(value, &geom_screen);

      /* Calculate real values for screen */
      real.width  = geom_screen.width * geom_grav.width / 100;
      real.height = geom_screen.height * geom_grav.height / 100;
      real.x      = geom_screen.x +
        (geom_screen.width - real.width) * geom_grav.x / 100;
      real.y      = geom_screen.y +
        (geom_screen.height - real.height) * geom_grav.y / 100;

      geom = subextGeometryInstantiate(real.x, real.y, real.width, real.height);
    }
  else rb_raise(rb_eArgError, "Unexpected value-type `%s'",
    rb_obj_classname(value));

  return geom;
}
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 Gravity from subtle and freeze this object.

1 gravity.kill
2 => nil
[show source]
VALUE
subextGravityKill(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_GRAVITY_KILL", data, 32, True);

  rb_obj_freeze(self); ///< Freeze object

  return Qnil;
}
save → Subtlext::Gravity

Save new Gravity object.

1 gravity.save
2 => nil
[show source]
VALUE
subextGravitySave(VALUE self)
{
  int id = -1;
  XRectangle geom = { 0 };
  char *name = NULL;
  VALUE match = Qnil;

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

  /* Find gravity */
  if(-1 == (id = GravityFindId(RSTRING_PTR(match), &name, &geom)))
    {
      SubMessageData data = { { 0, 0, 0, 0, 0 } };
      VALUE geometry = rb_iv_get(self, "@geometry");

      if(NIL_P(geometry = rb_iv_get(self, "@geometry")))
        rb_raise(rb_eStandardError, "No geometry given");

      subextGeometryToRect(geometry, &geom); ///< Get values

      /* Create new gravity */
      snprintf(data.b, sizeof(data.b), "%hdx%hd+%hd+%hd#%s",
        geom.x, geom.y, geom.width, geom.height, RSTRING_PTR(match));
      subSharedMessage(display, DefaultRootWindow(display),
        "SUBTLE_GRAVITY_NEW", data, 8, True);

      id = GravityFindId(RSTRING_PTR(match), NULL, NULL);
    }
  else ///< Update gravity
    {
      VALUE geometry = Qnil;

      geometry = subextGeometryInstantiate(geom.x, geom.y,
        geom.width, geom.height);

      rb_iv_set(self, "@name",    rb_str_new2(name));
      rb_iv_set(self, "@gravity", geometry);

      free(name);
    }

  /* Guess gravity id */
  if(-1 == id)
    {
      int ngravities = 0;
      char **gravities = NULL;

      gravities = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
        XInternAtom(display, "SUBTLE_GRAVITY_LIST", False), &ngravities);

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

      XFreeStringList(gravities);
    }

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

  return self;
}
tiling=(value) → Symbol or nil

Set the tiling mode for gravity

1 gravity.tiling = :vert
2 => :vert
3 
4 gravity.tiling = :horz
5 => :horz
6 
7 gravity.tiling = nil
8 => nil
[show source]
VALUE
subextGravityTilingWriter(VALUE self,
  VALUE value)
{
  int flags = 0;
  VALUE id = Qnil;
  SubMessageData data = { { 0, 0, 0, 0, 0 } };

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

  /* Check value type */
  switch(rb_type(value))
    {
      case T_SYMBOL:
        if(CHAR2SYM("horz")      == value) flags = SUB_EWMH_HORZ;
        else if(CHAR2SYM("vert") == value) flags = SUB_EWMH_VERT;
        break;
      case T_NIL: break;
      default: rb_raise(rb_eArgError, "Unexpected value-type `%s'",
        rb_obj_classname(value));
    }

  /* Assemble message */
  data.l[0] = FIX2INT(id);
  data.l[1] = flags;

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

  return value;
}
to_s ()

Alias for to_str

to_str → String

Convert this Gravity object to string.

1 puts gravity
2 => "TopLeft"
[show source]
VALUE
subextGravityToString(VALUE self)
{
  VALUE name = Qnil;

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

  return name;
}
to_sym → Symbol

Convert this Gravity object to symbol.

1 puts gravity.to_sym
2 => :center
[show source]
VALUE
subextGravityToSym(VALUE self)
{
  VALUE name = Qnil;

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

  return CHAR2SYM(RSTRING_PTR(name));
}