Class Subtlext::Screen < Object

Class for interaction with screens

Methods

public class

  1. current
  2. find
    [value]
  3. list
  4. new

public instance

  1. <=>
  2. ==
  3. screen?
  4. eql?
  5. hash
  6. screen
  7. save
  8. to_s
  9. to_str
  10. update
  11. view
  12. view=

Attributes

geometry [R] Geometry
id [R] Gravity id

Public class methods

current → Subtlext::Screen

Get current active Screen

1 Subtlext::Screen.current
2 => #<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
[value] → Subtlext::Screen or nil

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

fixnum
Array id
Subtlext::Geometry
Geometry
1 Subtlext::Screen.find(1)
2 => #<Subtlext::Screen:xxx>
3 
4 Subtlext::Screen[1]
5 => #<Subtlext::Screen:xxx>
6 
7 Subtlext::Screen.find(Subtlext::Geometry(10, 10, 100, 100)
8 => #<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

1 Subtlext::Screen.list
2 => [#<Subtlext::Screen:xxx>, #<Subtlext::Screen:xxx>]
3 
4 Subtlext::Screen.list
5 => []
[show source]
VALUE
subextScreenSingList(VALUE self)
{
  return ScreenList();
}
new(id) → Subtlext::Screen

Create a new Screen object

1 screen = Subtlext::Screen.new(0)
2 => #<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)

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

Check if this Screen is the current active Screen

1 screen.current?
2 => true
3 
4 screen.current?
5 => 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)

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;
}
screen → Subtlext::Screen

Jump to this Screen

1 screen.jump
2 => #<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;
}
save ()

Alias for update

to_s ()

Alias for to_str

to_str → String

Convert Screen object to String

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

1 screen.update
2 => #<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

1 screen.view
2 => #<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

1 screen.view = :www
2 => nil
3 
4 screen.view = Subtlext::View[0]
5 => 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;
}