示例#1
0
文件: view.c 项目: MinasMazar/subtle
VALUE
subViewSingCurrent(VALUE self)
{
  int nnames = 0;
  char **names = NULL;
  unsigned long *cur_view = NULL;
  VALUE view = Qnil;

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

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

  /* Check results */
  if(names && cur_view)
    {
      /* Create instance */
      view = subViewInstantiate(names[*cur_view]);
      rb_iv_set(view, "@id",  INT2FIX(*cur_view));
    }

  if(names)    XFreeStringList(names);
  if(cur_view) free(cur_view);

  return view;
} /* }}} */
示例#2
0
文件: sublet.c 项目: guns/subtle
VALUE
subSubletSingAll(VALUE self)
{
  int i, nsublets = 0;
  char **sublets = NULL;
  VALUE meth = Qnil, klass = Qnil, array = Qnil;

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

  /* Fetch data */
  meth   = rb_intern("new");
  klass  = rb_const_get(mod, rb_intern("Sublet"));
  array  = rb_ary_new();

  /* Check results */
  if((sublets = subSharedPropertyGetStrings(display,
      DefaultRootWindow(display), XInternAtom(display, "SUBTLE_SUBLET_LIST",
      False), &nsublets)))
    {
      for(i = 0; i < nsublets; i++)
        {
          VALUE s = rb_funcall(klass, meth, 1, rb_str_new2(sublets[i]));

          rb_iv_set(s, "@id", INT2FIX(i));
          rb_ary_push(array, s);
        }

      XFreeStringList(sublets);
    }

  return array;
} /* }}} */
示例#3
0
文件: gravity.c 项目: guns/subtle
/* GravityFindId {{{ */
static int
GravityFindId(char *match,
  char **name,
  XRectangle *geometry)
{
  int ret = -1, ngravities = 0;
  char **gravities = NULL;
  regex_t *preg = NULL;

  assert(match);

  /* Find gravity id */
  if((preg = subSharedRegexNew(match)) &&
      (gravities = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
      XInternAtom(display, "SUBTLE_GRAVITY_LIST", False), &ngravities)))
    {
      int i;
      XRectangle geom = { 0 };
      char buf[30] = { 0 };

      for(i = 0; i < ngravities; i++)
        {
          sscanf(gravities[i], "%hdx%hd+%hd+%hd#%s", &geom.x, &geom.y,
            &geom.width, &geom.height, buf);

          /* Check id and name */
          if((isdigit(match[0]) && atoi(match) == i) ||
              (!isdigit(match[0]) && subSharedRegexMatch(preg, buf)))
            {
              subSharedLogDebugSubtlext("Found: type=gravity, name=%s, id=%d\n", buf, i);

              if(geometry) *geometry = geom;
              if(name)
                {
                  *name = (char *)subSharedMemoryAlloc(strlen(buf) + 1, sizeof(char));
                  strncpy(*name, buf, strlen(buf));
                }

              ret = i;
              break;
           }
       }
    }
  else subSharedLogDebugSubtlext("Failed finding gravity `%s'\n", name);

  if(preg)       subSharedRegexKill(preg);
  if(gravities) XFreeStringList(gravities);

  return ret;
} /* }}} */
示例#4
0
文件: view.c 项目: AlexTalker/subtle
VALUE
subextViewSave(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 view if needed */
  if(-1 == (id = subextSubtlextFindString("_NET_DESKTOP_NAMES",
      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_VIEW_NEW", data, 8, True);

      id = subextSubtlextFindString("_NET_DESKTOP_NAMES",
        RSTRING_PTR(name), NULL, SUB_MATCH_EXACT);
    }

  /* Guess view id */
  if(-1 == id)
    {
      int nnames = 0;
      char **names = NULL;

      /* Get names of views */
      if((names = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
          XInternAtom(display, "_NET_DESKTOP_NAMES", False), &nnames)))
        {
          id = nnames; ///< New id should be last

          if(names) XFreeStringList(names);
        }
    }

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

  return self;
} /* }}} */
示例#5
0
文件: view.c 项目: AlexTalker/subtle
VALUE
subextViewSingVisible(VALUE self)
{
  int i, nnames = 0, *tags = NULL;
  char **names = NULL;
  unsigned long *visible = NULL;
  VALUE meth = Qnil, klass = Qnil, array = Qnil, v = Qnil;

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

  /* Fetch data */
  meth  = rb_intern("new");
  klass = rb_const_get(mod, rb_intern("View"));
  array = rb_ary_new();
  names = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
    XInternAtom(display, "_NET_DESKTOP_NAMES", False), &nnames);
  visible = (unsigned long *)subSharedPropertyGet(display,
    DefaultRootWindow(display), XA_CARDINAL, XInternAtom(display,
    "SUBTLE_VISIBLE_VIEWS", False), NULL);
  tags  = (int *)subSharedPropertyGet(display, ROOT, XA_CARDINAL,
      XInternAtom(display, "SUBTLE_VIEW_TAGS", False), NULL);

  /* Check results */
  if(names && visible && tags)
    {
      for(i = 0; i < nnames; i++)
        {
          /* Create view on match */
          if(*visible & (1L << (i + 1)) &&
              !NIL_P(v = rb_funcall(klass, meth, 1, rb_str_new2(names[i]))))
            {
              rb_iv_set(v, "@id",   INT2FIX(i));
              rb_iv_set(v, "@tags", INT2FIX(tags[i]));

              rb_ary_push(array, v);
            }
        }
    }

  if(names)   XFreeStringList(names);
  if(visible) free(visible);
  if(tags)    free(tags);

  return array;
} /* }}} */
示例#6
0
文件: view.c 项目: AlexTalker/subtle
/* ViewSelect {{{ */
static VALUE
ViewSelect(VALUE self,
  int dir)
{
  int nnames = 0;
  char **names = NULL;
  VALUE id = Qnil, ret = Qnil;

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

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

  /* Fetch data */
  if((names = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
    XInternAtom(display, "_NET_DESKTOP_NAMES", False), &nnames)))
    {
      int vid = FIX2INT(id);

      /* Select view */
      if(SUB_VIEW_NEXT == dir && vid < (nnames - 1))
        {
          vid++;
        }
      else if(SUB_VIEW_PREV == dir && 0 < vid)
        {
          vid--;
        }

      /* Create view */
      ret = subextViewInstantiate(names[vid]);
      subextViewUpdate(ret);

      XFreeStringList(names);
    }

  return ret;
} /* }}} */
示例#7
0
文件: view.c 项目: MinasMazar/subtle
VALUE
subViewSingList(VALUE self)
{
  int i, nnames = 0;
  long *tags = NULL;
  char **names = NULL;
  VALUE meth = Qnil, klass = Qnil, array = Qnil, v = Qnil;

  subSubtlextConnect(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  = (long *)subSharedPropertyGet(display, ROOT, XA_CARDINAL,
      XInternAtom(display, "SUBTLE_VIEW_TAGS", False), NULL);

  /* Check results */
  if(names && tags)
    {
      for(i = 0; i < nnames; i++)
        {
          if(!NIL_P(v = rb_funcall(klass, meth, 1, rb_str_new2(names[i]))))
            {
              rb_iv_set(v, "@id",   INT2FIX(i));
              rb_iv_set(v, "@tags", LONG2NUM(tags[i]));

              rb_ary_push(array, v);
            }
        }
    }

  if(names) XFreeStringList(names);
  if(tags)  free(tags);

  return array;
} /* }}} */
示例#8
0
文件: gravity.c 项目: guns/subtle
VALUE
subGravityUpdate(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");

      subGeometryToRect(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 = subGeometryInstantiate(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);
    }

  rb_iv_set(self, "@id", INT2FIX(id));

  return Qnil;
} /* }}} */
示例#9
0
文件: gravity.c 项目: guns/subtle
/* GravityFind {{{ */
static VALUE
GravityFind(char *source,
  int flags)
{
  int ngravities = 0;
  char **gravities = NULL;
  VALUE ret = Qnil;

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

  /* Get gravity list */
  if((gravities = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
      XInternAtom(display, "SUBTLE_GRAVITY_LIST", False), &ngravities)))
    {
      int i, selid = -1;
      XRectangle geometry = { 0 };
      char buf[30] = { 0 };
      VALUE klass_grav = Qnil, klass_geom = Qnil, meth = Qnil;
      VALUE gravity = Qnil, geom = Qnil;
      regex_t *preg = NULL;

      /* Fetch data */
      klass_grav = rb_const_get(mod, rb_intern("Gravity"));
      klass_geom = rb_const_get(mod, rb_intern("Geometry"));
      meth       = rb_intern("new");

      /* Create if source is given */
      if(source)
        {
          if(isdigit(source[0])) selid = atoi(source);
          preg = subSharedRegexNew(source);
        }

      /* Create gravity list */
      for(i = 0; i < ngravities; i++)
        {
          sscanf(gravities[i], "%hdx%hd+%hd+%hd#%s", &geometry.x, &geometry.y,
            &geometry.width, &geometry.height, buf);

          /* Check if gravity matches */
          if(!source || (source && (selid == i || (-1 == selid &&
              ((flags & SUB_MATCH_EXACT && 0 == strcmp(source, buf)) ||
              (preg && !(flags & SUB_MATCH_EXACT) &&
                subSharedRegexMatch(preg, buf)))))))
            {
              /* Create new gravity */
              gravity = rb_funcall(klass_grav, meth, 1, rb_str_new2(buf));
              geom    = rb_funcall(klass_geom, meth, 4, INT2FIX(geometry.x),
                INT2FIX(geometry.y), INT2FIX(geometry.width),
                INT2FIX(geometry.height));

              rb_iv_set(gravity, "@id",       INT2FIX(i));
              rb_iv_set(gravity, "@geometry", geom);

              ret = subSubtlextOneOrMany(gravity, ret);
            }
        }

      if(preg)    subSharedRegexKill(preg);
      XFreeStringList(gravities);
    }
  else rb_raise(rb_eStandardError, "Failed getting gravity list");

  return NIL_P(ret) ? rb_ary_new() : ret;
} /* }}} */