]> Dogcows Code - chaz/openbox/commitdiff
linear focus cycling
authorDana Jansens <danakj@orodu.net>
Thu, 23 Jan 2003 09:01:40 +0000 (09:01 +0000)
committerDana Jansens <danakj@orodu.net>
Thu, 23 Jan 2003 09:01:40 +0000 (09:01 +0000)
scripts/Makefile.am
scripts/builtins.py
scripts/focus.py [new file with mode: 0644]
src/openbox.cc
src/openbox.py
src/openbox_wrap.cc
src/python.hh

index cafe6928679447b5a9bd4edf1ec5312aece4bac9..ee0287a49391d0664411b8b51a8593967a272dfa 100644 (file)
@@ -1,6 +1,6 @@
 scriptdir = $(libdir)/openbox/python
 MAINTAINERCLEANFILES = Makefile.in
-script_DATA = config.py builtins.py defaults.py
+script_DATA = config.py builtins.py defaults.py focus.py
 EXTRA_DIST = $(script_DATA)
 
 distclean-local:
index e3424001c156c409c8569dd3ce8c46ae297687e6..4ae4587b8e0bf71f9ebc149f54d362f725314d62 100644 (file)
@@ -287,34 +287,8 @@ def setup_scroll():
 def setup_fallback_focus():
     """Sets up a focus fallback routine so that when no windows are focused,
        the last window to have focus on the desktop will be focused."""
-    focus_stack = []
-    def focused(data):
-        #global focus_stack
-        if data.client:
-            window = data.client.window()
-            # add to front the stack
-            if window in focus_stack:
-                focus_stack.remove(window)
-            focus_stack.insert(0, window)
-        else:
-            # pass around focus
-            desktop = openbox.screen(data.screen).desktop()
-            l = len(focus_stack)
-            i = 0
-            while i < l:
-                w = focus_stack[i]
-                client = openbox.findClient(w)
-                if not client: # window is gone, remove it
-                    focus_stack.pop(i)
-                    l = l - 1
-                elif client.desktop() == desktop and \
-                         client.normal() and client.focus():
-                    break
-                else:
-                    i = i + 1
-
-    ebind(EventFocus, focused)
-
+    global ob_focus_fallback # see focus.py
+    ob_focus_fallback = 1
     
 ############################################################################
 ### Window placement algorithms, choose one of these and ebind it to the ###
