summaryrefslogtreecommitdiff
path: root/manage.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2000-08-27 21:34:27 +0000
committersabetts <sabetts>2000-08-27 21:34:27 +0000
commite1306eafc699df1358faa9860ebf2fc6440274dd (patch)
tree4bf24dca4072105c00c22d6d110f0e845fcddf31 /manage.c
parente324b974b06b54e9e568caa0b61535ad46baceba (diff)
downloadratpoison-e1306eafc699df1358faa9860ebf2fc6440274dd.zip
Fixed the ClassHints crashes by using the GetWMName function instead
(The way we're supposed to do it).
Diffstat (limited to 'manage.c')
-rw-r--r--manage.c78
1 files changed, 57 insertions, 21 deletions
diff --git a/manage.c b/manage.c
index 7f2e6f5..62c0ad5 100644
--- a/manage.c
+++ b/manage.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "ratpoison.h"
@@ -65,37 +66,72 @@ grab_prefix_key (Window w)
GrabModeAsync, GrabModeAsync);
}
+/* Reget the WM_NAME property for the window and update its name. */
+int
+update_window_name (rp_window *win)
+{
+ XTextProperty text;
+ char **name_list;
+ int list_len;
+ int i;
+
+ if (!XGetWMName (dpy, win->w, &text))
+ {
+ fprintf (stderr, "ratpoison:manage.c: I can't get the WMName.\n");
+ return 0;
+ }
+
+ if (!XTextPropertyToStringList (&text, &name_list, &list_len))
+ {
+ fprintf (stderr, "ratpoison:manage.c:Error retrieving TextList.\n");
+ return 0;
+ }
+
+ for (i=0; i<list_len; i++)
+ {
+ printf ("WMName: %s\n", name_list[i]);
+ }
+
+ /* Set the window's name to the first in the name_list */
+ if (list_len > 0)
+ {
+ char *loc;
+
+ free (win->name);
+ if ((win->name = malloc (strlen (name_list[0]) + 1)) == NULL)
+ {
+ fprintf (stderr, "manage.c:update_window_name():Out of memory!\n");
+ exit (EXIT_FAILURE);
+ }
+ strcpy (win->name, name_list[0]);
+
+ /* A bit of a hack. If there's a : in the string, crop the
+ string off there. This is mostly brought on by netscape's
+ disgusting tendency to put its current URL in the WMName!!
+ arg! */
+ loc = strchr (win->name, ':');
+ if (loc) loc[0] = '\0';
+ }
+
+ /* Its our responsibility to free this. */
+ XFreeStringList (name_list);
+
+ return 1;
+}
+
void
manage (rp_window *win, screen_info *s)
{
- XClassHint hint;
+ if (!update_window_name (win)) return;
+ /* We successfully got the name, which means we can start managing! */
XMapWindow (dpy, win->w);
XMoveResizeWindow (dpy, win->w, 0, 0, s->root_attr.width, s->root_attr.height);
XSelectInput (dpy, win->w, PropertyChangeMask);
XAddToSaveSet(dpy, win->w);
grab_prefix_key (win->w);
-
win->state = STATE_MAPPED;
- if (!XGetClassHint (dpy, win->w, &hint))
- {
- fprintf (stderr, "ratpoison: I can't get the ClassHint, I don't what to do!\n");
- exit (EXIT_FAILURE);
- }
-
- free (win->name);
- if ((win->name = malloc (strlen (hint.res_name) + 1)) == NULL)
- {
- fprintf (stderr, "manage.c:manage():Out of memory!\n");
- exit (EXIT_FAILURE);
- }
- strcpy (win->name, hint.res_name);
-
- /* Its our responsibility to free these. */
- XFree (hint.res_name);
- XFree (hint.res_class);
-
#ifdef DEBUG
printf ("window '%s' managed.\n", win->name);
#endif
@@ -127,7 +163,7 @@ scanwins(screen_info *s)
if (wins[i] == s->bar_window || wins[i] == s->key_window) continue;
win = add_to_window_list (s, wins[i]);
- manage (win, s);
+ if (attr.map_state == IsViewable) manage (win, s);
}
XFree((void *) wins); /* cast is to shut stoopid compiler up */
}