XML serialization for set files, bug fixes and a new full screen mode
[terminatorX.git] / terminatorX / src / tX_mastergui.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2002  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_mastergui.cc
20  
21     Description: This implements the main (aka master) gtk+ GUI of terminatorX
22                  It serves as a container for the vtt-guis.
23 */    
24
25 #include <gtk/gtk.h>
26 #include <gdk/gdkx.h>
27 #include <X11/Xlib.h>
28 #include <math.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include "version.h"
32 #include "tX_global.h"
33 #include "tX_engine.h"
34 #include "tX_vttgui.h"
35 #include "tX_vtt.h"
36 #include "tX_flash.h"
37 #include "tX_dialog.h"
38 #include "tX_loaddlg.h"
39 #include "tX_seqpar.h"
40 #include "tX_pbutton.h"
41 #include "tX_sequencer.h"
42 #include "tX_mastergui.h"
43 #include "tX_knobloader.h"
44
45 #ifdef USE_SCHEDULER
46 #include <sys/time.h>
47 #include <sys/resource.h>
48 #endif
49
50 #define TX_SET_ID_10 "terminatorX turntable set file - version 1.0 - data:"
51 #define TX_SET_ID_11 "terminatorX turntable set file - version 1.1 - data:"
52 #define TX_SET_ID_12 "terminatorX turntable set file - version 1.2 - data:"
53 #define TX_SET_ID_13 "terminatorX turntable set file - version 1.3 - data:"
54 #define TX_SET_ID_14 "terminatorX turntable set file - version 1.4 - data:"
55
56 int audioon=0;
57 int sequencer_ready=1;
58
59 GtkWidget *tt_parent;
60 GtkWidget *control_parent;
61 GtkWidget *audio_parent;
62 GtkWidget *main_window;
63 GtkWidget *wav_progress;
64 GtkWidget *grab_button;
65 GtkWidget *main_flash_l;
66 GtkWidget *main_flash_r;
67 GtkWidget *rec_btn;
68 GtkWidget *fullscreen_button;
69
70 GtkWidget *seq_rec_btn;
71 GtkWidget *seq_play_btn;
72 GtkWidget *seq_stop_btn;
73 GtkAdjustment *seq_adj;
74 GtkWidget *seq_slider;
75 GtkWidget *seq_entry;
76 GtkWidget *panel_bar;
77
78 int buttons_on_panel_bar=0;
79
80 int seq_adj_care=1;
81 int seq_stop_override=0;
82
83 GtkAdjustment *volume_adj;
84 GtkAdjustment *pitch_adj;
85
86 /* seq-pars */
87 tX_seqpar_master_volume sp_master_volume;
88 tX_seqpar_master_pitch sp_master_pitch;
89
90 GtkWidget *AddTable;
91 GtkWidget *LoadSet;
92 GtkWidget *SaveSet;
93
94 GtkWidget *engine_btn;
95
96 bool tX_fullscreen_status=false;
97
98 int rec_dont_care=0;
99 gint update_tag;
100
101 #define connect_entry(wid, func, ptr); gtk_signal_connect(GTK_OBJECT(wid), "activate", (GtkSignalFunc) func, (void *) ptr);
102 #define connect_adj(wid, func, ptr); gtk_signal_connect(GTK_OBJECT(wid), "value_changed", (GtkSignalFunc) func, (void *) ptr);
103 #define connect_button(wid, func, ptr); gtk_signal_connect(GTK_OBJECT(wid), "clicked", (GtkSignalFunc) func, (void *) ptr);
104
105 Window xwindow;
106 #define WID_DYN TRUE, TRUE, 0
107 #define WID_FIX FALSE, FALSE, 0
108 extern void add_vtt(GtkWidget *ctrl, GtkWidget *audio, char *fn);
109 extern void destroy_gui(vtt_class *vtt);
110 extern void gui_show_frame(vtt_class *vtt, int show);
111
112 GdkWindow *save_dialog_win=NULL;
113 GdkWindow *load_dialog_win=NULL;
114 GtkWidget *save_dialog=NULL;
115 GtkWidget *load_dialog=NULL;
116
117 GdkWindow *rec_dialog_win=NULL;
118 GtkWidget *rec_dialog=NULL;
119
120 GtkWidget *no_of_vtts=NULL;
121 GtkWidget *used_mem=NULL;
122
123 int stop_update=0;
124 int update_delay;
125
126 vtt_class *old_focus=NULL;
127
128 int grab_status=0;
129 int last_grab_status=0;
130
131 GtkTooltips *gui_tooltips=NULL;
132
133 void gui_set_tooltip(GtkWidget *wid, char *tip)
134 {
135         gtk_tooltips_set_tip(gui_tooltips, wid, tip, NULL);
136 }
137
138 void turn_audio_off(void)
139 {
140         if (audioon) 
141         {
142                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0);
143                 while (gtk_events_pending()) gtk_main_iteration();              
144         }
145 }
146
147
148 gint pos_update(gpointer data)
149 {
150         f_prec temp;
151
152         if (stop_update) 
153         {               
154                 cleanup_all_vtts();
155                 tX_seqpar :: update_all_graphics();
156                 if (old_focus) gui_show_frame(old_focus, 0);
157                 old_focus=NULL;
158                 gtk_tx_flash_clear(main_flash_l);
159                 gtk_tx_flash_clear(main_flash_r);
160                 gdk_flush();    
161                 update_tag=0;
162                 return(FALSE);
163         }
164         else
165         {
166                 update_all_vtts();
167                 
168                 /*left vu meter */
169                 temp=vtt_class::mix_max_l;
170                 vtt_class::mix_max_l=0;
171                 gtk_tx_flash_set_level(main_flash_l, temp);
172
173                 /*right vu meter */
174                 temp=vtt_class::mix_max_r;
175                 vtt_class::mix_max_r=0;
176                 gtk_tx_flash_set_level(main_flash_r, temp);
177                 
178                 if (vtt_class::focused_vtt!=old_focus)
179                 {
180                         if (old_focus) gui_show_frame(old_focus, 0);
181                         old_focus=vtt_class::focused_vtt;
182                         if (old_focus) gui_show_frame(old_focus, 1);                    
183                 }
184                 if (grab_status!=last_grab_status)
185                 {
186                         last_grab_status=grab_status;
187                         if (!grab_status) 
188                         {
189                                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(grab_button), 0);
190                         }
191                 }
192                 gdk_flush();    
193                 update_delay--;
194                 
195                 if (update_delay < 0)
196                 {
197                         seq_update();
198                         tX_seqpar :: update_all_graphics();
199                         update_delay=globals.update_delay;
200                 }
201                 return(TRUE);
202         }
203 }
204
205 void mg_update_status()
206 {
207         FILE *procfs;
208         pid_t mypid;
209         char filename[PATH_MAX];
210         char buffer[256];
211         int found=0;    
212         int mem;
213         
214         mypid=getpid();
215         sprintf(filename, "/proc/%i/status", mypid);
216         procfs=fopen(filename, "r");
217         if (procfs)
218         {
219                 while((!feof(procfs)) && !found)
220                 {
221                         fgets(buffer, 256, procfs);
222                         if (strncmp("VmSize:", buffer, 7)==0)
223                         {
224                                 found=1;
225                                 sscanf(buffer, "VmSize: %i kB", &mem);
226                                 sprintf(buffer, "%i", mem);
227                                 gtk_label_set(GTK_LABEL(used_mem), buffer);
228                         }
229                 }
230         }
231         fclose(procfs); 
232         
233         sprintf(buffer, "%i", vtt_class::vtt_amount);
234         gtk_label_set(GTK_LABEL(no_of_vtts), buffer);
235 }
236
237 GtkSignalFunc new_table(GtkWidget *, char *fn)
238 {
239         turn_audio_off();
240                 
241                 if (fn) 
242                 {
243                         ld_create_loaddlg(TX_LOADDLG_MODE_SINGLE, 1);
244                         ld_set_filename(fn);
245                 }
246                 
247                 add_vtt(control_parent, audio_parent, fn);                              
248                 
249                 if (fn) ld_destroy();           
250         mg_update_status();
251         return NULL;
252 }
253
254 GtkSignalFunc drop_new_table(GtkWidget *widget, GdkDragContext *context,
255                 gint x, gint y, GtkSelectionData *selection_data,
256                 guint info, guint time, vtt_class *vtt)
257 {
258         char filename[PATH_MAX];
259         char *fn;
260         
261         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
262         filename[selection_data->length]=0;
263
264         fn = strchr (filename, '\r');
265         *fn=0;  
266         
267         fn = strchr (filename, ':');
268         if (fn) fn++; else fn=(char *) selection_data->data;
269         
270         new_table(NULL, fn);
271
272         strcpy (filename, "dont segfault workaround ;)");
273         return NULL;
274 }
275
276
277 /* Loading saved setups */
278
279 GtkSignalFunc cancel_load_tables(GtkWidget *wid)
280 {
281         gtk_widget_destroy(load_dialog);
282         load_dialog=NULL;
283         load_dialog_win=NULL;
284         return(0);
285 }
286
287 void load_tt_part(char * buffer)
288 {
289         FILE *in;
290         char idbuff[256];
291         char wbuf[PATH_MAX];
292         xmlDocPtr doc;
293         
294         turn_audio_off();
295         
296         strcpy(globals.tables_filename, buffer);
297         
298         doc = xmlParseFile(buffer);
299         if (doc) {
300                 vtt_class::load_all(doc, buffer);
301                 xmlFreeDoc(doc);
302         } 
303         
304 #ifdef ENABLE_TX_LEGACY
305         else {  
306                 in=fopen(buffer, "r");  
307         
308                 if (in) {
309                         fread(idbuff, strlen(TX_SET_ID_10), 1, in);
310                         if (strncmp(idbuff, TX_SET_ID_10, strlen(TX_SET_ID_10))==0) {
311                                 if (vtt_class::load_all_10(in, buffer)) tx_note("Error while reading set.", true);
312                         } else if (strncmp(idbuff, TX_SET_ID_11, strlen(TX_SET_ID_11))==0)      {
313                                 if (vtt_class::load_all_11(in, buffer)) tx_note("Error while reading set.", true);                      
314                         } else if (strncmp(idbuff, TX_SET_ID_12, strlen(TX_SET_ID_12))==0) {
315                                 if (vtt_class::load_all_12(in, buffer)) tx_note("Error while reading set.", true);                      
316                         } else if (strncmp(idbuff, TX_SET_ID_13, strlen(TX_SET_ID_13))==0) {
317                                 if (vtt_class::load_all_13(in, buffer)) tx_note("Error while reading set.", true);                      
318                         } else if (strncmp(idbuff, TX_SET_ID_14, strlen(TX_SET_ID_14))==0) {
319                                 if (vtt_class::load_all_14(in, buffer)) tx_note("Error while reading set.", true);                      
320                         }       else {
321                                 tx_note("This file is not a terminatorX set-file.", true);
322                                 fclose(in);
323                                 return;
324                         }
325                         fclose(in);     
326                 } else {
327                         strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
328                         strcat(idbuff, globals.tables_filename);
329                         strcat(idbuff, "\"");
330                         tx_note(idbuff, true);
331                         
332                         return;
333                 }
334         }
335 #else
336         else {
337                 strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
338                 strcat(idbuff, globals.tables_filename);
339                 strcat(idbuff, "\"");
340                 tx_note(idbuff, true);
341                 
342                 return;
343         }
344 #endif  
345         
346         tX_seqpar :: init_all_graphics();
347         vg_init_all_non_seqpars();
348                 
349         gtk_adjustment_set_value(volume_adj, 2.0-globals.volume);
350         gtk_adjustment_set_value(pitch_adj, globals.pitch);
351         sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
352         gtk_window_set_title(GTK_WINDOW(main_window), wbuf);            
353 }
354
355 void do_load_tables(GtkWidget *wid)
356 {
357         char buffer[PATH_MAX];
358         
359         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(load_dialog)));
360         
361         gtk_widget_destroy(load_dialog);
362         
363         load_dialog=NULL;
364         load_dialog_win=NULL;
365
366         load_tt_part(buffer);   
367 }
368
369 GtkSignalFunc load_tables()
370 {
371         if (load_dialog_win) 
372         {
373                 gdk_window_raise(load_dialog_win);
374                 return 0;
375         }
376         
377         load_dialog=gtk_file_selection_new("Load Set"); 
378         
379         gtk_file_selection_show_fileop_buttons(GTK_FILE_SELECTION(load_dialog));
380         gtk_file_selection_complete(GTK_FILE_SELECTION(load_dialog), "*.tX");
381         
382         if (strlen(globals.tables_filename))
383         {
384                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(load_dialog), globals.tables_filename);
385         }
386         
387         gtk_widget_show(load_dialog);
388         
389         load_dialog_win=load_dialog->window;
390         
391         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(load_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_load_tables), NULL);
392         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(load_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_load_tables), NULL); 
393         gtk_signal_connect (GTK_OBJECT(load_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_load_tables), NULL);        
394         
395         return NULL;
396 }
397
398 GtkSignalFunc drop_set(GtkWidget *widget, GdkDragContext *context,
399                 gint x, gint y, GtkSelectionData *selection_data,
400                 guint info, guint time, vtt_class *vtt)
401 {
402         char filename[PATH_MAX];
403         char *fn;
404         
405         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
406         filename[selection_data->length]=0;
407
408         fn = strchr (filename, '\r');
409         *fn=0;  
410         
411         fn = strchr (filename, ':');
412         if (fn) fn++; else fn=(char *) selection_data->data;
413         
414         load_tt_part(fn);
415
416         strcpy (filename, "dont segfault workaround ;)");
417         return NULL;
418 }
419
420
421 /* save tables */
422
423 GtkSignalFunc cancel_save_tables(GtkWidget *wid)
424 {
425         gtk_widget_destroy(save_dialog);
426         save_dialog=NULL;
427         save_dialog_win=NULL;
428         return(0);
429 }
430
431 void do_save_tables(GtkWidget *wid)
432 {
433         FILE *out;
434         char buffer[PATH_MAX];
435         char wbuf[PATH_MAX];
436         char *ext;
437         
438         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(save_dialog)));
439         strcpy(globals.tables_filename, buffer);
440         
441         gtk_widget_destroy(save_dialog);
442         
443         save_dialog=NULL;
444         save_dialog_win=NULL;
445         
446         ext=strrchr(buffer, '.');
447         
448         if (ext)
449         {
450                 if (strcmp(ext, ".tX")) strcat(buffer, ".tX");
451         }
452         else
453         {
454                 strcat(buffer, ".tX");
455         }
456         
457         out=fopen(buffer, "w");
458         
459         if (out)
460         {
461                 if (vtt_class::save_all(out)) tx_note("Error while saving set.", true);
462                 fclose(out);
463                 sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
464                 gtk_window_set_title(GTK_WINDOW(main_window), wbuf);                            
465         }
466         else
467         {
468                 tx_note("Failed to open file for write access.", true);
469         }
470 }
471
472 GtkSignalFunc save_tables()
473 {
474         if (save_dialog_win) 
475         {
476                 gdk_window_raise(save_dialog_win);
477                 return 0;
478         }
479         
480         save_dialog=gtk_file_selection_new("Save Set"); 
481         
482         if (strlen(globals.tables_filename))
483         {
484                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(save_dialog), globals.tables_filename);
485         }
486         
487         gtk_widget_show(save_dialog);
488         
489         save_dialog_win=save_dialog->window;
490         
491         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_save_tables), NULL);
492         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_save_tables), NULL); 
493         gtk_signal_connect (GTK_OBJECT(save_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_save_tables), NULL);        
494
495         return NULL;
496 }
497
498 GtkSignalFunc master_volume_changed (GtkWidget *wid, void *d)
499 {
500         sp_master_volume.receive_gui_value((float) 2.0-GTK_ADJUSTMENT(wid)->value);
501         return NULL;    
502 }
503
504 GtkSignalFunc master_pitch_changed(GtkWidget *wid, void *d)
505 {
506         sp_master_pitch.receive_gui_value((float) GTK_ADJUSTMENT(wid)->value);  
507         return NULL;    
508 }
509
510 GtkSignalFunc saturate_changed(GtkWidget *w, void *d)
511 {
512         vtt_class::enable_saturate (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)));
513         return NULL;    
514 }
515
516 void mg_enable_critical_buttons(int enable)
517 {
518         gtk_widget_set_sensitive(seq_rec_btn, enable);
519         gtk_widget_set_sensitive(seq_play_btn, enable);
520         gtk_widget_set_sensitive(seq_slider, enable);
521
522         gtk_widget_set_sensitive(rec_btn, enable);
523         vg_enable_critical_buttons(enable);
524 }
525
526
527 GtkSignalFunc seq_stop(GtkWidget *w, void *);
528
529 GtkSignalFunc audio_on(GtkWidget *w, void *d)
530 {
531         tX_engine_error res;
532         
533         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
534         {               
535                 sequencer_ready=0;
536                 mg_enable_critical_buttons(0);
537                 res=engine->run();
538                 sequencer_ready=1;
539
540                 if (res!=NO_ERROR)
541                 {
542                         mg_enable_critical_buttons(1);
543                         switch(res)
544                         {
545                                 case ERROR_BUSY:
546                                 tx_note("Error starting engine: engine is already running.", true);
547                                 break;
548                                 case ERROR_AUDIO:
549                                 tx_note("Error starting engine: failed to access audiodevice.", true);
550                                 break;
551                                 case ERROR_TAPE:
552                                 tx_note("Error starting engine: failed to open the recording file.", true);
553                                 break;
554                                 default:tx_note("Error starting engine: Unknown error.", true);
555                         }
556                         return 0;
557                 }
558
559                 stop_update=0;
560                 audioon=1;
561                 update_delay=globals.update_delay;
562                 update_tag=gtk_timeout_add(globals.update_idle, (GtkFunction) pos_update, NULL);
563                 gtk_widget_set_sensitive(grab_button, 1);
564         }
565         else
566         {               
567                 if (!sequencer_ready) return NULL;
568                 gtk_widget_set_sensitive(grab_button, 0);
569                 engine->stop();
570                 stop_update=1;
571                 audioon=0;
572                 if (engine->get_recording_request()) {
573                         engine->set_recording_request(false);
574                         rec_dont_care=1;
575                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rec_btn), 0);
576                         rec_dont_care=0;
577                 }
578                 seq_stop(NULL, NULL);
579                 mg_enable_critical_buttons(1);
580         }
581         
582         return NULL;
583 }
584
585 GtkSignalFunc cancel_rec(GtkWidget *wid)
586 {
587         gtk_widget_destroy(rec_dialog);
588         rec_dialog=NULL;
589         rec_dialog_win=NULL;
590         rec_dont_care=0;
591         return(0);
592 }
593
594 void do_rec(GtkWidget *wid)
595 {
596         char buffer[PATH_MAX];
597         
598         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(rec_dialog)));
599
600         if (strlen(buffer))
601         {
602                 strcpy(globals.record_filename, buffer);                
603                 engine->set_recording_request(true);
604                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rec_btn), 1);
605         }
606         
607         rec_dont_care=0;
608         
609         gtk_widget_destroy(rec_dialog);
610         
611         rec_dialog=NULL;
612         rec_dialog_win=NULL;
613 }
614
615 GtkSignalFunc select_rec_file()
616 {
617         if (rec_dialog_win) 
618         {
619                 gdk_window_raise(rec_dialog_win);
620                 return 0;
621         }
622         
623         rec_dialog=gtk_file_selection_new("Record To Disk");    
624         
625         if (strlen(globals.record_filename))
626         {
627                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(rec_dialog), globals.record_filename);
628         }
629         
630         gtk_widget_show(rec_dialog);
631         
632         rec_dialog_win=rec_dialog->window;
633         
634         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(rec_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_rec), NULL);
635         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(rec_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_rec), NULL);  
636         gtk_signal_connect (GTK_OBJECT(rec_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_rec), NULL); 
637         
638         return NULL;
639 }
640
641 GtkSignalFunc tape_on(GtkWidget *w, void *d)
642 {
643         if (rec_dont_care) return 0;
644
645         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
646         {       
647                 {
648                         rec_dont_care=1;
649                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
650                         select_rec_file();
651                 }
652         }
653         else
654         {
655                         engine->set_recording_request(false);
656         }
657         
658         return NULL;
659 }
660
661 void grab_on(GtkWidget *w, void *d)
662 {
663         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
664                 engine->set_grab_request();
665         }
666         grab_status=1;
667 }
668
669 void grab_off()
670 {
671         grab_status=0;
672 }
673
674 void quit()
675 {
676         turn_audio_off();
677         if (update_tag)
678         gtk_timeout_remove(update_tag);
679         globals.width=main_window->allocation.width;
680         globals.height=main_window->allocation.height;
681
682         gtk_main_quit();
683 }
684
685 void mplcfitx()
686 /* Most Probably Least Called Function In terminatorX :) */
687 {
688         show_about(0);
689 }
690
691 GtkSignalFunc seq_play(GtkWidget *w, void *)
692 {
693         if ((sequencer.is_empty()) &&   (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(seq_rec_btn)))) {
694                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
695                  {
696                         tx_note("Sequencer playback triggered - but no events recorded yet - nothing to playback!\n\nTo perform live with terminatorX just activate the audio engine with the \"Power\" button.");
697                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
698                  }
699         } else {
700                 if (seq_stop_override) return NULL;
701                         
702                 seq_adj_care=0;
703                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
704                 sequencer.trig_play();
705         
706                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 1);
707         }
708         
709         return NULL;
710 }
711
712 GtkSignalFunc seq_stop(GtkWidget *w, void *)
713 {
714         if (!sequencer_ready) return NULL;
715         sequencer.trig_stop();
716         seq_adj_care=1;
717         seq_stop_override=1;
718         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_play_btn), 0);
719         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_rec_btn), 0);
720         while (gtk_events_pending()) gtk_main_iteration();              
721         seq_stop_override=0;
722         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0); 
723         gtk_widget_set_sensitive(seq_slider, 1);        
724         gtk_widget_set_sensitive(engine_btn, 1);
725         gtk_widget_set_sensitive(seq_rec_btn, 1);
726
727         return NULL;
728 }
729
730 GtkSignalFunc seq_rec(GtkWidget *w, void *)
731 {
732         seq_adj_care=0;
733         gtk_widget_set_sensitive(seq_slider, 0);
734
735         if (seq_stop_override) return NULL;
736         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
737         gtk_widget_set_sensitive(engine_btn, 0);
738         gtk_widget_set_sensitive(seq_rec_btn, 0);
739         sequencer.trig_rec();
740         
741         return NULL;
742 }
743
744 void seq_update_entry(const guint32 timestamp)
745 {
746         char buffer[20];
747         guint32 samples;
748         guint32 minu,sec,hun;   
749         
750         samples=timestamp*globals.true_block_size;
751         
752         if (samples>0)
753         {
754                 minu=samples/2646000;
755                 samples-=2646000*minu;
756         
757                 sec=samples/44100;
758                 samples-=44100*sec;
759         
760                 hun=samples/441;
761         }
762         else
763         {
764                 minu=sec=hun=0;
765         }
766         
767         sprintf(buffer, "%02i:%02i.%02i", minu, sec, hun);
768         gtk_entry_set_text(GTK_ENTRY(seq_entry), buffer);
769 }
770
771 void seq_update()
772 {
773         seq_update_entry(sequencer.get_timestamp());
774         gtk_adjustment_set_value(seq_adj, sequencer.get_timestamp_as_float());
775         
776 }
777 void seq_slider_released(GtkWidget *wid, void *d)
778 {
779         seq_adj_care=0;
780         gtk_widget_set_sensitive(seq_slider, 0);        
781         sequencer.forward_to_start_timestamp(0);
782         gtk_widget_set_sensitive(seq_slider, 1);        
783         seq_adj_care=1;
784 }
785 void sequencer_move(GtkWidget *wid, void *d)
786 {
787         guint32 pos;
788         
789         if (seq_adj_care)
790         {
791                 pos=sequencer.set_start_timestamp((float) GTK_ADJUSTMENT(wid)->value);
792                 seq_update_entry(pos);  
793         }
794 }
795
796 #define add_sep();      dummy=gtk_hseparator_new ();\
797         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);\
798         gtk_widget_show(dummy);\
799
800 #define add_sep2();     dummy=gtk_hseparator_new ();\
801         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);\
802         gtk_widget_show(dummy);\
803
804 void create_mastergui(int x, int y)
805 {
806         GtkWidget *main_vbox;
807         GtkWidget *right_hbox;
808         GtkWidget *left_hbox;
809         GtkWidget *control_box;
810         GtkWidget *sequencer_box;
811         GtkAdjustment *dumadj;
812         GtkWidget *dummy;
813         GtkWidget *small_box;
814         GtkWidget *smaller_box;
815         
816         static GtkTargetEntry drop_types [] = {
817                 { "text/uri-list", 0, 0}
818         };
819         static gint n_drop_types = sizeof (drop_types) / sizeof(drop_types[0]);
820         
821         gui_tooltips=gtk_tooltips_new();
822
823         main_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
824
825         gtk_window_set_wmclass(GTK_WINDOW(main_window), "terminatorX", "tX_mastergui");
826
827         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
828         
829         gtk_container_set_border_width(GTK_CONTAINER(main_window), 5);
830
831         gtk_widget_realize(main_window);
832         
833         main_vbox=gtk_hbox_new(FALSE, 5);
834         
835         gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
836         gtk_widget_show(main_vbox);
837         
838         left_hbox=gtk_vbox_new(FALSE, 5);
839         gtk_box_pack_start(GTK_BOX(main_vbox), left_hbox, WID_DYN);
840         gtk_widget_show(left_hbox);
841         
842         control_box=gtk_hbox_new(FALSE, 5);
843         gtk_box_pack_start(GTK_BOX(left_hbox), control_box, WID_FIX);
844         gtk_widget_show(control_box);
845         
846 /*      dummy=gtk_hseparator_new();
847         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
848         gtk_widget_show(dummy);*/
849
850         sequencer_box=gtk_hbox_new(FALSE, 5);
851         gtk_box_pack_start(GTK_BOX(left_hbox), sequencer_box, WID_FIX);
852         gtk_widget_show(sequencer_box);
853
854         dummy=gtk_hseparator_new();
855         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
856         gtk_widget_show(dummy);
857
858         dummy=tx_xpm_label_box(TX_ICON_AUDIOENGINE, "Audio Eng.");
859         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
860         gtk_widget_show(dummy);
861         
862         dummy=tx_xpm_button_new(TX_ICON_POWER,"Power ", 1);
863         connect_button(dummy,audio_on, NULL);
864         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
865         gui_set_tooltip(dummy, "Turn the audio engine on/off.");
866         gtk_widget_show(dummy);
867         engine_btn=dummy;
868         
869         grab_button=tx_xpm_button_new(TX_ICON_GRAB, "Mouse Grab ", 1);
870         gtk_box_pack_start(GTK_BOX(control_box), grab_button, WID_FIX);
871         connect_button(grab_button, grab_on, NULL);
872         gui_set_tooltip(grab_button, "Enter the mouse grab mode operation. Press <ESCAPE> to exit grab mode.");
873         gtk_widget_show(grab_button);
874
875         dummy=gtk_check_button_new_with_label("Record");
876         rec_btn=dummy;
877         connect_button(dummy,tape_on, NULL);
878         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
879         gui_set_tooltip(dummy, "Record the audio the terminatorX' audio engine renders. You will be prompted to enter a name for the target wav-file.");
880         gtk_widget_show(dummy);
881         
882         dummy=gtk_label_new("Pitch:");
883         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
884         gtk_widget_show(dummy);
885
886         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.pitch, -3, 3, 0.001, 0.001, 0.01);
887         pitch_adj=dumadj;
888         connect_adj(dumadj, master_pitch_changed, NULL);        
889         dummy=gtk_hscale_new(dumadj);
890         gtk_scale_set_digits(GTK_SCALE(dummy), 2);
891         gtk_scale_set_value_pos(GTK_SCALE(dummy), GTK_POS_LEFT);
892         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_DYN);
893         gui_set_tooltip(dummy, "Use this scale to adjust the master pitch (affecting *all* turntables).");
894         gtk_widget_show(dummy);
895
896         dummy=tx_xpm_label_box(TX_ICON_SEQUENCER, "Sequencer");
897         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
898         gtk_widget_show(dummy);
899
900         dummy=tx_xpm_button_new(TX_ICON_PLAY,"Play ", 1);
901         connect_button(dummy, seq_play, NULL);
902         seq_play_btn=dummy;
903         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
904         gui_set_tooltip(dummy, "Playback previously recorded events from the sequencer. This will turn on the audio engine automagically.");
905         gtk_widget_show(dummy);
906
907         dummy=tx_xpm_button_new(TX_ICON_STOP,"Stop ", 0);
908         seq_stop_btn=dummy;
909         connect_button(dummy, seq_stop, NULL);  
910         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
911         gui_set_tooltip(dummy, "Stop the playback of sequencer events.");
912         gtk_widget_show(dummy);
913
914         dummy=tx_xpm_button_new(TX_ICON_RECORD,"Record ", 1);
915         connect_button(dummy, seq_rec, NULL);
916         seq_rec_btn=dummy;
917         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
918         gui_set_tooltip(dummy, "Enable recording of *events* into the sequencer. All touched controls will be recorded. Existing events for the song-time recording will be overwritten for touched controls.");
919         gtk_widget_show(dummy);
920
921         dummy=gtk_label_new("Pos:");
922         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
923         gtk_widget_show(dummy);
924         
925         dummy=gtk_entry_new_with_max_length(12);
926         seq_entry=dummy;
927         gtk_widget_set_usize(dummy, 65, 20);
928         gtk_entry_set_text(GTK_ENTRY(dummy), "00:00.00");
929         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
930         gtk_widget_show(dummy);
931
932         dumadj=(GtkAdjustment*) gtk_adjustment_new(0, 0, 100, 0.1, 1, 1);
933         seq_adj=dumadj;
934         connect_adj(dumadj, sequencer_move, NULL);      
935         dummy=gtk_hscale_new(dumadj);
936         seq_slider=dummy;
937         gtk_signal_connect(GTK_OBJECT(seq_slider), "button-release-event", (GtkSignalFunc) seq_slider_released, NULL);
938         gtk_scale_set_draw_value(GTK_SCALE(dummy), FALSE);
939         
940         gui_set_tooltip(dummy, "Select the start position for the sequencer in song-time.");
941         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_DYN);
942         gtk_widget_show(dummy);
943         
944         dummy=gtk_hbox_new(FALSE,2);
945         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_DYN);
946         gtk_widget_show(dummy);
947         
948         tt_parent=dummy;
949
950     panel_bar=gtk_hbox_new(TRUE,2);
951         gtk_box_pack_start(GTK_BOX(left_hbox), panel_bar, WID_FIX);
952
953         control_parent=gtk_hbox_new(FALSE,0);
954         gtk_box_pack_start(GTK_BOX(tt_parent), control_parent, WID_FIX);
955         gtk_widget_show(control_parent);
956
957         dummy=gtk_vseparator_new();
958         gtk_box_pack_start(GTK_BOX(tt_parent), dummy, WID_FIX);
959         gtk_widget_show(dummy);
960
961         audio_parent=gtk_vbox_new(FALSE,0);
962         gtk_box_pack_start(GTK_BOX(tt_parent), audio_parent, WID_DYN);
963         gtk_widget_show(audio_parent);
964         
965         dummy=gtk_vseparator_new();
966         gtk_box_pack_start(GTK_BOX(main_vbox), dummy, WID_FIX);
967         gtk_widget_show(dummy);
968                 
969         right_hbox=gtk_vbox_new(FALSE, 5);
970         gtk_box_pack_start(GTK_BOX(main_vbox), right_hbox, WID_FIX);
971         gtk_widget_show(right_hbox);
972         
973         dummy=gtk_button_new_with_label("Add Turntable");
974         AddTable=dummy; 
975         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
976         gui_set_tooltip(dummy, "Click this button to add a new turntable to the current set.");
977         gtk_widget_show(dummy);
978
979         gtk_drag_dest_set (GTK_WIDGET (dummy), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
980                         drop_types, n_drop_types,
981                         GDK_ACTION_COPY);
982                                                 
983         gtk_signal_connect (GTK_OBJECT (dummy), "drag_data_received",
984                         GTK_SIGNAL_FUNC(drop_new_table), NULL);
985         
986         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(new_table), NULL);       
987
988         dummy=gtk_button_new_with_label("Load Set");
989         LoadSet=dummy;
990         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
991         gtk_widget_show(dummy);
992         gui_set_tooltip(dummy, "Click to load a previously saved terminatorX-set-file. As an alternative you can drop a set file over this button.");
993         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(load_tables), NULL);     
994
995         gtk_drag_dest_set (GTK_WIDGET (dummy), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
996                         drop_types, n_drop_types,
997                         GDK_ACTION_COPY);
998                                                 
999         gtk_signal_connect (GTK_OBJECT (dummy), "drag_data_received",
1000                         GTK_SIGNAL_FUNC(drop_set), NULL);
1001         
1002         dummy=gtk_button_new_with_label("Save Set");
1003         SaveSet=dummy;
1004         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1005         gtk_widget_show(dummy);
1006         gui_set_tooltip(dummy, "Click here to save the current set.");
1007         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(save_tables), NULL);     
1008
1009         add_sep();
1010         
1011         dummy=gtk_button_new_with_label("Options");
1012         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1013         gtk_widget_show(dummy);
1014         gui_set_tooltip(dummy, "Click here to configure terminatorX.");
1015         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) display_options, NULL);
1016
1017         dummy=gtk_button_new_with_label("About/Legal");
1018         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1019         gtk_widget_show(dummy);
1020         gui_set_tooltip(dummy, "Click here to read the license and to get some information about this binary.");
1021         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) mplcfitx, NULL);      
1022
1023         dummy=gtk_button_new_with_label("Quit");
1024         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1025         gtk_widget_show(dummy);
1026         gui_set_tooltip(dummy, "Click here to exit terminatorX.");
1027         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) quit, NULL);
1028
1029         fullscreen_button=gtk_button_new_with_label("Fullscreen");
1030         gtk_box_pack_start(GTK_BOX(right_hbox), fullscreen_button, WID_FIX);
1031         
1032         add_sep();              
1033
1034         small_box=gtk_hbox_new(FALSE, 5);
1035         gtk_box_pack_start(GTK_BOX(right_hbox), small_box, WID_DYN);
1036         gtk_widget_show(small_box);
1037         
1038         smaller_box=gtk_vbox_new(FALSE, 0);
1039         gtk_box_pack_start(GTK_BOX(small_box), smaller_box, WID_FIX);
1040         gtk_widget_show(smaller_box);
1041         
1042         dummy = tx_pixmap_widget(TX_ICON_LOGO);
1043         gtk_box_pack_start(GTK_BOX(smaller_box), dummy, WID_FIX);
1044         gtk_widget_show( dummy );
1045
1046         dummy=gtk_label_new("0");
1047         used_mem=dummy;
1048         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1049         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1050         gtk_widget_show(dummy);
1051
1052         dummy=gtk_label_new("Mem/kB:");
1053         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1054         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1055         gtk_widget_show(dummy);
1056         
1057         add_sep2();
1058
1059         dummy=gtk_label_new("1");
1060         no_of_vtts=dummy;
1061         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1062         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1063         gtk_widget_show(dummy);
1064
1065         dummy=gtk_label_new("Vtts:");
1066         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1067         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1068         gtk_widget_show(dummy);
1069
1070         add_sep2();
1071
1072         dummy=gtk_label_new(VERSION);
1073         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1074         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1075         gtk_widget_show(dummy);
1076
1077         dummy=gtk_label_new("Release:");
1078         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1079         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1080         gtk_widget_show(dummy);
1081         
1082         add_sep2();
1083
1084         dummy=gtk_label_new("Status:");
1085         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1086         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1087         gtk_widget_show(dummy);
1088         
1089         dumadj=(GtkAdjustment*) gtk_adjustment_new(2.0-globals.volume, 0, 2, 0.01, 0.05, 0.005);
1090         volume_adj=dumadj;
1091
1092         connect_adj(dumadj, master_volume_changed, NULL);       
1093         dummy=gtk_vscale_new(dumadj);
1094         gtk_scale_set_draw_value(GTK_SCALE(dummy), False);
1095         gtk_box_pack_end(GTK_BOX(small_box), dummy, WID_DYN);
1096         gtk_widget_show(dummy); 
1097         gui_set_tooltip(dummy, "Adjust the master volume. This parameter will effect *all* turntables in the set.");
1098         
1099 #ifdef USE_FLASH        
1100         main_flash_r=gtk_tx_flash_new();
1101         gtk_box_pack_end(GTK_BOX(small_box), main_flash_r, WID_DYN);
1102         gtk_widget_show(main_flash_r);
1103
1104         main_flash_l=gtk_tx_flash_new();
1105         gtk_box_pack_end(GTK_BOX(small_box), main_flash_l, WID_DYN);
1106         gtk_widget_show(main_flash_l);
1107 #endif  
1108         gtk_window_set_default_size(GTK_WINDOW(main_window), x, y);     
1109         gtk_widget_set_sensitive(grab_button, 0);
1110
1111         new_table(NULL, NULL); // to give the user something to start with ;)
1112
1113         gtk_signal_connect (GTK_OBJECT(main_window), "delete-event", (GtkSignalFunc) quit, NULL);       
1114         
1115         if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
1116         else gtk_tooltips_disable(gui_tooltips);
1117 }
1118
1119 gfloat old_percent=-1;
1120
1121 void wav_progress_update(gfloat percent)
1122 {
1123         percent=floor(percent*10.0)/10.0; //Updating statusbars with gtk-themes eats up hell of a lot CPU-time
1124                                           // which is why we update every 10% only.
1125         
1126         if (wav_progress)
1127         {
1128                 if (old_percent != percent)
1129                 {
1130                         old_percent = percent;
1131                         gtk_progress_bar_update(GTK_PROGRESS_BAR(wav_progress), percent);
1132                         while (gtk_events_pending()) gtk_main_iteration();      
1133                 }
1134         }
1135
1136 }
1137
1138 void note_destroy(GtkWidget *widget, GtkWidget *mbox)
1139 {
1140         gtk_widget_destroy(GTK_WIDGET(mbox));
1141 }
1142
1143 void tx_note(const char *message, bool isError)
1144 {
1145         char buffer[4096]="terminatorX ";
1146         if (isError) {
1147                 strcat(buffer, "note:\n\n");
1148         } else {
1149                 strcat(buffer, "error:\n\n");
1150         }
1151         
1152         strcat(buffer, message);
1153         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window),
1154                 GTK_DIALOG_DESTROY_WITH_PARENT,
1155                 isError ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
1156         gtk_dialog_run(GTK_DIALOG(dialog));
1157         gtk_widget_destroy(dialog);     
1158 }
1159
1160
1161 void tx_l_note(const char *message)
1162 {
1163         char buffer[4096]="Plugin info:\n\n";
1164         strcat(buffer, message);
1165         
1166         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window),
1167                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
1168         gtk_dialog_run(GTK_DIALOG(dialog));
1169         gtk_widget_destroy(dialog);     
1170 }
1171
1172
1173 void add_to_panel_bar(GtkWidget *button) {
1174         buttons_on_panel_bar++;
1175         gtk_box_pack_start(GTK_BOX(panel_bar), button, WID_DYN);
1176         gtk_widget_show(panel_bar);
1177 }
1178
1179 void remove_from_panel_bar(GtkWidget *button) {
1180         buttons_on_panel_bar--;
1181         gtk_container_remove(GTK_CONTAINER(panel_bar), button);
1182         if (buttons_on_panel_bar==0) gtk_widget_hide(panel_bar);
1183 }
1184
1185 /* Fullscreen code... */
1186 #define _WIN_LAYER_TOP          -1
1187 #define _WIN_LAYER_NORMAL       4
1188 #define _NET_WM_STATE_REMOVE    0
1189 #define _NET_WM_STATE_ADD       1
1190 #define _NET_WM_STATE_TOGGLE    2
1191
1192 void fullscreen_toggle() {
1193         XEvent xev;
1194         Window win=GDK_WINDOW_XID(main_window->window);
1195         Display *disp=GDK_WINDOW_XDISPLAY(main_window->window);
1196         
1197         tX_fullscreen_status=!tX_fullscreen_status;
1198         
1199         /* Top layer.. */
1200         xev.xclient.type = ClientMessage;
1201         xev.xclient.serial = 0;
1202         xev.xclient.send_event = True;
1203         xev.xclient.display = disp;
1204         xev.xclient.window = win;
1205         xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_WIN_LAYER");
1206         xev.xclient.format = 32;
1207         xev.xclient.data.l[0] = tX_fullscreen_status ? _WIN_LAYER_TOP : _WIN_LAYER_NORMAL ;
1208         XSendEvent(disp, GDK_WINDOW_XID (gdk_get_default_root_window ()),
1209                 False, SubstructureRedirectMask | SubstructureNotifyMask,
1210                 &xev);
1211         
1212         /* Fullscreen */
1213         xev.xclient.type = ClientMessage;
1214         xev.xclient.serial = 0;
1215         xev.xclient.send_event = True;
1216         xev.xclient.display = disp;
1217         xev.xclient.window = win;
1218         xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1219         xev.xclient.format = 32;
1220         xev.xclient.data.l[0] = tX_fullscreen_status ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1221         xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", TRUE));
1222         xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (GDK_NONE);
1223         XSendEvent(gdk_display, GDK_WINDOW_XID (gdk_get_default_root_window ()),
1224                 False, SubstructureRedirectMask | SubstructureNotifyMask,
1225                 &xev);  
1226 }
1227
1228 #include <gdk/gdkkeysyms.h>
1229
1230 void fullscreen_setup() {
1231         GtkAccelGroup* accel_group=gtk_accel_group_new();
1232         gtk_widget_add_accelerator (fullscreen_button, "activate", accel_group, GDK_F11, (GdkModifierType) 0, (GtkAccelFlags) 0);
1233         g_signal_connect(fullscreen_button, "activate", (GCallback) fullscreen_toggle, NULL);
1234         gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group);
1235 }
1236
1237 void display_mastergui()
1238 {
1239         GtkWidget *top;
1240         gtk_widget_realize(main_window);
1241         tX_set_icon(main_window, "terminatorX");
1242         load_knob_pixs(main_window);
1243         fullscreen_setup();
1244         gtk_widget_show(main_window);
1245         top=gtk_widget_get_toplevel(main_window);
1246         xwindow=GDK_WINDOW_XWINDOW(top->window);
1247 }