comparing tweaks from Lukkario
https://github.com/Lukkario/mocicon-tweak/blob/master/mocicon.c Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
ffbcc5a732
commit
c4e2560c19
1 changed files with 84 additions and 63 deletions
147
mocicon.c
147
mocicon.c
|
@ -1,38 +1,41 @@
|
||||||
//MocIcon. see README for help.
|
//MocIcon. see README for help.
|
||||||
//compile with gcc -Wall -g mocicon.c -o mocicon `pkg-config --cflags --libs gtk+-2.0`
|
//compile with gcc -Wall -g mocicon.c -o mocicon `pkg-config --cflags --libs gtk+-2.0`
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static char *notify = "bash -c 'notify-send -t 2000 \"$(mocp -Q %artist)\" \"$(mocp -Q %song)\" -i gtk-cdrom'";
|
static char *notify = "bash -c 'notify-send -t 2000 \"$(mocp -Q %artist)\" \"$(mocp -Q %song)\" -i gnome-music'";
|
||||||
|
|
||||||
GtkWidget *menu, *quit_item, *launch_item, *play_item, *stop_item, *start_item, *next_item, *prev_item;
|
|
||||||
|
|
||||||
|
GtkWidget *menu, *quit_item, *launch_item, *next_item, *prev_item;
|
||||||
|
GtkStatusIcon *icon;
|
||||||
|
|
||||||
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 0:
|
case 0:
|
||||||
g_spawn_command_line_async("mocp --play", NULL);
|
g_spawn_command_line_async("mocp -x", NULL);
|
||||||
|
g_spawn_command_line_async("pkill mocicon", NULL);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
g_spawn_command_line_async("mocp --toggle-pause", NULL);
|
g_spawn_command_line_async("mocp --toggle-pause", NULL);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
g_spawn_command_line_async("mocp --exit", NULL);
|
g_spawn_command_line_async("mocp --next", NULL);
|
||||||
|
gtk_status_icon_set_from_stock(icon, GTK_STOCK_MEDIA_PAUSE);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
g_spawn_command_line_async("mocp --next", NULL);
|
g_spawn_command_line_async("mocp --previous", NULL);
|
||||||
|
gtk_status_icon_set_from_stock(icon, GTK_STOCK_MEDIA_PAUSE);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
g_spawn_command_line_async("mocp --previous", NULL);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
g_spawn_command_line_async(notify, NULL);
|
g_spawn_command_line_async(notify, NULL);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 5:
|
||||||
g_spawn_command_line_async("xterm -C mocp", NULL);
|
g_spawn_command_line_async("xfce4-terminal -e mocp", NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -41,77 +44,95 @@ send( GtkMenuItem *item, gpointer data) {
|
||||||
|
|
||||||
|
|
||||||
static void setup() {
|
static void setup() {
|
||||||
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");
|
|
||||||
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");
|
|
||||||
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(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(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(send), GINT_TO_POINTER( 0 ));
|
||||||
g_signal_connect(G_OBJECT(play_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 1 ));
|
g_signal_connect(G_OBJECT(next_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 2 ));
|
||||||
g_signal_connect(G_OBJECT(start_item),"activate", G_CALLBACK(send), GINT_TO_POINTER( 0 ));
|
g_signal_connect(G_OBJECT(prev_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 3 ));
|
||||||
g_signal_connect(G_OBJECT(stop_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 2 ));
|
g_signal_connect(G_OBJECT(launch_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 5 ));
|
||||||
g_signal_connect(G_OBJECT(next_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 3 ));
|
|
||||||
g_signal_connect(G_OBJECT(prev_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 4 ));
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), next_item);
|
||||||
g_signal_connect(G_OBJECT(launch_item), "activate", G_CALLBACK(send), GINT_TO_POINTER( 6 ));
|
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), stop_item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), quit_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), next_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), 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)
|
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.
|
// 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.
|
// Idk. needs work.
|
||||||
|
if(ev->button == 3)
|
||||||
{
|
{
|
||||||
if(ev->button == 3)
|
// Popup the menu
|
||||||
|
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, ev->button, ev->time);
|
||||||
|
}
|
||||||
|
|
||||||
// Popup the menu
|
if(ev->button == 2)
|
||||||
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, ev->button, ev->time);
|
{
|
||||||
|
send(NULL, GINT_TO_POINTER( 4 ));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if(ev->button == 1)
|
||||||
if(ev->button == 2) {
|
{
|
||||||
send(NULL, GINT_TO_POINTER( 5 ));
|
|
||||||
}
|
//Check if mocp is running (this prevent crashing app while mocp is not running and pressing play)
|
||||||
|
if( 0 == system("pidof -x mocp > /dev/null"))
|
||||||
|
{
|
||||||
if(ev->button == 1) {
|
//Getting mocp status and changing tray icon
|
||||||
send(NULL, GINT_TO_POINTER( 1 ));
|
FILE *get_mocp_status;
|
||||||
}
|
char mocp_status_output[4];
|
||||||
|
get_mocp_status = popen("/bin/mocp -Q %state", "r");
|
||||||
|
|
||||||
|
if (get_mocp_status == NULL)
|
||||||
|
{
|
||||||
|
printf("Error: could not get status from mocp\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *mocp_output = fgets(mocp_status_output, sizeof(mocp_status_output), get_mocp_status);
|
||||||
|
|
||||||
|
if (strcmp(mocp_output, "PLA") == 0)
|
||||||
|
{
|
||||||
|
gtk_status_icon_set_from_stock(icon, GTK_STOCK_MEDIA_PLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (strcmp(mocp_output, "PAU") == 0)
|
||||||
|
{
|
||||||
|
gtk_status_icon_set_from_stock(icon, GTK_STOCK_MEDIA_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pclose(get_mocp_status);
|
||||||
|
send(NULL, GINT_TO_POINTER( 1 ));
|
||||||
|
}
|
||||||
|
}
|
||||||
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