summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Screen.cc115
-rw-r--r--src/main.cc20
-rw-r--r--src/openbox.cc95
-rw-r--r--src/openbox.h10
4 files changed, 131 insertions, 109 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index bc1b9e65..7338f118 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -2265,59 +2265,72 @@ void BScreen::InitMenu(void) {
} else {
rootmenu = new Rootmenu(*this);
}
- Bool defaultMenu = True;
+ bool defaultMenu = true;
- if (openbox.getMenuFilename()) {
- FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
+ FILE *menu_file;
+ const char *menu_filename = openbox.getMenuFilename();
- if (!menu_file) {
- perror(openbox.getMenuFilename());
+ if (!(menu_file = fopen(menu_filename, "r"))) {
+ perror(menu_filename);
+ menu_filename = (char *) 0;
+ }
+ if (menu_filename == (char *) 0) {
+ // opening the menu file failed, try the DEFAULTMENU
+ menu_filename = DEFAULTMENU;
+ if (!(menu_file = fopen(menu_filename, "r"))) {
+ perror(menu_filename);
+ menu_filename = (char *) 0;
+ }
+ }
+
+ if (menu_filename) {
+ if (feof(menu_file)) {
+ fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
+ "%s: Empty menu file"), menu_filename);
+ menu_filename = (char *) 0;
} else {
- if (feof(menu_file)) {
- fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
- "%s: Empty menu file"),
- openbox.getMenuFilename());
- } else {
- char line[1024], label[1024];
- memset(line, 0, 1024);
- memset(label, 0, 1024);
-
- while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
- if (line[0] != '#') {
- int i, key = 0, index = -1, len = strlen(line);
-
- key = 0;
- for (i = 0; i < len; i++) {
- if (line[i] == '[') index = 0;
- else if (line[i] == ']') break;
- else if (line[i] != ' ')
- if (index++ >= 0)
- key += tolower(line[i]);
- }
+ // successsfully opened a menu file
+ char line[1024], label[1024];
+ memset(line, 0, 1024);
+ memset(label, 0, 1024);
+
+ while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
+ if (line[0] != '#') {
+ int i, key = 0, index = -1, len = strlen(line);
+
+ key = 0;
+ for (i = 0; i < len; i++) {
+ if (line[i] == '[') index = 0;
+ else if (line[i] == ']') break;
+ else if (line[i] != ' ')
+ if (index++ >= 0)
+ key += tolower(line[i]);
+ }
- if (key == 517) {
- index = -1;
- for (i = index; i < len; i++) {
- if (line[i] == '(') index = 0;
- else if (line[i] == ')') break;
- else if (index++ >= 0) {
- if (line[i] == '\\' && i < len - 1) i++;
- label[index - 1] = line[i];
- }
- }
+ if (key == 517) {
+ index = -1;
+ for (i = index; i < len; i++) {
+ if (line[i] == '(') index = 0;
+ else if (line[i] == ')') break;
+ else if (index++ >= 0) {
+ if (line[i] == '\\' && i < len - 1) i++;
+ label[index - 1] = line[i];
+ }
+ }
- if (index == -1) index = 0;
- label[index] = '\0';
+ if (index == -1) index = 0;
+ label[index] = '\0';
- rootmenu->setLabel(label);
- defaultMenu = parseMenuFile(menu_file, rootmenu);
- break;
- }
- }
- }
+ rootmenu->setLabel(label);
+ defaultMenu = parseMenuFile(menu_file, rootmenu);
+ if (!defaultMenu)
+ openbox.addMenuTimestamp(menu_filename);
+ break;
+ }
+ }
}
- fclose(menu_file);
}
+ fclose(menu_file);
}
if (defaultMenu) {
@@ -2329,8 +2342,6 @@ void BScreen::InitMenu(void) {
BScreen::Restart);
rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
BScreen::Exit);
- } else {
- openbox.setMenuFilename(openbox.getMenuFilename());
}
}
@@ -2530,10 +2541,9 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
}
if (! feof(submenufile)) {
- if (! parseMenuFile(submenufile, menu))
- openbox.setMenuFilename(newfile);
-
- fclose(submenufile);
+ if (!parseMenuFile(submenufile, menu))
+ openbox.addMenuTimestamp(newfile);
+ fclose(submenufile);
}
} else
perror(newfile);
@@ -2689,8 +2699,7 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
menu->insert(label, stylesmenu);
rootmenuList.push_back(stylesmenu);
}
-
- openbox.setMenuFilename(stylesdir);
+ openbox.addMenuTimestamp(stylesdir);
} else {
fprintf(stderr, i18n->getMessage(ScreenSet,
ScreenSTYLESDIRErrorNotDir,
diff --git a/src/main.cc b/src/main.cc
index 0b2360ab..84e0d90e 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -68,6 +68,7 @@ static void showHelp(int exitval) {
"\t\t\t 1997 - 2000 Brad Hughes\n\n"
" -display <string>\t\tuse display connection.\n"
" -rc <string>\t\t\tuse alternate resource file.\n"
+ " -menu <string>\t\t\tuse alternate menu file.\n"
" -version\t\t\tdisplay version and exit.\n"
" -help\t\t\t\tdisplay this help text and exit.\n\n"),
__openbox_version);
@@ -125,6 +126,7 @@ static void showHelp(int exitval) {
int main(int argc, char **argv) {
char *session_display = (char *) 0;
char *rc_file = (char *) 0;
+ char *menu_file = (char *) 0;
NLSInit("openbox.cat");
@@ -134,13 +136,25 @@ int main(int argc, char **argv) {
if ((++i) >= argc) {
fprintf(stderr,
- i18n->getMessage(mainSet, mainRCRequiresArg,
- "error: '-rc' requires and argument\n"));
+ i18n->getMessage(mainSet, mainRCRequiresArg,
+ "error: '-rc' requires and argument\n"));
::exit(1);
}
rc_file = argv[i];
+ } else if (! strcmp(argv[i], "-menu")) {
+ // look for alternative menu file to use
+
+ if ((++i) >= argc) {
+ fprintf(stderr,
+ i18n->getMessage(mainSet, mainMENURequiresArg,
+ "error: '-menu' requires and argument\n"));
+
+ ::exit(1);
+ }
+
+ menu_file = argv[i];
} else if (! strcmp(argv[i], "-display")) {
// check for -display option... to run on a display other than the one
// set by the environment variable DISPLAY
@@ -182,7 +196,7 @@ int main(int argc, char **argv) {
_chdir2(getenv("X11ROOT"));
#endif // __EMX__
- Openbox openbox(argc, argv, session_display, rc_file);
+ Openbox openbox(argc, argv, session_display, rc_file, menu_file);
openbox.eventLoop();
return(0);
diff --git a/src/openbox.cc b/src/openbox.cc
index 3a7fb6b9..4b5495bb 100644
--- a/src/openbox.cc
+++ b/src/openbox.cc
@@ -151,8 +151,8 @@ static Bool queueScanner(Display *, XEvent *e, char *args) {
Openbox *openbox;
-Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
- : BaseDisplay(m_argv[0], dpy_name) {
+Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc,
+ char *menu) : BaseDisplay(m_argv[0], dpy_name) {
grab();
if (! XSupportsLocale())
@@ -164,25 +164,35 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc)
::openbox = this;
argc = m_argc;
argv = m_argv;
- if (rc == NULL) {
+ if (rc == NULL || menu == NULL) {
char *homedir = getenv("HOME");
-
- rc_file = new char[strlen(homedir) + strlen("/.openbox/rc") + 1];
- sprintf(rc_file, "%s/.openbox", homedir);
-
+ char *configdir = new char[strlen(homedir) + strlen("/.openbox") + 1];
+ sprintf(configdir, "%s/.openbox", homedir);
// try to make sure the ~/.openbox directory exists
- mkdir(rc_file, S_IREAD | S_IWRITE | S_IEXEC | S_IRGRP | S_IWGRP | S_IXGRP |
+ mkdir(configdir, S_IREAD | S_IWRITE | S_IEXEC |
+ S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH);
- sprintf(rc_file, "%s/.openbox/rc", homedir);
- } else {
- rc_file = bstrdup(rc);
+
+ if (rc == NULL) {
+ rc_file = new char[strlen(configdir) + strlen("/rc") + 1];
+ sprintf(rc_file, "%s/rc", configdir);
+ } else
+ rc_file = bstrdup(rc);
+
+ if (menu == NULL) {
+ menu_file = new char[strlen(configdir) + strlen("/menu") + 1];
+ sprintf(menu_file, "%s/menu", configdir);
+ } else
+ menu_file = bstrdup(menu);
+
+ delete [] configdir;
}
config.setFile(rc_file);
-
+
no_focus = False;
- resource.menu_file = resource.style_file = NULL;
+ resource.style_file = NULL;
resource.titlebar_layout = NULL;
resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0;
@@ -240,9 +250,6 @@ Openbox::~Openbox() {
for_each(menuTimestamps.begin(), menuTimestamps.end(),
PointerAssassin());
- if (resource.menu_file)
- delete [] resource.menu_file;
-
if (resource.style_file)
delete [] resource.style_file;
@@ -252,6 +259,7 @@ Openbox::~Openbox() {
delete timer;
delete [] rc_file;
+ delete [] menu_file;
}
@@ -883,7 +891,6 @@ void Openbox::save() {
// save all values as they are so that the defaults will be written to the rc
// file
- config.setValue("session.menuFile", getMenuFilename());
config.setValue("session.colorsPerChannel",
resource.colors_per_channel);
config.setValue("session.styleFile", resource.style_file);
@@ -910,13 +917,6 @@ void Openbox::load() {
std::string s;
long l;
- if (resource.menu_file)
- delete [] resource.menu_file;
- if (config.getValue("session.menuFile", "Session.MenuFile", s))
- resource.menu_file = bstrdup(s.c_str());
- else
- resource.menu_file = bstrdup(DEFAULTMENU);
-
if (config.getValue("session.colorsPerChannel", "Session.ColorsPerChannel",
l))
resource.colors_per_channel = (l < 2 ? 2 : (l > 6 ? 6 : l)); // >= 2, <= 6
@@ -1001,6 +1001,29 @@ void Openbox::checkMenu() {
}
+void Openbox::addMenuTimestamp(const char *filename) {
+ bool found = false;
+
+ MenuTimestampList::iterator it;
+ for (it = menuTimestamps.begin(); it != menuTimestamps.end(); ++it)
+ if (! strcmp((*it)->filename, filename)) {
+ found = true;
+ break;
+ }
+ if (!found) {
+ struct stat buf;
+
+ if (! stat(filename, &buf)) {
+ MenuTimestamp *ts = new MenuTimestamp;
+
+ ts->filename = bstrdup(filename);
+ ts->timestamp = buf.st_ctime;
+
+ menuTimestamps.push_back(ts);
+ }
+ }
+}
+
void Openbox::rereadMenu() {
reread_menu_wait = True;
@@ -1027,30 +1050,6 @@ void Openbox::setStyleFilename(const char *filename) {
}
-void Openbox::setMenuFilename(const char *filename) {
- bool found = false;
-
- MenuTimestampList::iterator it;
- for (it = menuTimestamps.begin(); it != menuTimestamps.end(); ++it)
- if (! strcmp((*it)->filename, filename)) {
- found = true;
- break;
- }
- if (!found) {
- struct stat buf;
-
- if (! stat(filename, &buf)) {
- MenuTimestamp *ts = new MenuTimestamp;
-
- ts->filename = bstrdup(filename);
- ts->timestamp = buf.st_ctime;
-
- menuTimestamps.push_back(ts);
- }
- }
-}
-
-
void Openbox::timeout() {
if (reconfigure_wait)
real_reconfigure();
diff --git a/src/openbox.h b/src/openbox.h
index 61d5fdb2..a98b2f14 100644
--- a/src/openbox.h
+++ b/src/openbox.h
@@ -87,7 +87,7 @@ private:
struct resource {
Time double_click_interval;
- char *menu_file, *style_file;
+ char *style_file;
char *titlebar_layout;
int colors_per_channel;
timeval auto_raise_delay;
@@ -129,7 +129,7 @@ private:
Bool no_focus, reconfigure_wait, reread_menu_wait;
Time last_time;
Window masked;
- char *rc_file, **argv;
+ char *menu_file, *rc_file, **argv;
int argc;
Resource config;
@@ -144,7 +144,7 @@ protected:
public:
- Openbox(int, char **, char * = 0, char * = 0);
+ Openbox(int, char **, char * = 0, char * = 0, char * = 0);
virtual ~Openbox();
#ifdef HAVE_GETPID
@@ -173,7 +173,8 @@ public:
inline const char *getStyleFilename() const
{ return resource.style_file; }
inline const char *getMenuFilename() const
- { return resource.menu_file; }
+ { return menu_file; }
+ void addMenuTimestamp(const char *filename);
inline const int &getColorsPerChannel() const
{ return resource.colors_per_channel; }
@@ -197,7 +198,6 @@ public:
void shutdown();
void setStyleFilename(const char *);
- void setMenuFilename(const char *);
void saveMenuSearch(Window, Basemenu *);
void saveWindowSearch(Window, OpenboxWindow *);
void saveToolbarSearch(Window, Toolbar *);