mocicon: mostly formatting cleanup
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
82d541698d
commit
7b25f80de6
1 changed files with 71 additions and 68 deletions
131
mocicon.c
131
mocicon.c
|
@ -17,59 +17,60 @@ GtkWidget *menu, *quit_item, *launch_item, *play_item, *stop_item, *start_item,
|
||||||
static gboolean button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data);
|
static gboolean button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send( GtkMenuItem *item, gpointer data) {
|
send( GtkMenuItem *item, gpointer data)
|
||||||
|
{
|
||||||
switch(GPOINTER_TO_INT(data)) {
|
switch(GPOINTER_TO_INT(data)) {
|
||||||
case PTR_START:
|
case PTR_START:
|
||||||
g_spawn_command_line_async("mocp --play", NULL);
|
g_spawn_command_line_async("mocp --play", NULL);
|
||||||
break;
|
break;
|
||||||
case PTR_PLAYTOGGLE:
|
case PTR_PLAYTOGGLE:
|
||||||
g_spawn_command_line_async("mocp --toggle-pause", NULL);
|
g_spawn_command_line_async("mocp --toggle-pause", NULL);
|
||||||
break;
|
break;
|
||||||
case PTR_EXIT:
|
case PTR_EXIT:
|
||||||
g_spawn_command_line_async("mocp --exit", NULL);
|
g_spawn_command_line_async("mocp --exit", NULL);
|
||||||
break;
|
break;
|
||||||
case PTR_NEXT:
|
case PTR_NEXT:
|
||||||
g_spawn_command_line_async("mocp --next", NULL);
|
g_spawn_command_line_async("mocp --next", NULL);
|
||||||
break;
|
break;
|
||||||
case PTR_PREV:
|
case PTR_PREV:
|
||||||
g_spawn_command_line_async("mocp --previous", NULL);
|
g_spawn_command_line_async("mocp --previous", NULL);
|
||||||
break;
|
break;
|
||||||
case PTR_NOTIFY:
|
case PTR_NOTIFY:
|
||||||
g_spawn_command_line_async(notify, NULL);
|
g_spawn_command_line_async(notify, NULL);
|
||||||
break;
|
break;
|
||||||
case PTR_LAUNCH:
|
case PTR_LAUNCH:
|
||||||
g_spawn_command_line_async("xterm -C mocp", NULL);
|
g_spawn_command_line_async("xterm -C mocp", NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
static void setup() {
|
setup()
|
||||||
|
{
|
||||||
GtkStatusIcon *icon;
|
GtkStatusIcon *icon;
|
||||||
icon = gtk_status_icon_new_from_stock(GTK_STOCK_MEDIA_PLAY);
|
icon = gtk_status_icon_new_from_stock(GTK_STOCK_MEDIA_PLAY);
|
||||||
g_signal_connect(icon,"button-press-event", G_CALLBACK(button_press_cb), NULL);
|
g_signal_connect(icon,"button-press-event", G_CALLBACK(button_press_cb), NULL);
|
||||||
menu = gtk_menu_new();
|
menu = gtk_menu_new();
|
||||||
|
|
||||||
// Create Items
|
// Create Items
|
||||||
start_item = gtk_image_menu_item_new_with_label("Start Server");
|
start_item = gtk_image_menu_item_new_with_label("Start Server");
|
||||||
stop_item = gtk_image_menu_item_new_with_label("Stop Server");
|
stop_item = gtk_image_menu_item_new_with_label("Stop Server");
|
||||||
next_item = gtk_image_menu_item_new_with_label("Next");
|
next_item = gtk_image_menu_item_new_with_label("Next");
|
||||||
prev_item = gtk_image_menu_item_new_with_label("Previous");
|
prev_item = gtk_image_menu_item_new_with_label("Previous");
|
||||||
play_item = gtk_image_menu_item_new_with_label("Play/Pause");
|
play_item = gtk_image_menu_item_new_with_label("Play/Pause");
|
||||||
launch_item = gtk_image_menu_item_new_with_label("Launch Moc");
|
launch_item = gtk_image_menu_item_new_with_label("Launch Moc");
|
||||||
quit_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
|
quit_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
|
||||||
|
|
||||||
// Comment this section out if you don't want icons. sorry about the quit, it's stock.
|
// Comment this section out if you don't want icons. sorry about the quit, it's stock.
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(start_item), gtk_image_new_from_stock(GTK_STOCK_YES, GTK_ICON_SIZE_MENU));
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(start_item), gtk_image_new_from_stock(GTK_STOCK_YES, GTK_ICON_SIZE_MENU));
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(stop_item), gtk_image_new_from_stock(GTK_STOCK_NO, GTK_ICON_SIZE_MENU));
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(stop_item), gtk_image_new_from_stock(GTK_STOCK_NO, GTK_ICON_SIZE_MENU));
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(next_item), gtk_image_new_from_stock(GTK_STOCK_MEDIA_FORWARD, GTK_ICON_SIZE_MENU));
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(next_item), gtk_image_new_from_stock(GTK_STOCK_MEDIA_FORWARD, GTK_ICON_SIZE_MENU));
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(prev_item), gtk_image_new_from_stock(GTK_STOCK_MEDIA_REWIND, GTK_ICON_SIZE_MENU));
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(prev_item), gtk_image_new_from_stock(GTK_STOCK_MEDIA_REWIND, GTK_ICON_SIZE_MENU));
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(play_item), gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_MENU));
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(play_item), gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_MENU));
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(launch_item), gtk_image_new_from_stock(GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU));
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(launch_item), gtk_image_new_from_stock(GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU));
|
||||||
g_signal_connect(G_OBJECT(quit_item), "activate", G_CALLBACK(gtk_main_quit), NULL);
|
g_signal_connect(G_OBJECT(quit_item), "activate", G_CALLBACK(gtk_main_quit), NULL);
|
||||||
g_signal_connect(G_OBJECT(play_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( PTR_PLAYTOGGLE ));
|
g_signal_connect(G_OBJECT(play_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( PTR_PLAYTOGGLE ));
|
||||||
g_signal_connect(G_OBJECT(start_item),"activate", G_CALLBACK(send), GINT_TO_POINTER( PTR_START ));
|
g_signal_connect(G_OBJECT(start_item),"activate", G_CALLBACK(send), GINT_TO_POINTER( PTR_START ));
|
||||||
g_signal_connect(G_OBJECT(stop_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( PTR_EXIT ));
|
g_signal_connect(G_OBJECT(stop_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( PTR_EXIT ));
|
||||||
|
@ -79,46 +80,48 @@ static void setup() {
|
||||||
|
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), stop_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), stop_item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), start_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), start_item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), play_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), play_item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), next_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), next_item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), prev_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), prev_item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), launch_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), launch_item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), quit_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), quit_item);
|
||||||
// show widgets
|
// show widgets
|
||||||
gtk_widget_show_all(menu);
|
gtk_widget_show_all(menu);
|
||||||
};
|
|
||||||
|
|
||||||
gboolean button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data)
|
|
||||||
{
|
|
||||||
// I am not entirely sure what to do, double click implementation is possible. say double click to get info. single click just pause/plays. but it will STILL register the first click, so it would pause and then give info.
|
|
||||||
// Idk. needs work.
|
|
||||||
|
|
||||||
{
|
|
||||||
if(ev->button == 3)
|
|
||||||
|
|
||||||
// Popup the menu
|
|
||||||
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, ev->button, ev->time);
|
|
||||||
|
|
||||||
}
|
|
||||||
if(ev->button == 2) {
|
|
||||||
send(NULL, GINT_TO_POINTER( PTR_NOTIFY ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data)
|
||||||
|
{
|
||||||
|
// I am not entirely sure what to do, double click implementation is
|
||||||
|
// possible. say double click to get info. single click just
|
||||||
|
// pause/plays. but it will STILL register the first click, so it would
|
||||||
|
// pause and then give info.
|
||||||
|
// Idk. needs work.
|
||||||
|
|
||||||
if(ev->button == 1) {
|
if(ev->button == 3) {
|
||||||
|
// Popup the menu
|
||||||
|
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, ev->button, ev->time);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ev->button == 2) {
|
||||||
|
send(NULL, GINT_TO_POINTER( PTR_NOTIFY ));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ev->button == 1) {
|
||||||
send(NULL, GINT_TO_POINTER( PTR_PLAYTOGGLE ));
|
send(NULL, GINT_TO_POINTER( PTR_PLAYTOGGLE ));
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this whole section really should just be one function with an if/then statement instead of a dozen different little functions
|
//this whole section really should just be one function with an if/then statement instead of a dozen different little functions
|
||||||
|
|
||||||
//play or pause
|
//play or pause
|
||||||
gint main(gint argc, gchar **argv)
|
gint
|
||||||
|
main(gint argc, gchar **argv)
|
||||||
{
|
{
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
setup();
|
setup();
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue