Пример #1
0
void glk_cancel_line_event(window_t *win, event_t *ev)
{
    event_t dummyev;
    
    if (!ev) {
        ev = &dummyev;
    }

    gli_event_clearevent(ev);
    
    if (!win) {
        gli_strict_warning("cancel_line_event: invalid ref");
        return;
    }
    
    switch (win->type) {
        case wintype_TextBuffer:
            if (win->line_request) {
                win_textbuffer_cancel_line(win, ev);
                win->inputgen = 0;
            }
            break;
        case wintype_TextGrid:
            if (win->line_request) {
                win_textgrid_cancel_line(win, ev);
                win->inputgen = 0;
            }
            break;
        default:
            /* do nothing */
            break;
    }
}
Пример #2
0
void glk_select_poll(event_t *event)
{
    gli_event_clearevent(event);
    
    /* This only checks for timer events at the moment, and we don't
        support any, so I guess this is a pretty simple function. */
}
Пример #3
0
void gli_select(event_t *event, int block)
{
    gli_curevent = event;
    gli_event_clearevent(event);

    gli_input_guess_focus();

    if (block)
    {
	while (gli_curevent->type == evtype_None && !timeouts)
	    gtk_main_iteration();
    }

    else
    {
	while (gtk_events_pending() && !timeouts)
	    gtk_main_iteration();
    }

    if (gli_curevent->type == evtype_None && timeouts)
    {
	gli_event_store(evtype_Timer, NULL, 0, 0);
	timeouts = 0;
    }

    gli_curevent = NULL;
}
Пример #4
0
void glk_select_poll(event_t *event)
{
    int firsttime = TRUE;
    
    curevent = event;
    gli_event_clearevent(curevent);
    
    gli_windows_update();
    
    /* Now we check, once, all the stuff that glk_select() checks
        periodically. This includes rearrange events and timer events. 
       Yes, this looks like a loop, but that's just so we can use
        continue; it executes exactly once. */
        
    while (firsttime) {
        firsttime = FALSE;

        gli_windows_place_cursor();
        refresh();
        
#ifdef OPT_USE_SIGNALS

        /* We don't need to check to see if the program has just resumed. 
            The only reason glk_select() does that is to refresh the screen,
            and that's just been done anyhow. */

#ifdef OPT_WINCHANGED_SIGNAL
        /* Check to see if the screen-size has changed. The 
            screen_size_changed flag is set by the SIGWINCH signal
            handler. */
        if (screen_size_changed) {
            screen_size_changed = FALSE;
            gli_windows_size_change();
            continue;
        }
#endif /* OPT_WINCHANGED_SIGNAL */

#endif /* OPT_USE_SIGNALS */

#ifdef OPT_TIMED_INPUT
        /* Check to see if we've passed next_time. */
        if (timing_msec) {
            struct timeval tv;
            gettimeofday(&tv, NULL);
            if (tv.tv_sec > next_time.tv_sec
                || (tv.tv_sec == next_time.tv_sec &&
                    tv.tv_usec > next_time.tv_usec)) {
                next_time = tv;
                add_millisec_to_time(&next_time, timing_msec);
                gli_event_store(evtype_Timer, NULL, 0, 0);
                continue;
            }
        }
#endif /* OPT_TIMED_INPUT */
    }

    curevent = NULL;
}
Пример #5
0
void gli_select(event_t *event, int block)
{
    MSG msg;

    gli_curevent = event;
    gli_event_clearevent(event);

    gli_input_guess_focus();

    if (block)
    {
	while (gli_curevent->type == evtype_None && !timeouts)
	{
	    int code = GetMessage(&msg, NULL, 0, 0);
	    if (code < 0)
		exit(1);
	    if (code > 0)
	    {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	    }
	}
    }

    else
    {
	while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0 && !timeouts)
	{
	    TranslateMessage(&msg);
	    DispatchMessage(&msg);
	}
    }

    if (gli_curevent->type == evtype_None && timeouts)
    {
	gli_event_store(evtype_Timer, NULL, 0, 0);
	timeouts = 0;
    }

    gli_curevent = NULL;
}
Пример #6
0
void gli_select(event_t *event, int polled)
{
    MSG msg;

    gli_curevent = event;
    gli_event_clearevent(event);

    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    gli_dispatch_event(gli_curevent, polled);

    if (!polled)
    {
        while (gli_curevent->type == evtype_None && !timeouts)
        {
            int code = GetMessage(&msg, NULL, 0, 0);
            if (code < 0)
                exit(1);
            if (code > 0)
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            gli_dispatch_event(gli_curevent, polled);
        }
    }

    if (gli_curevent->type == evtype_None && timeouts)
    {
        gli_event_store(evtype_Timer, NULL, 0, 0);
        gli_dispatch_event(gli_curevent, polled);
        timeouts = 0;
    }

    gli_curevent = NULL;
}
Пример #7
0
void glk_select(event_t *event)
{
    window_t *win = gli_window_get();
    
    gli_event_clearevent(event);
    
    fflush(stdout);

    if (!win || !(win->char_request || win->line_request)) {
        /* No input requests. This is legal, but a pity, because the
            correct behavior is to wait forever. Bye bye. */
        while (1) {
            getchar();
        }
    }
    
    if (win->char_request) {
        char buf[256];
        glui32 kval;
        int len;
        
        /* How cheap are we? We don't want to fiddle with line 
            buffering, so we just accept an entire line (terminated by 
            return) and use the first key. Remember that return has to 
            be turned into a special keycode (and so would other keys,
            if we could recognize them.) */
 
        fgets(buf, 255, stdin);
        if (!gli_utf8input) {
            kval = buf[0];
        }
        else {
            int val;
            val = strlen(buf);
            if (val && (buf[val-1] == '\n' || buf[val-1] == '\r'))
                val--;
            len = gli_parse_utf8(buf, val, &kval, 1);
            if (!len)
                kval = '\n';
        }

        if (kval == '\r' || kval == '\n') {
            kval = keycode_Return;
        }
        else {
            if (!win->char_request_uni && kval >= 0x100)
                kval = '?';
        }
        
        win->char_request = FALSE;
        event->type = evtype_CharInput;
        event->win = win;
        event->val1 = kval;
        
    }
    else {
        /* line_request */
        char buf[256];
        int val;
        glui32 ix;

        fgets(buf, 255, stdin);
        val = strlen(buf);
        if (val && (buf[val-1] == '\n' || buf[val-1] == '\r'))
            val--;

        if (!gli_utf8input) {
            if (val > win->linebuflen)
                val = win->linebuflen;
            if (!win->line_request_uni) {
                memcpy(win->linebuf, buf, val);
            }
            else {
                glui32 *destbuf = (glui32 *)win->linebuf;
                for (ix=0; ix<val; ix++)
                    destbuf[ix] = (glui32)(((unsigned char *)buf)[ix]);
            }
        }
        else {
            glui32 ubuf[256];
            val = gli_parse_utf8(buf, val, ubuf, 256);
            if (val > win->linebuflen)
                val = win->linebuflen;
            if (!win->line_request_uni) {
                unsigned char *destbuf = (unsigned char *)win->linebuf;
                for (ix=0; ix<val; ix++) {
                    glui32 kval = ubuf[ix];
                    if (kval >= 0x100)
                        kval = '?';
                    destbuf[ix] = kval;
                }
            }
            else {
                /* We ought to perform Unicode Normalization Form C here. */
                glui32 *destbuf = (glui32 *)win->linebuf;
                for (ix=0; ix<val; ix++)
                    destbuf[ix] = ubuf[ix];
            }
        }

        if (!win->line_request_uni) {
            if (win->echostr) {
                gli_stream_echo_line(win->echostr, win->linebuf, val);
            }
        }
        else {
            if (win->echostr) {
                gli_stream_echo_line_uni(win->echostr, win->linebuf, val);
            }
        }

        if (gli_unregister_arr) {
            if (!win->line_request_uni)
                (*gli_unregister_arr)(win->linebuf, win->linebuflen, 
                    "&+#!Cn", win->inarrayrock);
            else
                (*gli_unregister_arr)(win->linebuf, win->linebuflen, 
                    "&+#!Iu", win->inarrayrock);
        }

        win->line_request = FALSE;
        win->line_request_uni = FALSE;
        win->linebuf = NULL;
        event->type = evtype_LineInput;
        event->win = win;
        event->val1 = val;
    }
}
Пример #8
0
void glk_select(event_t *event)
{
    int needrefresh = TRUE;
    
    curevent = event;
    gli_event_clearevent(curevent);
    
    gli_windows_update();
    gli_windows_set_paging(FALSE);
    gli_input_guess_focus();
    
    while (curevent->type == evtype_None) {
        int key;
    
        /* It would be nice to display a "hit any key to continue" message in
            all windows which require it. */
        if (needrefresh) {
            gli_windows_place_cursor();
            refresh();
            needrefresh = FALSE;
        }
        key = getch();
        
#ifdef OPT_USE_SIGNALS
        if (just_killed) {
            /* Someone hit ctrl-C. This flag is set by the
                SIGINT / SIGHUP signal handlers.*/
            gli_fast_exit();
        }
#endif /* OPT_USE_SIGNALS */
        
        if (key != ERR) {
            /* An actual key has been hit */
            gli_input_handle_key(key);
            needrefresh = TRUE;
            continue;
        }

        /* key == ERR; it's an idle event */
        
#ifdef OPT_USE_SIGNALS

        /* Check to see if the program has just resumed. This 
            flag is set by the SIGCONT signal handler. */
        if (just_resumed) {
            just_resumed = FALSE;
            gli_set_halfdelay();
            needrefresh = TRUE;
            continue;
        }

#ifdef OPT_WINCHANGED_SIGNAL
        /* Check to see if the screen-size has changed. The 
            screen_size_changed flag is set by the SIGWINCH signal
            handler. */
        if (screen_size_changed) {
            screen_size_changed = FALSE;
            gli_windows_size_change();
            needrefresh = TRUE;
            continue;
        }
#endif /* OPT_WINCHANGED_SIGNAL */

#endif /* OPT_USE_SIGNALS */

#ifdef OPT_TIMED_INPUT
        /* Check to see if we've passed next_time. */
        if (timing_msec) {
            struct timeval tv;
            gettimeofday(&tv, NULL);
            if (tv.tv_sec > next_time.tv_sec
                || (tv.tv_sec == next_time.tv_sec &&
                    tv.tv_usec > next_time.tv_usec)) {
                next_time = tv;
                add_millisec_to_time(&next_time, timing_msec);
                gli_event_store(evtype_Timer, NULL, 0, 0);
                continue;
            }
        }
#endif /* OPT_TIMED_INPUT */

    }
    
    /* An event has occurred; glk_select() is over. */
    gli_windows_trim_buffers();
    curevent = NULL;
}