void input_internal_key(const char *key) { if (is_menu_key(key) || screenlist_current() == menuscreen) { menuscreen_key_handler(key); } else { /* Keys are for scrolling or rotating */ if (strcmp(key,toggle_rotate_key) == 0) { autorotate = !autorotate; if (autorotate) { server_msg("Rotate", 4); } else { server_msg("Hold", 4); } } else if (strcmp(key,prev_screen_key) == 0) { screenlist_goto_prev(); server_msg("Prev", 4); } else if (strcmp(key,next_screen_key) == 0) { screenlist_goto_next(); server_msg("Next", 4); } else if (strcmp(key,scroll_up_key) == 0) { } else if (strcmp(key,scroll_down_key) == 0) { } } }
int handle_input(void) { const char *key; Screen *current_screen; Client *current_client; Client *target; KeyReservation *kr; debug(RPT_DEBUG, "%s()", __FUNCTION__); current_screen = screenlist_current(); if (current_screen) current_client = current_screen->client; else current_client = NULL; /* Handle all keypresses */ while ((key = drivers_get_key()) != NULL) { /* Find what client wants the key */ kr = input_find_key(key, current_client); if (kr) { /* A hit ! */ report(RPT_DEBUG, "%s: reserved key: \"%.40s\"", __FUNCTION__, key); target = kr->client; } else { report(RPT_DEBUG, "%s: left over key: \"%.40s\"", __FUNCTION__, key); /*target = current_client;*/ target = NULL; /* left-over keys are always for internal client */ } if (target == NULL) { report(RPT_DEBUG, "%s: key is for internal client", __FUNCTION__); input_internal_key(key); } else { /* It's an external client */ report(RPT_DEBUG, "%s: key is for external client on socket %d", __FUNCTION__, target->sock); input_send_to_client(target, key); } } return 0; }
void screenlist_process(void) { Screen *s; Screen *f; report(RPT_DEBUG, "%s()", __FUNCTION__); if (!screenlist) return; /* Sort the list according to priority class */ LL_Sort(screenlist, compare_priority); f = LL_GetFirst(screenlist); /**** First we need to check out the current situation. ****/ /* Check whether there is an active screen */ s = screenlist_current(); if (!s) { /* We have no active screen yet. * Try to switch to the first screen in the list... */ s = f; if (!s) { /* There was no screen in the list */ return; } screenlist_switch(s); return; } else { /* There already was an active screen. * Check to see if it has an expiry time. If so, decrease it * and then check to see if it has expired. Remove the screen * if expired. */ if (s->timeout != -1) { --(s->timeout); report(RPT_DEBUG, "Active screen [%.40s] has timeout->%d", s->id, s->timeout); if (s->timeout <= 0) { /* Expired, we can destroy it */ report(RPT_DEBUG, "Removing expired screen [%.40s]", s->id); client_remove_screen(s->client, s); screen_destroy(s); } } } /**** OK, current situation examined. We can now see if we need to switch. */ /* Is there a screen of a higher priority class than the * current one ? */ if (f->priority > s->priority) { /* Yes, switch to that screen, job done */ report(RPT_DEBUG, "%s: High priority screen [%.40s] selected", __FUNCTION__, f->id); screenlist_switch(f); return; } /* Current screen has been visible long enough and is it of 'normal' * priority ? */ if (autorotate && (timer - current_screen_start_time >= s->duration) && s->priority > PRI_BACKGROUND && s->priority <= PRI_FOREGROUND) { /* Ah, rotate! */ screenlist_goto_next(); } }
static void do_mainloop(void) { Screen *s; struct timeval t; struct timeval last_t; int sleeptime; long int process_lag = 0; long int render_lag = 0; long int t_diff; debug(RPT_DEBUG, "%s()", __FUNCTION__); gettimeofday(&t, NULL); /* Get initial time */ while (1) { /* Get current time */ last_t = t; gettimeofday(&t, NULL); t_diff = t.tv_sec - last_t.tv_sec; if ( ((t_diff + 1) > (LONG_MAX / 1e6)) || (t_diff < 0) ) { /* We're going to overflow the calculation - probably been to sleep, fudge the values */ t_diff = 0; process_lag = 1; render_lag = (1e6/RENDER_FREQ); } else { t_diff *= 1e6; t_diff += t.tv_usec - last_t.tv_usec; } process_lag += t_diff; if (process_lag > 0) { /* Time for a processing stroke */ sock_poll_clients(); /* poll clients for input*/ parse_all_client_messages(); /* analyze input from network clients*/ handle_input(); /* handle key input from devices*/ /* We've done the job... */ process_lag = 0 - (1e6/PROCESS_FREQ); /* Note : this does not make a fixed frequency */ } render_lag += t_diff; if (render_lag > 0) { /* Time for a rendering stroke */ timer ++; screenlist_process(); s = screenlist_current(); /* TODO: Move this call to every client connection * and every screen add... */ if (s == server_screen) { update_server_screen(); } render_screen(s, timer); /* We've done the job... */ if (render_lag > (1e6/RENDER_FREQ) * MAX_RENDER_LAG_FRAMES) { /* Cause rendering slowdown because too much lag */ render_lag = (1e6/RENDER_FREQ) * MAX_RENDER_LAG_FRAMES; } render_lag -= (1e6/RENDER_FREQ); /* Note: this DOES make a fixed frequency (except with slowdown) */ } /* Sleep just as long as needed */ sleeptime = min(0-process_lag, 0-render_lag); if (sleeptime > 0) { usleep(sleeptime); } /* Check if a SIGHUP has been caught */ if (got_reload_signal) { got_reload_signal = 0; do_reload(); } } /* Quit! */ exit_program(0); }