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", "ls", NULL};
47 gint child, c_stdout, line_len, terminator_pos;
49 /* this blocks for now, until the event stuff can handle it */
50 if (!g_spawn_async_with_pipes(NULL,
53 G_SPAWN_DO_NOT_REAP_CHILD,
55 &child, NULL, &c_stdout, NULL,
57 g_warning("%s: Unable to run timed_menu program",
62 io = g_io_channel_unix_new(c_stdout);
64 g_error("%s: Unable to get IO channel", __FUNCTION__);
68 menu_clear(TIMED_MENU(data));
70 while ( G_IO_STATUS_NORMAL == (status =
71 g_io_channel_read_line
72 (io, &line, &line_len, &terminator_pos, NULL))
74 /* the \n looks ugly */
75 line[terminator_pos] = '\0';
76 menu_add_entry(TIMED_MENU(data),
77 menu_entry_new_separator(line));
78 g_message("%s", line);
89 Timed_Menu_Data *d = g_new(Timed_Menu_Data, 1);
90 Menu *m = menu_new("", PLUGIN_NAME, NULL);
92 m->plugin = PLUGIN_NAME;
94 d->type = TIMED_MENU_PIPE;
95 d->timer = timer_start(1000000, &timed_menu_timeout_handler, m);
97 m->plugin_data = (void *)d;
102 void plugin_destroy (void *m)
104 /* this will be freed by timer_* */
105 timer_stop( ((Timed_Menu_Data *)TIMED_MENU(m)->plugin_data)->timer);
107 g_free( TIMED_MENU(m)->plugin_data );