1 // ------------------------------------------------------------------------
2 //
3 //  Copyright (C) 2010-2011 Fons Adriaensen <fons@linuxaudio.org>
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 // ------------------------------------------------------------------------
20 
21 
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <clthreads.h>
25 #include <sys/mman.h>
26 #include <signal.h>
27 #include "styles.h"
28 #include "jclient.h"
29 #include "mainwin.h"
30 
31 
32 #define NOPTS 3
33 #define CP (char *)
34 
35 
36 XrmOptionDescRec options [NOPTS] =
37 {
38     {CP"-h",   CP".help",     XrmoptionNoArg,   CP"true" },
39     {CP"-s",   CP".server",   XrmoptionSepArg,  0        },
40     {CP"-g",   CP".geometry", XrmoptionSepArg,  0        }
41 };
42 
43 
44 static Jclient  *jclient = 0;
45 static Mainwin  *mainwin = 0;
46 
47 
help(void)48 static void help (void)
49 {
50     fprintf (stderr, "\n%s-%s\n\n", PROGNAME, VERSION);
51     fprintf (stderr, "  (C) 2010-2011 Fons Adriaensen  <fons@linuxaudio.org>\n\n");
52     fprintf (stderr, "Options:\n");
53     fprintf (stderr, "  -h               Display this text\n");
54     fprintf (stderr, "  -name <name>     Jack client name\n");
55     fprintf (stderr, "  -s <server>      Jack server name\n");
56     fprintf (stderr, "  -g <geometery>   Window position\n");
57     exit (1);
58 }
59 
60 
sigint_handler(int)61 static void sigint_handler (int)
62 {
63     signal (SIGINT, SIG_IGN);
64     mainwin->stop ();
65 }
66 
67 
main(int ac,char * av[])68 int main (int ac, char *av [])
69 {
70     X_resman       xresman;
71     X_display     *display;
72     X_handler     *handler;
73     X_rootwin     *rootwin;
74     int            ev, xp, yp, xs, ys;
75 
76     xresman.init (&ac, av, CP PROGNAME, options, NOPTS);
77     if (xresman.getb (".help", 0)) help ();
78 
79     display = new X_display (xresman.get (".display", 0));
80     if (display->dpy () == 0)
81     {
82 	fprintf (stderr, "Can't open display.\n");
83         delete display;
84 	return 1;
85     }
86 
87     xp = yp = 100;
88     xs = Mainwin::XSIZE + 2;
89     ys = Mainwin::YSIZE + 22;
90     xresman.geometry (".geometry", display->xsize (), display->ysize (), 1, xp, yp, xs, ys);
91     if (styles_init (display, &xresman, SHARED))
92     {
93 	delete display;
94 	return 1;
95     }
96 
97     jclient = new Jclient (xresman.rname (), xresman.get (".server", 0));
98     rootwin = new X_rootwin (display);
99     mainwin = new Mainwin (rootwin, &xresman, xp, yp, jclient);
100     rootwin->handle_event ();
101     handler = new X_handler (display, mainwin, EV_X11);
102     handler->next_event ();
103     XFlush (display->dpy ());
104 
105     ITC_ctrl::connect (jclient, EV_EXIT, mainwin, EV_EXIT);
106 
107     if (mlockall (MCL_CURRENT | MCL_FUTURE)) fprintf (stderr, "Warning: memory lock failed.\n");
108     signal (SIGINT, sigint_handler);
109 
110     do
111     {
112 	ev = mainwin->process ();
113 	if (ev == EV_X11)
114 	{
115 	    rootwin->handle_event ();
116 	    handler->next_event ();
117 	}
118     }
119     while (ev != EV_EXIT);
120 
121     mainwin->x_unmap ();
122     styles_fini (display);
123     delete jclient;
124     delete handler;
125     delete rootwin;
126     delete display;
127 
128     return 0;
129 }
130 
131 
132 
133