diff options
Diffstat (limited to 'openbox')
| -rw-r--r-- | openbox/Makefile.am | 4 | ||||
| -rw-r--r-- | openbox/configwrap.c | 80 | ||||
| -rw-r--r-- | openbox/configwrap.h | 15 | ||||
| -rw-r--r-- | openbox/openbox.c | 3 | ||||
| -rw-r--r-- | openbox/pointer.c | 27 |
5 files changed, 119 insertions, 10 deletions
diff --git a/openbox/Makefile.am b/openbox/Makefile.am index 5eff8fdd..4cc5b4ce 100644 --- a/openbox/Makefile.am +++ b/openbox/Makefile.am @@ -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 index 00000000..3afa5c4c --- /dev/null +++ b/openbox/configwrap.c @@ -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 index 00000000..729646a3 --- /dev/null +++ b/openbox/configwrap.h @@ -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 diff --git a/openbox/openbox.c b/openbox/openbox.c index 7a0cfbb9..54f9b77e 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -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(); diff --git a/openbox/pointer.c b/openbox/pointer.c index 00720f3b..d2407685 100644 --- a/openbox/pointer.c +++ b/openbox/pointer.c @@ -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; |
