[as-devel] Recomputing icon on title change
Frank v Waveren (fvw@var.cx)
Mon, 19 Nov 2001 21:36:41 +0100
--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Attached is a patch to make afterstep re-determine which icon to use
after a window's title has changed. I like this, because my shell is
set up to set my aterm's title to user@host:<more stuff>, and I have
different icons, depending on which user/host. Without this patch,
afterstep will decide which icon to use when the window is first
iconised, and after that it will always use that icon, which is rather
annoying if you log into a different account using the same aterm.
I did however hit a problem when checking for memory leaks. Every time
XGrabKey is called some memory leakage appears to be occuring... I
strongly suspect it is indeed XGrabKey itself, at least with only the
XGrabKey commented out no leakage occurs. I suspect a bug in my
libX11.so (from XFree86 4.1.0), but before I start getting my hands
dirty on the libX11 code I'd like to hear from someone that it is
indeed a bug in the library. The problem can be triggered with the
attached 'titlechange.c', a quick & dirty program that changes it's
title very fast, causing the MyXGrabKey and thus XGrabKey to get
called very often, exposing the leak (titlechange.c only causes
leakage on an afterstep with my patch applied, I suspect the leak
would occur on an unpatched afterstep too but you'd need to create and
destroy a window many times as the unpatched afterstep never calls
MyXGrabKey more than once per window). To reproduce the leak, run the
patched afterstep and run titlechange with it's window iconized. I'd
love to hear from people using libX11 from elsewhere than XFree 4 too
btw.
PS: I also added two XDestroyWindows as I suspect those windows were
never getting destroyed and thus were clogging up the X server until
afterstep disconnects... Once again, someone who knows more about
X please check...
--
Frank v Waveren Fingerprint: 0EDB 8787
fvw@[var.cx|dse.nl|stack.nl|chello.nl] ICQ#10074100 09B9 6EF5 6425 B855
Public key: http://www.var.cx/pubkey/fvw@var.cx-gpg 7179 3036 E136 B85D
--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="as-icon-refind.diff"
diff -urNbB AfterStep-1.8.8/src/afterstep/events.c AfterStep-fvw/src/afterstep/events.c
--- AfterStep-1.8.8/src/afterstep/events.c Sun Jan 23 18:07:34 2000
+++ AfterStep-fvw/src/afterstep/events.c Mon Nov 19 20:54:28 2001
@@ -554,6 +554,8 @@
BroadcastName (M_WINDOW_NAME, Tmp_win->w, Tmp_win->frame,
(unsigned long) Tmp_win, Tmp_win->name);
+ ChangeIcon(Tmp_win);
+
/* fix the name in the title bar */
if (!(Tmp_win->flags & ICONIFIED))
SetTitleBar (Tmp_win, (Scr.Hilite == Tmp_win), True);
diff -urNbB AfterStep-1.8.8/src/afterstep/icons.c AfterStep-fvw/src/afterstep/icons.c
--- AfterStep-1.8.8/src/afterstep/icons.c Thu Jan 4 02:40:41 2001
+++ AfterStep-fvw/src/afterstep/icons.c Mon Nov 19 19:18:42 2001
@@ -237,14 +237,18 @@
FocusChangeMask);
if ((Textures.flags & SeparateButtonTitle) && (Scr.flags & IconTitle) && !(tmp_win->flags & NOICON_TITLE))
+ {
+ XDestroyWindow(dpy, tmp_win->icon_title_w);
tmp_win->icon_title_w =
XCreateWindow (dpy, Scr.Root, -999, -999, 16, 16, 0,
CopyFromParent, CopyFromParent, CopyFromParent,
valuemask, &attributes);
+ }
if ((tmp_win->flags & ICON_OURS) &&
tmp_win->icon_p_width > 0 && tmp_win->icon_p_height > 0)
{
+ XDestroyWindow(dpy, tmp_win->icon_pixmap_w);
tmp_win->icon_pixmap_w =
XCreateWindow (dpy, Scr.Root, -999, -999, 16, 16, 0,
CopyFromParent, CopyFromParent, CopyFromParent,
diff -urNbB AfterStep-1.8.8/src/afterstep/misc.c AfterStep-fvw/src/afterstep/misc.c
--- AfterStep-1.8.8/src/afterstep/misc.c Sat Feb 12 03:25:27 2000
+++ AfterStep-fvw/src/afterstep/misc.c Mon Nov 19 19:18:42 2001
@@ -579,7 +579,7 @@
{
mod = *mods++;
XGrabKey (display, keycode, modifiers | mod, grab_window, owner_events,
- pointer_mode, keyboard_mode);
+ pointer_mode, keyboard_mode); // A memory leak occurs here. Bug in Xlib?
}
while (mod);
}
--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="titlechange.c"
/* gcc -o titlechange titlechange.c -L/usr/X11R6/lib -lX11 */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
Window w;
Display *dpy;
dpy = XOpenDisplay(NULL);
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 60, 0, 0,
BlackPixel(dpy, DefaultScreen(dpy)));
XSelectInput(dpy, w, StructureNotifyMask);
XMapWindow(dpy, w);
for(;;)
{
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify)
break;
}
while(1)
{
int i;
char s[30];
usleep(1);
i=rand();
sprintf((char *) &s, "%i", i);
XStoreName(dpy, w, (char *) &s);
XSetIconName(dpy, w, (char *) &s);
XFlush(dpy);
}
}
--VS++wcV0S1rZb1Fb--