00001
00002
00003
00004
00005
00006 #include "../config.h"
00007 #include "../version.h"
00008
00009 extern "C" {
00010 #include <assert.h>
00011 #include <unistd.h>
00012 #include <stdlib.h>
00013 #include <X11/Xlib.h>
00014 }
00015
00016 #include <iostream>
00017 #include <string>
00018 #include <sstream>
00019 #include <map>
00020
00021 #include "ncwm.h"
00022
00023 #include "loader.h"
00024 #include "util.h"
00025 #include "kernel.h"
00026
00027
00028 static void version() {
00029 cout << "ncwm - no cheese window manager - " << __NCWM_VERSION
00030 << endl << " (C)opyright 2003 - 2004 by Anselm R. Garbe"
00031 << endl;
00032 }
00033
00034 static void usage() {
00035 cout << "usage: " << endl << endl
00036 << " ncwm [-d <display>] [-h] [-v]" << endl
00037 << endl
00038 << " -d display specifies the display to use" << endl
00039 << " -h prints out this help" << endl
00040 << " -v prints out above version info" << endl;
00041 }
00042
00043 Display *openDisplay(const char *displayName) {
00044
00045 Display *display = XOpenDisplay(displayName);
00046 if (!display) {
00047 if (displayName != 0) {
00048 cerr << "ncwm[E " << Util::timestamp()
00049 << "]: cannot open display \'"
00050 << displayName << "\', giving up" << endl;
00051 }
00052 else {
00053 cerr << "ncwm[E " << Util::timestamp()
00054 << "]: cannot open default display"
00055 << ", giving up" << endl;
00056 }
00057 exit(1);
00058 }
00059
00060 return display;
00061 }
00062
00063 static bool loadSettings(MSettings *settings, string filename,
00064 const char *home, bool suppressWarning = false,
00065 bool caseSensitive = false)
00066 {
00067
00068 Loader::load(settings, (string)CONFPATH + "/" + filename, true);
00069
00070
00071 string localConf = (string)home + "/.ncwm/" + filename;
00072 bool result = Loader::load(settings, localConf,
00073 suppressWarning, caseSensitive);
00074 if (!suppressWarning && !result) {
00075 cerr << "ncwm[W " << Util::timestamp()
00076 << "]: cannot load settings from '"
00077 << localConf << "', using defaults" << endl;
00078 }
00079 return result;
00080 }
00081
00082 static MSettings *initThemeSettings() {
00083
00084 MSettings *themeSettings = new MSettings();
00085
00086
00087
00088 (*themeSettings)["color.bar.background"] = "#F6F6F6";
00089 (*themeSettings)["color.bar.text"] = "black";
00090 (*themeSettings)["color.bar.shine"] = "#999999";
00091 (*themeSettings)["color.bar.shadow"] = "#999999";
00092 (*themeSettings)["color.meter.background"] = "#F6F6F6";
00093 (*themeSettings)["color.meter.figure.high"] = "red";
00094 (*themeSettings)["color.meter.figure.normal"] = "#253446";
00095 (*themeSettings)["color.meter.figure.low"] = "green";
00096 (*themeSettings)["color.meter.border.shine"] = "#7AA4D9";
00097 (*themeSettings)["color.meter.border.shadow"] = "#7AA4D9";
00098 (*themeSettings)["color.focusreq.background"] = "#FF4000";
00099 (*themeSettings)["color.focusreq.text"] = "black";
00100 (*themeSettings)["color.focusreq.shine"] = "#FFD900";
00101 (*themeSettings)["color.focusreq.shadow"] = "#FFD900";
00102 (*themeSettings)["color.tiled.shine.focussed"] = "#FFD900";
00103 (*themeSettings)["color.tiled.shadow.focussed"] = "#FFD900";
00104 (*themeSettings)["color.tiled.shine.normal"] = "black";
00105 (*themeSettings)["color.tiled.shadow.normal"] = "black";
00106 (*themeSettings)["color.button.background.normal"] = "#3A5D8A";
00107 (*themeSettings)["color.button.background.pressed"] = "#253446";
00108 (*themeSettings)["color.button.border.shine.normal"] = "#7AA4D9";
00109 (*themeSettings)["color.button.border.shine.pressed"] = "#7AA4D9";
00110 (*themeSettings)["color.button.border.shadow.normal"] = "#7AA4D9";
00111 (*themeSettings)["color.button.border.shadow.pressed"] = "#7AA4D9";
00112 (*themeSettings)["color.button.figure.shine.normal"] = "white";
00113 (*themeSettings)["color.button.figure.shine.pressed"] = "#BDBDBD";
00114 (*themeSettings)["color.button.figure.shadow.normal"] = "white";
00115 (*themeSettings)["color.button.figure.shadow.pressed"] = "#BDBDBD";
00116 (*themeSettings)["color.frame.background.normal"] = "#F6F6F6";
00117 (*themeSettings)["color.frame.background.focussed"] = "#3E71AA";
00118 (*themeSettings)["color.frame.pseudo"] = "#D9D9D9";
00119 (*themeSettings)["color.frame.shine.normal"] = "black";
00120 (*themeSettings)["color.frame.shine.focussed"] = "#26476A";
00121 (*themeSettings)["color.frame.shadow.normal"] = "black";
00122 (*themeSettings)["color.frame.shadow.focussed"] = "#26476A";
00123 (*themeSettings)["color.label.background.normal"] = "#F6F6F6";
00124 (*themeSettings)["color.label.background.focussed"] = "#D9D9D9";
00125 (*themeSettings)["color.label.text.normal"] = "black";
00126 (*themeSettings)["color.label.text.focussed"] = "black";
00127 (*themeSettings)["color.label.shine.normal"] = "#999999";
00128 (*themeSettings)["color.label.shine.focussed"] = "#848484";
00129 (*themeSettings)["color.label.shadow.normal"] = "#999999";
00130 (*themeSettings)["color.label.shadow.focussed"] = "#848484";
00131 (*themeSettings)["color.tab.background.active.normal"] = "#F6F6F6";
00132 (*themeSettings)["color.tab.background.inactive.normal"] = "#D9D9D9";
00133 (*themeSettings)["color.tab.background.active.focussed"] = "#3E71AA";
00134 (*themeSettings)["color.tab.background.inactive.focussed"] = "#F6F6F6";
00135 (*themeSettings)["color.tab.text.active.normal"] = "#ADADAD";
00136 (*themeSettings)["color.tab.text.inactive.normal"] = "#ADADAD";
00137 (*themeSettings)["color.tab.text.active.focussed"] = "white";
00138 (*themeSettings)["color.tab.text.inactive.focussed"] = "#ADADAD";
00139 (*themeSettings)["color.tab.shine.active.normal"] = "#F6F6F6";
00140 (*themeSettings)["color.tab.shine.inactive.normal"] = "#F6F6F6";
00141 (*themeSettings)["color.tab.shine.active.focussed"] = "#3E71AA";
00142 (*themeSettings)["color.tab.shine.inactive.focussed"] = "#F6F6F6";
00143 (*themeSettings)["color.tab.shadow.active.normal"] = "#F6F6F6";
00144 (*themeSettings)["color.tab.shadow.inactive.normal"] = "#F6F6F6";
00145 (*themeSettings)["color.tab.shadow.active.focussed"] = "#3E71AA";
00146 (*themeSettings)["color.tab.shadow.inactive.focussed"] = "#F6F6F6";
00147 (*themeSettings)["font"] = "fixed";
00148 (*themeSettings)["exec"] = "xsetroot -solid #7B96AC";
00149
00150 return themeSettings;
00151 }
00152
00153 static MSettings *initCommonSettings() {
00154
00155 MSettings *commonSettings = new MSettings();
00156
00157
00158 (*commonSettings)["resize-move.factor"] = "10";
00159 (*commonSettings)["terminal"] = "xterm -e";
00160 (*commonSettings)["statusbar.alignment"] = "bottom";
00161 #ifdef SLOT_SUPPORT
00162 (*commonSettings)["slot.alignment"] = "right";
00163 (*commonSettings)["slot.style"] = "transparent";
00164 (*commonSettings)["slot.tabs"] = "default";
00165 (*commonSettings)["slot.mode"] = "non-overlap";
00166 #endif
00167 (*commonSettings)["bar.buttons"] = "yes";
00168 (*commonSettings)["frame.buttons"] = "yes";
00169 (*commonSettings)["frame.colwidth"] = "60";
00170 (*commonSettings)["frame.autodestroy"] = "yes";
00171 (*commonSettings)["frame.mode"] = "tabbed";
00172 (*commonSettings)["border.width"] = "3";
00173 (*commonSettings)["default.client-mode"] = "float";
00174 (*commonSettings)["default.transient-mode"] = "float";
00175 (*commonSettings)["default.bar-mode"] = "show";
00176 (*commonSettings)["default.border-mode"] = "show";
00177 (*commonSettings)["startup.chain"] = "";
00178 (*commonSettings)["menu.actions"] = "xterm,restart,quit";
00179 (*commonSettings)["autocompletion.mode"] = "default";
00180 (*commonSettings)["cycle.mode"] = "default";
00181
00182 return commonSettings;
00183 }
00184
00185
00186 static MSettings *initActionSettings() {
00187
00188 MSettings *actionSettings = new MSettings();
00189
00190
00191 (*actionSettings)["intern.quit.keys"] = "ctrl+alt+q";
00192 (*actionSettings)["intern.grow-left.keys"] = "alt+r::h";
00193 (*actionSettings)["intern.grow-right.keys"] = "alt+r::l";
00194 (*actionSettings)["intern.grow-up.keys"] = "alt+r::k";
00195 (*actionSettings)["intern.grow-down.keys"] = "alt+r::j";
00196 (*actionSettings)["intern.shrink-left.keys"] = "shift+alt+r::h";
00197 (*actionSettings)["intern.shrink-right.keys"] = "shift+alt+r::l";
00198 (*actionSettings)["intern.shrink-up.keys"] = "shift+alt+r::k";
00199 (*actionSettings)["intern.shrink-down.keys"] = "shift+alt+r::j";
00200 (*actionSettings)["intern.move-client-left.keys"] = "shift+alt+h";
00201 (*actionSettings)["intern.move-client-right.keys"] = "shift+alt+l";
00202 (*actionSettings)["intern.move-client-up.keys"] = "shift+alt+k";
00203 (*actionSettings)["intern.move-client-down.keys"] = "shift+alt+j";
00204 (*actionSettings)["intern.select-frame-left.keys"] = "alt+h";
00205 (*actionSettings)["intern.select-frame-right.keys"] = "alt+l";
00206 (*actionSettings)["intern.select-frame-up.keys"] = "alt+k";
00207 (*actionSettings)["intern.select-frame-down.keys"] = "alt+j";
00208 (*actionSettings)["intern.kill-client.keys"] = "ctrl+alt+c";
00209 (*actionSettings)["intern.cycle-client-next.keys"] = "alt+Tab";
00210 (*actionSettings)["intern.cycle-client-prev.keys"] = "shift+alt+Tab";
00211 (*actionSettings)["intern.cycle-workspace-next.keys"] = "ctrl+alt+Right";
00212 (*actionSettings)["intern.cycle-workspace-prev.keys"] = "ctrl+alt+Left";
00213 (*actionSettings)["intern.split-frame-left.keys"] = "alt+s::h";
00214 (*actionSettings)["intern.split-frame-right.keys"] = "alt+s::l";
00215 (*actionSettings)["intern.split-frame-up.keys"] = "alt+s::k";
00216 (*actionSettings)["intern.split-frame-down.keys"] = "alt+s::j";
00217 (*actionSettings)["intern.join-frame-left.keys"] = "shift+alt+s::h";
00218 (*actionSettings)["intern.join-frame-right.keys"] = "shift+alt+s::l";
00219 (*actionSettings)["intern.join-frame-up.keys"] = "shift+alt+s::k";
00220 (*actionSettings)["intern.join-frame-down.keys"] = "shift+alt+s::j";
00221 (*actionSettings)["intern.detach-client.keys"] = "alt+d";
00222 (*actionSettings)["intern.attach-last-client.keys"] = "alt+a";
00223 (*actionSettings)["intern.toggle-client-mode.keys"] = "alt+m";
00224 (*actionSettings)["intern.toggle-mode.keys"] = "alt+f";
00225 (*actionSettings)["intern.inputmode.keys"] = "alt+i";
00226 (*actionSettings)["intern.exec.keys"] = "alt+e";
00227 (*actionSettings)["intern.grab-move.keys"] = "mod1+Button1";
00228 (*actionSettings)["intern.zoom-client.keys"] = "mod1+z";
00229
00230
00231 (*actionSettings)["extern.xterm.cmd"] = "xterm";
00232 (*actionSettings)["extern.xterm.keys"] = "alt+x";
00233
00234
00235 (*actionSettings)["chain.grow-full.seq"] =
00236 "grow-left,grow-right,grow-up,grow-down";
00237 (*actionSettings)["chain.grow-full.keys"] = "alt+r::f";
00238 (*actionSettings)["chain.shrink-full.seq"] =
00239 "shrink-left,shrink-right,shrink-up,shrink-down";
00240 (*actionSettings)["chain.shrink-full.keys"] = "shift+alt+r::f";
00241
00242 return actionSettings;
00243 }
00244
00245 static MSettings *initSessionSettings(Display *display)
00246 {
00247 MSettings *sessionSettings = new MSettings();
00248
00249 unsigned int monitorCount = ScreenCount(display);
00250
00251 ostringstream prefix;
00252
00253 for (unsigned int i = 0; i < monitorCount; i++) {
00254 prefix.str("");
00255 prefix << "monitor[" << i << "]";
00256
00257 (*sessionSettings)[prefix.str() + ".workspaces"] = "2";
00258 (*sessionSettings)[prefix.str() + ".focused"] = "0";
00259 (*sessionSettings)[prefix.str() + ".workspace[0].name"] = "workspace 1";
00260 (*sessionSettings)[prefix.str() + ".workspace[0].clientbar"] = "yes";
00261 (*sessionSettings)[prefix.str() + ".workspace[0].statusbar"] = "yes";
00262 (*sessionSettings)[prefix.str() + ".workspace[1].name"] = "workspace 2";
00263 (*sessionSettings)[prefix.str() + ".workspace[1].clientbar"] = "yes";
00264 (*sessionSettings)[prefix.str() + ".workspace[1].statusbar"] = "yes";
00265 #ifdef SLOT_SUPPORT
00266 (*sessionSettings)[prefix.str() + ".workspace[0].slot"] = "default";
00267 (*sessionSettings)[prefix.str() + ".workspace[1].slot"] = "default";
00268 #endif
00269 }
00270
00271 return sessionSettings;
00272 }
00273
00275
00276 int main(int argc, char *argv[])
00277 {
00278 string *displayName = 0;
00279 int c;
00280 unsigned int size;
00281
00282
00283 while ((c = getopt(argc, argv, "vhd:")) != -1) {
00284 switch (c) {
00285 case 'd':
00286 size = strlen(optarg);
00287 displayName = new string(optarg);
00288 break;
00289 case 'v':
00290 version();
00291 exit(0);
00292 break;
00293 case '?':
00294 case 'h':
00295 usage();
00296 exit(1);
00297 break;
00298 }
00299 }
00300
00301 const char *home = getenv("HOME");
00302 if (!home) {
00303 cerr << "ncwm[E " << Util::timestamp()
00304 << "]: cannot determine your $HOME directory,"
00305 << " giving up" << endl;
00306 exit(1);
00307 }
00308
00309 Display *display = openDisplay((displayName != 0) ?
00310 displayName->c_str() : 0);
00311
00312
00313 MSettings *themeSettings = initThemeSettings();
00314 bool existsThemeConf = loadSettings(themeSettings, "theme.conf", home);
00315 MSettings *commonSettings = initCommonSettings();
00316 bool existsCommonConf = loadSettings(commonSettings, "common.conf", home);
00317 MSettings *actionSettings = initActionSettings();
00318 loadSettings(actionSettings, "actions.session", home);
00319 loadSettings(actionSettings, "actions.conf", home, true);
00320 MSettings *sessionSettings = initSessionSettings(display);
00321 loadSettings(sessionSettings, "ncwm.session", home, false, true);
00322 loadSettings(sessionSettings, "session.conf", home, true, true);
00323
00324
00325 int result = Kernel::instance()->start(argv, display,
00326 themeSettings, commonSettings, actionSettings,
00327 sessionSettings, !existsCommonConf);
00328
00329
00330 if (result == 0) {
00331 if (!existsThemeConf) {
00332 Loader::saveSettings(themeSettings, (string)home +
00333 "/.ncwm/theme.conf");
00334 }
00335 if (!existsCommonConf) {
00336 Loader::saveSettings(commonSettings, (string)home +
00337 "/.ncwm/common.conf");
00338 }
00339 Kernel::instance()->saveSettings();
00340 }
00341
00342 return result;
00343 }