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