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