Mercurial > emacs
comparison src/xfns.c @ 56879:fcda7ee97ef5
* 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.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Thu, 02 Sep 2004 16:15:48 +0000 |
parents | c54fa35b4ded |
children | d95ac5c74632 8a6fd1c164cd 3219f94257bc |
comparison
equal
deleted
inserted
replaced
56878:0fd89f7ceec6 | 56879:fcda7ee97ef5 |
---|---|
1558 && !EQ (coding_system, Qcompound_text_with_extensions))); | 1558 && !EQ (coding_system, Qcompound_text_with_extensions))); |
1559 return buf; | 1559 return buf; |
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 | 1566 |
1567 name; if NAME is a string, set F's name to NAME and set | 1567 static void |
1568 F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | 1568 x_set_name_internal (f, name) |
1569 | 1569 FRAME_PTR f; |
1570 If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1571 suggesting a new name, which lisp code should override; if | |
1572 F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
1573 | |
1574 void | |
1575 x_set_name (f, name, explicit) | |
1576 struct frame *f; | |
1577 Lisp_Object name; | 1570 Lisp_Object name; |
1578 int explicit; | 1571 { |
1579 { | |
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; |
1621 #ifdef HAVE_X11R4 | 1575 #ifdef HAVE_X11R4 |
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 |
1630 text.encoding. But, there are non-internationalized window | 1586 text.encoding. But, there are non-internationalized window |
1631 managers which don't support that encoding. So, if NAME | 1587 managers which don't support that encoding. So, if NAME |
1636 | 1592 |
1637 We may also be able to use "UTF8_STRING" in text.encoding | 1593 We may also be able to use "UTF8_STRING" in text.encoding |
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; |
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); | |
1647 | 1606 |
1648 if (NILP (f->icon_name)) | 1607 if (NILP (f->icon_name)) |
1649 { | 1608 { |
1650 icon = text; | 1609 icon = text; |
1651 } | 1610 } |
1656 &bytes, &stringp); | 1615 &bytes, &stringp); |
1657 icon.encoding = (stringp ? XA_STRING | 1616 icon.encoding = (stringp ? XA_STRING |
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))); |
1665 #else /* not USE_GTK */ | 1626 #else /* not USE_GTK */ |
1666 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); | 1627 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); |
1667 #endif /* not USE_GTK */ | 1628 #endif /* not USE_GTK */ |
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 */ |
1678 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 1638 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1679 SDATA (name)); | 1639 SDATA (name)); |
1682 #endif /* not HAVE_X11R4 */ | 1642 #endif /* not HAVE_X11R4 */ |
1683 UNBLOCK_INPUT; | 1643 UNBLOCK_INPUT; |
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 | |
1658 void | |
1659 x_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. */ |
1690 void | 1708 void |
1691 x_explicitly_set_name (f, arg, oldval) | 1709 x_explicitly_set_name (f, arg, oldval) |
1733 if (NILP (name)) | 1751 if (NILP (name)) |
1734 name = f->name; | 1752 name = f->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 |
1796 void | 1759 void |
1797 x_set_scroll_bar_default_width (f) | 1760 x_set_scroll_bar_default_width (f) |
1798 struct frame *f; | 1761 struct frame *f; |