aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2004-09-02 16:15:48 +0000
committerJan Djärv2004-09-02 16:15:48 +0000
commitb10daec70920a4d17425bdfe816f2e4ec1a793e1 (patch)
tree5c3fc5a93377643f3d2a69500f33f8583f7fd0de /src
parentc3829a8e2fa294b3b15c4827d11c12653e2df3c3 (diff)
downloademacs-b10daec70920a4d17425bdfe816f2e4ec1a793e1.tar.gz
emacs-b10daec70920a4d17425bdfe816f2e4ec1a793e1.zip
* xfns.c (x_set_name_internal): New function. Check if we shall call
xfree before ENCODE_UTF_8. (x_set_name, x_set_title): Call x_set_name_internal.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/xfns.c187
2 files changed, 81 insertions, 112 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 77a331a7802..1f3c06e8cf9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12004-09-02 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2
3 * xfns.c (x_set_name_internal): New function. Check if we shall call
4 xfree before ENCODE_UTF_8.
5 (x_set_name, x_set_title): Call x_set_name_internal.
6
12004-08-31 NAKAMURA Toshikazu <nr-tkz@nifty.com> (tiny change) 72004-08-31 NAKAMURA Toshikazu <nr-tkz@nifty.com> (tiny change)
2 8
3 * w32fns.c (w32_load_font): If a BDF font is already loaded, do not 9 * w32fns.c (w32_load_font): If a BDF font is already loaded, do not
diff --git a/src/xfns.c b/src/xfns.c
index 8368e62a445..5ebdeca97d5 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1560,61 +1560,15 @@ x_encode_text (string, coding_system, selectionp, text_bytes, stringp)
1560} 1560}
1561 1561
1562 1562
1563/* Change the name of frame F to NAME. If NAME is nil, set F's name to 1563/* Set the WM name to NAME for frame F. Also set the icon name.
1564 x_id_name. 1564 If the frame already has an icon name, use that, otherwise set the
1565 1565 icon name to NAME. */
1566 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1567 name; if NAME is a string, set F's name to NAME and set
1568 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1569 1566
1570 If EXPLICIT is zero, that indicates that Emacs redisplay code is 1567static void
1571 suggesting a new name, which lisp code should override; if 1568x_set_name_internal (f, name)
1572 F->explicit_name is set, ignore the new name; otherwise, set it. */ 1569 FRAME_PTR f;
1573
1574void
1575x_set_name (f, name, explicit)
1576 struct frame *f;
1577 Lisp_Object name; 1570 Lisp_Object name;
1578 int explicit;
1579{ 1571{
1580 /* Make sure that requests from lisp code override requests from
1581 Emacs redisplay code. */
1582 if (explicit)
1583 {
1584 /* If we're switching from explicit to implicit, we had better
1585 update the mode lines and thereby update the title. */
1586 if (f->explicit_name && NILP (name))
1587 update_mode_lines = 1;
1588
1589 f->explicit_name = ! NILP (name);
1590 }
1591 else if (f->explicit_name)
1592 return;
1593
1594 /* If NAME is nil, set the name to the x_id_name. */
1595 if (NILP (name))
1596 {
1597 /* Check for no change needed in this very common case
1598 before we do any consing. */
1599 if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
1600 SDATA (f->name)))
1601 return;
1602 name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
1603 }
1604 else
1605 CHECK_STRING (name);
1606
1607 /* Don't change the name if it's already NAME. */
1608 if (! NILP (Fstring_equal (name, f->name)))
1609 return;
1610
1611 f->name = name;
1612
1613 /* For setting the frame title, the title parameter should override
1614 the name parameter. */
1615 if (! NILP (f->title))
1616 name = f->title;
1617
1618 if (FRAME_X_WINDOW (f)) 1572 if (FRAME_X_WINDOW (f))
1619 { 1573 {
1620 BLOCK_INPUT; 1574 BLOCK_INPUT;
@@ -1622,8 +1576,10 @@ x_set_name (f, name, explicit)
1622 { 1576 {
1623 XTextProperty text, icon; 1577 XTextProperty text, icon;
1624 int bytes, stringp; 1578 int bytes, stringp;
1579 int do_free_icon_value = 0, do_free_text_value = 0;
1625 Lisp_Object coding_system; 1580 Lisp_Object coding_system;
1626 1581
1582 coding_system = Qcompound_text;
1627 /* Note: Encoding strategy 1583 /* Note: Encoding strategy
1628 1584
1629 We encode NAME by compound-text and use "COMPOUND-TEXT" in 1585 We encode NAME by compound-text and use "COMPOUND-TEXT" in
@@ -1638,13 +1594,16 @@ x_set_name (f, name, explicit)
1638 in the future which can encode all Unicode characters. 1594 in the future which can encode all Unicode characters.
1639 But, for the moment, there's no way to know that the 1595 But, for the moment, there's no way to know that the
1640 current window manager supports it or not. */ 1596 current window manager supports it or not. */
1641 coding_system = Qcompound_text;
1642 text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp); 1597 text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp);
1643 text.encoding = (stringp ? XA_STRING 1598 text.encoding = (stringp ? XA_STRING
1644 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); 1599 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1645 text.format = 8; 1600 text.format = 8;
1646 text.nitems = bytes; 1601 text.nitems = bytes;
1647 1602
1603 /* Check early, because ENCODE_UTF_8 below may GC and name may be
1604 relocated. */
1605 do_free_text_value = text.value != SDATA (name);
1606
1648 if (NILP (f->icon_name)) 1607 if (NILP (f->icon_name))
1649 { 1608 {
1650 icon = text; 1609 icon = text;
@@ -1658,7 +1617,9 @@ x_set_name (f, name, explicit)
1658 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); 1617 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1659 icon.format = 8; 1618 icon.format = 8;
1660 icon.nitems = bytes; 1619 icon.nitems = bytes;
1620 do_free_icon_value = icon.value != SDATA (f->icon_name);
1661 } 1621 }
1622
1662#ifdef USE_GTK 1623#ifdef USE_GTK
1663 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), 1624 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1664 SDATA (ENCODE_UTF_8 (name))); 1625 SDATA (ENCODE_UTF_8 (name)));
@@ -1668,10 +1629,9 @@ x_set_name (f, name, explicit)
1668 1629
1669 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon); 1630 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
1670 1631
1671 if (!NILP (f->icon_name) 1632 if (do_free_icon_value)
1672 && icon.value != (unsigned char *) SDATA (f->icon_name))
1673 xfree (icon.value); 1633 xfree (icon.value);
1674 if (text.value != (unsigned char *) SDATA (name)) 1634 if (do_free_text_value)
1675 xfree (text.value); 1635 xfree (text.value);
1676 } 1636 }
1677#else /* not HAVE_X11R4 */ 1637#else /* not HAVE_X11R4 */
@@ -1684,6 +1644,64 @@ x_set_name (f, name, explicit)
1684 } 1644 }
1685} 1645}
1686 1646
1647/* Change the name of frame F to NAME. If NAME is nil, set F's name to
1648 x_id_name.
1649
1650 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1651 name; if NAME is a string, set F's name to NAME and set
1652 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1653
1654 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1655 suggesting a new name, which lisp code should override; if
1656 F->explicit_name is set, ignore the new name; otherwise, set it. */
1657
1658void
1659x_set_name (f, name, explicit)
1660 struct frame *f;
1661 Lisp_Object name;
1662 int explicit;
1663{
1664 /* Make sure that requests from lisp code override requests from
1665 Emacs redisplay code. */
1666 if (explicit)
1667 {
1668 /* If we're switching from explicit to implicit, we had better
1669 update the mode lines and thereby update the title. */
1670 if (f->explicit_name && NILP (name))
1671 update_mode_lines = 1;
1672
1673 f->explicit_name = ! NILP (name);
1674 }
1675 else if (f->explicit_name)
1676 return;
1677
1678 /* If NAME is nil, set the name to the x_id_name. */
1679 if (NILP (name))
1680 {
1681 /* Check for no change needed in this very common case
1682 before we do any consing. */
1683 if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
1684 SDATA (f->name)))
1685 return;
1686 name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
1687 }
1688 else
1689 CHECK_STRING (name);
1690
1691 /* Don't change the name if it's already NAME. */
1692 if (! NILP (Fstring_equal (name, f->name)))
1693 return;
1694
1695 f->name = name;
1696
1697 /* For setting the frame title, the title parameter should override
1698 the name parameter. */
1699 if (! NILP (f->title))
1700 name = f->title;
1701
1702 x_set_name_internal (f, name);
1703}
1704
1687/* This function should be called when the user's lisp code has 1705/* This function should be called when the user's lisp code has
1688 specified a name for the frame; the name will override any set by the 1706 specified a name for the frame; the name will override any set by the
1689 redisplay code. */ 1707 redisplay code. */
@@ -1735,62 +1753,7 @@ x_set_title (f, name, old_name)
1735 else 1753 else
1736 CHECK_STRING (name); 1754 CHECK_STRING (name);
1737 1755
1738 if (FRAME_X_WINDOW (f)) 1756 x_set_name_internal (f, name);
1739 {
1740 BLOCK_INPUT;
1741#ifdef HAVE_X11R4
1742 {
1743 XTextProperty text, icon;
1744 int bytes, stringp;
1745 Lisp_Object coding_system;
1746
1747 coding_system = Qcompound_text;
1748 /* See the comment "Note: Encoding strategy" in x_set_name. */
1749 text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp);
1750 text.encoding = (stringp ? XA_STRING
1751 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1752 text.format = 8;
1753 text.nitems = bytes;
1754
1755 if (NILP (f->icon_name))
1756 {
1757 icon = text;
1758 }
1759 else
1760 {
1761 /* See the comment "Note: Encoding strategy" in x_set_name. */
1762 icon.value = x_encode_text (f->icon_name, coding_system, 0,
1763 &bytes, &stringp);
1764 icon.encoding = (stringp ? XA_STRING
1765 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1766 icon.format = 8;
1767 icon.nitems = bytes;
1768 }
1769
1770#ifdef USE_GTK
1771 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1772 SDATA (ENCODE_UTF_8 (name)));
1773#else /* not USE_GTK */
1774 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
1775#endif /* not USE_GTK */
1776
1777 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
1778 &icon);
1779
1780 if (!NILP (f->icon_name)
1781 && icon.value != (unsigned char *) SDATA (f->icon_name))
1782 xfree (icon.value);
1783 if (text.value != (unsigned char *) SDATA (name))
1784 xfree (text.value);
1785 }
1786#else /* not HAVE_X11R4 */
1787 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1788 SDATA (name));
1789 XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1790 SDATA (name));
1791#endif /* not HAVE_X11R4 */
1792 UNBLOCK_INPUT;
1793 }
1794} 1757}
1795 1758
1796void 1759void