]> git.sur5r.net Git - i3/i3/blob - src/cmdparse.y
Bugfix: Switch to appropriate workspace when using 'focus' (+test) (Thanks rogutes)
[i3/i3] / src / cmdparse.y
1 %{
2 /*
3  * vim:ts=4:sw=4:expandtab
4  *
5  * i3 - an improved dynamic tiling window manager
6  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
7  *
8  * cmdparse.y: the parser for commands you send to i3 (or bind on keys)
9  *
10
11  */
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <limits.h>
17
18 #include "all.h"
19
20 /** When the command did not include match criteria (!), we use the currently
21  * focused command. Do not confuse this case with a command which included
22  * criteria but which did not match any windows. This macro has to be called in
23  * every command.
24  */
25 #define HANDLE_EMPTY_MATCH do { \
26     if (match_is_empty(&current_match)) { \
27         owindow *ow = smalloc(sizeof(owindow)); \
28         ow->con = focused; \
29         TAILQ_INIT(&owindows); \
30         TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
31     } \
32 } while (0)
33
34 typedef struct yy_buffer_state *YY_BUFFER_STATE;
35 extern int cmdyylex(struct context *context);
36 extern int cmdyyparse(void);
37 extern FILE *cmdyyin;
38 YY_BUFFER_STATE cmdyy_scan_string(const char *);
39
40 static struct context *context;
41 static Match current_match;
42
43 /*
44  * Helper data structure for an operation window (window on which the operation
45  * will be performed). Used to build the TAILQ owindows.
46  *
47  */
48 typedef struct owindow {
49     Con *con;
50     TAILQ_ENTRY(owindow) owindows;
51 } owindow;
52 static TAILQ_HEAD(owindows_head, owindow) owindows;
53
54 /* Holds the JSON which will be returned via IPC or NULL for the default return
55  * message */
56 static char *json_output;
57
58 /* We don’t need yydebug for now, as we got decent error messages using
59  * yyerror(). Should you ever want to extend the parser, it might be handy
60  * to just comment it in again, so it stays here. */
61 //int cmdyydebug = 1;
62
63 void cmdyyerror(const char *error_message) {
64     ELOG("\n");
65     ELOG("CMD: %s\n", error_message);
66     ELOG("CMD: in command:\n");
67     ELOG("CMD:   %s\n", context->line_copy);
68     ELOG("CMD:   ");
69     for (int c = 1; c <= context->last_column; c++)
70         if (c >= context->first_column)
71                 printf("^");
72         else printf(" ");
73     printf("\n");
74     ELOG("\n");
75     context->compact_error = sstrdup(error_message);
76 }
77
78 int cmdyywrap() {
79     return 1;
80 }
81
82 char *parse_cmd(const char *new) {
83     LOG("COMMAND: *%s*\n", new);
84     cmdyy_scan_string(new);
85
86     match_init(&current_match);
87     context = scalloc(sizeof(struct context));
88     context->filename = "cmd";
89     FREE(json_output);
90     if (cmdyyparse() != 0) {
91         fprintf(stderr, "Could not parse command\n");
92         asprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
93                  context->compact_error, context->first_column);
94         FREE(context->line_copy);
95         FREE(context->compact_error);
96         free(context);
97         return json_output;
98     }
99     printf("done, json output = %s\n", json_output);
100
101     FREE(context->line_copy);
102     FREE(context->compact_error);
103     free(context);
104     return json_output;
105 }
106
107 %}
108
109 %error-verbose
110 %lex-param { struct context *context }
111
112 %union {
113     char *string;
114     char chr;
115     int number;
116 }
117
118 %token              TOK_EXEC            "exec"
119 %token              TOK_EXIT            "exit"
120 %token              TOK_RELOAD          "reload"
121 %token              TOK_RESTART         "restart"
122 %token              TOK_KILL            "kill"
123 %token              TOK_WINDOW          "window"
124 %token              TOK_CLIENT          "client"
125 %token              TOK_FULLSCREEN      "fullscreen"
126 %token              TOK_GLOBAL          "global"
127 %token              TOK_LAYOUT          "layout"
128 %token              TOK_DEFAULT         "default"
129 %token              TOK_STACKED         "stacked"
130 %token              TOK_TABBED          "tabbed"
131 %token              TOK_BORDER          "border"
132 %token              TOK_NORMAL          "normal"
133 %token              TOK_NONE            "none"
134 %token              TOK_1PIXEL          "1pixel"
135 %token              TOK_MODE            "mode"
136 %token              TOK_TILING          "tiling"
137 %token              TOK_FLOATING        "floating"
138 %token              TOK_MODE_TOGGLE     "mode_toggle"
139 %token              TOK_ENABLE          "enable"
140 %token              TOK_DISABLE         "disable"
141 %token              TOK_WORKSPACE       "workspace"
142 %token              TOK_TOGGLE          "toggle"
143 %token              TOK_FOCUS           "focus"
144 %token              TOK_MOVE            "move"
145 %token              TOK_OPEN            "open"
146 %token              TOK_NEXT            "next"
147 %token              TOK_PREV            "prev"
148 %token              TOK_SPLIT           "split"
149 %token              TOK_HORIZONTAL      "horizontal"
150 %token              TOK_VERTICAL        "vertical"
151 %token              TOK_UP              "up"
152 %token              TOK_DOWN            "down"
153 %token              TOK_LEFT            "left"
154 %token              TOK_RIGHT           "right"
155 %token              TOK_PARENT          "parent"
156 %token              TOK_CHILD           "child"
157 %token              TOK_APPEND_LAYOUT   "append_layout"
158 %token              TOK_MARK            "mark"
159 %token              TOK_RESIZE          "resize"
160 %token              TOK_GROW            "grow"
161 %token              TOK_SHRINK          "shrink"
162 %token              TOK_PX              "px"
163 %token              TOK_OR              "or"
164 %token              TOK_PPT             "ppt"
165 %token              TOK_NOP             "nop"
166
167 %token              TOK_CLASS           "class"
168 %token              TOK_ID              "id"
169 %token              TOK_CON_ID          "con_id"
170 %token              TOK_TITLE           "title"
171
172 %token  <string>    STR                 "<string>"
173 %token  <number>    NUMBER              "<number>"
174
175 %type   <number>    direction
176 %type   <number>    split_direction
177 %type   <number>    fullscreen_mode
178 %type   <number>    level
179 %type   <number>    window_mode
180 %type   <number>    boolean
181 %type   <number>    border_style
182 %type   <number>    layout_mode
183 %type   <number>    resize_px
184 %type   <number>    resize_way
185 %type   <number>    resize_tiling
186 %type   <number>    optional_kill_mode
187
188 %%
189
190 commands:
191     commands ';' command
192     | command
193     {
194         owindow *current;
195
196         printf("single command completely parsed, dropping state...\n");
197         while (!TAILQ_EMPTY(&owindows)) {
198             current = TAILQ_FIRST(&owindows);
199             TAILQ_REMOVE(&owindows, current, owindows);
200             free(current);
201         }
202         match_init(&current_match);
203     }
204     ;
205
206 command:
207     match operations
208     ;
209
210 match:
211     | matchstart criteria matchend
212     {
213         printf("match parsed\n");
214     }
215     ;
216
217 matchstart:
218     '['
219     {
220         printf("start\n");
221         match_init(&current_match);
222         TAILQ_INIT(&owindows);
223         /* copy all_cons */
224         Con *con;
225         TAILQ_FOREACH(con, &all_cons, all_cons) {
226             owindow *ow = smalloc(sizeof(owindow));
227             ow->con = con;
228             TAILQ_INSERT_TAIL(&owindows, ow, owindows);
229         }
230     }
231     ;
232
233 matchend:
234     ']'
235     {
236         owindow *next, *current;
237
238         printf("match specification finished, matching...\n");
239         /* copy the old list head to iterate through it and start with a fresh
240          * list which will contain only matching windows */
241         struct owindows_head old = owindows;
242         TAILQ_INIT(&owindows);
243         for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
244             /* make a copy of the next pointer and advance the pointer to the
245              * next element as we are going to invalidate the element’s
246              * next/prev pointers by calling TAILQ_INSERT_TAIL later */
247             current = next;
248             next = TAILQ_NEXT(next, owindows);
249
250             printf("checking if con %p / %s matches\n", current->con, current->con->name);
251             if (current_match.con_id != NULL) {
252                 if (current_match.con_id == current->con) {
253                     printf("matches container!\n");
254                     TAILQ_INSERT_TAIL(&owindows, current, owindows);
255
256                 }
257             } else if (current_match.mark != NULL && current->con->mark != NULL &&
258                     strcasecmp(current_match.mark, current->con->mark) == 0) {
259                 printf("match by mark\n");
260                     TAILQ_INSERT_TAIL(&owindows, current, owindows);
261
262             } else {
263                 if (current->con->window == NULL)
264                     continue;
265                 if (match_matches_window(&current_match, current->con->window)) {
266                     printf("matches window!\n");
267                     TAILQ_INSERT_TAIL(&owindows, current, owindows);
268                 } else {
269                     printf("doesnt match\n");
270                     free(current);
271                 }
272             }
273         }
274
275         TAILQ_FOREACH(current, &owindows, owindows) {
276             printf("matching: %p / %s\n", current->con, current->con->name);
277         }
278
279     }
280     ;
281
282 criteria:
283     criteria criterion
284     | criterion
285     ;
286
287 criterion:
288     TOK_CLASS '=' STR
289     {
290         printf("criteria: class = %s\n", $3);
291         current_match.class = $3;
292     }
293     | TOK_CON_ID '=' STR
294     {
295         printf("criteria: id = %s\n", $3);
296         char *end;
297         long parsed = strtol($3, &end, 10);
298         if (parsed == LONG_MIN ||
299             parsed == LONG_MAX ||
300             parsed < 0 ||
301             (end && *end != '\0')) {
302             ELOG("Could not parse con id \"%s\"\n", $3);
303         } else {
304             current_match.con_id = (Con*)parsed;
305             printf("id as int = %p\n", current_match.con_id);
306         }
307     }
308     | TOK_ID '=' STR
309     {
310         printf("criteria: window id = %s\n", $3);
311         char *end;
312         long parsed = strtol($3, &end, 10);
313         if (parsed == LONG_MIN ||
314             parsed == LONG_MAX ||
315             parsed < 0 ||
316             (end && *end != '\0')) {
317             ELOG("Could not parse window id \"%s\"\n", $3);
318         } else {
319             current_match.id = parsed;
320             printf("window id as int = %d\n", current_match.id);
321         }
322     }
323     | TOK_MARK '=' STR
324     {
325         printf("criteria: mark = %s\n", $3);
326         current_match.mark = $3;
327     }
328     | TOK_TITLE '=' STR
329     {
330         printf("criteria: title = %s\n", $3);
331         current_match.title = $3;
332     }
333     ;
334
335 operations:
336     operation
337     | operations ',' operation
338     ;
339
340 operation:
341     exec
342     | exit
343     | restart
344     | reload
345     | border
346     | layout
347     | append_layout
348     | move
349     | workspace
350     | focus
351     | kill
352     | open
353     | fullscreen
354     | split
355     | floating
356     | mark
357     | resize
358     | nop
359     | mode
360     ;
361
362 exec:
363     TOK_EXEC STR
364     {
365         printf("should execute %s\n", $2);
366         start_application($2);
367         free($2);
368     }
369     ;
370
371 exit:
372     TOK_EXIT
373     {
374         printf("exit, bye bye\n");
375         exit(0);
376     }
377     ;
378
379 reload:
380     TOK_RELOAD
381     {
382         printf("reloading\n");
383         kill_configerror_nagbar(false);
384         load_configuration(conn, NULL, true);
385         x_set_i3_atoms();
386         /* Send an IPC event just in case the ws names have changed */
387         ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"reload\"}");
388     }
389     ;
390
391 restart:
392     TOK_RESTART
393     {
394         printf("restarting i3\n");
395         i3_restart(false);
396     }
397     ;
398
399 focus:
400     TOK_FOCUS
401     {
402         owindow *current;
403
404         if (match_is_empty(&current_match)) {
405             ELOG("You have to specify which window/container should be focused.\n");
406             ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
407
408             asprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
409                      "specify which window/container should be focused\"}");
410             break;
411         }
412
413         int count = 0;
414         TAILQ_FOREACH(current, &owindows, owindows) {
415             Con *ws = con_get_workspace(current->con);
416             workspace_show(ws->name);
417             LOG("focusing %p / %s\n", current->con, current->con->name);
418             con_focus(current->con);
419             count++;
420         }
421
422         if (count > 1)
423             LOG("WARNING: Your criteria for the focus command matches %d containers, "
424                 "while only exactly one container can be focused at a time.\n", count);
425
426         tree_render();
427     }
428     | TOK_FOCUS direction
429     {
430         int direction = $2;
431         switch (direction) {
432             case TOK_LEFT:
433                 LOG("Focusing left\n");
434                 tree_next('p', HORIZ);
435                 break;
436             case TOK_RIGHT:
437                 LOG("Focusing right\n");
438                 tree_next('n', HORIZ);
439                 break;
440             case TOK_UP:
441                 LOG("Focusing up\n");
442                 tree_next('p', VERT);
443                 break;
444             case TOK_DOWN:
445                 LOG("Focusing down\n");
446                 tree_next('n', VERT);
447                 break;
448             default:
449                 ELOG("Invalid focus direction (%d)\n", direction);
450                 break;
451         }
452
453         tree_render();
454     }
455     | TOK_FOCUS window_mode
456     {
457         printf("should focus: ");
458
459         if ($2 == TOK_TILING)
460             printf("tiling\n");
461         else if ($2 == TOK_FLOATING)
462             printf("floating\n");
463         else printf("mode toggle\n");
464
465         Con *ws = con_get_workspace(focused);
466         Con *current;
467         if (ws != NULL) {
468             int to_focus = $2;
469             if ($2 == TOK_MODE_TOGGLE) {
470                 current = TAILQ_FIRST(&(ws->focus_head));
471                 if (current->type == CT_FLOATING_CON)
472                     to_focus = TOK_TILING;
473                 else to_focus = TOK_FLOATING;
474             }
475             TAILQ_FOREACH(current, &(ws->focus_head), focused) {
476                 if ((to_focus == TOK_FLOATING && current->type != CT_FLOATING_CON) ||
477                     (to_focus == TOK_TILING && current->type == CT_FLOATING_CON))
478                     continue;
479
480                 con_focus(con_descend_focused(current));
481                 break;
482             }
483         }
484
485         tree_render();
486     }
487     | TOK_FOCUS level
488     {
489         if ($2 == TOK_PARENT)
490             level_up();
491         else level_down();
492
493         tree_render();
494     }
495     ;
496
497 window_mode:
498     TOK_TILING        { $$ = TOK_TILING; }
499     | TOK_FLOATING    { $$ = TOK_FLOATING; }
500     | TOK_MODE_TOGGLE { $$ = TOK_MODE_TOGGLE; }
501     ;
502
503 level:
504     TOK_PARENT  { $$ = TOK_PARENT; }
505     | TOK_CHILD { $$ = TOK_CHILD;  }
506     ;
507
508 kill:
509     TOK_KILL optional_kill_mode
510     {
511         owindow *current;
512
513         printf("killing!\n");
514         /* check if the match is empty, not if the result is empty */
515         if (match_is_empty(&current_match))
516             tree_close_con($2);
517         else {
518             TAILQ_FOREACH(current, &owindows, owindows) {
519                 printf("matching: %p / %s\n", current->con, current->con->name);
520                 tree_close(current->con, $2, false);
521             }
522         }
523
524         tree_render();
525     }
526     ;
527
528 optional_kill_mode:
529     /* empty */             { $$ = KILL_WINDOW; }
530     | TOK_WINDOW { $$ = KILL_WINDOW; }
531     | TOK_CLIENT { $$ = KILL_CLIENT; }
532     ;
533
534 workspace:
535     TOK_WORKSPACE TOK_NEXT
536     {
537         workspace_next();
538         tree_render();
539     }
540     | TOK_WORKSPACE TOK_PREV
541     {
542         workspace_prev();
543         tree_render();
544     }
545     | TOK_WORKSPACE STR
546     {
547         printf("should switch to workspace %s\n", $2);
548         workspace_show($2);
549         free($2);
550
551         tree_render();
552     }
553     ;
554
555 open:
556     TOK_OPEN
557     {
558         printf("opening new container\n");
559         Con *con = tree_open_con(NULL, NULL);
560         con_focus(con);
561         asprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
562
563         tree_render();
564     }
565     ;
566
567 fullscreen:
568     TOK_FULLSCREEN fullscreen_mode
569     {
570         printf("toggling fullscreen, mode = %s\n", ($2 == CF_OUTPUT ? "normal" : "global"));
571         owindow *current;
572
573         HANDLE_EMPTY_MATCH;
574
575         TAILQ_FOREACH(current, &owindows, owindows) {
576             printf("matching: %p / %s\n", current->con, current->con->name);
577             con_toggle_fullscreen(current->con, $2);
578         }
579
580         tree_render();
581     }
582     ;
583
584 fullscreen_mode:
585     /* empty */  { $$ = CF_OUTPUT; }
586     | TOK_GLOBAL { $$ = CF_GLOBAL; }
587     ;
588
589 split:
590     TOK_SPLIT split_direction
591     {
592         /* TODO: use matches */
593         printf("splitting in direction %c\n", $2);
594         tree_split(focused, ($2 == 'v' ? VERT : HORIZ));
595
596         tree_render();
597     }
598     ;
599
600 split_direction:
601     TOK_HORIZONTAL  { $$ = 'h'; }
602     | 'h'           { $$ = 'h'; }
603     | TOK_VERTICAL  { $$ = 'v'; }
604     | 'v'           { $$ = 'v'; }
605     ;
606
607 floating:
608     TOK_FLOATING boolean
609     {
610         HANDLE_EMPTY_MATCH;
611
612         owindow *current;
613         TAILQ_FOREACH(current, &owindows, owindows) {
614             printf("matching: %p / %s\n", current->con, current->con->name);
615             if ($2 == TOK_TOGGLE) {
616                 printf("should toggle mode\n");
617                 toggle_floating_mode(current->con, false);
618             } else {
619                 printf("should switch mode to %s\n", ($2 == TOK_FLOATING ? "floating" : "tiling"));
620                 if ($2 == TOK_ENABLE) {
621                     floating_enable(current->con, false);
622                 } else {
623                     floating_disable(current->con, false);
624                 }
625             }
626         }
627
628         tree_render();
629     }
630     ;
631
632 boolean:
633     TOK_ENABLE    { $$ = TOK_ENABLE; }
634     | TOK_DISABLE { $$ = TOK_DISABLE; }
635     | TOK_TOGGLE  { $$ = TOK_TOGGLE; }
636     ;
637
638 border:
639     TOK_BORDER border_style
640     {
641         printf("border style should be changed to %d\n", $2);
642         owindow *current;
643
644         HANDLE_EMPTY_MATCH;
645
646         TAILQ_FOREACH(current, &owindows, owindows) {
647             printf("matching: %p / %s\n", current->con, current->con->name);
648             if ($2 == TOK_TOGGLE) {
649                 current->con->border_style++;
650                 current->con->border_style %= 3;
651             } else current->con->border_style = $2;
652         }
653
654         tree_render();
655     }
656     ;
657
658 border_style:
659     TOK_NORMAL      { $$ = BS_NORMAL; }
660     | TOK_NONE      { $$ = BS_NONE; }
661     | TOK_1PIXEL    { $$ = BS_1PIXEL; }
662     | TOK_TOGGLE    { $$ = TOK_TOGGLE; }
663     ;
664
665 move:
666     TOK_MOVE direction
667     {
668         printf("moving in direction %d\n", $2);
669         tree_move($2);
670
671         tree_render();
672     }
673     | TOK_MOVE TOK_WORKSPACE STR
674     {
675         owindow *current;
676
677         printf("should move window to workspace %s\n", $3);
678         /* get the workspace */
679         Con *ws = workspace_get($3, NULL);
680         free($3);
681
682         HANDLE_EMPTY_MATCH;
683
684         TAILQ_FOREACH(current, &owindows, owindows) {
685             printf("matching: %p / %s\n", current->con, current->con->name);
686             con_move_to_workspace(current->con, ws);
687         }
688
689         tree_render();
690     }
691     ;
692
693 append_layout:
694     TOK_APPEND_LAYOUT STR
695     {
696         printf("restoring \"%s\"\n", $2);
697         tree_append_json($2);
698         free($2);
699         tree_render();
700     }
701     ;
702
703 layout:
704     TOK_LAYOUT layout_mode
705     {
706         printf("changing layout to %d\n", $2);
707         owindow *current;
708
709         /* check if the match is empty, not if the result is empty */
710         if (match_is_empty(&current_match))
711             con_set_layout(focused->parent, $2);
712         else {
713             TAILQ_FOREACH(current, &owindows, owindows) {
714                 printf("matching: %p / %s\n", current->con, current->con->name);
715                 con_set_layout(current->con, $2);
716             }
717         }
718
719         tree_render();
720     }
721     ;
722
723 layout_mode:
724     TOK_DEFAULT   { $$ = L_DEFAULT; }
725     | TOK_STACKED { $$ = L_STACKED; }
726     | TOK_TABBED  { $$ = L_TABBED; }
727     ;
728
729 mark:
730     TOK_MARK STR
731     {
732         printf("marking window with str %s\n", $2);
733         owindow *current;
734
735         HANDLE_EMPTY_MATCH;
736
737         TAILQ_FOREACH(current, &owindows, owindows) {
738             printf("matching: %p / %s\n", current->con, current->con->name);
739             current->con->mark = sstrdup($2);
740         }
741
742         free($<string>2);
743
744         tree_render();
745     }
746     ;
747
748 nop:
749     TOK_NOP STR
750     {
751         printf("-------------------------------------------------\n");
752         printf("  NOP: %s\n", $2);
753         printf("-------------------------------------------------\n");
754         free($2);
755     }
756     ;
757
758 resize:
759     TOK_RESIZE resize_way direction resize_px resize_tiling
760     {
761         /* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
762         printf("resizing in way %d, direction %d, px %d or ppt %d\n", $2, $3, $4, $5);
763         int direction = $3;
764         int px = $4;
765         int ppt = $5;
766         if ($2 == TOK_SHRINK) {
767             px *= -1;
768             ppt *= -1;
769         }
770
771         if (con_is_floating(focused)) {
772             printf("floating resize\n");
773             if (direction == TOK_UP) {
774                 focused->parent->rect.y -= px;
775                 focused->parent->rect.height += px;
776             } else if (direction == TOK_DOWN) {
777                 focused->rect.height += px;
778             } else if (direction == TOK_LEFT) {
779                 focused->rect.x -= px;
780                 focused->rect.width += px;
781             } else {
782                 focused->rect.width += px;
783             }
784         } else {
785             LOG("tiling resize\n");
786             /* get the default percentage */
787             int children = con_num_children(focused->parent);
788             Con *other;
789             LOG("ins. %d children\n", children);
790             double percentage = 1.0 / children;
791             LOG("default percentage = %f\n", percentage);
792
793             if (direction == TOK_UP || direction == TOK_LEFT) {
794                 other = TAILQ_PREV(focused, nodes_head, nodes);
795             } else {
796                 other = TAILQ_NEXT(focused, nodes);
797             }
798             if (other == TAILQ_END(workspaces)) {
799                 LOG("No other container in this direction found, cannot resize.\n");
800                 return 0;
801             }
802             LOG("other->percent = %f\n", other->percent);
803             LOG("focused->percent before = %f\n", focused->percent);
804             if (focused->percent == 0.0)
805                 focused->percent = percentage;
806             if (other->percent == 0.0)
807                 other->percent = percentage;
808             focused->percent += ((double)ppt / 100.0);
809             other->percent -= ((double)ppt / 100.0);
810             LOG("focused->percent after = %f\n", focused->percent);
811             LOG("other->percent after = %f\n", other->percent);
812         }
813
814         tree_render();
815     }
816     ;
817
818 resize_px:
819     /* empty */
820     {
821         $$ = 10;
822     }
823     | NUMBER TOK_PX
824     {
825         $$ = $1;
826     }
827     ;
828
829 resize_tiling:
830     /* empty */
831     {
832         $$ = 10;
833     }
834     | TOK_OR NUMBER TOK_PPT
835     {
836         $$ = $2;
837     }
838     ;
839
840 resize_way:
841     TOK_GROW        { $$ = TOK_GROW; }
842     | TOK_SHRINK    { $$ = TOK_SHRINK; }
843     ;
844
845 direction:
846     TOK_UP          { $$ = TOK_UP; }
847     | TOK_DOWN      { $$ = TOK_DOWN; }
848     | TOK_LEFT      { $$ = TOK_LEFT; }
849     | TOK_RIGHT     { $$ = TOK_RIGHT; }
850     ;
851
852 mode:
853     TOK_MODE STR
854     {
855         switch_mode($2);
856     }
857     ;