コード例 #1
0
ファイル: i3ipc-con.c プロジェクト: bobbymcshane/i3ipc-glib
/**
 * i3ipc_con_find_marked:
 * @self: an #i3ipcCon
 * @pattern: a perl-compatible regular expression pattern
 * @err: (allow-none): return location for a GError or NULL
 *
 * Returns: (transfer container) (element-type i3ipcCon): A list of descendent
 * Cons which have the mark that matches the pattern
 */
GList *i3ipc_con_find_marked(i3ipcCon *self, const gchar *pattern, GError **err) {
  GList *descendents;
  GRegex *regex;
  GList *retval = NULL;
  GError *tmp_error = NULL;

  g_return_val_if_fail(err == NULL || *err == NULL, NULL);

  regex = g_regex_new(pattern, 0, 0, &tmp_error);

  if (tmp_error != NULL) {
    g_propagate_error(err, tmp_error);
    return NULL;
  }

  descendents = i3ipc_con_descendents(self);
  guint len = g_list_length(descendents);

  for (gint i = 0; i < len; i += 1) {
    i3ipcCon *con = I3IPC_CON(g_list_nth_data(descendents, i));

    if (con->priv->mark && g_regex_match(regex, con->priv->mark, 0, NULL))
      retval = g_list_append(retval, con);
  }

  g_list_free(descendents);
  g_regex_unref(regex);

  return retval;

}
コード例 #2
0
ファイル: ipc.c プロジェクト: cornerman/i3-easyfocus
static i3ipcCon *con_get_visible_container(i3ipcCon *con)
{
    unsigned long id;
    g_object_get(con, "id", &id, NULL);
    LOG("find visible container in con '%lu'\n", id);

    GList *descendants = i3ipc_con_descendents(con);

    i3ipcCon *target = con;
    GList *elem = NULL;
    i3ipcCon *curr = NULL;
    for (elem = descendants; elem; elem = elem->next)
    {
        curr = elem->data;
        gboolean fullscreen;
        g_object_get(curr, "fullscreen-mode", &fullscreen, NULL);
        if (fullscreen)
        {
            LOG("con is in fullscreen mode\n");
            target = curr;
            break;
        }
    }

    g_list_free(descendants);

    return target;
}
コード例 #3
0
ファイル: i3ipc-con.c プロジェクト: bobbymcshane/i3ipc-glib
/**
 * i3ipc_con_find_focused:
 * @self: an #i3ipcCon
 *
 * Returns: (transfer none): The focused Con, or NULL if not found in this Con.
 *
 */
i3ipcCon *i3ipc_con_find_focused(i3ipcCon *self) {
  GList *descendents;
  GList *cmp_result;
  i3ipcCon *retval = NULL;

  descendents = i3ipc_con_descendents(self);

  if (descendents == NULL)
    return NULL;

  cmp_result = g_list_find_custom(descendents, NULL, i3ipc_con_focused_cmp_func);

  if (cmp_result != NULL)
    retval = I3IPC_CON(cmp_result->data);

  g_list_free(descendents);

  return retval;
}
コード例 #4
0
ファイル: i3ipc-con.c プロジェクト: bobbymcshane/i3ipc-glib
/**
 * i3ipc_con_find_by_window:
 * @self: an #i3ipcCon
 * @window_id: the window id of the con to find
 *
 * Returns: (transfer none): The con with the given window id among this con's descendents
 */
i3ipcCon *i3ipc_con_find_by_window(i3ipcCon *self, const gint window_id) {
  GList *descendents;
  i3ipcCon *retval = NULL;

  descendents = i3ipc_con_descendents(self);
  guint len = g_list_length(descendents);

  for (gint i = 0; i < len; i += 1) {
    i3ipcCon *con = I3IPC_CON(g_list_nth_data(descendents, i));

    if (con->priv->window == window_id) {
      retval = con;
      break;
    }
  }

  g_list_free(descendents);

  return retval;
}
コード例 #5
0
ファイル: i3ipc-con.c プロジェクト: bobbymcshane/i3ipc-glib
/**
 * i3ipc_con_leaves:
 * @self: an #i3ipcCon
 *
 * Finds the leaf descendent nodes of a given container excluding dock clients.
 *
 * Returns: (transfer container) (element-type i3ipcCon): a list of leaf descendent nodes
 */
GList *i3ipc_con_leaves(i3ipcCon *self) {
  GList *descendents;
  GList *retval = NULL;

  descendents = i3ipc_con_descendents(self);
  guint len = g_list_length(descendents);

  for (gint i = 0; i < len; i += 1) {
    i3ipcCon *con = I3IPC_CON(g_list_nth_data(descendents, i));

    if (g_list_length(con->priv->nodes) == 0
        && g_strcmp0(con->priv->type, "con") == 0
        && g_strcmp0(con->priv->parent->priv->type, "dockarea") != 0)
      retval = g_list_append(retval, con);
  }

  g_list_free(descendents);

  return retval;
}