│ 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/ │
+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
xmlto,
docbook-xml,
pkg-config,
- libev-dev,
- flex,
- bison,
+ libev-dev (>= 1:4.04),
libyajl-dev,
libpcre3-dev,
libstartup-notification0-dev (>= 0.10),
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
<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 {
</ul>
<br style="clear: both">
<div id="content" class="pod">
-<h1>i3 Perl documentation (testsuite)</h1>
+<h1>i3 Perl documentation</h1>
EOF
);
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]]
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.
+++ /dev/null
-%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();
-}
-
-%%
+++ /dev/null
-%{
-/*
- * 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); }
- ;
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)
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.*
#include <sys/stat.h>
#include <fcntl.h>
#include <glob.h>
+#include <assert.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
#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 */
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;
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.
*
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);
# 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);
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';
'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 {
# 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 '#';
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.
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;
}
}
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})) {
=head1 VERSION
-Version 1.2
+Version 1.3
=head1 AUTHOR
/* 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;
}
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);
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");
*/
#include <stdio.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <getopt.h>
#include <limits.h>
+#include <fcntl.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
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 */
}
*
* 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
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
*/
void kill_configerror_nagbar(bool wait_for_it);
-/* prototype for src/cfgparse.y */
-void parse_file(const char *f);
-
#endif
#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.
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
/**
* 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 {
#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().
*/
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
*/
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
#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
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
--- /dev/null
+/*
+ * 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;
+}
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'
->
'+'
->
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'
->
'+'
->
+++ /dev/null
-/*
- * 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();
-}
-
-%%
+++ /dev/null
-%{
-/*
- * 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(¤t_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(¤t_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, ¤t_bar, sizeof(Barconfig));
- TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
-
- memset(¤t_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(¤t_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; }
- ;
*/
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 */
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;
* 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"
#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.
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
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))
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.
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.*
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);
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);
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 */
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);
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);
}
/*
/* 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;
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. */
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);
}
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);
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))
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();
}
#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);
+}
* 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);
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;
* 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 });
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;
}
}
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. */
#!/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);
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);
);
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;
}
fake-outputs 1024x768+0+0,1024x768+1024+0
EOT
+my $pid = launch_with_config($config);
exit_gracefully($pid);
# 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) = @_;
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');
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');
$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');
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');
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
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() {
$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');
unlink($tmp);
is($startup_id, '', 'startup_id empty');
+}
done_testing;
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.
$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;
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');
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');
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');
--- /dev/null
+#!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;
# 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');
################################################################################
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';
# 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;