+/*
+ * Gets the output which is the next one in the given direction.
+ *
+ */
+Output *get_output_next(direction_t direction, Output *current) {
+ Output *output, *candidate = NULL;
+
+ TAILQ_FOREACH(output, &outputs, outputs) {
+ if (!output->active)
+ continue;
+
+ if (((direction == D_UP) || (direction == D_DOWN)) &&
+ (current->rect.x != output->rect.x))
+ continue;
+
+ if (((direction == D_LEFT) || (direction == D_RIGHT)) &&
+ (current->rect.y != output->rect.y))
+ continue;
+
+ switch (direction) {
+ case D_UP:
+ if (output->rect.y < current->rect.y &&
+ (!candidate || output->rect.y < candidate->rect.y))
+ candidate = output;
+ break;
+ case D_DOWN:
+ if (output->rect.y > current->rect.y &&
+ (!candidate || output->rect.y > candidate->rect.y))
+ candidate = output;
+ break;
+ case D_LEFT:
+ if (output->rect.x < current->rect.x &&
+ (!candidate || output->rect.x > candidate->rect.x))
+ candidate = output;
+ break;
+ case D_RIGHT:
+ if (output->rect.x > current->rect.x &&
+ (!candidate || output->rect.x < candidate->rect.x))
+ candidate = output;
+ break;
+ }
+ }
+
+ return candidate;
+}
+