diff --git a/scripts/focus.py b/scripts/focus.py
new file mode 100644 (file)
index 0000000..084faeb
--- /dev/null
@@ -0,0 +1,86 @@
+###########################################################################
+###          Functions for helping out with your window focus.          ###
+###########################################################################
+
+ob_focus_raise = 1
+ob_focus_fallback = 0
+ob_focus_stack = []
+
+def ob_focused(data):
+    global ob_focus_raise
+    global ob_focus_fallback
+    global ob_focus_stack
+    if data.client:
+        window = data.client.window()
+        # add/move to front the stack
+        if window in ob_focus_stack:
+            ob_focus_stack.remove(window)
+        ob_focus_stack.insert(0, window)
+    elif ob_focus_fallback:
+        # pass around focus
+        desktop = openbox.screen(data.screen).desktop()
+        l = len(ob_focus_stack)
+        i = 0
+        while i < l:
+            w = ob_focus_stack[i]
+            client = openbox.findClient(w)
+            if not client: # window is gone, remove it
+                ob_focus_stack.pop(i)
+                l = l - 1
+            elif client.desktop() == desktop and \
+                     client.normal() and client.focus():
+                break
+            else:
+                i = i + 1
+
+ebind(EventFocus, ob_focused)
+
+def focus_next(data, num=1, forward=1):
+    """Focus the next (or previous, with forward=0) window in a linear
+       order."""
+    screen = openbox.screen(data.screen)
+    count = screen.clientCount()
+
+    if not count: return # no clients
+    
+    target = 0
+    if data.client:
+        client_win = data.client.window()
+        found = 0
+        r = range(count)
+        if not forward:
+            r.reverse()
+        for i in r:
+            if found:
+                target = i
+                break
+            elif screen.client(i).window() == client_win:
+                found = 1
+        if not found: # wraparound
+            if forward: target = 0
+            else: target = count - 1
+
+    t = target
+    curdesk = screen.desktop()
+    while 1:
+        client = screen.client(t)
+        if client.normal() and \
+               (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
+               and client.focus():
+            if ob_focus_raise:
+                screen.raiseWindow(client)
+            return
+        if forward:
+            t += 1
+            if t == count: t = 0
+        else:
+            t -= 1
+            if t < 0: t = count - 1
+        if t == target: return # nothing to focus
+
+def focus_prev(data, num=1):
+    """Focus the previous window in a linear order."""
+    focus_next(data, num, forward=0)
+
+
+print "Loaded focus.py"
index 6436140db239210613b5f299a450b4062754bae9..edee736e32f6a10c0ef5feaff1029774414d6500 100644 (file)
@@ -150,6 +150,7 @@ Openbox::Openbox(int argc, char **argv)
   python_exec(SCRIPTDIR"/config.py"); // load openbox config values
   // run all of the python scripts
   python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks
+  python_exec(SCRIPTDIR"/focus.py"); // focus helpers
   // run the user's script or the system defaults if that fails
   if (!python_exec(_scriptfilepath.c_str()))
     python_exec(SCRIPTDIR"/defaults.py"); // system default bahaviors
index ea88e12a42a2a542b85bd5348323a633f662e604..91e5031fca5419e47fcd6d42db61db3e0185c6fb 100644 (file)
@@ -910,6 +910,7 @@ EventNewWindow = _openbox.EventNewWindow
 EventCloseWindow = _openbox.EventCloseWindow
 EventStartup = _openbox.EventStartup
 EventShutdown = _openbox.EventShutdown
+EventKey = _openbox.EventKey
 EventFocus = _openbox.EventFocus
 EventBell = _openbox.EventBell
 NUM_EVENTS = _openbox.NUM_EVENTS
@@ -1026,6 +1027,9 @@ class KeyData(_object):
     __swig_setmethods__["key"] = _openbox.KeyData_key_set
     __swig_getmethods__["key"] = _openbox.KeyData_key_get
     if _newclass:key = property(_openbox.KeyData_key_get,_openbox.KeyData_key_set)
+    __swig_setmethods__["action"] = _openbox.KeyData_action_set
+    __swig_getmethods__["action"] = _openbox.KeyData_action_get
+    if _newclass:action = property(_openbox.KeyData_action_get,_openbox.KeyData_action_set)
     def __init__(self,*args):
         self.this = apply(_openbox.new_KeyData,args)
         self.thisown = 1
index 43b0e95ef728e53b3d312b694067c806bd3ab79f..67cf06d1cb91895c78430328c919c37d7add1d7d 100644 (file)
@@ -1008,7 +1008,7 @@ static PyObject *_wrap_Display_screenInfo(PyObject *self, PyObject *args) {
     
     if(!PyArg_ParseTuple(args,(char *)"Oi:Display_screenInfo",&obj0,&arg2)) goto fail;
     if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Display,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
-    result = (otk::ScreenInfo *)(arg1)->screenInfo(arg2);
+    result = (otk::ScreenInfo *)((otk::Display const *)arg1)->screenInfo(arg2);
     
     resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__ScreenInfo, 0);
     return resultobj;
@@ -1029,7 +1029,7 @@ static PyObject *_wrap_Display_findScreen(PyObject *self, PyObject *args) {
     if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Display,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
     arg2 = (Window) PyInt_AsLong(obj1);
     if (PyErr_Occurred()) SWIG_fail;
-    result = (otk::ScreenInfo *)(arg1)->findScreen(arg2);
+    result = (otk::ScreenInfo *)((otk::Display const *)arg1)->findScreen(arg2);
     
     resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__ScreenInfo, 0);
     return resultobj;
@@ -1047,7 +1047,7 @@ static PyObject *_wrap_Display_renderControl(PyObject *self, PyObject *args) {
     
     if(!PyArg_ParseTuple(args,(char *)"Oi:Display_renderControl",&obj0,&arg2)) goto fail;
     if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Display,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
-    result = (otk::RenderControl *)(arg1)->renderControl(arg2);
+    result = (otk::RenderControl *)((otk::Display const *)arg1)->renderControl(arg2);
     
     resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__RenderControl, 0);
     return resultobj;
@@ -11144,6 +11144,40 @@ static PyObject *_wrap_KeyData_key_get(PyObject *self, PyObject *args) {
 }
 
 
+static PyObject *_wrap_KeyData_action_set(PyObject *self, PyObject *args) {
+    PyObject *resultobj;
+    ob::KeyData *arg1 = (ob::KeyData *) 0 ;
+    int arg2 ;
+    PyObject * obj0  = 0 ;
+    
+    if(!PyArg_ParseTuple(args,(char *)"Oi:KeyData_action_set",&obj0,&arg2)) goto fail;
+    if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__KeyData,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
+    if (arg1) (arg1)->action = (ob::EventAction )arg2;
+    
+    Py_INCREF(Py_None); resultobj = Py_None;
+    return resultobj;
+    fail:
+    return NULL;
+}
+
+
+static PyObject *_wrap_KeyData_action_get(PyObject *self, PyObject *args) {
+    PyObject *resultobj;
+    ob::KeyData *arg1 = (ob::KeyData *) 0 ;
+    int result;
+    PyObject * obj0  = 0 ;
+    
+    if(!PyArg_ParseTuple(args,(char *)"O:KeyData_action_get",&obj0)) goto fail;
+    if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__KeyData,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
+    result = (int) ((arg1)->action);
+    
+    resultobj = PyInt_FromLong((long)result);
+    return resultobj;
+    fail:
+    return NULL;
+}
+
+
 static PyObject *_wrap_new_KeyData(PyObject *self, PyObject *args) {
     PyObject *resultobj;
     int arg1 ;
@@ -11781,6 +11815,8 @@ static PyMethodDef SwigMethods[] = {
         { (char *)"KeyData_state_get", _wrap_KeyData_state_get, METH_VARARGS },
         { (char *)"KeyData_key_set", _wrap_KeyData_key_set, METH_VARARGS },
         { (char *)"KeyData_key_get", _wrap_KeyData_key_get, METH_VARARGS },
+        { (char *)"KeyData_action_set", _wrap_KeyData_action_set, METH_VARARGS },
+        { (char *)"KeyData_action_get", _wrap_KeyData_action_get, METH_VARARGS },
         { (char *)"new_KeyData", _wrap_new_KeyData, METH_VARARGS },
         { (char *)"KeyData_swigregister", KeyData_swigregister, METH_VARARGS },
         { (char *)"mbind", _wrap_mbind, METH_VARARGS },
@@ -12053,6 +12089,7 @@ static swig_const_info swig_const_table[] = {
 { SWIG_PY_INT,     (char *)"EventCloseWindow", (long) ob::EventCloseWindow, 0, 0, 0},
 { SWIG_PY_INT,     (char *)"EventStartup", (long) ob::EventStartup, 0, 0, 0},
 { SWIG_PY_INT,     (char *)"EventShutdown", (long) ob::EventShutdown, 0, 0, 0},
+{ SWIG_PY_INT,     (char *)"EventKey", (long) ob::EventKey, 0, 0, 0},
 { SWIG_PY_INT,     (char *)"EventFocus", (long) ob::EventFocus, 0, 0, 0},
 { SWIG_PY_INT,     (char *)"EventBell", (long) ob::EventBell, 0, 0, 0},
 { SWIG_PY_INT,     (char *)"NUM_EVENTS", (long) ob::NUM_EVENTS, 0, 0, 0},
index b97987817bd95869340fa55f2425cdfe26437138..7cec766712a9ac1376f9dff7b38400b3d0e65eb3 100644 (file)
@@ -61,6 +61,7 @@ enum EventAction {
   EventCloseWindow,
   EventStartup,
   EventShutdown,
+  EventKey,
   EventFocus,
   EventBell,
   NUM_EVENTS
@@ -147,6 +148,7 @@ public:
   Time time;
   unsigned int state;
   std::string key;
+  EventAction action; // this is here so that all the Data structs have .action
 
   KeyData(int screen, Client *client, Time time, unsigned int state,
           unsigned int key) {
@@ -156,6 +158,7 @@ public:
     this->state  = state;
     this->key    = XKeysymToString(XKeycodeToKeysym(**otk::display,
                                                     key, 0));
+    this->action = EventKey;
   }
 };
 
This page took 0.031819 seconds and 4 git commands to generate.