all repos — openbox @ 115fedf432d73f17ade48eaa2fa12dfd333bfcaa

openbox fork - make it a bit more like ryudo

src/main.cc (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-

/*! @file main.cc
  @brief Main entry point for the application
*/

#include "config.h"

extern "C" {
#ifdef    HAVE_UNISTD_H
#  include <sys/types.h>
#  include <unistd.h>
#endif // HAVE_UNISTD_H

#include "gettext.h"
}

#include "openbox.hh"
#include "otk/util.hh"

#include <clocale>
#include <cstdio>

int main(int argc, char **argv) {
  // initialize the locale
  if (!setlocale(LC_ALL, ""))
    printf("Couldn't set locale from environment.\n");
  bindtextdomain(PACKAGE, LOCALEDIR);
  bind_textdomain_codeset(PACKAGE, "UTF-8");
  textdomain(PACKAGE);

  ob::Openbox *openbox = new ob::Openbox(argc, argv);
  openbox->eventLoop();

  if (openbox->doRestart()) {
    std::string prog = openbox->restartProgram();

    delete openbox; // shutdown the current one!
    
    if (!prog.empty()) {
      execl("/bin/sh", "/bin/sh", "-c", prog.c_str(), NULL); 
      perror(prog.c_str());
    }
    
    // fall back in case the above execlp doesn't work
    execvp(argv[0], argv);
    execvp(otk::basename(argv[0]).c_str(), argv);
  }

  delete openbox; // shutdown
}