1999-11-18 20:05:24 -08:00
|
|
|
/*
|
2000-01-05 09:34:32 -08:00
|
|
|
* Copyright (C) 1997-2000, Michael Jennings
|
1999-08-17 18:12:47 -07:00
|
|
|
*
|
1999-11-18 20:05:24 -08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
1999-08-17 18:12:47 -07:00
|
|
|
*
|
1999-11-18 20:05:24 -08:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
1999-08-17 18:12:47 -07:00
|
|
|
*
|
1999-11-18 20:05:24 -08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1999-08-17 18:12:47 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const char cvs_ident[] = "$Id$";
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "feature.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
1999-10-07 15:18:14 -07:00
|
|
|
#include "startup.h"
|
1999-08-17 18:12:47 -07:00
|
|
|
#include "actions.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "e.h"
|
|
|
|
#include "events.h"
|
|
|
|
#include "menus.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "pixmap.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "scrollbar.h"
|
|
|
|
#include "term.h"
|
|
|
|
#include "windows.h"
|
|
|
|
|
|
|
|
action_t *action_list = NULL;
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
action_handle_string(event_t *ev, action_t *action) {
|
1999-10-19 10:44:02 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
REQUIRE_RVAL(action->param.string != NULL, 0);
|
1999-10-27 11:10:40 -07:00
|
|
|
cmd_write((unsigned char *) action->param.string, strlen(action->param.string));
|
1999-08-17 18:12:47 -07:00
|
|
|
return 1;
|
1999-10-19 10:44:02 -07:00
|
|
|
ev = NULL;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
action_handle_echo(event_t *ev, action_t *action) {
|
1999-10-19 10:44:02 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
REQUIRE_RVAL(action->param.string != NULL, 0);
|
1999-10-27 11:10:40 -07:00
|
|
|
tt_write((unsigned char *) action->param.string, strlen(action->param.string));
|
1999-08-17 18:12:47 -07:00
|
|
|
return 1;
|
1999-10-19 10:44:02 -07:00
|
|
|
ev = NULL;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
2000-07-03 12:08:41 -07:00
|
|
|
unsigned char
|
|
|
|
action_handle_function(event_t *ev, action_t *action) {
|
|
|
|
REQUIRE_RVAL(action->param.string != NULL, 0);
|
|
|
|
/* To be continued.... :-) */
|
|
|
|
return 1;
|
|
|
|
ev = NULL;
|
|
|
|
}
|
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
unsigned char
|
|
|
|
action_handle_menu(event_t *ev, action_t *action) {
|
|
|
|
REQUIRE_RVAL(action->param.menu != NULL, 0);
|
|
|
|
menu_invoke(ev->xbutton.x, ev->xbutton.y, TermWin.parent, action->param.menu, ev->xbutton.time);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-07-03 12:08:41 -07:00
|
|
|
action_t *
|
|
|
|
action_find_match(unsigned short mod, unsigned char button, KeySym keysym) {
|
|
|
|
|
|
|
|
action_t *action;
|
|
|
|
|
|
|
|
D_ACTIONS(("mod == 0x%08x, button == %d, keysym == 0x%08x\n", mod, button, keysym));
|
|
|
|
for (action = action_list; action; action = action->next) {
|
|
|
|
D_ACTIONS(("Checking action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
|
|
|
|
if ((action->mod == mod) && (action->button == button) && (action->keysym == keysym)) {
|
|
|
|
D_ACTIONS(("Match found at %8p\n", action));
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
unsigned char
|
|
|
|
action_dispatch(event_t *ev, KeySym keysym) {
|
|
|
|
|
|
|
|
action_t *action;
|
1999-12-02 18:31:33 -08:00
|
|
|
unsigned int m = (AltMask | MetaMask | NumLockMask);
|
1999-08-17 18:12:47 -07:00
|
|
|
|
|
|
|
ASSERT(ev != NULL);
|
2000-04-17 22:16:00 -07:00
|
|
|
D_ACTIONS(("Event %8p: Button %d, Keysym 0x%08x, Key State 0x%08x\n", ev, ev->xbutton.button, keysym, ev->xkey.state));
|
1999-08-17 18:12:47 -07:00
|
|
|
for (action = action_list; action; action = action->next) {
|
|
|
|
D_ACTIONS(("Checking action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
|
|
|
|
if (ev->xany.type == ButtonPress) {
|
|
|
|
if ((action->button == BUTTON_NONE) || ((action->button != BUTTON_ANY) && (action->button != ev->xbutton.button))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (action->button != BUTTON_NONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
D_ACTIONS(("Button passed.\n"));
|
|
|
|
if (action->mod != MOD_ANY) {
|
|
|
|
if (LOGICAL_XOR((action->mod & MOD_SHIFT), (ev->xkey.state & ShiftMask))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (LOGICAL_XOR((action->mod & MOD_CTRL), (ev->xkey.state & ControlMask))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (LOGICAL_XOR((action->mod & MOD_LOCK), (ev->xkey.state & LockMask))) {
|
|
|
|
continue;
|
|
|
|
}
|
1999-12-02 18:31:33 -08:00
|
|
|
if (LOGICAL_XOR((action->mod & MOD_META), (ev->xkey.state & MetaMask))) {
|
1999-08-17 18:12:47 -07:00
|
|
|
continue;
|
|
|
|
}
|
1999-12-02 18:31:33 -08:00
|
|
|
if (LOGICAL_XOR((action->mod & MOD_ALT), (ev->xkey.state & AltMask))) {
|
1999-08-17 18:12:47 -07:00
|
|
|
continue;
|
|
|
|
}
|
1999-12-02 18:31:33 -08:00
|
|
|
if (((action->mod & MOD_MOD1) && !(ev->xkey.state & Mod1Mask)) || (!(action->mod & MOD_MOD1) && (ev->xkey.state & Mod1Mask) && !(Mod1Mask & m))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (((action->mod & MOD_MOD2) && !(ev->xkey.state & Mod2Mask)) || (!(action->mod & MOD_MOD2) && (ev->xkey.state & Mod2Mask) && !(Mod2Mask & m))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (((action->mod & MOD_MOD3) && !(ev->xkey.state & Mod3Mask)) || (!(action->mod & MOD_MOD3) && (ev->xkey.state & Mod3Mask) && !(Mod3Mask & m))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (((action->mod & MOD_MOD4) && !(ev->xkey.state & Mod4Mask)) || (!(action->mod & MOD_MOD4) && (ev->xkey.state & Mod4Mask) && !(Mod4Mask & m))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (((action->mod & MOD_MOD5) && !(ev->xkey.state & Mod5Mask)) || (!(action->mod & MOD_MOD5) && (ev->xkey.state & Mod5Mask) && !(Mod5Mask & m))) {
|
1999-08-17 18:12:47 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
D_ACTIONS(("Modifiers passed. keysym == 0x%08x, action->keysym == 0x%08x\n", keysym, action->keysym));
|
2000-01-03 00:07:32 -08:00
|
|
|
if ((ev->xany.type == KeyPress) && (action->keysym) && (keysym != action->keysym)) {
|
1999-08-17 18:12:47 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
D_ACTIONS(("Match found.\n"));
|
|
|
|
/* If we've passed all the above tests, it's a match. Dispatch the handler. */
|
|
|
|
return ((action->handler)(ev, action));
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_t type, void *param) {
|
|
|
|
|
2000-07-03 12:08:41 -07:00
|
|
|
action_t *action;
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2000-07-03 12:08:41 -07:00
|
|
|
if (!action_list || (action = action_find_match(mod, button, keysym)) == NULL) {
|
|
|
|
action = (action_t *) MALLOC(sizeof(action_t));
|
|
|
|
action->next = action_list;
|
|
|
|
action_list = action;
|
1999-08-17 18:12:47 -07:00
|
|
|
} else {
|
2000-07-03 12:08:41 -07:00
|
|
|
if (action->type == ACTION_STRING || action->type == ACTION_ECHO || action->type == ACTION_FUNCTION) {
|
|
|
|
if (action->param.string) {
|
|
|
|
FREE(action->param.string);
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
action->mod = mod;
|
|
|
|
action->button = button;
|
|
|
|
action->type = type;
|
|
|
|
action->keysym = keysym;
|
|
|
|
switch(type) {
|
Wed Apr 5 21:48:39 PDT 2000 Michael Jennings <mej@eterm.org>
There are now two different sets of settings you can save. You can
save user settings, which are the things that one would generally
consider to be user-specific (toggles, text colors, etc.). You can
also save theme settings, which saves *everything*, including the
stuff that user settings don't include (like imageclasses, menus,
etc.). Settings are saved to user.cfg and theme.cfg, respectively.
Also, Eterm will now detect if it cannot write to the location from
which it got the theme (i.e., a system-wide directory), and will fall
back on ~/.Eterm/themes/<theme>. It WILL create this directory tree
if it does not already exist.
Hopefully this will make more people happy. :-)
SVN revision: 2440
2000-04-05 21:52:52 -07:00
|
|
|
case ACTION_STRING:
|
|
|
|
action->handler = (action_handler_t) action_handle_string;
|
|
|
|
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
|
|
|
|
strcpy(action->param.string, (char *) param);
|
|
|
|
parse_escaped_string(action->param.string);
|
|
|
|
break;
|
|
|
|
case ACTION_ECHO:
|
|
|
|
action->handler = (action_handler_t) action_handle_echo;
|
|
|
|
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
|
|
|
|
strcpy(action->param.string, (char *) param);
|
|
|
|
parse_escaped_string(action->param.string);
|
|
|
|
break;
|
2000-07-03 12:08:41 -07:00
|
|
|
case ACTION_FUNCTION:
|
|
|
|
action->handler = (action_handler_t) action_handle_function;
|
|
|
|
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
|
|
|
|
strcpy(action->param.string, (char *) param);
|
|
|
|
parse_escaped_string(action->param.string);
|
|
|
|
break;
|
Wed Apr 5 21:48:39 PDT 2000 Michael Jennings <mej@eterm.org>
There are now two different sets of settings you can save. You can
save user settings, which are the things that one would generally
consider to be user-specific (toggles, text colors, etc.). You can
also save theme settings, which saves *everything*, including the
stuff that user settings don't include (like imageclasses, menus,
etc.). Settings are saved to user.cfg and theme.cfg, respectively.
Also, Eterm will now detect if it cannot write to the location from
which it got the theme (i.e., a system-wide directory), and will fall
back on ~/.Eterm/themes/<theme>. It WILL create this directory tree
if it does not already exist.
Hopefully this will make more people happy. :-)
SVN revision: 2440
2000-04-05 21:52:52 -07:00
|
|
|
case ACTION_MENU:
|
|
|
|
action->handler = (action_handler_t) action_handle_menu;
|
|
|
|
action->param.menu = (menu_t *) param;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
D_ACTIONS(("Added action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
|
|
|
|
}
|
|
|
|
|