]> git.sur5r.net Git - i3/i3/blobdiff - src/commands.c
Implement special value 'current' for output. (#2483)
[i3/i3] / src / commands.c
index 1612a5eff608cb8133442fd78cf256060d45684b..58641d6ad627bcd36ade1ae766aba4d1487d814f 100644 (file)
@@ -9,6 +9,7 @@
  * commands.c: all command functions (see commands_parser.c)
  *
  */
+#include <stdint.h>
 #include <float.h>
 #include <stdarg.h>
 
@@ -46,7 +47,7 @@
         }                                               \
     } while (0)
 
-/** If an error occured during parsing of the criteria, we want to exit instead
+/** If an error occurred during parsing of the criteria, we want to exit instead
  * of relying on fallback behavior. See #2091. */
 #define HANDLE_INVALID_MATCH                                   \
     do {                                                       \
@@ -86,17 +87,6 @@ static bool definitelyGreaterThan(float a, float b, float epsilon) {
     return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
 }
 
-/*
- * Returns the output containing the given container.
- */
-static Output *get_output_of_con(Con *con) {
-    Con *output_con = con_get_output(con);
-    Output *output = get_output_by_name(output_con->name);
-    assert(output != NULL);
-
-    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
@@ -716,8 +706,8 @@ void cmd_resize_set(I3_CMD, long cwidth, long cheight) {
  * Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
  *
  */
-void cmd_border(I3_CMD, const char *border_style_str, const char *border_width) {
-    DLOG("border style should be changed to %s with border width %s\n", border_style_str, border_width);
+void cmd_border(I3_CMD, const char *border_style_str, long border_width) {
+    DLOG("border style should be changed to %s with border width %ld\n", border_style_str, border_width);
     owindow *current;
 
     HANDLE_EMPTY_MATCH;
@@ -725,39 +715,35 @@ void cmd_border(I3_CMD, const char *border_style_str, const char *border_width)
     TAILQ_FOREACH(current, &owindows, owindows) {
         DLOG("matching: %p / %s\n", current->con, current->con->name);
         int border_style = current->con->border_style;
-        char *end;
-        int tmp_border_width = -1;
-        tmp_border_width = strtol(border_width, &end, 10);
-        if (end == border_width) {
-            /* no valid digits found */
-            tmp_border_width = -1;
-        }
+        int con_border_width = border_width;
+
         if (strcmp(border_style_str, "toggle") == 0) {
             border_style++;
             border_style %= 3;
             if (border_style == BS_NORMAL)
-                tmp_border_width = 2;
+                con_border_width = 2;
             else if (border_style == BS_NONE)
-                tmp_border_width = 0;
+                con_border_width = 0;
             else if (border_style == BS_PIXEL)
-                tmp_border_width = 1;
+                con_border_width = 1;
         } else {
-            if (strcmp(border_style_str, "normal") == 0)
+            if (strcmp(border_style_str, "normal") == 0) {
                 border_style = BS_NORMAL;
-            else if (strcmp(border_style_str, "pixel") == 0)
+            } else if (strcmp(border_style_str, "pixel") == 0) {
                 border_style = BS_PIXEL;
-            else if (strcmp(border_style_str, "1pixel") == 0) {
+            else if (strcmp(border_style_str, "1pixel") == 0) {
                 border_style = BS_PIXEL;
-                tmp_border_width = 1;
-            } else if (strcmp(border_style_str, "none") == 0)
+                con_border_width = 1;
+            } else if (strcmp(border_style_str, "none") == 0) {
                 border_style = BS_NONE;
-            else {
+            else {
                 ELOG("BUG: called with border_style=%s\n", border_style_str);
                 ysuccess(false);
                 return;
             }
         }
-        con_set_border_style(current->con, border_style, tmp_border_width);
+
+        con_set_border_style(current->con, border_style, logical_px(con_border_width));
     }
 
     cmd_output->needs_tree_render = true;
@@ -1039,7 +1025,7 @@ void cmd_move_con_to_output(I3_CMD, const char *name) {
     TAILQ_FOREACH(current, &owindows, owindows) {
         DLOG("matching: %p / %s\n", current->con, current->con->name);
 
-        Output *current_output = get_output_of_con(current->con);
+        Output *current_output = get_output_for_con(current->con);
         assert(current_output != NULL);
 
         Output *output = get_output_from_string(current_output, name);
@@ -1629,7 +1615,7 @@ void cmd_open(I3_CMD) {
     ystr("success");
     y(bool, true);
     ystr("id");
-    y(integer, (long int)con);
+    y(integer, (uintptr_t)con);
     y(map_close);
 
     cmd_output->needs_tree_render = true;
@@ -1651,7 +1637,7 @@ void cmd_focus_output(I3_CMD, const char *name) {
     Output *output;
 
     TAILQ_FOREACH(current, &owindows, owindows)
-    current_output = get_output_of_con(current->con);
+    current_output = get_output_for_con(current->con);
     assert(current_output != NULL);
 
     output = get_output_from_string(current_output, name);
@@ -1913,7 +1899,9 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
     GREP_FIRST(check_dest, output_get_content(output),
                !strcasecmp(child->name, new_name));
 
-    if (check_dest != NULL) {
+    /* If check_dest == workspace, the user might be changing the case of the
+     * workspace, or it might just be a no-op. */
+    if (check_dest != NULL && check_dest != workspace) {
         yerror("New workspace \"%s\" already exists", new_name);
         return;
     }