-#endif // HAVE_BASENAME
-
-
-// X event scanner for enter/leave notifies - adapted from twm
-typedef struct scanargs {
- Window w;
- Bool leave, inferior, enter;
-} scanargs;
-
-static Bool queueScanner(Display *, XEvent *e, char *args) {
- if ((e->type == LeaveNotify) &&
- (e->xcrossing.window == ((scanargs *) args)->w) &&
- (e->xcrossing.mode == NotifyNormal)) {
- ((scanargs *) args)->leave = True;
- ((scanargs *) args)->inferior = (e->xcrossing.detail == NotifyInferior);
- } else if ((e->type == EnterNotify) &&
- (e->xcrossing.mode == NotifyUngrab)) {
- ((scanargs *) args)->enter = True;
- }
-
- return False;
-}
-
-Openbox *openbox;
-
-
-Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc,
- char *menu) : BaseDisplay(m_argv[0], dpy_name) {
- grab();
-
- if (! XSupportsLocale())
- fprintf(stderr, "X server does not support locale\n");
-
- if (XSetLocaleModifiers("") == NULL)
- fprintf(stderr, "cannot set locale modifiers\n");
-
- ::openbox = this;
- argc = m_argc;
- argv = m_argv;
- if (rc == NULL || menu == NULL) {
- char *homedir = getenv("HOME");
- char *configdir = new char[strlen(homedir) + strlen("/.openbox") + 1];
- sprintf(configdir, "%s/.openbox", homedir);
- // try to make sure the ~/.openbox directory exists
- mkdir(configdir, S_IREAD | S_IWRITE | S_IEXEC |
- S_IRGRP | S_IWGRP | S_IXGRP |
- S_IROTH | S_IWOTH | S_IXOTH);
-
-
- 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.style_file = NULL;
- resource.titlebar_layout = NULL;
- resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec = 0;
-
- current_screen = (BScreen *) 0;
- masked_window = (OpenboxWindow *) 0;
- masked = None;
-
- load();
-
-#ifdef HAVE_GETPID
- openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False);
-#endif // HAVE_GETPID
-
- for (unsigned int s = 0; s < numberOfScreens(); s++) {
- BScreen *screen = new BScreen(*this, s, config);
-
- if (! screen->isScreenManaged()) {
- delete screen;
- continue;
- }
-
- screenList.push_back(screen);
- }
-
- if (screenList.empty()) {
- fprintf(stderr,
- i18n(openboxSet, openboxNoManagableScreens,
- "Openbox::Openbox: no managable screens found, aborting.\n"));
- ::exit(3);
- }
- current_screen = screenList.front();
-
- // save current settings and default values
- save();
-
- XSynchronize(getXDisplay(), False);
- XSync(getXDisplay(), False);
-
- reconfigure_wait = reread_menu_wait = False;
-
- timer = new BTimer(*this, *this);
- timer->setTimeout(0);
- timer->fireOnce(True);
-
- ungrab();
-
- focusWindow(0);
- }
-
-
-Openbox::~Openbox() {
- for_each(screenList.begin(), screenList.end(),
- PointerAssassin());
-
- for_each(menuTimestamps.begin(), menuTimestamps.end(),
- PointerAssassin());
-
- if (resource.style_file)
- delete [] resource.style_file;
-
- if (resource.titlebar_layout)
- delete [] resource.titlebar_layout;
-
- delete timer;
-
- delete [] rc_file;
- delete [] menu_file;
-}
-
-
-void Openbox::process_event(XEvent *e) {
- if ((masked == e->xany.window && masked_window) &&
- (e->type == MotionNotify)) {
- last_time = e->xmotion.time;
- masked_window->motionNotifyEvent(&e->xmotion);
- return;
- }
-
- switch (e->type) {
- case ButtonPress: {
- // strip the lock key modifiers
- e->xbutton.state &= ~(NumLockMask | ScrollLockMask | LockMask);
-
- last_time = e->xbutton.time;
-
- OpenboxWindow *win = (OpenboxWindow *) 0;
- Basemenu *menu = (Basemenu *) 0;
-
-#ifdef SLIT
- Slit *slit = (Slit *) 0;
-#endif // SLIT
-
- Toolbar *tbar = (Toolbar *) 0;
-
- if ((win = searchWindow(e->xbutton.window))) {
- win->buttonPressEvent(&e->xbutton);
-
- if (e->xbutton.button == 1)
- win->installColormap(True);
- } else if ((menu = searchMenu(e->xbutton.window))) {
- menu->buttonPressEvent(&e->xbutton);
-
-#ifdef SLIT
- } else if ((slit = searchSlit(e->xbutton.window))) {
- slit->buttonPressEvent(&e->xbutton);
-#endif // SLIT
-
- } else if ((tbar = searchToolbar(e->xbutton.window))) {
- tbar->buttonPressEvent(&e->xbutton);
- } else {
- ScreenList::iterator it;
- for (it = screenList.begin(); it != screenList.end(); ++it) {
- BScreen *screen = *it;
- if (e->xbutton.window == screen->getRootWindow()) {
- if (e->xbutton.button == 1) {
- if (! screen->isRootColormapInstalled())
- screen->getImageControl()->installRootColormap();
-
- if (screen->getWorkspacemenu()->isVisible())
- screen->getWorkspacemenu()->hide();
-
- if (screen->getRootmenu()->isVisible())
- screen->getRootmenu()->hide();
- } else if (e->xbutton.button == 2) {
- int mx = e->xbutton.x_root -
- (screen->getWorkspacemenu()->getWidth() / 2);
- int my = e->xbutton.y_root -
- (screen->getWorkspacemenu()->getTitleHeight() / 2);
-
- if (mx < 0) mx = 0;
- if (my < 0) my = 0;
-
- if (mx + screen->getWorkspacemenu()->getWidth() >
- screen->size().w())
- mx = screen->size().w() -
- screen->getWorkspacemenu()->getWidth() -
- screen->getBorderWidth();
-
- if (my + screen->getWorkspacemenu()->getHeight() >
- screen->size().h())
- my = screen->size().h() -
- screen->getWorkspacemenu()->getHeight() -
- screen->getBorderWidth();
-
- screen->getWorkspacemenu()->move(mx, my);
-
- if (! screen->getWorkspacemenu()->isVisible()) {
- screen->getWorkspacemenu()->removeParent();
- screen->getWorkspacemenu()->show();
- }
- } else if (e->xbutton.button == 3) {
- int mx = e->xbutton.x_root -
- (screen->getRootmenu()->getWidth() / 2);
- int my = e->xbutton.y_root -
- (screen->getRootmenu()->getTitleHeight() / 2);
-
- if (mx < 0) mx = 0;
- if (my < 0) my = 0;
-
- if (mx + screen->getRootmenu()->getWidth() > screen->size().w())
- mx = screen->size().w() -
- screen->getRootmenu()->getWidth() -
- screen->getBorderWidth();
-
- if (my + screen->getRootmenu()->getHeight() > screen->size().h())
- my = screen->size().h() -
- screen->getRootmenu()->getHeight() -
- screen->getBorderWidth();