class Subtlext::Gravity

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

Class for Client placement

Public Instance Aliases

to_s -> to_str

Aliases

Attributes

id [R]

Gravity id

name [R]

Name of the gravity

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.

Subtlext::Gravity.find(1)
=> [#<Subtlext::Gravity:xxx>]

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

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

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

Subtlext::Gravity[:center]
=> [#<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.

Subtlext::Gravity.first(1)
=> #<Subtlext::Gravity:xxx>

Subtlext::Gravity.first("subtle")
=> #<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.

Subtlext::Gravity.list
=> [#<Subtlext::Gravity:xxx>, #<Subtlext::Gravity:xxx>]

Subtlext::Gravity.list
=> []
[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.

gravity = Subtlext::Gravity.new("center", 0, 0, 100, 100)
=> #<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)

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

gravity.clients
=> [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>]

tag.clients
=> []
[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)

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

Get the Gravity Geometry

gravity.geometry
=> #<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

gravity.geometry = 0, 0, 100, 100
=> 0

gravity.geometry = [ 0, 0, 100, 100 ]
=> [ 0, 0, 100, 100 ]

gravity.geometry = { x: 0, y: 0, width: 100, height: 100 }
=> { x: 0, y: 0, width: 100, height: 100 }

gravity.geometry = "0x0+100+100"
=> "0x0+100+100"

gravity.geometry = Subtlext::Geometry(0, 0, 100, 100)
=> #<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.

gravity.geometry_for(screen)
=> #<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.

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

gravity.kill
=> 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.

gravity.save
=> 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

gravity.tiling = :vert
=> :vert

gravity.tiling = :horz
=> :horz

gravity.tiling = nil
=> 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_str -> String

Convert this Gravity object to string.

puts gravity
=> "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.

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

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

  return CHAR2SYM(RSTRING_PTR(name));
}