pointer's variables are config vars
authorDana Jansens <danakj@orodu.net>
Sun, 16 Mar 2003 23:15:20 +0000 (23:15 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Mar 2003 23:15:20 +0000 (23:15 +0000)
doc/python/config.txt
openbox/Makefile.am
openbox/configwrap.c [new file with mode: 0644]
openbox/configwrap.h [new file with mode: 0644]
openbox/openbox.c
openbox/pointer.c
python/config.py
python/rc.py

index 0362fde..5ed5517 100644 (file)
@@ -11,3 +11,58 @@ Methods
 
 ----
 
+add(modulename, name, friendlyname, description, type, default, **keywords):
+
+Add a variable to the configuration system for a module.
+
+       modulename: The name of the module, e.g. 'focus'
+       name: The name of the variable, e.g. 'my_variable'
+       friendlyname: The user-friendly name of the variable, e.g.
+                     'My Variable'
+       description: The detailed destription of the variable, e.g.
+                    'Does Things'
+       type: The type of the variable, one of:
+             * 'boolean'
+             * 'enum'
+             * 'integer'
+             * 'string'
+             * 'function'
+             * 'object'
+       default: The default value for the variable, e.g. 300
+       keywords: Extra keyword=value pairs to further define the variable.
+                 These can be:
+                 * For 'enum' types:
+                     * options : A list of possible options for the variable.
+                                 This *must* be set for all enum variables.
+                 * For 'integer' types:
+                     * min : The minimum value for the variable.
+                     * max : The maximum value for the variable.
+
+----
+
+set(modulename, name, value):
+
+Sets the value for a variable of the specified module.
+
+       modulename: The name of the module, e.g. 'focus'
+       name: The name of the variable, e.g. 'my_variable'
+       value: The new value for the variable.
+
+----
+
+reset(modulename, name):
+
+Resets the value for a variable in the specified module back to its original
+(default) value.
+
+       modulename: The name of the module, e.g. 'focus'
+       name: The name of the variable, e.g. 'my_variable'
+
+----
+
+get(modulename, name):
+
+Returns the current value for a variable in the specified module.
+
+       modulename: The name of the module, e.g. 'focus'
+       name: The name of the variable, e.g. 'my variable'
index 5eff8fd..4cc5b4c 100644 (file)
@@ -20,12 +20,12 @@ ob3_LDADD=@LIBINTL@ ../render/librender.a
 ob3_LDFLAGS=-export-dynamic
 ob3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c prop.c \
        python.c screen.c stacking.c xerror.c hooks.c themerc.c timer.c \
-       clientwrap.c openboxwrap.c pointer.c keyboard.c engine.c
+       clientwrap.c openboxwrap.c pointer.c keyboard.c engine.c configwrap.c
 
 noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \
        openbox.h prop.h python.h screen.h stacking.h xerror.h themerc.h \
        timer.h hooks.h clientwrap.h openboxwrap.h pointer.h keyboard.h \
-       engine.h
+       engine.h configwrap.h
 
 MAINTAINERCLEANFILES= Makefile.in
 
diff --git a/openbox/configwrap.c b/openbox/configwrap.c
new file mode 100644 (file)
index 0000000..3afa5c4
--- /dev/null
@@ -0,0 +1,80 @@
+#include <Python.h>
+#include <glib.h>
+
+/* This simply wraps the config.py module so that it can be accessed from the
+   C code.
+*/
+
+static PyObject *add, *get, *set, *reset;
+
+void configwrap_startup()
+{
+    PyObject *c, *cdict;
+
+    /* get the ob module/dict */
+    c = PyImport_ImportModule("config"); /* new */
+    g_assert(c != NULL);
+    cdict = PyModule_GetDict(c); /* borrowed */
+    g_assert(cdict != NULL);
+
+    /* get the functions */
+    add = PyDict_GetItemString(cdict, "add");
+    g_assert(add != NULL);
+    get = PyDict_GetItemString(cdict, "get");
+    g_assert(get != NULL);
+    set = PyDict_GetItemString(cdict, "set");
+    g_assert(set != NULL);
+    reset = PyDict_GetItemString(cdict, "reset");
+    g_assert(reset != NULL);
+
+    Py_DECREF(c);
+}
+
+void configwrap_shutdown()
+{
+    Py_DECREF(get);
+    Py_DECREF(set);
+    Py_DECREF(reset);
+    Py_DECREF(add);
+}
+
+void configwrap_add_int(char *modname, char *varname, char *friendname,
+                             char *description, int defvalue)
+{
+    PyObject *r;
+
+    r= PyObject_CallFunction(add, "sssssi", modname, varname,
+                             friendname, description, "integer", defvalue);
+    g_assert(r != NULL);
+    Py_DECREF(r);
+}
+
+int configwrap_get_int(char *modname, char *varname)
+{
+    PyObject *r;
+    int i;
+
+    r = PyObject_CallFunction(get, "ss", modname, varname);
+    g_assert(r != NULL);
+    i = PyInt_AsLong(r);
+    Py_DECREF(r);
+    return i;
+}
+
+void configwrap_set_int(char *modname, char *varname, int value)
+{
+    PyObject *r;
+
+    r = PyObject_CallFunction(set, "ssi", modname, varname, value);
+    g_assert(r != NULL);
+    Py_DECREF(r);
+}
+
+void configwrap_reset(char *modname, char *varname)
+{
+    PyObject *r;
+
+    r = PyObject_CallFunction(reset, "ss", modname, varname);
+    g_assert(r != NULL);
+    Py_DECREF(r);
+}
diff --git a/openbox/configwrap.h b/openbox/configwrap.h
new file mode 100644 (file)
index 0000000..729646a
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __configwrap_h
+#define __configwrap_h
+
+void configwrap_startup();
+void configwrap_shutdown();
+
+void configwrap_add_int(char *modname, char *varname, char *friendname,
+                        char *description, int defvalue);
+int configwrap_get_int(char *modname, char *varname);
+void configwrap_set_int(char *modname, char *varname, int value);
+
+
+void configwrap_reset(char *modname, char *varname);
+
+#endif
index 7a0cfbb..54f9b77 100644 (file)
@@ -14,6 +14,7 @@
 #include "hooks.h"
 #include "clientwrap.h"
 #include "openboxwrap.h"
+#include "configwrap.h"
 #include "themerc.h"
 #include "timer.h"
 #include "../render/render.h"
@@ -133,6 +134,7 @@ int main(int argc, char **argv)
        themerc_startup();
        engine_startup(themerc_engine);
        python_startup();
+        configwrap_startup();
        openboxwrap_startup();
        clientwrap_startup();
        hooks_startup();
@@ -170,6 +172,7 @@ int main(int argc, char **argv)
        hooks_shutdown();
        clientwrap_shutdown();
        openboxwrap_shutdown();
+        configwrap_shutdown();
        python_shutdown();
        engine_shutdown();
        themerc_shutdown();
index 00720f3..d240768 100644 (file)
@@ -4,6 +4,7 @@
 #include "engine.h"
 #include "openbox.h"
 #include "hooks.h"
+#include "configwrap.h"
 
 #include <glib.h>
 #include <Python.h>
@@ -24,7 +25,6 @@ typedef enum {
 /* GData of GSList*s of PointerBinding*s. */
 static GData *bound_contexts;
 static gboolean grabbed;
-static int double_click_rate, drag_threshold;
 PyObject *grab_func;
 
 struct foreach_grab_temp {
@@ -332,6 +332,9 @@ void pointer_event(XEvent *e, Client *c)
     guint state;
     GSList *it = NULL;
     PointerBinding *b = NULL;
+    guint drag_threshold;
+
+    drag_threshold = configwrap_get_int("input", "drag_threshold");
 
     contextq = engine_get_context(c, e->xany.window);
 
@@ -388,8 +391,8 @@ void pointer_event(XEvent *e, Client *c)
        if (button == e->xbutton.button) {
            /* determine if this is a valid 'click'. Its not if the release is
             not over the window, or if a drag occured. */
-           if (ABS(e->xbutton.x_root - pressx) < (unsigned)drag_threshold &&
-               ABS(e->xbutton.y_root - pressy) < (unsigned)drag_threshold &&
+           if (ABS(e->xbutton.x_root - pressx) < drag_threshold &&
+               ABS(e->xbutton.y_root - pressy) < drag_threshold &&
                e->xbutton.x >= 0 && e->xbutton.y >= 0) {
                int junk;
                Window wjunk;
@@ -403,7 +406,8 @@ void pointer_event(XEvent *e, Client *c)
            /* determine if this is a valid 'double-click' */
            if (click) {
                if (lastbutton == button &&
-                   e->xbutton.time - double_click_rate < time) {
+                   e->xbutton.time -
+                    configwrap_get_int("input", "double_click_rate") < time) {
                    dblclick = TRUE;
                    lastbutton = 0;
                } else
@@ -432,8 +436,8 @@ void pointer_event(XEvent *e, Client *c)
         break;
     case MotionNotify:
         /* watch out for the drag threshold */
-        if (ABS(e->xmotion.x_root - pressx) < (unsigned)drag_threshold &&
-            ABS(e->xmotion.y_root - pressy) < (unsigned)drag_threshold)
+        if (ABS(e->xmotion.x_root - pressx) < drag_threshold &&
+            ABS(e->xmotion.y_root - pressy) < drag_threshold)
             break;
         fire_event(str->str, contextq, Action_Motion,
                    state, button, e->xmotion.x_root,
@@ -690,8 +694,15 @@ void pointer_startup()
     Pointer *ptr;
 
     grabbed = FALSE;
-    double_click_rate = 300;
-    drag_threshold = 3;
+    configwrap_add_int("input", "double_click_rate", "Double-Click Rate",
+                       "An integer containing the number of milliseconds in "
+                       "which 2 clicks must be received to cause a "
+                       "double-click event.", 300);
+    configwrap_add_int("input", "drag_threshold", "Drag Threshold",
+                       "An integer containing the number of pixels a drag "
+                       "must go before motion events start getting generated. "
+                       "Once a drag has begun, the button release will not "
+                       "count as a click event.", 3);
     g_datalist_init(&bound_contexts);
 
     PointerType.ob_type = &PyType_Type;
index 2ab22f9..3aa6c58 100644 (file)
@@ -186,57 +186,5 @@ _types = [ 'boolean', # Boolean types can only hold a value of 0 or 1.
 
            'object'   # Object types can hold any python object.
            ];
-  
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#############################################################################
-### Options that can be changed to adjust the behavior of Openbox.        ###
-#############################################################################
-
-THEME = "/usr/local/share/openbox/styles/fieron2"
-"""The theme used to decorate everything."""
-
-#TITLEBAR_LAYOUT = [ "icon", "title", "alldesktops", "iconify", "maximize", "close" ]
-TITLEBAR_LAYOUT = "DITMC"
-"""The layout of the buttons/label on client titlebars, can be made up of the
-following:
-    I - iconify button
-    L - text label
-    M - maximize button,
-    D - all-desktops button
-    C - close button
-If no 'L' is included in the string, one will be added to the end by
-Openbox."""
-
-DOUBLE_CLICK_DELAY = 300
-"""The number of milliseconds in which 2 clicks are perceived as a
-double-click."""
-
-DRAG_THRESHOLD = 3
-"""The amount of pixels that you have to drag the mouse before motion events
-will start occuring."""
-
-DESKTOP_NAMES = ["one", "two", "three", "four", "five", "six", "seven", \
-                 "eight", "nine", "ten", "eleven", "twelve"]
-"""The name of each desktop."""
-
-NUMBER_OF_DESKTOPS = 4
-"""The number of desktops/workspaces which can be scrolled between."""
-
-#############################################################################
 
 print "Loaded config.py"
index e3cf76f..8ddfa46 100644 (file)
@@ -2,6 +2,9 @@ import hooks, ob, keymap, buttonmap, os, sys, input, motion, historyplacement
 import stackedcycle
 from input import Pointer
 
+import config
+print dir(config)
+
 hooks.managed.append(historyplacement.place)
 
 _grab = 0