📄 event.svga
字号:
Halts program execution until a specified event occurs. The event is
returned. All pending events not in the specified mask will be ignored and
removed from the queue.
****************************************************************************/
void _WDAPI WD_haltEvent(
WD_event *evt,
uint mask)
{
do { /* Wait for an event */
WD_getEvent(evt,EVT_EVERYEVT);
} while (!(evt->what & mask));
}
/****************************************************************************
PARAMETERS:
evt - Place to store event
mask - Event mask to use
RETURNS:
True if an event was pending.
REMARKS:
Retrieves the next pending event defined in 'mask' from the event queue.
The event queue is adjusted to reflect the new state after the event has
been removed.
****************************************************************************/
ibool _WDAPI WD_getEvent(
WD_event *evt,
uint mask)
{
int evtID,next,prev;
pumpEvents();
if (moveCursor)
moveCursor(mx,my); /* Move the mouse cursor */
evt->what = EVT_NULLEVT; /* Default to null event */
if (count) {
for (evtID = head; evtID != -1; evtID = evtq[evtID].next) {
if (evtq[evtID].what & mask)
break; /* Found an event */
}
if (evtID == -1)
return false; /* Event was not found */
next = evtq[evtID].next;
prev = evtq[evtID].prev;
if (prev != -1)
evtq[prev].next = next;
else
head = next;
if (next != -1)
evtq[next].prev = prev;
else
tail = prev;
*evt = evtq[evtID]; /* Return the event */
evtq[evtID].next = freeHead; /* and return to free list */
freeHead = evtID;
count--;
if (evt->what == EVT_MOUSEMOVE)
oldMove = -1;
if (evt->what == EVT_KEYREPEAT)
oldKey = -1;
}
return evt->what != EVT_NULLEVT;
}
/****************************************************************************
PARAMETERS:
evt - Place to store event
mask - Event mask to use
RETURNS:
True if an event is pending.
REMARKS:
Peeks at the next pending event defined in 'mask' in the event queue. The
event is not removed from the event queue.
****************************************************************************/
ibool _WDAPI WD_peekEvent(
WD_event *evt,
uint mask)
{
int evtID;
pumpEvents();
if (moveCursor)
moveCursor(mx,my); /* Move the mouse cursor */
evt->what = EVT_NULLEVT; /* Default to null event */
if (count) {
for (evtID = head; evtID != -1; evtID = evtq[evtID].next) {
if (evtq[evtID].what & mask)
break; /* Found an event */
}
if (evtID == -1)
return false; /* Event was not found */
*evt = evtq[evtID]; /* Return the event */
}
return evt->what != EVT_NULLEVT;
}
/****************************************************************************
PARAMETERS:
hwndMain - Handle to main window
_xRes - X resolution of graphics mode to be used
_yRes - Y resolulion of graphics mode to be used
RETURNS:
Handle to the fullscreen event window if (we return hwndMain on Linux)
REMARKS:
Initiliase the event handling module. Here we install our mouse handling
ISR to be called whenever any button's are pressed or released. We also
build the free list of events in the event queue.
****************************************************************************/
WD_HWND _WDAPI WD_startFullScreen(
WD_HWND hwndMain,
int _xRes,
int _yRes)
{
int i;
struct termios conf;
if (!installed) {
Gpm_Connect gpm;
/* Build free list, and initialise global data structures */
for (i = 0; i < EVENTQSIZE; i++)
evtq[i].next = i+1;
evtq[EVENTQSIZE-1].next = -1; /* Terminate list */
count = freeHead = 0;
head = tail = -1;
oldMove = -1;
oldKey = -1;
xRes = _xRes;
yRes = _yRes;
/* Open the console device and initialise it for raw mode */
tty_fd = PM_openConsole();
/* Wait until virtual terminal is active and take over control */
wait_vt_active();
take_vt_control();
/* Initialise keyboard handling to raw mode */
if (ioctl(tty_fd, KDGKBMODE, &oldkbmode)) {
printf("WD_startFullScreen: cannot get keyboard mode.\n");
exit(-1);
}
old_flags = fcntl(tty_fd,F_GETFL);
fcntl(tty_fd,F_SETFL,old_flags |= O_NONBLOCK);
tcgetattr(tty_fd, &conf);
old_conf = conf;
conf.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | NOFLSH | ISIG);
conf.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | BRKINT | PARMRK | INPCK | IUCLC | IXON | IXOFF);
conf.c_iflag |= (IGNBRK | IGNPAR);
conf.c_cc[VMIN] = 1;
conf.c_cc[VTIME] = 0;
conf.c_cc[VSUSP] = 0;
tcsetattr(tty_fd, TCSAFLUSH, &conf);
ioctl(tty_fd, KDSKBMODE, K_MEDIUMRAW);
/* Clear the keyboard state information */
memset(key_down, 0, sizeof(key_down));
ioctl(tty_fd,KDSETLED,key_modifiers = 0);
/* Initialize the mouse connection
The user *MUST* run gpm with the option -R for this to work (or have a MouseSystems mouse)
*/
if(Gpm_Open(&gpm,0) > 0){ /* GPM available */
if ((conn = open(GPM_NODE_FIFO,O_RDONLY|O_SYNC)) < 0)
fprintf(stderr,"WD_startFullScreen: Can't open mouse connection.\n");
}else{
fprintf(stderr,"Warning: when not using gpm -R, only MouseSystems mice are currently supported.\n");
if ((conn = open("/dev/mouse",O_RDONLY|O_SYNC)) < 0)
fprintf(stderr,"WD_startFullScreen: Can't open /dev/mouse.\n");
}
Gpm_Close();
/* TODO: Scale the mouse coordinates to the specific resolution */
/* Save the state of the console */
if ((stateBuf = malloc(PM_getConsoleStateSize())) == NULL) {
printf("Out of memory!\n");
exit(-1);
}
PM_saveConsoleState(stateBuf,tty_fd);
initmode = VBE_getVideoMode();
/* Initialize the signal handler for timer events */
signal(SIGALRM, timerHandler);
/* Capture termination signals so we can clean up properly */
signal(SIGTERM, exitHandler);
signal(SIGINT, exitHandler);
signal(SIGQUIT, exitHandler);
atexit(restore_term);
/* Signal that we are installed */
installed = true;
}
return hwndMain;
}
/****************************************************************************
REMARKS:
Lets the library know when fullscreen graphics mode has been initialized so
that we can properly scale the mouse driver coordinates.
****************************************************************************/
void _WDAPI WD_inFullScreen(void)
{
/* Nothing to do in here */
}
/****************************************************************************
REMARKS:
Suspends all of our event handling operations. This is also used to
de-install the event handling code.
****************************************************************************/
void _WDAPI WD_restoreGDI(void)
{
restore_term();
}
/****************************************************************************
PARAMETERS:
ticks - Number of ticks between timer tick messages
RETURNS:
Previous value for the timer tick event spacing.
REMARKS:
The event module will automatically generate periodic timer tick events for
you, with 'ticks' between each event posting. If you set the value of
'ticks' to 0, the timer tick events are turned off.
****************************************************************************/
int _WDAPI WD_setTimerTick(
int ticks)
{
int old;
struct itimerval tim;
long ms = TICKS_TO_USEC(ticks);
getitimer(ITIMER_REAL, &tim);
old = USEC_TO_TICKS(tim.it_value.tv_sec*1000000.0 + tim.it_value.tv_usec);
tim.it_interval.tv_sec = ms / 1000000;
tim.it_interval.tv_usec = ms % 1000000;
setitimer(ITIMER_REAL, &tim, NULL);
return old;
}
/****************************************************************************
PARAMETERS:
saveState - Address of suspend app callback to register
REMARKS:
Registers a user application supplied suspend application callback so that
we can properly handle virtual terminal switching.
****************************************************************************/
void _WDAPI WD_setSuspendAppCallback(
int (_ASMAPI *saveState)(int flags))
{
suspendAppCallback = saveState;
}
/****************************************************************************
PARAMETERS:
x - New X coordinate to move the mouse cursor to
y - New Y coordinate to move the mouse cursor to
REMARKS:
Moves to mouse cursor to the specified coordinate.
****************************************************************************/
void _WDAPI WD_setMousePos(
int x,
int y)
{
mx = x;
my = y;
}
/****************************************************************************
PARAMETERS:
x - Place to store X coordinate of mouse cursor
y - Place to store Y coordinate of mouse cursor
REMARKS:
Reads the current mouse cursor location int *screen* coordinates.
****************************************************************************/
void _WDAPI WD_getMousePos(
int *x,
int *y)
{
*x = mx;
*y = my;
}
/****************************************************************************
PARAMETERS:
mcb - Address of mouse callback function
REMARKS:
Registers an application supplied mouse callback function that is called
whenever the mouse cursor moves.
****************************************************************************/
void _WDAPI WD_setMouseCallback(
void (_ASMAPI *mcb)(int x,int y))
{
moveCursor = mcb;
}
/****************************************************************************
PARAMETERS:
xRes - New X resolution of graphics mode
yRes - New Y resolution of graphics mode
REMARKS:
This is called to inform the event handling code that the screen resolution
has changed so that the mouse coordinates can be scaled appropriately.
****************************************************************************/
void _WDAPI WD_changeResolution(
int xRes,
int yRes)
{
// Gpm_FitValues(xRes, yRes); // ??
}
/****************************************************************************
PARAMETERS:
scancode - Scan code to check if a key is down
REMARKS:
Determines if a particular key is down based on the scan code for the key.
****************************************************************************/
ibool _WDAPI WD_isKeyDown(
uchar scancode)
{
return key_down[scancode];
}
/****************************************************************************
REMARKS:
Determines if the application needs to run in safe mode. Not necessary for
anything but broken Windows 95 display drivers so we return false for
Linux.
****************************************************************************/
int _WDAPI WD_isSafeMode(void)
{
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -