class Subtlext::Screen

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

Class for interaction with screens

Methods

Public Class

  1. current
  2. find
  3. list
  4. new

Public Instance

  1. <=>
  2. ==
  3. current?
  4. eql?
  5. geometry
  6. hash
  7. id
  8. jump
  9. to_str
  10. update
  11. view
  12. view=

Public Instance Aliases

save -> update

Aliases

to_s -> to_str

Attributes

geometry [R]

Geometry

id [R]

Screen id

Public Class methods

current -> Subtlext::Screen

Get current active Screen

Subtlext::Screen.current
=> #<Subtlext::Screen:xxx>
[show source]
VALUE
subextScreenSingCurrent(VALUE self)
{
  int rx = 0, ry = 0, x = 0, y = 0;
  unsigned int mask = 0;
  unsigned long nworkareas = 0, npanels = 0;
  long *workareas = NULL, *panels = NULL;
  VALUE screen = Qnil;
  Window root = None, win = None;

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

  /* Get current screen */
  XQueryPointer(display, DefaultRootWindow(display), &root,
    &win, &rx, &ry, &x, &y, &mask);

  /* Fetch data */
  workareas = (long *)subSharedPropertyGet(display, DefaultRootWindow(display),
    XA_CARDINAL, XInternAtom(display, "_NET_WORKAREA", False), &nworkareas);
  panels    = (long *)subSharedPropertyGet(display, DefaultRootWindow(display),
    XA_CARDINAL, XInternAtom(display, "SUBTLE_SCREEN_PANELS", False),
    &npanels);

  /* Get workarea list */
  if(workareas && panels)
    {
      int i;

      for(i = 0; i < nworkareas / 4; i++)
        {
          /* Check if coordinates are in screen rects including panel size */
          if(rx >= workareas[i * 4 + 0] &&
              rx < workareas[i * 4 + 0] + workareas[i * 4 + 2] &&
              ry >= (workareas[i * 4 + 1] - panels[i * 2 + 0]) &&
              ry < (workareas[i * 4 + 1] + workareas[i * 4 + 3] +
              panels[i * 2 + 1]))
            {
              VALUE geometry = Qnil;

              /* Create new screen */
              screen   = subextScreenInstantiate(i);
              geometry = subextGeometryInstantiate(workareas[i * 4 + 0],
                workareas[i * 4 + 1], workareas[i * 4 + 2],
                workareas[i * 4 + 3]);

              rb_iv_set(screen, "@geometry", geometry);
            }
        }
    }

  if(workareas) free(workareas);
  if(panels)    free(panels);

  return screen;
}
find(value) -> Subtlext::Screen or nil

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

fixnum

Array id

Subtlext::Geometry

Geometry

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

Subtlext::Screen.find(Subtlext::Geometry(10, 10, 100, 100)
=> #<Subtlext::Screen:xxx>
[show source]
VALUE
subextScreenSingFind(VALUE self,
  VALUE value)
{
  VALUE screen = Qnil;

  /* Check object type */
  switch(rb_type(value))
    {
      case T_FIXNUM:
          {
            VALUE screens = ScreenList();

            screen = rb_ary_entry(screens, FIX2INT(value));
          }
        break;
      case T_OBJECT:
          {
            VALUE klass = rb_const_get(mod, rb_intern("Geometry"));

            /* Check object instance */
            if(rb_obj_is_instance_of(value, klass))
              {
                unsigned long nworkareas = 0;
                long *workareas = NULL;

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

                /* Get workarea list */
                if((workareas = (long *)subSharedPropertyGet(display,
                    DefaultRootWindow(display), XA_CARDINAL,
                    XInternAtom(display, "_NET_WORKAREA", False),
                    &nworkareas)))
                  {
                    int i;
                    XRectangle geom = { 0 };

                    subextGeometryToRect(value, &geom);

                    for(i = 0; i < nworkareas / 4; i++)
                      {
                        /* Check if coordinates are in screen rects */
                        if(geom.x >= workareas[i * 4 + 0] && geom.x <
                            workareas[i * 4 + 0] + workareas[i * 4 + 2] &&
                            geom.y >= workareas[i * 4 + 1] && geom.y <
                            workareas[i * 4 + 1] + workareas[i * 4 + 3])
                          {
                            VALUE geometry = Qnil;

                            /* Create new screen */
                            screen   = subextScreenInstantiate(i);
                            geometry = subextGeometryInstantiate(
                              workareas[i * 4 + 0], workareas[i * 4 + 1],
                              workareas[i * 4 + 2], workareas[i * 4 + 3]);

                            rb_iv_set(screen, "@geometry", geometry);

                            break;
                          }
                      }

                    free(workareas);
                  }
              }
          }
        break;
      default: rb_raise(rb_eArgError, "Unexpected value type `%s'",
        rb_obj_classname(value));
    }

  return screen;
}
list -> Array

Get Array of all Screen

Subtlext::Screen.list
=> [#<Subtlext::Screen:xxx>, #<Subtlext::Screen:xxx>]
Subtlext::Screen.list
=> []
[show source]
VALUE
subextScreenSingList(VALUE self)
{
  return ScreenList();
}
new(id) -> Subtlext::Screen

Create a new Screen object

screen = Subtlext::Screen.new(0)
=> #<Subtlext::Screen:xxx>
[show source]
VALUE
subextScreenInit(VALUE self,
  VALUE id)
{
  if(!FIXNUM_P(id) || 0 > FIX2INT(id))
    rb_raise(rb_eArgError, "Unexpected value-type `%s'",
      rb_obj_classname(id));

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

  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);
}
screen? -> true or false

Check if this Screen is the current active Screen

screen.current?
=> true
screen.current?
=> false
[show source]
VALUE
subextScreenAskCurrent(VALUE self)
{
  /* Check ruby object */
  rb_check_frozen(self);

  return rb_equal(self, subextScreenSingCurrent(Qnil));
}
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;
}
screen -> Subtlext::Screen

