2001-12-27 23:30:36 +00:00
|
|
|
/*
|
|
|
|
|
* screen.c
|
|
|
|
|
* This file is part of LCDd, the lcdproc server.
|
|
|
|
|
*
|
|
|
|
|
* This file is released under the GNU General Public License. Refer to the
|
|
|
|
|
* COPYING file distributed with this package.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 1999, William Ferrell, Scott Scriven
|
2003-02-27 21:20:20 +00:00
|
|
|
* 2003, Joris Robijn
|
2001-12-27 23:30:36 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Does screen management
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
1999-12-09 23:15:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2001-11-29 14:09:13 +00:00
|
|
|
#include "shared/report.h"
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2001-12-30 00:15:25 +00:00
|
|
|
#include "drivers.h"
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
#include "clients.h"
|
|
|
|
|
#include "widget.h"
|
|
|
|
|
#include "screenlist.h"
|
|
|
|
|
#include "screen.h"
|
2002-06-29 16:37:18 +00:00
|
|
|
#include "menuscreens.h"
|
2001-09-21 21:08:10 +00:00
|
|
|
#include "main.h"
|
2001-11-14 13:57:25 +00:00
|
|
|
#include "render.h"
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2001-09-28 14:23:41 +00:00
|
|
|
int default_duration = 0;
|
2001-11-12 17:35:43 +00:00
|
|
|
int default_timeout = -1;
|
2001-07-18 22:30:12 +00:00
|
|
|
|
2003-02-27 21:20:20 +00:00
|
|
|
char *pri_names[] = {
|
|
|
|
|
"hidden",
|
|
|
|
|
"background",
|
|
|
|
|
"info",
|
|
|
|
|
"foreground",
|
|
|
|
|
"alert",
|
|
|
|
|
"input",
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
Screen *
|
|
|
|
|
screen_create (char * id, Client * client)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2002-04-26 00:00:31 +00:00
|
|
|
Screen *s;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2002-07-14 20:30:33 +00:00
|
|
|
debug( RPT_DEBUG, "%s( id=\"%.40s\", client=[%d] )", __FUNCTION__, id, (client?client->sock:-1));
|
|
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
s = malloc (sizeof (Screen));
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!s) {
|
2002-07-14 20:30:33 +00:00
|
|
|
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
2002-04-26 00:00:31 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (!id) {
|
2002-07-14 20:30:33 +00:00
|
|
|
report (RPT_ERR, "%s: Need id string", __FUNCTION__);
|
2002-04-26 00:00:31 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* Client can be NULL for serverscreens and other client-less screens */
|
|
|
|
|
|
|
|
|
|
s->id = strdup(id);
|
|
|
|
|
if (!s->id) {
|
2002-07-14 20:30:33 +00:00
|
|
|
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
2000-04-03 22:13:57 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
s->name = NULL;
|
2003-02-27 21:20:20 +00:00
|
|
|
s->priority = PRI_INFO;
|
2001-09-25 14:03:13 +00:00
|
|
|
s->duration = default_duration;
|
2002-04-26 00:00:31 +00:00
|
|
|
s->backlight = BACKLIGHT_OPEN;
|
|
|
|
|
s->heartbeat = HEARTBEAT_OPEN;
|
|
|
|
|
s->width = display_props->width;
|
|
|
|
|
s->height = display_props->height;
|
2001-05-25 03:14:27 +00:00
|
|
|
s->keys = NULL;
|
2002-04-26 00:00:31 +00:00
|
|
|
s->client = client;
|
|
|
|
|
s->widgetlist = NULL;
|
|
|
|
|
s->timeout = default_timeout; /*ignored unless greater than 0.*/
|
|
|
|
|
s->backlight = BACKLIGHT_OPEN; /*Lets the screen do it's own*/
|
2001-12-30 00:15:25 +00:00
|
|
|
/*or do what the client says.*/
|
2002-05-26 19:21:23 +00:00
|
|
|
s->cursor = CURSOR_OFF;
|
|
|
|
|
s->cursor_x = 1;
|
|
|
|
|
s->cursor_y = 1;
|
2001-11-29 14:09:13 +00:00
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
s->widgetlist = LL_new ();
|
|
|
|
|
if (!s->widgetlist) {
|
2002-07-14 20:30:33 +00:00
|
|
|
report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
|
2000-04-03 22:13:57 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2002-06-28 23:35:55 +00:00
|
|
|
menuscreen_add_screen (s);
|
|
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
return s;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
int
|
2002-04-26 00:00:31 +00:00
|
|
|
screen_destroy (Screen * s)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2002-04-26 00:00:31 +00:00
|
|
|
Widget *w;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2002-07-14 20:30:33 +00:00
|
|
|
debug( RPT_DEBUG, "%s( s=[%.40s] )", __FUNCTION__, s->id );
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2002-06-28 23:35:55 +00:00
|
|
|
menuscreen_remove_screen (s);
|
|
|
|
|
|
|
|
|
|
screenlist_remove (s);
|
|
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
for (w=LL_GetFirst(s->widgetlist); w; w=LL_GetNext(s->widgetlist)) {
|
2001-12-30 00:15:25 +00:00
|
|
|
/* Free a widget...*/
|
2000-04-03 22:13:57 +00:00
|
|
|
widget_destroy (w);
|
2002-04-26 00:00:31 +00:00
|
|
|
}
|
|
|
|
|
LL_Destroy (s->widgetlist);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (s->id)
|
|
|
|
|
free (s->id);
|
|
|
|
|
if (s->name)
|
|
|
|
|
free (s->name);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
free (s);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
int
|
|
|
|
|
screen_add_widget (Screen * s, Widget * w)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2002-07-14 20:30:33 +00:00
|
|
|
debug( RPT_DEBUG, "%s( s=[%.40s], widget=[%.40s] )", __FUNCTION__, s->id, w->id );
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
LL_Push (s->widgetlist, (void *) w);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
screen_remove_widget (Screen * s, Widget * w)
|
|
|
|
|
{
|
2002-07-14 20:30:33 +00:00
|
|
|
debug( RPT_DEBUG, "%s( s=[%.40s], widget=[%.40s] )", __FUNCTION__, s->id, w->id );
|
2002-04-26 00:00:31 +00:00
|
|
|
|
|
|
|
|
LL_Remove (s->widgetlist, (void *) w);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget *
|
|
|
|
|
screen_find_widget (Screen * s, char *id)
|
|
|
|
|
{
|
|
|
|
|
Widget * w;
|
|
|
|
|
|
|
|
|
|
if (!s)
|
2000-04-03 22:13:57 +00:00
|
|
|
return NULL;
|
|
|
|
|
if (!id)
|
|
|
|
|
return NULL;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2002-07-14 20:30:33 +00:00
|
|
|
debug( RPT_DEBUG, "%s( s=[%.40s], id=\"%.40s\" )", __FUNCTION__, s->id, id );
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2002-04-26 00:00:31 +00:00
|
|
|
for ( w=LL_GetFirst(s->widgetlist); w; w=LL_GetNext(s->widgetlist) ) {
|
|
|
|
|
if (0 == strcmp (w->id, id)) {
|
2002-07-14 20:30:33 +00:00
|
|
|
debug (RPT_DEBUG, "%s: Found %s", __FUNCTION__, id);
|
2002-04-26 00:00:31 +00:00
|
|
|
return w;
|
2000-04-03 22:13:57 +00:00
|
|
|
}
|
2002-04-26 00:00:31 +00:00
|
|
|
/* Search subscreens recursively */
|
|
|
|
|
if (w->type == WID_FRAME) {
|
|
|
|
|
w = widget_search_subs (w, id);
|
|
|
|
|
if (w)
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-14 20:30:33 +00:00
|
|
|
debug (RPT_DEBUG, "%s: Not found", __FUNCTION__);
|
2000-04-03 22:13:57 +00:00
|
|
|
return NULL;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
2003-02-27 21:20:20 +00:00
|
|
|
|
|
|
|
|
Priority
|
|
|
|
|
screen_pri_name_to_pri (char * priname)
|
|
|
|
|
{
|
|
|
|
|
Priority pri = WID_NONE;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; pri_names[i]; i++) {
|
|
|
|
|
if (strcmp (pri_names[i], priname) == 0) {
|
|
|
|
|
pri = i;
|
|
|
|
|
break; /* it's valid: skip out...*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
screen_pri_to_pri_name (Priority pri)
|
|
|
|
|
{
|
|
|
|
|
return pri_names[pri];
|
|
|
|
|
}
|