X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Frandr.c;h=dd30925b9301c654132105bda8a23f325e452203;hb=5aa43d61f84e69c9b46cfc3e37c6806b887f01d8;hp=e48e2065d8e0cb14696de89f9db964a77f677ea7;hpb=2e0f5335f45c1b698e62627db3a63862b1281efd;p=i3%2Fi3 diff --git a/src/randr.c b/src/randr.c index e48e2065..dd30925b 100644 --- a/src/randr.c +++ b/src/randr.c @@ -143,6 +143,52 @@ Output *get_output_most(direction_t direction, Output *current) { return candidate; } +/* + * 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; +} + /* * Disables RandR support by creating exactly one output with the size of the * X11 screen. @@ -379,6 +425,12 @@ void init_ws_for_output(Output *output, Con *content) { continue; DLOG("relevant command = %s\n", bind->command); char *target = bind->command + strlen("workspace "); + /* We check if this is the workspace next/prev command. Beware: The + * workspace names "next" and "prev" are OK, so we check before + * stripping the double quotes */ + if (strncasecmp(target, "next", strlen("next")) == 0 || + strncasecmp(target, "prev", strlen("prev")) == 0) + continue; if (*target == '"') target++; FREE(ws->name); @@ -395,10 +447,12 @@ void init_ws_for_output(Output *output, Con *content) { if (!exists) { /* Set ->num to the number of the workspace, if the name actually * is a number or starts with a number */ - long parsed_num = strtol(ws->name, NULL, 10); + char *endptr = NULL; + long parsed_num = strtol(ws->name, &endptr, 10); if (parsed_num == LONG_MIN || parsed_num == LONG_MAX || - parsed_num <= 0) + parsed_num < 0 || + endptr == ws->name) ws->num = -1; else ws->num = parsed_num; LOG("Used number %d for workspace with name %s\n", ws->num, ws->name);