int
screenlist_goto_prev(void)
{
	Screen *s;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	if (!current_screen)
		return -1;

	/* Find current screen in screenlist */
	for (s = LL_GetFirst(screenlist); s && s != current_screen; s = LL_GetNext(screenlist));

	/* One step back */
	s = LL_GetPrev(screenlist);
	if (!s) {
		/* We're at the start of the screenlist. We should find the
		 * last screen with the same priority as the first screen.
		 */
		Screen *f = LL_GetFirst(screenlist);
		Screen *n;

		s = f;
		while ((n = LL_GetNext(screenlist)) && n->priority == f->priority) {
			s = n;
		}
	}
	screenlist_switch(s);
	return 0;
}
Ejemplo n.º 2
0
int input_reserve_key(const char *key, bool exclusive, Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(key=\"%.40s\", exclusive=%d, client=[%d])", __FUNCTION__, key, exclusive, (client?client->sock:-1));

	/* Find out if this key is already reserved in a way that interferes
	 * with the new reservation.
	 */
	for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
		if (strcmp(kr->key, key) == 0) {
			if (kr->exclusive || exclusive) {
				/* Sorry ! */
				return -1;
			}
		}
	}

	/* We can now safely add it ! */
	kr = malloc(sizeof(KeyReservation));
	kr->key = strdup(key);
	kr->exclusive = exclusive;
	kr->client = client;
	LL_Push(keylist, kr);

	report(RPT_INFO, "Key \"%.40s\" is now reserved in %s mode by client [%d]", key, (exclusive?"exclusive":"shared"), (client?client->sock:-1));

	return 0;
}
Ejemplo n.º 3
0
/** Find a widget on a screen by its id.
 * \param s   Screen where to look for the widget.
 * \param id  Identifier of the widget.
 * \return    Pointerr to the widget; \c NULL if widget was not found or error.
 */
Widget *
screen_find_widget(Screen *s, char *id)
{
	Widget *w;

	if (!s)
		return NULL;
	if (!id)
		return NULL;

	debug(RPT_DEBUG, "%s(s=[%.40s], id=\"%.40s\")", __FUNCTION__, s->id, id);

	for (w = LL_GetFirst(s->widgetlist); w != NULL; w = LL_GetNext(s->widgetlist)) {
		if (0 == strcmp(w->id, id)) {
			debug(RPT_DEBUG, "%s: Found %s", __FUNCTION__, id);
			return w;
		}
		/* Search subscreens recursively */
		if (w->type == WID_FRAME) {
			w = widget_search_subs(w, id);
			if (w != NULL)
				return w;
		}
	}
	debug(RPT_DEBUG, "%s: Not found", __FUNCTION__);
	return NULL;
}
Ejemplo n.º 4
0
/** Destroy a screen.
 * \param s    Screen to destroy.
 * \retval <0  Error; no screen given.
 * \retval  0  Success.
 */
int
screen_destroy(Screen *s)
{
	Widget *w;

	debug(RPT_DEBUG, "%s(s=[%.40s])", __FUNCTION__, s->id);

	menuscreen_remove_screen(s);

	screenlist_remove(s);

	for (w = LL_GetFirst(s->widgetlist); w; w = LL_GetNext(s->widgetlist)) {
		/* Free a widget...*/
		widget_destroy(w);
	}
	LL_Destroy(s->widgetlist);
	s->widgetlist = NULL;

	if (s->id != NULL) {
		free(s->id);
		s->id = NULL;
	}
	if (s->name != NULL) {
		free(s->name);
		s->name = NULL;
	}

	free(s);
	s = NULL;

	return 0;
}
int
screenlist_goto_next(void)
{
	Screen *s;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	if (!current_screen)
		return -1;

	/* Find current screen in screenlist */
	for (s = LL_GetFirst(screenlist); s && s != current_screen; s = LL_GetNext(screenlist))
		;

	/* One step forward */
	s = LL_GetNext(screenlist);
	if (!s || s->priority < current_screen->priority) {
		/* To far, go back to start of screenlist */
		s = LL_GetFirst(screenlist);
	}
	screenlist_switch(s);
	return 0;
}
Ejemplo n.º 6
0
KeyReservation *input_find_key(const char *key, Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(key=\"%.40s\", client=[%d])", __FUNCTION__, key, (client?client->sock:-1));

	for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
		if (strcmp(kr->key, key) == 0) {
			if (kr->exclusive || client==kr->client) {
				return kr;
			}
		}
	}
	return NULL;
}
Ejemplo n.º 7
0
void input_release_key(const char *key, Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(key=\"%.40s\", client=[%d])", __FUNCTION__, key, (client?client->sock:-1));

	for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
		if (kr->client == client
		&& strcmp(kr->key, key) == 0) {
			free(kr->key);
			free(kr);
			LL_DeleteNode(keylist);
			report(RPT_INFO, "Key \"%.40s\" was reserved in %s mode by client [%d] and is now released", key, (kr->exclusive?"exclusive":"shared"), (client?client->sock:-1));
			return;
		}
	}
}
void menuitem_destroy_ring(MenuItem *item)
{
	debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__,
			((item != NULL) ? item->id : "(null)"));

	if (item != NULL) {
	char *s;

		/* deallocate the strings */
		for (s = LL_GetFirst(item->data.ring.strings);
		     s != NULL;
		     s = LL_GetNext(item->data.ring.strings)) {
			free(s);
		}
		/* and the list */
		LL_Destroy(item->data.ring.strings);
	}
}
Ejemplo n.º 9
0
void input_release_client_keys(Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(client=[%d])", __FUNCTION__, (client?client->sock:-1));

	kr=LL_GetFirst(keylist);
	while (kr) {
		if (kr->client == client) {
			report(RPT_INFO, "Key \"%.40s\" was reserved in %s mode by client [%d] and is now released", kr->key, (kr->exclusive?"exclusive":"shared"), (client?client->sock:-1));
			free(kr->key);
			free(kr);
			LL_DeleteNode(keylist);
			kr = LL_Get(keylist);
		} else {
			kr = LL_GetNext(keylist);
		}
	}
}
Ejemplo n.º 10
0
void *
LL_Look (LinkedList * list)				  // Peek at first node
{
	return LL_GetFirst (list);
}
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();
	}
}