Beispiel #1
0
void client_remove(struct WM_t *W, struct wmclient *C)
{
    int idx = get_client_index(W, C->win), i;

    if (W->clients[idx] != C)
    {
        msg("client_remove: somehow get_client_index failed! :o\n");
        return;
    }

    W->clients[idx] = NULL;
    /* Update all the focus numbers, i.e. decrease (bring forward) all the windows
       with bigger focus numbers. */
    for (i = idx; i < W->nclients; i++)
        W->clients[i] = W->clients[i + 1];
    W->nclients--;

    msg("Removing client \'%s\'\n", C->name);
    free(C->name);
    free(C);

    msg("About to print\n");
    print_clients(W);
    msg("Printed, about to focus\n");

    client_focus(W, W->clients[0]);
    msg("Focused\n");
}
Beispiel #2
0
/* Find a wmclient structure from its window ID */
struct wmclient *client_from_window(struct WM_t *W, Window id)
{
    int idx = get_client_index(W, id);
    if (idx >= 0)
        return W->clients[idx];
    return NULL;
}
Beispiel #3
0
void client_focus(struct WM_t *W, struct wmclient *C)
{
    int oldidx;
    struct wmclient *old;

    /* Don't do anything if there's nothing to focus */
    if (W->nclients == 0)
        return;

    oldidx = get_client_index(W, C->win);
    old = W->clients[0];

    move_down_client_list(W, 0, oldidx);
    W->clients[0] = C;

    /* Unfocus the old window */
    /* Re-enable grabbing for click events */
    XGrabButton(W->XDisplay, Button1, 0, old->win, 0, ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
                GrabModeAsync, GrabModeSync, None, None);
    /* Make the border boring */
    set_border_colour(W, old, 0);

    set_border_colour(W, C, 1);
    XRaiseWindow(W->XDisplay, C->win);
    XSetInputFocus(W->XDisplay, C->win, RevertToPointerRoot, CurrentTime);
    XUngrabButton(W->XDisplay, Button1, 0, C->win);

    refresh_current_head(W);
}
Beispiel #4
0
static int ident_func(int fd, char* message, char* arguments)
{
	int index;

	if (arguments == NULL)
		return send_error(fd, message, "protocol error\n");
	log_trace1("IDENT %s", arguments);
	index = get_client_index(fd);
	if (clis[index].ident_string != NULL)
		return send_error(fd, message, "protocol error\n");
	clis[index].ident_string = strdup(arguments);
	if (clis[index].ident_string == NULL)
		return send_error(fd, message, "out of memory\n");

	log_trace("%s connected", clis[index].ident_string);
	return send_success(fd, message);
}
Beispiel #5
0
static int code_func(int fd, char* message, char* arguments)
{
	int index;
	struct event_info* ei;
	struct config_info* ci;
	int ret;

	if (arguments == NULL)
		return send_error(fd, message, "protocol error\n");
	index = get_client_index(fd);
	if (index == -1)
		return send_error(fd, message, "identify yourself first!\n");
	if (clis[index].pending_code != NULL)
		return send_error(fd, message, "protocol error\n");

	log_trace2("%s asking for code -%s-", clis[index].ident_string, arguments);

	ei = clis[index].first_event;
	if (ei != NULL) {
		log_trace2("compare: -%s- -%s-", ei->code, arguments);
		if (strcmp(ei->code, arguments) == 0) {
			ci = ei->first;
			if (ci != NULL) {
				log_trace2("result: -%s-", ci->config_string);
				ret = send_result(fd, message, ci->config_string);
				ei->first = ci->next;
				free(ci->config_string);
				free(ci);
				return ret;
			}
			clis[index].first_event = ei->next;
			free(ei->code);
			free(ei);
			return send_success(fd, message);
		} else {
			return send_success(fd, message);
		}
	}

	clis[index].pending_code = strdup(arguments);
	if (clis[index].pending_code == NULL)
		return send_error(fd, message, "out of memory\n");
	return 1;
}