Jump to this Screen

screen.jump
=> #<Subtlext::Screen:xxx>
[show source]
VALUE
subextScreenJump(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_SCREEN_JUMP", data, 32, True);

  return self;
}
to_str -> String

Convert Screen object to String

puts screen
=> "0x0+800+600"
[show source]
VALUE
subextScreenToString(VALUE self)
{
  VALUE geom = Qnil;

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

  return subextGeometryToString(geom);
}
update -> Subtlext::Screen

Update Screen properties

screen.update
=> #<Subtlext::Screen:xxx>
[show source]
VALUE
subextScreenUpdate(VALUE self)
{
  VALUE id = Qnil, screens = Qnil, screen = Qnil;

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

  /* Find screen */
  if((screens = ScreenList()) &&
      RTEST(screen = rb_ary_entry(screens, FIX2INT(id))))
    {
      VALUE geometry = rb_iv_get(screen, "@geometry");

      rb_iv_set(self, "@geometry", geometry);
    }
  else rb_raise(rb_eStandardError, "Invalid screen id `%d'",
    (int)FIX2INT(id));

  return self;
}
view -> Subtlext::View

Get active view for screen

screen.view
=> #<Subtlext::View:xxx>
[show source]
VALUE
subextScreenViewReader(VALUE self)
{
  VALUE ret = Qnil;
  int nnames = 0;
  char **names = NULL;
  unsigned long *screens = NULL;

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

  /* Fetch data */
  names   = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
    XInternAtom(display, "_NET_DESKTOP_NAMES", False), &nnames);
  screens = (unsigned long *)subSharedPropertyGet(display,
    DefaultRootWindow(display), XA_CARDINAL, XInternAtom(display,
    "SUBTLE_SCREEN_VIEWS", False), NULL);

  /* Check results */
  if(names && screens)
    {
      int id = 0, vid = 0;

      if(0 <= (id = FIX2INT(rb_iv_get(self, "@id"))))
        {
          if(0 <= (vid = screens[id]) && vid < nnames)
            {
              ret = subextViewInstantiate(names[vid]);

              if(!NIL_P(ret)) rb_iv_set(ret, "@id", INT2FIX(vid));
            }
        }
    }

  if(names)   XFreeStringList(names);
  if(screens) free(screens);

  return ret;
}
view=(fixnum) -> Fixnum
view=(symbol) -> Symbol
view=(object) -> Subtlext::View

Set active view for screen

screen.view = :www
=> nil
screen.view = Subtlext::View[0]
=> nil
[show source]
VALUE
subextScreenViewWriter(VALUE self,
  VALUE value)
{
  VALUE vid = Qnil, view = Qnil, sid = Qnil;
  SubMessageData data = { { 0, 0, 0, 0, 0 } };

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

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

  /* Check instance type */
  if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("View"))))
    view = value;
  else view = subextViewSingFirst(Qnil, value);

  GET_ATTR(view, "@id", vid);

  /* Send message */
  data.l[0] = FIX2LONG(vid);
  data.l[1] = CurrentTime;
  data.l[2] = FIX2LONG(sid);

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

  return value;
}