Timed menu that reads output from a process while the window is hidden
This commit is contained in:
parent
3fab044f34
commit
03d42b5d82
3 changed files with 67 additions and 19 deletions
|
@ -90,11 +90,11 @@ void menu_startup()
|
||||||
|
|
||||||
menu_add_entry(m, menu_entry_new_submenu("subz", s));
|
menu_add_entry(m, menu_entry_new_submenu("subz", s));
|
||||||
|
|
||||||
/*
|
|
||||||
t = (Menu *)plugin_create("timed_menu");
|
t = (Menu *)plugin_create("timed_menu");
|
||||||
a = action_from_string("execute");
|
a = action_from_string("execute");
|
||||||
a->data.execute.path = g_strdup("xeyes");
|
a->data.execute.path = g_strdup("xeyes");
|
||||||
menu_add_entry(t, menu_entry_new("xeyes", a));*/
|
menu_add_entry(t, menu_entry_new("xeyes", a));
|
||||||
|
menu_add_entry(m, menu_entry_new_submenu("timed", t));
|
||||||
|
|
||||||
s = menu_new("empty", "chub", m);
|
s = menu_new("empty", "chub", m);
|
||||||
menu_add_entry(m, menu_entry_new_submenu("empty", s));
|
menu_add_entry(m, menu_entry_new_submenu("empty", s));
|
||||||
|
@ -293,6 +293,17 @@ void menu_hide(Menu *self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void menu_clear(Menu *self) {
|
||||||
|
GList *it;
|
||||||
|
|
||||||
|
for (it = self->entries; it; it = it->next) {
|
||||||
|
MenuEntry *entry = it->data;
|
||||||
|
menu_entry_free(entry);
|
||||||
|
}
|
||||||
|
self->entries = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MenuEntry *menu_find_entry(Menu *menu, Window win)
|
MenuEntry *menu_find_entry(Menu *menu, Window win)
|
||||||
{
|
{
|
||||||
GList *it;
|
GList *it;
|
||||||
|
|
|
@ -104,6 +104,8 @@ void menu_show_full(Menu *menu, int x, int y, Client *client);
|
||||||
|
|
||||||
void menu_hide(Menu *self);
|
void menu_hide(Menu *self);
|
||||||
|
|
||||||
|
void menu_clear(Menu *self);
|
||||||
|
|
||||||
MenuEntry *menu_entry_new_full(char *label, Action *action,
|
MenuEntry *menu_entry_new_full(char *label, Action *action,
|
||||||
MenuEntryRenderType render_type,
|
MenuEntryRenderType render_type,
|
||||||
gpointer submenu);
|
gpointer submenu);
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#include "kernel/menu.h"
|
#include "kernel/menu.h"
|
||||||
#include "kernel/timer.h"
|
#include "kernel/timer.h"
|
||||||
#include "timed_menu.h"
|
#include "timed_menu.h"
|
||||||
#include "kernel/action.h"
|
#include "kernel/action.h"
|
||||||
|
|
||||||
|
#define TIMED_MENU(m) ((Menu *)m)
|
||||||
|
#define TIMED_MENU_DATA(m) ((Timed_Menu_Data *)((Menu *)m)->plugin_data)
|
||||||
static char *PLUGIN_NAME = "timed_menu";
|
static char *PLUGIN_NAME = "timed_menu";
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -17,6 +21,7 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Timed_Menu_Type type;
|
Timed_Menu_Type type;
|
||||||
Timer *timer; /* timer code handles free */
|
Timer *timer; /* timer code handles free */
|
||||||
|
char *command; /* for the PIPE */
|
||||||
} Timed_Menu_Data;
|
} Timed_Menu_Data;
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,24 +33,54 @@ void plugin_shutdown() { }
|
||||||
void timed_menu_timeout_handler(void *data)
|
void timed_menu_timeout_handler(void *data)
|
||||||
{
|
{
|
||||||
Action *a;
|
Action *a;
|
||||||
printf("woop timer %s\n", ((Menu *)data)->name);
|
|
||||||
((Menu *)data)->invalid = TRUE;
|
((Menu *)data)->invalid = TRUE;
|
||||||
|
|
||||||
if (((Menu *)data)->shown) {
|
if (!TIMED_MENU(data)->shown) {
|
||||||
a = action_from_string("execute");
|
switch (TIMED_MENU_DATA(data)->type) {
|
||||||
a->data.execute.path = g_strdup("xeyes");
|
case (TIMED_MENU_PIPE):
|
||||||
menu_add_entry((Menu *)data, menu_entry_new("xeyes", a));
|
{
|
||||||
|
/* if the menu is not shown, run a process and use its output
|
||||||
menu_show_full( (Menu *)data, ((Menu *)data)->location.x,
|
as menu */
|
||||||
((Menu *)data)->location.y, NULL);
|
char *args[] = {"/bin/sh", "-c", "ls", NULL};
|
||||||
} else {
|
GIOChannel *io;
|
||||||
GList *it;
|
char *line;
|
||||||
|
gint child, c_stdout, line_len, terminator_pos;
|
||||||
for (it = ((Menu *)data)->entries; it; it = it->next) {
|
GIOStatus status;
|
||||||
MenuEntry *entry = it->data;
|
/* this blocks for now, until the event stuff can handle it */
|
||||||
menu_entry_free(entry);
|
if (!g_spawn_async_with_pipes(NULL,
|
||||||
|
args,
|
||||||
|
NULL,
|
||||||
|
G_SPAWN_DO_NOT_REAP_CHILD,
|
||||||
|
NULL, NULL,
|
||||||
|
&child, NULL, &c_stdout, NULL,
|
||||||
|
NULL)) {
|
||||||
|
g_warning("%s: Unable to run timed_menu program",
|
||||||
|
__FUNCTION__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
io = g_io_channel_unix_new(c_stdout);
|
||||||
|
if (io == NULL) {
|
||||||
|
g_error("%s: Unable to get IO channel", __FUNCTION__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
menu_clear(TIMED_MENU(data));
|
||||||
|
|
||||||
|
while ( G_IO_STATUS_NORMAL == (status =
|
||||||
|
g_io_channel_read_line
|
||||||
|
(io, &line, &line_len, &terminator_pos, NULL))
|
||||||
|
) {
|
||||||
|
/* the \n looks ugly */
|
||||||
|
line[terminator_pos] = '\0';
|
||||||
|
menu_add_entry(TIMED_MENU(data),
|
||||||
|
menu_entry_new_separator(line));
|
||||||
|
g_message("%s", line);
|
||||||
|
g_free(line);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
((Menu *)data)->entries = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +102,7 @@ void *plugin_create()
|
||||||
void plugin_destroy (void *m)
|
void plugin_destroy (void *m)
|
||||||
{
|
{
|
||||||
/* this will be freed by timer_* */
|
/* this will be freed by timer_* */
|
||||||
timer_stop( ((Timed_Menu_Data *)((Menu *)m)->plugin_data)->timer);
|
timer_stop( ((Timed_Menu_Data *)TIMED_MENU(m)->plugin_data)->timer);
|
||||||
|
|
||||||
g_free( ((Menu *)m)->plugin_data );
|
g_free( TIMED_MENU(m)->plugin_data );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue