예제 #1
0
파일: monitor.c 프로젝트: shellkr/bspwm
monitor_t *nearest_monitor(monitor_t *m, direction_t dir, desktop_select_t sel)
{
    int dmin = INT_MAX;
    monitor_t *nearest = NULL;
    xcb_rectangle_t rect = m->rectangle;
    for (monitor_t *f = mon_head; f != NULL; f = f->next) {
        if (f == m)
            continue;
        coordinates_t loc = {f, f->desk, NULL};
        if (!desktop_matches(&loc, &loc, sel))
            continue;
        xcb_rectangle_t r = f->rectangle;
        if ((dir == DIR_LEFT && r.x < rect.x) ||
                (dir == DIR_RIGHT && r.x >= (rect.x + rect.width)) ||
                (dir == DIR_UP && r.y < rect.y) ||
                (dir == DIR_DOWN && r.y >= (rect.y + rect.height))) {
            int d = abs((r.x + r.width / 2) - (rect.x + rect.width / 2)) +
                abs((r.y + r.height / 2) - (rect.y + rect.height / 2));
            if (d < dmin) {
                dmin = d;
                nearest = f;
            }
        }
    }
    return nearest;
}
예제 #2
0
파일: desktop.c 프로젝트: nas30/bspwm
bool find_closest_desktop(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, desktop_select_t sel)
{
	monitor_t *m = ref->monitor;
	desktop_t *d = ref->desktop;
	desktop_t *f = (dir == CYCLE_PREV ? d->prev : d->next);

#define HANDLE_BOUNDARIES(f)  \
	if (f == NULL) { \
		m = (dir == CYCLE_PREV ? m->prev : m->next); \
		if (m == NULL) { \
			m = (dir == CYCLE_PREV ? mon_tail : mon_head); \
		} \
		f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); \
	}
	HANDLE_BOUNDARIES(f)

	while (f != d) {
		coordinates_t loc = {m, f, NULL};
		if (desktop_matches(&loc, ref, sel)) {
			*dst = loc;
			return true;
		}
		f = (dir == CYCLE_PREV ? f->prev : f->next);
		HANDLE_BOUNDARIES(f)
	}
#undef HANDLE_BOUNDARIES

	return false;
}
예제 #3
0
파일: monitor.c 프로젝트: shellkr/bspwm
monitor_t *closest_monitor(monitor_t *m, cycle_dir_t dir, desktop_select_t sel)
{
    monitor_t *f = (dir == CYCLE_PREV ? m->prev : m->next);
    if (f == NULL)
        f = (dir == CYCLE_PREV ? mon_tail : mon_head);

    while (f != m) {
        coordinates_t loc = {m, m->desk, NULL};
        if (desktop_matches(&loc, &loc, sel))
            return f;
        f = (dir == CYCLE_PREV ? m->prev : m->next);
        if (f == NULL)
            f = (dir == CYCLE_PREV ? mon_tail : mon_head);
    }

    return NULL;
}
예제 #4
0
파일: desktop.c 프로젝트: Iroxxar/bspwm
desktop_t *closest_desktop(monitor_t *m, desktop_t *d, cycle_dir_t dir, desktop_select_t sel)
{
	desktop_t *f = (dir == CYCLE_PREV ? d->prev : d->next);
	if (f == NULL)
		f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head);

	while (f != d) {
		coordinates_t loc = {m, f, NULL};
		if (desktop_matches(&loc, &loc, sel))
			return f;
		f = (dir == CYCLE_PREV ? f->prev : f->next);
		if (f == NULL)
			f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head);
	}

	return NULL;
}
예제 #5
0
파일: history.c 프로젝트: mztriz/bspwm
bool history_find_monitor(history_dir_t hdi, coordinates_t *ref, coordinates_t *dst, desktop_select_t sel)
{
    if (history_needle == NULL)
        history_needle = history_tail;

    history_t *h;
    for (h = history_needle; h != NULL; h = (hdi == HISTORY_OLDER ? h->prev : h->next)) {
        if (h == history_needle
                || !h->latest
                || (h->loc.monitor == ref->monitor)
                || !desktop_matches(&h->loc, ref, sel))
            continue;
        history_needle = h;
        *dst = h->loc;
        return true;
    }
    return false;
}
예제 #6
0
파일: query.c 프로젝트: dj95/bspwm
int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, FILE *rsp)
{
	int count = 0;
	for (monitor_t *m = mon_head; m != NULL; m = m->next) {
		if (trg->monitor != NULL && m != trg->monitor) {
			continue;
		}
		for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
			coordinates_t loc = {m, d, NULL};
			if ((trg->desktop != NULL && d != trg->desktop) ||
			    (sel != NULL && !desktop_matches(&loc, ref, *sel))) {
				continue;
			}
			fprintf(rsp, "0x%08X\n", d->id);
			count++;
		}
	}
	return count;
}
예제 #7
0
bool history_find_desktop(history_dir_t hdi, coordinates_t *ref, coordinates_t *dst, desktop_select_t sel)
{
	if (history_needle == NULL || record_history) {
		history_needle = history_tail;
	}

	history_t *h;
	for (h = history_needle; h != NULL; h = (hdi == HISTORY_OLDER ? h->prev : h->next)) {
		if (!h->latest ||
		    h->loc.desktop == ref->desktop ||
		    !desktop_matches(&h->loc, ref, sel)) {
			continue;
		}
		if (!record_history) {
			history_needle = h;
		}
		*dst = h->loc;
		return true;
	}
	return false;
}