📄 event.c
字号:
/*..........................................................................*//* *//* L a s t W a v e K e r n e l 3 . 0 *//* *//* Copyright (C) 1998-2002 Emmanuel Bacry. *//* email : lastwave@cmap.polytechnique.fr *//* *//*..........................................................................*//* *//* This program is a 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 *//* *//* This program 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 (in a file named COPYRIGHT); *//* if not, write to the Free Software Foundation, Inc., *//* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//*..........................................................................*//****************************************************************************//* *//* event.c Deals with window manager events *//* *//****************************************************************************/#include "lastwave.h"#include "xx_system.h"extern char IsEventBlocked();extern char IsEventBlockedSpecial();/* * The name for the special keys * * WARNING : If you add one special key code in window_event.h don't forget to add its name here */ const char SpecialKeyNames[][10] = { "right","up","left","down", "home","end","clear", "delete","tab", "f1","f2","f3","f4","f5","f6","f7","f8","f9","f10","f11","f12","f13","f14","f15", "any"};/************************************************************** * * Miscellaneous Functions * **************************************************************//* * Conversion of a key code to a printable string * It Prints something like "{Ctrl up}" or simply "a". * If flagBraces == YES then it adds some braces if the string is longer than just 1 char. */ char *KeyCode2Str(unsigned long key, char flagBraces){static char result[100]; char str[100],str1[2]; unsigned long k = key & KeyMask; unsigned long m = key & ModMask; str[0] = '\0'; if (key == EOF) strcat(str,"eof"); else { if (m == ModShift) strcat(str,"shift "); else if (m == ModCtrl) strcat(str,"ctrl "); else if (m == ModOpt) strcat(str,"opt "); else if (m == ModOpt + ModCtrl) strcat(str,"ctrlOpt "); else if (m == ModShift + ModCtrl) strcat(str,"ctrlShift "); else if (m == ModShift+ModOpt) strcat(str,"optShift "); else if (m == ModShift+ModOpt+ModCtrl) strcat(str,"ctrlOptShift "); if (k == '\r' || k == '\n') strcat(str,"\n"); else if (k<' ' || k >'~') { if (k == EscapeKC) strcat(str,"esc"); else if (k == EofKC) strcat(str,"eof"); else if (k >= FirstKC && k < LastKC) strcat(str,SpecialKeyNames[k-FirstKC]); else { sprintf(result,"0x%lx",k); strcat(str,result); } } else { str1[0] = k; str1[1] = '\0'; strcat(str,str1); } } if (flagBraces == YES && strlen(str) != 1) { strcpy(result,"{"); strcat(result,str); strcat(result,"}"); } else strcpy(result,str); return(result);}/* * Conversion of a button field to a printable string * It Prints something like "Ctrl left" or simply "left". */ char *ButtonCode2Str(unsigned long button){ static char str[30]; unsigned long k = button & ButtonMask; unsigned long m = button & ModMask; str[0] = '\0'; if (m == ModShift) strcat(str,"shift "); else if (m == ModCtrl) strcat(str,"ctrl "); else if (m == ModOpt) strcat(str,"opt "); else if (m == ModOpt + ModCtrl) strcat(str,"ctrlOpt "); else if (m == ModShift + ModCtrl) strcat(str,"ctrlShift "); else if (m == ModShift+ModOpt) strcat(str,"optShift "); else if (m == ModShift+ModOpt+ModCtrl) strcat(str,"ctrlOptShift "); if (k == LeftButton) strcat(str,"left"); else if (k == RightButton) strcat(str,"right"); else if (k == MiddleButton) strcat(str,"middle"); else strcat(str,"no"); return(str); }/* * Function that associate a combination of modifiers to a string (returns 0 if failed) */static unsigned long Str2Modifiers(char *mod){ if (mod != NULL) { if (!strcmp(mod,"shift")) return(ModShift); if (!strcmp(mod,"ctrl")) return(ModCtrl); if (!strcmp(mod,"ctrlShift")) return(ModCtrl+ModShift); if (!strcmp(mod,"opt")) return(ModOpt); if (!strcmp(mod,"ctrlOpt")) return(ModCtrl+ModOpt); if (!strcmp(mod,"optShift")) return(ModOpt+ModShift); if (!strcmp(mod,"ctrlOptShift")) return(ModCtrl+ModOpt+ModShift); if (!strcmp(mod,"any")) return(ModAny); } return(0);} /************************************************************************ * * Miscellaneous functions on Bindings and binding groups * ************************************************************************//* * The maximum length of binded key sequences */# define MaxLengthKeySeq 40/* * The chained list of the different group names */static BINDINGGROUP theBindingGroups;/* * The chained lists of the terminal bindings */static BINDING theTerminalBindings[LastEventCategory];/* * Initialization of the terminal binding structures */void InitTerminalBindings(void){ int i; for (i=0;i<LastEventCategory;i++) theTerminalBindings[i] = NULL;}/* * Delete a binding group */static void DeleteBindingGroup(BINDINGGROUP g){ g->nBindings--; if (g->nBindings != 0) return; if (g->previous != NULL) { if (g->next != NULL) g->next->previous = g->previous; g->previous->next = g->next; } else { if (g->next != NULL) g->next->previous = NULL; *(g->chainedList) = g->next; } DeleteStr(g->name); if (g->help != NULL) DeleteStr(g->help); Free(g);}/* * Creates a binding group (or returns it if it already exists */static BINDINGGROUP NewBindingGroup(char *name, char *help){ BINDINGGROUP group; /* Looking for the group name. if it exists and creates it if it does not*/ group = theBindingGroups; while (group != NULL) { if (!strcmp(group->name,name)) break; group = group->next; } if (group == NULL) { group = (BINDINGGROUP) Malloc(sizeof (struct bindingGroup)); group->name = CopyStr(name); group->flagActive = NO; group->previous = NULL; group->next = theBindingGroups; group->chainedList = &(theBindingGroups); group->nBindings = 0; group->help = NULL; if (group->next != NULL) group->next->previous = group; theBindingGroups = group; } if (group->help != NULL && help != NULL) { Free(group->help); group->help = NULL; } if (help != NULL) group->help = CopyStr(help); return(group);}/* * Delete a binding */static void DeleteBinding(BINDING b){ DeleteBindingGroup(b->group); if (b->previous != NULL) { if (b->next != NULL) b->next->previous = b->previous; b->previous->next = b->next; } else { if (b->next != NULL) b->next->previous = NULL; *(b->chainedList) = b->next; } DeleteScript(b->script); if (b->keys != NULL) Free(b->keys); if (b->timer != NULL && (b->eventType == TimeEvent || b->eventType == DelayEvent)) XXDeleteTimer(b->timer); Free(b);}/* * Get the corresponding 'category' of an eventType */ static int GetBindingCategory(unsigned long eventType){ if (eventType & ButtonDown || eventType & ButtonUp) return(ButtonEventCategory); if (eventType & KeyDown1 || eventType & KeyUp) return(KeyEventCategory); if (eventType & Enter || eventType & Leave) return(EnterLeaveEventCategory); if (eventType & MouseMotion) return(MotionEventCategory); if (eventType & Draw) return(OtherEventCategory); if (eventType & Del) return(OtherEventCategory); if (eventType & Resize) return(OtherEventCategory); if (eventType & ErrorEvent) return(OtherEventCategory); if (eventType & TimeEvent) return(OtherEventCategory); if (eventType & DelayEvent) return(OtherEventCategory); Errorf("GetBindingCategory() : Unknown event type '%d'",eventType); return(0);}//// Dealing with timer binding//static void ActivateTimerBinding(BINDING b){ if (b->eventType == DelayEvent) { if (b->timer != NULL) Errorf("ActivateTimerBinding() : binding already activated"); b->timer = XXCreateTimer(); XXStartTimer(b->timer,(int) (b->delay*1000),NO); } else if (b->eventType == TimeEvent) { if (b->timer != NULL) Errorf("ActivateTimerBinding() : binding already activated"); b->timer = XXCreateTimer(); XXStartTimer(b->timer,(int) ((b->time-MyTime())*1000),YES); } else Errorf("ActivateTimerBinding() : Bad eventType");}static void DeActivateTimerBinding(BINDING b){ if (b->eventType == DelayEvent || b->eventType == TimeEvent) { if (b->timer != NULL) XXDeleteTimer(b->timer); b->timer = NULL; } else Errorf("DeActivateTimerBinding() : Bad eventType");}/************************************************************************ * * Main command for creating a new binding * ************************************************************************/void C_SetBinding(char **argv){ GCLASS class; char *type; char lookForModifiers; char *groupName; char *help; char *endp; long lval; struct binding b; char **keyList,**list; unsigned long keys[MaxLengthKeySeq]; int nKeys; char *keyName; BINDING binding; BINDING *theBindings = NULL; BINDINGGROUP group; int cat,i; LWFLOAT time; /* First we try to read a group name and a one line help */ argv = ParseArgv(argv,tSTR,&groupName,-1); /* If there is just one argument left then we process ! */ if (argv[1] == NULL) { argv = ParseArgv(argv,tSTR,&help,0); NewBindingGroup(groupName,help); return; } /* Try to read the class */ argv = ParseArgv(argv,tWORD,&help,-1); if (!strcmp("terminal",help)) theBindings = theTerminalBindings; else if ((class = (GCLASS) GetElemHashTable(theGClasses,help)) != NULL) theBindings = class->theBindings; else Errorf("Unknown '%s' gclass",help); /* Initialize the binding fields and some related variables */ b.button = NoButton; b.keys = NULL; b.script = NULL; b.timer = NULL; nKeys = 0; lookForModifiers = YES; /* Get the event type */ argv = ParseArgv(argv,tWORD,&type,-1); /* * Set the 'eventType', 'button', 'modifiers', 'keys', 'keyModifiers' binding fields */ /* Buttons events */ if (!strcmp(type,"leftButtonUp")) {b.eventType = ButtonUp; b.button = LeftButton;} else if (!strcmp(type,"leftButtonDown")) {b.eventType = ButtonDown; b.button = LeftButton;} else if (!strcmp(type,"leftButton")) {b.eventType = ButtonDown+ButtonUp; b.button = LeftButton;} else if (!strcmp(type,"leftButtonMotion")) {b.eventType = MouseMotion; b.button = LeftButton;} else if (!strcmp(type,"middleButtonUp")) {b.eventType = ButtonUp; b.button = MiddleButton;} else if (!strcmp(type,"middleButtonDown")) {b.eventType = ButtonDown; b.button = MiddleButton;} else if (!strcmp(type,"middleButton")) {b.eventType = ButtonDown+ButtonUp; b.button = MiddleButton;} else if (!strcmp(type,"middleButtonMotion")) {b.eventType = MouseMotion; b.button = MiddleButton;} else if (!strcmp(type,"rightButtonUp")) {b.eventType = ButtonUp; b.button = RightButton;} else if (!strcmp(type,"rightButtonDown")) {b.eventType = ButtonDown; b.button = RightButton;} else if (!strcmp(type,"rightButton")) {b.eventType = ButtonDown+ButtonUp; b.button = RightButton;} else if (!strcmp(type,"rightButtonMotion")) {b.eventType = MouseMotion; b.button = RightButton;} else if (!strcmp(type,"buttonUp")) {b.eventType = ButtonUp; b.button = LeftButton + MiddleButton + RightButton;} else if (!strcmp(type,"buttonDown")) {b.eventType = ButtonDown; b.button = LeftButton + MiddleButton + RightButton;} else if (!strcmp(type,"buttonMotion")) {b.eventType = MouseMotion; b.button = LeftButton + MiddleButton + RightButton;} /* Motion/Enter/leave events */ else if (!strcmp(type,"motion")) {b.eventType = MouseMotion;b.button = NoButton;} else if (!strcmp(type,"leave")) {lookForModifiers = NO;b.eventType = Leave;} else if (!strcmp(type,"enter")) {lookForModifiers = NO;b.eventType = Enter;} else if (!strcmp(type,"enterLeave")) {lookForModifiers = NO;b.eventType = Enter+Leave;} /* Key Events */ else if (!strncmp(type,"key",3)) { /* Reading the list of keys */ argv = ParseArgv(argv,tLIST,&keyList,-1); /* Loop on this list */ while (*keyList != NULL) { if (nKeys >= MaxLengthKeySeq) Errorf("Binded key sequence is too long (should be <= %d)",MaxLengthKeySeq); /* Parse the key name and the eventual modifier keys */ ParseWordList(*keyList,&list); keyList++; if (*list == NULL) Errorf("Missing key name for key binding"); if (*(list+1) == NULL) { keyName = *list; keys[nKeys] = 0; } else if (*(list+2) == NULL) { keys[nKeys] = Str2Modifiers(*list);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -