3 #include "kernel/menu.h"
4 #include "kernel/timer.h"
5 #include "timed_menu.h"
6 #include "kernel/action.h"
8 #define TIMED_MENU(m) ((Menu *)m)
9 #define TIMED_MENU_DATA(m) ((Timed_Menu_Data *)((Menu *)m)->plugin_data)
10 static char *PLUGIN_NAME = "timed_menu";
16 /* we can use various GIO channels to support reading menus (can we add them to
23 Timer *timer; /* timer code handles free */
24 char *command; /* for the PIPE */
28 void plugin_setup_config() { }
31 void plugin_shutdown() { }
33 void timed_menu_timeout_handler(void *data)
36 ((Menu *)data)->invalid = TRUE;
38 if (!TIMED_MENU(data)->shown) {
39 switch (TIMED_MENU_DATA(data)->type) {
40 case (TIMED_MENU_PIPE):
42 /* if the menu is not shown, run a process and use its output
44 char *args[] = {"/bin/sh", "-c", TIMED_MENU_DATA(data)->command,
48 gint child, c_stdout, line_len, terminator_pos;
50 /* this blocks for now, until the event stuff can handle it */
51 if (!g_spawn_async_with_pipes(NULL,
54 G_SPAWN_DO_NOT_REAP_CHILD,
56 &child, NULL, &c_stdout, NULL,
58 g_warning("%s: Unable to run timed_menu program",
63 io = g_io_channel_unix_new(c_stdout);
65 g_error("%s: Unable to get IO channel", __FUNCTION__);
69 menu_clear(TIMED_MENU(data));
71 while ( G_IO_STATUS_NORMAL == (status =
72 g_io_channel_read_line
73 (io, &line, &line_len, &terminator_pos, NULL))
75 /* the \n looks ugly */
76 line[terminator_pos] = '\0';
77 menu_add_entry(TIMED_MENU(data),
78 menu_entry_new_separator(line));
79 g_message("%s", line);
90 Timed_Menu_Data *d = g_new(Timed_Menu_Data, 1);
91 Menu *m = menu_new("", PLUGIN_NAME, NULL);
93 m->plugin = PLUGIN_NAME;
95 d->type = TIMED_MENU_PIPE;
96 d->timer = timer_start(1000000, &timed_menu_timeout_handler, m);
99 m->plugin_data = (void *)d;
104 void plugin_destroy (void *m)
106 /* this will be freed by timer_* */
107 timer_stop( ((Timed_Menu_Data *)TIMED_MENU(m)->plugin_data)->timer);
109 g_free( TIMED_MENU(m)->plugin_data );