Base: LCDproc 0.5.2
[lcdproc-de200c.git] / server / serverscreens.c
blobad722c9b763a35fd857310b9ddb122188390c21d
1 /*
2 * serverscreens.c
3 * This file is part of LCDd, the lcdproc server.
5 * This file is released under the GNU General Public License. Refer to the
6 * COPYING file distributed with this package.
8 * Copyright (c) 1999, William Ferrell, Scott Scriven
9 * 2002, Joris Robijn
12 * Implements the serverscreens
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "shared/report.h"
25 #include "shared/configfile.h"
27 #include "drivers/lcd.h"
28 #include "drivers.h"
29 #include "clients.h"
30 #include "screen.h"
31 #include "screenlist.h"
32 #include "widget.h"
33 #include "main.h"
34 #include "serverscreens.h"
36 #define UNSET_INT -1
38 #define MAX_SERVERSCREEN_WIDTH 40
41 Screen *server_screen;
42 int rotate_server_screen = UNSET_INT;
45 int
46 server_screen_init(void)
48 Widget *w;
49 int line;
51 debug(RPT_DEBUG, "server_screen_init");
53 /* Create the screen */
54 server_screen = screen_create("_server_screen", NULL);
55 if (!server_screen) {
56 report(RPT_ERR, "server_screen_init: Error allocating screen");
57 return -1;
59 server_screen->name = "Server screen";
60 server_screen->duration = RENDER_FREQ; /* 1 second, instead of 4...*/
62 if ((rotate_server_screen == UNSET_INT) || (rotate_server_screen == 1)) {
63 server_screen->priority = PRI_INFO;
64 } else {
65 server_screen->priority = PRI_BACKGROUND;
68 /* Create all the widgets...*/
69 for (line = 1; line <= 4; line++) {
70 char id[8];
71 sprintf(id, "line%d", line);
73 w = widget_create(id, WID_STRING, server_screen);
74 if (!w) {
75 report(RPT_ERR, "server_screen_init: Can't create a widget");
76 return -1;
78 screen_add_widget(server_screen, w);
79 w->x = 1;
80 w->y = line;
81 w->text = malloc(MAX_SERVERSCREEN_WIDTH+1);
82 if (line == 1) {
83 w->type = WID_TITLE;
84 strncpy(w->text, "LCDproc Server", MAX_SERVERSCREEN_WIDTH);
85 } else {
86 w->text[0] = '\0';
90 /* And enqueue the screen*/
91 screenlist_add(server_screen);
93 debug(RPT_DEBUG, "server_screen_init done");
95 return 0;
98 int
99 server_screen_shutdown(void)
101 if (!server_screen)
102 return -1;
104 screenlist_remove(server_screen);
105 screen_destroy(server_screen);
106 return 0;
110 update_server_screen(void)
112 Client *c;
113 Widget *w;
114 int num_clients;
115 int num_screens;
117 /* Now get info on the number of connected clients...*/
118 num_clients = clients_client_count();
120 /* ... and screens */
121 num_screens = 0;
122 for (c = clients_getfirst(); c != NULL; c = clients_getnext()) {
123 num_screens += client_screen_count(c);
126 /* Format strings for the appropriate size display... */
127 if (display_props->height >= 3) {
128 w = screen_find_widget(server_screen, "line2");
129 snprintf(w->text, MAX_SERVERSCREEN_WIDTH,
130 "Clients: %i", num_clients);
131 w = screen_find_widget(server_screen, "line3");
132 snprintf(w->text, MAX_SERVERSCREEN_WIDTH,
133 "Screens: %i", num_screens);
134 } else {
135 w = screen_find_widget(server_screen, "line2");
136 snprintf(w->text, MAX_SERVERSCREEN_WIDTH,
137 ((display_props->width >= 16)
138 ? "Cli: %i Scr: %i"
139 : "C: %i S: %i"),
140 num_clients, num_screens);
142 return 0;
146 goodbye_screen(void)
148 if (!display_props)
149 return 0;
151 drivers_clear();
153 if (config_has_key("Server", "GoodBye")) { /* custom GoodBye */
154 int i;
156 /* loop over all display lines to read config & display message */
157 for (i = 0; i < display_props->height; i++) {
158 const char *line = config_get_string("Server", "GoodBye", i, "");
160 drivers_string(1, 1+i, line);
163 else { /* default GoodBye */
164 if ((display_props->height >= 2) && (display_props->width >= 16)) {
165 int xoffs = (display_props->width - 16) / 2;
166 int yoffs = (display_props->height - 2) / 2;
168 char *top = "Thanks for using";
169 #ifdef LINUX
170 char *low = "LCDproc & Linux!";
171 #else
172 char *low = " LCDproc! ";
173 #endif
175 drivers_string(1+xoffs, 1+yoffs, top);
176 drivers_string(1+xoffs, 2+yoffs, low);
180 drivers_cursor(1, 1, CURSOR_OFF);
181 drivers_flush();
183 return 0;