]> git.sur5r.net Git - i3/i3/blobdiff - src/cmdparse.y
Merge branch 'master' into next
[i3/i3] / src / cmdparse.y
index d319bb3f0974e5ac0532be5e531f8201da3da510..7425c31ddd344577f556b31051aaa6b155c239d0 100644 (file)
@@ -155,6 +155,8 @@ bool definitelyGreaterThan(float a, float b, float epsilon) {
 %token              TOK_OPEN            "open"
 %token              TOK_NEXT            "next"
 %token              TOK_PREV            "prev"
+%token              TOK_SCRATCHPAD      "scratchpad"
+%token              TOK_SHOW            "show"
 %token              TOK_SPLIT           "split"
 %token              TOK_HORIZONTAL      "horizontal"
 %token              TOK_VERTICAL        "vertical"
@@ -385,6 +387,7 @@ operation:
     | mark
     | resize
     | nop
+    | scratchpad
     | mode
     ;
 
@@ -436,6 +439,13 @@ restart:
 focus:
     TOK_FOCUS
     {
+        if (focused &&
+            focused->type != CT_WORKSPACE &&
+            focused->fullscreen_mode != CF_NONE) {
+            LOG("Cannot change focus while in fullscreen mode.\n");
+            break;
+        }
+
         owindow *current;
 
         if (match_is_empty(&current_match)) {
@@ -486,6 +496,13 @@ focus:
     }
     | TOK_FOCUS direction
     {
+        if (focused &&
+            focused->type != CT_WORKSPACE &&
+            focused->fullscreen_mode != CF_NONE) {
+            LOG("Cannot change focus while in fullscreen mode.\n");
+            break;
+        }
+
         int direction = $2;
         switch (direction) {
             case TOK_LEFT:
@@ -513,6 +530,13 @@ focus:
     }
     | TOK_FOCUS window_mode
     {
+        if (focused &&
+            focused->type != CT_WORKSPACE &&
+            focused->fullscreen_mode != CF_NONE) {
+            LOG("Cannot change focus while in fullscreen mode.\n");
+            break;
+        }
+
         printf("should focus: ");
 
         if ($2 == TOK_TILING)
@@ -545,6 +569,13 @@ focus:
     }
     | TOK_FOCUS level
     {
+        if (focused &&
+            focused->type != CT_WORKSPACE &&
+            focused->fullscreen_mode != CF_NONE) {
+            LOG("Cannot change focus while in fullscreen mode.\n");
+            break;
+        }
+
         if ($2 == TOK_PARENT)
             level_up();
         else level_down();
@@ -608,6 +639,11 @@ workspace:
     }
     | TOK_WORKSPACE STR
     {
+        if (strncasecmp($2, "__i3_", strlen("__i3_")) == 0) {
+            printf("You cannot switch to the i3 internal workspaces.\n");
+            break;
+        }
+
         printf("should switch to workspace %s\n", $2);
 
         Con *ws = con_get_workspace(focused);
@@ -752,23 +788,29 @@ move:
         printf("moving in direction %d\n", direction);
         if (con_is_floating(focused)) {
             printf("floating move with %d pixels\n", px);
+            Rect newrect = focused->parent->rect;
             if (direction == TOK_LEFT) {
-                focused->parent->rect.x -= px;
+                newrect.x -= px;
             } else if (direction == TOK_RIGHT) {
-                focused->parent->rect.x += px;
+                newrect.x += px;
             } else if (direction == TOK_UP) {
-                focused->parent->rect.y -= px;
+                newrect.y -= px;
             } else if (direction == TOK_DOWN) {
-                focused->parent->rect.y += px;
+                newrect.y += px;
             }
+            floating_reposition(focused->parent, newrect);
         } else {
             tree_move(direction);
+            tree_render();
         }
-
-        tree_render();
     }
     | TOK_MOVE TOK_WORKSPACE STR
     {
+        if (strncasecmp($3, "__i3_", strlen("__i3_")) == 0) {
+            printf("You cannot switch to the i3 internal workspaces.\n");
+            break;
+        }
+
         owindow *current;
 
         /* Error out early to not create a non-existing workspace (in
@@ -826,7 +868,7 @@ move:
     {
         owindow *current;
 
-        printf("should move window to output %s", $3);
+        printf("should move window to output %s\n", $3);
 
         HANDLE_EMPTY_MATCH;
 
@@ -851,8 +893,10 @@ move:
             output = get_output_by_name($3);
         free($3);
 
-        if (!output)
+        if (!output) {
+            printf("No such output found.\n");
             break;
+        }
 
         /* get visible workspace on output */
         Con *ws = NULL;
@@ -867,6 +911,20 @@ move:
 
         tree_render();
     }
+    | TOK_MOVE TOK_SCRATCHPAD
+    {
+        printf("should move window to scratchpad\n");
+        owindow *current;
+
+        HANDLE_EMPTY_MATCH;
+
+        TAILQ_FOREACH(current, &owindows, owindows) {
+            printf("matching: %p / %s\n", current->con, current->con->name);
+            scratchpad_move(current->con);
+        }
+
+        tree_render();
+    }
     ;
 
 append_layout:
@@ -908,6 +966,14 @@ layout_mode:
 mark:
     TOK_MARK STR
     {
+        printf("Clearing all windows which have that mark first\n");
+
+        Con *con;
+        TAILQ_FOREACH(con, &all_cons, all_cons) {
+            if (con->mark && strcmp(con->mark, $2) == 0)
+                FREE(con->mark);
+        }
+
         printf("marking window with str %s\n", $2);
         owindow *current;
 
@@ -915,11 +981,9 @@ mark:
 
         TAILQ_FOREACH(current, &owindows, owindows) {
             printf("matching: %p / %s\n", current->con, current->con->name);
-            current->con->mark = sstrdup($2);
+            current->con->mark = $2;
         }
 
-        free($<string>2);
-
         tree_render();
     }
     ;
@@ -934,6 +998,26 @@ nop:
     }
     ;
 
+scratchpad:
+    TOK_SCRATCHPAD TOK_SHOW
+    {
+        printf("should show scratchpad window\n");
+        owindow *current;
+
+        if (match_is_empty(&current_match)) {
+            scratchpad_show(NULL);
+        } else {
+            TAILQ_FOREACH(current, &owindows, owindows) {
+                printf("matching: %p / %s\n", current->con, current->con->name);
+                scratchpad_show(current->con);
+            }
+        }
+
+        tree_render();
+    }
+    ;
+
+
 resize:
     TOK_RESIZE resize_way direction resize_px resize_tiling
     {
@@ -947,18 +1031,19 @@ resize:
             ppt *= -1;
         }
 
-        if (con_is_floating(focused)) {
+        Con *floating_con;
+        if ((floating_con = con_inside_floating(focused))) {
             printf("floating resize\n");
             if (direction == TOK_UP) {
-                focused->parent->rect.y -= px;
-                focused->parent->rect.height += px;
+                floating_con->rect.y -= px;
+                floating_con->rect.height += px;
             } else if (direction == TOK_DOWN) {
-                focused->parent->rect.height += px;
+                floating_con->rect.height += px;
             } else if (direction == TOK_LEFT) {
-                focused->parent->rect.x -= px;
-                focused->parent->rect.width += px;
+                floating_con->rect.x -= px;
+                floating_con->rect.width += px;
             } else {
-                focused->parent->rect.width += px;
+                floating_con->rect.width += px;
             }
         } else {
             LOG("tiling resize\n");
@@ -967,6 +1052,16 @@ resize:
             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 =
+                (direction == TOK_LEFT || direction == TOK_RIGHT ? HORIZ : VERT);
+
+            while (current->type != CT_WORKSPACE &&
+                   current->type != CT_FLOATING_CON &&
+                   current->parent->orientation != search_orientation)
+                current = current->parent;
+
             /* get the default percentage */
             int children = con_num_children(current->parent);
             Con *other;