void X11ProcessSelectionNotifyEvent(FcitxX11 *x11priv, XSelectionEvent *selection_event) { X11ConvertSelection *convert; int id; int next_id; FcitxHandlerTable *table = x11priv->convertSelection; id = fcitx_handler_table_first_id(table, sizeof(Atom), &selection_event->selection); if (id == FCITX_OBJECT_POOL_INVALID_ID) return; unsigned long nitems; int ret_format; Atom ret_type = None; unsigned char *buff; buff = X11GetWindowProperty(x11priv, x11priv->eventWindow, selection_event->property, &ret_type, &ret_format, &nitems); for (;(convert = fcitx_handler_table_get_by_id(table, id));id = next_id) { next_id = fcitx_handler_table_next_id(table, convert); if (convert->cb(x11priv, selection_event->selection, selection_event->target, ret_format, nitems, buff, convert)) { fcitx_handler_table_remove_by_id(table, id); } } if (buff) { XFree(buff); buff = NULL; } }
void X11SelectionNotifyRemove(FcitxX11 *x11priv, unsigned int id) { #ifdef HAVE_XFIXES if (!(x11priv->hasXfixes && id != FCITX_OBJECT_POOL_INVALID_ID)) return; fcitx_handler_table_remove_by_id(x11priv->selectionNotify, id); #endif }
void X11SelectionNotifyRemove(FcitxX11 *x11priv, int id) { #ifdef HAVE_XFIXES if (!(x11priv->hasXfixes && id >= 0)) return; fcitx_handler_table_remove_by_id(x11priv->selectionNotify, id); #endif }
int main() { FcitxHandlerTable *table = fcitx_handler_table_new(sizeof(HandlerObj), test_free_handler_obj); HandlerObj obj; int i; for (i = 0;i < 6;i++) { obj.id = i; obj.str = strdup(strs[i]); fcitx_handler_table_append_strkey(table, KEY1, &obj); } for (;i < 12;i++) { obj.id = i; obj.str = strdup(strs[i]); fcitx_handler_table_prepend_strkey(table, KEY1, &obj); } for (i = 0;i < 6;i++) { obj.id = i; obj.str = strdup(strs[i]); fcitx_handler_table_prepend_strkey(table, KEY2, &obj); } for (;i < 12;i++) { obj.id = i; obj.str = strdup(strs[i]); fcitx_handler_table_append_strkey(table, KEY2, &obj); } HandlerObj *p; assert(free_count == 0); for (p = fcitx_handler_table_first_strkey(table, KEY1), i = 0; p; p = fcitx_handler_table_next(table, p), i++) { assert(i < 12); assert(p->id == order[i]); assert(strcmp(p->str, strs[p->id]) == 0); } assert(i == 12); fcitx_handler_table_remove_key_strkey(table, KEY1); assert(free_count == 12); assert(fcitx_handler_table_first_strkey(table, KEY1) == NULL); unsigned int id; unsigned int next_id; id = fcitx_handler_table_last_id_strkey(table, KEY2); i = 0; for (;(p = fcitx_handler_table_get_by_id(table, id));id = next_id, i++) { next_id = fcitx_handler_table_prev_id(table, p); assert(i < 12); assert(p->id == order[i]); assert(strcmp(p->str, strs[p->id]) == 0); fcitx_handler_table_remove_by_id(table, id); assert(free_count == i + 13); } assert(i == 12); assert(free_count == 24); assert(fcitx_handler_table_first_id_strkey(table, KEY2) == FCITX_OBJECT_POOL_INVALID_ID); assert(fcitx_handler_table_last_id_strkey(table, KEY2) == FCITX_OBJECT_POOL_INVALID_ID); assert(fcitx_handler_table_first_strkey(table, KEY_NOT_EXIST) == NULL); assert(fcitx_handler_table_last_strkey(table, KEY_NOT_EXIST) == NULL); fcitx_handler_table_remove_by_id(table, FCITX_OBJECT_POOL_INVALID_ID); fcitx_handler_table_remove_key_strkey(table, KEY_NOT_EXIST); fcitx_handler_table_free(table); return 0; }