a tiny webserver used to display the current itunes song
1/*
2 * eyetunesgui
3 * Copyright (c) 2011, 2013 joshua stein <jcs@jcs.org>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <Cocoa/Cocoa.h>
31
32#include "WKWindow.h"
33
34#define EYETUNES_URL "http://127.0.0.1:2000/"
35
36__dead void usage(void);
37
38int main(int argc, char* argv[])
39{
40 int ch;
41 int height = 0, width = 0, x = 0, y = 0;
42
43 while ((ch = getopt(argc, argv, "h:w:x:y:")) != -1)
44 switch (ch) {
45 case 'h':
46 height = (int)strtol(optarg, (char **)NULL, 10);
47 break;
48 case 'w':
49 width = (int)strtol(optarg, (char **)NULL, 10);
50 break;
51 case 'x':
52 x = (int)strtol(optarg, (char **)NULL, 10);
53 break;
54 case 'y':
55 y = (int)strtol(optarg, (char **)NULL, 10);
56 break;
57 default:
58 usage();
59 }
60
61 argc -= optind;
62 argv += optind;
63
64 if (height <= 0 || width <= 0 || x < 0 || y < 0)
65 usage();
66
67 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
68 [NSApplication sharedApplication];
69
70 WKWindow *WKW = [WKWindow alloc];
71 [WKW initWithX:x y:y width:width height:height];
72 [WKW loadURL:[NSString stringWithFormat:@"%s", EYETUNES_URL]];
73
74 /* give us a simple icon so we can quit */
75 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
76
77 [NSApp run];
78
79 [pool release];
80 return (0);
81}
82
83__dead void
84usage(void)
85{
86 extern char *__progname;
87
88 fprintf(stderr, "usage: %s -x x -y y -w width -h height\n", __progname);
89 exit(1);
90}