Mega change to the LCDd's header files:

1. Use <stdbool.h> if it is available but keep a compatibility shim in
   shared/defines.h in case it is not.
2. Unbreak the circular header dependencies (mostly):
   2a. client.c and client.h may NOT depend on 'struct Menu'. Use a void pointer
       and casts instead.
   2b. Separate the data type definitions in client.h and screen.h from
       function prototypes which may require other data structures. This makes
       header dependencies much more easy to maintain. Usually the data types
       should have been moved to their own files but I (mmdolze) chose to
       separate them using different header guards.
   2c. Remove many now unused header includes.
Apply (old BSD-) style on menuscreens.c.
This commit is contained in:
mmdolze
2012-02-22 22:25:32 +00:00
parent 5e1edf5b60
commit a151ee0fc4
33 changed files with 321 additions and 247 deletions
+1 -1
View File
@@ -171,7 +171,7 @@ dnl Checks for header files.
AC_HEADER_DIRENT AC_HEADER_DIRENT
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h sys/io.h errno.h) AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h sys/io.h errno.h)
AC_CHECK_HEADERS(limits.h kvm.h sys/param.h sys/dkstat.h) AC_CHECK_HEADERS(limits.h kvm.h sys/param.h sys/dkstat.h stdbool.h)
dnl check sys/sysctl.h seperately, as it requires other headers on at least OpenBSD dnl check sys/sysctl.h seperately, as it requires other headers on at least OpenBSD
AC_CHECK_HEADERS([sys/sysctl.h], [], [], AC_CHECK_HEADERS([sys/sysctl.h], [], [],
+8 -6
View File
@@ -20,11 +20,11 @@
#endif #endif
#include "client.h" #include "client.h"
#include "screen.h"
#include "screenlist.h" #include "screenlist.h"
#include "render.h" #include "render.h"
#include "input.h" #include "input.h"
#include "menuscreens.h" #include "menuscreens.h"
#include "menuitem.h"
#include "shared/report.h" #include "shared/report.h"
#include "shared/LL.h" #include "shared/LL.h"
@@ -71,6 +71,7 @@ int
client_destroy(Client *c) client_destroy(Client *c)
{ {
Screen *s; Screen *s;
Menu *m;
char *str; char *str;
if (!c) if (!c)
@@ -99,12 +100,13 @@ client_destroy(Client *c)
} }
LL_Destroy(c->screenlist); LL_Destroy(c->screenlist);
m = (Menu *) c->menu;
/* Destroy the client's menu, if it exists */ /* Destroy the client's menu, if it exists */
if (c->menu) { if (m) {
menuscreen_inform_item_destruction(c->menu); menuscreen_inform_item_destruction(m);
menu_remove_item(c->menu->parent, c->menu); menu_remove_item(m->parent, m);
menuscreen_inform_item_modified(c->menu->parent); menuscreen_inform_item_modified(m->parent);
menuitem_destroy(c->menu); menuitem_destroy(m);
} }
/* Forget client's key reservations */ /* Forget client's key reservations */
+21 -9
View File
@@ -1,5 +1,15 @@
/** \file server/client.h /** \file server/client.h
* Defines all the client data and actions. * Defines all the client data and actions.
*
* \note If you only need 'struct Client' to work with you should use the
* following code (which does not create an indirect dependency on
* 'struct Screen'):
*
* \code
* #define INC_TYPES_ONLY 1
* #include "client.h"
* #undef INC_TYPES_ONLY
* \endcode
*/ */
/* This file is part of LCDd, the lcdproc server. /* This file is part of LCDd, the lcdproc server.
@@ -11,15 +21,10 @@
* 2002, Joris Robijn * 2002, Joris Robijn
*/ */
#include "menu.h" #ifndef CLIENT_H_TYPES
#include "menuitem.h" #define CLIENT_H_TYPES
/* These headers are placed here on purpose ! (circular references) */
#ifndef CLIENT_H
#define CLIENT_H
#include "shared/LL.h" #include "shared/LL.h"
#include <stdio.h>
#define CLIENT_NAME_SIZE 256 #define CLIENT_NAME_SIZE 256
@@ -42,11 +47,18 @@ typedef struct Client {
LinkedList *messages; /**< Messages that the client sent. */ LinkedList *messages; /**< Messages that the client sent. */
LinkedList *screenlist; /**< List of client's screens. */ LinkedList *screenlist; /**< List of client's screens. */
Menu *menu; /**< Menu hierarchy, if any */ void* menu; /**< Menu hierarchy, if any */
} Client; } Client;
#endif
#ifndef INC_TYPES_ONLY
#ifndef CLIENT_H_FNCS
#define CLIENT_H_FNCS
#define INC_TYPES_ONLY 1
#include "screen.h" #include "screen.h"
#undef INC_TYPES_ONLY
/* When a new client connects, set up a new client data struct */ /* When a new client connects, set up a new client data struct */
Client *client_create(int sock); Client *client_create(int sock);
@@ -73,4 +85,4 @@ int client_remove_screen(Client *c, Screen *s);
int client_screen_count(Client *c); int client_screen_count(Client *c);
#endif #endif
#endif
+3 -2
View File
@@ -19,9 +19,10 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include "shared/report.h"
#include "shared/LL.h"
#include "client.h" #include "client.h"
#include "clients.h" #include "clients.h"
#include "shared/report.h"
#include "render.h" #include "render.h"
LinkedList *clientlist = NULL; LinkedList *clientlist = NULL;
@@ -91,7 +92,7 @@ Client *
clients_remove_client(Client *c, Direction whereto) clients_remove_client(Client *c, Direction whereto)
{ {
Client *client = LL_Remove(clientlist, c, whereto); Client *client = LL_Remove(clientlist, c, whereto);
return client; return client;
} }
-3
View File
@@ -14,9 +14,6 @@
#define CLIENTS_H #define CLIENTS_H
#include "client.h" #include "client.h"
#include "shared/LL.h"
/* extern LinkedList *clientlist; Not needed outside ? */
/* Initialize and kill client list...*/ /* Initialize and kill client list...*/
int clients_init(void); int clients_init(void);
+3 -2
View File
@@ -28,9 +28,10 @@
#include "shared/sockets.h" #include "shared/sockets.h"
#include "drivers.h" #include "drivers.h"
#include "render.h"
#include "client.h" #include "client.h"
#include "render.h"
#include "input.h" #include "input.h"
#include "client_commands.h"
/** /**
@@ -96,7 +97,7 @@ bye_func(Client *c, int argc, char **argv)
c->state = GONE; c->state = GONE;
//sock_send_error(c->sock, "\"bye\" is currently ignored\n"); //sock_send_error(c->sock, "\"bye\" is currently ignored\n");
} }
return 0; return 0;
} }
+3 -3
View File
@@ -14,6 +14,9 @@
* 2003, Joris Robijn * 2003, Joris Robijn
*/ */
#include <stdlib.h>
#include <string.h>
#include "command_list.h" #include "command_list.h"
#include "server_commands.h" #include "server_commands.h"
#include "client_commands.h" #include "client_commands.h"
@@ -21,9 +24,6 @@
#include "widget_commands.h" #include "widget_commands.h"
#include "menu_commands.h" #include "menu_commands.h"
#include <stdlib.h>
#include <string.h>
static client_function commands[] = { static client_function commands[] = {
{ "test_func", test_func_func }, { "test_func", test_func_func },
{ "hello", hello_func }, { "hello", hello_func },
+1 -1
View File
@@ -13,7 +13,7 @@
#ifndef COMMANDS_COMMAND_LIST_H #ifndef COMMANDS_COMMAND_LIST_H
#define COMMANDS_COMMAND_LIST_H #define COMMANDS_COMMAND_LIST_H
#include "../client.h" #include "client.h"
/** /**
* The function list for clients is stored in a table, and the items each * The function list for clients is stored in a table, and the items each
+2 -2
View File
@@ -31,11 +31,11 @@
#include "shared/report.h" #include "shared/report.h"
#include "shared/sockets.h" #include "shared/sockets.h"
#include "menu.h" #include "client.h"
#include "menuitem.h" #include "menuitem.h"
#include "menu.h"
#include "menuscreens.h" #include "menuscreens.h"
#include "menu_commands.h" #include "menu_commands.h"
#include "client.h"
/* Local functions */ /* Local functions */
MenuEventFunc(menu_commands_handler); MenuEventFunc(menu_commands_handler);
+1
View File
@@ -30,6 +30,7 @@
#include "client.h" #include "client.h"
#include "screen.h" #include "screen.h"
#include "render.h" #include "render.h"
#include "screen_commands.h"
/** /**
* Tells the server the client has another screen to offer * Tells the server the client has another screen to offer
+1
View File
@@ -29,6 +29,7 @@
#include "client.h" #include "client.h"
#include "render.h" #include "render.h"
#include "server_commands.h"
#define ALL_OUTPUTS_ON -1 #define ALL_OUTPUTS_ON -1
#define ALL_OUTPUTS_OFF 0 #define ALL_OUTPUTS_OFF 0
+1 -1
View File
@@ -30,8 +30,8 @@
#include "client.h" #include "client.h"
#include "screen.h" #include "screen.h"
#include "widget.h" #include "widget.h"
#include "drivers.h" #include "drivers.h"
#include "widget_commands.h"
/** /**
+6 -4
View File
@@ -14,11 +14,13 @@
#include "drivers/lcd.h" #include "drivers/lcd.h"
#ifndef bool #ifdef HAVE_CONFIG_H
# define bool short # include "config.h"
# define true 1
# define false 0
#endif #endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#include "shared/defines.h"
Driver * Driver *
driver_load(const char *name, const char *filename); driver_load(const char *name, const char *filename);
+1 -3
View File
@@ -24,11 +24,9 @@
#include "shared/report.h" #include "shared/report.h"
#include "shared/configfile.h" #include "shared/configfile.h"
#include "drivers.h"
#include "driver.h" #include "driver.h"
#include "drivers/lcd.h" #include "drivers.h"
#include "widget.h" #include "widget.h"
/* lcd.h is used for the driver API definition */
LinkedList *loaded_drivers = NULL; /**< list of loaded drivers */ LinkedList *loaded_drivers = NULL; /**< list of loaded drivers */
-7
View File
@@ -22,13 +22,6 @@ typedef struct DisplayProps {
extern DisplayProps *display_props; extern DisplayProps *display_props;
#ifndef bool
# define bool short
# define true 1
# define false 0
#endif
int int
drivers_load_driver(const char *name); drivers_load_driver(const char *name);
+5 -4
View File
@@ -11,8 +11,6 @@
* 2003, Joris Robijn * 2003, Joris Robijn
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -20,13 +18,16 @@
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/report.h" #include "shared/report.h"
#include "shared/configfile.h" #include "shared/configfile.h"
#include "shared/LL.h"
#include "drivers.h" #include "drivers.h"
#define INC_TYPES_ONLY 1
#include "client.h" #include "client.h"
#include "screen.h"
#undef INC_TYPES_ONLY
#include "screenlist.h" #include "screenlist.h"
#include "menuscreens.h" #include "menuscreens.h"
#include "input.h" #include "input.h"
#include "render.h" /* For server_msg* */ #include "render.h" /* For server_msg* */
@@ -137,7 +138,7 @@ void input_send_to_client(Client *c, const char *key)
snprintf(s, size, "key %s\n", key); snprintf(s, size, "key %s\n", key);
sock_send_string(c->sock, s); sock_send_string(c->sock, s);
free(s); free(s);
} }
else else
report(RPT_ERR, "%s: malloc failure", __FUNCTION__); report(RPT_ERR, "%s: malloc failure", __FUNCTION__);
} }
+7 -7
View File
@@ -13,17 +13,17 @@
#ifndef INPUT_H #ifndef INPUT_H
#define INPUT_H #define INPUT_H
#include <stdlib.h> #ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#include "shared/defines.h"
/* Accepts and uses keypad input while displaying screens... */ /* Accepts and uses keypad input while displaying screens... */
int handle_input(void); int handle_input(void);
#ifndef bool
# define bool short
# define true 1
# define false 0
#endif
typedef struct KeyReservation { typedef struct KeyReservation {
char *key; char *key;
bool exclusive; bool exclusive;
+1 -1
View File
@@ -57,8 +57,8 @@
#include "drivers.h" #include "drivers.h"
#include "sock.h" #include "sock.h"
#include "clients.h" #include "clients.h"
#include "screenlist.h"
#include "screen.h" #include "screen.h"
#include "screenlist.h"
#include "parse.h" #include "parse.h"
#include "render.h" #include "render.h"
#include "serverscreens.h" #include "serverscreens.h"
+3 -4
View File
@@ -32,14 +32,13 @@
# include "config.h" # include "config.h"
#endif #endif
#include "widget.h"
#include "screen.h"
#include "menuitem.h" #include "menuitem.h"
#include "menu.h" #include "menu.h"
#include "shared/report.h" #include "shared/report.h"
#include "drivers.h" #include "drivers.h"
#include "screen.h"
#include "widget.h"
extern Menu *custom_main_menu; extern Menu *custom_main_menu;
@@ -209,7 +208,7 @@ menu_create(char *id, MenuEventFunc(*event_func),
if (new_menu != NULL) { if (new_menu != NULL) {
new_menu->data.menu.contents = LL_new(); new_menu->data.menu.contents = LL_new();
new_menu->data.menu.association = NULL; new_menu->data.menu.association = NULL;
} }
return new_menu; return new_menu;
} }
+8 -10
View File
@@ -12,27 +12,25 @@
* 2005, Peter Marschall - error checks, ... * 2005, Peter Marschall - error checks, ...
*/ */
#include "menuitem.h"
/* These headers are placed here on purpose ! (circular references) */
#ifndef MENU_H #ifndef MENU_H
#define MENU_H #define MENU_H
#ifndef bool #ifdef HAVE_CONFIG_H
# define bool short # include "config.h"
# define true 1
# define false 0
#endif #endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#include "shared/defines.h"
#include "shared/LL.h" #include "shared/LL.h"
#include "menuitem.h"
/** A Menu is a MenuItem too. /** A Menu is a MenuItem too.
* This definition is only for better understanding of this code. * This definition is only for better understanding of this code.
*/ */
typedef MenuItem Menu; typedef MenuItem Menu;
#include "screen.h"
/** Creates a new menu. */ /** Creates a new menu. */
Menu *menu_create(char *id, MenuEventFunc(*event_func), Menu *menu_create(char *id, MenuEventFunc(*event_func),
char *text, Client *client); char *text, Client *client);
@@ -43,8 +41,8 @@ Menu *menu_create(char *id, MenuEventFunc(*event_func),
*/ */
void menu_destroy(Menu *menu); void menu_destroy(Menu *menu);
void menu_add_item(Menu *menu, MenuItem *item);
/** Adds an item to the menu */ /** Adds an item to the menu */
void menu_add_item(Menu *menu, MenuItem *item);
/** Removes an item from the menu (does not destroy it) */ /** Removes an item from the menu (does not destroy it) */
void menu_remove_item(Menu *menu, MenuItem *item); void menu_remove_item(Menu *menu, MenuItem *item);
+30 -25
View File
@@ -17,12 +17,14 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "shared/report.h" #include "shared/report.h"
#include "shared/defines.h" #include "shared/defines.h"
#include "widget.h"
#include "screen.h"
#include "menuitem.h" #include "menuitem.h"
#include "menuscreens.h"
#include "menu.h" #include "menu.h"
#include "drivers.h" #include "drivers.h"
@@ -134,7 +136,10 @@ MenuItem *menuitem_search(char *menu_id, Client *client)
} }
/******** FUNCTION TABLES ********/ /******** FUNCTION TABLES ********/
/* Tables with functions to call for all different item types */ /*-
* Tables with functions to call for all different item types. The order is:
* "menu", "action", "checkbox", "ring", "slider", "numeric", "alpha", "ip".
*/
void (*destructor_table[NUM_ITEMTYPES]) (MenuItem *item) = void (*destructor_table[NUM_ITEMTYPES]) (MenuItem *item) =
{ {
@@ -284,7 +289,7 @@ MenuItem *menuitem_create_checkbox(char *id, MenuEventFunc(*event_func),
if (new_item != NULL) { if (new_item != NULL) {
new_item->data.checkbox.allow_gray = allow_gray; new_item->data.checkbox.allow_gray = allow_gray;
new_item->data.checkbox.value = value; new_item->data.checkbox.value = value;
} }
return new_item; return new_item;
} }
@@ -301,7 +306,7 @@ MenuItem *menuitem_create_ring(char *id, MenuEventFunc(*event_func),
if (new_item != NULL) { if (new_item != NULL) {
new_item->data.ring.strings = tablist2linkedlist(strings); new_item->data.ring.strings = tablist2linkedlist(strings);
new_item->data.ring.value = value; new_item->data.ring.value = value;
} }
return new_item; return new_item;
} }
@@ -328,7 +333,7 @@ MenuItem *menuitem_create_slider(char *id, MenuEventFunc(*event_func),
new_item->data.slider.maxvalue = maxvalue; new_item->data.slider.maxvalue = maxvalue;
new_item->data.slider.stepsize = stepsize; new_item->data.slider.stepsize = stepsize;
new_item->data.slider.value = value; new_item->data.slider.value = value;
} }
return new_item; return new_item;
} }
@@ -351,7 +356,7 @@ MenuItem *menuitem_create_numeric(char *id, MenuEventFunc(*event_func),
menuitem_destroy(new_item); menuitem_destroy(new_item);
return NULL; return NULL;
} }
} }
return new_item; return new_item;
} }
@@ -445,7 +450,7 @@ MenuItem *menuitem_create_ip(char *id, MenuEventFunc(*event_func),
__FUNCTION__, id, value); __FUNCTION__, id, value);
strncpy(new_item->data.ip.value, ipinfo->dummy, new_item->data.ip.maxlength); strncpy(new_item->data.ip.value, ipinfo->dummy, new_item->data.ip.maxlength);
new_item->data.ip.value[new_item->data.ip.maxlength] = '\0'; new_item->data.ip.value[new_item->data.ip.maxlength] = '\0';
} }
} }
new_item->data.ip.edit_str = malloc(new_item->data.ip.maxlength + 1); new_item->data.ip.edit_str = malloc(new_item->data.ip.maxlength + 1);
@@ -476,7 +481,7 @@ void menuitem_destroy(MenuItem *item)
/* And finally...*/ /* And finally...*/
free(item); free(item);
} }
} }
void menuitem_destroy_ring(MenuItem *item) void menuitem_destroy_ring(MenuItem *item)
@@ -495,7 +500,7 @@ void menuitem_destroy_ring(MenuItem *item)
} }
/* and the list */ /* and the list */
LL_Destroy(item->data.ring.strings); LL_Destroy(item->data.ring.strings);
} }
} }
void menuitem_destroy_slider(MenuItem *item) void menuitem_destroy_slider(MenuItem *item)
@@ -507,7 +512,7 @@ void menuitem_destroy_slider(MenuItem *item)
/* These strings should always be allocated */ /* These strings should always be allocated */
free(item->data.slider.mintext); free(item->data.slider.mintext);
free(item->data.slider.maxtext); free(item->data.slider.maxtext);
} }
} }
void menuitem_destroy_numeric(MenuItem *item) void menuitem_destroy_numeric(MenuItem *item)
@@ -518,7 +523,7 @@ void menuitem_destroy_numeric(MenuItem *item)
if (item != NULL) { if (item != NULL) {
/* This string should always be allocated */ /* This string should always be allocated */
free(item->data.numeric.edit_str); free(item->data.numeric.edit_str);
} }
} }
void menuitem_destroy_alpha(MenuItem *item) void menuitem_destroy_alpha(MenuItem *item)
@@ -531,7 +536,7 @@ void menuitem_destroy_alpha(MenuItem *item)
free(item->data.alpha.allowed_extra); free(item->data.alpha.allowed_extra);
free(item->data.alpha.value); free(item->data.alpha.value);
free(item->data.alpha.edit_str); free(item->data.alpha.edit_str);
} }
} }
void menuitem_destroy_ip(MenuItem *item) void menuitem_destroy_ip(MenuItem *item)
@@ -559,7 +564,7 @@ void menuitem_reset(MenuItem *item)
func = reset_table[item->type]; func = reset_table[item->type];
if (func) if (func)
func(item); func(item);
} }
} }
void menuitem_reset_numeric(MenuItem *item) void menuitem_reset_numeric(MenuItem *item)
@@ -577,7 +582,7 @@ void menuitem_reset_numeric(MenuItem *item)
} else { } else {
snprintf(item->data.numeric.edit_str, MAX_NUMERIC_LEN, snprintf(item->data.numeric.edit_str, MAX_NUMERIC_LEN,
"%d", item->data.numeric.value); "%d", item->data.numeric.value);
} }
} }
} }
@@ -591,7 +596,7 @@ void menuitem_reset_alpha(MenuItem *item)
item->data.alpha.edit_offs = 0; item->data.alpha.edit_offs = 0;
memset(item->data.alpha.edit_str, '\0', item->data.alpha.maxlength+1); memset(item->data.alpha.edit_str, '\0', item->data.alpha.maxlength+1);
strcpy(item->data.alpha.edit_str, item->data.alpha.value); strcpy(item->data.alpha.edit_str, item->data.alpha.value);
} }
} }
void menuitem_reset_ip(MenuItem *item) void menuitem_reset_ip(MenuItem *item)
@@ -620,8 +625,8 @@ void menuitem_reset_ip(MenuItem *item)
tmpstr[0] = ipinfo->sep; tmpstr[0] = ipinfo->sep;
tmpstr[1] = '\0'; tmpstr[1] = '\0';
strcat(item->data.ip.edit_str, tmpstr); strcat(item->data.ip.edit_str, tmpstr);
} }
} }
} }
@@ -664,8 +669,8 @@ void menuitem_rebuild_screen(MenuItem *item, Screen *s)
/* Also always call update_screen */ /* Also always call update_screen */
menuitem_update_screen(item, s); menuitem_update_screen(item, s);
} }
} }
} }
void menuitem_rebuild_screen_slider(MenuItem *item, Screen *s) void menuitem_rebuild_screen_slider(MenuItem *item, Screen *s)
@@ -1027,7 +1032,7 @@ MenuResult menuitem_process_input_slider(MenuItem *item, MenuToken token, const
* Note: The max value is actually reached, * Note: The max value is actually reached,
* because of min(maxvalue, value + stepsize) below. * because of min(maxvalue, value + stepsize) below.
* Wrapping then happens on the next key press. * Wrapping then happens on the next key press.
*/ */
if ((!(keymask & (MENUTOKEN_LEFT | MENUTOKEN_DOWN))) && if ((!(keymask & (MENUTOKEN_LEFT | MENUTOKEN_DOWN))) &&
(item->data.slider.value == item->data.slider.maxvalue)) (item->data.slider.value == item->data.slider.maxvalue))
item->data.slider.value = item->data.slider.minvalue; item->data.slider.value = item->data.slider.minvalue;
@@ -1210,7 +1215,7 @@ MenuResult menuitem_process_input_numeric(MenuItem *item, MenuToken token, const
default: default:
return MENURESULT_NONE; return MENURESULT_NONE;
} }
} }
return MENURESULT_ERROR; return MENURESULT_ERROR;
} }
@@ -1339,7 +1344,7 @@ MenuResult menuitem_process_input_alpha(MenuItem *item, MenuToken token, const c
item->data.alpha.edit_pos--; item->data.alpha.edit_pos--;
if (item->data.alpha.edit_offs > item->data.alpha.edit_pos) if (item->data.alpha.edit_offs > item->data.alpha.edit_pos)
item->data.alpha.edit_offs = item->data.alpha.edit_pos; item->data.alpha.edit_offs = item->data.alpha.edit_pos;
} }
return MENURESULT_NONE; return MENURESULT_NONE;
case MENUTOKEN_OTHER: case MENUTOKEN_OTHER:
if (pos >= item->data.alpha.maxlength) { if (pos >= item->data.alpha.maxlength) {
@@ -1356,9 +1361,9 @@ MenuResult menuitem_process_input_alpha(MenuItem *item, MenuToken token, const c
if (pos >= display_props->width - 2) if (pos >= display_props->width - 2)
item->data.alpha.edit_offs++; item->data.alpha.edit_offs++;
} }
default: default:
return MENURESULT_NONE; return MENURESULT_NONE;
} }
} }
return MENURESULT_ERROR; return MENURESULT_ERROR;
} }
@@ -1489,7 +1494,7 @@ MenuResult menuitem_process_input_ip(MenuItem *item, MenuToken token, const char
} }
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
return MENURESULT_NONE; return MENURESULT_NONE;
} }
/* NOTREACHED */ /* NOTREACHED */
+9 -9
View File
@@ -11,7 +11,7 @@
* *
* The slider, numeric & string input and menu have their own screen, * The slider, numeric & string input and menu have their own screen,
* that comes to front when the items are selected. * that comes to front when the items are selected.
* One menuitem is in a different file: Menu data is in menu,h. * One menuitem is in a different file: Menu data is in menu.h.
*/ */
/* This file is part of LCDd, the lcdproc server. /* This file is part of LCDd, the lcdproc server.
@@ -27,13 +27,15 @@
#ifndef MENUITEM_H #ifndef MENUITEM_H
#define MENUITEM_H #define MENUITEM_H
#include "shared/LL.h" #ifdef HAVE_CONFIG_H
# include "config.h"
#ifndef bool
# define bool short
# define true 1
# define false 0
#endif #endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#include "shared/defines.h"
#include "shared/LL.h"
/********************************************************************* /*********************************************************************
* Data definitions of the menustuff * Data definitions of the menustuff
@@ -191,8 +193,6 @@ typedef struct MenuItem {
} MenuItem; } MenuItem;
#include "screen.h"
/********************************************************************* /*********************************************************************
* Functions to use the menustuff * Functions to use the menustuff
*/ */
+150 -114
View File
@@ -1,7 +1,7 @@
/** \file server/menuscreens.c /** \file server/menuscreens.c
* Creates the server menu screen(s) and creates the menus that should be * Creates the server menu screen(s) and creates the menus that should be
* displayed on this screen. * displayed on this screen.
* It also handles its keypresses and converts them to menu tokens for * It also handles its key presses and converts them to menu tokens for
* easier processing. * easier processing.
* *
* \note * \note
@@ -9,7 +9,8 @@
* a menu or on a separate SCREEN, for flexibility. * a menu or on a separate SCREEN, for flexibility.
*/ */
/* This file is part of LCDd, the lcdproc server. /*-
* This file is part of LCDd, the lcdproc server.
* *
* This file is released under the GNU General Public License. * This file is released under the GNU General Public License.
* Refer to the COPYING file distributed with this package. * Refer to the COPYING file distributed with this package.
@@ -23,6 +24,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include "screen.h" #include "screen.h"
#include "screenlist.h" #include "screenlist.h"
@@ -53,7 +55,7 @@ Screen *menuscreen = NULL;
MenuItem *active_menuitem = NULL; MenuItem *active_menuitem = NULL;
/** the "real" main_menu */ /** the "real" main_menu */
Menu *main_menu = NULL; Menu *main_menu = NULL;
/** customizable entry point into the menu system (see menu_set_main()). */ /** customizable entry point into the menu system (see menuscreen_set_main()). */
Menu *custom_main_menu = NULL; Menu *custom_main_menu = NULL;
Menu *screens_menu = NULL; Menu *screens_menu = NULL;
@@ -75,14 +77,17 @@ MenuEventFunc(titlespeed_handler);
MenuEventFunc(contrast_handler); MenuEventFunc(contrast_handler);
MenuEventFunc(brightness_handler); MenuEventFunc(brightness_handler);
int menuscreens_init(void) int
menuscreens_init(void)
{ {
const char *tmp; const char *tmp;
debug(RPT_DEBUG, "%s()", __FUNCTION__); debug(RPT_DEBUG, "%s()", __FUNCTION__);
/* Get keys from config file: MenuKey, EnterKey, UpKey, DownKey, LeftKey, RightKey. /*
* For a working menu at least 3 are necessary: MenuKey, EnterKey, UpKey/DownKey. * Get keys from config file: MenuKey, EnterKey, UpKey, DownKey,
* LeftKey, RightKey. For a working menu at least 3 are necessary:
* MenuKey, EnterKey, UpKey/DownKey.
*/ */
keymask = 0; keymask = 0;
menu_key = enter_key = NULL; menu_key = enter_key = NULL;
@@ -150,7 +155,8 @@ int menuscreens_init(void)
} }
int menuscreens_shutdown(void) int
menuscreens_shutdown(void)
{ {
debug(RPT_DEBUG, "%s()", __FUNCTION__); debug(RPT_DEBUG, "%s()", __FUNCTION__);
@@ -175,30 +181,31 @@ int menuscreens_shutdown(void)
/* Forget menu's key reservations */ /* Forget menu's key reservations */
input_release_client_keys(NULL); input_release_client_keys(NULL);
if (menu_key != NULL) if (menu_key != NULL)
free(menu_key); free(menu_key);
if (enter_key != NULL) if (enter_key != NULL)
free(enter_key); free(enter_key);
if (up_key != NULL) if (up_key != NULL)
free(up_key); free(up_key);
if (down_key != NULL) if (down_key != NULL)
free(down_key); free(down_key);
if (left_key != NULL) if (left_key != NULL)
free(left_key); free(left_key);
if (right_key != NULL) if (right_key != NULL)
free(right_key); free(right_key);
keymask = 0; keymask = 0;
return 0; return 0;
} }
void menuscreen_inform_item_destruction(MenuItem *item) void
menuscreen_inform_item_destruction(MenuItem * item)
{ {
MenuItem *i; MenuItem *i;
debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__,
((item != NULL) ? item->id : "(null)")); ((item != NULL) ? item->id : "(null)"));
/* Are we currently in (a subitem of) the given item ? */ /* Are we currently in (a subitem of) the given item ? */
for (i = active_menuitem; i != NULL; i = i->parent) { for (i = active_menuitem; i != NULL; i = i->parent) {
@@ -208,10 +215,11 @@ void menuscreen_inform_item_destruction(MenuItem *item)
} }
} }
void menuscreen_inform_item_modified(MenuItem *item) void
menuscreen_inform_item_modified(MenuItem * item)
{ {
debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__,
((item != NULL) ? item->id : "(null)")); ((item != NULL) ? item->id : "(null)"));
if ((active_menuitem == NULL) || (item == NULL)) if ((active_menuitem == NULL) || (item == NULL))
return; return;
@@ -222,7 +230,8 @@ void menuscreen_inform_item_modified(MenuItem *item)
} }
} }
bool is_menu_key(const char *key) bool
is_menu_key(const char *key)
{ {
if ((menu_key != NULL) && (key != NULL) && (strcmp(key, menu_key) == 0)) if ((menu_key != NULL) && (key != NULL) && (strcmp(key, menu_key) == 0))
return true; return true;
@@ -230,12 +239,13 @@ bool is_menu_key(const char *key)
return false; return false;
} }
/** This function changes the menuitem to the given one, and does necesary /** This function changes the menuitem to the given one, and does necessary
* actions. * actions.
* To leave the menu system, specify NULL for new_menuitem. * To leave the menu system, specify NULL for new_menuitem.
* The item will not be reset when the new item is a child of the last one. * The item will not be reset when the new item is a child of the last one.
*/ */
void menuscreen_switch_item(MenuItem *new_menuitem) void
menuscreen_switch_item(MenuItem * new_menuitem)
{ {
MenuItem *old_menuitem = active_menuitem; MenuItem *old_menuitem = active_menuitem;
@@ -249,16 +259,19 @@ void menuscreen_switch_item(MenuItem *new_menuitem)
/* What was the state change ? */ /* What was the state change ? */
if (!old_menuitem && !new_menuitem) { if (!old_menuitem && !new_menuitem) {
/* Nothing to be done */ /* Nothing to be done */
} else if (old_menuitem && !new_menuitem) { }
else if (old_menuitem && !new_menuitem) {
/* leave menu system */ /* leave menu system */
menuscreen->priority = PRI_HIDDEN; menuscreen->priority = PRI_HIDDEN;
} else if (!old_menuitem && new_menuitem) { }
else if (!old_menuitem && new_menuitem) {
/* Menu is becoming active */ /* Menu is becoming active */
menuitem_reset(active_menuitem); menuitem_reset(active_menuitem);
menuitem_rebuild_screen(active_menuitem, menuscreen); menuitem_rebuild_screen(active_menuitem, menuscreen);
menuscreen->priority = PRI_INPUT; menuscreen->priority = PRI_INPUT;
} else { }
else {
/* We're left with the usual case: a menu level switch */ /* We're left with the usual case: a menu level switch */
if (old_menuitem->parent != new_menuitem) { if (old_menuitem->parent != new_menuitem) {
menuitem_reset(new_menuitem); menuitem_reset(new_menuitem);
@@ -266,34 +279,36 @@ void menuscreen_switch_item(MenuItem *new_menuitem)
menuitem_rebuild_screen(active_menuitem, menuscreen); menuitem_rebuild_screen(active_menuitem, menuscreen);
} }
if (old_menuitem && old_menuitem->event_func) if (old_menuitem && old_menuitem->event_func)
old_menuitem->event_func(old_menuitem, MENUEVENT_LEAVE); old_menuitem->event_func(old_menuitem, MENUEVENT_LEAVE);
if (new_menuitem && new_menuitem->event_func) if (new_menuitem && new_menuitem->event_func)
new_menuitem->event_func(new_menuitem, MENUEVENT_ENTER); new_menuitem->event_func(new_menuitem, MENUEVENT_ENTER);
return; return;
} }
static void handle_quit(void) static void
handle_quit(void)
{ {
debug(RPT_DEBUG, "%s: Closing menu screen", __FUNCTION__); debug(RPT_DEBUG, "%s: Closing menu screen", __FUNCTION__);
menuscreen_switch_item(NULL); menuscreen_switch_item(NULL);
} }
static void handle_close(void) static void
handle_close(void)
{ {
debug(RPT_DEBUG, "%s: Closing item", __FUNCTION__); debug(RPT_DEBUG, "%s: Closing item", __FUNCTION__);
menuscreen_switch_item( menuscreen_switch_item(
(active_menuitem == menuscreen_get_main()) (active_menuitem == menuscreen_get_main())
? NULL ? NULL
: active_menuitem->parent); : active_menuitem->parent);
} }
static void handle_none(void) static void
handle_none(void)
{ {
debug(RPT_DEBUG, "%s: Staying in item", __FUNCTION__); debug(RPT_DEBUG, "%s: Staying in item", __FUNCTION__);
if (active_menuitem) if (active_menuitem) {
{
menuitem_update_screen(active_menuitem, menuscreen); menuitem_update_screen(active_menuitem, menuscreen);
/* No rebuild needed, only value can be changed */ /* No rebuild needed, only value can be changed */
} }
@@ -305,45 +320,49 @@ static void handle_none(void)
* own screen. The menuitem_process_input function should do * own screen. The menuitem_process_input function should do
* things like toggling checkboxes ! * things like toggling checkboxes !
*/ */
static void handle_enter(void) static void
handle_enter(void)
{ {
debug(RPT_DEBUG, "%s: Entering subitem", __FUNCTION__); debug(RPT_DEBUG, "%s: Entering subitem", __FUNCTION__);
menuscreen_switch_item(menu_get_current_item(active_menuitem)); menuscreen_switch_item(menu_get_current_item(active_menuitem));
} }
static void handle_predecessor(void) static void
handle_predecessor(void)
{ {
MenuItem* predecessor; MenuItem *predecessor;
MenuItem* item = (active_menuitem->type == MENUITEM_MENU) MenuItem *item = (active_menuitem->type == MENUITEM_MENU)
? menu_get_item_for_predecessor_check(active_menuitem) ? menu_get_item_for_predecessor_check(active_menuitem)
: active_menuitem; : active_menuitem;
assert(item != NULL); assert(item != NULL);
debug(RPT_DEBUG, "%s: Switching to registered predecessor '%s' of '%s'.", debug(RPT_DEBUG, "%s: Switching to registered predecessor '%s' of '%s'.",
__FUNCTION__, item->predecessor_id, item->id); __FUNCTION__, item->predecessor_id, item->id);
predecessor = menuitem_search(item->predecessor_id, predecessor = menuitem_search(item->predecessor_id,
(Client *) active_menuitem->client); (Client *) active_menuitem->client);
if (predecessor == NULL) { if (predecessor == NULL) {
// note: if _quit_, _close_, _none_ get here this /*
// would be an implementation error - they should * note: if _quit_, _close_, _none_ get here this would be an
// have been handled via different MENURESULT codes. * implementation error - they should have been handled via
* different MENURESULT codes.
*/
report(RPT_ERR, "%s: cannot find predecessor '%s' of '%s'.", report(RPT_ERR, "%s: cannot find predecessor '%s' of '%s'.",
__FUNCTION__, item->predecessor_id, item->id); __FUNCTION__, item->predecessor_id, item->id);
return; return;
} }
switch (predecessor->type) { switch (predecessor->type) {
case MENUITEM_ACTION: case MENUITEM_ACTION:
case MENUITEM_CHECKBOX: case MENUITEM_CHECKBOX:
case MENUITEM_RING: case MENUITEM_RING:
if (active_menuitem != predecessor->parent) if (active_menuitem != predecessor->parent)
menuscreen_switch_item(predecessor->parent); menuscreen_switch_item(predecessor->parent);
// this won't work for hidden subitems /* this won't work for hidden subitems */
menu_select_subitem(active_menuitem, item->predecessor_id); menu_select_subitem(active_menuitem, item->predecessor_id);
menuitem_update_screen(active_menuitem, menuscreen); menuitem_update_screen(active_menuitem, menuscreen);
break; break;
default: default:
if ((predecessor->parent != NULL) && if ((predecessor->parent != NULL) &&
(predecessor->parent->type == MENUITEM_MENU)) { (predecessor->parent->type == MENUITEM_MENU)) {
// update parent menu too /* update parent menu too */
menu_select_subitem(predecessor->parent, predecessor->id); menu_select_subitem(predecessor->parent, predecessor->id);
} }
menuscreen_switch_item(predecessor); menuscreen_switch_item(predecessor);
@@ -351,39 +370,42 @@ static void handle_predecessor(void)
} }
} }
static void handle_successor(void) static void
handle_successor(void)
{ {
MenuItem *successor; MenuItem *successor;
MenuItem* item = (active_menuitem->type == MENUITEM_MENU) MenuItem *item = (active_menuitem->type == MENUITEM_MENU)
? menu_get_item_for_successor_check(active_menuitem) ? menu_get_item_for_successor_check(active_menuitem)
: active_menuitem; : active_menuitem;
assert(item != NULL); assert(item != NULL);
debug(RPT_DEBUG, "%s: Switching to registered successor '%s' of '%s'.", debug(RPT_DEBUG, "%s: Switching to registered successor '%s' of '%s'.",
__FUNCTION__, item->successor_id, item->id); __FUNCTION__, item->successor_id, item->id);
successor = menuitem_search(item->successor_id, successor = menuitem_search(item->successor_id,
(Client *) active_menuitem->client); (Client *) active_menuitem->client);
if (successor == NULL) { if (successor == NULL) {
// note: if _quit_, _close_, _none_ get here this /*
// would be an implementation error - they should * note: if _quit_, _close_, _none_ get here this would be an
// have been handled via different MENURESULT codes. * implementation error - they should have been handled via
* different MENURESULT codes.
*/
report(RPT_ERR, "%s: cannot find successor '%s' of '%s'.", report(RPT_ERR, "%s: cannot find successor '%s' of '%s'.",
__FUNCTION__, item->successor_id, item->id); __FUNCTION__, item->successor_id, item->id);
return; return;
} }
switch (successor->type) { switch (successor->type) {
case MENUITEM_ACTION: case MENUITEM_ACTION:
case MENUITEM_CHECKBOX: case MENUITEM_CHECKBOX:
case MENUITEM_RING: case MENUITEM_RING:
if (active_menuitem != successor->parent) if (active_menuitem != successor->parent)
menuscreen_switch_item(successor->parent); menuscreen_switch_item(successor->parent);
// this won't work for hidden subitems /* this won't work for hidden subitems */
menu_select_subitem(active_menuitem, item->successor_id); menu_select_subitem(active_menuitem, item->successor_id);
menuitem_update_screen(active_menuitem, menuscreen); menuitem_update_screen(active_menuitem, menuscreen);
break; break;
default: default:
if ((successor->parent != NULL) && if ((successor->parent != NULL) &&
(successor->parent->type == MENUITEM_MENU)) { (successor->parent->type == MENUITEM_MENU)) {
// update parent menu too /* update parent menu too */
menu_select_subitem(successor->parent, successor->id); menu_select_subitem(successor->parent, successor->id);
} }
menuscreen_switch_item(successor); menuscreen_switch_item(successor);
@@ -391,7 +413,8 @@ static void handle_successor(void)
} }
} }
void menuscreen_key_handler(const char *key) void
menuscreen_key_handler(const char *key)
{ {
MenuToken token = MENUTOKEN_NONE; MenuToken token = MENUTOKEN_NONE;
MenuResult res; MenuResult res;
@@ -429,34 +452,35 @@ void menuscreen_key_handler(const char *key)
res = menuitem_process_input(active_menuitem, token, key, keymask); res = menuitem_process_input(active_menuitem, token, key, keymask);
switch (res) { switch (res) {
case MENURESULT_ERROR: case MENURESULT_ERROR:
report(RPT_ERR, "%s: Error from menuitem_process_input", __FUNCTION__); report(RPT_ERR, "%s: Error from menuitem_process_input", __FUNCTION__);
break; break;
case MENURESULT_NONE: case MENURESULT_NONE:
handle_none(); handle_none();
break; break;
case MENURESULT_ENTER: case MENURESULT_ENTER:
handle_enter(); handle_enter();
break; break;
case MENURESULT_CLOSE: case MENURESULT_CLOSE:
handle_close(); handle_close();
break; break;
case MENURESULT_QUIT: case MENURESULT_QUIT:
handle_quit(); handle_quit();
break; break;
case MENURESULT_PREDECESSOR: case MENURESULT_PREDECESSOR:
handle_predecessor(); handle_predecessor();
break; break;
case MENURESULT_SUCCESSOR: case MENURESULT_SUCCESSOR:
handle_successor(); handle_successor();
break; break;
default: default:
assert(!"unexpected menuresult"); assert(!"unexpected menuresult");
break; break;
} }
} }
void menuscreen_create_menu(void) void
menuscreen_create_menu(void)
{ {
Menu *options_menu; Menu *options_menu;
Menu *driver_menu; Menu *driver_menu;
@@ -480,10 +504,10 @@ void menuscreen_create_menu(void)
menu_add_item(main_menu, options_menu); menu_add_item(main_menu, options_menu);
#ifdef LCDPROC_TESTMENUS #ifdef LCDPROC_TESTMENUS
/* TODO: /*
* Menu items in the screens menu currently have no functions assigned. * TODO: Menu items in the screens menu currently have no functions
* Thefore only enable the menu for testing. If functions are available, * assigned. Therefore only enable the menu for testing. If functions
* this code should be outside the #ifdef. * are available, this code should be outside the #ifdef.
*/ */
screens_menu = menu_create("screens", NULL, "Screens", NULL); screens_menu = menu_create("screens", NULL, "Screens", NULL);
if (screens_menu == NULL) { if (screens_menu == NULL) {
@@ -495,8 +519,10 @@ void menuscreen_create_menu(void)
menuscreen_create_testmenu(); menuscreen_create_testmenu();
#endif #endif
/* add option menu contents: /*
* menu's client is NULL since we're in the server */ * add option menu contents: menu's client is NULL since we're in the
* server
*/
checkbox = menuitem_create_checkbox("heartbeat", heartbeat_handler, "Heartbeat", NULL, true, heartbeat); checkbox = menuitem_create_checkbox("heartbeat", heartbeat_handler, "Heartbeat", NULL, true, heartbeat);
menu_add_item(options_menu, checkbox); menu_add_item(options_menu, checkbox);
@@ -507,8 +533,10 @@ void menuscreen_create_menu(void)
"TitleSpeed", NULL, "0", "10", TITLESPEED_NO, TITLESPEED_MAX, 1, titlespeed); "TitleSpeed", NULL, "0", "10", TITLESPEED_NO, TITLESPEED_MAX, 1, titlespeed);
menu_add_item(options_menu, slider); menu_add_item(options_menu, slider);
/* add driver specific option menus for each driver: /*
* menu's client is NULL since we're in the server */ * add driver specific option menus for each driver: menu's client is
* NULL since we're in the server
*/
for (driver = drivers_getfirst(); driver; driver = drivers_getnext()) { for (driver = drivers_getfirst(); driver; driver = drivers_getnext()) {
int contrast_avail = (driver->get_contrast && driver->set_contrast) ? 1 : 0; int contrast_avail = (driver->get_contrast && driver->set_contrast) ? 1 : 0;
int brightness_avail = (driver->get_brightness && driver->set_brightness) ? 1 : 0; int brightness_avail = (driver->get_brightness && driver->set_brightness) ? 1 : 0;
@@ -518,7 +546,7 @@ void menuscreen_create_menu(void)
driver_menu = menu_create(driver->name, NULL, driver->name, NULL); driver_menu = menu_create(driver->name, NULL, driver->name, NULL);
if (driver_menu == NULL) { if (driver_menu == NULL) {
report(RPT_ERR, "%s: Cannot create menu for driver %s", report(RPT_ERR, "%s: Cannot create menu for driver %s",
__FUNCTION__, driver->name); __FUNCTION__, driver->name);
continue; continue;
} }
menu_set_association(driver_menu, driver); menu_set_association(driver_menu, driver);
@@ -528,7 +556,7 @@ void menuscreen_create_menu(void)
/* menu's client is NULL since we're in the server */ /* menu's client is NULL since we're in the server */
slider = menuitem_create_slider("contrast", contrast_handler, "Contrast", slider = menuitem_create_slider("contrast", contrast_handler, "Contrast",
NULL, "min", "max", 0, 1000, 25, contrast); NULL, "min", "max", 0, 1000, 25, contrast);
menu_add_item(driver_menu, slider); menu_add_item(driver_menu, slider);
} }
if (brightness_avail) { if (brightness_avail) {
@@ -536,11 +564,11 @@ void menuscreen_create_menu(void)
int offbrightness = driver->get_brightness(driver, BACKLIGHT_OFF); int offbrightness = driver->get_brightness(driver, BACKLIGHT_OFF);
slider = menuitem_create_slider("onbrightness", brightness_handler, "On Brightness", slider = menuitem_create_slider("onbrightness", brightness_handler, "On Brightness",
NULL, "min", "max", 0, 1000, 25, onbrightness); NULL, "min", "max", 0, 1000, 25, onbrightness);
menu_add_item(driver_menu, slider); menu_add_item(driver_menu, slider);
slider = menuitem_create_slider("offbrightness", brightness_handler, "Off Brightness", slider = menuitem_create_slider("offbrightness", brightness_handler, "Off Brightness",
NULL, "min", "max", 0, 1000, 25, offbrightness); NULL, "min", "max", 0, 1000, 25, offbrightness);
menu_add_item(driver_menu, slider); menu_add_item(driver_menu, slider);
} }
} }
@@ -548,7 +576,9 @@ void menuscreen_create_menu(void)
} }
#ifdef LCDPROC_TESTMENUS #ifdef LCDPROC_TESTMENUS
void menuscreen_create_testmenu(void) { void
menuscreen_create_testmenu(void)
{
MenuItem *test_item; MenuItem *test_item;
Menu *test_menu; Menu *test_menu;
@@ -609,20 +639,20 @@ void menuscreen_create_testmenu(void) {
test_item = menuitem_create_alpha("", NULL, "Alpha, caps only", NULL, 0, 3, 12, true, false, false, "-", "LCDPROC"); test_item = menuitem_create_alpha("", NULL, "Alpha, caps only", NULL, 0, 3, 12, true, false, false, "-", "LCDPROC");
menu_add_item(test_menu, test_item); menu_add_item(test_menu, test_item);
test_item = menuitem_create_ip("", NULL, "IPv4", NULL, 0, "192.168.1.245"); test_item = menuitem_create_ip("", NULL, "IPv4", NULL, false, "192.168.1.245");
menu_add_item(test_menu, test_item); menu_add_item(test_menu, test_item);
test_item = menuitem_create_ip("", NULL, "IPv6", NULL, 1, "1080:0:0:0:8:800:200C:417A"); test_item = menuitem_create_ip("", NULL, "IPv6", NULL, true, "1080:0:0:0:8:800:200C:417A");
menu_add_item(test_menu, test_item); menu_add_item(test_menu, test_item);
test_item = menuitem_create_ring("", NULL, "Charset", NULL, testiso, 0); test_item = menuitem_create_ring("", NULL, "Charset", NULL, testiso, 0);
menu_add_item(test_menu, test_item); menu_add_item(test_menu, test_item);
} }
#endif /*LCDPROC_TESTMENUS*/ #endif /* LCDPROC_TESTMENUS */
MenuEventFunc (heartbeat_handler) MenuEventFunc(heartbeat_handler)
{ {
debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), event); ((item != NULL) ? item->id : "(null)"), event);
if ((item != NULL) && (event == MENUEVENT_UPDATE)) { if ((item != NULL) && (event == MENUEVENT_UPDATE)) {
/* Set heartbeat setting */ /* Set heartbeat setting */
@@ -632,10 +662,10 @@ MenuEventFunc (heartbeat_handler)
return 0; return 0;
} }
MenuEventFunc (backlight_handler) MenuEventFunc(backlight_handler)
{ {
debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), event); ((item != NULL) ? item->id : "(null)"), event);
if ((item != NULL) && (event == MENUEVENT_UPDATE)) { if ((item != NULL) && (event == MENUEVENT_UPDATE)) {
/* Set backlight setting */ /* Set backlight setting */
@@ -645,10 +675,10 @@ MenuEventFunc (backlight_handler)
return 0; return 0;
} }
MenuEventFunc (titlespeed_handler) MenuEventFunc(titlespeed_handler)
{ {
debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), event); ((item != NULL) ? item->id : "(null)"), event);
if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) { if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) {
/* set titlespeed setting */ /* set titlespeed setting */
@@ -658,12 +688,15 @@ MenuEventFunc (titlespeed_handler)
return 0; return 0;
} }
MenuEventFunc (contrast_handler) MenuEventFunc(contrast_handler)
{ {
debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), event); ((item != NULL) ? item->id : "(null)"), event);
/* This function can be called by one of several drivers that support contrast */ /*
* This function can be called by one of several drivers that support
* contrast
*/
if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) { if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) {
/* Determine the driver by following the menu's association */ /* Determine the driver by following the menu's association */
Driver *driver = item->parent->data.menu.association; Driver *driver = item->parent->data.menu.association;
@@ -671,18 +704,21 @@ MenuEventFunc (contrast_handler)
if (driver != NULL) { if (driver != NULL) {
driver->set_contrast(driver, item->data.slider.value); driver->set_contrast(driver, item->data.slider.value);
report(RPT_INFO, "Menu: set contrast of [%.40s] to %d", report(RPT_INFO, "Menu: set contrast of [%.40s] to %d",
driver->name, item->data.slider.value); driver->name, item->data.slider.value);
} }
} }
return 0; return 0;
} }
MenuEventFunc (brightness_handler) MenuEventFunc(brightness_handler)
{ {
debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__,
((item != NULL) ? item->id : "(null)"), event); ((item != NULL) ? item->id : "(null)"), event);
/* This function can be called by one of several drivers that support brightness ! */ /*
* This function can be called by one of several drivers that support
* brightness !
*/
if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) { if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) {
/* Determine the driver by following the menu's association */ /* Determine the driver by following the menu's association */
Driver *driver = item->parent->data.menu.association; Driver *driver = item->parent->data.menu.association;
@@ -706,7 +742,7 @@ menuscreen_add_screen(Screen *s)
MenuItem *mi; MenuItem *mi;
debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__, debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__,
((s != NULL) ? s->id : "(null)")); ((s != NULL) ? s->id : "(null)"));
/* screens have not been created or no screen given ... */ /* screens have not been created or no screen given ... */
if ((screens_menu == NULL) || (s == NULL)) if ((screens_menu == NULL) || (s == NULL))
@@ -735,7 +771,7 @@ menuscreen_add_screen(Screen *s)
menu_add_item(m, mi); menu_add_item(m, mi);
mi = menuitem_create_ring("", NULL, "Priority", s->client, mi = menuitem_create_ring("", NULL, "Priority", s->client,
"Hidden\tBackground\tForeground\tAlert\tInput", s->priority); "Hidden\tBackground\tForeground\tAlert\tInput", s->priority);
menu_add_item(m, mi); menu_add_item(m, mi);
} }
@@ -744,7 +780,7 @@ void
menuscreen_remove_screen(Screen *s) menuscreen_remove_screen(Screen *s)
{ {
debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__, debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__,
(s != NULL) ? s->id : "(NULL)"); (s != NULL) ? s->id : "(NULL)");
/* allow to remove the menuscreen itself */ /* allow to remove the menuscreen itself */
if ((s == NULL) || (s == menuscreen)) if ((s == NULL) || (s == menuscreen))
@@ -759,22 +795,22 @@ menuscreen_remove_screen(Screen *s)
} }
int int
menuscreen_goto(Menu *menu) menuscreen_goto(Menu * menu)
{ {
debug(RPT_DEBUG, "%s(m=[%s]): active_menuitem=[%s]", debug(RPT_DEBUG, "%s(m=[%s]): active_menuitem=[%s]",
__FUNCTION__, (menu != NULL) ? menu->id : "(NULL)", __FUNCTION__, (menu != NULL) ? menu->id : "(NULL)",
(active_menuitem != NULL) ? active_menuitem->id : "(NULL)"); (active_menuitem != NULL) ? active_menuitem->id : "(NULL)");
menuscreen_switch_item(menu); menuscreen_switch_item(menu);
return 0; return 0;
} }
/** sets custom main menu. Use NULL pointer to reset it to the "real" main /** sets custom main menu. Use NULL pointer to reset it to the "real" main
* menu. */ * menu. */
int int
menuscreen_set_main(Menu *menu) menuscreen_set_main(Menu * menu)
{ {
debug(RPT_DEBUG, "%s(m=[%s])", debug(RPT_DEBUG, "%s(m=[%s])",
__FUNCTION__, (menu != NULL) ? menu->id : "(NULL)"); __FUNCTION__, (menu != NULL) ? menu->id : "(NULL)");
custom_main_menu = menu; custom_main_menu = menu;
return 0; return 0;
} }
-1
View File
@@ -16,7 +16,6 @@
#define MENUSCREENS_H #define MENUSCREENS_H
#include "menu.h" #include "menu.h"
#include "menuitem.h"
#include "screen.h" #include "screen.h"
extern Screen *menuscreen; extern Screen *menuscreen;
+1 -3
View File
@@ -12,8 +12,6 @@
#ifndef RENDER_H #ifndef RENDER_H
#define RENDER_H #define RENDER_H
#include "screen.h"
#define HEARTBEAT_OFF 0 #define HEARTBEAT_OFF 0
#define HEARTBEAT_ON 1 #define HEARTBEAT_ON 1
#define HEARTBEAT_OPEN 2 #define HEARTBEAT_OPEN 2
@@ -31,7 +29,7 @@
#define CURSOR_UNDER 5 #define CURSOR_UNDER 5
#define TITLESPEED_NO 0 /* needs to be (TITLESPEED_MIN - 1) */ #define TITLESPEED_NO 0 /* needs to be (TITLESPEED_MIN - 1) */
#define TITLESPEED_MIN 1 #define TITLESPEED_MIN 1
#define TITLESPEED_MAX 10 #define TITLESPEED_MAX 10
extern int heartbeat; extern int heartbeat;
-1
View File
@@ -25,7 +25,6 @@
#include "clients.h" #include "clients.h"
#include "widget.h" #include "widget.h"
#include "screenlist.h" #include "screenlist.h"
#include "screen.h"
#include "menuscreens.h" #include "menuscreens.h"
#include "main.h" #include "main.h"
#include "render.h" #include "render.h"
+30 -12
View File
@@ -1,5 +1,15 @@
/** \file server/screen.h /** \file server/screen.h
* Public interface to the screen management methods. * Public interface to the screen management methods.
*
* \note If you only need 'struct Screen' to work with you should use the
* following code (which does not create an indirect dependency on
* 'struct Widget'):
*
* \code
* #define INC_TYPES_ONLY 1
* #include "screen.h"
* #undef INC_TYPES_ONLY
* \endcode
*/ */
/* This file is part of LCDd, the lcdproc server. /* This file is part of LCDd, the lcdproc server.
@@ -11,16 +21,18 @@
* 2003, Joris Robijn * 2003, Joris Robijn
*/ */
#include "menu.h" #ifndef SCREEN_H_TYPES
#include "menuitem.h" #define SCREEN_H_TYPES
#include "client.h"
/* These headers are placed here on purpose ! (circular references) */
#ifndef SCREEN_H
#define SCREEN_H
#include "shared/LL.h" #include "shared/LL.h"
#include "client.h"
#ifdef INC_TYPES_ONLY
# include "client.h"
#else
# define INC_TYPES_ONLY 1
# include "client.h"
# undef INC_TYPES_ONLY
#endif
typedef enum { PRI_HIDDEN, PRI_BACKGROUND, PRI_INFO, PRI_FOREGROUND, typedef enum { PRI_HIDDEN, PRI_BACKGROUND, PRI_INFO, PRI_FOREGROUND,
PRI_ALERT, PRI_INPUT PRI_ALERT, PRI_INPUT
@@ -43,13 +55,18 @@ typedef struct Screen {
struct Client *client; struct Client *client;
} Screen; } Screen;
#include "widget.h"
extern int default_duration ; extern int default_duration ;
extern int default_priority ; extern int default_priority ;
#include "client.h" #endif
#ifndef INC_TYPES_ONLY
#ifndef SCREEN_H_FNCS
#define SCREEN_H_FNCS
#define INC_TYPES_ONLY 1
#include "widget.h"
#undef INC_TYPES_ONLY
/* Creates a new screen */ /* Creates a new screen */
Screen *screen_create(char *id, Client *client); Screen *screen_create(char *id, Client *client);
@@ -87,3 +104,4 @@ Priority screen_pri_name_to_pri(char *pri_name);
char *screen_pri_to_pri_name(Priority pri); char *screen_pri_to_pri_name(Priority pri);
#endif #endif
#endif
+3 -1
View File
@@ -18,8 +18,10 @@
#include "shared/LL.h" #include "shared/LL.h"
#include "shared/sockets.h" #include "shared/sockets.h"
#include "shared/report.h" #include "shared/report.h"
#include "screenlist.h"
#include "client.h"
#include "screen.h" #include "screen.h"
#include "screenlist.h"
#include "main.h" /* for timer */ #include "main.h" /* for timer */
+7 -1
View File
@@ -13,7 +13,13 @@
#ifndef SCREENLIST_H #ifndef SCREENLIST_H
#define SCREENLIST_H #define SCREENLIST_H
#include "screen.h" #ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#include "shared/defines.h"
#define AUTOROTATE_OFF 0 #define AUTOROTATE_OFF 0
#define AUTOROTATE_ON 1 #define AUTOROTATE_ON 1
+3 -5
View File
@@ -37,15 +37,13 @@
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include "sock.h"
#include "client.h"
#include "clients.h"
#include "screen.h"
#include "shared/report.h" #include "shared/report.h"
#include "screenlist.h"
#include "shared/sring.h" #include "shared/sring.h"
#include "shared/defines.h" #include "shared/defines.h"
#include "clients.h"
#include "sock.h"
/****************************************************************************/ /****************************************************************************/
static fd_set active_fd_set, read_fd_set; static fd_set active_fd_set, read_fd_set;
+2 -1
View File
@@ -16,8 +16,9 @@
#define SOCK_H #define SOCK_H
#include "shared/sockets.h" #include "shared/sockets.h"
#define INC_TYPES_ONLY 1
#include "client.h" #include "client.h"
#undef INC_TYPES_ONLY
/* Server functions...*/ /* Server functions...*/
int sock_init(char* bind_addr, int bind_port); int sock_init(char* bind_addr, int bind_port);
+3 -4
View File
@@ -10,13 +10,12 @@
* Copyright (c) 1999, William Ferrell, Selene Scriven * Copyright (c) 1999, William Ferrell, Selene Scriven
*/ */
#include "screen.h"
/* These headers are placed here on purpose ! (circular references) */
#ifndef WIDGET_H #ifndef WIDGET_H
#define WIDGET_H #define WIDGET_H
struct Widget; #define INC_TYPES_ONLY 1
#include "screen.h"
#undef INC_TYPES_ONLY
/* These correspond to the index into the "types" array...*/ /* These correspond to the index into the "types" array...*/
typedef enum WidgetType { typedef enum WidgetType {
+7
View File
@@ -20,4 +20,11 @@
# define max(a,b) (((a) > (b)) ? (a) : (b)) # define max(a,b) (((a) > (b)) ? (a) : (b))
#endif #endif
/* Our own way of saying yes/no */
#ifndef bool
# define bool short
# define true 1
# define false 0
#endif
#endif #endif