summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Screen.cc98
-rw-r--r--src/blackbox.cc18
-rw-r--r--src/blackbox.hh10
-rw-r--r--src/main.cc16
4 files changed, 77 insertions, 65 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index 2844d874..f793c91e 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -1118,56 +1118,64 @@ void BScreen::InitMenu(void) {
}
bool defaultMenu = True;
- if (blackbox->getMenuFilename()) {
- FILE *menu_file = fopen(blackbox->getMenuFilename(), "r");
-
- if (!menu_file) {
- perror(blackbox->getMenuFilename());
+ FILE *menu_file = (FILE *) 0;
+ const char *menu_filename = blackbox->getMenuFilename();
+
+ if (menu_filename)
+ if (!(menu_file = fopen(menu_filename, "r")))
+ perror(menu_filename);
+ if (!menu_file) { // opening the menu file failed, try the default menu
+ menu_filename = DEFAULTMENU;
+ if (!(menu_file = fopen(menu_filename, "r")))
+ perror(menu_filename);
+ }
+
+ if (menu_file) {
+ if (feof(menu_file)) {
+ fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
+ "%s: Empty menu file"),
+ menu_filename);
} else {
- if (feof(menu_file)) {
- fprintf(stderr, i18n(ScreenSet, ScreenEmptyMenuFile,
- "%s: Empty menu file"),
- blackbox->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);
-
- 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]);
- }
+ 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);
+
+ 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) { // [begin]
- 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) { // [begin]
+ 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)
+ blackbox->addMenuTimestamp(menu_filename);
+ break;
}
}
}
- fclose(menu_file);
}
+ fclose(menu_file);
}
if (defaultMenu) {
@@ -1180,9 +1188,7 @@ void BScreen::InitMenu(void) {
rootmenu->insert(i18n(ScreenSet, ScreenExit, "Exit"),
BScreen::Exit);
rootmenu->setLabel(i18n(BasemenuSet, BasemenuBlackboxMenu,
- "Blackbox Menu"));
- } else {
- blackbox->saveMenuFilename(blackbox->getMenuFilename());
+ "Openbox Menu"));
}
}
@@ -1339,7 +1345,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
if (! feof(submenufile)) {
if (! parseMenuFile(submenufile, menu))
- blackbox->saveMenuFilename(newfile);
+ blackbox->addMenuTimestamp(newfile);
fclose(submenufile);
}
@@ -1470,7 +1476,7 @@ bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
rootmenuList.push_back(stylesmenu);
}
- blackbox->saveMenuFilename(stylesdir);
+ blackbox->addMenuTimestamp(stylesdir);
} else {
fprintf(stderr,
i18n(ScreenSet, ScreenSTYLESDIRErrorNotDir,
diff --git a/src/blackbox.cc b/src/blackbox.cc
index 4325933b..bca48e5d 100644
--- a/src/blackbox.cc
+++ b/src/blackbox.cc
@@ -134,7 +134,7 @@ static Bool queueScanner(Display *, XEvent *e, char *args) {
Blackbox *blackbox;
-Blackbox::Blackbox(char **m_argv, char *dpy_name, char *rc)
+Blackbox::Blackbox(char **m_argv, char *dpy_name, char *rc, char *menu)
: BaseDisplay(m_argv[0], dpy_name) {
if (! XSupportsLocale())
fprintf(stderr, "X server does not support locale\n");
@@ -144,8 +144,10 @@ Blackbox::Blackbox(char **m_argv, char *dpy_name, char *rc)
::blackbox = this;
argv = m_argv;
- if (! rc) rc = "~/.blackboxrc";
+ if (! rc) rc = "~/.openbox/rc";
rc_file = expandTilde(rc);
+ if (! menu) menu = "~/.openbox/menu";
+ menu_file = expandTilde(menu);
no_focus = False;
@@ -978,9 +980,6 @@ void Blackbox::save_rc(void) {
load_rc();
- sprintf(rc_string, "session.menuFile: %s", getMenuFilename());
- XrmPutLineResource(&new_blackboxrc, rc_string);
-
sprintf(rc_string, "session.colorsPerChannel: %d",
resource.colors_per_channel);
XrmPutLineResource(&new_blackboxrc, rc_string);
@@ -1186,13 +1185,6 @@ void Blackbox::load_rc(void) {
int int_value;
unsigned long long_value;
- if (XrmGetResource(database, "session.menuFile", "Session.MenuFile",
- &value_type, &value)) {
- resource.menu_file = expandTilde(value.addr);
- } else {
- resource.menu_file = DEFAULTMENU;
- }
-
resource.colors_per_channel = 4;
if (XrmGetResource(database, "session.colorsPerChannel",
"Session.ColorsPerChannel", &value_type, &value) &&
@@ -1595,7 +1587,7 @@ void Blackbox::saveStyleFilename(const string& filename) {
}
-void Blackbox::saveMenuFilename(const string& filename) {
+void Blackbox::addMenuTimestamp(const string& filename) {
assert(! filename.empty());
bool found = False;
diff --git a/src/blackbox.hh b/src/blackbox.hh
index b494039c..0545bcc8 100644
--- a/src/blackbox.hh
+++ b/src/blackbox.hh
@@ -109,7 +109,7 @@ private:
struct BResource {
Time double_click_interval;
- std::string menu_file, style_file;
+ std::string style_file;
int colors_per_channel;
timeval auto_raise_delay;
unsigned long cache_life, cache_max;
@@ -148,7 +148,7 @@ private:
bool no_focus, reconfigure_wait, reread_menu_wait;
Time last_time;
char **argv;
- std::string rc_file;
+ std::string menu_file, rc_file;
Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state,
@@ -205,7 +205,7 @@ private:
public:
- Blackbox(char **m_argv, char *dpy_name = 0, char *rc = 0);
+ Blackbox(char **m_argv, char *dpy_name = 0, char *rc = 0, char *menu = 0);
virtual ~Blackbox(void);
Basemenu *searchMenu(Window window);
@@ -235,7 +235,7 @@ public:
inline const char *getStyleFilename(void) const
{ return resource.style_file.c_str(); }
inline const char *getMenuFilename(void) const
- { return resource.menu_file.c_str(); }
+ { return menu_file.c_str(); }
inline int getColorsPerChannel(void) const
{ return resource.colors_per_channel; }
@@ -263,7 +263,7 @@ public:
void shutdown(void);
void load_rc(BScreen *screen);
void saveStyleFilename(const std::string& filename);
- void saveMenuFilename(const std::string& filename);
+ void addMenuTimestamp(const std::string& filename);
void restart(const char *prog = 0);
void reconfigure(void);
void rereadMenu(void);
diff --git a/src/main.cc b/src/main.cc
index 370e6ecd..e213c808 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -65,6 +65,7 @@ static void showHelp(int exitval) {
"\t\t\t 1997 - 2000, 2002 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);
@@ -101,6 +102,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;
i18n.openCatalog("blackbox.cat");
@@ -117,6 +119,18 @@ int main(int argc, char **argv) {
}
rc_file = argv[i];
+ } else if (! strcmp(argv[i], "-menu")) {
+ // look for alternative menu file to use
+
+ if ((++i) >= argc) {
+ fprintf(stderr,
+ i18n(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
@@ -156,7 +170,7 @@ int main(int argc, char **argv) {
_chdir2(getenv("X11ROOT"));
#endif // __EMX__
- Blackbox blackbox(argv, session_display, rc_file);
+ Blackbox blackbox(argv, session_display, rc_file, menu_file);
blackbox.eventLoop();
return(0);