X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fopenbox.cc;h=c946cd274433b39037ebc8a388f85fee3cb26744;hb=ae093dba2fb97124bb4af3eaf4070b46f07dfd74;hp=7c25bc624d9eecc9b7685e487da78fbfed87c866;hpb=6d16679486a9268a17f3bfd03b05febf1644a87e;p=chaz%2Fopenbox diff --git a/src/openbox.cc b/src/openbox.cc index 7c25bc62..c946cd27 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,29 +164,40 @@ 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; - masked_window = NULL; + current_screen = (BScreen *) 0; + masked_window = (OpenboxWindow *) 0; masked = None; load(); @@ -195,8 +206,8 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False); #endif // HAVE_GETPID - for (int i = 0; i < getNumberOfScreens(); i++) { - BScreen *screen = new BScreen(*this, i, config); + for (unsigned int s = 0; s < numberOfScreens(); s++) { + BScreen *screen = new BScreen(*this, s, config); if (! screen->isScreenManaged()) { delete screen; @@ -212,7 +223,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) "Openbox::Openbox: no managable screens found, aborting.\n")); ::exit(3); } - focused_screen = screenList.front(); + current_screen = screenList.front(); // save current settings and default values save(); @@ -228,7 +239,7 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) ungrab(); - focusWindow((OpenboxWindow *) 0); + focusWindow(0); } @@ -239,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; @@ -251,6 +259,7 @@ Openbox::~Openbox() { delete timer; delete [] rc_file; + delete [] menu_file; } @@ -867,11 +876,11 @@ void Openbox::restart(const char *prog) { void Openbox::shutdown() { BaseDisplay::shutdown(); - focusWindow((OpenboxWindow *) 0); - std::for_each(screenList.begin(), screenList.end(), std::mem_fun(&BScreen::shutdown)); + focusWindow(0); + XSync(getXDisplay(), False); } @@ -882,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); @@ -909,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 @@ -942,7 +943,7 @@ void Openbox::load() { else resource.double_click_interval = 250; - if (!config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l)) + if (config.getValue("session.autoRaiseDelay", "Session.AutoRaiseDelay", l)) resource.auto_raise_delay.tv_usec = l; else resource.auto_raise_delay.tv_usec = 400; @@ -1000,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; @@ -1026,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(); @@ -1062,12 +1062,11 @@ void Openbox::timeout() { OpenboxWindow *Openbox::focusedWindow() { - if (focused_screen == (BScreen *) 0) - return (OpenboxWindow *) 0; - Workspace *w = focused_screen->getCurrentWorkspace(); - if (w == (Workspace *) 0) - return (OpenboxWindow *) 0; - return w->focusedWindow(); + Workspace *w; + if (current_screen) + if ((w = current_screen->getCurrentWorkspace())) + return w->focusedWindow(); + return (OpenboxWindow *) 0; } @@ -1082,28 +1081,26 @@ void Openbox::focusWindow(OpenboxWindow *win) { old_wkspc = old_screen->getWorkspace(old_win->getWorkspaceNumber()); old_tbar = old_screen->getToolbar(); - old_win->setFocusFlag(False); + old_win->setFocusFlag(false); old_wkspc->focusWindow((OpenboxWindow *) 0); } if (win && !win->isIconic()) { - focused_screen = win->getScreen(); - tbar = focused_screen->getToolbar(); - wkspc = focused_screen->getWorkspace(win->getWorkspaceNumber()); + current_screen = win->getScreen(); + tbar = current_screen->getToolbar(); + wkspc = current_screen->getWorkspace(win->getWorkspaceNumber()); win->setFocusFlag(true); wkspc->focusWindow(win); if (tbar) tbar->redrawWindowLabel(true); - focused_screen->updateNetizenWindowFocus(); + current_screen->updateNetizenWindowFocus(); } else { - ASSERT(focused_screen != (BScreen *) 0); - XSetInputFocus(getXDisplay(), focused_screen->getRootWindow(), - None, CurrentTime); + XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime); } if (old_tbar && old_tbar != tbar) old_tbar->redrawWindowLabel(true); - if (old_screen && old_screen != focused_screen) + if (old_screen && old_screen != current_screen) old_screen->updateNetizenWindowFocus(); }