-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.c
253 lines (213 loc) · 8.19 KB
/
callback.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
* callback.c Copyright © 2009 by Benoît Rouits <[email protected]>
* Published under the terms of the GNU General Public License v2 (GPLv2).
*
*************************************************
* jackie: a small jack daemon startup interface *
*************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* see the COPYING file included in the jackie package or
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt for the full licence
*
*/
#include <unistd.h>
#include <libintl.h>
#include <locale.h>
#include <gtk/gtk.h>
#include <jack/jack.h>
#include <jack/statistics.h>
#include "jk.h"
#include "menu.h"
#include "about.h"
#include "version.h"
#include "window.h"
#define _(string) gettext (string)
/* handler for left-button click */
void tray_icon_on_left_click(GtkStatusIcon* instance, gpointer app_data)
{
JkAppData* d = (JkAppData*) app_data;
guint button;
button = 1;
gtk_status_icon_set_blinking(instance, FALSE);
if (app_data)
menu_show(GTK_MENU(d->left_menu), button, gtk_get_current_event_time());
}
/* handler for right-button click */
void tray_icon_on_right_click(GtkStatusIcon* instance, guint button, guint activate_time, gpointer app_data)
{
JkAppData* d = (JkAppData*) app_data;
gtk_status_icon_set_blinking(instance, FALSE);
if (app_data)
menu_show(GTK_MENU(d->right_menu), button, activate_time);
}
void jk_on_jackd_error(const char* msg) {
puts(msg);
}
void jk_on_jackd_info(const char* msg) {
puts(msg);
}
int jk_on_jackd_xrun(void* app_data) {
JkAppData* d = (JkAppData*) app_data;
gchar* buf = NULL;
buf = g_strdup_printf(_("xrun: %d. last: %.0f usecs"), ++d->xrun, jack_get_xrun_delayed_usecs(d->jackd_client));
gtk_status_icon_set_tooltip (d->tray_icon, buf);
g_free(buf);
return 0;
}
/* handler for the "Start" menu item */
void menu_item_on_start_stop(GtkMenuItem* instance, gpointer app_data)
{
JkAppData* d = (JkAppData*) app_data;
static GtkWidget* img = NULL;
/* check if jackd is running */
if (d->jackd_client) { /* stop jackd */
jack_client_close(d->jackd_client);
d->jackd_client = NULL;
gtk_status_icon_set_tooltip(d->tray_icon, _("Disconnected"));
if (img) {
gtk_widget_destroy(img);
img = NULL;
}
img = gtk_image_new_from_stock(GTK_STOCK_CONNECT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(instance), img);
gtk_menu_item_set_label(instance, "gtk-connect");
gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(instance), TRUE);
return;
}
/* else reload config then start jackd */
d->jackd_client = jack_client_open("jackie", JackNullOption, &d->jackd_status);
if (!d->jackd_client) {
gtk_status_icon_set_tooltip(d->tray_icon, _("Could not connect or start Jackd"));
} else {
/* set info/error callbacks */
jack_set_error_function(jk_on_jackd_error);
jack_set_info_function(jk_on_jackd_info);
jack_set_xrun_callback(d->jackd_client, jk_on_jackd_xrun, app_data);
jack_activate(d->jackd_client);
gtk_status_icon_set_tooltip(d->tray_icon, _("Connected"));
if (img) {
gtk_widget_destroy(img);
img = NULL;
}
img = gtk_image_new_from_stock(GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(instance), img);
gtk_menu_item_set_label(instance, "gtk-disconnect");
gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(instance), TRUE);
}
}
/* handler for the "About" menu item (see version.h) */
void menu_item_on_about(GtkMenuItem* instance, gpointer unused)
{
GtkAboutDialog* about;
const gchar* authors [] = {
PROG_AUTHOR0,
NULL
};
about = about_create (PROG_NAME, PROG_VERSION, PROG_COPYRIGHT,
PROG_COMMENT, PROG_LICENSE, PROG_WEBSITE,
authors);
about_show(about);
unused = NULL; /* avoid compiler warnings */
instance = NULL; /* _ */
return;
}
/* handler for the "Patchbay" menu item */
void menu_item_on_patch(GtkMenuItem* instance, gpointer app_data) {
JkAppData* d = (JkAppData*)app_data;
gboolean ret;
jk_read_config(d);
ret = jk_spawn_application(d->patchbay_cmdline);
if (ret == FALSE)
gtk_status_icon_set_tooltip(d->tray_icon, _("Failed to launch application"));
instance = NULL;
}
/* handler for the "Transport" menu item */
void menu_item_on_trans(GtkMenuItem* instance, gpointer app_data) {
JkAppData* d = (JkAppData*)app_data;
gboolean ret;
jk_read_config(d);
ret = jk_spawn_application(d->transport_cmdline);
if (ret == FALSE)
gtk_status_icon_set_tooltip(d->tray_icon, _("Failed to launch application"));
instance = NULL;
}
/* callback on Preferences window closed */
void on_pref_close (gpointer app_data) {
JkAppData* d = (JkAppData*)app_data;
const gchar* text;
text = gtk_entry_get_text(d->patchbay_entry);
g_free(d->patchbay_cmdline);
d->patchbay_cmdline = g_strdup(text); /* set patchbay command line */
text = gtk_entry_get_text(d->transport_entry);
g_free(d->transport_cmdline);
d->transport_cmdline = g_strdup(text); /* set transport command line */
/* write it to $HOME/.jackie */
jk_write_config(d);
gtk_widget_hide(GTK_WIDGET(d->pref_window));
gtk_widget_destroy(GTK_WIDGET(d->pref_window));
d->pref_window = NULL;
}
/* handler for the "Preference" menu item */
void menu_item_on_pref(GtkMenuItem* instance, gpointer app_data) {
JkAppData* d = (JkAppData*)app_data;
GtkVBox* vbox;
GtkHBox* hbox1;
GtkHBox* hbox2;
GtkHBox* hbox3;
GtkLabel* transport_label;
GtkLabel* patchbay_label;
GtkLabel* label0;
GtkButton* button1;
d->pref_window = window_create(_("Preferences"));
gtk_window_set_default_size (GTK_WINDOW(d->pref_window), 300, 200);
gtk_window_set_resizable (GTK_WINDOW(d->pref_window), TRUE);
vbox = GTK_VBOX(gtk_vbox_new(TRUE, 0));
gtk_container_add(GTK_CONTAINER(d->pref_window), GTK_WIDGET(vbox));
hbox1 = GTK_HBOX(gtk_hbox_new(TRUE, 0));
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox1), TRUE, FALSE, 10);
hbox2 = GTK_HBOX(gtk_hbox_new(TRUE, 0));
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox2), TRUE, FALSE, 10);
hbox3 = GTK_HBOX(gtk_hbox_new (TRUE, 0));
gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(hbox3), TRUE, FALSE, 10);
patchbay_label = GTK_LABEL(gtk_label_new(_("Patchbay command line")));
gtk_box_pack_start(GTK_BOX(hbox1), GTK_WIDGET(patchbay_label), TRUE, FALSE, 0);
transport_label = GTK_LABEL(gtk_label_new(_("Transport command line")));
gtk_box_pack_start(GTK_BOX(hbox2), GTK_WIDGET(transport_label), TRUE, FALSE, 0);
jk_read_config(d);
d->patchbay_entry = GTK_ENTRY(gtk_entry_new());
gtk_entry_set_text(d->patchbay_entry, d->patchbay_cmdline); /* patchbay command line */
gtk_box_pack_start(GTK_BOX(hbox1), GTK_WIDGET(d->patchbay_entry), TRUE, FALSE, 10);
d->transport_entry = GTK_ENTRY(gtk_entry_new());
gtk_entry_set_text(d->transport_entry, d->transport_cmdline); /* transport command line */
gtk_box_pack_start(GTK_BOX(hbox2), GTK_WIDGET(d->transport_entry), TRUE, FALSE, 10);
label0 = GTK_LABEL(gtk_label_new (""));
gtk_box_pack_start (GTK_BOX(hbox3), GTK_WIDGET(label0), TRUE, FALSE, 10);
button1 = GTK_BUTTON(gtk_button_new_from_stock (GTK_STOCK_CLOSE));
gtk_box_pack_start (GTK_BOX(hbox3), GTK_WIDGET(button1), FALSE, FALSE, 10);
g_signal_connect_swapped (G_OBJECT(button1), "clicked", G_CALLBACK(on_pref_close), (gpointer)d);
g_signal_connect_swapped(G_OBJECT(d->pref_window), "delete-event", G_CALLBACK(on_pref_close), (gpointer)d);
gtk_widget_show_all(GTK_WIDGET(d->pref_window));
instance = NULL; /* avoid warnings */
}
/* handler for the "Quit" menu item */
void menu_item_on_quit(GtkMenuItem* instance, gpointer app_data)
{
JkAppData* d = (JkAppData*) app_data;
jk_quit(d);
instance = NULL; /* useless but does not warn at compile time */
}