- LOG("other->percent = %f\n", other->percent);
- LOG("current->percent before = %f\n", current->percent);
- if (current->percent == 0.0)
- current->percent = percentage;
- if (other->percent == 0.0)
- other->percent = percentage;
- double new_current_percent = current->percent + ((double)ppt / 100.0);
- double new_other_percent = other->percent - ((double)ppt / 100.0);
- LOG("new_current_percent = %f\n", new_current_percent);
- LOG("new_other_percent = %f\n", new_other_percent);
- /* Ensure that the new percentages are positive and greater than
- * 0.05 to have a reasonable minimum size. */
- if (definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON) &&
- definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
- current->percent += ((double)ppt / 100.0);
- other->percent -= ((double)ppt / 100.0);
- LOG("current->percent after = %f\n", current->percent);
- LOG("other->percent after = %f\n", other->percent);
- } else {
- LOG("Not resizing, already at minimum size\n");
+ break;
+ } while (current->type != CT_WORKSPACE &&
+ current->type != CT_FLOATING_CON);
+
+ if (other == NULL) {
+ LOG("No other container in this direction found, trying to look further up in the tree...\n");
+ ysuccess(false);
+ return false;
+ }
+
+ LOG("other->percent = %f\n", other->percent);
+ LOG("current->percent before = %f\n", current->percent);
+ if (current->percent == 0.0)
+ current->percent = percentage;
+ if (other->percent == 0.0)
+ other->percent = percentage;
+ double new_current_percent = current->percent + ((double)ppt / 100.0);
+ double new_other_percent = other->percent - ((double)ppt / 100.0);
+ LOG("new_current_percent = %f\n", new_current_percent);
+ LOG("new_other_percent = %f\n", new_other_percent);
+ /* Ensure that the new percentages are positive and greater than
+ * 0.05 to have a reasonable minimum size. */
+ if (definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON) &&
+ definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
+ current->percent += ((double)ppt / 100.0);
+ other->percent -= ((double)ppt / 100.0);
+ LOG("current->percent after = %f\n", current->percent);
+ LOG("other->percent after = %f\n", other->percent);
+ } else {
+ LOG("Not resizing, already at minimum size\n");
+ }
+
+ return true;
+}
+
+static bool cmd_resize_tiling_width_height(I3_CMD, char *way, char *direction, int ppt) {
+ LOG("width/height resize\n");
+ /* get the appropriate current container (skip stacked/tabbed cons) */
+ Con *current = focused;
+ while (current->parent->layout == L_STACKED ||
+ current->parent->layout == L_TABBED)
+ current = current->parent;
+
+ /* Then further go up until we find one with the matching orientation. */
+ orientation_t search_orientation =
+ (strcmp(direction, "width") == 0 ? HORIZ : VERT);
+
+ while (current->type != CT_WORKSPACE &&
+ current->type != CT_FLOATING_CON &&
+ con_orientation(current->parent) != search_orientation)
+ current = current->parent;
+
+ /* get the default percentage */
+ int children = con_num_children(current->parent);
+ LOG("ins. %d children\n", children);
+ double percentage = 1.0 / children;
+ LOG("default percentage = %f\n", percentage);
+
+ orientation_t orientation = con_orientation(current->parent);
+
+ if ((orientation == HORIZ &&
+ strcmp(direction, "height") == 0) ||
+ (orientation == VERT &&
+ strcmp(direction, "width") == 0)) {
+ LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
+ (orientation == HORIZ ? "horizontal" : "vertical"));
+ ysuccess(false);
+ return false;
+ }
+
+ if (children == 1) {
+ LOG("This is the only container, cannot resize.\n");
+ ysuccess(false);
+ return false;
+ }
+
+ /* Ensure all the other children have a percentage set. */
+ Con *child;
+ TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
+ LOG("child->percent = %f (child %p)\n", child->percent, child);
+ if (child->percent == 0.0)
+ child->percent = percentage;
+ }
+
+ double new_current_percent = current->percent + ((double)ppt / 100.0);
+ double subtract_percent = ((double)ppt / 100.0) / (children - 1);
+ LOG("new_current_percent = %f\n", new_current_percent);
+ LOG("subtract_percent = %f\n", subtract_percent);
+ /* Ensure that the new percentages are positive and greater than
+ * 0.05 to have a reasonable minimum size. */
+ TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
+ if (child == current)
+ continue;
+ if (!definitelyGreaterThan(child->percent - subtract_percent, 0.05, DBL_EPSILON)) {
+ LOG("Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->percent - subtract_percent);
+ ysuccess(false);
+ return false;