/* * action.c -- Enfle action binding * (C)Copyright 1999, 2000 by Hiroshi Takekawa * This file is part of Enfle. * * Last Modified: Sat Apr 8 04:13:39 2000. * $Id: action.c,v 1.4 2000/04/22 09:38:24 sian Exp $ * * Enfle is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Enfle is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "action.h" Event action(Hash *act_hash, char *trigger, Info *info, Binfo *binfo, Image *p, Dlist_data *t) { Event (*func)(Info *, Binfo *, Image *, Dlist_data *); if ((func = hash_lookup(act_hash, trigger)) == NULL) return _NOTHING; return func(info, binfo, p, t); } Event action_by_key(Hash *act_hash, KeySym keysym, int state, Info *info, Binfo *binfo, Image *p, Dlist_data *t) { char trigger[8]; sprintf(trigger, "%02X%04X", state, (int)keysym); /* fprintf(stderr, "trigger = %s\n", trigger); */ return action(act_hash, trigger, info, binfo, p, t); } int action_register(Hash *act_hash, char *trigger, Event func(Info *, Binfo *, Image *, Dlist_data *)) { return hash_register(act_hash, trigger, func); } int action_register_by_key(Hash *act_hash, KeySym keysym, int state, Event func(Info *, Binfo *, Image *, Dlist_data *)) { char trigger[8]; sprintf(trigger, "%02X%04X", state, (int)keysym); return action_register(act_hash, trigger, func); } int action_register_by_keys(Hash *act_hash, Action_key keys[]) { int i; for (i = 0; keys[i].func != NULL; i++) if (!action_register_by_key(act_hash, keys[i].keysym, keys[i].state, keys[i].func)) return 0; return i; }