]> Dogcows Code - chaz/openbox/blob - plugins/menu/timed_menu.c
Menu uber patch
[chaz/openbox] / plugins / menu / timed_menu.c
1 #include "kernel/menu.h"
2 #include "kernel/timer.h"
3 #include "timed_menu.h"
4 #include "kernel/action.h"
5
6 static char *PLUGIN_NAME = "timed_menu";
7
8 typedef enum {
9 TIMED_MENU_PIPE
10 } Timed_Menu_Type;
11
12 /* we can use various GIO channels to support reading menus (can we add them to
13 the event loop? )
14 stat() based update
15 exec() based read
16 */
17 typedef struct {
18 Timed_Menu_Type type;
19 Timer *timer; /* timer code handles free */
20 } Timed_Menu_Data;
21
22
23 void plugin_setup_config() { }
24 void plugin_startup()
25 { }
26 void plugin_shutdown() { }
27
28 void timed_menu_timeout_handler(void *data)
29 {
30 Action *a;
31 printf("woop timer %s\n", ((Menu *)data)->name);
32 ((Menu *)data)->invalid = TRUE;
33
34 if (((Menu *)data)->shown) {
35 a = action_from_string("execute");
36 a->data.execute.path = g_strdup("xeyes");
37 menu_add_entry((Menu *)data, menu_entry_new("xeyes", a));
38
39 menu_show_full( (Menu *)data, ((Menu *)data)->location.x,
40 ((Menu *)data)->location.y, NULL);
41 } else {
42 GList *it;
43
44 for (it = ((Menu *)data)->entries; it; it = it->next) {
45 MenuEntry *entry = it->data;
46 menu_entry_free(entry);
47 }
48 ((Menu *)data)->entries = NULL;
49 }
50 }
51
52 void *plugin_create()
53 {
54 Timed_Menu_Data *d = g_new(Timed_Menu_Data, 1);
55 Menu *m = menu_new("", PLUGIN_NAME, NULL);
56
57 m->plugin = PLUGIN_NAME;
58
59 d->type = TIMED_MENU_PIPE;
60 d->timer = timer_start(1000000, &timed_menu_timeout_handler, m);
61
62 m->plugin_data = (void *)d;
63
64 return (void *)m;
65 }
66
67 void plugin_destroy (void *m)
68 {
69 /* this will be freed by timer_* */
70 timer_stop( ((Timed_Menu_Data *)((Menu *)m)->plugin_data)->timer);
71
72 g_free( ((Menu *)m)->plugin_data );
73 }
This page took 0.034578 seconds and 4 git commands to generate.