- t->sent = event_get_server_time();
- /*ob_debug("PING: '%s' (timestamp %lu)\n", t->client->title, t->sent);*/
- ob_debug("PINGing client %s at %lu\n", t->client->title, t->sent);
- PROP_MSG_TO(t->client->window, t->client->window, wm_protocols,
- prop_atoms.net_wm_ping, t->sent, t->client->window, 0, 0,
- NoEventMask);
+ /* t->id is 0 when it hasn't been assigned an id ever yet.
+ we can reuse ids when t->waiting == 0, because we won't be getting a
+ pong for that id in the future again. that way for apps that aren't
+ timing out we don't need to remove/add them from/to the hash table */
+ if (t->id == 0 || t->waiting > 0) {
+ /* pick an id, and reinsert in the hash table with the new id */
+ if (t->id) g_hash_table_remove(ping_ids, &t->id);
+ t->id = ping_next_id;
+ if (++ping_next_id == 0) ++ping_next_id; /* skip 0 on wraparound */
+ g_hash_table_insert(ping_ids, &t->id, t);
+ }
+
+ /*ob_debug("+PING: '%s' (id %u)", t->client->title, t->id);*/
+ OBT_PROP_MSG_TO(t->client->window, t->client->window, WM_PROTOCOLS,
+ OBT_PROP_ATOM(NET_WM_PING), t->id, t->client->window, 0, 0,
+ NoEventMask);