]> Dogcows Code - chaz/openbox/commitdiff
valgrind fixes, and fixes for writing shit all over the environment. yay~!!!!!!!
authorDana Jansens <danakj@orodu.net>
Sat, 11 Jan 2003 11:16:36 +0000 (11:16 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 11 Jan 2003 11:16:36 +0000 (11:16 +0000)
otk/display.cc
otk/util.cc
otk/util.hh
src/actions.cc
src/bindings.cc
src/client.cc
src/openbox.cc
src/python.cc

index 33dca01bdb38daf12a19de42caa152b62fbe3486..98288bd02dcdf54990437673a55fb1e9d14264f4 100644 (file)
@@ -7,6 +7,7 @@
 #include "display.hh"
 #include "screeninfo.hh"
 #include "gccache.hh"
+#include "util.hh"
 
 extern "C" {
 #include <X11/keysym.h>
@@ -27,10 +28,6 @@ extern "C" {
 #  include <stdio.h>
 #endif // HAVE_STDIO_H
 
-#ifdef    HAVE_STDLIB_H
-#  include <stdlib.h>
-#endif // HAVE_STDLIB_H
-
 #ifdef    HAVE_SIGNAL_H
 #  include <signal.h>
 #endif // HAVE_SIGNAL_H
@@ -110,11 +107,7 @@ line argument.\n\n"));
   // set the DISPLAY environment variable for any lauched children, to the
   // display we're using, so they open in the right place.
   // XXX rm -> std::string dtmp = "DISPLAY=" + DisplayString(display);
-  if (putenv(const_cast<char*>((std::string("DISPLAY=") +
-                                DisplayString(display)).c_str()))) {
-    printf(_("warning: couldn't set environment variable 'DISPLAY'\n"));
-    perror("putenv()");
-  }
+  putenv(std::string("DISPLAY=") + DisplayString(display));
   
   // find the availability of X extensions we like to use
 #ifdef XKB
index ebca51d51ef0f6fe38c4a4ee4fcbebdaa4c3fe62..a3ec0034ac35e9105d1a8a1a6086303c3e52f9ea 100644 (file)
@@ -23,6 +23,9 @@ extern "C" {
 #  include <process.h>
 #endif //   HAVE_PROCESS_H             __EMX__
 
+#include "gettext.h"
+#define _(str) gettext(str)
+
 #include <assert.h>
 }
 
@@ -48,9 +51,8 @@ void bexec(const string& command, const string& displaystring) {
 #ifndef    __EMX__
   if (! fork()) {
     setsid();
-    int ret = putenv(const_cast<char *>(displaystring.c_str()));
-    assert(ret != -1);
-    ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
+    putenv(displaystring);
+    int ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
     exit(ret);
   }
 #else //   __EMX__
@@ -101,6 +103,19 @@ string itostring(long i) {
   return tmp;
 }
 
+void putenv(const std::string &data)
+{
+  char *c = new char[data.size() + 1];
+  std::string::size_type i, max;
+  for (i = 0, max = data.size(); i < max; ++i)
+    c[i] = data[i];
+  c[i] = 0;
+  if (::putenv(c)) {
+    printf(_("warning: couldn't set environment variable\n"));
+    perror("putenv()");
+  }
+}
+
 string basename (const string& path) {
   string::size_type slash = path.rfind('/');
   if (slash == string::npos)
index 2664c1faa78d8674ac782d9887a4785d3d3450d4..2325ebf0b813ff0b38ae5a0bceb48caac82bd5c9 100644 (file)
@@ -40,6 +40,7 @@ inline std::string itostring(unsigned int i)
 inline std::string itostring(int i)
   { return itostring((long) i); }
 
+void putenv(const std::string &data);
 
 std::string basename(const std::string& path);
 
index 15a3e6c2667f0b9c88cd5a700f3d6fd9619c9709..96290bddc6ab9ac80caf76d0936586036c901c2e 100644 (file)
@@ -37,8 +37,10 @@ OBActions::~OBActions()
 void OBActions::insertPress(const XButtonEvent &e)
 {
   ButtonPressAction *a = _posqueue[BUTTONS - 1];
-  for (int i=BUTTONS-1; i>0;)
-    _posqueue[i] = _posqueue[--i];
+  // rm'd the last one, shift them all down one
+  for (int i = BUTTONS-1; i > 0; --i) {
+    _posqueue[i] = _posqueue[i-1];
+  }
   _posqueue[0] = a;
   a->button = e.button;
   a->pos.setPoint(e.x_root, e.y_root);
@@ -49,17 +51,19 @@ void OBActions::insertPress(const XButtonEvent &e)
 
 void OBActions::removePress(const XButtonEvent &e)
 {
+  int i;
   ButtonPressAction *a = 0;
-  for (int i=0; i<BUTTONS; ++i) {
-    if (_posqueue[i]->button == e.button)
+  for (i=0; i<BUTTONS-1; ++i)
+    if (_posqueue[i]->button == e.button) {
       a = _posqueue[i];
-    if (a) // found one and removed it
+      break;
+    }
+  if (a) { // found one, remove it and shift the rest up one
+    for (; i < BUTTONS-1; ++i)
       _posqueue[i] = _posqueue[i+1];
-  }
-  if (a) { // found one
     _posqueue[BUTTONS-1] = a;
-    a->button = 0;
   }
+  _posqueue[BUTTONS-1]->button = 0;
 }
 
 void OBActions::buttonPressHandler(const XButtonEvent &e)
index 7c13ca64f9eba8e3290817a14eb9b7f51e8a7726..90bac388ece91f901c043df1cd3c31fe7d03aa38 100644 (file)
@@ -158,7 +158,7 @@ OBBindings::~OBBindings()
 {
   grabKeys(false);
   removeAllKeys();
-  removeAllButtons();
+//  removeAllButtons(); XXX
   removeAllEvents();
 }
 
@@ -456,7 +456,7 @@ bool OBBindings::addButton(const std::string &but, MouseContext context,
 
 void OBBindings::removeAllButtons()
 {
-  for (int i = i; i < NUM_MOUSE_CONTEXT; ++i) {
+  for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) {
     ButtonBindingList::iterator it, end = _buttons[i].end();
     for (it = _buttons[i].begin(); it != end; ++it) {
       for (int a = 0; a < NUM_MOUSE_ACTION; ++a) {
index a427a21e6f63f759da1ffdd69dc3b2d0abcaf507..c69d576a47f1c5c3b4e1d58359d3ae4ce0ae9be3 100644 (file)
@@ -43,6 +43,8 @@ OBClient::OBClient(int screen, Window window)
   _focused = false;
   // not a transient by default of course
   _transient_for = 0;
+  // pick a layer to start from
+  _layer = Layer_Normal;
   
   getArea();
   getDesktop();
index 42cc1fefe96a3017c2a93a73bc0a40ab6ec67eec..600c9d8d90bcfdf372080c4b32d1ecd376e4c3e1 100644 (file)
@@ -13,7 +13,7 @@
 #include "otk/property.hh"
 #include "otk/display.hh"
 #include "otk/assassin.hh"
-#include "otk/util.hh" // TEMPORARY
+#include "otk/util.hh"
 
 extern "C" {
 #include <X11/cursorfont.h>
@@ -202,7 +202,7 @@ Openbox::~Openbox()
     if (!_restart_prog.empty()) {
       const std::string &dstr =
         otk::OBDisplay::screenInfo(first_screen)->displayString();
-      putenv(const_cast<char *>(dstr.c_str()));
+      otk::putenv(const_cast<char *>(dstr.c_str()));
       execlp(_restart_prog.c_str(), _restart_prog.c_str(), NULL);
       perror(_restart_prog.c_str());
     }
@@ -381,23 +381,9 @@ void Openbox::setFocusedClient(OBClient *c)
 
 void Openbox::execute(int screen, const std::string &bin)
 {
-#ifdef    __EMX__
-  // XXX: whats this for? windows?
-  spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", bin.c_str(), NULL);
-#else //  __EMX__
   if (screen >= ScreenCount(otk::OBDisplay::display))
     screen = 0;
-  const std::string &dstr =
-    otk::OBDisplay::screenInfo(screen)->displayString();
-  
-  if (! fork()) {
-      setsid();
-      int ret = putenv(const_cast<char *>(dstr.c_str()));
-      assert(ret != -1);
-      ret = execl("/bin/sh", "/bin/sh", "-c", bin.c_str(), NULL);
-      exit(ret);
-    }
-#endif // __EMX__
+  otk::bexec(bin, otk::OBDisplay::screenInfo(screen)->displayString());
 }
 
 }
index 2c71b0182748aa4a44c7410bb97a4cd28eaf6d18..891d11203104b03f1140e6286a03b29a9a2de9f7 100644 (file)
@@ -19,28 +19,17 @@ static PyObject *obdict = NULL;
 
 void python_init(char *argv0)
 {
-  std::string path;
-  
   // start the python engine
-  //Py_SetProgramName(argv0);
-  //Py_Initialize();
+  Py_SetProgramName(argv0);
+  Py_Initialize();
   // initialize the C python module
-  //init_openbox();
+  init_openbox();
   // include the openbox directories for python scripts in the sys path
-//  PyRun_SimpleString("import sys");
-printf("SCRIPTDIR=%s\n", SCRIPTDIR);
-printf("1 getenv(DISPLAY)=%s\n", getenv("DISPLAY"));
-  path = "sys.path";
-printf("2 getenv(DISPLAY)=%s\n", getenv("DISPLAY"));
-  path = "sys.path.append('";
-printf("3 getenv(DISPLAY)=%s\n", getenv("DISPLAY"));
-  path += SCRIPTDIR;
-  path += "')";
-  PyRun_SimpleString(const_cast<char*>(path.c_str()));
-  path = "sys.path.append('";
-  path += otk::expandTilde("~/.openbox/python");
-  path += "')";
-  PyRun_SimpleString(const_cast<char*>(path.c_str()));
+  PyRun_SimpleString("import sys");
+  PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')");
+  PyRun_SimpleString(const_cast<char*>(("sys.path.append('" +
+                                        otk::expandTilde("~/.openbox/python") +
+                                        "')").c_str()));
   // import the otk and openbox modules into the main namespace
   PyRun_SimpleString("from openbox import *;");
   // set up convenience global variables
This page took 0.033468 seconds and 4 git commands to generate.