]> git.sur5r.net Git - i3/i3/commitdiff
Merge branch 'master' into next
authorMichael Stapelberg <michael@stapelberg.de>
Thu, 24 Jan 2013 13:45:14 +0000 (14:45 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 24 Jan 2013 13:45:14 +0000 (14:45 +0100)
62 files changed:
DEPENDS
debian/changelog
debian/control
docs/hacking-howto
docs/i3-pod2html
docs/ipc
docs/userguide
i3-config-wizard/cfgparse.l [deleted file]
i3-config-wizard/cfgparse.y [deleted file]
i3-config-wizard/i3-config-wizard.mk
i3-config-wizard/main.c
i3-dmenu-desktop
i3-dump-log/main.c
i3-input/main.c
i3-msg/main.c
i3-nagbar/main.c
i3bar/include/xcb.h
i3bar/include/xcb_atoms.def
i3bar/src/ipc.c
i3bar/src/xcb.c
include/config.h
include/config_parser.h
include/data.h
include/i3/ipc.h
include/key_press.h
include/libi3.h
include/util.h
include/xcb.h
libi3/get_process_filename.c [new file with mode: 0644]
libi3/ipc_recv_message.c
libi3/ipc_send_message.c
parser-specs/config.spec
src/cfgparse.l [deleted file]
src/cfgparse.y [deleted file]
src/commands.c
src/con.c
src/config.c
src/config_parser.c
src/display_version.c
src/handlers.c
src/i3.mk
src/ipc.c
src/key_press.c
src/main.c
src/manage.c
src/render.c
src/scratchpad.c
src/tree.c
src/util.c
src/workspace.c
src/x.c
testcases/complete-run.pl
testcases/new-test
testcases/t/132-move-workspace.t
testcases/t/166-assign.t
testcases/t/173-regress-focus-assign.t
testcases/t/175-startup-notification.t
testcases/t/185-scratchpad.t
testcases/t/189-floating-constraints.t
testcases/t/202-scratchpad-criteria.t [new file with mode: 0644]
testcases/t/503-workspace.t
testcases/t/510-focus-across-outputs.t

diff --git a/DEPENDS b/DEPENDS
index fe9ba17f9eb66ad960ac734d1d7034ec7059a084..4b0902723a179ee6d1a4ed31102b61eeceb78bd0 100644 (file)
--- a/DEPENDS
+++ b/DEPENDS
@@ -10,9 +10,7 @@
 │ pkg-config  │ 0.25   │ 0.26   │ http://pkgconfig.freedesktop.org/      │
 │ libxcb      │ 1.1.93 │ 1.7    │ http://xcb.freedesktop.org/dist/       │
 │ xcb-util    │ 0.3.3  │ 0.3.8  │ http://xcb.freedesktop.org/dist/       │
-│ libev       │ 4.0    │ 4.04   │ http://libev.schmorp.de/               │
-│ flex        │ 2.5.35 │ 2.5.35 │ http://flex.sourceforge.net/           │
-│ bison       │ 2.4.1  │ 2.4.1  │ http://www.gnu.org/software/bison/     │
+│ libev       │ 4.0    │ 4.11   │ http://libev.schmorp.de/               │
 │ yajl        │ 1.0.8  │ 2.0.1  │ http://lloyd.github.com/yajl/          │
 │ asciidoc    │ 8.3.0  │ 8.6.4  │ http://www.methods.co.nz/asciidoc/     │
 │ xmlto       │ 0.0.23 │ 0.0.23 │ http://www.methods.co.nz/asciidoc/     │
index dcb966aed79ada9febb06ab3200d183efe0d2511..ebdfbcef3ec7369c850fa23966f225ab4b92a40a 100644 (file)
@@ -1,3 +1,9 @@
+i3-wm (4.4.1-0) unstable; urgency=low
+
+  * NOT YET RELEASED
+
+ -- Michael Stapelberg <stapelberg@debian.org>  Wed, 12 Dec 2012 00:23:32 +0100
+
 i3-wm (4.4-1) experimental; urgency=low
 
   * New upstream release
index 02f00de25f2e7cb13c2d2e2250ba7fb040ec1846..f9ecb5582319e63446cddc6c93ed6ff33c5a44b8 100644 (file)
@@ -14,9 +14,7 @@ Build-Depends: debhelper (>= 7.0.50~),
                xmlto,
                docbook-xml,
                pkg-config,
-               libev-dev,
-               flex,
-               bison,
+               libev-dev (>= 1:4.04),
                libyajl-dev,
                libpcre3-dev,
                libstartup-notification0-dev (>= 0.10),
index 8a246efc3efc03c5220c20f6658799d3a0c2af79..05fc9cbda30dbf769abee9e6b5e44f8722710158 100644 (file)
@@ -971,7 +971,8 @@ apply to the branch, preserving your commit message and name:
 git format-patch origin
 -----------------------
 
-Just send us the generated file via email.
+Just send the generated file via email to the i3-discuss mailing list, see
+http://i3wm.org/contact/
 
 == Thought experiments
 
index 56a769f8b8247eb503c77da3a03a25e7cbf8fff0..bda7e8d7dc69902db6a13ec5b24e937ebb034da5 100755 (executable)
@@ -30,7 +30,7 @@ $parser->html_header_before_title(
 <link rel="icon" type="image/png" href="/favicon.png">
 <meta charset="utf-8">
 <meta name="generator" content="Pod::Simple::HTML">
-<meta name="description" content="i3 Perl documentation (testsuite)">
+<meta name="description" content="i3 Perl documentation">
 <link rel="stylesheet" href="http://i3wm.org/css/style.css" type="text/css" />
 <style type="text/css">
 .pod pre {
@@ -81,7 +81,7 @@ $parser->html_header_after_title(
                        </ul>
        <br style="clear: both">
 <div id="content" class="pod">
-<h1>i3 Perl documentation (testsuite)</h1>
+<h1>i3 Perl documentation</h1>
 
 EOF
 );
index 17397548a25f59e20ba8f533c5ac59aee318c43f..c32c59e35864fbc2026ab3f685515299085324c1 100644 (file)
--- a/docs/ipc
+++ b/docs/ipc
@@ -712,3 +712,5 @@ Perl::
 Python::
        * https://github.com/whitelynx/i3ipc
        * https://github.com/ziberna/i3-py (includes higher-level features)
+Go::
+       * https://github.com/proxypoke/i3ipc
index 5880541c22a8ce462b9b98fd3d662216109ffe29..52571bd4b6745cb36ca2007198bb0ee0ea3ae784 100644 (file)
@@ -324,7 +324,7 @@ font pango:[family list] [style options] [size]
 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
 font pango:DejaVu Sans Mono 10
 font pango:DejaVu Sans Mono, Terminus Bold Semi-Condensed 11
-font pango:Terminus 11x
+font pango:Terminus 11px
 --------------------------------------------------------------
 
 [[keybindings]]
@@ -1612,7 +1612,7 @@ bindsym $mod+r mode "resize"
 Often when in a multi-monitor environment, you want to quickly jump to a
 specific window. For example, while working on workspace 3 you may want to
 jump to your mail client to email your boss that you’ve achieved some
-important goal. Instead of figuring out how to navigate to your mailclient,
+important goal. Instead of figuring out how to navigate to your mail client,
 it would be more convenient to have a shortcut. You can use the +focus+ command
 with criteria for that.
 
diff --git a/i3-config-wizard/cfgparse.l b/i3-config-wizard/cfgparse.l
deleted file mode 100644 (file)
index 772b847..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-%option nounput
-%option noinput
-%option noyy_top_state
-%option stack
-
-%{
-/*
- * vim:ts=8:expandtab
- *
- */
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include "cfgparse.tab.h"
-
-int yycolumn = 1;
-
-struct context {
-        int line_number;
-        char *line_copy;
-
-        char *compact_error;
-
-        /* These are the same as in YYLTYPE */
-        int first_column;
-        int last_column;
-};
-
-
-#define YY_DECL int yylex (struct context *context)
-
-#define YY_USER_ACTION { \
-        context->first_column = yycolumn; \
-        context->last_column = yycolumn+yyleng-1; \
-        yycolumn += yyleng; \
-}
-
-%}
-
-EOL    (\r?\n)
-
-%s BINDCODE_COND
-%s BIND_AWS_COND
-%s BIND_A2WS_COND
-%x BUFFER_LINE
-
-%%
-
-       {
-               /* This is called when a new line is lexed. We only want the
-                * first line to match to go into state BUFFER_LINE */
-               if (context->line_number == 0) {
-                       context->line_number = 1;
-                       BEGIN(INITIAL);
-                       yy_push_state(BUFFER_LINE);
-               }
-       }
-
-<BUFFER_LINE>^[^\r\n]*/{EOL}? {
-       /* save whole line */
-       context->line_copy = strdup(yytext);
-
-       yyless(0);
-       yy_pop_state();
-       yy_set_bol(true);
-       yycolumn = 1;
-}
-
-
-<BIND_A2WS_COND>[^\n]+          { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
-[0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
-bind                            { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
-bindcode                        { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
-Mod1                            { yylval.number = (1 << 3); return MODIFIER; }
-Mod2                            { yylval.number = (1 << 4); return MODIFIER; }
-Mod3                            { yylval.number = (1 << 5); return MODIFIER; }
-Mod4                            { yylval.number = (1 << 6); return MODIFIER; }
-Mod5                            { yylval.number = (1 << 7); return MODIFIER; }
-Mode_switch                     { yylval.number = (1 << 8); return MODIFIER; }
-$mod                           { yylval.number = (1 << 9); return TOKMODVAR; }
-control                         { return TOKCONTROL; }
-ctrl                            { return TOKCONTROL; }
-shift                           { return TOKSHIFT; }
-{EOL}                           {
-                                 if (context->line_copy) {
-                                    free(context->line_copy);
-                                   context->line_copy = NULL;
-                                 }
-                                  context->line_number++;
-                                  BEGIN(INITIAL);
-                                  yy_push_state(BUFFER_LINE);
-                                }
-<BINDCODE_COND>[ \t]+           { BEGIN(BIND_AWS_COND); return WHITESPACE; }
-<BIND_AWS_COND>[ \t]+           { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
-[ \t]+                          { return WHITESPACE; }
-.                               { return (int)yytext[0]; }
-
-<<EOF>> {
-        while (yy_start_stack_ptr > 0)
-                yy_pop_state();
-        yyterminate();
-}
-
-%%
diff --git a/i3-config-wizard/cfgparse.y b/i3-config-wizard/cfgparse.y
deleted file mode 100644 (file)
index 17c3953..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-%{
-/*
- * vim:ts=4:sw=4:expandtab
- *
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <X11/Xlib.h>
-#include <X11/XKBlib.h>
-
-#include "libi3.h"
-
-extern Display *dpy;
-
-struct context {
-        int line_number;
-        char *line_copy;
-
-        char *compact_error;
-
-        /* These are the same as in YYLTYPE */
-        int first_column;
-        int last_column;
-
-        char *result;
-};
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-extern int yylex(struct context *context);
-extern int yyparse(void);
-extern FILE *yyin;
-YY_BUFFER_STATE yy_scan_string(const char *);
-
-static struct context *context;
-static xcb_connection_t *conn;
-static xcb_key_symbols_t *keysyms;
-
-/* We don’t need yydebug for now, as we got decent error messages using
- * yyerror(). Should you ever want to extend the parser, it might be handy
- * to just comment it in again, so it stays here. */
-//int yydebug = 1;
-
-void yyerror(const char *error_message) {
-    fprintf(stderr, "\n");
-    fprintf(stderr, "CONFIG: %s\n", error_message);
-    fprintf(stderr, "CONFIG: line %d:\n",
-        context->line_number);
-    fprintf(stderr, "CONFIG:   %s\n", context->line_copy);
-    fprintf(stderr, "CONFIG:   ");
-    for (int c = 1; c <= context->last_column; c++)
-        if (c >= context->first_column)
-            fprintf(stderr, "^");
-        else fprintf(stderr, " ");
-    fprintf(stderr, "\n");
-    fprintf(stderr, "\n");
-}
-
-int yywrap() {
-    return 1;
-}
-
-char *rewrite_binding(const char *bindingline) {
-    char *result = NULL;
-
-    conn = xcb_connect(NULL, NULL);
-    if (conn == NULL || xcb_connection_has_error(conn)) {
-        fprintf(stderr, "Cannot open display\n");
-        exit(1);
-    }
-    keysyms = xcb_key_symbols_alloc(conn);
-
-    context = calloc(sizeof(struct context), 1);
-
-    yy_scan_string(bindingline);
-
-    if (yyparse() != 0) {
-        fprintf(stderr, "Could not parse configfile\n");
-        exit(1);
-    }
-
-    result = context->result;
-
-    if (context->line_copy)
-        free(context->line_copy);
-    free(context);
-    xcb_key_symbols_free(keysyms);
-    xcb_disconnect(conn);
-
-    return result;
-}
-
-/* XXX: does not work for combinations of modifiers yet */
-static char *modifier_to_string(int modifiers) {
-    //printf("should convert %d to string\n", modifiers);
-    if (modifiers == (1 << 3))
-        return strdup("$mod+");
-    else if (modifiers == ((1 << 3) | (1 << 0)))
-        return strdup("$mod+Shift+");
-    else if (modifiers == (1 << 9))
-        return strdup("$mod+");
-    else if (modifiers == ((1 << 9) | (1 << 0)))
-        return strdup("$mod+Shift+");
-    else if (modifiers == (1 << 0))
-        return strdup("Shift+");
-    else return strdup("");
-}
-
-/*
- * Returns true if sym is bound to any key except for 'except_keycode' on the
- * first four layers (normal, shift, mode_switch, mode_switch + shift).
- *
- */
-static bool keysym_used_on_other_key(KeySym sym, xcb_keycode_t except_keycode) {
-    xcb_keycode_t i,
-                  min_keycode = xcb_get_setup(conn)->min_keycode,
-                  max_keycode = xcb_get_setup(conn)->max_keycode;
-
-    for (i = min_keycode; i && i <= max_keycode; i++) {
-        if (i == except_keycode)
-            continue;
-        for (int level = 0; level < 4; level++) {
-            if (xcb_key_symbols_get_keysym(keysyms, i, level) != sym)
-                continue;
-            return true;
-        }
-    }
-    return false;
-}
-
-%}
-
-%error-verbose
-%lex-param { struct context *context }
-
-%union {
-    int number;
-    char *string;
-}
-
-%token <number>NUMBER "<number>"
-%token <string>STR "<string>"
-%token TOKBINDCODE
-%token TOKMODVAR "$mod"
-%token MODIFIER "<modifier>"
-%token TOKCONTROL "control"
-%token TOKSHIFT "shift"
-%token WHITESPACE "<whitespace>"
-
-%%
-
-lines: /* empty */
-    | lines WHITESPACE bindcode
-    | lines error
-    | lines bindcode
-    ;
-
-bindcode:
-    TOKBINDCODE WHITESPACE binding_modifiers NUMBER WHITESPACE STR
-    {
-        //printf("\tFound keycode binding mod%d with key %d and command %s\n", $<number>3, $4, $<string>6);
-        int level = 0;
-        if (($<number>3 & (1 << 0))) {
-            /* When shift is included, we really need to use the second-level
-             * symbol (upper-case). The lower-case symbol could be on a
-             * different key than the upper-case one (unlikely for letters, but
-             * more likely for special characters). */
-            level = 1;
-
-            /* Try to use the keysym on the first level (lower-case). In case
-             * this doesn’t make it ambiguous (think of a keyboard layout
-             * having '1' on two different keys, but '!' only on keycode 10),
-             * we’ll stick with the keysym of the first level.
-             *
-             * This reduces a lot of confusion for users who switch keyboard
-             * layouts from qwerty to qwertz or other slight variations of
-             * qwerty (yes, that happens quite often). */
-            KeySym sym = XkbKeycodeToKeysym(dpy, $4, 0, 0);
-            if (!keysym_used_on_other_key(sym, $4))
-                level = 0;
-        }
-        KeySym sym = XkbKeycodeToKeysym(dpy, $4, 0, level);
-        char *str = XKeysymToString(sym);
-        char *modifiers = modifier_to_string($<number>3);
-        sasprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $<string>6);
-        free(modifiers);
-    }
-    ;
-
-binding_modifiers:
-    /* NULL */                               { $<number>$ = 0; }
-    | binding_modifier
-    | binding_modifiers '+' binding_modifier { $<number>$ = $<number>1 | $<number>3; }
-    | binding_modifiers '+'                  { $<number>$ = $<number>1; }
-    ;
-
-binding_modifier:
-    MODIFIER        { $<number>$ = $<number>1; }
-    | TOKMODVAR     { $<number>$ = $<number>1; }
-    | TOKCONTROL    { $<number>$ = (1 << 2); }
-    | TOKSHIFT      { $<number>$ = (1 << 0); }
-    ;
index 3847786ece17a46ef5386e3b12147bbab457ba10..e759b4bd8c9fae4c17e85a0367febdbd4b7e3566 100644 (file)
@@ -2,27 +2,18 @@ ALL_TARGETS += i3-config-wizard/i3-config-wizard
 INSTALL_TARGETS += install-i3-config-wizard
 CLEAN_TARGETS += clean-i3-config-wizard
 
-i3_config_wizard_SOURCES_GENERATED  = i3-config-wizard/cfgparse.tab.c i3-config-wizard/cfgparse.yy.c
-i3_config_wizard_SOURCES           := $(filter-out $(i3_config_wizard_SOURCES_GENERATED),$(wildcard i3-config-wizard/*.c))
+i3_config_wizard_SOURCES           := $(wildcard i3-config-wizard/*.c)
 i3_config_wizard_HEADERS           := $(wildcard i3-config-wizard/*.h)
 i3_config_wizard_CFLAGS             = $(XCB_CFLAGS) $(XCB_KBD_CFLAGS) $(X11_CFLAGS) $(PANGO_CFLAGS)
 i3_config_wizard_LIBS               = $(XCB_LIBS) $(XCB_KBD_LIBS) $(X11_LIBS) $(PANGO_LIBS)
 
-i3_config_wizard_OBJECTS := $(i3_config_wizard_SOURCES_GENERATED:.c=.o) $(i3_config_wizard_SOURCES:.c=.o)
+i3_config_wizard_OBJECTS := $(i3_config_wizard_SOURCES:.c=.o)
 
 
-i3-config-wizard/%.o: i3-config-wizard/%.c $(i3_config_wizard_HEADERS)
+i3-config-wizard/%.o: i3-config-wizard/%.c $(i3_config_wizard_HEADERS) i3-config-parser.stamp
        echo "[i3-config-wizard] CC $<"
        $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_config_wizard_CFLAGS) $(I3_CFLAGS) $(CFLAGS) -c -o $@ $<
 
-i3-config-wizard/cfgparse.yy.c: i3-config-wizard/cfgparse.l i3-config-wizard/cfgparse.tab.o $(i3_config_wizard_HEADERS)
-       echo "[i3-config-wizard] LEX $<"
-       $(FLEX) -i -o $@ $<
-
-i3-config-wizard/cfgparse.tab.c: i3-config-wizard/cfgparse.y $(i3_config_wizard_HEADERS)
-       echo "[i3-config-wizard] YACC $<"
-       $(BISON) --debug --verbose -b $(basename $< .y) -d $<
-
 i3-config-wizard/i3-config-wizard: libi3.a $(i3_config_wizard_OBJECTS)
        echo "[i3-config-wizard] Link i3-config-wizard"
        $(CC) $(I3_LDFLAGS) $(LDFLAGS) -o $@ $(filter-out libi3.a,$^) $(LIBS) $(i3_config_wizard_LIBS)
@@ -34,4 +25,4 @@ install-i3-config-wizard: i3-config-wizard/i3-config-wizard
 
 clean-i3-config-wizard:
        echo "[i3-config-wizard] Clean"
-       rm -f $(i3_config_wizard_OBJECTS) $(i3_config_wizard_SOURCES_GENERATED) i3-config-wizard/i3-config-wizard i3-config-wizard/cfgparse.{output,dot,tab.h,y.o}
+       rm -f $(i3_config_wizard_OBJECTS) $(i3_config_wizard_SOURCES_GENERATED) i3-config-wizard/i3-config-wizard i3-config-wizard/cfgparse.*
index 1eb738f631ba3aa34a9dbe62ad08030eb586651a..54c8e0245478d11b97677d8d445e4518d7ee8510 100644 (file)
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <glob.h>
+#include <assert.h>
 
 #include <xcb/xcb.h>
 #include <xcb/xcb_aux.h>
@@ -44,6 +45,7 @@
 
 #include <X11/Xlib.h>
 #include <X11/keysym.h>
+#include <X11/XKBlib.h>
 
 /* We need SYSCONFDIR for the path to the keycode config template, so raise an
  * error if it’s not defined for whatever reason */
@@ -68,6 +70,7 @@ enum { MOD_Mod1, MOD_Mod4 } modifier = MOD_Mod4;
 static char *config_path;
 static uint32_t xcb_numlock_mask;
 xcb_connection_t *conn;
+static xcb_key_symbols_t *keysyms;
 xcb_screen_t *root_screen;
 static xcb_get_modifier_mapping_reply_t *modmap_reply;
 static i3Font font;
@@ -80,9 +83,342 @@ static xcb_key_symbols_t *symbols;
 xcb_window_t root;
 Display *dpy;
 
-char *rewrite_binding(const char *bindingline);
 static void finish();
 
+#include "GENERATED_config_enums.h"
+
+typedef struct token {
+    char *name;
+    char *identifier;
+    /* This might be __CALL */
+    cmdp_state next_state;
+    union {
+        uint16_t call_identifier;
+    } extra;
+} cmdp_token;
+
+typedef struct tokenptr {
+    cmdp_token *array;
+    int n;
+} cmdp_token_ptr;
+
+
+#include "GENERATED_config_tokens.h"
+
+static cmdp_state state;
+/* A list which contains the states that lead to the current state, e.g.
+ * INITIAL, WORKSPACE_LAYOUT.
+ * When jumping back to INITIAL, statelist_idx will simply be set to 1
+ * (likewise for other states, e.g. MODE or BAR).
+ * This list is used to process the nearest error token. */
+static cmdp_state statelist[10] = { INITIAL };
+/* NB: statelist_idx points to where the next entry will be inserted */
+static int statelist_idx = 1;
+
+struct stack_entry {
+    /* Just a pointer, not dynamically allocated. */
+    const char *identifier;
+    enum {
+        STACK_STR = 0,
+        STACK_LONG = 1,
+    } type;
+    union {
+        char *str;
+        long num;
+    } val;
+};
+
+/* 10 entries should be enough for everybody. */
+static struct stack_entry stack[10];
+
+/*
+ * Pushes a string (identified by 'identifier') on the stack. We simply use a
+ * single array, since the number of entries we have to store is very small.
+ *
+ */
+static void push_string(const char *identifier, const char *str) {
+    for (int c = 0; c < 10; c++) {
+        if (stack[c].identifier != NULL &&
+            strcmp(stack[c].identifier, identifier) != 0)
+            continue;
+        if (stack[c].identifier == NULL) {
+            /* Found a free slot, let’s store it here. */
+            stack[c].identifier = identifier;
+            stack[c].val.str = sstrdup(str);
+            stack[c].type = STACK_STR;
+        } else {
+            /* Append the value. */
+            char *prev = stack[c].val.str;
+            sasprintf(&(stack[c].val.str), "%s,%s", prev, str);
+            free(prev);
+        }
+        return;
+    }
+
+    /* When we arrive here, the stack is full. This should not happen and
+     * means there’s either a bug in this parser or the specification
+     * contains a command with more than 10 identified tokens. */
+    fprintf(stderr, "BUG: commands_parser stack full. This means either a bug "
+                    "in the code, or a new command which contains more than "
+                    "10 identified tokens.\n");
+    exit(1);
+}
+
+static void push_long(const char *identifier, long num) {
+    for (int c = 0; c < 10; c++) {
+        if (stack[c].identifier != NULL)
+            continue;
+        /* Found a free slot, let’s store it here. */
+        stack[c].identifier = identifier;
+        stack[c].val.num = num;
+        stack[c].type = STACK_LONG;
+        return;
+    }
+
+    /* When we arrive here, the stack is full. This should not happen and
+     * means there’s either a bug in this parser or the specification
+     * contains a command with more than 10 identified tokens. */
+    fprintf(stderr, "BUG: commands_parser stack full. This means either a bug "
+                    "in the code, or a new command which contains more than "
+                    "10 identified tokens.\n");
+    exit(1);
+
+}
+
+static const char *get_string(const char *identifier) {
+    for (int c = 0; c < 10; c++) {
+        if (stack[c].identifier == NULL)
+            break;
+        if (strcmp(identifier, stack[c].identifier) == 0)
+            return stack[c].val.str;
+    }
+    return NULL;
+}
+
+
+static void clear_stack(void) {
+    for (int c = 0; c < 10; c++) {
+        if (stack[c].type == STACK_STR && stack[c].val.str != NULL)
+            free(stack[c].val.str);
+        stack[c].identifier = NULL;
+        stack[c].val.str = NULL;
+        stack[c].val.num = 0;
+    }
+}
+
+/*
+ * Returns true if sym is bound to any key except for 'except_keycode' on the
+ * first four layers (normal, shift, mode_switch, mode_switch + shift).
+ *
+ */
+static bool keysym_used_on_other_key(KeySym sym, xcb_keycode_t except_keycode) {
+    xcb_keycode_t i,
+                  min_keycode = xcb_get_setup(conn)->min_keycode,
+                  max_keycode = xcb_get_setup(conn)->max_keycode;
+
+    for (i = min_keycode; i && i <= max_keycode; i++) {
+        if (i == except_keycode)
+            continue;
+        for (int level = 0; level < 4; level++) {
+            if (xcb_key_symbols_get_keysym(keysyms, i, level) != sym)
+                continue;
+            return true;
+        }
+    }
+    return false;
+}
+
+
+static char *next_state(const cmdp_token *token) {
+    cmdp_state _next_state = token->next_state;
+
+    if (token->next_state == __CALL) {
+        const char *modifiers = get_string("modifiers");
+        int keycode = atoi(get_string("key"));
+        int level = 0;
+        if (modifiers != NULL &&
+            strstr(modifiers, "Shift") != NULL) {
+            /* When shift is included, we really need to use the second-level
+             * symbol (upper-case). The lower-case symbol could be on a
+             * different key than the upper-case one (unlikely for letters, but
+             * more likely for special characters). */
+            level = 1;
+
+            /* Try to use the keysym on the first level (lower-case). In case
+             * this doesn’t make it ambiguous (think of a keyboard layout
+             * having '1' on two different keys, but '!' only on keycode 10),
+             * we’ll stick with the keysym of the first level.
+             *
+             * This reduces a lot of confusion for users who switch keyboard
+             * layouts from qwerty to qwertz or other slight variations of
+             * qwerty (yes, that happens quite often). */
+            KeySym sym = XkbKeycodeToKeysym(dpy, keycode, 0, 0);
+            if (!keysym_used_on_other_key(sym, keycode))
+                level = 0;
+        }
+        KeySym sym = XkbKeycodeToKeysym(dpy, keycode, 0, level);
+        char *str = XKeysymToString(sym);
+        const char *release = get_string("release");
+        char *res;
+        char *modrep = (modifiers == NULL ? sstrdup("") : sstrdup(modifiers));
+        char *comma;
+        while ((comma = strchr(modrep, ',')) != NULL) {
+            *comma = '+';
+        }
+        sasprintf(&res, "bindsym %s%s%s %s%s\n", (modifiers == NULL ? "" : modrep), (modifiers == NULL ? "" : "+"), str, (release == NULL ? "" : release), get_string("command"));
+        clear_stack();
+        return res;
+    }
+
+    state = _next_state;
+
+    /* See if we are jumping back to a state in which we were in previously
+     * (statelist contains INITIAL) and just move statelist_idx accordingly. */
+    for (int i = 0; i < statelist_idx; i++) {
+        if (statelist[i] != _next_state)
+            continue;
+        statelist_idx = i+1;
+        return NULL;
+    }
+
+    /* Otherwise, the state is new and we add it to the list */
+    statelist[statelist_idx++] = _next_state;
+    return NULL;
+}
+
+
+static char *rewrite_binding(const char *input) {
+    state = INITIAL;
+    statelist_idx = 1;
+
+    const char *walk = input;
+    const size_t len = strlen(input);
+    int c;
+    const cmdp_token *token;
+    char *result = NULL;
+
+    /* The "<=" operator is intentional: We also handle the terminating 0-byte
+     * explicitly by looking for an 'end' token. */
+    while ((walk - input) <= len) {
+        /* Skip whitespace before every token, newlines are relevant since they
+         * separate configuration directives. */
+        while ((*walk == ' ' || *walk == '\t') && *walk != '\0')
+            walk++;
+
+               //printf("remaining input: %s\n", walk);
+
+        cmdp_token_ptr *ptr = &(tokens[state]);
+        for (c = 0; c < ptr->n; c++) {
+            token = &(ptr->array[c]);
+
+            /* A literal. */
+            if (token->name[0] == '\'') {
+                if (strncasecmp(walk, token->name + 1, strlen(token->name) - 1) == 0) {
+                    if (token->identifier != NULL)
+                        push_string(token->identifier, token->name + 1);
+                    walk += strlen(token->name) - 1;
+                    if ((result = next_state(token)) != NULL)
+                        return result;
+                    break;
+                }
+                continue;
+            }
+
+            if (strcmp(token->name, "number") == 0) {
+                /* Handle numbers. We only accept decimal numbers for now. */
+                char *end = NULL;
+                errno = 0;
+                long int num = strtol(walk, &end, 10);
+                if ((errno == ERANGE && (num == LONG_MIN || num == LONG_MAX)) ||
+                    (errno != 0 && num == 0))
+                    continue;
+
+                /* No valid numbers found */
+                if (end == walk)
+                    continue;
+
+                if (token->identifier != NULL)
+                    push_long(token->identifier, num);
+
+                /* Set walk to the first non-number character */
+                walk = end;
+                if ((result = next_state(token)) != NULL)
+                    return result;
+                break;
+            }
+
+            if (strcmp(token->name, "string") == 0 ||
+                strcmp(token->name, "word") == 0) {
+                const char *beginning = walk;
+                /* Handle quoted strings (or words). */
+                if (*walk == '"') {
+                    beginning++;
+                    walk++;
+                    while (*walk != '\0' && (*walk != '"' || *(walk-1) == '\\'))
+                        walk++;
+                } else {
+                    if (token->name[0] == 's') {
+                        while (*walk != '\0' && *walk != '\r' && *walk != '\n')
+                            walk++;
+                    } else {
+                        /* For a word, the delimiters are white space (' ' or
+                         * '\t'), closing square bracket (]), comma (,) and
+                         * semicolon (;). */
+                        while (*walk != ' ' && *walk != '\t' &&
+                               *walk != ']' && *walk != ',' &&
+                               *walk !=  ';' && *walk != '\r' &&
+                               *walk != '\n' && *walk != '\0')
+                            walk++;
+                    }
+                }
+                if (walk != beginning) {
+                    char *str = scalloc(walk-beginning + 1);
+                    /* We copy manually to handle escaping of characters. */
+                    int inpos, outpos;
+                    for (inpos = 0, outpos = 0;
+                         inpos < (walk-beginning);
+                         inpos++, outpos++) {
+                        /* We only handle escaped double quotes to not break
+                         * backwards compatibility with people using \w in
+                         * regular expressions etc. */
+                        if (beginning[inpos] == '\\' && beginning[inpos+1] == '"')
+                            inpos++;
+                        str[outpos] = beginning[inpos];
+                    }
+                    if (token->identifier)
+                        push_string(token->identifier, str);
+                    free(str);
+                    /* If we are at the end of a quoted string, skip the ending
+                     * double quote. */
+                    if (*walk == '"')
+                        walk++;
+                    if ((result = next_state(token)) != NULL)
+                        return result;
+                    break;
+                }
+            }
+
+            if (strcmp(token->name, "end") == 0) {
+                //printf("checking for end: *%s*\n", walk);
+                if (*walk == '\0' || *walk == '\n' || *walk == '\r') {
+                    if ((result = next_state(token)) != NULL)
+                        return result;
+                    /* To make sure we start with an appropriate matching
+                     * datastructure for commands which do *not* specify any
+                     * criteria, we re-initialize the criteria system after
+                     * every command. */
+                    // TODO: make this testable
+                    walk++;
+                    break;
+               }
+           }
+        }
+    }
+
+    return NULL;
+}
+
+
 /*
  * Having verboselog() and errorlog() is necessary when using libi3.
  *
@@ -466,6 +802,7 @@ int main(int argc, char *argv[]) {
         xcb_connection_has_error(conn))
         errx(1, "Cannot open display\n");
 
+    keysyms = xcb_key_symbols_alloc(conn);
     xcb_get_modifier_mapping_cookie_t modmap_cookie;
     modmap_cookie = xcb_get_modifier_mapping(conn);
     symbols = xcb_key_symbols_alloc(conn);
index 20c7fbeaaec296aafe71becc8b60a40a506bf6d8..3a52faa57537b5c1005d2c8e30e3e59819ce9fed 100755 (executable)
@@ -6,7 +6,7 @@
 # No dependencies except for perl ≥ v5.10
 
 use strict;
-use warnings;
+use warnings qw(FATAL utf8);
 use Data::Dumper;
 use IPC::Open2;
 use POSIX qw(locale_h);
@@ -17,16 +17,26 @@ use Getopt::Long;
 use Pod::Usage;
 use v5.10;
 use utf8;
-use open ':encoding(utf8)';
+use open ':encoding(UTF-8)';
 
 binmode STDOUT, ':utf8';
 binmode STDERR, ':utf8';
 
 # reads in a whole file
 sub slurp {
-    open(my $fh, '<', shift) or die "$!";
+    my ($filename) = @_;
+    open(my $fh, '<', $filename) or die "$!";
     local $/;
-    <$fh>;
+    my $result;
+    eval {
+        $result = <$fh>;
+    };
+    if ($@) {
+        warn "Could not read $filename: $@";
+        return undef;
+    } else {
+        return $result;
+    }
 }
 
 my $entry_type = 'both';
@@ -35,7 +45,7 @@ my $result = GetOptions(
     'dmenu=s' => \$dmenu_cmd,
     'entry-type=s' => \$entry_type,
     'version' => sub {
-        say "dmenu-desktop 1.2 © 2012 Michael Stapelberg";
+        say "dmenu-desktop 1.3 © 2012 Michael Stapelberg";
         exit 0;
     },
     'help' => sub {
@@ -135,7 +145,9 @@ for my $file (values %desktops) {
     # Extract all “Name” and “Exec” keys from the [Desktop Entry] group
     # and store them in $apps{$base}.
     my %names;
-    my @lines = split("\n", slurp($file));
+    my $content = slurp($file);
+    next unless defined($content);
+    my @lines = split("\n", $content);
     for my $line (@lines) {
         my $first = substr($line, 0, 1);
         next if $line eq '' || $first eq '#';
@@ -209,6 +221,13 @@ for my $app (keys %apps) {
     next if (!exists($apps{$app}->{Type}) ||
              $apps{$app}->{Type} ne 'Application');
 
+    # Skip broken files (Type=application, but no Exec key).
+    if (!exists($apps{$app}->{Exec}) ||
+        $apps{$app}->{Exec} eq '') {
+        warn 'File ' . $apps{$app}->{_Location} . ' is broken: it contains Type=Application, but no Exec key/value pair.';
+        next;
+    }
+
     # Don’t offer apps which have NoDisplay == true or Hidden == true.
     # See http://wiki.xfce.org/howto/customize-menu#hide_menu_entries
     # for the difference between NoDisplay and Hidden.
@@ -250,6 +269,11 @@ for my $app (keys %apps) {
 
     if ($entry_type eq 'command' || $entry_type eq 'both') {
         my ($command) = split(' ', $apps{$app}->{Exec});
+
+        # Don’t add “geany” if “Geany” is already present.
+        my @keys = map { lc } keys %choices;
+        next if lc(basename($command)) ~~ @keys;
+
         $choices{basename($command)} = $app;
     }
 }
@@ -282,6 +306,8 @@ my $status = ($? >> 8);
 exit $status unless $status == 0;
 
 my $choice = <$dmenu_out>;
+# dmenu ≥ 4.4 adds a newline after the choice
+chomp($choice);
 my $app;
 # Exact match: the user chose “Avidemux (GTK+)”
 if (exists($choices{$choice})) {
@@ -451,7 +477,7 @@ command) and both (type = both).
 
 =head1 VERSION
 
-Version 1.2
+Version 1.3
 
 =head1 AUTHOR
 
index 48465c75718e696a44779638a5198f98c1e993dd..852a5cf7b2fc944e50272fcd2c1a9b676c2070f6 100644 (file)
@@ -42,14 +42,19 @@ static int check_for_wrap(void) {
     /* The log wrapped. Print the remaining content and reset walk to the top
      * of the log. */
     wrap_count = header->wrap_count;
-    write(STDOUT_FILENO, walk, ((logbuffer + header->offset_last_wrap) - walk));
+    const int len = (logbuffer + header->offset_last_wrap) - walk;
+    if (write(STDOUT_FILENO, walk, len) != len)
+        err(EXIT_FAILURE, "write()");
     walk = logbuffer + sizeof(i3_shmlog_header);
     return 1;
 }
 
 static void print_till_end(void) {
     check_for_wrap();
-    int n = write(STDOUT_FILENO, walk, ((logbuffer + header->offset_next_write) - walk));
+    const int len = (logbuffer + header->offset_next_write) - walk;
+    const int n = write(STDOUT_FILENO, walk, len);
+    if (len != n)
+        err(EXIT_FAILURE, "write()");
     if (n > 0) {
         walk += n;
     }
@@ -121,7 +126,7 @@ int main(int argc, char *argv[]) {
 
     struct stat statbuf;
 
-    /* NB: While we must never read, we need O_RDWR for the pthread condvar. */
+    /* NB: While we must never write, we need O_RDWR for the pthread condvar. */
     int logbuffer_shm = shm_open(shmname, O_RDWR, 0);
     if (logbuffer_shm == -1)
         err(EXIT_FAILURE, "Could not shm_open SHM segment for the i3 log (%s)", shmname);
@@ -129,7 +134,7 @@ int main(int argc, char *argv[]) {
     if (fstat(logbuffer_shm, &statbuf) != 0)
         err(EXIT_FAILURE, "stat(%s)", shmname);
 
-    /* NB: While we must never read, we need O_RDWR for the pthread condvar. */
+    /* NB: While we must never write, we need PROT_WRITE for the pthread condvar. */
     logbuffer = mmap(NULL, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, logbuffer_shm, 0);
     if (logbuffer == MAP_FAILED)
         err(EXIT_FAILURE, "Could not mmap SHM segment for the i3 log");
index f98afd3d195995c637eb1711e0d8dc5b36e732f7..49db4df231dd234260e30369d3f589353140b78f 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * i3-input/main.c: Utility which lets the user input commands and sends them
  *                  to i3.
@@ -76,6 +76,24 @@ void errorlog(char *fmt, ...) {
     va_end(args);
 }
 
+/*
+ * Restores the X11 input focus to whereever it was before.
+ * This is necessary because i3-input’s window has override_redirect=1
+ * (→ unmanaged by the window manager) and thus i3-input changes focus itself.
+ * This function is called on exit().
+ *
+ */
+static void restore_input_focus(void) {
+    xcb_generic_error_t *error;
+    xcb_get_input_focus_reply_t *reply = xcb_get_input_focus_reply(conn, focus_cookie, &error);
+    if (error != NULL) {
+        fprintf(stderr, "[i3-input] ERROR: Could not restore input focus (X error %d)\n", error->error_code);
+        return;
+    }
+    xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, reply->focus, XCB_CURRENT_TIME);
+    xcb_flush(conn);
+}
+
 /*
  * Concats the glyphs (either UCS-2 or UTF-8) to a single string, suitable for
  * rendering it (UCS-2) or sending it to i3 (UTF-8).
@@ -187,6 +205,10 @@ static void finish_input() {
     /* prefix the command if a prefix was specified on commandline */
     printf("command = %s\n", full);
 
+    restore_input_focus();
+
+    xcb_aux_sync(conn);
+
     ipc_send_message(sockfd, strlen(full), 0, (uint8_t*)full);
 
 #if 0
@@ -239,6 +261,7 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
         return 1;
     }
     if (sym == XK_Escape) {
+        restore_input_focus();
         exit(0);
     }
 
@@ -283,24 +306,6 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
     return 1;
 }
 
-/*
- * Restores the X11 input focus to whereever it was before.
- * This is necessary because i3-input’s window has override_redirect=1
- * (→ unmanaged by the window manager) and thus i3-input changes focus itself.
- * This function is called on exit().
- *
- */
-static void restore_input_focus(void) {
-    xcb_generic_error_t *error;
-    xcb_get_input_focus_reply_t *reply = xcb_get_input_focus_reply(conn, focus_cookie, &error);
-    if (error != NULL) {
-        fprintf(stderr, "[i3-input] ERROR: Could not restore input focus (X error %d)\n", error->error_code);
-        return;
-    }
-    xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, reply->focus, XCB_CURRENT_TIME);
-    xcb_flush(conn);
-}
-
 int main(int argc, char *argv[]) {
     format = strdup("%s");
     socket_path = getenv("I3SOCK");
@@ -420,7 +425,6 @@ int main(int argc, char *argv[]) {
     /* Set input focus (we have override_redirect=1, so the wm will not do
      * this for us) */
     xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
-    atexit(restore_input_focus);
 
     /* Grab the keyboard to get all input */
     xcb_flush(conn);
@@ -440,6 +444,7 @@ int main(int argc, char *argv[]) {
 
     if (reply->status != XCB_GRAB_STATUS_SUCCESS) {
         fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status);
+        restore_input_focus();
         exit(-1);
     }
 
index 607c5269b2f52a406132cedbcd5dbf1eefd1cb30..3259043c4393a8e428fe3141c7c515271ac0c593 100644 (file)
 
 static char *socket_path;
 
+/*
+ * Having verboselog() and errorlog() is necessary when using libi3.
+ *
+ */
+void verboselog(char *fmt, ...) {
+    va_list args;
+
+    va_start(args, fmt);
+    vfprintf(stdout, fmt, args);
+    va_end(args);
+}
+
+void errorlog(char *fmt, ...) {
+    va_list args;
+
+    va_start(args, fmt);
+    vfprintf(stderr, fmt, args);
+    va_end(args);
+}
+
 int main(int argc, char *argv[]) {
     socket_path = getenv("I3SOCK");
     int o, option_index = 0;
@@ -126,7 +146,7 @@ int main(int argc, char *argv[]) {
     addr.sun_family = AF_LOCAL;
     strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
     if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
-        err(EXIT_FAILURE, "Could not connect to i3");
+        err(EXIT_FAILURE, "Could not connect to i3 on socket \"%s\"", socket_path);
 
     if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t*)payload) == -1)
         err(EXIT_FAILURE, "IPC: write()");
@@ -135,13 +155,16 @@ int main(int argc, char *argv[]) {
         return 0;
 
     uint32_t reply_length;
+    uint32_t reply_type;
     uint8_t *reply;
     int ret;
-    if ((ret = ipc_recv_message(sockfd, message_type, &reply_length, &reply)) != 0) {
+    if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
         if (ret == -1)
             err(EXIT_FAILURE, "IPC: read()");
         exit(1);
     }
+    if (reply_type != message_type)
+        errx(EXIT_FAILURE, "IPC: Received reply of type %d but expected %d", reply_type, message_type);
     printf("%.*s\n", reply_length, reply);
     free(reply);
 
index a38d1839ed7b08cfd90ab3fb00c492aa4db805be..e700e2e9259a299564cd7208a6470807d613c4ef 100644 (file)
@@ -10,6 +10,7 @@
  */
 #include <stdio.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -20,6 +21,7 @@
 #include <stdint.h>
 #include <getopt.h>
 #include <limits.h>
+#include <fcntl.h>
 
 #include <xcb/xcb.h>
 #include <xcb/xcb_aux.h>
@@ -135,7 +137,38 @@ static void handle_button_release(xcb_connection_t *conn, xcb_button_release_eve
     button_t *button = get_button_at(event->event_x, event->event_y);
     if (!button)
         return;
-    start_application(button->action);
+
+    /* We need to create a custom script containing our actual command
+     * since not every terminal emulator which is contained in
+     * i3-sensible-terminal supports -e with multiple arguments (and not
+     * all of them support -e with one quoted argument either).
+     *
+     * NB: The paths need to be unique, that is, don’t assume users close
+     * their nagbars at any point in time (and they still need to work).
+     * */
+    char *script_path = get_process_filename("nagbar-cmd");
+
+    int fd = open(script_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IXUSR);
+    if (fd == -1) {
+        warn("Could not create temporary script to store the nagbar command");
+        return;
+    }
+    FILE *script = fdopen(fd, "w");
+    if (script == NULL) {
+        warn("Could not fdopen() temporary script to store the nagbar command");
+        return;
+    }
+    fprintf(script, "#!/bin/sh\nrm %s\n%s", script_path, button->action);
+    /* Also closes fd */
+    fclose(script);
+
+    char *terminal_cmd;
+    sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", script_path);
+
+    start_application(terminal_cmd);
+
+    free(terminal_cmd);
+    free(script_path);
 
     /* TODO: unset flag, re-render */
 }
index 75019c8d2a93ecc4b3893047eea0e6e8fed9442a..69440537448c99096306b04dbc95659c04b9aeb4 100644 (file)
@@ -88,6 +88,15 @@ void get_atoms(void);
  */
 void kick_tray_clients(i3_output *output);
 
+/*
+ * We need to set the _NET_SYSTEM_TRAY_COLORS atom on the tray selection window
+ * to make GTK+ 3 applets with Symbolic Icons visible. If the colors are unset,
+ * they assume a light background.
+ * See also https://bugzilla.gnome.org/show_bug.cgi?id=679591
+ *
+ */
+void init_tray_colors(void);
+
 /*
  * Destroy the bar of the specified output
  *
index b75ceabd538afa3a96aba1fb87fd1a23f06a6403..65a147c4718aeb44fcd57d5580cca4c55925dd1a 100644 (file)
@@ -6,6 +6,7 @@ ATOM_DO(MANAGER)
 ATOM_DO(_NET_SYSTEM_TRAY_ORIENTATION)
 ATOM_DO(_NET_SYSTEM_TRAY_VISUAL)
 ATOM_DO(_NET_SYSTEM_TRAY_OPCODE)
+ATOM_DO(_NET_SYSTEM_TRAY_COLORS)
 ATOM_DO(_XEMBED_INFO)
 ATOM_DO(_XEMBED)
 #undef ATOM_DO
index 2170e50965466f6082f055677a5ccdbe8e42ebbf..faab8e102890a84422b6fc8c5231d71c58c245b3 100644 (file)
@@ -84,6 +84,8 @@ void got_bar_config(char *reply) {
      * workspaces. Everything else (creating the bars, showing the right workspace-
      * buttons and more) is taken care of by the event-drivenness of the code */
     i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
+
+    free_colors(&(config.colors));
     parse_config_json(reply);
 
     /* Now we can actually use 'config', so let's subscribe to the appropriate
@@ -97,7 +99,6 @@ void got_bar_config(char *reply) {
 
     /* Resolve color strings to colorpixels and save them, then free the strings. */
     init_colors(&(config.colors));
-    free_colors(&(config.colors));
 
     /* The name of this function is actually misleading. Even if no command is
      * specified, this function initiates the watchers to listen on stdin and
index 3a8d8b9c3add9197b9088c640802bead9cc91ba8..e0abfadd746ca5fed1c5a6a94988f71c035e0cf9 100644 (file)
@@ -49,6 +49,10 @@ int              screen;
 xcb_screen_t     *root_screen;
 xcb_window_t     xcb_root;
 
+/* selection window for tray support */
+static xcb_window_t selwin = XCB_NONE;
+static xcb_intern_atom_reply_t *tray_reply = NULL;
+
 /* This is needed for integration with libi3 */
 xcb_connection_t *conn;
 
@@ -268,6 +272,9 @@ void init_colors(const struct xcb_color_strings_t *new_colors) {
     PARSE_COLOR(focus_ws_bg, "#285577");
     PARSE_COLOR(focus_ws_border, "#4c7899");
 #undef PARSE_COLOR
+
+    init_tray_colors();
+    xcb_flush(xcb_connection);
 }
 
 /*
@@ -991,6 +998,31 @@ void init_xcb_late(char *fontname) {
     }
 }
 
+/*
+ * Inform clients waiting for a new _NET_SYSTEM_TRAY that we took the
+ * selection.
+ *
+ */
+static void send_tray_clientmessage(void) {
+    uint8_t buffer[32] = { 0 };
+    xcb_client_message_event_t *ev = (xcb_client_message_event_t*)buffer;
+
+    ev->response_type = XCB_CLIENT_MESSAGE;
+    ev->window = xcb_root;
+    ev->type = atoms[MANAGER];
+    ev->format = 32;
+    ev->data.data32[0] = XCB_CURRENT_TIME;
+    ev->data.data32[1] = tray_reply->atom;
+    ev->data.data32[2] = selwin;
+
+    xcb_send_event(xcb_connection,
+                   0,
+                   xcb_root,
+                   0xFFFFFF,
+                   (char*)buffer);
+}
+
+
 /*
  * Initializes tray support by requesting the appropriate _NET_SYSTEM_TRAY atom
  * for the X11 display we are running on, then acquiring the selection for this
@@ -1003,11 +1035,11 @@ void init_tray(void) {
     char atomname[strlen("_NET_SYSTEM_TRAY_S") + 11];
     snprintf(atomname, strlen("_NET_SYSTEM_TRAY_S") + 11, "_NET_SYSTEM_TRAY_S%d", screen);
     xcb_intern_atom_cookie_t tray_cookie;
-    xcb_intern_atom_reply_t *tray_reply;
-    tray_cookie = xcb_intern_atom(xcb_connection, 0, strlen(atomname), atomname);
+    if (tray_reply == NULL)
+        tray_cookie = xcb_intern_atom(xcb_connection, 0, strlen(atomname), atomname);
 
     /* tray support: we need a window to own the selection */
-    xcb_window_t selwin = xcb_generate_id(xcb_connection);
+    selwin = xcb_generate_id(xcb_connection);
     uint32_t selmask = XCB_CW_OVERRIDE_REDIRECT;
     uint32_t selval[] = { 1 };
     xcb_create_window(xcb_connection,
@@ -1033,9 +1065,13 @@ void init_tray(void) {
                         1,
                         &orientation);
 
-    if (!(tray_reply = xcb_intern_atom_reply(xcb_connection, tray_cookie, NULL))) {
-        ELOG("Could not get atom %s\n", atomname);
-        exit(EXIT_FAILURE);
+    init_tray_colors();
+
+    if (tray_reply == NULL) {
+        if (!(tray_reply = xcb_intern_atom_reply(xcb_connection, tray_cookie, NULL))) {
+            ELOG("Could not get atom %s\n", atomname);
+            exit(EXIT_FAILURE);
+        }
     }
 
     xcb_set_selection_owner(xcb_connection,
@@ -1062,23 +1098,48 @@ void init_tray(void) {
         return;
     }
 
-    /* Inform clients waiting for a new _NET_SYSTEM_TRAY that we are here */
-    void *event = scalloc(32);
-    xcb_client_message_event_t *ev = event;
-    ev->response_type = XCB_CLIENT_MESSAGE;
-    ev->window = xcb_root;
-    ev->type = atoms[MANAGER];
-    ev->format = 32;
-    ev->data.data32[0] = XCB_CURRENT_TIME;
-    ev->data.data32[1] = tray_reply->atom;
-    ev->data.data32[2] = selwin;
-    xcb_send_event(xcb_connection,
-                   0,
-                   xcb_root,
-                   0xFFFFFF,
-                   (char*)ev);
-    free(event);
-    free(tray_reply);
+    send_tray_clientmessage();
+}
+
+/*
+ * We need to set the _NET_SYSTEM_TRAY_COLORS atom on the tray selection window
+ * to make GTK+ 3 applets with Symbolic Icons visible. If the colors are unset,
+ * they assume a light background.
+ * See also https://bugzilla.gnome.org/show_bug.cgi?id=679591
+ *
+ */
+void init_tray_colors(void) {
+    /* Convert colors.bar_fg (#rrggbb) to 16-bit RGB */
+    const char *bar_fg = (config.colors.bar_fg ? config.colors.bar_fg : "#FFFFFF");
+
+    DLOG("Setting bar_fg = %s as _NET_SYSTEM_TRAY_COLORS\n", bar_fg);
+
+    char strgroups[3][3] = {{bar_fg[1], bar_fg[2], '\0'},
+                            {bar_fg[3], bar_fg[4], '\0'},
+                            {bar_fg[5], bar_fg[6], '\0'}};
+    const uint8_t r = strtol(strgroups[0], NULL, 16);
+    const uint8_t g = strtol(strgroups[1], NULL, 16);
+    const uint8_t b = strtol(strgroups[2], NULL, 16);
+
+    const uint16_t r16 = ((uint16_t)r << 8) | r;
+    const uint16_t g16 = ((uint16_t)g << 8) | g;
+    const uint16_t b16 = ((uint16_t)b << 8) | b;
+
+    const uint32_t tray_colors[12] = {
+        r16, g16, b16, /* foreground color */
+        r16, g16, b16, /* error color */
+        r16, g16, b16, /* warning color */
+        r16, g16, b16, /* success color */
+    };
+
+    xcb_change_property(xcb_connection,
+                        XCB_PROP_MODE_REPLACE,
+                        selwin,
+                        atoms[_NET_SYSTEM_TRAY_COLORS],
+                        XCB_ATOM_CARDINAL,
+                        32,
+                        12,
+                        tray_colors);
 }
 
 /*
@@ -1138,6 +1199,9 @@ void get_atoms(void) {
  *
  */
 void kick_tray_clients(i3_output *output) {
+    if (TAILQ_EMPTY(output->trayclients))
+        return;
+
     trayclient *trayclient;
     while (!TAILQ_EMPTY(output->trayclients)) {
         trayclient = TAILQ_FIRST(output->trayclients);
@@ -1153,6 +1217,20 @@ void kick_tray_clients(i3_output *output) {
          * event afterwards, but better safe than sorry. */
         TAILQ_REMOVE(output->trayclients, trayclient, tailq);
     }
+
+    /* Fake a DestroyNotify so that Qt re-adds tray icons.
+     * We cannot actually destroy the window because then Qt will not restore
+     * its event mask on the new window. */
+    uint8_t buffer[32] = { 0 };
+    xcb_destroy_notify_event_t *event = (xcb_destroy_notify_event_t*)buffer;
+
+    event->response_type = XCB_DESTROY_NOTIFY;
+    event->event = selwin;
+    event->window = selwin;
+
+    xcb_send_event(conn, false, selwin, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)event);
+
+    send_tray_clientmessage();
 }
 
 /*
@@ -1398,7 +1476,7 @@ void reconfig_windows(void) {
             values[3] = font.height + 6;
             values[4] = XCB_STACK_MODE_ABOVE;
 
-            DLOG("Destroying buffer for output %s", walk->name);
+            DLOG("Destroying buffer for output %s\n", walk->name);
             xcb_free_pixmap(xcb_connection, walk->buffer);
 
             DLOG("Reconfiguring Window for output %s to %d,%d\n", walk->name, values[0], values[1]);
@@ -1407,7 +1485,7 @@ void reconfig_windows(void) {
                                                                         mask,
                                                                         values);
 
-            DLOG("Recreating buffer for output %s", walk->name);
+            DLOG("Recreating buffer for output %s\n", walk->name);
             xcb_void_cookie_t pm_cookie = xcb_create_pixmap_checked(xcb_connection,
                                                                     root_screen->root_depth,
                                                                     walk->buffer,
index 04f1c85f65ded1e8b1e088afe6a9aa2c6e300489..4a95d43fee8e7f25df2ce4979dc0c97595715f1e 100644 (file)
@@ -6,8 +6,8 @@
  *
  * include/config.h: Contains all structs/variables for the configurable
  * part of i3 as well as functions handling the configuration file (calling
- * the parser (src/cfgparse.y) with the correct path, switching key bindings
- * mode).
+ * the parser (src/config_parse.c) with the correct path, switching key
+ * bindings mode).
  *
  */
 #ifndef I3_CONFIG_H
@@ -24,8 +24,6 @@ extern char *current_configpath;
 extern Config config;
 extern SLIST_HEAD(modes_head, Mode) modes;
 extern TAILQ_HEAD(barconfig_head, Barconfig) barconfigs;
-/* defined in src/cfgparse.y */
-extern bool force_old_config_parser;
 
 /**
  * Used during the config file lexing/parsing to keep the state of the lexer
@@ -342,7 +340,4 @@ Binding *get_binding(uint16_t modifiers, bool key_release, xcb_keycode_t keycode
  */
 void kill_configerror_nagbar(bool wait_for_it);
 
-/* prototype for src/cfgparse.y */
-void parse_file(const char *f);
-
 #endif
index 0daf8118ec75ebbd85ce92245180d86ff6d0d102..fb863f3bf7b8e366af6fb262c133503f116efa0c 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <yajl/yajl_gen.h>
 
+extern pid_t config_error_nagbar_pid;
+
 /*
  * The result of a parse_config call. Currently unused, but the JSON output
  * will be useful in the future when we implement a config parsing IPC command.
@@ -29,4 +31,11 @@ struct ConfigResult {
 
 struct ConfigResult *parse_config(const char *input, struct context *context);
 
+/**
+ * Parses the given file by first replacing the variables, then calling
+ * parse_config and possibly launching i3-nagbar.
+ *
+ */
+void parse_file(const char *f);
+
 #endif
index 70b650115ea7586022069199f3aa529b3eb1776a..9a814f4517edb63d5ccc10694773070ddad69c35 100644 (file)
@@ -196,7 +196,8 @@ struct regex {
 
 /**
  * Holds a keybinding, consisting of a keycode combined with modifiers and the
- * command which is executed as soon as the key is pressed (see src/cfgparse.y)
+ * command which is executed as soon as the key is pressed (see
+ * src/config_parser.c)
  *
  */
 struct Binding {
index 93b2ae87392e43a43b000ae5cd9d0beeed83c6c6..2380edab30c79437cd9aca1de1fbb784f11b810b 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * This public header defines the different constants and message types to use
  * for the IPC interface to i3 (see docs/ipc for more information).
 #ifndef I3_I3_IPC_H
 #define I3_I3_IPC_H
 
+#include <stdint.h>
+
+typedef struct i3_ipc_header {
+    /* 6 = strlen(I3_IPC_MAGIC) */
+    char magic[6];
+    uint32_t size;
+    uint32_t type;
+} __attribute__ ((packed)) i3_ipc_header_t;
+
 /*
  * Messages from clients to i3
  *
index 417843a10fbea0c1a5e7c202539d7811e53f36e3..b231b8f5b4d34ba027ff1dc80c0a922c28720fe8 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef I3_KEY_PRESS_H
 #define I3_KEY_PRESS_H
 
+extern pid_t command_error_nagbar_pid;
+
 /**
  * There was a key press. We compare this key code with our bindings table and pass
  * the bound action to parse_command().
index 7547845b9bf2245a97242badd9bcd6d7c9ff8e7f..6714cc5b921d6f61a201abaee51dd9f6337ba51e 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * libi3: contains functions which are used by i3 *and* accompanying tools such
  * as i3-msg, i3-config-wizard, …
@@ -202,8 +202,8 @@ int ipc_connect(const char *socket_path);
  * Returns 0 on success.
  *
  */
-int ipc_send_message(int sockfd, uint32_t message_size,
-                     uint32_t message_type, const uint8_t *payload);
+int ipc_send_message(int sockfd, const uint32_t message_size,
+                     const uint32_t message_type, const uint8_t *payload);
 
 /**
  * Reads a message from the given socket file descriptor and stores its length
@@ -216,7 +216,7 @@ int ipc_send_message(int sockfd, uint32_t message_size,
  * Returns 0 on success.
  *
  */
-int ipc_recv_message(int sockfd, uint32_t message_type,
+int ipc_recv_message(int sockfd, uint32_t *message_type,
                      uint32_t *reply_length, uint8_t **reply);
 
 /**
@@ -355,4 +355,10 @@ xcb_visualtype_t *get_visualtype(xcb_screen_t *screen);
  */
 bool is_debug_build() __attribute__((const));
 
+/**
+ * Returns the name of a temporary file with the specified prefix.
+ *
+ */
+char *get_process_filename(const char *prefix);
+
 #endif
index e397a4e80ac37bbc77e230c6b497f12b3f33b638..61a38f3ec030537f184cf9a84c1f23b96373efa2 100644 (file)
@@ -105,13 +105,6 @@ char *resolve_tilde(const char *path);
  */
 bool path_exists(const char *path);
 
-
-/**
- * Returns the name of a temporary file with the specified prefix.
- *
- */
-char *get_process_filename(const char *prefix);
-
 /**
  * Restart i3 in-place
  * appends -a to argument list to disable autostart
@@ -130,4 +123,23 @@ void *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
 
 #endif
 
+/**
+ * Starts an i3-nagbar instance with the given parameters. Takes care of
+ * handling SIGCHLD and killing i3-nagbar when i3 exits.
+ *
+ * The resulting PID will be stored in *nagbar_pid and can be used with
+ * kill_nagbar() to kill the bar later on.
+ *
+ */
+void start_nagbar(pid_t *nagbar_pid, char *argv[]);
+
+/**
+ * Kills the i3-nagbar process, if *nagbar_pid != -1.
+ *
+ * If wait_for_it is set (restarting i3), this function will waitpid(),
+ * otherwise, ev is assumed to handle it (reloading).
+ *
+ */
+void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it);
+
 #endif
index 15d3e28fc4e1e81dbd8020fcd960ce6ba9b3f739..540135694187e9a6d2e4f896ca60844b0d61cdd8 100644 (file)
                           XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |   /* …subwindows get notifies */ \
                           XCB_EVENT_MASK_ENTER_WINDOW)           /* …user moves cursor inside our window */
 
+#define ROOT_EVENT_MASK   (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | \
+                           XCB_EVENT_MASK_BUTTON_PRESS | \
+                           XCB_EVENT_MASK_STRUCTURE_NOTIFY |         /* when the user adds a screen (e.g. video \
+                                                                            projector), the root window gets a \
+                                                                            ConfigureNotify */ \
+                           XCB_EVENT_MASK_POINTER_MOTION | \
+                           XCB_EVENT_MASK_PROPERTY_CHANGE | \
+                           XCB_EVENT_MASK_ENTER_WINDOW)
+
 #define xmacro(atom) xcb_atom_t A_ ## atom;
 #include "atoms.xmacro"
 #undef xmacro
diff --git a/libi3/get_process_filename.c b/libi3/get_process_filename.c
new file mode 100644 (file)
index 0000000..630e3d1
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ * i3 - an improved dynamic tiling window manager
+ * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
+ *
+ */
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <err.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <unistd.h>
+
+#include "libi3.h"
+
+/*
+ * Returns the name of a temporary file with the specified prefix.
+ *
+ */
+char *get_process_filename(const char *prefix) {
+    /* dir stores the directory path for this and all subsequent calls so that
+     * we only create a temporary directory once per i3 instance. */
+    static char *dir = NULL;
+    if (dir == NULL) {
+        /* Check if XDG_RUNTIME_DIR is set. If so, we use XDG_RUNTIME_DIR/i3 */
+        if ((dir = getenv("XDG_RUNTIME_DIR"))) {
+            char *tmp;
+            sasprintf(&tmp, "%s/i3", dir);
+            dir = tmp;
+            struct stat buf;
+            if (stat(dir, &buf) != 0) {
+                if (mkdir(dir, 0700) == -1) {
+                    perror("mkdir()");
+                    return NULL;
+                }
+            }
+        } else {
+            /* If not, we create a (secure) temp directory using the template
+             * /tmp/i3-<user>.XXXXXX */
+            struct passwd *pw = getpwuid(getuid());
+            const char *username = pw ? pw->pw_name : "unknown";
+            sasprintf(&dir, "/tmp/i3-%s.XXXXXX", username);
+            /* mkdtemp modifies dir */
+            if (mkdtemp(dir) == NULL) {
+                perror("mkdtemp()");
+                return NULL;
+            }
+        }
+    }
+    char *filename;
+    sasprintf(&filename, "%s/%s.%d", dir, prefix, getpid());
+    return filename;
+}
index f5c4a62b69dc7ba8742ce1832b4e22422fcc05a3..8fd438e3455f2bf1456e1f52fdd18d442bd0aefb 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  */
 #include <string.h>
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <i3/ipc.h>
 
  * (reply_length) as well as a pointer to its contents (reply).
  *
  * Returns -1 when read() fails, errno will remain.
- * Returns -2 when the IPC protocol is violated (invalid magic, unexpected
+ * Returns -2 on EOF.
+ * Returns -3 when the IPC protocol is violated (invalid magic, unexpected
  * message type, EOF instead of a message). Additionally, the error will be
  * printed to stderr.
  * Returns 0 on success.
  *
  */
-int ipc_recv_message(int sockfd, uint32_t message_type,
+int ipc_recv_message(int sockfd, uint32_t *message_type,
                      uint32_t *reply_length, uint8_t **reply) {
     /* Read the message header first */
-    uint32_t to_read = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t);
+    const uint32_t to_read = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t);
     char msg[to_read];
     char *walk = msg;
 
     uint32_t read_bytes = 0;
     while (read_bytes < to_read) {
-        int n = read(sockfd, msg + read_bytes, to_read);
+        int n = read(sockfd, msg + read_bytes, to_read - read_bytes);
         if (n == -1)
             return -1;
         if (n == 0) {
-            fprintf(stderr, "IPC: received EOF instead of reply\n");
+            ELOG("IPC: received EOF instead of reply\n");
             return -2;
         }
 
         read_bytes += n;
-        to_read -= n;
     }
 
     if (memcmp(walk, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)) != 0) {
-        fprintf(stderr, "IPC: invalid magic in reply\n");
-        return -2;
+        ELOG("IPC: invalid magic in reply\n");
+        return -3;
     }
 
     walk += strlen(I3_IPC_MAGIC);
     *reply_length = *((uint32_t*)walk);
     walk += sizeof(uint32_t);
-    if (*((uint32_t*)walk) != message_type) {
-        fprintf(stderr, "IPC: unexpected reply type (got %d, expected %d)\n", *((uint32_t*)walk), message_type);
-        return -2;
-    }
+    if (message_type != NULL)
+        *message_type = *((uint32_t*)walk);
 
     *reply = smalloc(*reply_length);
 
-    to_read = *reply_length;
     read_bytes = 0;
-    while (read_bytes < to_read) {
-        int n = read(sockfd, *reply + read_bytes, to_read);
-        if (n == -1)
+    int n;
+    while (read_bytes < *reply_length) {
+        if ((n = read(sockfd, *reply + read_bytes, *reply_length - read_bytes)) == -1) {
+            if (errno == EINTR || errno == EAGAIN)
+                continue;
             return -1;
+        }
 
         read_bytes += n;
-        to_read -= n;
     }
 
     return 0;
index 88d87a6a892ec1149096021042c99444704db88c..c5560c0de9789aef20e27ec667cfd36c7ce0464a 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  */
 #include <string.h>
  * Returns 0 on success.
  *
  */
-int ipc_send_message(int sockfd, uint32_t message_size,
-                     uint32_t message_type, const uint8_t *payload) {
-    int buffer_size = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t) + message_size;
-    char msg[buffer_size];
-    char *walk = msg;
-
-    strncpy(walk, I3_IPC_MAGIC, buffer_size - 1);
-    walk += strlen(I3_IPC_MAGIC);
-    memcpy(walk, &message_size, sizeof(uint32_t));
-    walk += sizeof(uint32_t);
-    memcpy(walk, &message_type, sizeof(uint32_t));
-    walk += sizeof(uint32_t);
-    memcpy(walk, payload, message_size);
+int ipc_send_message(int sockfd, const uint32_t message_size,
+                     const uint32_t message_type, const uint8_t *payload) {
+    const i3_ipc_header_t header = {
+        /* We don’t use I3_IPC_MAGIC because it’s a 0-terminated C string. */
+        .magic = { 'i', '3', '-', 'i', 'p', 'c' },
+        .size = message_size,
+        .type = message_type
+    };
 
     int sent_bytes = 0;
-    while (sent_bytes < buffer_size) {
-        int n = write(sockfd, msg + sent_bytes, buffer_size - sent_bytes);
-        if (n == -1) {
+    int n = 0;
+
+    /* This first loop is basically unnecessary. No operating system has
+     * buffers which cannot fit 14 bytes into them, so the write() will only be
+     * called once. */
+    while (sent_bytes < sizeof(i3_ipc_header_t)) {
+        if ((n = write(sockfd, ((void*)&header) + sent_bytes, sizeof(i3_ipc_header_t) - sent_bytes)) == -1) {
+            if (errno == EAGAIN)
+                continue;
+            return -1;
+        }
+
+        sent_bytes += n;
+    }
+
+    sent_bytes = 0;
+
+    while (sent_bytes < message_size) {
+        if ((n = write(sockfd, payload + sent_bytes, message_size - sent_bytes)) == -1) {
             if (errno == EAGAIN)
                 continue;
             return -1;
index 7a31a5d820ef4c6121beab711d4b1ba05a3b0a99..427d9fc4305cba85be3feef69c024faf1e9d6eb1 100644 (file)
@@ -272,7 +272,7 @@ state FONT:
 state BINDING:
   release = '--release'
       ->
-  modifiers = 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5', 'Shift', 'Control', 'Ctrl', 'Mode_switch'
+  modifiers = 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5', 'Shift', 'Control', 'Ctrl', 'Mode_switch', '$mod'
       ->
   '+'
       ->
@@ -317,7 +317,7 @@ state MODE_IGNORE_LINE:
 state MODE_BINDING:
   release = '--release'
       ->
-  modifiers = 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5', 'Shift', 'Control', 'Ctrl', 'Mode_switch'
+  modifiers = 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5', 'Shift', 'Control', 'Ctrl', 'Mode_switch', '$mod'
       ->
   '+'
       ->
diff --git a/src/cfgparse.l b/src/cfgparse.l
deleted file mode 100644 (file)
index 6eef8a5..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * vim:ts=4:sw=4:expandtab
- *
- */
-%option nounput
-%option noinput
-%option noyy_top_state
-%option stack
-
-%{
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <xcb/xcb.h>
-
-#include "log.h"
-#include "data.h"
-#include "config.h"
-#include "util.h"
-#include "libi3.h"
-
-#include "cfgparse.tab.h"
-
-int yycolumn = 1;
-
-#define YY_DECL int yylex (struct context *context)
-
-#define YY_USER_ACTION { \
-    context->first_column = yycolumn; \
-    context->last_column = yycolumn+yyleng-1; \
-    yycolumn += yyleng; \
-}
-
-/* macro to first eat whitespace, then expect a string */
-#define WS_STRING do { \
-    yy_push_state(WANT_STRING); \
-    yy_push_state(EAT_WHITESPACE); \
-} while (0)
-
-#define BAR_TRIPLE_COLOR do { \
-    yy_push_state(BAR_COLOR); \
-    yy_push_state(BAR_COLOR); \
-    yy_push_state(BAR_COLOR); \
-} while (0)
-
-%}
-
-EOL     (\r?\n)
-
-%s WANT_STRING
-%s WANT_QSTRING
-%s BINDSYM_COND
-%s ASSIGN_COND
-%s ASSIGN_TARGET_COND
-%s COLOR_COND
-%s OUTPUT_COND
-%s FOR_WINDOW_COND
-%s EAT_WHITESPACE
-%s BORDER_WIDTH
-
-%x BUFFER_LINE
-%x BAR
-%x BAR_MODE
-%x BAR_MODIFIER
-%x BAR_POSITION
-%x BAR_COLORS
-%x BAR_COLOR
-
-%x EXEC
-%x OPTRELEASE
-
-%%
-
-    {
-        /* This is called when a new line is lexed. We only want the
-         * first line to match to go into state BUFFER_LINE */
-        if (context->line_number == 0) {
-            context->line_number = 1;
-            BEGIN(INITIAL);
-            yy_push_state(BUFFER_LINE);
-        }
-    }
-
-<BUFFER_LINE>^[^\r\n]*/{EOL}? {
-    /* save whole line */
-    context->line_copy = sstrdup(yytext);
-
-    yyless(0);
-    yy_pop_state();
-    yy_set_bol(true);
-    yycolumn = 1;
-}
-
- /* This part of the lexer handles the bar {} blocks */
-<BAR,BAR_MODE,BAR_MODIFIER,BAR_POSITION,BAR_COLORS,BAR_COLOR>[ \t]+ { /* ignore whitespace */ ; }
-<BAR>"{"                        { return '{'; }
-<BAR>"}"                        { yy_pop_state(); return '}'; }
-<BAR>^[ \t]*#[^\n]*             { return TOKCOMMENT; }
-<BAR>output                     { WS_STRING; return TOK_BAR_OUTPUT; }
-<BAR>tray_output                { WS_STRING; return TOK_BAR_TRAY_OUTPUT; }
-<BAR>socket_path                { WS_STRING; return TOK_BAR_SOCKET_PATH; }
-<BAR>mode                       { yy_push_state(BAR_MODE); return TOK_BAR_MODE; }
-<BAR_MODE>hide                  { yy_pop_state(); return TOK_BAR_HIDE; }
-<BAR_MODE>dock                  { yy_pop_state(); return TOK_BAR_DOCK; }
-<BAR>modifier                   { yy_push_state(BAR_MODIFIER); return TOK_BAR_MODIFIER; }
-<BAR_MODIFIER>control           { yy_pop_state(); return TOK_BAR_CONTROL; }
-<BAR_MODIFIER>ctrl              { yy_pop_state(); return TOK_BAR_CONTROL; }
-<BAR_MODIFIER>shift             { yy_pop_state(); return TOK_BAR_SHIFT; }
-<BAR_MODIFIER>Mod1              { yy_pop_state(); return TOK_BAR_MOD1; }
-<BAR_MODIFIER>Mod2              { yy_pop_state(); return TOK_BAR_MOD2; }
-<BAR_MODIFIER>Mod3              { yy_pop_state(); return TOK_BAR_MOD3; }
-<BAR_MODIFIER>Mod4              { yy_pop_state(); return TOK_BAR_MOD4; }
-<BAR_MODIFIER>Mod5              { yy_pop_state(); return TOK_BAR_MOD5; }
-<BAR>position                   { yy_push_state(BAR_POSITION); return TOK_BAR_POSITION; }
-<BAR_POSITION>bottom            { yy_pop_state(); return TOK_BAR_BOTTOM; }
-<BAR_POSITION>top               { yy_pop_state(); return TOK_BAR_TOP; }
-<BAR>status_command             { WS_STRING; return TOK_BAR_STATUS_COMMAND; }
-<BAR>i3bar_command              { WS_STRING; return TOK_BAR_I3BAR_COMMAND; }
-<BAR>font                       { WS_STRING; return TOK_BAR_FONT; }
-<BAR>workspace_buttons          { return TOK_BAR_WORKSPACE_BUTTONS; }
-<BAR>verbose                    { return TOK_BAR_VERBOSE; }
-<BAR>colors                     { yy_push_state(BAR_COLORS); return TOK_BAR_COLORS; }
-<BAR_COLORS>"{"                 { return '{'; }
-<BAR_COLORS>"}"                 { yy_pop_state(); return '}'; }
-<BAR_COLORS>^[ \t]*#[^\n]*      { return TOKCOMMENT; }
-<BAR_COLORS>background          { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_BACKGROUND; }
-<BAR_COLORS>statusline          { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_STATUSLINE; }
-<BAR_COLORS>focused_workspace   { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_FOCUSED_WORKSPACE; }
-<BAR_COLORS>active_workspace    { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_ACTIVE_WORKSPACE; }
-<BAR_COLORS>inactive_workspace  { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_INACTIVE_WORKSPACE; }
-<BAR_COLORS>urgent_workspace    { BAR_TRIPLE_COLOR; return TOK_BAR_COLOR_URGENT_WORKSPACE; }
-<BAR_COLOR>#[0-9a-fA-F]+        { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
-<BAR_COLOR>{EOL}                {
-                                  yy_pop_state();
-                                  FREE(context->line_copy);
-                                  context->line_number++;
-                                  yy_push_state(BUFFER_LINE);
-                                }
-<BAR,BAR_COLORS,BAR_MODE,BAR_MODIFIER,BAR_POSITION>[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
-
-
-
-<FOR_WINDOW_COND>"]"            { yy_pop_state(); return ']'; }
-<ASSIGN_COND>"["                {
-                                  /* this is the case for the new assign syntax
-                                   * that uses criteria */
-                                  yy_pop_state();
-                                  yy_push_state(FOR_WINDOW_COND);
-                                  /* afterwards we will be in ASSIGN_TARGET_COND */
-                                  return '[';
-                                }
-<EAT_WHITESPACE>[ \t]*          { yy_pop_state(); }
-<EAT_WHITESPACE>{EOL}           { yy_pop_state(); }
-<BINDSYM_COND>{EOL}             { yy_pop_state(); }
-<WANT_QSTRING>\"[^\"]+\"        {
-                                  yy_pop_state();
-                                  /* strip quotes */
-                                  char *copy = sstrdup(yytext+1);
-                                  copy[strlen(copy)-1] = '\0';
-                                  yylval.string = copy;
-                                  return STR;
-                                }
-<WANT_STRING>[^\n]+             { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
-<OUTPUT_COND>[a-zA-Z0-9\/_-]+   { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
-^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
-<COLOR_COND>#[0-9a-fA-F]+       { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
-<COLOR_COND>{EOL}               {
-                                  yy_pop_state();
-                                  FREE(context->line_copy);
-                                  context->line_number++;
-                                  yy_push_state(BUFFER_LINE);
-                                }
-<ASSIGN_TARGET_COND>[ \t]*→[ \t]*     { BEGIN(WANT_STRING); }
-<ASSIGN_TARGET_COND>[ \t]+      { BEGIN(WANT_STRING); }
-<BORDER_WIDTH>[^\n][0-9]+       { printf("Border width set to: %s\n", yytext); yylval.number = atoi(yytext); return NUMBER;}
-<EXEC>--no-startup-id           { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
-<EXEC>.                         { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
-<OPTRELEASE>--release           { printf("--release\n"); yy_pop_state(); return TOK_RELEASE; }
-<OPTRELEASE>.                   { printf("anything else (optrelease): *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
-[0-9-]+                         { yylval.number = atoi(yytext); return NUMBER; }
-bar                             { yy_push_state(BAR); return TOK_BAR; }
-mode                            { return TOKMODE; }
-bind                            { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
-bindcode                        { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); yy_push_state(OPTRELEASE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
-bindsym                         { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); yy_push_state(OPTRELEASE); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
-floating_maximum_size           { return TOKFLOATING_MAXIMUM_SIZE; }
-floating_minimum_size           { return TOKFLOATING_MINIMUM_SIZE; }
-floating_modifier               { return TOKFLOATING_MODIFIER; }
-workspace                       { return TOKWORKSPACE; }
-output                          { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
-terminal                        { WS_STRING; return TOKTERMINAL; }
-font                            { WS_STRING; return TOKFONT; }
-assign                          { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
-set[^\n]*                       { return TOKCOMMENT; }
-ipc-socket                      { WS_STRING; return TOKIPCSOCKET; }
-ipc_socket                      { WS_STRING; return TOKIPCSOCKET; }
-restart_state                   { WS_STRING; return TOKRESTARTSTATE; }
-default_orientation             { return TOK_ORIENTATION; }
-horizontal                      { return TOK_HORIZ; }
-vertical                        { return TOK_VERT; }
-auto                            { return TOK_AUTO; }
-workspace_layout                { return TOK_WORKSPACE_LAYOUT; }
-new_window                      { return TOKNEWWINDOW; }
-new_float                       { return TOKNEWFLOAT; }
-normal                          { yy_push_state(BORDER_WIDTH); return TOK_NORMAL; }
-none                            { return TOK_NONE; }
-1pixel                          { return TOK_1PIXEL; }
-pixel                           { yy_push_state(BORDER_WIDTH); return TOK_PIXEL; }
-hide_edge_borders               { return TOK_HIDE_EDGE_BORDERS; }
-both                            { return TOK_BOTH; }
-focus_follows_mouse             { return TOKFOCUSFOLLOWSMOUSE; }
-force_focus_wrapping            { return TOK_FORCE_FOCUS_WRAPPING; }
-force_xinerama                  { return TOK_FORCE_XINERAMA; }
-force-xinerama                  { return TOK_FORCE_XINERAMA; }
-fake_outputs                    { WS_STRING; return TOK_FAKE_OUTPUTS; }
-fake-outputs                    { WS_STRING; return TOK_FAKE_OUTPUTS; }
-workspace_auto_back_and_forth   { return TOK_WORKSPACE_AUTO_BAF; }
-force_display_urgency_hint      { return TOK_WORKSPACE_URGENCY_TIMER; }
-ms                              { return TOK_TIME_MS; }
-workspace_bar                   { return TOKWORKSPACEBAR; }
-popup_during_fullscreen         { return TOK_POPUP_DURING_FULLSCREEN; }
-ignore                          { return TOK_IGNORE; }
-leave_fullscreen                { return TOK_LEAVE_FULLSCREEN; }
-for_window                      {
-                                  /* Example: for_window [class="urxvt"] border none
-                                   *
-                                   * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
-                                   * Then, we require a whitespace (EAT_WHITESPACE)
-                                   * And the rest of the line is parsed as a string
-                                   */
-                                  yy_push_state(WANT_STRING);
-                                  yy_push_state(EAT_WHITESPACE);
-                                  yy_push_state(FOR_WINDOW_COND);
-                                  return TOK_FOR_WINDOW;
-                                }
-default                         { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
-stacking                        { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
-stacked                         { return TOK_STACKING; }
-tabbed                          { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
-stack-limit                     { return TOKSTACKLIMIT; }
-cols                            { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
-rows                            { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
-exec                            { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC; }
-exec_always                     { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC_ALWAYS; }
-client.background               { yy_push_state(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
-client.focused                  { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
-client.focused_inactive         { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
-client.unfocused                { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
-client.urgent                   { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
-bar.focused                     { yy_push_state(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
-bar.unfocused                   { yy_push_state(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
-bar.urgent                      { yy_push_state(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
-Mod1                            { yylval.number = BIND_MOD1; return MODIFIER; }
-Mod2                            { yylval.number = BIND_MOD2; return MODIFIER; }
-Mod3                            { yylval.number = BIND_MOD3; return MODIFIER; }
-Mod4                            { yylval.number = BIND_MOD4; return MODIFIER; }
-Mod5                            { yylval.number = BIND_MOD5; return MODIFIER; }
-Mode_switch                     { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
-control                         { return TOKCONTROL; }
-ctrl                            { return TOKCONTROL; }
-shift                           { return TOKSHIFT; }
-
-class                           { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
-instance                        { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
-window_role                     { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
-id                              { yy_push_state(WANT_QSTRING); return TOK_ID; }
-con_id                          { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
-con_mark                        { yy_push_state(WANT_QSTRING); return TOK_MARK; }
-title                           { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
-urgent                          { yy_push_state(WANT_QSTRING); return TOK_URGENT; }
-
-<*>{EOL}                        {
-                                  FREE(context->line_copy);
-                                  context->line_number++;
-                                  yy_push_state(BUFFER_LINE);
-                                }
-<BINDSYM_COND>[ \t]+            { yy_pop_state(); yy_push_state(WANT_STRING); }
-<OUTPUT_COND>[ \t]+             { yy_pop_state(); yy_push_state(WANT_STRING); }
-[ \t]+                          { /* ignore whitespace */ ; }
-\"[^\"]+\"                      {
-                                  /* if ASSIGN_COND then */
-                                  if (yy_start_stack_ptr > 0)
-                                      yy_pop_state();
-                                  /* yylval will be the string, but without quotes */
-                                  char *copy = sstrdup(yytext+1);
-                                  copy[strlen(copy)-1] = '\0';
-                                  yylval.string = copy;
-                                  return QUOTEDSTRING;
-                                }
-<ASSIGN_COND>[^ \t\"\[]+        { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
-<BINDSYM_COND>[a-zA-Z0-9_]+     { yylval.string = sstrdup(yytext); return WORD; }
-[a-zA-Z]+                       { yylval.string = sstrdup(yytext); return WORD; }
-.                               { return (int)yytext[0]; }
-
-<<EOF>> {
-    while (yy_start_stack_ptr > 0)
-        yy_pop_state();
-    yyterminate();
-}
-
-%%
diff --git a/src/cfgparse.y b/src/cfgparse.y
deleted file mode 100644 (file)
index 2a22aae..0000000
+++ /dev/null
@@ -1,1875 +0,0 @@
-%{
-/*
- * vim:ts=4:sw=4:expandtab
- *
- */
-#undef I3__FILE__
-#define I3__FILE__ "cfgparse.y"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "all.h"
-
-bool force_old_config_parser = false;
-
-static pid_t configerror_pid = -1;
-
-static Match current_match;
-static Barconfig current_bar;
-/* The pattern which was specified by the user, for example -misc-fixed-*. We
- * store this in a separate variable because in the i3 config struct we just
- * store the i3Font. */
-static char *font_pattern;
-/* The path to the temporary script files used by i3-nagbar. We need to keep
- * them around to delete the files in the i3-nagbar SIGCHLD handler. */
-static char *edit_script_path, *pager_script_path;
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-extern int yylex(struct context *context);
-extern int yyparse(void);
-extern int yylex_destroy(void);
-extern FILE *yyin;
-YY_BUFFER_STATE yy_scan_string(const char *);
-
-static struct bindings_head *current_bindings;
-static struct context *context;
-
-/* We don’t need yydebug for now, as we got decent error messages using
- * yyerror(). Should you ever want to extend the parser, it might be handy
- * to just comment it in again, so it stays here. */
-//int yydebug = 1;
-
-void yyerror(const char *error_message) {
-    context->has_errors = true;
-
-    ELOG("\n");
-    ELOG("CONFIG: %s\n", error_message);
-    ELOG("CONFIG: in file \"%s\", line %d:\n",
-        context->filename, context->line_number);
-    ELOG("CONFIG:   %s\n", context->line_copy);
-    char buffer[context->last_column+1];
-    buffer[context->last_column] = '\0';
-    for (int c = 1; c <= context->last_column; c++)
-        buffer[c-1] = (c >= context->first_column ? '^' : ' ');
-    ELOG("CONFIG:   %s\n", buffer);
-    ELOG("\n");
-}
-
-int yywrap(void) {
-    return 1;
-}
-
-/*
- * Goes through each line of buf (separated by \n) and checks for statements /
- * commands which only occur in i3 v4 configuration files. If it finds any, it
- * returns version 4, otherwise it returns version 3.
- *
- */
-static int detect_version(char *buf) {
-    char *walk = buf;
-    char *line = buf;
-    while (*walk != '\0') {
-        if (*walk != '\n') {
-            walk++;
-            continue;
-        }
-
-        /* check for some v4-only statements */
-        if (strncasecmp(line, "bindcode", strlen("bindcode")) == 0 ||
-            strncasecmp(line, "force_focus_wrapping", strlen("force_focus_wrapping")) == 0 ||
-            strncasecmp(line, "# i3 config file (v4)", strlen("# i3 config file (v4)")) == 0 ||
-            strncasecmp(line, "workspace_layout", strlen("workspace_layout")) == 0) {
-            printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
-            return 4;
-        }
-
-        /* if this is a bind statement, we can check the command */
-        if (strncasecmp(line, "bind", strlen("bind")) == 0) {
-            char *bind = strchr(line, ' ');
-            if (bind == NULL)
-                goto next;
-            while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
-                bind++;
-            if (*bind == '\0')
-                goto next;
-            if ((bind = strchr(bind, ' ')) == NULL)
-                goto next;
-            while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
-                bind++;
-            if (*bind == '\0')
-                goto next;
-            if (strncasecmp(bind, "layout", strlen("layout")) == 0 ||
-                strncasecmp(bind, "floating", strlen("floating")) == 0 ||
-                strncasecmp(bind, "workspace", strlen("workspace")) == 0 ||
-                strncasecmp(bind, "focus left", strlen("focus left")) == 0 ||
-                strncasecmp(bind, "focus right", strlen("focus right")) == 0 ||
-                strncasecmp(bind, "focus up", strlen("focus up")) == 0 ||
-                strncasecmp(bind, "focus down", strlen("focus down")) == 0 ||
-                strncasecmp(bind, "border normal", strlen("border normal")) == 0 ||
-                strncasecmp(bind, "border 1pixel", strlen("border 1pixel")) == 0 ||
-                strncasecmp(bind, "border pixel", strlen("border pixel")) == 0 ||
-                strncasecmp(bind, "border borderless", strlen("border borderless")) == 0 ||
-                strncasecmp(bind, "--no-startup-id", strlen("--no-startup-id")) == 0 ||
-                strncasecmp(bind, "bar", strlen("bar")) == 0) {
-                printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
-                return 4;
-            }
-        }
-
-next:
-        /* advance to the next line */
-        walk++;
-        line = walk;
-    }
-
-    return 3;
-}
-
-/*
- * Calls i3-migrate-config-to-v4 to migrate a configuration file (input
- * buffer).
- *
- * Returns the converted config file or NULL if there was an error (for
- * example the script could not be found in $PATH or the i3 executable’s
- * directory).
- *
- */
-static char *migrate_config(char *input, off_t size) {
-    int writepipe[2];
-    int readpipe[2];
-
-    if (pipe(writepipe) != 0 ||
-        pipe(readpipe) != 0) {
-        warn("migrate_config: Could not create pipes");
-        return NULL;
-    }
-
-    pid_t pid = fork();
-    if (pid == -1) {
-        warn("Could not fork()");
-        return NULL;
-    }
-
-    /* child */
-    if (pid == 0) {
-        /* close writing end of writepipe, connect reading side to stdin */
-        close(writepipe[1]);
-        dup2(writepipe[0], 0);
-
-        /* close reading end of readpipe, connect writing side to stdout */
-        close(readpipe[0]);
-        dup2(readpipe[1], 1);
-
-        static char *argv[] = {
-            NULL, /* will be replaced by the executable path */
-            NULL
-        };
-        exec_i3_utility("i3-migrate-config-to-v4", argv);
-    }
-
-    /* parent */
-
-    /* close reading end of the writepipe (connected to the script’s stdin) */
-    close(writepipe[0]);
-
-    /* write the whole config file to the pipe, the script will read everything
-     * immediately */
-    int written = 0;
-    int ret;
-    while (written < size) {
-        if ((ret = write(writepipe[1], input + written, size - written)) < 0) {
-            warn("Could not write to pipe");
-            return NULL;
-        }
-        written += ret;
-    }
-    close(writepipe[1]);
-
-    /* close writing end of the readpipe (connected to the script’s stdout) */
-    close(readpipe[1]);
-
-    /* read the script’s output */
-    int conv_size = 65535;
-    char *converted = malloc(conv_size);
-    int read_bytes = 0;
-    do {
-        if (read_bytes == conv_size) {
-            conv_size += 65535;
-            converted = realloc(converted, conv_size);
-        }
-        ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
-        if (ret == -1) {
-            warn("Cannot read from pipe");
-            FREE(converted);
-            return NULL;
-        }
-        read_bytes += ret;
-    } while (ret > 0);
-
-    /* get the returncode */
-    int status;
-    wait(&status);
-    if (!WIFEXITED(status)) {
-        fprintf(stderr, "Child did not terminate normally, using old config file (will lead to broken behaviour)\n");
-        return NULL;
-    }
-
-    int returncode = WEXITSTATUS(status);
-    if (returncode != 0) {
-        fprintf(stderr, "Migration process exit code was != 0\n");
-        if (returncode == 2) {
-            fprintf(stderr, "could not start the migration script\n");
-            /* TODO: script was not found. tell the user to fix his system or create a v4 config */
-        } else if (returncode == 1) {
-            fprintf(stderr, "This already was a v4 config. Please add the following line to your config file:\n");
-            fprintf(stderr, "# i3 config file (v4)\n");
-            /* TODO: nag the user with a message to include a hint for i3 in his config file */
-        }
-        return NULL;
-    }
-
-    return converted;
-}
-
-/*
- * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
- * it exited (or could not be started, depending on the exit code).
- *
- */
-static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
-    ev_child_stop(EV_A_ watcher);
-
-    if (unlink(edit_script_path) != 0)
-        warn("Could not delete temporary i3-nagbar script %s", edit_script_path);
-    if (unlink(pager_script_path) != 0)
-        warn("Could not delete temporary i3-nagbar script %s", pager_script_path);
-
-    if (!WIFEXITED(watcher->rstatus)) {
-        fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
-        return;
-    }
-
-    int exitcode = WEXITSTATUS(watcher->rstatus);
-    printf("i3-nagbar process exited with status %d\n", exitcode);
-    if (exitcode == 2) {
-        fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
-    }
-
-    configerror_pid = -1;
-}
-
-/* We need ev >= 4 for the following code. Since it is not *that* important (it
- * only makes sure that there are no i3-nagbar instances left behind) we still
- * support old systems with libev 3. */
-#if EV_VERSION_MAJOR >= 4
-/*
- * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
- * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
- *
- */
-static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
-    if (configerror_pid != -1) {
-        LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", configerror_pid);
-        kill(configerror_pid, SIGKILL);
-    }
-}
-#endif
-
-/*
- * Writes the given command as a shell script to path.
- * Returns true unless something went wrong.
- *
- */
-static bool write_nagbar_script(const char *path, const char *command) {
-    int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IXUSR);
-    if (fd == -1) {
-        warn("Could not create temporary script to store the nagbar command");
-        return false;
-    }
-    write(fd, "#!/bin/sh\n", strlen("#!/bin/sh\n"));
-    write(fd, command, strlen(command));
-    close(fd);
-    return true;
-}
-
-/*
- * Starts an i3-nagbar process which alerts the user that his configuration
- * file contains one or more errors. Also offers two buttons: One to launch an
- * $EDITOR on the config file and another one to launch a $PAGER on the error
- * logfile.
- *
- */
-static void start_configerror_nagbar(const char *config_path) {
-    if (only_check_config)
-        return;
-
-    fprintf(stderr, "Starting i3-nagbar due to configuration errors\n");
-
-    /* We need to create a custom script containing our actual command
-     * since not every terminal emulator which is contained in
-     * i3-sensible-terminal supports -e with multiple arguments (and not
-     * all of them support -e with one quoted argument either).
-     *
-     * NB: The paths need to be unique, that is, don’t assume users close
-     * their nagbars at any point in time (and they still need to work).
-     * */
-    edit_script_path = get_process_filename("nagbar-cfgerror-edit");
-    pager_script_path = get_process_filename("nagbar-cfgerror-pager");
-
-    configerror_pid = fork();
-    if (configerror_pid == -1) {
-        warn("Could not fork()");
-        return;
-    }
-
-    /* child */
-    if (configerror_pid == 0) {
-        char *edit_command, *pager_command;
-        sasprintf(&edit_command, "i3-sensible-editor \"%s\" && i3-msg reload\n", config_path);
-        sasprintf(&pager_command, "i3-sensible-pager \"%s\"\n", errorfilename);
-        if (!write_nagbar_script(edit_script_path, edit_command) ||
-            !write_nagbar_script(pager_script_path, pager_command))
-            return;
-
-        char *editaction,
-             *pageraction;
-        sasprintf(&editaction, "i3-sensible-terminal -e \"%s\"", edit_script_path);
-        sasprintf(&pageraction, "i3-sensible-terminal -e \"%s\"", pager_script_path);
-        char *argv[] = {
-            NULL, /* will be replaced by the executable path */
-            "-t",
-            (context->has_errors ? "error" : "warning"),
-            "-m",
-            (context->has_errors ?
-             "You have an error in your i3 config file!" :
-             "Your config is outdated. Please fix the warnings to make sure everything works."),
-            "-b",
-            "edit config",
-            editaction,
-            (errorfilename ? "-b" : NULL),
-            (context->has_errors ? "show errors" : "show warnings"),
-            pageraction,
-            NULL
-        };
-        exec_i3_utility("i3-nagbar", argv);
-    }
-
-    /* parent */
-    /* install a child watcher */
-    ev_child *child = smalloc(sizeof(ev_child));
-    ev_child_init(child, &nagbar_exited, configerror_pid, 0);
-    ev_child_start(main_loop, child);
-
-/* We need ev >= 4 for the following code. Since it is not *that* important (it
- * only makes sure that there are no i3-nagbar instances left behind) we still
- * support old systems with libev 3. */
-#if EV_VERSION_MAJOR >= 4
-    /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
-     * still running) */
-    ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
-    ev_cleanup_init(cleanup, nagbar_cleanup);
-    ev_cleanup_start(main_loop, cleanup);
-#endif
-}
-
-/*
- * Kills the configerror i3-nagbar process, if any.
- *
- * Called when reloading/restarting.
- *
- * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
- * ev is assumed to handle it (reloading).
- *
- */
-void kill_configerror_nagbar(bool wait_for_it) {
-    if (configerror_pid == -1)
-        return;
-
-    if (kill(configerror_pid, SIGTERM) == -1)
-        warn("kill(configerror_nagbar) failed");
-
-    if (!wait_for_it)
-        return;
-
-    /* When restarting, we don’t enter the ev main loop anymore and after the
-     * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
-     * for us and we would end up with a <defunct> process. Therefore we
-     * waitpid() here. */
-    waitpid(configerror_pid, NULL, 0);
-}
-
-/*
- * Checks for duplicate key bindings (the same keycode or keysym is configured
- * more than once). If a duplicate binding is found, a message is printed to
- * stderr and the has_errors variable is set to true, which will start
- * i3-nagbar.
- *
- */
-static void check_for_duplicate_bindings(struct context *context) {
-    Binding *bind, *current;
-    TAILQ_FOREACH(current, bindings, bindings) {
-        TAILQ_FOREACH(bind, bindings, bindings) {
-            /* Abort when we reach the current keybinding, only check the
-             * bindings before */
-            if (bind == current)
-                break;
-
-            /* Check if one is using keysym while the other is using bindsym.
-             * If so, skip. */
-            /* XXX: It should be checked at a later place (when translating the
-             * keysym to keycodes) if there are any duplicates */
-            if ((bind->symbol == NULL && current->symbol != NULL) ||
-                (bind->symbol != NULL && current->symbol == NULL))
-                continue;
-
-            /* If bind is NULL, current has to be NULL, too (see above).
-             * If the keycodes differ, it can't be a duplicate. */
-            if (bind->symbol != NULL &&
-                strcasecmp(bind->symbol, current->symbol) != 0)
-                continue;
-
-            /* Check if the keycodes or modifiers are different. If so, they
-             * can't be duplicate */
-            if (bind->keycode != current->keycode ||
-                bind->mods != current->mods ||
-                bind->release != current->release)
-                continue;
-
-            context->has_errors = true;
-            if (current->keycode != 0) {
-                ELOG("Duplicate keybinding in config file:\n  modmask %d with keycode %d, command \"%s\"\n",
-                     current->mods, current->keycode, current->command);
-            } else {
-                ELOG("Duplicate keybinding in config file:\n  modmask %d with keysym %s, command \"%s\"\n",
-                     current->mods, current->symbol, current->command);
-            }
-        }
-    }
-}
-
-static void migrate_i3bar_exec(struct Autostart *exec) {
-    ELOG("**********************************************************************\n");
-    ELOG("IGNORING exec command: %s\n", exec->command);
-    ELOG("It contains \"i3bar\". Since i3 v4.1, i3bar will be automatically started\n");
-    ELOG("for each 'bar' configuration block in your i3 config. Please remove the exec\n");
-    ELOG("line and add the following to your i3 config:\n");
-    ELOG("\n");
-    ELOG("    bar {\n");
-    ELOG("        status_command i3status\n");
-    ELOG("    }\n");
-    ELOG("**********************************************************************\n");
-
-    /* Generate a dummy bar configuration */
-    Barconfig *bar_config = scalloc(sizeof(Barconfig));
-    /* The hard-coded ID is not a problem. It does not conflict with the
-     * auto-generated bar IDs and having multiple hard-coded IDs is irrelevant
-     * – they all just contain status_command = i3status */
-    bar_config->id = sstrdup("migrate-bar");
-    bar_config->status_command = sstrdup("i3status");
-    TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
-
-    /* Trigger an i3-nagbar */
-    context->has_warnings = true;
-}
-
-void parse_file(const char *f) {
-    SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
-    int fd, ret, read_bytes = 0;
-    struct stat stbuf;
-    char *buf;
-    FILE *fstr;
-    char buffer[1026], key[512], value[512];
-
-    if ((fd = open(f, O_RDONLY)) == -1)
-        die("Could not open configuration file: %s\n", strerror(errno));
-
-    if (fstat(fd, &stbuf) == -1)
-        die("Could not fstat file: %s\n", strerror(errno));
-
-    buf = scalloc((stbuf.st_size + 1) * sizeof(char));
-    while (read_bytes < stbuf.st_size) {
-        if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
-            die("Could not read(): %s\n", strerror(errno));
-        read_bytes += ret;
-    }
-
-    if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
-        die("Could not lseek: %s\n", strerror(errno));
-
-    if ((fstr = fdopen(fd, "r")) == NULL)
-        die("Could not fdopen: %s\n", strerror(errno));
-
-    while (!feof(fstr)) {
-        if (fgets(buffer, 1024, fstr) == NULL) {
-            if (feof(fstr))
-                break;
-            die("Could not read configuration file\n");
-        }
-
-        /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
-        if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
-            key[0] == '#' || strlen(key) < 3)
-            continue;
-
-        if (strcasecmp(key, "set") == 0) {
-            if (value[0] != '$') {
-                ELOG("Malformed variable assignment, name has to start with $\n");
-                continue;
-            }
-
-            /* get key/value for this variable */
-            char *v_key = value, *v_value;
-            if (strstr(value, " ") == NULL && strstr(value, "\t") == NULL) {
-                ELOG("Malformed variable assignment, need a value\n");
-                continue;
-            }
-
-            if (!(v_value = strstr(value, " ")))
-                v_value = strstr(value, "\t");
-
-            *(v_value++) = '\0';
-            while (*v_value == '\t' || *v_value == ' ')
-                v_value++;
-
-            struct Variable *new = scalloc(sizeof(struct Variable));
-            new->key = sstrdup(v_key);
-            new->value = sstrdup(v_value);
-            SLIST_INSERT_HEAD(&variables, new, variables);
-            DLOG("Got new variable %s = %s\n", v_key, v_value);
-            continue;
-        }
-    }
-    fclose(fstr);
-
-    /* For every custom variable, see how often it occurs in the file and
-     * how much extra bytes it requires when replaced. */
-    struct Variable *current, *nearest;
-    int extra_bytes = 0;
-    /* We need to copy the buffer because we need to invalidate the
-     * variables (otherwise we will count them twice, which is bad when
-     * 'extra' is negative) */
-    char *bufcopy = sstrdup(buf);
-    SLIST_FOREACH(current, &variables, variables) {
-        int extra = (strlen(current->value) - strlen(current->key));
-        char *next;
-        for (next = bufcopy;
-             next < (bufcopy + stbuf.st_size) &&
-             (next = strcasestr(next, current->key)) != NULL;
-             next += strlen(current->key)) {
-            *next = '_';
-            extra_bytes += extra;
-        }
-    }
-    FREE(bufcopy);
-
-    /* Then, allocate a new buffer and copy the file over to the new one,
-     * but replace occurences of our variables */
-    char *walk = buf, *destwalk;
-    char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
-    destwalk = new;
-    while (walk < (buf + stbuf.st_size)) {
-        /* Find the next variable */
-        SLIST_FOREACH(current, &variables, variables)
-            current->next_match = strcasestr(walk, current->key);
-        nearest = NULL;
-        int distance = stbuf.st_size;
-        SLIST_FOREACH(current, &variables, variables) {
-            if (current->next_match == NULL)
-                continue;
-            if ((current->next_match - walk) < distance) {
-                distance = (current->next_match - walk);
-                nearest = current;
-            }
-        }
-        if (nearest == NULL) {
-            /* If there are no more variables, we just copy the rest */
-            strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
-            destwalk += (buf + stbuf.st_size) - walk;
-            *destwalk = '\0';
-            break;
-        } else {
-            /* Copy until the next variable, then copy its value */
-            strncpy(destwalk, walk, distance);
-            strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
-            walk += distance + strlen(nearest->key);
-            destwalk += distance + strlen(nearest->value);
-        }
-    }
-
-    /* analyze the string to find out whether this is an old config file (3.x)
-     * or a new config file (4.x). If it’s old, we run the converter script. */
-    int version = detect_version(buf);
-    if (version == 3) {
-        /* We need to convert this v3 configuration */
-        char *converted = migrate_config(new, stbuf.st_size);
-        if (converted != NULL) {
-            ELOG("\n");
-            ELOG("****************************************************************\n");
-            ELOG("NOTE: Automatically converted configuration file from v3 to v4.\n");
-            ELOG("\n");
-            ELOG("Please convert your config file to v4. You can use this command:\n");
-            ELOG("    mv %s %s.O\n", f, f);
-            ELOG("    i3-migrate-config-to-v4 %s.O > %s\n", f, f);
-            ELOG("****************************************************************\n");
-            ELOG("\n");
-            free(new);
-            new = converted;
-        } else {
-            printf("\n");
-            printf("**********************************************************************\n");
-            printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
-            printf("was not correctly installed on your system?\n");
-            printf("**********************************************************************\n");
-            printf("\n");
-        }
-    }
-
-
-    context = scalloc(sizeof(struct context));
-    context->filename = f;
-
-    if (force_old_config_parser) {
-        /* now lex/parse it */
-        yy_scan_string(new);
-        if (yyparse() != 0) {
-            fprintf(stderr, "Could not parse configfile\n");
-            exit(1);
-        }
-    } else {
-        struct ConfigResult *config_output = parse_config(new, context);
-        yajl_gen_free(config_output->json_gen);
-    }
-
-    check_for_duplicate_bindings(context);
-
-    /* XXX: The following code will be removed in i3 v4.3 (three releases from
-     * now, as of 2011-10-22) */
-    /* Check for any exec or exec_always lines starting i3bar. We remove these
-     * and add a bar block instead. Additionally, a i3-nagbar warning (not an
-     * error) will be displayed so that users update their config file. */
-    struct Autostart *exec, *next;
-    for (exec = TAILQ_FIRST(&autostarts); exec; ) {
-        next = TAILQ_NEXT(exec, autostarts);
-        if (strstr(exec->command, "i3bar") != NULL) {
-            migrate_i3bar_exec(exec);
-            TAILQ_REMOVE(&autostarts, exec, autostarts);
-        }
-        exec = next;
-    }
-
-    for (exec = TAILQ_FIRST(&autostarts_always); exec; ) {
-        next = TAILQ_NEXT(exec, autostarts_always);
-        if (strstr(exec->command, "i3bar") != NULL) {
-            migrate_i3bar_exec(exec);
-            TAILQ_REMOVE(&autostarts_always, exec, autostarts_always);
-        }
-        exec = next;
-    }
-
-    if (context->has_errors || context->has_warnings) {
-        ELOG("FYI: You are using i3 version " I3_VERSION "\n");
-        if (version == 3)
-            ELOG("Please convert your configfile first, then fix any remaining errors (see above).\n");
-        start_configerror_nagbar(f);
-    }
-
-    if (force_old_config_parser)
-        yylex_destroy();
-    FREE(context->line_copy);
-    free(context);
-    FREE(font_pattern);
-    free(new);
-    free(buf);
-
-    while (!SLIST_EMPTY(&variables)) {
-        current = SLIST_FIRST(&variables);
-        FREE(current->key);
-        FREE(current->value);
-        SLIST_REMOVE_HEAD(&variables, variables);
-        FREE(current);
-    }
-}
-
-%}
-
-%error-verbose
-%lex-param { struct context *context }
-
-%union {
-    int number;
-    char *string;
-    uint32_t *single_color;
-    struct Colortriple *color;
-    Match *match;
-    struct Binding *binding;
-}
-
-%token  <number>        NUMBER                      "<number>"
-%token  <string>        WORD                        "<word>"
-%token  <string>        STR                         "<string>"
-%token  <string>        STR_NG                      "<string (non-greedy)>"
-%token  <string>        HEXCOLOR                    "#<hex>"
-%token  <string>        OUTPUT                      "<RandR output>"
-%token                  TOKBINDCODE
-%token                  TOKTERMINAL
-%token                  TOKCOMMENT                  "<comment>"
-%token                  TOKFONT                     "font"
-%token                  TOKBINDSYM                  "bindsym"
-%token  <number>        MODIFIER                    "<modifier>"
-%token                  TOKCONTROL                  "control"
-%token                  TOKSHIFT                    "shift"
-%token                  TOKFLOATING_MODIFIER        "floating_modifier"
-%token                  TOKFLOATING_MAXIMUM_SIZE    "floating_maximum_size"
-%token                  TOKFLOATING_MINIMUM_SIZE    "floating_minimum_size"
-%token  <string>        QUOTEDSTRING                "<quoted string>"
-%token                  TOKWORKSPACE                "workspace"
-%token                  TOKOUTPUT                   "output"
-%token                  TOKASSIGN                   "assign"
-%token                  TOKSET
-%token                  TOKIPCSOCKET                "ipc_socket"
-%token                  TOKRESTARTSTATE             "restart_state"
-%token                  TOKEXEC                     "exec"
-%token                  TOKEXEC_ALWAYS              "exec_always"
-%token  <single_color>  TOKSINGLECOLOR
-%token  <color>         TOKCOLOR
-%token                  TOKARROW                    "→"
-%token                  TOKMODE                     "mode"
-%token                  TOK_TIME_MS                 "ms"
-%token                  TOK_BAR                     "bar"
-%token                  TOK_ORIENTATION             "default_orientation"
-%token                  TOK_HORIZ                   "horizontal"
-%token                  TOK_VERT                    "vertical"
-%token                  TOK_AUTO                    "auto"
-%token                  TOK_WORKSPACE_LAYOUT        "workspace_layout"
-%token                  TOKNEWWINDOW                "new_window"
-%token                  TOKNEWFLOAT                 "new_float"
-%token                  TOK_NORMAL                  "normal"
-%token                  TOK_NONE                    "none"
-%token                  TOK_PIXEL                   "pixel"
-%token                  TOK_1PIXEL                  "1pixel"
-%token                  TOK_HIDE_EDGE_BORDERS       "hide_edge_borders"
-%token                  TOK_BOTH                    "both"
-%token                  TOKFOCUSFOLLOWSMOUSE        "focus_follows_mouse"
-%token                  TOK_FORCE_FOCUS_WRAPPING    "force_focus_wrapping"
-%token                  TOK_FORCE_XINERAMA          "force_xinerama"
-%token                  TOK_FAKE_OUTPUTS            "fake_outputs"
-%token                  TOK_WORKSPACE_AUTO_BAF      "workspace_auto_back_and_forth"
-%token                  TOK_WORKSPACE_URGENCY_TIMER "force_display_urgency_hint"
-%token                  TOKWORKSPACEBAR             "workspace_bar"
-%token                  TOK_DEFAULT                 "default"
-%token                  TOK_STACKING                "stacking"
-%token                  TOK_TABBED                  "tabbed"
-%token  <number>        TOKSTACKLIMIT               "stack-limit"
-%token                  TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen"
-%token                  TOK_IGNORE                  "ignore"
-%token                  TOK_LEAVE_FULLSCREEN        "leave_fullscreen"
-%token                  TOK_FOR_WINDOW              "for_window"
-
-%token                  TOK_BAR_OUTPUT              "output (bar)"
-%token                  TOK_BAR_TRAY_OUTPUT         "tray_output"
-%token                  TOK_BAR_SOCKET_PATH         "socket_path"
-%token                  TOK_BAR_MODE                "mode (bar)"
-%token                  TOK_BAR_HIDE                "hide"
-%token                  TOK_BAR_DOCK                "dock"
-%token                  TOK_BAR_MODIFIER            "modifier (bar)"
-%token                  TOK_BAR_CONTROL             "shift (bar)"
-%token                  TOK_BAR_SHIFT               "control (bar)"
-%token                  TOK_BAR_MOD1                "Mod1"
-%token                  TOK_BAR_MOD2                "Mod2"
-%token                  TOK_BAR_MOD3                "Mod3"
-%token                  TOK_BAR_MOD4                "Mod4"
-%token                  TOK_BAR_MOD5                "Mod5"
-%token                  TOK_BAR_POSITION            "position"
-%token                  TOK_BAR_BOTTOM              "bottom"
-%token                  TOK_BAR_TOP                 "top"
-%token                  TOK_BAR_STATUS_COMMAND      "status_command"
-%token                  TOK_BAR_I3BAR_COMMAND       "i3bar_command"
-%token                  TOK_BAR_FONT                "font (bar)"
-%token                  TOK_BAR_WORKSPACE_BUTTONS   "workspace_buttons"
-%token                  TOK_BAR_VERBOSE             "verbose"
-%token                  TOK_BAR_COLORS              "colors"
-%token                  TOK_BAR_COLOR_BACKGROUND    "background"
-%token                  TOK_BAR_COLOR_STATUSLINE    "statusline"
-%token                  TOK_BAR_COLOR_FOCUSED_WORKSPACE "focused_workspace"
-%token                  TOK_BAR_COLOR_ACTIVE_WORKSPACE "active_workspace"
-%token                  TOK_BAR_COLOR_INACTIVE_WORKSPACE "inactive_workspace"
-%token                  TOK_BAR_COLOR_URGENT_WORKSPACE "urgent_workspace"
-%token                  TOK_NO_STARTUP_ID           "--no-startup-id"
-%token                  TOK_RELEASE                 "--release"
-
-%token              TOK_MARK            "mark"
-%token              TOK_CLASS           "class"
-%token              TOK_INSTANCE        "instance"
-%token              TOK_WINDOW_ROLE     "window_role"
-%token              TOK_ID              "id"
-%token              TOK_CON_ID          "con_id"
-%token              TOK_TITLE           "title"
-%token              TOK_URGENT          "urgent"
-
-%type   <binding>       binding
-%type   <binding>       bindcode
-%type   <binding>       bindsym
-%type   <number>        binding_modifiers
-%type   <number>        binding_modifier
-%type   <number>        direction
-%type   <number>        layout_mode
-%type   <number>        border_style
-%type   <number>        new_window
-%type   <number>        hide_edge_borders
-%type   <number>        edge_hiding_mode
-%type   <number>        new_float
-%type   <number>        colorpixel
-%type   <number>        bool
-%type   <number>        popup_setting
-%type   <number>        bar_position_position
-%type   <number>        bar_mode_mode
-%type   <number>        bar_modifier_modifier
-%type   <number>        optional_no_startup_id
-%type   <number>        optional_border_width
-%type   <number>        optional_release
-%type   <string>        command
-%type   <string>        word_or_number
-%type   <string>        duration
-%type   <string>        qstring_or_number
-%type   <string>        optional_workspace_name
-%type   <string>        workspace_name
-%type   <string>        window_class
-
-%%
-
-lines: /* empty */
-    | lines error
-    | lines line
-    ;
-
-line:
-    bindline
-    | for_window
-    | mode
-    | bar
-    | floating_maximum_size
-    | floating_minimum_size
-    | floating_modifier
-    | orientation
-    | workspace_layout
-    | new_window
-    | new_float
-    | hide_edge_borders
-    | focus_follows_mouse
-    | force_focus_wrapping
-    | force_xinerama
-    | fake_outputs
-    | force_display_urgency_hint
-    | workspace_back_and_forth
-    | workspace_bar
-    | workspace
-    | assign
-    | ipcsocket
-    | restart_state
-    | exec
-    | exec_always
-    | single_color
-    | color
-    | terminal
-    | font
-    | comment
-    | popup_during_fullscreen
-    ;
-
-comment:
-    TOKCOMMENT
-    ;
-
-command:
-    STR
-    ;
-
-bindline:
-    binding
-    {
-        TAILQ_INSERT_TAIL(bindings, $1, bindings);
-    }
-    ;
-
-binding:
-    TOKBINDCODE bindcode         { $$ = $2; }
-    | TOKBINDSYM bindsym         { $$ = $2; }
-    ;
-
-bindcode:
-    optional_release binding_modifiers NUMBER command
-    {
-        DLOG("bindcode: release = %d, mod = %d, key = %d, command = %s\n", $1, $2, $3, $4);
-        Binding *new = scalloc(sizeof(Binding));
-
-        new->release = $1;
-        new->keycode = $3;
-        new->mods = $2;
-        new->command = $4;
-
-        $$ = new;
-    }
-    ;
-
-bindsym:
-    optional_release binding_modifiers word_or_number command
-    {
-        DLOG("bindsym: release = %d, mod = %d, key = %s, command = %s\n", $1, $2, $3, $4);
-        Binding *new = scalloc(sizeof(Binding));
-
-        new->release = $1;
-        new->symbol = $3;
-        new->mods = $2;
-        new->command = $4;
-
-        $$ = new;
-    }
-    ;
-
-optional_release:
-    /* empty */ { $$ = B_UPON_KEYPRESS; }
-    | TOK_RELEASE  { $$ = B_UPON_KEYRELEASE; }
-    ;
-
-for_window:
-    TOK_FOR_WINDOW match command
-    {
-        if (match_is_empty(&current_match)) {
-            ELOG("Match is empty, ignoring this for_window statement\n");
-            break;
-        }
-        printf("\t should execute command %s for the criteria mentioned above\n", $3);
-        Assignment *assignment = scalloc(sizeof(Assignment));
-        assignment->type = A_COMMAND;
-        assignment->match = current_match;
-        assignment->dest.command = $3;
-        TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
-    }
-    ;
-
-match:
-    | matchstart criteria matchend
-    {
-        printf("match parsed\n");
-    }
-    ;
-
-matchstart:
-    '['
-    {
-        printf("start\n");
-        match_init(&current_match);
-    }
-    ;
-
-matchend:
-    ']'
-    {
-        printf("match specification finished\n");
-    }
-    ;
-
-criteria:
-    criteria criterion
-    | criterion
-    ;
-
-criterion:
-    TOK_CLASS '=' STR
-    {
-        printf("criteria: class = %s\n", $3);
-        current_match.class = regex_new($3);
-        free($3);
-    }
-    | TOK_INSTANCE '=' STR
-    {
-        printf("criteria: instance = %s\n", $3);
-        current_match.instance = regex_new($3);
-        free($3);
-    }
-    | TOK_WINDOW_ROLE '=' STR
-    {
-        printf("criteria: window_role = %s\n", $3);
-        current_match.role = regex_new($3);
-        free($3);
-    }
-    | TOK_CON_ID '=' STR
-    {
-        printf("criteria: id = %s\n", $3);
-        char *end;
-        long parsed = strtol($3, &end, 10);
-        if (parsed == LONG_MIN ||
-            parsed == LONG_MAX ||
-            parsed < 0 ||
-            (end && *end != '\0')) {
-            ELOG("Could not parse con id \"%s\"\n", $3);
-        } else {
-            current_match.con_id = (Con*)parsed;
-            printf("id as int = %p\n", current_match.con_id);
-        }
-    }
-    | TOK_ID '=' STR
-    {
-        printf("criteria: window id = %s\n", $3);
-        char *end;
-        long parsed = strtol($3, &end, 10);
-        if (parsed == LONG_MIN ||
-            parsed == LONG_MAX ||
-            parsed < 0 ||
-            (end && *end != '\0')) {
-            ELOG("Could not parse window id \"%s\"\n", $3);
-        } else {
-            current_match.id = parsed;
-            printf("window id as int = %d\n", current_match.id);
-        }
-    }
-    | TOK_MARK '=' STR
-    {
-        printf("criteria: mark = %s\n", $3);
-        current_match.mark = regex_new($3);
-        free($3);
-    }
-    | TOK_TITLE '=' STR
-    {
-        printf("criteria: title = %s\n", $3);
-        current_match.title = regex_new($3);
-        free($3);
-    }
-    | TOK_URGENT '=' STR
-    {
-        printf("criteria: urgent = %s\n", $3);
-        if (strcasecmp($3, "latest") == 0 ||
-            strcasecmp($3, "newest") == 0 ||
-            strcasecmp($3, "recent") == 0 ||
-            strcasecmp($3, "last") == 0) {
-            current_match.urgent = U_LATEST;
-        } else if (strcasecmp($3, "oldest") == 0 ||
-                   strcasecmp($3, "first") == 0) {
-            current_match.urgent = U_OLDEST;
-        }
-        free($3);
-    }
-    ;
-
-qstring_or_number:
-    QUOTEDSTRING
-    | NUMBER { sasprintf(&$$, "%d", $1); }
-    ;
-
-word_or_number:
-    WORD
-    | NUMBER
-    {
-        sasprintf(&$$, "%d", $1);
-    }
-    ;
-
-duration:
-    NUMBER { sasprintf(&$$, "%d", $1); }
-    | NUMBER TOK_TIME_MS { sasprintf(&$$, "%d", $1); }
-    ;
-
-mode:
-    TOKMODE QUOTEDSTRING '{' modelines '}'
-    {
-        if (strcasecmp($2, "default") == 0) {
-            printf("You cannot use the name \"default\" for your mode\n");
-            exit(1);
-        }
-        printf("\t now in mode %s\n", $2);
-        printf("\t current bindings = %p\n", current_bindings);
-        Binding *binding;
-        TAILQ_FOREACH(binding, current_bindings, bindings) {
-            printf("got binding on mods %d, keycode %d, symbol %s, command %s\n",
-                            binding->mods, binding->keycode, binding->symbol, binding->command);
-        }
-
-        struct Mode *mode = scalloc(sizeof(struct Mode));
-        mode->name = $2;
-        mode->bindings = current_bindings;
-        current_bindings = NULL;
-        SLIST_INSERT_HEAD(&modes, mode, modes);
-    }
-    ;
-
-
-modelines:
-    /* empty */
-    | modelines modeline
-    ;
-
-modeline:
-    comment
-    | binding
-    {
-        if (current_bindings == NULL) {
-            current_bindings = scalloc(sizeof(struct bindings_head));
-            TAILQ_INIT(current_bindings);
-        }
-
-        TAILQ_INSERT_TAIL(current_bindings, $1, bindings);
-    }
-    ;
-
-bar:
-    TOK_BAR '{' barlines '}'
-    {
-        printf("\t new bar configuration finished, saving.\n");
-        /* Generate a unique ID for this bar */
-        current_bar.id = sstrdup("bar-XXXXXX");
-        /* This works similar to mktemp in that it replaces the last six X with
-         * random letters, but without the restriction that the given buffer
-         * has to contain a valid path name. */
-        char *x = current_bar.id + strlen("bar-");
-        while (*x != '\0') {
-            *(x++) = (rand() % 26) + 'a';
-        }
-
-        /* If no font was explicitly set, we use the i3 font as default */
-        if (!current_bar.font && font_pattern)
-            current_bar.font = sstrdup(font_pattern);
-
-        /* Copy the current (static) structure into a dynamically allocated
-         * one, then cleanup our static one. */
-        Barconfig *bar_config = scalloc(sizeof(Barconfig));
-        memcpy(bar_config, &current_bar, sizeof(Barconfig));
-        TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
-
-        memset(&current_bar, '\0', sizeof(Barconfig));
-    }
-    ;
-
-barlines:
-    /* empty */
-    | barlines barline
-    ;
-
-barline:
-    comment
-    | bar_status_command
-    | bar_i3bar_command
-    | bar_output
-    | bar_tray_output
-    | bar_position
-    | bar_mode
-    | bar_modifier
-    | bar_font
-    | bar_workspace_buttons
-    | bar_verbose
-    | bar_socket_path
-    | bar_colors
-    | bar_color_background
-    | bar_color_statusline
-    | bar_color_focused_workspace
-    | bar_color_active_workspace
-    | bar_color_inactive_workspace
-    | bar_color_urgent_workspace
-    ;
-
-bar_status_command:
-    TOK_BAR_STATUS_COMMAND STR
-    {
-        DLOG("should add status command %s\n", $2);
-        FREE(current_bar.status_command);
-        current_bar.status_command = $2;
-    }
-    ;
-
-bar_i3bar_command:
-    TOK_BAR_I3BAR_COMMAND STR
-    {
-        DLOG("should add i3bar_command %s\n", $2);
-        FREE(current_bar.i3bar_command);
-        current_bar.i3bar_command = $2;
-    }
-    ;
-
-bar_output:
-    TOK_BAR_OUTPUT STR
-    {
-        DLOG("bar output %s\n", $2);
-        int new_outputs = current_bar.num_outputs + 1;
-        current_bar.outputs = srealloc(current_bar.outputs, sizeof(char*) * new_outputs);
-        current_bar.outputs[current_bar.num_outputs] = $2;
-        current_bar.num_outputs = new_outputs;
-    }
-    ;
-
-bar_tray_output:
-    TOK_BAR_TRAY_OUTPUT STR
-    {
-        DLOG("tray %s\n", $2);
-        FREE(current_bar.tray_output);
-        current_bar.tray_output = $2;
-    }
-    ;
-
-bar_position:
-    TOK_BAR_POSITION bar_position_position
-    {
-        DLOG("position %d\n", $2);
-        current_bar.position = $2;
-    }
-    ;
-
-bar_position_position:
-    TOK_BAR_TOP      { $$ = P_TOP; }
-    | TOK_BAR_BOTTOM { $$ = P_BOTTOM; }
-    ;
-
-bar_mode:
-    TOK_BAR_MODE bar_mode_mode
-    {
-        DLOG("mode %d\n", $2);
-        current_bar.mode = $2;
-    }
-    ;
-
-bar_mode_mode:
-    TOK_BAR_HIDE   { $$ = M_HIDE; }
-    | TOK_BAR_DOCK { $$ = M_DOCK; }
-    ;
-
-bar_modifier:
-    TOK_BAR_MODIFIER bar_modifier_modifier
-    {
-        DLOG("modifier %d\n", $2);
-        current_bar.modifier = $2;
-    };
-
-bar_modifier_modifier:
-    TOK_BAR_CONTROL { $$ = M_CONTROL; }
-    | TOK_BAR_SHIFT { $$ = M_SHIFT; }
-    | TOK_BAR_MOD1  { $$ = M_MOD1; }
-    | TOK_BAR_MOD2  { $$ = M_MOD2; }
-    | TOK_BAR_MOD3  { $$ = M_MOD3; }
-    | TOK_BAR_MOD4  { $$ = M_MOD4; }
-    | TOK_BAR_MOD5  { $$ = M_MOD5; }
-    ;
-
-bar_font:
-    TOK_BAR_FONT STR
-    {
-        DLOG("font %s\n", $2);
-        FREE(current_bar.font);
-        current_bar.font = $2;
-    }
-    ;
-
-bar_workspace_buttons:
-    TOK_BAR_WORKSPACE_BUTTONS bool
-    {
-        DLOG("workspace_buttons = %d\n", $2);
-        /* We store this inverted to make the default setting right when
-         * initializing the struct with zero. */
-        current_bar.hide_workspace_buttons = !($2);
-    }
-    ;
-
-bar_verbose:
-    TOK_BAR_VERBOSE bool
-    {
-        DLOG("verbose = %d\n", $2);
-        current_bar.verbose = $2;
-    }
-    ;
-
-bar_socket_path:
-    TOK_BAR_SOCKET_PATH STR
-    {
-        DLOG("socket_path = %s\n", $2);
-        FREE(current_bar.socket_path);
-        current_bar.socket_path = $2;
-    }
-    ;
-
-bar_colors:
-    TOK_BAR_COLORS '{' barlines '}'
-    {
-        /* At the moment, the TOK_BAR_COLORS token is only to make the config
-         * friendlier for humans. We might change this in the future if it gets
-         * more complex. */
-    }
-    ;
-
-bar_color_background:
-    TOK_BAR_COLOR_BACKGROUND HEXCOLOR
-    {
-        DLOG("background = %s\n", $2);
-        current_bar.colors.background = $2;
-    }
-    ;
-
-bar_color_statusline:
-    TOK_BAR_COLOR_STATUSLINE HEXCOLOR
-    {
-        DLOG("statusline = %s\n", $2);
-        current_bar.colors.statusline = $2;
-    }
-    ;
-
-bar_color_focused_workspace:
-    TOK_BAR_COLOR_FOCUSED_WORKSPACE HEXCOLOR HEXCOLOR
-    {
-        /* Old syntax: text / background */
-        DLOG("focused_ws = %s, %s (old)\n", $2, $3);
-        current_bar.colors.focused_workspace_bg = $3;
-        current_bar.colors.focused_workspace_text = $2;
-    }
-    | TOK_BAR_COLOR_FOCUSED_WORKSPACE HEXCOLOR HEXCOLOR HEXCOLOR
-    {
-        /* New syntax: border / background / text */
-        DLOG("focused_ws = %s, %s and %s\n", $2, $3, $4);
-        current_bar.colors.focused_workspace_border = $2;
-        current_bar.colors.focused_workspace_bg = $3;
-        current_bar.colors.focused_workspace_text = $4;
-    }
-    ;
-
-bar_color_active_workspace:
-    TOK_BAR_COLOR_ACTIVE_WORKSPACE HEXCOLOR HEXCOLOR
-    {
-        /* Old syntax: text / background */
-        DLOG("active_ws = %s, %s (old)\n", $2, $3);
-        current_bar.colors.active_workspace_bg = $3;
-        current_bar.colors.active_workspace_text = $2;
-    }
-    | TOK_BAR_COLOR_ACTIVE_WORKSPACE HEXCOLOR HEXCOLOR HEXCOLOR
-    {
-        /* New syntax: border / background / text */
-        DLOG("active_ws = %s, %s and %s\n", $2, $3, $4);
-        current_bar.colors.active_workspace_border = $2;
-        current_bar.colors.active_workspace_bg = $3;
-        current_bar.colors.active_workspace_text = $4;
-    }
-    ;
-
-bar_color_inactive_workspace:
-    TOK_BAR_COLOR_INACTIVE_WORKSPACE HEXCOLOR HEXCOLOR
-    {
-        /* Old syntax: text / background */
-        DLOG("inactive_ws = %s, %s (old)\n", $2, $3);
-        current_bar.colors.inactive_workspace_bg = $3;
-        current_bar.colors.inactive_workspace_text = $2;
-    }
-    | TOK_BAR_COLOR_INACTIVE_WORKSPACE HEXCOLOR HEXCOLOR HEXCOLOR
-    {
-        DLOG("inactive_ws = %s, %s and %s\n", $2, $3, $4);
-        current_bar.colors.inactive_workspace_border = $2;
-        current_bar.colors.inactive_workspace_bg = $3;
-        current_bar.colors.inactive_workspace_text = $4;
-    }
-    ;
-
-bar_color_urgent_workspace:
-    TOK_BAR_COLOR_URGENT_WORKSPACE HEXCOLOR HEXCOLOR
-    {
-        /* Old syntax: text / background */
-        DLOG("urgent_ws = %s, %s (old)\n", $2, $3);
-        current_bar.colors.urgent_workspace_bg = $3;
-        current_bar.colors.urgent_workspace_text = $2;
-    }
-    | TOK_BAR_COLOR_URGENT_WORKSPACE HEXCOLOR HEXCOLOR HEXCOLOR
-    {
-        DLOG("urgent_ws = %s, %s and %s\n", $2, $3, $4);
-        current_bar.colors.urgent_workspace_border = $2;
-        current_bar.colors.urgent_workspace_bg = $3;
-        current_bar.colors.urgent_workspace_text = $4;
-    }
-    ;
-
-floating_maximum_size:
-    TOKFLOATING_MAXIMUM_SIZE NUMBER WORD NUMBER
-    {
-        printf("floating_maximum_width = %d\n", $2);
-        printf("floating_maximum_height = %d\n", $4);
-        config.floating_maximum_width = $2;
-        config.floating_maximum_height = $4;
-    }
-    ;
-
-floating_minimum_size:
-    TOKFLOATING_MINIMUM_SIZE NUMBER WORD NUMBER
-    {
-        printf("floating_minimum_width = %d\n", $2);
-        printf("floating_minimum_height = %d\n", $4);
-        config.floating_minimum_width = $2;
-        config.floating_minimum_height = $4;
-    }
-    ;
-
-floating_modifier:
-    TOKFLOATING_MODIFIER binding_modifiers
-    {
-        DLOG("floating modifier = %d\n", $2);
-        config.floating_modifier = $2;
-    }
-    ;
-
-orientation:
-    TOK_ORIENTATION direction
-    {
-        DLOG("New containers should start with split direction %d\n", $2);
-        config.default_orientation = $2;
-    }
-    ;
-
-direction:
-    TOK_HORIZ       { $$ = HORIZ; }
-    | TOK_VERT      { $$ = VERT; }
-    | TOK_AUTO      { $$ = NO_ORIENTATION; }
-    ;
-
-workspace_layout:
-    TOK_WORKSPACE_LAYOUT layout_mode
-    {
-        DLOG("new containers will be in mode %d\n", $2);
-        config.default_layout = $2;
-
-#if 0
-        /* We also need to change the layout of the already existing
-         * workspaces here. Workspaces may exist at this point because
-         * of the other directives which are modifying workspaces
-         * (setting the preferred screen or name). While the workspace
-         * objects are already created, they have never been used.
-         * Thus, the user very likely awaits the default container mode
-         * to trigger in this case, regardless of where it is inside
-         * his configuration file. */
-        Workspace *ws;
-        TAILQ_FOREACH(ws, workspaces, workspaces) {
-                if (ws->table == NULL)
-                        continue;
-                switch_layout_mode(global_conn,
-                                   ws->table[0][0],
-                                   config.container_mode);
-        }
-#endif
-    }
-    | TOK_WORKSPACE_LAYOUT TOKSTACKLIMIT TOKSTACKLIMIT NUMBER
-    {
-        DLOG("stack-limit %d with val %d\n", $3, $4);
-        config.container_stack_limit = $3;
-        config.container_stack_limit_value = $4;
-
-#if 0
-        /* See the comment above */
-        Workspace *ws;
-        TAILQ_FOREACH(ws, workspaces, workspaces) {
-                if (ws->table == NULL)
-                        continue;
-                Container *con = ws->table[0][0];
-                con->stack_limit = config.container_stack_limit;
-                con->stack_limit_value = config.container_stack_limit_value;
-        }
-#endif
-    }
-    ;
-
-layout_mode:
-    TOK_DEFAULT       { $$ = L_DEFAULT; }
-    | TOK_STACKING    { $$ = L_STACKED; }
-    | TOK_TABBED      { $$ = L_TABBED; }
-    ;
-
-new_window:
-    TOKNEWWINDOW border_style
-    {
-        DLOG("new windows should start with border style %d\n", $2);
-        config.default_border = $2;
-    }
-    ;
-
-new_float:
-    TOKNEWFLOAT border_style
-    {
-       DLOG("new floating windows should start with border style %d\n", $2);
-       config.default_floating_border = $2;
-    }
-    ;
-
-border_style:
-    TOK_NORMAL optional_border_width
-    {
-        /* FIXME: the whole border_style thing actually screws up when new_float is used because it overwrites earlier values :-/ */
-        config.default_border_width = $2;
-        $$ = BS_NORMAL;
-    }
-    | TOK_1PIXEL
-    {
-        config.default_border_width = 1;
-        $$ = BS_PIXEL;
-    }
-    | TOK_NONE
-    {
-        config.default_border_width = 0;
-        $$ = BS_NONE;
-    }
-    | TOK_PIXEL optional_border_width
-    {
-        config.default_border_width = $2;
-        $$ = BS_PIXEL;
-    }
-    ;
-
-bool:
-    NUMBER
-    {
-        $$ = ($1 == 1);
-    }
-    | WORD
-    {
-        DLOG("checking word \"%s\"\n", $1);
-        $$ = (strcasecmp($1, "yes") == 0 ||
-              strcasecmp($1, "true") == 0 ||
-              strcasecmp($1, "on") == 0 ||
-              strcasecmp($1, "enable") == 0 ||
-              strcasecmp($1, "active") == 0);
-    }
-    ;
-
-hide_edge_borders:
-    TOK_HIDE_EDGE_BORDERS edge_hiding_mode
-    {
-        DLOG("hide edge borders = %d\n", $2);
-        config.hide_edge_borders = $2;
-    }
-    ;
-
-edge_hiding_mode:
-    TOK_NONE        { $$ = ADJ_NONE; }
-    | TOK_VERT      { $$ = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE; }
-    | TOK_HORIZ     { $$ = ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE; }
-    | TOK_BOTH      { $$ = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE | ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE; }
-    | bool          { $$ = ($1 ? ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE : ADJ_NONE); }
-    ;
-
-focus_follows_mouse:
-    TOKFOCUSFOLLOWSMOUSE bool
-    {
-        DLOG("focus follows mouse = %d\n", $2);
-        config.disable_focus_follows_mouse = !($2);
-    }
-    ;
-
-force_focus_wrapping:
-    TOK_FORCE_FOCUS_WRAPPING bool
-    {
-        DLOG("force focus wrapping = %d\n", $2);
-        config.force_focus_wrapping = $2;
-    }
-    ;
-
-force_xinerama:
-    TOK_FORCE_XINERAMA bool
-    {
-        DLOG("force xinerama = %d\n", $2);
-        config.force_xinerama = $2;
-    }
-    ;
-
-fake_outputs:
-    TOK_FAKE_OUTPUTS STR
-    {
-        DLOG("fake outputs = %s\n", $2);
-        config.fake_outputs = $2;
-    }
-    ;
-
-workspace_back_and_forth:
-    TOK_WORKSPACE_AUTO_BAF bool
-    {
-        DLOG("automatic workspace back-and-forth = %d\n", $2);
-        config.workspace_auto_back_and_forth = $2;
-    }
-    ;
-
-force_display_urgency_hint:
-    TOK_WORKSPACE_URGENCY_TIMER duration
-    {
-        DLOG("workspace urgency_timer = %f\n", atoi($2) / 1000.0);
-        config.workspace_urgency_timer = atoi($2) / 1000.0;
-    }
-    ;
-
-workspace_bar:
-    TOKWORKSPACEBAR bool
-    {
-        DLOG("workspace bar = %d\n", $2);
-        config.disable_workspace_bar = !($2);
-    }
-    ;
-
-workspace:
-    TOKWORKSPACE qstring_or_number TOKOUTPUT OUTPUT optional_workspace_name
-    {
-        char *ws_name = $2;
-
-        if ($5 != NULL) {
-            ELOG("The old (v3) syntax workspace <number> output <output> <name> is deprecated.\n");
-            ELOG("Please use the new syntax: workspace \"<workspace>\" output <output>\n");
-            ELOG("In your case, the following should work:\n");
-            ELOG("    workspace \"%s\" output %s\n", $5, $4);
-            ws_name = $5;
-            context->has_warnings = true;
-        }
-
-        DLOG("Assigning workspace \"%s\" to output \"%s\"\n", ws_name, $4);
-        /* Check for earlier assignments of the same workspace so that we
-         * don’t have assignments of a single workspace to different
-         * outputs */
-        struct Workspace_Assignment *assignment;
-        bool duplicate = false;
-        TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
-            if (strcasecmp(assignment->name, ws_name) == 0) {
-                ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
-                     ws_name);
-                assignment->output = $4;
-                duplicate = true;
-            }
-        }
-        if (!duplicate) {
-            assignment = scalloc(sizeof(struct Workspace_Assignment));
-            assignment->name = ws_name;
-            assignment->output = $4;
-            TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
-        }
-    }
-    | TOKWORKSPACE NUMBER workspace_name
-    {
-        int ws_num = $2;
-        if (ws_num < 1) {
-            DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
-        } else {
-            DLOG("workspace name to: %s\n", $3);
-#if 0
-            if ($<string>3 != NULL) {
-                    workspace_set_name(workspace_get(ws_num - 1), $<string>3);
-                    free($<string>3);
-            }
-#endif
-        }
-    }
-    ;
-
-optional_workspace_name:
-    /* empty */          { $$ = NULL; }
-    | workspace_name     { $$ = $1; }
-    ;
-
-workspace_name:
-    QUOTEDSTRING         { $$ = $1; }
-    | STR                { $$ = $1; }
-    | WORD               { $$ = $1; }
-    ;
-
-assign:
-    TOKASSIGN window_class STR
-    {
-        /* This is the old, deprecated form of assignments. It’s provided for
-         * compatibility in version (4.1, 4.2, 4.3) and will be removed
-         * afterwards. It triggers an i3-nagbar warning starting from 4.1. */
-        ELOG("You are using the old assign syntax (without criteria). "
-             "Please see the User's Guide for the new syntax and fix "
-             "your config file.\n");
-        context->has_warnings = true;
-        printf("assignment of %s to *%s*\n", $2, $3);
-        char *workspace = $3;
-        char *criteria = $2;
-
-        Assignment *assignment = scalloc(sizeof(Assignment));
-        Match *match = &(assignment->match);
-        match_init(match);
-
-        char *separator = NULL;
-        if ((separator = strchr(criteria, '/')) != NULL) {
-            *(separator++) = '\0';
-            char *pattern;
-            sasprintf(&pattern, "(?i)%s", separator);
-            match->title = regex_new(pattern);
-            free(pattern);
-            printf("  title = %s\n", separator);
-        }
-        if (*criteria != '\0') {
-            char *pattern;
-            sasprintf(&pattern, "(?i)%s", criteria);
-            match->class = regex_new(pattern);
-            free(pattern);
-            printf("  class = %s\n", criteria);
-        }
-        free(criteria);
-
-        /* Compatibility with older versions: If the assignment target starts
-         * with ~, we create the equivalent of:
-         *
-         * for_window [class="foo"] floating enable
-         */
-        if (*workspace == '~') {
-            workspace++;
-            if (*workspace == '\0') {
-                /* This assignment was *only* for floating */
-                assignment->type = A_COMMAND;
-                assignment->dest.command = sstrdup("floating enable");
-                TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
-                break;
-            } else {
-                /* Create a new assignment and continue afterwards */
-                Assignment *floating = scalloc(sizeof(Assignment));
-                match_copy(&(floating->match), match);
-                floating->type = A_COMMAND;
-                floating->dest.command = sstrdup("floating enable");
-                TAILQ_INSERT_TAIL(&assignments, floating, assignments);
-            }
-        }
-
-        assignment->type = A_TO_WORKSPACE;
-        assignment->dest.workspace = workspace;
-        TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
-    }
-    | TOKASSIGN match STR
-    {
-        if (match_is_empty(&current_match)) {
-            ELOG("Match is empty, ignoring this assignment\n");
-            break;
-        }
-        printf("new assignment, using above criteria, to workspace %s\n", $3);
-        Assignment *assignment = scalloc(sizeof(Assignment));
-        assignment->match = current_match;
-        assignment->type = A_TO_WORKSPACE;
-        assignment->dest.workspace = $3;
-        TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
-    }
-    ;
-
-window_class:
-    QUOTEDSTRING
-    | STR_NG
-    ;
-
-ipcsocket:
-    TOKIPCSOCKET STR
-    {
-        config.ipc_socket_path = $2;
-    }
-    ;
-
-restart_state:
-    TOKRESTARTSTATE STR
-    {
-        config.restart_state_path = $2;
-    }
-    ;
-
-exec:
-    TOKEXEC optional_no_startup_id STR
-    {
-        struct Autostart *new = smalloc(sizeof(struct Autostart));
-        new->command = $3;
-        new->no_startup_id = $2;
-        TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
-    }
-    ;
-
-exec_always:
-    TOKEXEC_ALWAYS optional_no_startup_id STR
-    {
-        struct Autostart *new = smalloc(sizeof(struct Autostart));
-        new->command = $3;
-        new->no_startup_id = $2;
-        TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
-    }
-    ;
-
-optional_border_width:
-    /* empty */ { $$ = 2; } // 2 pixels is the default value for any type of border
-    | NUMBER  { $$ = $1; }
-    ;
-
-optional_no_startup_id:
-    /* empty */ { $$ = false; }
-    | TOK_NO_STARTUP_ID  { $$ = true; }
-    ;
-
-terminal:
-    TOKTERMINAL STR
-    {
-        ELOG("The terminal option is DEPRECATED and has no effect. "
-            "Please remove it from your configuration file.\n");
-    }
-    ;
-
-font:
-    TOKFONT STR
-    {
-        config.font = load_font($2, true);
-        set_font(&config.font);
-        printf("font %s\n", $2);
-        FREE(font_pattern);
-        font_pattern = $2;
-    }
-    ;
-
-single_color:
-    TOKSINGLECOLOR colorpixel
-    {
-        uint32_t *dest = $1;
-        *dest = $2;
-    }
-    ;
-
-color:
-    TOKCOLOR colorpixel colorpixel colorpixel
-    {
-        struct Colortriple *dest = $1;
-
-        dest->border = $2;
-        dest->background = $3;
-        dest->text = $4;
-    }
-    | TOKCOLOR colorpixel colorpixel colorpixel colorpixel
-    {
-        struct Colortriple *dest = $1;
-
-        dest->border = $2;
-        dest->background = $3;
-        dest->text = $4;
-        dest->indicator = $5;
-    }
-    ;
-
-colorpixel:
-    HEXCOLOR
-    {
-        $$ = get_colorpixel($1);
-        free($1);
-    }
-    ;
-
-
-binding_modifiers:
-    /* NULL */                               { $$ = 0; }
-    | binding_modifier
-    | binding_modifiers '+' binding_modifier { $$ = $1 | $3; }
-    | binding_modifiers '+'                  { $$ = $1; }
-    ;
-
-binding_modifier:
-    MODIFIER        { $$ = $1; }
-    | TOKCONTROL    { $$ = BIND_CONTROL; }
-    | TOKSHIFT      { $$ = BIND_SHIFT; }
-    ;
-
-popup_during_fullscreen:
-    TOK_POPUP_DURING_FULLSCREEN popup_setting
-    {
-        DLOG("popup_during_fullscreen setting: %d\n", $2);
-        config.popup_during_fullscreen = $2;
-    }
-    ;
-
-popup_setting:
-    TOK_IGNORE              { $$ = PDF_IGNORE; }
-    | TOK_LEAVE_FULLSCREEN  { $$ = PDF_LEAVE_FULLSCREEN; }
-    ;
index 2ca8387c91e7387ec0835672c4a5866caa28c89e..323c5ae49f061cd4857c595c9a875c0b36bb491d 100644 (file)
@@ -1602,8 +1602,8 @@ void cmd_exit(I3_CMD) {
  */
 void cmd_reload(I3_CMD) {
     LOG("reloading\n");
-    kill_configerror_nagbar(false);
-    kill_commanderror_nagbar(false);
+    kill_nagbar(&config_error_nagbar_pid, false);
+    kill_nagbar(&command_error_nagbar_pid, false);
     load_configuration(conn, NULL, true);
     x_set_i3_atoms();
     /* Send an IPC event just in case the ws names have changed */
index ad5025a92057aa10aa16d4916065f42fcf884183..70c7d7f5a6cf8f7d07638f87376e61d9501afb18 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -1573,6 +1573,10 @@ char *con_get_tree_representation(Con *con) {
         buf = sstrdup("T[");
     else if (con->layout == L_STACKED)
         buf = sstrdup("S[");
+    else {
+        ELOG("BUG: Code not updated to account for new layout type\n");
+        assert(false);
+    }
 
     /* 2) append representation of children */
     Con *child;
index e5470a8f62c97553f12720f031695be36f1739e8..595aa435da66805e4baa9ea1f7f2b51ff0eace9c 100644 (file)
@@ -6,8 +6,8 @@
  * i3 - an improved dynamic tiling window manager
  * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
  *
- * config.c: Configuration file (calling the parser (src/cfgparse.y) with the
- *           correct path, switching key bindings mode).
+ * config.c: Configuration file (calling the parser (src/config_parser.c) with
+ *           the correct path, switching key bindings mode).
  *
  */
 #include "all.h"
index 80d436b1d44a522fd97d38b353fe682e91b09113..7391896bf4ef391023b5e17834ead257085f92f7 100644 (file)
 #include <unistd.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "all.h"
 
 #define y(x, ...) yajl_gen_ ## x (command_output.json_gen, ##__VA_ARGS__)
 #define ystr(str) yajl_gen_string(command_output.json_gen, (unsigned char*)str, strlen(str))
 
+#ifndef TEST_PARSER
+pid_t config_error_nagbar_pid = -1;
+static struct context *context;
+#endif
+
 /*******************************************************************************
  * The data structures used for parsing. Essentially the current state and a
  * list of tokens for that state.
@@ -649,4 +658,439 @@ int main(int argc, char *argv[]) {
     context.filename = "<stdin>";
     parse_config(argv[1], &context);
 }
+
+#else
+
+/*
+ * Goes through each line of buf (separated by \n) and checks for statements /
+ * commands which only occur in i3 v4 configuration files. If it finds any, it
+ * returns version 4, otherwise it returns version 3.
+ *
+ */
+static int detect_version(char *buf) {
+    char *walk = buf;
+    char *line = buf;
+    while (*walk != '\0') {
+        if (*walk != '\n') {
+            walk++;
+            continue;
+        }
+
+        /* check for some v4-only statements */
+        if (strncasecmp(line, "bindcode", strlen("bindcode")) == 0 ||
+            strncasecmp(line, "force_focus_wrapping", strlen("force_focus_wrapping")) == 0 ||
+            strncasecmp(line, "# i3 config file (v4)", strlen("# i3 config file (v4)")) == 0 ||
+            strncasecmp(line, "workspace_layout", strlen("workspace_layout")) == 0) {
+            printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
+            return 4;
+        }
+
+        /* if this is a bind statement, we can check the command */
+        if (strncasecmp(line, "bind", strlen("bind")) == 0) {
+            char *bind = strchr(line, ' ');
+            if (bind == NULL)
+                goto next;
+            while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
+                bind++;
+            if (*bind == '\0')
+                goto next;
+            if ((bind = strchr(bind, ' ')) == NULL)
+                goto next;
+            while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
+                bind++;
+            if (*bind == '\0')
+                goto next;
+            if (strncasecmp(bind, "layout", strlen("layout")) == 0 ||
+                strncasecmp(bind, "floating", strlen("floating")) == 0 ||
+                strncasecmp(bind, "workspace", strlen("workspace")) == 0 ||
+                strncasecmp(bind, "focus left", strlen("focus left")) == 0 ||
+                strncasecmp(bind, "focus right", strlen("focus right")) == 0 ||
+                strncasecmp(bind, "focus up", strlen("focus up")) == 0 ||
+                strncasecmp(bind, "focus down", strlen("focus down")) == 0 ||
+                strncasecmp(bind, "border normal", strlen("border normal")) == 0 ||
+                strncasecmp(bind, "border 1pixel", strlen("border 1pixel")) == 0 ||
+                strncasecmp(bind, "border pixel", strlen("border pixel")) == 0 ||
+                strncasecmp(bind, "border borderless", strlen("border borderless")) == 0 ||
+                strncasecmp(bind, "--no-startup-id", strlen("--no-startup-id")) == 0 ||
+                strncasecmp(bind, "bar", strlen("bar")) == 0) {
+                printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
+                return 4;
+            }
+        }
+
+next:
+        /* advance to the next line */
+        walk++;
+        line = walk;
+    }
+
+    return 3;
+}
+
+/*
+ * Calls i3-migrate-config-to-v4 to migrate a configuration file (input
+ * buffer).
+ *
+ * Returns the converted config file or NULL if there was an error (for
+ * example the script could not be found in $PATH or the i3 executable’s
+ * directory).
+ *
+ */
+static char *migrate_config(char *input, off_t size) {
+    int writepipe[2];
+    int readpipe[2];
+
+    if (pipe(writepipe) != 0 ||
+        pipe(readpipe) != 0) {
+        warn("migrate_config: Could not create pipes");
+        return NULL;
+    }
+
+    pid_t pid = fork();
+    if (pid == -1) {
+        warn("Could not fork()");
+        return NULL;
+    }
+
+    /* child */
+    if (pid == 0) {
+        /* close writing end of writepipe, connect reading side to stdin */
+        close(writepipe[1]);
+        dup2(writepipe[0], 0);
+
+        /* close reading end of readpipe, connect writing side to stdout */
+        close(readpipe[0]);
+        dup2(readpipe[1], 1);
+
+        static char *argv[] = {
+            NULL, /* will be replaced by the executable path */
+            NULL
+        };
+        exec_i3_utility("i3-migrate-config-to-v4", argv);
+    }
+
+    /* parent */
+
+    /* close reading end of the writepipe (connected to the script’s stdin) */
+    close(writepipe[0]);
+
+    /* write the whole config file to the pipe, the script will read everything
+     * immediately */
+    int written = 0;
+    int ret;
+    while (written < size) {
+        if ((ret = write(writepipe[1], input + written, size - written)) < 0) {
+            warn("Could not write to pipe");
+            return NULL;
+        }
+        written += ret;
+    }
+    close(writepipe[1]);
+
+    /* close writing end of the readpipe (connected to the script’s stdout) */
+    close(readpipe[1]);
+
+    /* read the script’s output */
+    int conv_size = 65535;
+    char *converted = malloc(conv_size);
+    int read_bytes = 0;
+    do {
+        if (read_bytes == conv_size) {
+            conv_size += 65535;
+            converted = realloc(converted, conv_size);
+        }
+        ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
+        if (ret == -1) {
+            warn("Cannot read from pipe");
+            FREE(converted);
+            return NULL;
+        }
+        read_bytes += ret;
+    } while (ret > 0);
+
+    /* get the returncode */
+    int status;
+    wait(&status);
+    if (!WIFEXITED(status)) {
+        fprintf(stderr, "Child did not terminate normally, using old config file (will lead to broken behaviour)\n");
+        return NULL;
+    }
+
+    int returncode = WEXITSTATUS(status);
+    if (returncode != 0) {
+        fprintf(stderr, "Migration process exit code was != 0\n");
+        if (returncode == 2) {
+            fprintf(stderr, "could not start the migration script\n");
+            /* TODO: script was not found. tell the user to fix his system or create a v4 config */
+        } else if (returncode == 1) {
+            fprintf(stderr, "This already was a v4 config. Please add the following line to your config file:\n");
+            fprintf(stderr, "# i3 config file (v4)\n");
+            /* TODO: nag the user with a message to include a hint for i3 in his config file */
+        }
+        return NULL;
+    }
+
+    return converted;
+}
+
+/*
+ * Checks for duplicate key bindings (the same keycode or keysym is configured
+ * more than once). If a duplicate binding is found, a message is printed to
+ * stderr and the has_errors variable is set to true, which will start
+ * i3-nagbar.
+ *
+ */
+static void check_for_duplicate_bindings(struct context *context) {
+    Binding *bind, *current;
+    TAILQ_FOREACH(current, bindings, bindings) {
+        TAILQ_FOREACH(bind, bindings, bindings) {
+            /* Abort when we reach the current keybinding, only check the
+             * bindings before */
+            if (bind == current)
+                break;
+
+            /* Check if one is using keysym while the other is using bindsym.
+             * If so, skip. */
+            /* XXX: It should be checked at a later place (when translating the
+             * keysym to keycodes) if there are any duplicates */
+            if ((bind->symbol == NULL && current->symbol != NULL) ||
+                (bind->symbol != NULL && current->symbol == NULL))
+                continue;
+
+            /* If bind is NULL, current has to be NULL, too (see above).
+             * If the keycodes differ, it can't be a duplicate. */
+            if (bind->symbol != NULL &&
+                strcasecmp(bind->symbol, current->symbol) != 0)
+                continue;
+
+            /* Check if the keycodes or modifiers are different. If so, they
+             * can't be duplicate */
+            if (bind->keycode != current->keycode ||
+                bind->mods != current->mods ||
+                bind->release != current->release)
+                continue;
+
+            context->has_errors = true;
+            if (current->keycode != 0) {
+                ELOG("Duplicate keybinding in config file:\n  modmask %d with keycode %d, command \"%s\"\n",
+                     current->mods, current->keycode, current->command);
+            } else {
+                ELOG("Duplicate keybinding in config file:\n  modmask %d with keysym %s, command \"%s\"\n",
+                     current->mods, current->symbol, current->command);
+            }
+        }
+    }
+}
+
+/*
+ * Parses the given file by first replacing the variables, then calling
+ * parse_config and possibly launching i3-nagbar.
+ *
+ */
+void parse_file(const char *f) {
+    SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
+    int fd, ret, read_bytes = 0;
+    struct stat stbuf;
+    char *buf;
+    FILE *fstr;
+    char buffer[1026], key[512], value[512];
+
+    if ((fd = open(f, O_RDONLY)) == -1)
+        die("Could not open configuration file: %s\n", strerror(errno));
+
+    if (fstat(fd, &stbuf) == -1)
+        die("Could not fstat file: %s\n", strerror(errno));
+
+    buf = scalloc((stbuf.st_size + 1) * sizeof(char));
+    while (read_bytes < stbuf.st_size) {
+        if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
+            die("Could not read(): %s\n", strerror(errno));
+        read_bytes += ret;
+    }
+
+    if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
+        die("Could not lseek: %s\n", strerror(errno));
+
+    if ((fstr = fdopen(fd, "r")) == NULL)
+        die("Could not fdopen: %s\n", strerror(errno));
+
+    while (!feof(fstr)) {
+        if (fgets(buffer, 1024, fstr) == NULL) {
+            if (feof(fstr))
+                break;
+            die("Could not read configuration file\n");
+        }
+
+        /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
+        if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
+            key[0] == '#' || strlen(key) < 3)
+            continue;
+
+        if (strcasecmp(key, "set") == 0) {
+            if (value[0] != '$') {
+                ELOG("Malformed variable assignment, name has to start with $\n");
+                continue;
+            }
+
+            /* get key/value for this variable */
+            char *v_key = value, *v_value;
+            if (strstr(value, " ") == NULL && strstr(value, "\t") == NULL) {
+                ELOG("Malformed variable assignment, need a value\n");
+                continue;
+            }
+
+            if (!(v_value = strstr(value, " ")))
+                v_value = strstr(value, "\t");
+
+            *(v_value++) = '\0';
+            while (*v_value == '\t' || *v_value == ' ')
+                v_value++;
+
+            struct Variable *new = scalloc(sizeof(struct Variable));
+            new->key = sstrdup(v_key);
+            new->value = sstrdup(v_value);
+            SLIST_INSERT_HEAD(&variables, new, variables);
+            DLOG("Got new variable %s = %s\n", v_key, v_value);
+            continue;
+        }
+    }
+    fclose(fstr);
+
+    /* For every custom variable, see how often it occurs in the file and
+     * how much extra bytes it requires when replaced. */
+    struct Variable *current, *nearest;
+    int extra_bytes = 0;
+    /* We need to copy the buffer because we need to invalidate the
+     * variables (otherwise we will count them twice, which is bad when
+     * 'extra' is negative) */
+    char *bufcopy = sstrdup(buf);
+    SLIST_FOREACH(current, &variables, variables) {
+        int extra = (strlen(current->value) - strlen(current->key));
+        char *next;
+        for (next = bufcopy;
+             next < (bufcopy + stbuf.st_size) &&
+             (next = strcasestr(next, current->key)) != NULL;
+             next += strlen(current->key)) {
+            *next = '_';
+            extra_bytes += extra;
+        }
+    }
+    FREE(bufcopy);
+
+    /* Then, allocate a new buffer and copy the file over to the new one,
+     * but replace occurences of our variables */
+    char *walk = buf, *destwalk;
+    char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
+    destwalk = new;
+    while (walk < (buf + stbuf.st_size)) {
+        /* Find the next variable */
+        SLIST_FOREACH(current, &variables, variables)
+            current->next_match = strcasestr(walk, current->key);
+        nearest = NULL;
+        int distance = stbuf.st_size;
+        SLIST_FOREACH(current, &variables, variables) {
+            if (current->next_match == NULL)
+                continue;
+            if ((current->next_match - walk) < distance) {
+                distance = (current->next_match - walk);
+                nearest = current;
+            }
+        }
+        if (nearest == NULL) {
+            /* If there are no more variables, we just copy the rest */
+            strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
+            destwalk += (buf + stbuf.st_size) - walk;
+            *destwalk = '\0';
+            break;
+        } else {
+            /* Copy until the next variable, then copy its value */
+            strncpy(destwalk, walk, distance);
+            strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
+            walk += distance + strlen(nearest->key);
+            destwalk += distance + strlen(nearest->value);
+        }
+    }
+
+    /* analyze the string to find out whether this is an old config file (3.x)
+     * or a new config file (4.x). If it’s old, we run the converter script. */
+    int version = detect_version(buf);
+    if (version == 3) {
+        /* We need to convert this v3 configuration */
+        char *converted = migrate_config(new, stbuf.st_size);
+        if (converted != NULL) {
+            ELOG("\n");
+            ELOG("****************************************************************\n");
+            ELOG("NOTE: Automatically converted configuration file from v3 to v4.\n");
+            ELOG("\n");
+            ELOG("Please convert your config file to v4. You can use this command:\n");
+            ELOG("    mv %s %s.O\n", f, f);
+            ELOG("    i3-migrate-config-to-v4 %s.O > %s\n", f, f);
+            ELOG("****************************************************************\n");
+            ELOG("\n");
+            free(new);
+            new = converted;
+        } else {
+            printf("\n");
+            printf("**********************************************************************\n");
+            printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
+            printf("was not correctly installed on your system?\n");
+            printf("**********************************************************************\n");
+            printf("\n");
+        }
+    }
+
+
+    context = scalloc(sizeof(struct context));
+    context->filename = f;
+
+    struct ConfigResult *config_output = parse_config(new, context);
+    yajl_gen_free(config_output->json_gen);
+
+    check_for_duplicate_bindings(context);
+
+    if (context->has_errors || context->has_warnings) {
+        ELOG("FYI: You are using i3 version " I3_VERSION "\n");
+        if (version == 3)
+            ELOG("Please convert your configfile first, then fix any remaining errors (see above).\n");
+
+        char *editaction,
+             *pageraction;
+        sasprintf(&editaction, "i3-sensible-editor \"%s\" && i3-msg reload\n", f);
+        sasprintf(&pageraction, "i3-sensible-pager \"%s\"\n", errorfilename);
+        char *argv[] = {
+            NULL, /* will be replaced by the executable path */
+            "-t",
+            (context->has_errors ? "error" : "warning"),
+            "-m",
+            (context->has_errors ?
+             "You have an error in your i3 config file!" :
+             "Your config is outdated. Please fix the warnings to make sure everything works."),
+            "-b",
+            "edit config",
+            editaction,
+            (errorfilename ? "-b" : NULL),
+            (context->has_errors ? "show errors" : "show warnings"),
+            pageraction,
+            NULL
+        };
+
+        start_nagbar(&config_error_nagbar_pid, argv);
+        free(editaction);
+        free(pageraction);
+    }
+
+    FREE(context->line_copy);
+    free(context);
+    free(new);
+    free(buf);
+
+    while (!SLIST_EMPTY(&variables)) {
+        current = SLIST_FIRST(&variables);
+        FREE(current->key);
+        FREE(current->value);
+        SLIST_REMOVE_HEAD(&variables, variables);
+        FREE(current);
+    }
+}
+
 #endif
index ac1a622c6ece3e90bf91b027304576177406652f..0901ae07b4cfea2cb391e5e5cd89899605e2c386 100644 (file)
@@ -101,15 +101,18 @@ void display_running_version(void) {
         err(EXIT_FAILURE, "IPC: write()");
 
     uint32_t reply_length;
+    uint32_t reply_type;
     uint8_t *reply;
     int ret;
-    if ((ret = ipc_recv_message(sockfd, I3_IPC_MESSAGE_TYPE_GET_VERSION,
-                                &reply_length, &reply)) != 0) {
+    if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
         if (ret == -1)
             err(EXIT_FAILURE, "IPC: read()");
         exit(EXIT_FAILURE);
     }
 
+    if (reply_type != I3_IPC_MESSAGE_TYPE_GET_VERSION)
+        errx(EXIT_FAILURE, "Got reply type %d, but expected %d (GET_VERSION)", reply_type, I3_IPC_MESSAGE_TYPE_GET_VERSION);
+
 #if YAJL_MAJOR >= 2
     yajl_handle handle = yajl_alloc(&version_callbacks, NULL, NULL);
 #else
index 1bfcce562b9af13084889cb07be8cd5a138aeb3d..4f2d870eb00a9e3ee84503a1f9e6bd0178307e45 100644 (file)
@@ -339,7 +339,7 @@ static void handle_configure_request(xcb_configure_request_event_t *event) {
 
     if (fullscreen != con && con_is_floating(con) && con_is_leaf(con)) {
         /* find the height for the decorations */
-        int deco_height = config.font.height + 5;
+        int deco_height = con->deco_rect.height;
         /* we actually need to apply the size/position changes to the *parent*
          * container */
         Rect bsr = con_border_style_rect(con);
index dedf4e27b91831f2f1dd0274473acb3a6ac146c9..38099fb52b88e3d794089656d2eddd8d459bef2f 100644 (file)
--- a/src/i3.mk
+++ b/src/i3.mk
@@ -2,7 +2,6 @@ ALL_TARGETS += i3
 INSTALL_TARGETS += install-i3
 CLEAN_TARGETS += clean-i3
 
-i3_SOURCES_GENERATED  = src/cfgparse.tab.c src/cfgparse.yy.c
 i3_SOURCES           := $(filter-out $(i3_SOURCES_GENERATED),$(wildcard src/*.c))
 i3_HEADERS_CMDPARSER := $(wildcard include/GENERATED_*.h)
 i3_HEADERS           := $(filter-out $(i3_HEADERS_CMDPARSER),$(wildcard include/*.h))
@@ -37,14 +36,6 @@ src/%.o: src/%.c $(i3_HEADERS_DEP)
        echo "[i3] CC $<"
        $(CC) $(I3_CPPFLAGS) $(XCB_CPPFLAGS) $(CPPFLAGS) $(i3_CFLAGS) $(I3_CFLAGS) $(CFLAGS) $(PCH_FLAGS) -c -o $@ ${canonical_path}/$<
 
-src/cfgparse.yy.c: src/cfgparse.l src/cfgparse.tab.o $(i3_HEADERS_DEP)
-       echo "[i3] LEX $<"
-       $(FLEX) -i -o $@ ${canonical_path}/$<
-
-src/cfgparse.tab.c: src/cfgparse.y $(i3_HEADERS_DEP)
-       echo "[i3] YACC $<"
-       $(BISON) --debug --verbose -b $(basename $< .y) -d ${canonical_path}/$<
-
 # This target compiles the command parser twice:
 # Once with -DTEST_PARSER, creating a stand-alone executable used for tests,
 # and once as an object file for i3.
@@ -96,4 +87,4 @@ install-i3: i3
 
 clean-i3:
        echo "[i3] Clean"
-       rm -f $(i3_OBJECTS) $(i3_SOURCES_GENERATED) $(i3_HEADERS_CMDPARSER) include/loglevels.h loglevels.tmp include/all.h.pch i3-command-parser.stamp i3-config-parser.stamp i3 src/*.gcno src/cfgparse.{output,dot,tab.h,y.o} src/cmdparse.*
+       rm -f $(i3_OBJECTS) $(i3_SOURCES_GENERATED) $(i3_HEADERS_CMDPARSER) include/loglevels.h loglevels.tmp include/all.h.pch i3-command-parser.stamp i3-config-parser.stamp i3 src/*.gcno src/cfgparse.* src/cmdparse.*
index 17c15b9e91e723a128794e218694b8196e3475e9..2379ba5fae2a072b19c49780973b6a6c4978d0c0 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -802,18 +802,16 @@ handler_t handlers[8] = {
  *
  */
 static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
-    char buf[2048];
-    int n = read(w->fd, buf, sizeof(buf));
-
-    /* On error or an empty message, we close the connection */
-    if (n <= 0) {
-#if 0
-        /* FIXME: I get these when closing a client socket,
-         * therefore we just treat them as an error. Is this
-         * correct? */
-        if (errno == EAGAIN || errno == EWOULDBLOCK)
-                return;
-#endif
+    uint32_t message_type;
+    uint32_t message_length;
+    uint8_t *message;
+
+    int ret = ipc_recv_message(w->fd, &message_type, &message_length, &message);
+    /* EOF or other error */
+    if (ret < 0) {
+        /* Was this a spurious read? See ev(3) */
+        if (ret == -1 && errno == EAGAIN)
+            return;
 
         /* If not, there was some kind of error. We don’t bother
          * and close the connection */
@@ -841,51 +839,11 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
         return;
     }
 
-    /* Terminate the message correctly */
-    buf[n] = '\0';
-
-    /* Check if the message starts with the i3 IPC magic code */
-    if (n < strlen(I3_IPC_MAGIC)) {
-        DLOG("IPC: message too short, ignoring\n");
-        return;
-    }
-
-    if (strncmp(buf, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)) != 0) {
-        DLOG("IPC: message does not start with the IPC magic\n");
-        return;
-    }
-
-    uint8_t *message = (uint8_t*)buf;
-    while (n > 0) {
-        DLOG("IPC: n = %d\n", n);
-        message += strlen(I3_IPC_MAGIC);
-        n -= strlen(I3_IPC_MAGIC);
-
-        /* The next 32 bit after the magic are the message size */
-        uint32_t message_size;
-        memcpy(&message_size, (uint32_t*)message, sizeof(uint32_t));
-        message += sizeof(uint32_t);
-        n -= sizeof(uint32_t);
-
-        if (message_size > n) {
-            DLOG("IPC: Either the message size was wrong or the message was not read completely, dropping\n");
-            return;
-        }
-
-        /* The last 32 bits of the header are the message type */
-        uint32_t message_type;
-        memcpy(&message_type, (uint32_t*)message, sizeof(uint32_t));
-        message += sizeof(uint32_t);
-        n -= sizeof(uint32_t);
-
-        if (message_type >= (sizeof(handlers) / sizeof(handler_t)))
-            DLOG("Unhandled message type: %d\n", message_type);
-        else {
-            handler_t h = handlers[message_type];
-            h(w->fd, message, n, message_size, message_type);
-        }
-        n -= message_size;
-        message += message_size;
+    if (message_type >= (sizeof(handlers) / sizeof(handler_t)))
+        DLOG("Unhandled message type: %d\n", message_type);
+    else {
+        handler_t h = handlers[message_type];
+        h(w->fd, message, 0, message_length, message_type);
     }
 }
 
index 5919e64c7d06ab2baac84f2af36c6b7163dfad17..ca5c3a0bbd7ab105d56e34ad36ce93c164dc2d60 100644 (file)
@@ -19,169 +19,7 @@ static int current_nesting_level;
 static bool parse_error_key;
 static bool command_failed;
 
-/* XXX: I don’t want to touch too much of the nagbar code at once, but we
- * should refactor this with src/cfgparse.y into a clean generic nagbar
- * interface. It might come in handy in other situations within i3, too. */
-static char *pager_script_path;
-static pid_t nagbar_pid = -1;
-
-/*
- * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
- * it exited (or could not be started, depending on the exit code).
- *
- */
-static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
-    ev_child_stop(EV_A_ watcher);
-
-    if (unlink(pager_script_path) != 0)
-        warn("Could not delete temporary i3-nagbar script %s", pager_script_path);
-
-    if (!WIFEXITED(watcher->rstatus)) {
-        fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
-        return;
-    }
-
-    int exitcode = WEXITSTATUS(watcher->rstatus);
-    printf("i3-nagbar process exited with status %d\n", exitcode);
-    if (exitcode == 2) {
-        fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
-    }
-
-    nagbar_pid = -1;
-}
-
-/* We need ev >= 4 for the following code. Since it is not *that* important (it
- * only makes sure that there are no i3-nagbar instances left behind) we still
- * support old systems with libev 3. */
-#if EV_VERSION_MAJOR >= 4
-/*
- * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
- * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
- *
- */
-static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
-    if (nagbar_pid != -1) {
-        LOG("Sending SIGKILL (%d) to i3-nagbar with PID %d\n", SIGKILL, nagbar_pid);
-        kill(nagbar_pid, SIGKILL);
-    }
-}
-#endif
-
-/*
- * Writes the given command as a shell script to path.
- * Returns true unless something went wrong.
- *
- */
-static bool write_nagbar_script(const char *path, const char *command) {
-    int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IXUSR);
-    if (fd == -1) {
-        warn("Could not create temporary script to store the nagbar command");
-        return false;
-    }
-    write(fd, "#!/bin/sh\n", strlen("#!/bin/sh\n"));
-    write(fd, command, strlen(command));
-    close(fd);
-    return true;
-}
-
-/*
- * Starts an i3-nagbar process which alerts the user that his configuration
- * file contains one or more errors. Also offers two buttons: One to launch an
- * $EDITOR on the config file and another one to launch a $PAGER on the error
- * logfile.
- *
- */
-static void start_commanderror_nagbar(void) {
-    if (nagbar_pid != -1) {
-        DLOG("i3-nagbar for command error already running, not starting again.\n");
-        return;
-    }
-
-    DLOG("Starting i3-nagbar due to command error\n");
-
-    /* We need to create a custom script containing our actual command
-     * since not every terminal emulator which is contained in
-     * i3-sensible-terminal supports -e with multiple arguments (and not
-     * all of them support -e with one quoted argument either).
-     *
-     * NB: The paths need to be unique, that is, don’t assume users close
-     * their nagbars at any point in time (and they still need to work).
-     * */
-    pager_script_path = get_process_filename("nagbar-cfgerror-pager");
-
-    nagbar_pid = fork();
-    if (nagbar_pid == -1) {
-        warn("Could not fork()");
-        return;
-    }
-
-    /* child */
-    if (nagbar_pid == 0) {
-        char *pager_command;
-        sasprintf(&pager_command, "i3-sensible-pager \"%s\"\n", errorfilename);
-        if (!write_nagbar_script(pager_script_path, pager_command))
-            return;
-
-        char *pageraction;
-        sasprintf(&pageraction, "i3-sensible-terminal -e \"%s\"", pager_script_path);
-        char *argv[] = {
-            NULL, /* will be replaced by the executable path */
-            "-t",
-            "error",
-            "-m",
-            "The configured command for this shortcut could not be run successfully.",
-            "-b",
-            "show errors",
-            pageraction,
-            NULL
-        };
-        exec_i3_utility("i3-nagbar", argv);
-    }
-
-    /* parent */
-    /* install a child watcher */
-    ev_child *child = smalloc(sizeof(ev_child));
-    ev_child_init(child, &nagbar_exited, nagbar_pid, 0);
-    ev_child_start(main_loop, child);
-
-/* We need ev >= 4 for the following code. Since it is not *that* important (it
- * only makes sure that there are no i3-nagbar instances left behind) we still
- * support old systems with libev 3. */
-#if EV_VERSION_MAJOR >= 4
-    /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
-     * still running) */
-    ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
-    ev_cleanup_init(cleanup, nagbar_cleanup);
-    ev_cleanup_start(main_loop, cleanup);
-#endif
-}
-
-/*
- * Kills the commanderror i3-nagbar process, if any.
- *
- * Called when reloading/restarting, since the user probably fixed his wrong
- * keybindings.
- *
- * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
- * ev is assumed to handle it (reloading).
- *
- */
-void kill_commanderror_nagbar(bool wait_for_it) {
-    if (nagbar_pid == -1)
-        return;
-
-    if (kill(nagbar_pid, SIGTERM) == -1)
-        warn("kill(configerror_nagbar) failed");
-
-    if (!wait_for_it)
-        return;
-
-    /* When restarting, we don’t enter the ev main loop anymore and after the
-     * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
-     * for us and we would end up with a <defunct> process. Therefore we
-     * waitpid() here. */
-    waitpid(nagbar_pid, NULL, 0);
-}
+pid_t command_error_nagbar_pid = -1;
 
 static int json_boolean(void *ctx, int boolval) {
     DLOG("Got bool: %d, parse_error_key %d, nesting_level %d\n", boolval, parse_error_key, current_nesting_level);
@@ -302,8 +140,23 @@ void handle_key_press(xcb_key_press_event_t *event) {
     if (state != yajl_status_ok) {
         ELOG("Could not parse my own reply. That's weird. reply is %.*s\n", (int)length, reply);
     } else {
-        if (command_failed)
-            start_commanderror_nagbar();
+        if (command_failed) {
+            char *pageraction;
+            sasprintf(&pageraction, "i3-sensible-pager \"%s\"\n", errorfilename);
+            char *argv[] = {
+                NULL, /* will be replaced by the executable path */
+                "-t",
+                "error",
+                "-m",
+                "The configured command for this shortcut could not be run successfully.",
+                "-b",
+                "show errors",
+                pageraction,
+                NULL
+            };
+            start_nagbar(&command_error_nagbar_pid, argv);
+            free(pageraction);
+        }
     }
 
     yajl_free(handle);
index cb6767fbb761b8d2bd61a87e8ddfe191c88b1f31..a49241dda9d4ec39737c397caeed73ac830e727b 100644 (file)
@@ -374,8 +374,7 @@ int main(int argc, char *argv[]) {
                     fake_outputs = sstrdup(optarg);
                     break;
                 } else if (strcmp(long_options[option_index].name, "force-old-config-parser-v4.4-only") == 0) {
-                    LOG("FORCING OLD CONFIG PARSER!\n");
-                    force_old_config_parser = true;
+                    ELOG("You are passing --force-old-config-parser-v4.4-only, but that flag was removed by now.\n");
                     break;
                 }
                 /* fall-through */
@@ -461,14 +460,16 @@ int main(int argc, char *argv[]) {
             err(EXIT_FAILURE, "IPC: write()");
 
         uint32_t reply_length;
+        uint32_t reply_type;
         uint8_t *reply;
         int ret;
-        if ((ret = ipc_recv_message(sockfd, I3_IPC_MESSAGE_TYPE_COMMAND,
-                                    &reply_length, &reply)) != 0) {
+        if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
             if (ret == -1)
                 err(EXIT_FAILURE, "IPC: read()");
             return 1;
         }
+        if (reply_type != I3_IPC_MESSAGE_TYPE_COMMAND)
+            errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_MESSAGE_TYPE_COMMAND);
         printf("%.*s\n", reply_length, reply);
         return 0;
     }
@@ -542,17 +543,8 @@ int main(int argc, char *argv[]) {
             config.ipc_socket_path = sstrdup(config.ipc_socket_path);
     }
 
-    uint32_t mask = XCB_CW_EVENT_MASK;
-    uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
-                          XCB_EVENT_MASK_BUTTON_PRESS |
-                          XCB_EVENT_MASK_STRUCTURE_NOTIFY |         /* when the user adds a screen (e.g. video
-                                                                           projector), the root window gets a
-                                                                           ConfigureNotify */
-                          XCB_EVENT_MASK_POINTER_MOTION |
-                          XCB_EVENT_MASK_PROPERTY_CHANGE |
-                          XCB_EVENT_MASK_ENTER_WINDOW };
     xcb_void_cookie_t cookie;
-    cookie = xcb_change_window_attributes_checked(conn, root, mask, values);
+    cookie = xcb_change_window_attributes_checked(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ ROOT_EVENT_MASK });
     check_error(conn, cookie, "Another window manager seems to be running");
 
     xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(conn, gcookie, NULL);
@@ -603,13 +595,13 @@ int main(int argc, char *argv[]) {
         int i1;
         if (!XkbQueryExtension(xkbdpy,&i1,&xkb_event_base,&errBase,&major,&minor)) {
             fprintf(stderr, "XKB not supported by X-server\n");
-            return 1;
+           xkb_supported = false;
         }
         /* end of ugliness */
 
-        if (!XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
-                             XkbMapNotifyMask | XkbStateNotifyMask,
-                             XkbMapNotifyMask | XkbStateNotifyMask)) {
+        if (xkb_supported && !XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
+                                              XkbMapNotifyMask | XkbStateNotifyMask,
+                                              XkbMapNotifyMask | XkbStateNotifyMask)) {
             fprintf(stderr, "Could not set XKB event mask\n");
             return 1;
         }
index 2d102eebae0bbff9a826a02f4e0df4ccb47c48b8..ff7fdc6d09bae81c641cbc66162667995f00ec91 100644 (file)
@@ -64,8 +64,12 @@ void restore_geometry(void) {
                                 con->rect.x, con->rect.y);
         }
 
+    /* Strictly speaking, this line doesn’t really belong here, but since we
+     * are syncing, let’s un-register as a window manager first */
+    xcb_change_window_attributes(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT });
+
     /* Make sure our changes reach the X server, we restart/exit now */
-    xcb_flush(conn);
+    xcb_aux_sync(conn);
 }
 
 /*
index 1216241b49af184a8e2ef45cdf997768b6f54af0..476d1ca8e1fa4bc909e856e7ee88d3e79517d06c 100644 (file)
@@ -202,6 +202,7 @@ void render_con(Con *con, bool render_fullscreen) {
 
     /* precalculate the sizes to be able to correct rounding errors */
     int sizes[children];
+    memset(sizes, 0, children*sizeof(int));
     if ((con->layout == L_SPLITH || con->layout == L_SPLITV) && children > 0) {
         assert(!TAILQ_EMPTY(&con->nodes_head));
         Con *child;
index 7b30909554040360233317dd7f70bdeedb9ff28b..c38e63b177d4542f4c7fcc12df8c02b1c943ef89 100644 (file)
@@ -94,6 +94,24 @@ void scratchpad_show(Con *con) {
         con_toggle_fullscreen(focused, CF_OUTPUT);
     }
 
+    /* If this was 'scratchpad show' without criteria, we check if there is a
+     * visible scratchpad window on another workspace. In this case we move it
+     * to the current workspace. */
+    Con *walk_con;
+    Con *focused_ws = con_get_workspace(focused);
+    TAILQ_FOREACH(walk_con, &all_cons, all_cons) {
+        Con *walk_ws = con_get_workspace(walk_con);
+        if (walk_ws &&
+            !con_is_internal(walk_ws) && focused_ws != walk_ws &&
+            (floating = con_inside_floating(walk_con)) &&
+            floating->scratchpad_state != SCRATCHPAD_NONE) {
+            DLOG("Found a visible scratchpad window on another workspace,\n");
+            DLOG("moving it to this workspace: con = %p\n", walk_con);
+            con_move_to_workspace(walk_con, focused_ws, true, false);
+            return;
+        }
+    }
+
     /* If this was 'scratchpad show' without criteria, we check if the
      * currently focused window is a scratchpad window and should be hidden
      * again. */
index 7a5fb9f010081c7a24f28fbac1673b0471a4583b..c398ee1d36f6722a35fe4b77fb569ea3350d86d4 100644 (file)
@@ -251,15 +251,28 @@ bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool
         free(con->window);
     }
 
-    /* kill the X11 part of this container */
-    x_con_kill(con);
+    Con *ws = con_get_workspace(con);
+
+    /* Figure out which container to focus next before detaching 'con'. */
+    if (con_is_floating(con)) {
+        if (con == focused) {
+            DLOG("This is the focused container, i need to find another one to focus. I start looking at ws = %p\n", ws);
+            next = con_next_focused(parent);
+
+            dont_kill_parent = true;
+            DLOG("Alright, focusing %p\n", next);
+        } else {
+            next = NULL;
+        }
+    }
 
+    /* Detach the container so that it will not be rendered anymore. */
     con_detach(con);
 
     /* disable urgency timer, if needed */
     if (con->urgency_timer != NULL) {
         DLOG("Removing urgency timer of con %p\n", con);
-        workspace_update_urgent_flag(con_get_workspace(con));
+        workspace_update_urgent_flag(ws);
         ev_timer_stop(main_loop, con->urgency_timer);
         FREE(con->urgency_timer);
     }
@@ -270,21 +283,24 @@ bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool
         con_fix_percent(parent);
     }
 
+    /* Render the tree so that the surrounding containers take up the space
+     * which 'con' does no longer occupy. If we don’t render here, there will
+     * be a gap in our containers and that could trigger an EnterNotify for an
+     * underlying container, see ticket #660.
+     *
+     * Rendering has to be avoided when dont_kill_parent is set (when
+     * tree_close calls itself recursively) because the tree is in a
+     * non-renderable state during that time. */
+    if (!dont_kill_parent)
+        tree_render();
+
+    /* kill the X11 part of this container */
+    x_con_kill(con);
+
     if (con_is_floating(con)) {
-        Con *ws = con_get_workspace(con);
         DLOG("Container was floating, killing floating container\n");
         tree_close(parent, DONT_KILL_WINDOW, false, (con == focused));
         DLOG("parent container killed\n");
-        if (con == focused) {
-            DLOG("This is the focused container, i need to find another one to focus. I start looking at ws = %p\n", ws);
-            /* go down the focus stack as far as possible */
-            next = con_descend_focused(ws);
-
-            dont_kill_parent = true;
-            DLOG("Alright, focusing %p\n", next);
-        } else {
-            next = NULL;
-        }
     }
 
     free(con->name);
index e623ce81b822e0121d2641665145b2da2402f05d..e2df3ca9c0c9456f606d237bd90ce18d7a744793 100644 (file)
@@ -183,44 +183,6 @@ static char **append_argument(char **original, char *argument) {
     return result;
 }
 
-/*
- * Returns the name of a temporary file with the specified prefix.
- *
- */
-char *get_process_filename(const char *prefix) {
-    /* dir stores the directory path for this and all subsequent calls so that
-     * we only create a temporary directory once per i3 instance. */
-    static char *dir = NULL;
-    if (dir == NULL) {
-        /* Check if XDG_RUNTIME_DIR is set. If so, we use XDG_RUNTIME_DIR/i3 */
-        if ((dir = getenv("XDG_RUNTIME_DIR"))) {
-            char *tmp;
-            sasprintf(&tmp, "%s/i3", dir);
-            dir = tmp;
-            if (!path_exists(dir)) {
-                if (mkdir(dir, 0700) == -1) {
-                    perror("mkdir()");
-                    return NULL;
-                }
-            }
-        } else {
-            /* If not, we create a (secure) temp directory using the template
-             * /tmp/i3-<user>.XXXXXX */
-            struct passwd *pw = getpwuid(getuid());
-            const char *username = pw ? pw->pw_name : "unknown";
-            sasprintf(&dir, "/tmp/i3-%s.XXXXXX", username);
-            /* mkdtemp modifies dir */
-            if (mkdtemp(dir) == NULL) {
-                perror("mkdtemp()");
-                return NULL;
-            }
-        }
-    }
-    char *filename;
-    sasprintf(&filename, "%s/%s.%d", dir, prefix, getpid());
-    return filename;
-}
-
 #define y(x, ...) yajl_gen_ ## x (gen, ##__VA_ARGS__)
 #define ystr(str) yajl_gen_string(gen, (unsigned char*)str, strlen(str))
 
@@ -304,8 +266,8 @@ char *store_restart_layout(void) {
 void i3_restart(bool forget_layout) {
     char *restart_filename = forget_layout ? NULL : store_restart_layout();
 
-    kill_configerror_nagbar(true);
-    kill_commanderror_nagbar(true);
+    kill_nagbar(&config_error_nagbar_pid, true);
+    kill_nagbar(&command_error_nagbar_pid, true);
 
     restore_geometry();
 
@@ -382,3 +344,103 @@ void *memmem(const void *l, size_t l_len, const void *s, size_t s_len) {
 }
 
 #endif
+
+/*
+ * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
+ * it exited (or could not be started, depending on the exit code).
+ *
+ */
+static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
+    ev_child_stop(EV_A_ watcher);
+
+    if (!WIFEXITED(watcher->rstatus)) {
+        ELOG("ERROR: i3-nagbar did not exit normally.\n");
+        return;
+    }
+
+    int exitcode = WEXITSTATUS(watcher->rstatus);
+    DLOG("i3-nagbar process exited with status %d\n", exitcode);
+    if (exitcode == 2) {
+        ELOG("ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
+    }
+
+    *((pid_t*)watcher->data) = -1;
+}
+
+/*
+ * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
+ * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
+ *
+ */
+static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
+    pid_t *nagbar_pid = (pid_t*)watcher->data;
+    if (*nagbar_pid != -1) {
+        LOG("Sending SIGKILL (%d) to i3-nagbar with PID %d\n", SIGKILL, *nagbar_pid);
+        kill(*nagbar_pid, SIGKILL);
+    }
+}
+
+/*
+ * Starts an i3-nagbar instance with the given parameters. Takes care of
+ * handling SIGCHLD and killing i3-nagbar when i3 exits.
+ *
+ * The resulting PID will be stored in *nagbar_pid and can be used with
+ * kill_nagbar() to kill the bar later on.
+ *
+ */
+void start_nagbar(pid_t *nagbar_pid, char *argv[]) {
+    if (*nagbar_pid != -1) {
+        DLOG("i3-nagbar already running (PID %d), not starting again.\n", *nagbar_pid);
+        return;
+    }
+
+    *nagbar_pid = fork();
+    if (*nagbar_pid == -1) {
+        warn("Could not fork()");
+        return;
+    }
+
+    /* child */
+    if (*nagbar_pid == 0)
+        exec_i3_utility("i3-nagbar", argv);
+
+    DLOG("Starting i3-nagbar with PID %d\n", *nagbar_pid);
+
+    /* parent */
+    /* install a child watcher */
+    ev_child *child = smalloc(sizeof(ev_child));
+    ev_child_init(child, &nagbar_exited, *nagbar_pid, 0);
+    child->data = nagbar_pid;
+    ev_child_start(main_loop, child);
+
+    /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
+     * still running) */
+    ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
+    ev_cleanup_init(cleanup, nagbar_cleanup);
+    cleanup->data = nagbar_pid;
+    ev_cleanup_start(main_loop, cleanup);
+}
+
+/*
+ * Kills the i3-nagbar process, if *nagbar_pid != -1.
+ *
+ * If wait_for_it is set (restarting i3), this function will waitpid(),
+ * otherwise, ev is assumed to handle it (reloading).
+ *
+ */
+void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it) {
+    if (*nagbar_pid == -1)
+        return;
+
+    if (kill(*nagbar_pid, SIGTERM) == -1)
+        warn("kill(configerror_nagbar) failed");
+
+    if (!wait_for_it)
+        return;
+
+    /* When restarting, we don’t enter the ev main loop anymore and after the
+     * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
+     * for us and we would end up with a <defunct> process. Therefore we
+     * waitpid() here. */
+    waitpid(*nagbar_pid, NULL, 0);
+}
index 4ccf421c09f1b429e34152b175e395558b77269e..5a0913bfcc77852c1084fe2f2908097000714b8c 100644 (file)
@@ -397,7 +397,7 @@ static void _workspace_show(Con *workspace) {
      * the corresponding workspace is cleaned up.
      * NOTE: Internal cons such as __i3_scratch (when a scratchpad window is
      * focused) are skipped, see bug #868. */
-    if (current && !(current->name[0] == '_' && current->name[1] == '_')) {
+    if (current && !con_is_internal(current)) {
         FREE(previous_workspace_name);
         if (current) {
             previous_workspace_name = sstrdup(current->name);
diff --git a/src/x.c b/src/x.c
index 8f0ae37d538984efcf59dd5395d7f94c016c2ac2..fcb63c35bdef19765540800ecb610011ced1941a 100644 (file)
--- a/src/x.c
+++ b/src/x.c
@@ -465,7 +465,7 @@ void x_draw_decoration(Con *con) {
     xcb_rectangle_t drect = { con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height };
     xcb_poly_fill_rectangle(conn, parent->pixmap, parent->pm_gc, 1, &drect);
 
-    /* 5: draw two unconnected lines in border color */
+    /* 5: draw two unconnected horizontal lines in border color */
     xcb_change_gc(conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
     Rect *dr = &(con->deco_rect);
     int deco_diff_l = 2;
@@ -539,19 +539,21 @@ after_title:
      * the right border again after rendering the text (and the unconnected
      * lines in border color). */
 
-    /* Draw a separator line after every tab (except the last one), so that
-     * tabs can be easily distinguished. */
-    if (parent->layout == L_TABBED && TAILQ_NEXT(con, nodes) != NULL) {
+    /* Draw a 1px separator line before and after every tab, so that tabs can
+     * be easily distinguished. */
+    if (parent->layout == L_TABBED) {
         xcb_change_gc(conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
     } else {
         xcb_change_gc(conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
     }
-    xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, parent->pixmap, parent->pm_gc, 4,
+    xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, parent->pixmap, parent->pm_gc, 6,
                   (xcb_point_t[]){
+                      { dr->x + dr->width, dr->y },
+                      { dr->x + dr->width, dr->y + dr->height },
                       { dr->x + dr->width - 1, dr->y },
                       { dr->x + dr->width - 1, dr->y + dr->height },
-                      { dr->x + dr->width - 2, dr->y },
-                      { dr->x + dr->width - 2, dr->y + dr->height }
+                      { dr->x, dr->y + dr->height },
+                      { dr->x, dr->y },
                   });
 
     xcb_change_gc(conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
@@ -918,8 +920,12 @@ void x_push_changes(Con *con) {
 
             Output *current = get_output_containing(pointerreply->root_x, pointerreply->root_y);
             Output *target = get_output_containing(mid_x, mid_y);
-            if (current != target)
+            if (current != target) {
+                /* Ignore MotionNotify events generated by warping */
+                xcb_change_window_attributes(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT });
                 xcb_warp_pointer(conn, XCB_NONE, root, 0, 0, 0, 0, mid_x, mid_y);
+                xcb_change_window_attributes(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ ROOT_EVENT_MASK });
+            }
         }
         warp_to = NULL;
     }
@@ -955,7 +961,7 @@ void x_push_changes(Con *con) {
             }
 
             if (set_focus) {
-                DLOG("Updating focus (focused: %p / %s)\n", focused, focused->name);
+                DLOG("Updating focus (focused: %p / %s) to X11 window 0x%08x\n", focused, focused->name, to_focus);
                 /* We remove XCB_EVENT_MASK_FOCUS_CHANGE from the event mask to get
                  * no focus change events for our own focus changes. We only want
                  * these generated by the clients. */
index b812180270aaa75866fa7ca3cdb930218cde0cc8..560dd4c3de0bc21f6c4126b7f152ef4b424d89fb 100755 (executable)
@@ -1,10 +1,11 @@
 #!/usr/bin/env perl
 # vim:ts=4:sw=4:expandtab
-# © 2010-2011 Michael Stapelberg and contributors
+# © 2010-2012 Michael Stapelberg and contributors
 package complete_run;
 use strict;
 use warnings;
 use v5.10;
+use utf8;
 # the following are modules which ship with Perl (>= 5.10):
 use Pod::Usage;
 use Cwd qw(abs_path);
@@ -29,6 +30,9 @@ use AnyEvent::I3 qw(:all);
 use X11::XCB::Connection;
 use JSON::XS; # AnyEvent::I3 depends on it, too.
 
+binmode STDOUT, ':utf8';
+binmode STDERR, ':utf8';
+
 # Close superfluous file descriptors which were passed by running in a VIM
 # subshell or situations like that.
 AnyEvent::Util::close_all_fds_except(0, 1, 2);
@@ -78,7 +82,7 @@ my @binaries = qw(
                );
 
 foreach my $binary (@binaries) {
-    die "$binary executable not found" unless -e $binary;
+    die "$binary executable not found, did you run “make”?" unless -e $binary;
     die "$binary is not an executable" unless -x $binary;
 }
 
index 2849301e9b2ccb01007e8254a04fb2a9e878922c..c2546158267fa2b5a49bf75579b936fea7e9dd7a 100755 (executable)
@@ -79,6 +79,7 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
 fake-outputs 1024x768+0+0,1024x768+1024+0
 EOT
 
+my $pid = launch_with_config($config);
 
 
 exit_gracefully($pid);
index d09910397a81de46e0cbd50938177967bdbebd51..6367488a3b4b6495fe872c356049e7b10bba31d5 100644 (file)
@@ -23,6 +23,7 @@ my $i3 = i3(get_socket_path());
 # We move the pointer out of our way to avoid a bug where the focus will
 # be set to the window under the cursor
 $x->root->warp_pointer(0, 0);
+sync_with_i3;
 
 sub move_workspace_test {
     my ($movecmd) = @_;
index 6af13fa566eccb4ae7e658b41f99f07845f22a56..1cee1ebbeeed77f0b498c5c5d3b23e5fb0e02905 100644 (file)
@@ -98,6 +98,7 @@ my $workspaces = get_workspace_names;
 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
 
 $window = open_special;
+sync_with_i3;
 
 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
@@ -157,6 +158,7 @@ $workspaces = get_workspace_names;
 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
 
 $window = open_special;
+sync_with_i3;
 
 my $content = get_ws($tmp);
 ok(@{$content->{nodes}} == 0, 'no tiling cons');
@@ -205,6 +207,7 @@ is(@docked, 0, 'one dock client yet');
 $window = open_special(
     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
 );
+sync_with_i3;
 
 $content = get_ws($tmp);
 ok(@{$content->{nodes}} == 0, 'no tiling cons');
index f27ec0e4b625225796663d521597fdda550933be..aff3fe3a61c6f9711b26a5bf0c6056ae1f495f63 100644 (file)
@@ -73,6 +73,7 @@ ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
 ok(get_ws($tmp)->{focused}, 'current workspace focused');
 
 my $window = open_special;
+sync_with_i3;
 
 ok(@{get_ws_content($tmp)} == 0, 'special window not on current workspace');
 ok(@{get_ws_content('targetws')} == 1, 'special window on targetws');
index 7160399d3387fddc66bfd62caa6746a2de343b0f..ee285ff74a6087e0108f9f9dca177f1b723352b9 100644 (file)
@@ -21,6 +21,10 @@ use i3test;
 use POSIX qw(mkfifo);
 use File::Temp qw(:POSIX);
 
+SKIP: {
+
+    skip "X11::XCB too old (need >= 0.07)", 24 if $X11::XCB::VERSION < 0.07;
+
 use ExtUtils::PkgConfig;
 
 # setup dependency on libstartup-notification using pkg-config
@@ -42,16 +46,10 @@ static SnDisplay *sndisplay;
 static SnLauncheeContext *ctx;
 static xcb_connection_t *conn;
 
-// TODO: this should use $x
-void init_ctx() {
-    int screen;
-    if ((conn = xcb_connect(NULL, &screen)) == NULL ||
-        xcb_connection_has_error(conn))
-        errx(1, "x11 conn failed");
-
-    printf("screen = %d\n", screen);
+void init_ctx(void *connptr) {
+    conn = (xcb_connection_t*)connptr;
     sndisplay = sn_xcb_display_new(conn, NULL, NULL);
-    ctx = sn_launchee_context_new_from_environment(sndisplay, screen);
+    ctx = sn_launchee_context_new_from_environment(sndisplay, 0);
 }
 
 const char *get_startup_id() {
@@ -101,7 +99,7 @@ isnt($startup_id, '', 'startup_id not empty');
 $ENV{DESKTOP_STARTUP_ID} = $startup_id;
 
 # Create a new libstartup-notification launchee context
-init_ctx();
+init_ctx($x->get_xcb_conn());
 
 # Make sure the context was set up successfully
 is(get_startup_id(), $startup_id, 'libstartup-notification returns the same id');
@@ -211,5 +209,6 @@ close($fh);
 unlink($tmp);
 
 is($startup_id, '', 'startup_id empty');
+}
 
 done_testing;
index dafe51e07efca0827f8b7831e9b253a702baa997..598f2b360e6a05a27f7b4ef520347ccd1a605395 100644 (file)
@@ -216,39 +216,6 @@ cmd 'scratchpad show';
 
 isnt(get_focused($tmp), $fresh_id, 'focus changed');
 
-################################################################################
-# 7: Verify that using scratchpad show with criteria works as expected:
-# When matching a scratchpad window which is visible, it should hide it.
-# When matching a scratchpad window which is on __i3_scratch, it should show it.
-# When matching a non-scratchpad window, it should be a no-op.
-################################################################################
-
-# Verify that using 'scratchpad show' without any matching windows is a no-op.
-$old_focus = get_focused($tmp);
-
-cmd '[title="nomatch"] scratchpad show';
-
-is(get_focused($tmp), $old_focus, 'non-matching criteria have no effect');
-
-# Verify that we can use criteria to show a scratchpad window.
-cmd '[title="scratch-match"] scratchpad show';
-
-my $scratch_focus = get_focused($tmp);
-isnt($scratch_focus, $old_focus, 'matching criteria works');
-
-cmd '[title="scratch-match"] scratchpad show';
-
-isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');
-is(get_focused($tmp), $old_focus, 'focus restored');
-
-# Verify that we cannot use criteria to show a non-scratchpad window.
-my $tmp2 = fresh_workspace;
-my $non_scratch_window = open_window(name => 'non-scratch');
-cmd "workspace $tmp";
-is(get_focused($tmp), $old_focus, 'focus still ok');
-cmd '[title="non-match"] scratchpad show';
-is(get_focused($tmp), $old_focus, 'focus unchanged');
-
 ################################################################################
 # 8: Show it, move it around, hide it. Verify that the position is retained
 # when showing it again.
@@ -369,6 +336,70 @@ verify_scratchpad_move_multiple_win(0);
 $tmp = fresh_workspace;
 verify_scratchpad_move_multiple_win(1);
 
+################################################################################
+# 12: open a scratchpad window on a workspace, switch to another workspace and
+# call 'scratchpad show' again
+################################################################################
+
+sub verify_scratchpad_move_with_visible_scratch_con {
+    my ($first, $second, $cross_output) = @_;
+
+    cmd "workspace $first";
+
+    my $window1 = open_window;
+    cmd 'move scratchpad';
+
+    my $window2 = open_window;
+    cmd 'move scratchpad';
+
+    # this should bring up window 1
+    cmd 'scratchpad show';
+
+    my $ws = get_ws($first);
+    is(scalar @{$ws->{floating_nodes}}, 1, 'one floating node on ws1');
+    is($x->input_focus, $window1->id, "showed the correct scratchpad window1");
+
+    # this should bring up window 1
+    cmd "workspace $second";
+    cmd 'scratchpad show';
+    is($x->input_focus, $window1->id, "showed the correct scratchpad window1");
+
+    my $ws2 = get_ws($second);
+    is(scalar @{$ws2->{floating_nodes}}, 1, 'one floating node on ws2');
+    unless ($cross_output) {
+        ok(!workspace_exists($first), 'ws1 was empty and therefore closed');
+    } else {
+        $ws = get_ws($first);
+        is(scalar @{$ws->{floating_nodes}}, 0, 'ws1 has no floating nodes');
+    }
+
+    # hide window 1 again
+    cmd 'move scratchpad';
+
+    # this should bring up window 2
+    cmd "workspace $first";
+    cmd 'scratchpad show';
+    is($x->input_focus, $window2->id, "showed the correct scratchpad window");
+}
+
+# let's clear the scratchpad first
+sub clear_scratchpad {
+    while (scalar @{get_ws('__i3_scratch')->{floating_nodes}}) {
+        cmd 'scratchpad show';
+        cmd 'kill';
+    }
+}
+
+clear_scratchpad;
+is (scalar @{get_ws('__i3_scratch')->{floating_nodes}}, 0, "scratchpad is empty");
+
+my ($first, $second);
+$first = fresh_workspace;
+$second = fresh_workspace;
+
+verify_scratchpad_move_with_visible_scratch_con($first, $second, 0);
+does_i3_live;
+
 # TODO: make i3bar display *something* when a window on the scratchpad has the urgency hint
 
 done_testing;
index 0d3d226808a782479c90bf0906431d5c194bb442..debbb0a21487742c4971f9e4e23f4dcee69929e1 100644 (file)
@@ -146,6 +146,7 @@ $window = open_floating_window(rect => [ 0, 0, 100, 100 ]);
 cmd 'border none';
 cmd 'resize shrink height 80px or 80ppt';
 cmd 'resize shrink width 80px or 80ppt';
+sync_with_i3;
 $rect = $window->rect;
 is($rect->{width}, 60, 'width = 60');
 is($rect->{height}, 50, 'height = 50');
@@ -170,6 +171,7 @@ $window = open_floating_window(rect => [ 200, 200, 50, 50 ]);
 cmd 'border none';
 cmd 'resize grow height 100px or 100ppt';
 cmd 'resize grow width 100px or 100ppt';
+sync_with_i3;
 $rect = $window->rect;
 is($rect->{width}, 100, 'width = 100');
 is($rect->{height}, 100, 'height = 100');
@@ -177,6 +179,7 @@ is($rect->{height}, 100, 'height = 100');
 my $old_x = $rect->{x};
 my $old_y = $rect->{y};
 cmd 'resize grow up 10px or 10ppt';
+sync_with_i3;
 $rect = $window->rect;
 is($rect->{x}, $old_x, 'window did not move when trying to resize');
 is($rect->{y}, $old_y, 'window did not move when trying to resize');
diff --git a/testcases/t/202-scratchpad-criteria.t b/testcases/t/202-scratchpad-criteria.t
new file mode 100644 (file)
index 0000000..2603f65
--- /dev/null
@@ -0,0 +1,58 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+#
+# Please read the following documents before working on tests:
+# • http://build.i3wm.org/docs/testsuite.html
+#   (or docs/testsuite)
+#
+# • http://build.i3wm.org/docs/lib-i3test.html
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
+#
+# • http://build.i3wm.org/docs/ipc.html
+#   (or docs/ipc)
+#
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
+#   (unless you are already familiar with Perl)
+#
+# Verifies that using criteria to address scratchpad windows works.
+use i3test;
+
+################################################################################
+# Verify that using scratchpad show with criteria works as expected:
+# When matching a scratchpad window which is visible, it should hide it.
+# When matching a scratchpad window which is on __i3_scratch, it should show it.
+# When matching a non-scratchpad window, it should be a no-op.
+################################################################################
+
+my $tmp = fresh_workspace;
+
+my $third_window = open_window(name => 'scratch-match');
+cmd 'move scratchpad';
+
+# Verify that using 'scratchpad show' without any matching windows is a no-op.
+my $old_focus = get_focused($tmp);
+
+cmd '[title="nomatch"] scratchpad show';
+
+is(get_focused($tmp), $old_focus, 'non-matching criteria have no effect');
+
+# Verify that we can use criteria to show a scratchpad window.
+cmd '[title="scratch-match"] scratchpad show';
+
+my $scratch_focus = get_focused($tmp);
+isnt($scratch_focus, $old_focus, 'matching criteria works');
+
+cmd '[title="scratch-match"] scratchpad show';
+
+isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');
+is(get_focused($tmp), $old_focus, 'focus restored');
+
+# Verify that we cannot use criteria to show a non-scratchpad window.
+my $tmp2 = fresh_workspace;
+my $non_scratch_window = open_window(name => 'non-scratch');
+cmd "workspace $tmp";
+is(get_focused($tmp), $old_focus, 'focus still ok');
+cmd '[title="non-match"] scratchpad show';
+is(get_focused($tmp), $old_focus, 'focus unchanged');
+
+done_testing;
index 20d4fd2ba1a0abca0c694c874f2de8db6678f355..c79643e3592705bb98441b7ee5ee10f56691c740 100644 (file)
@@ -61,8 +61,18 @@ open_window;
 # output 2: 2
 cmd 'workspace 1';
 cmd 'workspace next';
+# We need to sync after changing focus to a different output to wait for the
+# EnterNotify to be processed, otherwise it will be processed at some point
+# later in time and mess up our subsequent tests.
+sync_with_i3;
+
 is(focused_ws, '2', 'workspace 2 focused');
 cmd 'workspace next';
+# We need to sync after changing focus to a different output to wait for the
+# EnterNotify to be processed, otherwise it will be processed at some point
+# later in time and mess up our subsequent tests.
+sync_with_i3;
+
 is(focused_ws, '5', 'workspace 5 focused');
 
 ################################################################################
@@ -81,11 +91,9 @@ cmd 'workspace prev_on_output';
 is(focused_ws, '1', 'workspace 1 focused');
 
 cmd 'workspace 2';
-
-# XXX: This is to avoid EnterNotifies changing the focus. Not sure why they
-# appear sometimes in the first place. Only happens when running the full
-# testsuite.
-$x->root->warp_pointer(1025, 0);
+# We need to sync after changing focus to a different output to wait for the
+# EnterNotify to be processed, otherwise it will be processed at some point
+# later in time and mess up our subsequent tests.
 sync_with_i3;
 
 cmd 'workspace prev_on_output';
index 7f68a2d50abe0c20063e25794cbb0d7f58de4895..2c6fd396ff5471e0e55c0faee59152978ee81b44 100644 (file)
@@ -39,22 +39,22 @@ cmd 'floating toggle';
 
 # Focus screen 1
 $x->root->warp_pointer(1025, 0);
-my $s1_ws = fresh_workspace;
 sync_with_i3;
+my $s1_ws = fresh_workspace;
 
 my $fourth = open_window;
 
 # Focus screen 2
 $x->root->warp_pointer(0, 769);
-my $s2_ws = fresh_workspace;
 sync_with_i3;
+my $s2_ws = fresh_workspace;
 
 my $fifth = open_window;
 
 # Focus screen 3
 $x->root->warp_pointer(1025, 769);
-my $s3_ws = fresh_workspace;
 sync_with_i3;
+my $s3_ws = fresh_workspace;
 
 my $sixth = open_window;
 my $seventh = open_window;