Method for routing events from key strokes in a multi-processing computer systems4896290Abstract A computer system in which multiple processes may run concurrently includes a window manager for displaying windows associated with different processes. One of the processes represented by a window may be designated as active. Keystrokes are translated by a keyboard driver to events represented by keycodes. The keycodes are routed to processes with which they are associated by reference to a routing table. Unless otherwise indicated, a keycode is routed to the active process. Where a keycode is associated with and transferred to the window manager, subsequent keycodes are stored in a typeahead buffer. The window manager may modify the routing table. After completion of the window manager operation, all keycodes remaining in the buffer are routed to their associated processes as determined by the modified routing table. Claims What is claimed is: Description BACKGROUND OF THE INVENTION
______________________________________
UIvget(specp, wait, remove, eventp)
______________________________________
UIVSPEC *specp;
INT wait;
INT remove;
UNIREC *eventp;
______________________________________
The specp variable is a pointer to an array of UIVSPEC structures each specifying one or more events which may be returned. As set forth above, the last entry in the array should have the "type" variable set to a value which indicates that that specification ends the array. If the specp pointer is null, the first event in the event queue will be returned. The wait variable is a flag indicating whether the process should be blocked to wait for an event matching this specification if none is found in the queue. The remove variable is a flag indicating whether the event record is to be removed from the queue once found. The eventp variable is pointer to a UIVREC structure to receive the found event. This function looks for an event in the event queue which matches the given specification. This specification may include one or more different specifications of the type shown in Listing 5 arranged as an array terminated with an empty specification, as discussed above. The following function allows the calling process to put an event back into its event queue in the order specified by the event's time stamp.
______________________________________
UIvrequeue(eventp, countp)
______________________________________
UIVREC *eventp;
ULONG *countp;
______________________________________
The event variable is a pointer to the UIVREC structure which contains the event to be placed back on queue. The countp parameter, if non-zero is a pointer to a variable to receive the number of events in the current process's event queue after this event is reposted. The UIvrequeue functions allows a calling process which has removed an event from the queue, but which does not wish to process the event, to return it to the queue so that it can be processed later. If requested, this function also returns the number of events in the event queue. The following function allows a process to send an event to the event queue of another process.
______________________________________
UIvpost(eventp, process, wait, countp)
______________________________________
UIVREC *eventp;
K --PROCESS process;
INT wait,
ULONG *countp;
______________________________________
The event parameter is a pointer to the UIVREC structure which defines the event to be posted. The process parameter is the process I.D. to which the event is to be sent. The wait parameter is a flag indicating whether the process blocked to wait for the event to be posted if the receiving processes event queue is full. The countp parameter, if not null, is a pointer to a variable to receive the number of events currently in the receiving processes event queue. The following function will flush all events which match the given specification list from the event queue.
______________________________________
UIvflush(specp)
______________________________________
UIVSPEC *specp;
______________________________________
The specp parameter is a pointer to an array of UIVSPEC structures which specify the events to be flushed. The following function allows a process to determine the number of events in another processor's event queue and the maximum number of events which that process may have in its event queue.
______________________________________
UIvgtcount(process, countp, maxp)
______________________________________
K-PROCESS process;
ULONG *countp;
ULONG *maxp;
______________________________________
The process variable is the process I.D. The countp parameter is a pointer to a variable to receive the number of events currently in the specified processor's event queue. The maxp parameter is a pointer to a variable to receive the maximum number of events which may be queued in the specified processor's event queue. Referring to FIG. 1, there is shown a diagram which illustrates the flow of data and signals between the various portions of a typical system incorporating the present invention. In FIG. 1, keyboard driver 10 represents a process which accepts input data from a user, such as might be typed on a keyboard 12 or which might be indicated by manipulations of a mouse type device 14. Associated with keyboard driver 10 is a translation table 16, described in more detail below. The keyboard driver receives scan codes from keyboard 12 indicating the make and break status of each of the keys on the keyboard. In the described embodiment, these scan codes are 8 bites long. It also may receive data from a mouse 14 indicating mouse movements and activation of mouse buttons. It should be appreciated that other types of input sources, such as touch screen indicators may used in place of or in addition to the keyboard and/or mouse input devices illustrated in FIG. 1. The incorporation of such devices into the present invention is easily done by one of ordinary skill in the art. The output from keyboard driver 10 is a key code which is 16 bytes in the described embodiment. Each key code is passed to a procedure 20 which will be referred to as the input funnel. The input funnel is responsible for assuring that the codes from keyboard driver 10 are routed to the appropriate process running on the system. This process might be an application program or alternatively may be a signal to the operating system indicating that certain functions are to take place. For example, a user running an applications program might desire to change the window size, and the keys indicating this change of window size would be sent to a window manager process, illustrated by block 30 in FIG. 1, which would carry out the appropriate steps in response to the users input. The input funnel 20 has associated with it a routing table 22, described in more detail below, and which includes data representative of the various processes to which the input funnel may send events. In FIG. 1, a block 40 represents a first application program with which a user is interacting. In the described embodiment, a user may have several programs executing at one time. These programs will each have individual windows on the screen which may vary in size from a small icon, indicating that the program is loaded, to a larger window which displays data from the program. In the described embodiment, many windows may be present on the user's display simultaneously, reflecting the different programs and processes which may be running concurrently. However, input data from a user may be sent, to, i.e., put in the event queue 46 of, only a single process at one time. The process to which data may be sent is displayed on the screen in a window denoted as the "active window", as illustrated by dotted box 50 in FIG. 1. Additional applications programs 42 and 44 are illustrated in FIG. 1. These programs may be executing in the background or may be suspended, however, only the program 40 in the active window may receive user data from the keyboard. A user may send data to other applications by making another application's window active in place of the current active window. Selected keystrokes may be interrupted by the input funnel and put in the event queue of applications programs not in the active window and to other processes, as indicated by dashed lines 21, as described below. The operating system in the described embodiment includes a window manager process 30 which controls the data displayed to a user on a device such as CRT display. Window manager 30 may control, for example, the number, size, location, and updating of various windows displaying the output from different programs to a user. The user communicates with window manager 30 via input from keyboard 12 or mouse 14. This input is applied via keyboard driver to input funnel 20. Input funnel 20 includes a routing table 22 which is used to identify those input events from the user which should be directed to the window manager 30. For example, a particular key, such as a function key, is typically defined to be the key which a user presses to interact directly with window manager 30. In response to the depression of this key, keyboard driver 10 will pass a key code representative of that key to the input funnel 20. Input funnel 20 uses data in routing table 22 to identify this key as intended for the window manager process 30 and sends this key directly to the window manager. In response to a key intended for window manager 30, the input funnel 20 also sets a flag indicating that the window manager, has been called. While this flag is set, all further keyboard input is routed by the input funnel 20 to a typeahead process 60. This is necessary because the ultimate destination of keys typed after a window function is called may not be the application program which is currently in the active window. This is described in more detail below. Additional keys typed after the window manager has been called are sent by input funnel 20 to the typeahead process 60 and are stored in a typeahead buffer 62 pending the completion of the window operation. Typically, window operations require additional input to complete the operation, and window manager 30 will receive these additional key codes from typeahead buffer 60, as described in more detail below. Thus input funnel 20 in conjunction with typeahead process 60 ensures that keys typed by a user after the initiation of a window event are sent to the correct destination. The operation of keyboard driver 10 is similar to known types of keyboard device drivers, with one exception discussed below. The functions performed by keyboard driver 10 are shown generally in FIG. 2. It should be appreciated that the specific program code needed to implement these functions will vary, depending upon the particular programming language and computer processor being used. In the described embodiment, keyboard driver 10 is interrupt driven in response to the depression of a key, although it could equally well be called by being polled. Keyboard driver 10 first receives a scan code sent by keyboard 12 in response to the depression or release of a keyboard key, block 100. In the preferred embodiment, the scan codes from the keyboard are 8 bytes long, giving 256 possible different scan codes. The following description assumes operation of the keyboard driver wherein a single key code is sent in response to the depression of the key, and no key code is sent upon the release of the key. Additionally, the keyboard driver may be designed so that holding a key down for a predetermined period will cause the keyboard driver to send multiple key codes representative of that key to provide an automatic repeat key function. In some circumstances, it is desirable to provide a keyboard output representative of when a key is depressed and when it is released, also known as typeamatic action. The present invention may be used with such an implementation also, and such a modification with the embodiment described herein is within the capabilities of one ordinary skill in the art. Following receipt of a scan code from the keyboard, block 100, the keyboard driver checks the scan code to determine whether the depressed key is a shift key, block 102. Shift keys serve to modify the meaning of a subsequently depressed key, and include keys such as upper case shift, control, ALT, and others. Additionally, combinations of shift keys may be used. In the present embodiment, 10 different shift keys and combinations are defined. Other key combinations may be defined which have special functions or meanings to the system or a process. For example, it is typical to define a three key combination to reboot the computer or workstation. Although not shown in FIG. 2, these combinations may be identified in block 102 and the appropriate operational function carried out in response thereto. If the depressed key is a shift key, the keyboard driver proceeds to block 104 where it changes the shift state. The keyboard driver process then ends and the keyboard driver returns to the previous routine, block 110. If the keyboard driver determines that the depressed key is not a shift key, it proceeds to block 106 where the keyboard driver gets the appropriate key code from translation table 16 and forwards it to the input funnel at 108. Referring to FIG. 2A, there is a diagram which shows how the translation table is implemented in the present embodiment. The translation table includes a plurality of planes 112a, 112b and 112n each of which represents a different shift state. Within each plane are stored the key codes which are to be generated in response to the activation of each non-shift key. Thus, the shift state provides an index into the translation table while the scan code from the activated key provides the offset. In the described embodiment, each of the key codes stored in translation table 16 is composed of 16 bits. It should be appreciated that storing the key codes in the manner described above allows an arbitrary number of different shift states to be defined while requiring memory only for those planes, or shift states, which are, in fact, being used by a particular process or application program. Furthermore, the translation table maybe changed to accommodate the requirements of different programs. Thus, by writing new data into translation table 16 used by keyboard driver 10, different key codes will be produced by the keyboard driver in response to keys pressed by a user. In the present embodiment, window manager 30 controls which application is in the active window 50, and thus which application is responding to keys typed at the keyboard by a user. When a user switches the active window from one application program to another application program, window manager 30 will, if required, replace the translation table 16 in keyboard driver 10 with a new translation table suitable for the new application program. After the proper key code has been determined from translation table 16, the keyboard driver goes to the input funnel routine 108, shown in more detail in FIG. 3. FIG. 3 shows the functions performed by the input funnel. After receiving a key code, block 120, from the keyboard driver, the input funnel checks the typeahead flag to see whether or not it is set, block 122. If so, the input funnel sends the key code to the typeahead process, block 124, described in more detail below, followed by a return 150. Otherwise the input funnel looks up the key code in the routing table, block 126. The structure of the routing table is shown in more detail in FIG. 3A. The input funnel first takes the 8 most significant bits of the 16 bit key code and uses that value as an index into a first table 200 identified as T1 in FIG. 3A. Table T1 includes 256 entries each of which consists of a pointer to the beginning of a secondary table elsewhere in memory described below. In the described embodiment, the pointers in table T1 are 32 bits long. If the value within table T1 is a null, or 0, value, block 128, the input funnel sends the key code directly to the application program, at block 130, which is currently running in the the active window. A return 148 follows. A process I.D. table 202 is kept by the system which gives the process identification numbers for all of the currently active processes. In the described embodiment, up to 48 different processes may be active at one time. The process I.D. in the first table entry is always that of the application running in the active window. The process I.D. in the second table entry is that of the window manager process 30. If the value in table T1 is other then null, the input funnel uses the 32 bit pointer as an index to a 256-byte secondary table and uses the 8 least significant bits as as an offset into that table, block 132. Referring to FIG. 3A, the first entry 204 in table T1 is null. This indicates that the key code should be sent directly to the process in the active window, and thus no secondary table is required. The second entry 204 in table T1 is an address value designated as A1. This address indicates first entry in a secondary table 210. The input funnel takes the 8 least significant bytes of the key code and uses that as an offset into table 210. Table 210 and each of the other secondary tables which may be stored each include a numerical value between 1 and 48 which indicates the process to which the key code will be sent. After looking up the process number in the appropriate secondary table, the input funnel refers, block 134, to the process I.D. table 202 to find the process I.D. number which is used to inform the system of the process to which the current key code event is to be sent, block 138. Once the key code is sent, the input funnel returns, block 140. It should be appreciated that the above described procedure results in a sparse array for the translation table in which a primary table T1 and one or more secondary tables are stored to identify key codes which are sent to processes other than the currently active application. The values in the secondary tables indicate the process to which the key code is sent. A value of 0 indicates that the key code is to be sent to the currently active application. Thus, a key code having the 8 most significant bytes equal to a value other than null may still be sent to the active application if the corresponding entry in the appropriate secondary table is 0. A value of 1 in the secondary table indicates that the key code is to be sent to the window manager. This is a special situation which causes the input funnel to activate the typeahead buffer. Thus, if the input funnel determines that the key is for the window manager, block 136, the input funnel sets a typeahead process flag, block 142, and sends the key to the window manager, block 144, followed by a return 146. The next time the input funnel is called, the typeahead flag is detected in block 122, and all further keyboard input is sent to the typeahead process, block 124, as long as the typeahead process is active, as described below. FIG. 4 shows the steps carried out by the typeahead process 60. When it receives an event, the typeahead process stores the event in typeahead buffer 62, block 160. The typeahead process next checks a flush flag, block 162. The flush flag is set by the window manager and indicates that a window event has been completed and that all further key codes stored in typeahead buffer 62 are to be rerouted through the input funnel 20 to the appropriate application. Thus, if the flush flag is set, the typeahead process will send the next event in the typeahead buffer to the input funnel, block 164. Typeahead process 60 next checks to determine whether the typeahead buffer is empty, block 166. If not, it returns to block 164 and sends the next event in the typeahead buffer to the input funnel. If the typeahead buffer is empty, the flush flag is reset, block 170 and the typeahead process resets the typeahead flag, block 168, in the input funnel (checked in block 122) to cause the input funnel to resume sending user events directly to their destination, rather than to the typeahead process, block 170. A return 180 follows. If the flush flag is not set, block 162, the typeahead process may return as soon as the key code is stored in the typeahead buffer 62. Alternately the typeahead process may proceed to block 176. A first key code which is identified as being intended for the window manager 30 is sent directly by the input funnel to the window manager process, block 144. Normally, a window function will require further key strokes from a user for completion. These key strokes are provided by the typeahead process by a routine shown generally at 174. This routine may be entered immediately following block 162, it may be periodically activated by a polling routine, or it may be called by the window manager 30 when the window manager determines that it needs an additional key. If called by other than the window manager, the typeahead process checks the window manager request flag, block 176 to determine whether it should send a key code to the window manager. If so, or if the typeahead process is called directly by the window manager, it sends the next event in the typeahead buffer 62 to window manager, block 178. The functions performed by the window manager 30 will vary depending upon the particular type of program being run, the complexity of the window structure, and other parameters related to the hardware and software of a particular system. The implementation of these different functions is well within the ordinary skill of those in the art. FIG. 5 shows certain portions of routines which will be carried out by window manager process 30 and which interrelate with the above described functions. The window manager is called up by a user by the depression of a key corresponding to a window function. This key is recognized by the input funnel based on data in the keyboard translation table 16 and the input funnel routing table 22, as described above. After the window manager routine is begun by the depression of a window function key, block 180, the window manager next determines the appropriate action to be carried out in response to that key, block 182. The window manager executes the appropriate steps block 184 and then determines whether another key or event is needed for further execution, block 186. Some window functions may be accomplished with a single key stroke. For example, a window close function may be activated with a single key stroke. Other window functions may require more than one key. For example, a window resize function will require that the window manager be called up, the resize operation be initiated, and then the window manager will request cursor key strokes or mouse movements and buttons from the typeahead process in order to receive input from the user as to the particular resize operation. In such cases, the window manager will determine that it needs additional input to complete the operation, block 188, and will repeat the above described sequence of operation until it determines that the window operation is complete, block 186. The flush flag in the typehead process is set, block 187, and the window manager returns, block 189. In carrying out the above described operations, the window manager may change the application running in the active window. In this case, the sequence of steps shown in FIG. 6 would be carried out. This sequence may be integrated as part of the execution of the window function being performed in block 184, or it may be located elsewhere in the window manager functioning. In FIG. 6, the window manager first checks to determine whether a new application has been made active, block 192. If not, the following steps are skipped, and the window manager proceeds to return or to carry out the next function, block 199. Otherwise, the window manager will check to determine whether a new translation table is needed, block 194. A default translation table is provided by the operating system, and many, if not most, applications programs will use the default key translation table. In this case, a new translation table does not need to be loaded. However, where an application requires a new translation table, the window manager will load the appropriate translation table when the new application becomes the active application, as shown in FIG. 6 at 196. Next, at 198, the window manager updates the process I.D table 202. As discussed above, the first entry in the process I.D. table always corresponds with the application running in the active window. Thus, any change of the application in the active window will require updating the process I.D. table. Invocation of some applications programs will also require changes in the routing tables 22. As described above, user key strokes are sent either to the window manager or to the program running in the active window. Some programs may, however, perform functions in the background in response to particular keys or key combinations entered by a user. For example, a keyboard macroprogram may be activated by a user and record succeeding key strokes until deactivated by the user. A debugger program, as another example, may be activated or deactivated by a user while the program runs in the active window. Such programs when first invoked would call the system and would appropriately modify tables 200 and 210 so that the proper key codes would be sent as events to these operations operating in the background. It should be appreciated that in applying the teachings set forth above, those of ordinary skill in the art will make modifications and additions which are within the scope of the present invention. Accordingly, the description herein of a preferred embodiment should not be taken as a limitation on the invention, but rather the invention should only be interpreted in accordance with the appended claims.
|
Same subclass Same class Consider this |
||||||||||
