This event consists of a single serialized map containing a property
+change (string)+ which holds the name of current mode in use. The name
is the same as specified in config when creating a mode. The default
-mode is simply named default.
+mode is simply named default. It contains a second property, +pango_markup+, which
+defines whether pango markup shall be used for displaying this mode.
*Example:*
---------------------------
-{ "change": "default" }
+{
+ "change": "default",
+ "pango_markup": true
+}
---------------------------
=== window event
struct mode_json_params {
char *json;
char *cur_key;
+ char *name;
+ bool pango_markup;
mode *mode;
};
struct mode_json_params *params = (struct mode_json_params *)params_;
if (!strcmp(params->cur_key, "change")) {
- /* Save the name */
- params->mode->name = i3string_from_markup_with_length((const char *)val, len);
- /* Save its rendered width */
- params->mode->width = predict_text_width(params->mode->name);
+ char *copy = smalloc(sizeof(const unsigned char) * (len + 1));
+ strncpy(copy, (const char *)val, len);
+ copy[len] = '\0';
- DLOG("Got mode change: %s\n", i3string_as_utf8(params->mode->name));
+ params->name = copy;
FREE(params->cur_key);
+ return 1;
+ }
+
+ FREE(params->cur_key);
+ return 0;
+}
+
+/*
+ * Parse a boolean.
+ *
+ */
+static int mode_boolean_cb(void *params_, int val) {
+ struct mode_json_params *params = (struct mode_json_params *)params_;
+ if (strcmp(params->cur_key, "pango_markup") == 0) {
+ DLOG("Setting pango_markup to %d.\n", val);
+ params->pango_markup = val;
+
+ FREE(params->cur_key);
return 1;
}
+ FREE(params->cur_key);
return 0;
}
return 1;
}
+static int mode_end_map_cb(void *params_) {
+ struct mode_json_params *params = (struct mode_json_params *)params_;
+
+ /* Save the name */
+ params->mode->name = i3string_from_utf8(params->name);
+ i3string_set_markup(params->mode->name, params->pango_markup);
+ /* Save its rendered width */
+ params->mode->width = predict_text_width(params->mode->name);
+
+ DLOG("Got mode change: %s\n", i3string_as_utf8(params->mode->name));
+ FREE(params->cur_key);
+
+ return 1;
+}
+
/* A datastructure to pass all these callbacks to yajl */
static yajl_callbacks mode_callbacks = {
.yajl_string = mode_string_cb,
+ .yajl_boolean = mode_boolean_cb,
.yajl_map_key = mode_map_key_cb,
+ .yajl_end_map = mode_end_map_cb,
};
/*
*/
Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code,
const char *release, const char *border, const char *whole_window,
- const char *command, const char *mode);
+ const char *command, const char *mode, bool pango_markup);
/**
* Grab the bound keys (tell X to send us keypress events for those keycodes)
*/
struct Mode {
char *name;
+ bool pango_markup;
struct bindings_head *bindings;
SLIST_ENTRY(Mode) modes;
CFGFUN(workspace, const char *workspace, const char *output);
CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command);
-CFGFUN(enter_mode, const char *mode);
+CFGFUN(enter_mode, const char *pango_markup, const char *mode);
CFGFUN(mode_binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command);
CFGFUN(bar_font, const char *font);
################################################################################
state MODENAME:
+ pango_markup = '--pango_markup'
+ ->
modename = word
- -> call cfg_enter_mode($modename); MODEBRACE
+ -> call cfg_enter_mode($pango_markup, $modename); MODEBRACE
state MODEBRACE:
end
* the list of modes.
*
*/
-static struct Mode *mode_from_name(const char *name) {
+static struct Mode *mode_from_name(const char *name, bool pango_markup) {
struct Mode *mode;
/* Try to find the mode in the list of modes and return it */
/* If the mode was not found, create a new one */
mode = scalloc(1, sizeof(struct Mode));
mode->name = sstrdup(name);
+ mode->pango_markup = pango_markup;
mode->bindings = scalloc(1, sizeof(struct bindings_head));
TAILQ_INIT(mode->bindings);
SLIST_INSERT_HEAD(&modes, mode, modes);
*/
Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code,
const char *release, const char *border, const char *whole_window,
- const char *command, const char *modename) {
+ const char *command, const char *modename, bool pango_markup) {
Binding *new_binding = scalloc(1, sizeof(Binding));
DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release);
new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
if (group_bits_set > 1)
ELOG("Keybinding has more than one Group specified, but your X server is always in precisely one group. The keybinding can never trigger.\n");
- struct Mode *mode = mode_from_name(modename);
+ struct Mode *mode = mode_from_name(modename, pango_markup);
TAILQ_INSERT_TAIL(mode->bindings, new_binding, bindings);
return new_binding;
grab_all_keys(conn);
char *event_msg;
- sasprintf(&event_msg, "{\"change\":\"%s\"}", mode->name);
+ sasprintf(&event_msg, "{\"change\":\"%s\", \"pango_markup\":%s}",
+ mode->name, (mode->pango_markup ? "true" : "false"));
ipc_send_event("mode", I3_IPC_EVENT_MODE, event_msg);
FREE(event_msg);
}
CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
- configure_binding(bindtype, modifiers, key, release, border, whole_window, command, DEFAULT_BINDING_MODE);
+ configure_binding(bindtype, modifiers, key, release, border, whole_window, command, DEFAULT_BINDING_MODE, false);
}
/*******************************************************************************
******************************************************************************/
static char *current_mode;
+static bool current_mode_pango_markup;
CFGFUN(mode_binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
- configure_binding(bindtype, modifiers, key, release, border, whole_window, command, current_mode);
+ configure_binding(bindtype, modifiers, key, release, border, whole_window, command, current_mode, current_mode_pango_markup);
}
-CFGFUN(enter_mode, const char *modename) {
+CFGFUN(enter_mode, const char *pango_markup, const char *modename) {
if (strcasecmp(modename, DEFAULT_BINDING_MODE) == 0) {
ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE);
exit(1);
DLOG("\t now in mode %s\n", modename);
FREE(current_mode);
current_mode = sstrdup(modename);
+ current_mode_pango_markup = (pango_markup != NULL);
}
CFGFUN(exec, const char *exectype, const char *no_startup_id, const char *command) {
EOT
my $expected = <<'EOT';
-cfg_enter_mode(meh)
+cfg_enter_mode((null), meh)
cfg_mode_binding(bindsym, Mod1,Shift, x, (null), (null), (null), resize grow)
cfg_mode_binding(bindcode, Mod1, 44, (null), (null), (null), resize shrink)
cfg_mode_binding(bindsym, Mod1, x, --release, (null), (null), exec foo)
EOT
$expected = <<'EOT';
-cfg_enter_mode(yo)
+cfg_enter_mode((null), yo)
cfg_mode_binding(bindsym, (null), x, (null), (null), (null), resize shrink left)
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
ERROR: CONFIG: (in file <stdin>)