52850e935e
(upstream git commit 1089b0b201cef30fbfd03620339f5e8a166feded)
259 lines
10 KiB
Plaintext
259 lines
10 KiB
Plaintext
$OpenBSD: patch-src_commands_c,v 1.3 2012/08/27 09:49:18 dcoppa Exp $
|
|
|
|
From b88ab981fd0a5725ed886a9f9788a5b1e721534c Mon Sep 17 00:00:00 2001
|
|
From: Ondrej Grover <ondrej.grover@gmail.com>
|
|
Date: Wed, 02 May 2012 14:05:27 +0000
|
|
Subject: bugfix: less differentiation between named and numbered workspaces
|
|
|
|
calling workspace by number now also checks for switching back and forth
|
|
and creates a new workspace if no workspace starting with that number is
|
|
found
|
|
|
|
also removed the obsolete tree_render() in favor of setting
|
|
cmd_output->needs_tree_render to true
|
|
|
|
From 1089b0b201cef30fbfd03620339f5e8a166feded Mon Sep 17 00:00:00 2001
|
|
From: Joel Stemmer <stemmertech@gmail.com>
|
|
Date: Sat, 18 Aug 2012 13:25:00 +0000
|
|
Subject: fix resizing floating windows by height
|
|
|
|
From 83dc5d5cb6c71d365cd79b376fcb073e9120144d Mon Sep 17 00:00:00 2001
|
|
From: Michael Stapelberg <michael@stapelberg.de>
|
|
Date: Sun, 22 Jul 2012 19:25:38 +0000
|
|
Subject: Bugfix: Fix duplicate return value for 'resize' command
|
|
|
|
From 4eab046e8fa40535d1a2ad80533915983ef0ee7e Mon Sep 17 00:00:00 2001
|
|
From: Fernando Tarla Cardoso Lemos <fernandotcl@gmail.com>
|
|
Date: Sat, 21 Apr 2012 19:34:25 +0000
|
|
Subject: Allow focus w/ target when in fs in some cases.
|
|
|
|
If the target is in a different workspace, there's no reason why
|
|
we wouldn't allow the user to focus it. We already allow this when
|
|
focusing a workspace, for example.
|
|
|
|
--- src/commands.c.orig Wed Apr 25 23:21:25 2012
|
|
+++ src/commands.c Mon Aug 27 11:43:14 2012
|
|
@@ -65,6 +65,28 @@ static Output *get_output_from_string(Output *current_
|
|
return output;
|
|
}
|
|
|
|
+/*
|
|
+ * Checks whether we switched to a new workspace and returns false in that case,
|
|
+ * signaling that further workspace switching should be done by the calling function
|
|
+ * If not, calls workspace_back_and_forth() if workspace_auto_back_and_forth is set
|
|
+ * and return true, signaling that no further workspace switching should occur in the calling function.
|
|
+ *
|
|
+ */
|
|
+static bool maybe_back_and_forth(struct CommandResult *cmd_output, char *name) {
|
|
+ Con *ws = con_get_workspace(focused);
|
|
+
|
|
+ /* If we switched to a different workspace, do nothing */
|
|
+ if (strcmp(ws->name, name) != 0)
|
|
+ return false;
|
|
+
|
|
+ DLOG("This workspace is already focused.\n");
|
|
+ if (config.workspace_auto_back_and_forth) {
|
|
+ workspace_back_and_forth();
|
|
+ cmd_output->needs_tree_render = true;
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
// This code is commented out because we might recycle it for popping up error
|
|
// messages on parser errors.
|
|
#if 0
|
|
@@ -448,7 +470,7 @@ static void cmd_resize_floating(I3_CMD, char *way, cha
|
|
if (strcmp(direction, "up") == 0) {
|
|
floating_con->rect.y -= px;
|
|
floating_con->rect.height += px;
|
|
- } else if (strcmp(direction, "down") == 0) {
|
|
+ } else if (strcmp(direction, "down") == 0 || strcmp(direction, "height") == 0) {
|
|
floating_con->rect.height += px;
|
|
} else if (strcmp(direction, "left") == 0) {
|
|
floating_con->rect.x -= px;
|
|
@@ -458,7 +480,7 @@ static void cmd_resize_floating(I3_CMD, char *way, cha
|
|
}
|
|
}
|
|
|
|
-static void cmd_resize_tiling_direction(I3_CMD, char *way, char *direction, int ppt) {
|
|
+static bool cmd_resize_tiling_direction(I3_CMD, char *way, char *direction, int ppt) {
|
|
LOG("tiling resize\n");
|
|
/* get the appropriate current container (skip stacked/tabbed cons) */
|
|
Con *current = focused;
|
|
@@ -491,7 +513,7 @@ static void cmd_resize_tiling_direction(I3_CMD, char *
|
|
LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
|
|
(orientation == HORIZ ? "horizontal" : "vertical"));
|
|
cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
+ return false;
|
|
}
|
|
|
|
if (strcmp(direction, "up") == 0 || strcmp(direction, "left") == 0) {
|
|
@@ -502,7 +524,7 @@ static void cmd_resize_tiling_direction(I3_CMD, char *
|
|
if (other == TAILQ_END(workspaces)) {
|
|
LOG("No other container in this direction found, cannot resize.\n");
|
|
cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
+ return false;
|
|
}
|
|
LOG("other->percent = %f\n", other->percent);
|
|
LOG("current->percent before = %f\n", current->percent);
|
|
@@ -525,9 +547,11 @@ static void cmd_resize_tiling_direction(I3_CMD, char *
|
|
} else {
|
|
LOG("Not resizing, already at minimum size\n");
|
|
}
|
|
+
|
|
+ return true;
|
|
}
|
|
|
|
-static void cmd_resize_tiling_width_height(I3_CMD, char *way, char *direction, int ppt) {
|
|
+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;
|
|
@@ -559,13 +583,13 @@ static void cmd_resize_tiling_width_height(I3_CMD, cha
|
|
LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
|
|
(orientation == HORIZ ? "horizontal" : "vertical"));
|
|
cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
+ return false;
|
|
}
|
|
|
|
if (children == 1) {
|
|
LOG("This is the only container, cannot resize.\n");
|
|
cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
+ return false;
|
|
}
|
|
|
|
/* Ensure all the other children have a percentage set. */
|
|
@@ -588,13 +612,13 @@ static void cmd_resize_tiling_width_height(I3_CMD, cha
|
|
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);
|
|
cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
+ return false;
|
|
}
|
|
}
|
|
if (!definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON)) {
|
|
LOG("Not resizing, already at minimum size\n");
|
|
cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
+ return false;
|
|
}
|
|
|
|
current->percent += ((double)ppt / 100.0);
|
|
@@ -606,6 +630,8 @@ static void cmd_resize_tiling_width_height(I3_CMD, cha
|
|
child->percent -= subtract_percent;
|
|
LOG("child->percent after (%p) = %f\n", child, child->percent);
|
|
}
|
|
+
|
|
+ return true;
|
|
}
|
|
|
|
/*
|
|
@@ -628,9 +654,13 @@ void cmd_resize(I3_CMD, char *way, char *direction, ch
|
|
cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, px);
|
|
} else {
|
|
if (strcmp(direction, "width") == 0 ||
|
|
- strcmp(direction, "height") == 0)
|
|
- cmd_resize_tiling_width_height(current_match, cmd_output, way, direction, ppt);
|
|
- else cmd_resize_tiling_direction(current_match, cmd_output, way, direction, ppt);
|
|
+ strcmp(direction, "height") == 0) {
|
|
+ if (!cmd_resize_tiling_width_height(current_match, cmd_output, way, direction, ppt))
|
|
+ return;
|
|
+ } else {
|
|
+ if (!cmd_resize_tiling_direction(current_match, cmd_output, way, direction, ppt))
|
|
+ return;
|
|
+ }
|
|
}
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
@@ -752,12 +782,19 @@ void cmd_workspace_number(I3_CMD, char *which) {
|
|
child->num == parsed_num);
|
|
|
|
if (!workspace) {
|
|
- LOG("There is no workspace with number %d.\n", parsed_num);
|
|
+ LOG("There is no workspace with number %d, creating a new one.\n", parsed_num);
|
|
cmd_output->json_output = sstrdup("{\"success\": false, "
|
|
"\"error\": \"No such workspace\"}");
|
|
+ /* terminate the which string after the endposition of the number */
|
|
+ *endptr = '\0';
|
|
+ if (maybe_back_and_forth(cmd_output, which))
|
|
+ return;
|
|
+ workspace_show_by_name(which);
|
|
+ cmd_output->needs_tree_render = true;
|
|
return;
|
|
}
|
|
-
|
|
+ if (maybe_back_and_forth(cmd_output, which))
|
|
+ return;
|
|
workspace_show(workspace);
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
@@ -789,20 +826,8 @@ void cmd_workspace_name(I3_CMD, char *name) {
|
|
}
|
|
|
|
DLOG("should switch to workspace %s\n", name);
|
|
-
|
|
- Con *ws = con_get_workspace(focused);
|
|
-
|
|
- /* Check if the command wants to switch to the current workspace */
|
|
- if (strcmp(ws->name, name) == 0) {
|
|
- DLOG("This workspace is already focused.\n");
|
|
- if (config.workspace_auto_back_and_forth) {
|
|
- workspace_back_and_forth();
|
|
- tree_render();
|
|
- }
|
|
- cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
- }
|
|
-
|
|
+ if (maybe_back_and_forth(cmd_output, name))
|
|
+ return;
|
|
workspace_show_by_name(name);
|
|
|
|
cmd_output->needs_tree_render = true;
|
|
@@ -1196,16 +1221,7 @@ void cmd_focus_level(I3_CMD, char *level) {
|
|
*/
|
|
void cmd_focus(I3_CMD) {
|
|
DLOG("current_match = %p\n", current_match);
|
|
- if (focused &&
|
|
- focused->type != CT_WORKSPACE &&
|
|
- focused->fullscreen_mode != CF_NONE) {
|
|
- LOG("Cannot change focus while in fullscreen mode.\n");
|
|
- cmd_output->json_output = sstrdup("{\"sucess\": false}");
|
|
- return;
|
|
- }
|
|
|
|
- owindow *current;
|
|
-
|
|
if (match_is_empty(current_match)) {
|
|
ELOG("You have to specify which window/container should be focused.\n");
|
|
ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
|
|
@@ -1217,12 +1233,24 @@ void cmd_focus(I3_CMD) {
|
|
}
|
|
|
|
int count = 0;
|
|
+ owindow *current;
|
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
|
Con *ws = con_get_workspace(current->con);
|
|
/* If no workspace could be found, this was a dock window.
|
|
* Just skip it, you cannot focus dock windows. */
|
|
if (!ws)
|
|
continue;
|
|
+
|
|
+ /* Don't allow the focus switch if the focused and current
|
|
+ * containers are in the same workspace. */
|
|
+ if (focused &&
|
|
+ focused->type != CT_WORKSPACE &&
|
|
+ focused->fullscreen_mode != CF_NONE &&
|
|
+ con_get_workspace(focused) == ws) {
|
|
+ LOG("Cannot change focus while in fullscreen mode (same workspace).\n");
|
|
+ cmd_output->json_output = sstrdup("{\"success\": false}");
|
|
+ return;
|
|
+ }
|
|
|
|
/* If the container is not on the current workspace,
|
|
* workspace_show() will switch to a different workspace and (if
|