diff options
author | Julien Danjou <julien@danjou.info> | 2009-01-28 15:59:08 +0100 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2009-04-03 12:58:59 +0200 |
commit | f548384bad1f2c7e29b7a788a7d80c8375909c8f (patch) | |
tree | bb81d1151135ebde5fd6b5b1dbf27f9bc4430688 | |
parent | 2d948c85bab1f48dd2aedf429f419c8839e0e18b (diff) |
Move message retrieval and creation to get_or_add_message()
Signed-off-by: Julien Danjou <julien@danjou.info>
-rw-r--r-- | libsn/sn-xmessages.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/libsn/sn-xmessages.c b/libsn/sn-xmessages.c index f862b81..6a10174 100644 --- a/libsn/sn-xmessages.c +++ b/libsn/sn-xmessages.c @@ -339,23 +339,16 @@ message_set_message(SnXmessage *message, const char *src) } static SnXmessage* -add_event_to_messages (SnDisplay *display, - XEvent *xevent) +get_or_add_message(SnList *pending_messages, + Window win, + Atom type_atom_begin) { FindMessageData fmd; SnXmessage *message; - SnList *pending_messages; - - /* We don't want screwy situations to end up causing us to allocate - * infinite memory. Cap the length of a message. - */ -#define MAX_MESSAGE_LENGTH 4096 - - fmd.window = xevent->xclient.window; + + fmd.window = win; fmd.message = NULL; - sn_internal_display_get_xmessage_data (display, NULL, - &pending_messages); if (pending_messages) sn_list_foreach (pending_messages, find_message_foreach, &fmd); @@ -364,11 +357,33 @@ add_event_to_messages (SnDisplay *display, if (message == NULL) { - message = message_new(xevent->xclient.message_type, xevent->xclient.window); + message = message_new(type_atom_begin, win); sn_list_prepend (pending_messages, message); } + return message; +} + +static SnXmessage* +add_event_to_messages (SnDisplay *display, + XEvent *xevent) +{ + SnXmessage *message; + SnList *pending_messages; + + sn_internal_display_get_xmessage_data (display, NULL, + &pending_messages); + + message = get_or_add_message(pending_messages, + xevent->xclient.window, + xevent->xclient.message_type); + + /* We don't want screwy situations to end up causing us to allocate + * infinite memory. Cap the length of a message. + */ +#define MAX_MESSAGE_LENGTH 4096 + if (message->allocated > MAX_MESSAGE_LENGTH) { /* This message is some kind of crap - just dump it. */ |