static Output *get_output_from_string(Output *current_output, const char *output_str) {
Output *output;
- if (strcasecmp(output_str, "left") == 0) {
- output = get_output_next(D_LEFT, current_output, CLOSEST_OUTPUT);
- if (!output)
- output = get_output_most(D_RIGHT, current_output);
- } else if (strcasecmp(output_str, "right") == 0) {
- output = get_output_next(D_RIGHT, current_output, CLOSEST_OUTPUT);
- if (!output)
- output = get_output_most(D_LEFT, current_output);
- } else if (strcasecmp(output_str, "up") == 0) {
- output = get_output_next(D_UP, current_output, CLOSEST_OUTPUT);
- if (!output)
- output = get_output_most(D_DOWN, current_output);
- } else if (strcasecmp(output_str, "down") == 0) {
- output = get_output_next(D_DOWN, current_output, CLOSEST_OUTPUT);
- if (!output)
- output = get_output_most(D_UP, current_output);
- } else output = get_output_by_name(output_str);
+ if (strcasecmp(output_str, "left") == 0)
+ output = get_output_next_wrap(D_LEFT, current_output);
+ else if (strcasecmp(output_str, "right") == 0)
+ output = get_output_next_wrap(D_RIGHT, current_output);
+ else if (strcasecmp(output_str, "up") == 0)
+ output = get_output_next_wrap(D_UP, current_output);
+ else if (strcasecmp(output_str, "down") == 0)
+ output = get_output_next_wrap(D_DOWN, current_output);
+ else output = get_output_by_name(output_str);
return output;
}
static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floating_con, int px) {
LOG("floating resize\n");
Rect old_rect = floating_con->rect;
+ Con *focused_con = con_descend_focused(floating_con);
+
+ /* ensure that resize will take place even if pixel increment is smaller than
+ * height increment or width increment.
+ * fixes #1011 */
+ if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 ||
+ strcmp(direction, "height") == 0) {
+ if (px < 0)
+ px = (-px < focused_con->height_increment) ? -focused_con->height_increment : px;
+ else
+ px = (px < focused_con->height_increment) ? focused_con->height_increment : px;
+ } else if (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0) {
+ if (px < 0)
+ px = (-px < focused_con->width_increment) ? -focused_con->width_increment : px;
+ else
+ px = (px < focused_con->width_increment) ? focused_con->width_increment : px;
+ }
if (strcmp(direction, "up") == 0) {
floating_con->rect.height += px;
return;
if (strcmp(direction, "up") == 0) {
- floating_con->rect.y -= px;
+ floating_con->rect.y -= (floating_con->rect.height - old_rect.height);
} else if (strcmp(direction, "left") == 0) {
- floating_con->rect.x -= px;
+ floating_con->rect.x -= (floating_con->rect.width - old_rect.width);
}
+
+ /* If this is a scratchpad window, don't auto center it from now on. */
+ if (floating_con->scratchpad_state == SCRATCHPAD_FRESH)
+ floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
}
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, char *way, char *direction, int ppt) {
// TODO: clean this up with commands.spec as soon as we switched away from the lex/yacc command parser
if (strcasecmp(name, "up") == 0)
- output = get_output_next(D_UP, current_output, CLOSEST_OUTPUT);
+ output = get_output_next_wrap(D_UP, current_output);
else if (strcasecmp(name, "down") == 0)
- output = get_output_next(D_DOWN, current_output, CLOSEST_OUTPUT);
+ output = get_output_next_wrap(D_DOWN, current_output);
else if (strcasecmp(name, "left") == 0)
- output = get_output_next(D_LEFT, current_output, CLOSEST_OUTPUT);
+ output = get_output_next_wrap(D_LEFT, current_output);
else if (strcasecmp(name, "right") == 0)
- output = get_output_next(D_RIGHT, current_output, CLOSEST_OUTPUT);
+ output = get_output_next_wrap(D_RIGHT, current_output);
else
output = get_output_by_name(name);
return;
}
+ Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
int count = 0;
owindow *current;
TAILQ_FOREACH(current, &owindows, owindows) {
return;
}
+ /* In case this is a scratchpad window, call scratchpad_show(). */
+ if (ws == __i3_scratch) {
+ scratchpad_show(current->con);
+ count++;
+ /* While for the normal focus case we can change focus multiple
+ * times and only a single window ends up focused, we could show
+ * multiple scratchpad windows. So, rather break here. */
+ break;
+ }
+
/* If the container is not on the current workspace,
* workspace_show() will switch to a different workspace and (if
* enabled) trigger a mouse pointer warp to the currently focused
if (strcmp(layout_str, "stacking") == 0)
layout_str = "stacked";
owindow *current;
- int layout;
+ layout_t layout;
/* default is a special case which will be handled in con_set_layout(). */
if (strcmp(layout_str, "default") == 0)
layout = L_DEFAULT;
x_set_i3_atoms();
/* Send an IPC event just in case the ws names have changed */
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"reload\"}");
+ /* Send an update event for the barconfig just in case it has changed */
+ update_barconfig();
// XXX: default reply for now, make this a better reply
ysuccess(true);
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"rename\"}");
}
+
+/*
+ * Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]'
+ *
+ */
+bool cmd_bar_mode(char *bar_mode, char *bar_id) {
+ int mode;
+ bool toggle = false;
+ if (strcmp(bar_mode, "dock") == 0)
+ mode = M_DOCK;
+ else if (strcmp(bar_mode, "hide") == 0)
+ mode = M_HIDE;
+ else if (strcmp(bar_mode, "invisible") == 0)
+ mode = M_INVISIBLE;
+ else if (strcmp(bar_mode, "toggle") == 0)
+ toggle = true;
+ else {
+ ELOG("Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
+ return false;
+ }
+
+ bool changed_sth = false;
+ Barconfig *current = NULL;
+ TAILQ_FOREACH(current, &barconfigs, configs) {
+ if (bar_id && strcmp(current->id, bar_id) != 0)
+ continue;
+
+ if (toggle)
+ mode = (current->mode + 1) % 2;
+
+ DLOG("Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->id, bar_mode, mode);
+ current->mode = mode;
+ changed_sth = true;
+
+ if (bar_id)
+ break;
+ }
+
+ if (bar_id && !changed_sth) {
+ DLOG("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Implementation of 'bar hidden_state hide|show|toggle [<bar_id>]'
+ *
+ */
+bool cmd_bar_hidden_state(char *bar_hidden_state, char *bar_id) {
+ int hidden_state;
+ bool toggle = false;
+ if (strcmp(bar_hidden_state, "hide") == 0)
+ hidden_state = S_HIDE;
+ else if (strcmp(bar_hidden_state, "show") == 0)
+ hidden_state = S_SHOW;
+ else if (strcmp(bar_hidden_state, "toggle") == 0)
+ toggle = true;
+ else {
+ ELOG("Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
+ return false;
+ }
+
+ bool changed_sth = false;
+ Barconfig *current = NULL;
+ TAILQ_FOREACH(current, &barconfigs, configs) {
+ if (bar_id && strcmp(current->id, bar_id) != 0)
+ continue;
+
+ if (toggle)
+ hidden_state = (current->hidden_state + 1) % 2;
+
+ DLOG("Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->id, bar_hidden_state, hidden_state);
+ current->hidden_state = hidden_state;
+ changed_sth = true;
+
+ if (bar_id)
+ break;
+ }
+
+ if (bar_id && !changed_sth) {
+ DLOG("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'
+ *
+ */
+void cmd_bar(I3_CMD, char *bar_type, char *bar_value, char *bar_id) {
+ bool ret;
+ if (strcmp(bar_type, "mode") == 0)
+ ret = cmd_bar_mode(bar_value, bar_id);
+ else if (strcmp(bar_type, "hidden_state") == 0)
+ ret = cmd_bar_hidden_state(bar_value, bar_id);
+ else {
+ ELOG("Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
+ ret = false;
+ }
+
+ ysuccess(ret);
+ if (!ret)
+ return;
+
+ update_barconfig();
+}