示例#1
0
static Window *visible_windows(i3ipcCon *root)
{
    GList *nodes = g_list_copy((GList *) i3ipc_con_get_nodes(root));
    GList *floating = g_list_copy((GList *) i3ipc_con_get_floating_nodes(root));
    nodes = g_list_concat(nodes, floating);
    if (nodes == NULL)
    {
        return con_to_window(root);
    }

    gchar *layout = NULL;
    g_object_get(root, "layout", &layout, NULL);

    Window *res = NULL;
    const GList *elem;
    if ((strcmp(layout, "tabbed") == 0) ||
        (strcmp(layout, "stacked") == 0))
    {
        unsigned long focus_id = con_get_focused_id(root);
        for (elem = nodes; elem; elem = elem->next)
        {
            i3ipcCon *curr = elem->data;
            unsigned long id;
            g_object_get(curr, "id", &id, NULL);
            Window *win = NULL;
            if (id == focus_id)
            {
                win = visible_windows(curr);
                if (win->id != id)
                {
                    res = window_append(res, con_to_window(curr));
                }
            }
            else
            {
                win = con_to_window(curr);
            }

            res = window_append(res, win);
        }
    }
    else if ((strcmp(layout, "splith") == 0) ||
             (strcmp(layout, "splitv") == 0))
    {
        for (elem = nodes; elem; elem = elem->next)
        {
            i3ipcCon *curr = elem->data;
            res = window_append(res, visible_windows(curr));
        }
    }
    else
    {
        LOG("unknown layout of con: %s\n", layout);
    }

    g_free(layout);
    g_list_free(nodes);

    return res;
}
示例#2
0
static Window *visible_windows_on_all_outputs(i3ipcCon *root, SortMethod sort_method)
{
    GSList *raw_replies = i3ipc_connection_get_workspaces(connection, NULL);
    GSList *replies = g_slist_reverse(raw_replies); // i3ipc-glib reverses the order internally

    if (sort_method == BY_NUMBER)
    {
        replies = g_slist_sort(replies, compare_workspace_nums);
    }
    else if (sort_method == BY_LOCATION)
    {
        GSList *outputs = i3ipc_connection_get_outputs(connection, NULL);
        replies = g_slist_sort_with_data(replies, compare_workspace_position, outputs);
        g_slist_free_full(outputs, (GDestroyNotify) i3ipc_output_reply_free);
    }

    GList *workspaces = i3ipc_con_workspaces(root);

    Window *res = NULL;
    const GSList *reply;
    i3ipcWorkspaceReply *curr_reply;
    for (reply = replies; reply; reply = reply->next)
    {
        curr_reply = reply->data;
        if (!curr_reply->visible)
            continue;

        const GList *ws;
        i3ipcCon *curr_ws;
        for (ws = workspaces; ws; ws = ws->next)
        {
            curr_ws = ws->data;
            const char *name = i3ipc_con_get_name(curr_ws);
            if (strcmp(curr_reply->name, name) == 0)
            {
                i3ipcCon *con = con_get_visible_container(curr_ws);
                res = window_append(res, visible_windows(con));
                break;
            }
        }
    }

    g_slist_free_full(replies, (GDestroyNotify) i3ipc_workspace_reply_free);
    g_list_free(workspaces);

    return res;
}
示例#3
0
文件: lz77.c 项目: in3pid/lz77
void compress(int in, int out)
{
  match_t m;
  window_t w;
  char *p;
  char *end;
  char buf[BUFSIZE];
  int length;
  char tab[64];
  int n = 0;

  window_init(&w, BUFSIZE);

  while ((length = read(in, buf, BUFSIZE)) > 0) {
    p = buf;
    end = buf+length;
    while (p < end) {
      m = window_match(&w, p, end);
      if (match_length(m) <= 1) {
	if (n >= match_length_max) {
	  write_tab(out, tab, match_length_max);
	  n = 0;
	}
	tab[n++] = *p;
	window_append(&w, *p);
	p++;
      }
      else {
	if (n) {
	  write_tab(out, tab, n);
	  n = 0;
	}
	write(out, &m, sizeof m);
	window_append_match(&w, m);
	p += match_length(m);
      }
      window_flush(&w);
    }
  }
  if (n) write_tab(out, tab, n);
  window_free(&w);
}