version bump
[blackbox.git] / src / main.cc
blob2c48e0d16455da5ad173ea8bdb9d905eae1583bc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // main.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
25 // #define PRINT_SIZES
27 #if defined(PRINT_SIZES)
28 # include "Screen.hh"
29 # include "Slit.hh"
30 # include "Toolbar.hh"
31 # include "Window.hh"
32 #endif
34 #include "blackbox.hh"
35 #include "../version.h"
37 #include <stdio.h>
40 static void showHelp(int exitval) {
41 // print version - this should not be localized!
42 printf("Blackbox %s\n"
43 "Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry\n"
44 "Copyright (c) 1997 - 2000, 2002 - 2005 Bradley T Hughes\n",
45 __blackbox_version);
47 // print program usage and command line options
48 printf(" -display <string>\t\tuse display connection.\n"
49 " -single <string>\t\tmanage the default screen only\n"
50 " -rc <string>\t\t\tuse alternate resource file.\n"
51 " -version\t\t\tdisplay version and exit.\n"
52 " -help\t\t\t\tdisplay this help text and exit.\n\n");
54 // some people have requested that we print out compile options
55 // as well
56 printf("Compile time options:\n"
57 " Debugging:\t\t\t%s\n"
58 " Shape:\t\t\t%s\n\n",
59 #ifdef DEBUG
60 "yes",
61 #else // !DEBUG
62 "no",
63 #endif // DEBUG
65 #ifdef SHAPE
66 "yes"
67 #else // !SHAPE
68 "no"
69 #endif // SHAPE
72 ::exit(exitval);
75 int main(int argc, char **argv) {
76 const char *dpy_name = 0;
77 std::string rc_file;
78 bool multi_head = true;
80 for (int i = 1; i < argc; ++i) {
81 if (! strcmp(argv[i], "-help")) {
82 showHelp(0);
83 } else if (! strcmp(argv[i], "-version")) {
84 // print current version string, this should not be localized!
85 printf("Blackbox %s\n"
86 "Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry\n"
87 "Copyright (c) 1997 - 2000, 2002 - 2005 Bradley T Hughes\n",
88 __blackbox_version);
90 ::exit(0);
91 } else if (! strcmp(argv[i], "-rc")) {
92 // look for alternative rc file to use
94 if ((++i) >= argc) {
95 fprintf(stderr, "error: '-rc' requires and argument\n");
96 ::exit(1);
99 rc_file = argv[i];
100 } else if (! strcmp(argv[i], "-display")) {
101 // check for -display option... to run on a display other than the one
102 // set by the environment variable DISPLAY
104 if ((++i) >= argc) {
105 fprintf(stderr, "error: '-display' requires an argument\n");
106 ::exit(1);
109 dpy_name = argv[i];
110 std::string dtmp = "DISPLAY=";
111 dtmp += dpy_name;
113 if (putenv(const_cast<char*>(dtmp.c_str()))) {
114 fprintf(stderr,
115 "warning: couldn't set environment variable 'DISPLAY'\n");
116 perror("putenv()");
118 } else if (! strcmp(argv[i], "-single")) {
119 multi_head = false;
120 } else { // invalid command line option
121 showHelp(-1);
125 #ifdef __EMX__
126 _chdir2(getenv("X11ROOT"));
127 #endif // __EMX__
129 if (rc_file.empty())
130 rc_file = "~/.blackboxrc";
131 rc_file = bt::expandTilde(rc_file);
133 #if defined(PRINT_SIZES)
134 printf("Blackbox : %4d bytes\n"
135 "BScreen : %4d bytes\n"
136 "BlackboxWindow: %4d bytes\n"
137 "Toolbar : %4d bytes\n"
138 "Slit : %4d bytes\n",
139 sizeof(Blackbox),
140 sizeof(BScreen),
141 sizeof(BlackboxWindow),
142 sizeof(Toolbar),
143 sizeof(Slit));
144 #endif
146 Blackbox blackbox(argv, dpy_name, rc_file, multi_head);
147 blackbox.run();
148 return 0;