Merge pull request #1994 from Airblader/bug-1992

Make pango markup in mode names optional with a flag.
This commit is contained in:
Michael Stapelberg
2015-10-13 12:08:42 -07:00
15 changed files with 90 additions and 42 deletions

View File

@ -27,7 +27,7 @@ const char *DEFAULT_BINDING_MODE = "default";
* 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 */
@ -39,6 +39,7 @@ static struct Mode *mode_from_name(const char *name) {
/* 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);
@ -54,7 +55,7 @@ static struct Mode *mode_from_name(const char *name) {
*/
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);
@ -91,7 +92,7 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
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;
@ -437,7 +438,8 @@ void switch_mode(const char *new_mode) {
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);

View File

@ -108,7 +108,7 @@ CFGFUN(font, const char *font) {
}
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);
}
/*******************************************************************************
@ -116,12 +116,13 @@ CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, co
******************************************************************************/
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);
@ -129,6 +130,7 @@ CFGFUN(enter_mode, const char *modename) {
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) {

View File

@ -342,7 +342,7 @@ void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, bo
i3String *window_parse_title_format(i3Window *win) {
/* We need to ensure that we only escape the window title if pango
* is used by the current font. */
const bool is_markup = font_is_pango();
const bool pango_markup = font_is_pango();
char *format = win->title_format;
if (format == NULL)
@ -359,19 +359,19 @@ i3String *window_parse_title_format(i3Window *win) {
for (char *walk = format; *walk != '\0'; walk++) {
if (STARTS_WITH(walk, "%title")) {
if (escaped_title == NULL)
escaped_title = win->name == NULL ? "" : i3string_as_utf8(is_markup ? i3string_escape_markup(win->name) : win->name);
escaped_title = win->name == NULL ? "" : i3string_as_utf8(pango_markup ? i3string_escape_markup(win->name) : win->name);
buffer_len = buffer_len - strlen("%title") + strlen(escaped_title);
walk += strlen("%title") - 1;
} else if (STARTS_WITH(walk, "%class")) {
if (escaped_class == NULL)
escaped_class = is_markup ? g_markup_escape_text(win->class_class, -1) : win->class_class;
escaped_class = pango_markup ? g_markup_escape_text(win->class_class, -1) : win->class_class;
buffer_len = buffer_len - strlen("%class") + strlen(escaped_class);
walk += strlen("%class") - 1;
} else if (STARTS_WITH(walk, "%instance")) {
if (escaped_instance == NULL)
escaped_instance = is_markup ? g_markup_escape_text(win->class_instance, -1) : win->class_instance;
escaped_instance = pango_markup ? g_markup_escape_text(win->class_instance, -1) : win->class_instance;
buffer_len = buffer_len - strlen("%instance") + strlen(escaped_instance);
walk += strlen("%instance") - 1;
@ -403,6 +403,6 @@ i3String *window_parse_title_format(i3Window *win) {
*outwalk = '\0';
i3String *formatted = i3string_from_utf8(buffer);
i3string_set_markup(formatted, is_markup);
i3string_set_markup(formatted, pango_markup);
return formatted;
}