Changeset 257b9c4 for select.c


Ignore:
Timestamp:
May 23, 2011, 8:57:46 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
81db142
Parents:
3535a6e
git-author:
David Benjamin <davidben@mit.edu> (02/26/11 00:17:01)
git-committer:
David Benjamin <davidben@mit.edu> (05/23/11 20:57:46)
Message:
Punt pre-select actions

The four users are now directly handled with GSources.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • select.c

    r3535a6e r257b9c4  
    33static GMainLoop *loop = NULL;
    44static int dispatch_active = 0;
    5 static int psa_active = 0;
    65
    76static GSource *owl_timer_source;
     
    231230
    232231static gboolean owl_io_dispatch_prepare(GSource *source, int *timeout) {
    233   owl_select_do_pre_select_actions(); /* HACK */
    234232  *timeout = -1;
    235233  return FALSE;
     
    331329    owl_function_makemsg("Unable to handle keypress");
    332330  }
    333 }
    334 
    335 owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data)
    336 {
    337   owl_ps_action *a = g_new(owl_ps_action, 1);
    338   owl_list *psa_list = owl_global_get_psa_list(&g);
    339   a->needs_gc = 0;
    340   a->callback = cb;
    341   a->destroy = destroy;
    342   a->data = data;
    343   owl_list_append_element(psa_list, a);
    344   return a;
    345 }
    346 
    347 void owl_select_psa_gc(void)
    348 {
    349   int i;
    350   owl_list *psa_list;
    351   owl_ps_action *a;
    352 
    353   psa_list = owl_global_get_psa_list(&g);
    354   for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) {
    355     a = owl_list_get_element(psa_list, i);
    356     if (a->needs_gc) {
    357       owl_list_remove_element(psa_list, i);
    358       if (a->destroy) {
    359         a->destroy(a);
    360       }
    361       g_free(a);
    362     }
    363   }
    364 }
    365 
    366 void owl_select_remove_pre_select_action(owl_ps_action *a)
    367 {
    368   a->needs_gc = 1;
    369   if (!psa_active)
    370     owl_select_psa_gc();
    371 }
    372 
    373 int owl_select_do_pre_select_actions(void)
    374 {
    375   int i, len, ret;
    376   owl_list *psa_list;
    377 
    378   psa_active = 1;
    379   ret = 0;
    380   psa_list = owl_global_get_psa_list(&g);
    381   len = owl_list_get_size(psa_list);
    382   for (i = 0; i < len; i++) {
    383     owl_ps_action *a = owl_list_get_element(psa_list, i);
    384     if (a->callback != NULL && a->callback(a, a->data)) {
    385       ret = 1;
    386     }
    387   }
    388   psa_active = 0;
    389   owl_select_psa_gc();
    390   return ret;
    391331}
    392332
Note: See TracChangeset for help on using the changeset viewer.