Skip to content

Commit

Permalink
Fix updating window and icon titles.
Browse files Browse the repository at this point in the history
With the introduction of the TitleFormat and IconTitleFormat styles, a change
of the window or icon name could affect both titles.  The existing code did not
reflect this and a change in the icon name might not be visible in the window
title and vice versa.  The patch cleans up and unifies handling of changes of
the window and icon names and fixes this problem.

Also, the said patch simply set the default IconTitleFormat to the same as
TitleFormat, so the icon name would never be used anyway.  This commit replaces
the default IconTitleFormat with "%i" instead.
  • Loading branch information
domivogt committed Mar 1, 2017
1 parent b57836a commit bc685fd
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 65 deletions.
135 changes: 115 additions & 20 deletions fvwm/add_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ static void setup_name_count(FvwmWindow *fw, Bool is_icon)
return;
}

static char *interpolate_titleformat_name(FvwmWindow *fw, window_style *style,
Bool is_icon)
static char *interpolate_titleformat_name(
int *ret_bits, FvwmWindow *fw, window_style *style, Bool is_icon)
{
char stringbuf[MAX_VISIBLE_NAME_LEN] = "";

Expand All @@ -590,12 +590,15 @@ static char *interpolate_titleformat_name(FvwmWindow *fw, window_style *style,
char win_name_len[MAX_WINDOW_NAME_NUMBER_DIGITS+1];
char w_id[12];

*ret_bits = 0;
if (is_icon)
{
format = (style->flags.has_icon_title_format_string) ?
SGET_ICON_TITLE_FORMAT_STRING(*style) :
DEFAULT_TITLE_FORMAT;
} else {
DEFAULT_ICON_TITLE_FORMAT;
}
else
{
format = (style->flags.has_title_format_string) ?
SGET_TITLE_FORMAT_STRING(*style) :
DEFAULT_TITLE_FORMAT;
Expand All @@ -604,7 +607,11 @@ static char *interpolate_titleformat_name(FvwmWindow *fw, window_style *style,
while (*format)
{
int pos;
for (pos = 0; format[pos] && format[pos] != '%'; pos++);

for (pos = 0; format[pos] && format[pos] != '%'; pos++)
{
/* nothing */
}

strncat(stringbuf, format, pos);
format += pos;
Expand All @@ -616,6 +623,8 @@ static char *interpolate_titleformat_name(FvwmWindow *fw, window_style *style,
switch (*format)
{
case 'n':
/* format contains the window name */
*ret_bits |= 1;
if (strlen(stringbuf) +
strlen(fw->name.name) >
MAX_VISIBLE_NAME_LEN)
Expand Down Expand Up @@ -645,6 +654,8 @@ static char *interpolate_titleformat_name(FvwmWindow *fw, window_style *style,
strcat(stringbuf, fw->class.res_class);
break;
case 'i':
/* format contains icon name */
*ret_bits |= 2;
/* Not every application will have an icon
* name set; don't crash trying to dereference
* this if the name doesn't exist.
Expand Down Expand Up @@ -1420,8 +1431,24 @@ static void destroy_auxiliary_windows(
return;
}

static void broadcast_window_names(FvwmWindow *fw, int changed_names)
{
if (changed_names & 1)
{
EWMH_SetVisibleName(fw, False);
BroadcastWindowIconNames(fw, True, False);
}
if (changed_names & 2)
{
EWMH_SetVisibleName(fw, True);
BroadcastWindowIconNames(fw, False, True);
}
}

static void setup_icon(FvwmWindow *fw, window_style *pstyle)
{
int affected_titles;

increase_icon_hint_count(fw);
/* find a suitable icon pixmap */
if ((fw->wmhints) && (fw->wmhints->flags & IconWindowHint))
Expand Down Expand Up @@ -1482,16 +1509,13 @@ static void setup_icon(FvwmWindow *fw, window_style *pstyle)
fw->icon_name.name = fw->name.name;
SET_WAS_ICON_NAME_PROVIDED(fw, 0);
}
setup_visible_name(fw, True);

affected_titles = setup_visible_names(fw, 2);

/* wait until the window is iconified and the icon window is mapped
* before creating the icon window
*/
FW_W_ICON_TITLE(fw) = None;

EWMH_SetVisibleName(fw, True);
BroadcastWindowIconNames(fw, False, True);
broadcast_window_names(fw, affected_titles);
if (fw->icon_bitmap_file != NULL &&
fw->icon_bitmap_file != Scr.DefaultIcon)
{
Expand Down Expand Up @@ -1776,31 +1800,102 @@ static int is_geometry_invalid_with_hints(

/* ---------------------------- interface functions ------------------------ */

void setup_visible_name(FvwmWindow *fw, Bool is_icon)
/* what_changed:
* 1 = title name
* 2 = icon name
* 3 = both
* 4 = title format style
* 8 = icon title format style
*
* Returns which titles need to be updated (like what_changed). The return
* value can be used as the 'which' argument of update_window_names.
*/
int setup_visible_names(FvwmWindow *fw, int what_changed)
{
char *ext_name;
window_style style;
int affected_titles;
int changed_names;
int changed_styles;
int force_update;
int bits;

if (fw == NULL)
{
/* should never happen */
return;
return 0;
}

changed_names = (what_changed & 3);
changed_styles = ((what_changed >> 2) & 3);
force_update = changed_styles;
if (fw->visible_name == NULL)
{
force_update |= 1;
}
if (fw->visible_icon_name == NULL)
{
force_update |= 2;
}
affected_titles = 0;
affected_titles |= changed_styles;
/* TA: Get the window style. */
lookup_style(fw, &style);
ext_name = interpolate_titleformat_name(fw, &style, is_icon);

if (is_icon)
if (changed_names != 0 || (force_update & 1))
{
fw->visible_icon_name = strdup(ext_name);
ext_name = interpolate_titleformat_name(
&bits, fw, &style, False);
if ((changed_names & bits) || (force_update & 1))
{
fw->visible_name = ext_name;
affected_titles |= 1;
}
else
{
free(ext_name);
}
}
else
if (changed_names != 0 || (force_update & 2))
{
fw->visible_name = strdup(ext_name);
ext_name = interpolate_titleformat_name(
&bits, fw, &style, True);
if ((changed_names & bits) || (force_update & 2))
{
fw->visible_icon_name = ext_name;
affected_titles |= 2;
}
else
{
free(ext_name);
}
}

free(ext_name);
return (changed_styles) ? changed_styles : affected_titles;
}

/* changed_names:
* 1 = title
* 2 = icon
* 3 = both
*/
void update_window_names(FvwmWindow *fw, int changed_names)
{
int affected_titles;

affected_titles = setup_visible_names(fw, changed_names);
affected_titles |= changed_names;
/* fix the name in the title bar */
if (!IS_ICONIFIED(fw))
{
border_draw_decorations(
fw, PART_TITLE, (Scr.Hilite == fw), True, CLEAR_ALL,
NULL, NULL);
}
broadcast_window_names(fw, affected_titles);
if (affected_titles & 2)
{
RedoIconName(fw);
}

return;
}
Expand Down Expand Up @@ -2367,7 +2462,7 @@ FvwmWindow *AddWindow(
setup_icon_font(fw, &style, False);

/***** visible window name ****/
setup_visible_name(fw, False);
setup_visible_names(fw, 1);
EWMH_SetVisibleName(fw, False);
if (Scr.bo.do_display_new_window_names)
{
Expand Down
3 changes: 2 additions & 1 deletion fvwm/add_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

/* ---------------------------- interface functions ------------------------ */

void setup_visible_name(FvwmWindow *fw, Bool is_icon);
int setup_visible_names(FvwmWindow *fw, int what_changed);
void update_window_names(FvwmWindow *fw, int which);
void setup_wm_hints(FvwmWindow *fw);
void setup_snapping(FvwmWindow *fw, window_style *pstyle);
void setup_placement_penalty(FvwmWindow *fw, window_style *pstyle);
Expand Down
24 changes: 6 additions & 18 deletions fvwm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3365,6 +3365,8 @@ void HandlePropertyNotify(const evh_args_t *ea)
}
case XA_WM_NAME:
{
int changed_names;

flush_property_notify_stop_at_event_type(
te->xproperty.atom, FW_W(fw), 0, 0);
if (XGetGeometry(
Expand Down Expand Up @@ -3411,17 +3413,7 @@ void HandlePropertyNotify(const evh_args_t *ea)
{
fw->name.name = NoName; /* must not happen */
}
setup_visible_name(fw, False);
BroadcastWindowIconNames(fw, True, False);

/* fix the name in the title bar */
if (!IS_ICONIFIED(fw))
{
border_draw_decorations(
fw, PART_TITLE, (Scr.Hilite == fw), True,
CLEAR_ALL, NULL, NULL);
}
EWMH_SetVisibleName(fw, False);
changed_names = 1;
/*
* if the icon name is NoName, set the name of the icon to be
* the same as the window
Expand All @@ -3437,10 +3429,9 @@ void HandlePropertyNotify(const evh_args_t *ea)
)
{
fw->icon_name = fw->name;
setup_visible_name(fw, True);
BroadcastWindowIconNames(fw, False, True);
RedoIconName(fw);
changed_names |= 2;
}
update_window_names(fw, changed_names);
break;
}
case XA_WM_ICON_NAME:
Expand Down Expand Up @@ -3495,10 +3486,7 @@ void HandlePropertyNotify(const evh_args_t *ea)
fw->icon_name.name = fw->name.name;
SET_WAS_ICON_NAME_PROVIDED(fw, 0);
}
setup_visible_name(fw, True);
BroadcastWindowIconNames(fw, False, True);
RedoIconName(fw);
EWMH_SetVisibleName(fw, True);
update_window_names(fw, 2);
break;
}
case XA_WM_HINTS:
Expand Down
27 changes: 7 additions & 20 deletions fvwm/ewmh_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,8 @@ int EWMH_WMIconName(EWMH_CMD_ARGS)
return 1;
}

setup_visible_name(fw, True);
EWMH_SetVisibleName(fw, True);
BroadcastWindowIconNames(fw, False, True);
RedoIconName(fw);
update_window_names(fw, 2);

return 1;
}

Expand All @@ -198,6 +196,7 @@ int EWMH_WMName(EWMH_CMD_ARGS)
char *val;
char *tmp_str;
FlocaleCharset *fc = NULL;
int what_changed;

if (!FiconvSupport)
return 0;
Expand Down Expand Up @@ -249,27 +248,15 @@ int EWMH_WMName(EWMH_CMD_ARGS)
return 1;
}

setup_visible_name(fw, False);
SET_NAME_CHANGED(fw, 1);
EWMH_SetVisibleName(fw, False);
BroadcastWindowIconNames(fw, True, False);

/* fix the name in the title bar */
if (!IS_ICONIFIED(fw))
{
border_draw_decorations(
fw, PART_TITLE, (Scr.Hilite == fw),
True, CLEAR_ALL, NULL, NULL);
}

what_changed = 1;
if (!WAS_ICON_NAME_PROVIDED(fw))
{
fw->icon_name = fw->name;
setup_visible_name(fw, True);
BroadcastWindowIconNames(fw, False, True);
EWMH_SetVisibleName(fw, True);
RedoIconName(fw);
what_changed |= 2;
}
update_window_names(fw, what_changed);

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion fvwm/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ MatchWinToSM(
{
free_window_names(ewin, True, False);
ewin->name.name = matches[i].wm_name;
setup_visible_name(ewin, False);
setup_visible_names(ewin, 1);
}
}
SET_NAME_CHANGED(ewin,IS_NAME_CHANGED(&(matches[i])));
Expand Down
3 changes: 0 additions & 3 deletions fvwm/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#ifndef _STYLE_
#define _STYLE_

/* The default title in case the user doesn't supply one. */
#define DEFAULT_TITLE_FORMAT "%n"

/* access to the special flags of a style */
/* call these with a pointer to a style_flags struct */
#define SDO_DECORATE_TRANSIENT(sf) \
Expand Down
4 changes: 2 additions & 2 deletions fvwm/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ static void apply_window_updates(
}
if (flags->do_update_visible_window_name)
{
setup_visible_name(t, False);
setup_visible_names(t, 4);
BroadcastName(M_VISIBLE_NAME,FW_W(t),FW_W_FRAME(t),
(unsigned long)t,t->visible_name);
EWMH_SetVisibleName(t, False);
}

if (flags->do_update_visible_icon_name)
{
setup_visible_name(t, True);
setup_visible_names(t, 8);
BroadcastName(MX_VISIBLE_ICON_NAME,FW_W(t),FW_W_FRAME(t),
(unsigned long)t,t->visible_icon_name);
EWMH_SetVisibleName(t, True);
Expand Down
4 changes: 4 additions & 0 deletions libs/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@
#define MAX_RESOURCE_LEN 200 /* characters */
#define MAX_CLASS_LEN 200 /* characters */

/* The default title and icon title in case the user doesn't supply one. */
#define DEFAULT_TITLE_FORMAT "%n"
#define DEFAULT_ICON_TITLE_FORMAT "%i"

/* Set the maximum size a visible name can be. */
#define MAX_VISIBLE_NAME_LEN 4096

Expand Down

0 comments on commit bc685fd

Please sign in to comment.