Attachment "tk-wm-title.patch" to
ticket [959973ff]
added by
jenglish
2004-06-22 23:24:38.
Date: Tue Jun 22 09:22:45 AM PDT 2004
Files: unix/tkUnixWm.c
Bugid: 959973
--- unix/tkUnixWm.c.wm-title.old 2004-06-22 08:19:47.000000000 -0700
+++ unix/tkUnixWm.c 2004-06-22 09:22:21.000000000 -0700
@@ -333,6 +333,7 @@
static void UpdateHints _ANSI_ARGS_((TkWindow *winPtr));
static void UpdateSizeHints _ANSI_ARGS_((TkWindow *winPtr,
int newWidth, int newHeight));
+static void UpdateTitle _ANSI_ARGS_((TkWindow *winPtr));
static void UpdateVRootGeometry _ANSI_ARGS_((WmInfo *wmPtr));
static void UpdateWmProtocols _ANSI_ARGS_((WmInfo *wmPtr));
static void WaitForConfigureNotify _ANSI_ARGS_((TkWindow *winPtr,
@@ -607,7 +608,6 @@
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
XTextProperty textProp;
- Tk_Uid string;
if (wmPtr->flags & WM_NEVER_MAPPED) {
Tcl_DString ds;
@@ -629,24 +629,8 @@
* window.
*/
- string = (wmPtr->title != NULL) ? wmPtr->title : winPtr->nameUid;
- Tcl_UtfToExternalDString(NULL, string, -1, &ds);
- string = Tcl_DStringValue(&ds);
- if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
- &textProp) != 0) {
- XSetWMName(winPtr->display, wmPtr->wrapperPtr->window, &textProp);
- XFree((char *) textProp.value);
- }
- Tcl_DStringFree(&ds);
-
TkWmSetClass(winPtr);
-
- if (wmPtr->iconName != NULL) {
- Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
- XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
- Tcl_DStringValue(&ds));
- Tcl_DStringFree(&ds);
- }
+ UpdateTitle(winPtr);
if (wmPtr->masterPtr != NULL) {
/*
@@ -2046,12 +2030,7 @@
wmPtr->iconName = ckalloc((unsigned) (length + 1));
strcpy(wmPtr->iconName, argv3);
if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- Tcl_DString ds;
-
- Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
- XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
- Tcl_DStringValue(&ds));
- Tcl_DStringFree(&ds);
+ UpdateTitle(winPtr);
}
}
return TCL_OK;
@@ -2944,17 +2923,7 @@
strcpy(wmPtr->title, argv3);
if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- XTextProperty textProp;
- Tcl_DString ds;
-
- Tcl_UtfToExternalDString(NULL, wmPtr->title, -1, &ds);
- if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
- &textProp) != 0) {
- XSetWMName(winPtr->display, wmPtr->wrapperPtr->window,
- &textProp);
- XFree((char *) textProp.value);
- }
- Tcl_DStringFree(&ds);
+ UpdateTitle(winPtr);
}
}
return TCL_OK;
@@ -4307,6 +4276,68 @@
}
/*
+ *--------------------------------------------------------------
+ *
+ * UpdateTitle --
+ *
+ * This procedure is called to update the window title and
+ * icon name. It sets the ICCCM-defined properties WM_NAME
+ * and WM_ICON_NAME for older window managers, and the
+ * freedesktop.org-defined _NET_WM_NAME and _NET_WM_ICON_NAME
+ * properties for newer ones. The ICCCM properties are
+ * stored in the system encoding, the newer properties
+ * are stored in UTF-8.
+ *
+ * NOTE: the ICCCM specifies that WM_NAME and WM_ICON_NAME are
+ * stored in ISO-Latin-1. Tk has historically used the default
+ * system encoding (since 8.1). It's not clear whether this is
+ * correct or not.
+ *
+ * Side effects:
+ * Properties get changed for winPtr.
+ *
+ *--------------------------------------------------------------
+ */
+static void
+UpdateTitle(winPtr)
+ TkWindow *winPtr;
+{
+ WmInfo *wmPtr = winPtr->wmInfoPtr;
+ Atom XA_UTF8_STRING = Tk_InternAtom((Tk_Window) winPtr, "UTF8_STRING");
+ const char *string;
+ Tcl_DString ds;
+
+ /*
+ * Set window title:
+ */
+ string = (wmPtr->title != NULL) ? wmPtr->title : winPtr->nameUid;
+ Tcl_UtfToExternalDString(NULL, string, -1, &ds);
+ XStoreName(winPtr->display, wmPtr->wrapperPtr->window,
+ Tcl_DStringValue(&ds));
+ Tcl_DStringFree(&ds);
+
+ XChangeProperty(winPtr->display, wmPtr->wrapperPtr->window,
+ Tk_InternAtom((Tk_Window) winPtr, "_NET_WM_NAME"),
+ XA_UTF8_STRING, 8, PropModeReplace,
+ string, (signed int)strlen(string));
+
+ /*
+ * Set icon name:
+ */
+ if (wmPtr->iconName != NULL) {
+ Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
+ XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
+ Tcl_DStringValue(&ds));
+ Tcl_DStringFree(&ds);
+
+ XChangeProperty(winPtr->display, wmPtr->wrapperPtr->window,
+ Tk_InternAtom((Tk_Window) winPtr, "_NET_WM_ICON_NAME"),
+ XA_UTF8_STRING, 8, PropModeReplace,
+ wmPtr->iconName, (signed int)strlen(wmPtr->iconName));
+ }
+}
+
+/*
*----------------------------------------------------------------------
*
* WaitForConfigureNotify --