summaryrefslogtreecommitdiff
path: root/src/communications.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-02-27 12:33:00 +0000
committersabetts <sabetts>2003-02-27 12:33:00 +0000
commit293fca91a75f15c696c2f1d9dd4227f558cfc26f (patch)
tree9fa4d15ede6975b561b07d4d8004c0885c8124fd /src/communications.c
parent6b341ac568efd980ddbbbfbb2c4960204879afdb (diff)
downloadratpoison-293fca91a75f15c696c2f1d9dd4227f558cfc26f.zip
* src/main.c (free_screen): new function
(clean_up): call free_screen on each screen. free the screen array. free defaults.window_fmt. * src/number.h (free_numbers): new prototype * src/number.c (free_numbers): new function * src/manage.c (get_wmname): use XGetWindowProperty to get the window name. (unmanaged_window): free wname after using it. * src/main.c (wm_name): new global (main): internalize WM_NAME atom. (clean_up): free data structures for keybindings, aliases, the bar, window numbers, and input history. * src/input.h (free_history): new prototype * src/input.c (free_history): new function * src/events.c (execute_remote_command): free properties returned by XGetWindowProperty(). * src/data.h (wm_name): new extern * src/communications.c (recieve_command_result): free properties returned by XGetWindowProperty(). * src/bar.h (free_bar): new prototype * src/bar.c (update_window_names): bar_buffer is not static. (update_window_names): free bar_buffer after using it. (marked_message): free the GC after using it. (free_bar): new function. * src/actions.h (free_keybindings): new prototype (free_aliases): likewise * src/actions.c (free_keybindings): new function (free_aliases): likewise (cmd_tmpwm): unmap the key window before calling the new wm, and remap it afterwards.
Diffstat (limited to 'src/communications.c')
-rw-r--r--src/communications.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/communications.c b/src/communications.c
index 9818ae6..7705c85 100644
--- a/src/communications.c
+++ b/src/communications.c
@@ -34,29 +34,50 @@
static void
recieve_command_result (Window w)
{
+ int status;
Atom type_ret;
int format_ret;
unsigned long nitems;
unsigned long bytes_after;
- unsigned char *result;
-
-
- if (XGetWindowProperty (dpy, w, rp_command_result,
- 0, 0, False, XA_STRING,
- &type_ret, &format_ret, &nitems, &bytes_after,
- &result) == Success
- &&
- XGetWindowProperty (dpy, w, rp_command_result,
- 0, (bytes_after / 4) + (bytes_after % 4 ? 1 : 0),
- True, XA_STRING, &type_ret, &format_ret, &nitems,
- &bytes_after, &result) == Success)
+ unsigned char *result = NULL;
+
+ /* First, find out how big the property is. */
+ status = XGetWindowProperty (dpy, w, rp_command_result,
+ 0, 0, False, XA_STRING,
+ &type_ret, &format_ret, &nitems, &bytes_after,
+ &result);
+
+ /* Failed to retrieve property. */
+ if (status != Success || result == NULL)
{
- if (result && strlen (result))
- {
- printf ("%s\n", result);
- }
- XFree (result);
+ PRINT_DEBUG (("failed to get command result length\n"));
+ return;
}
+
+ /* XGetWindowProperty always allocates one extra byte even if
+ the property is zero length. */
+ XFree (result);
+
+ /* Now that we have the length of the message, we can get the
+ whole message. */
+ status = XGetWindowProperty (dpy, w, rp_command_result,
+ 0, (bytes_after / 4) + (bytes_after % 4 ? 1 : 0),
+ True, XA_STRING, &type_ret, &format_ret, &nitems,
+ &bytes_after, &result);
+
+ /* Failed to retrieve property. */
+ if (status != Success || result == NULL)
+ {
+ PRINT_DEBUG (("failed to get command result\n"));
+ return;
+ }
+
+ /* If result is not the empty string, print it. */
+ if (strlen (result))
+ printf ("%s\n", result);
+
+ /* Free the result. */
+ XFree (result);
}
int