linear focus cycling
This commit is contained in:
parent
9a64438a5a
commit
707f70682a
7 changed files with 137 additions and 32 deletions
|
@ -1,6 +1,6 @@
|
||||||
scriptdir = $(libdir)/openbox/python
|
scriptdir = $(libdir)/openbox/python
|
||||||
MAINTAINERCLEANFILES = Makefile.in
|
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)
|
EXTRA_DIST = $(script_DATA)
|
||||||
|
|
||||||
distclean-local:
|
distclean-local:
|
||||||
|
|
|
@ -287,34 +287,8 @@ def setup_scroll():
|
||||||
def setup_fallback_focus():
|
def setup_fallback_focus():
|
||||||
"""Sets up a focus fallback routine so that when no windows are focused,
|
"""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."""
|
the last window to have focus on the desktop will be focused."""
|
||||||
focus_stack = []
|
global ob_focus_fallback # see focus.py
|
||||||
def focused(data):
|
ob_focus_fallback = 1
|
||||||
#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)
|
|
||||||
|
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
### Window placement algorithms, choose one of these and ebind it to the ###
|
### Window placement algorithms, choose one of these and ebind it to the ###
|
||||||
|
|
86
scripts/focus.py
Normal file
86
scripts/focus.py
Normal file
|
@ -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"
|
|
@ -150,6 +150,7 @@ Openbox::Openbox(int argc, char **argv)
|
||||||
python_exec(SCRIPTDIR"/config.py"); // load openbox config values
|
python_exec(SCRIPTDIR"/config.py"); // load openbox config values
|
||||||
// run all of the python scripts
|
// run all of the python scripts
|
||||||
python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks
|
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
|
// run the user's script or the system defaults if that fails
|
||||||
if (!python_exec(_scriptfilepath.c_str()))
|
if (!python_exec(_scriptfilepath.c_str()))
|
||||||
python_exec(SCRIPTDIR"/defaults.py"); // system default bahaviors
|
python_exec(SCRIPTDIR"/defaults.py"); // system default bahaviors
|
||||||
|
|
|
@ -910,6 +910,7 @@ EventNewWindow = _openbox.EventNewWindow
|
||||||
EventCloseWindow = _openbox.EventCloseWindow
|
EventCloseWindow = _openbox.EventCloseWindow
|
||||||
EventStartup = _openbox.EventStartup
|
EventStartup = _openbox.EventStartup
|
||||||
EventShutdown = _openbox.EventShutdown
|
EventShutdown = _openbox.EventShutdown
|
||||||
|
EventKey = _openbox.EventKey
|
||||||
EventFocus = _openbox.EventFocus
|
EventFocus = _openbox.EventFocus
|
||||||
EventBell = _openbox.EventBell
|
EventBell = _openbox.EventBell
|
||||||
NUM_EVENTS = _openbox.NUM_EVENTS
|
NUM_EVENTS = _openbox.NUM_EVENTS
|
||||||
|
@ -1026,6 +1027,9 @@ class KeyData(_object):
|
||||||
__swig_setmethods__["key"] = _openbox.KeyData_key_set
|
__swig_setmethods__["key"] = _openbox.KeyData_key_set
|
||||||
__swig_getmethods__["key"] = _openbox.KeyData_key_get
|
__swig_getmethods__["key"] = _openbox.KeyData_key_get
|
||||||
if _newclass:key = property(_openbox.KeyData_key_get,_openbox.KeyData_key_set)
|
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):
|
def __init__(self,*args):
|
||||||
self.this = apply(_openbox.new_KeyData,args)
|
self.this = apply(_openbox.new_KeyData,args)
|
||||||
self.thisown = 1
|
self.thisown = 1
|
||||||
|
|
|
@ -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(!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;
|
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);
|
resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__ScreenInfo, 0);
|
||||||
return resultobj;
|
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;
|
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Display,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
|
||||||
arg2 = (Window) PyInt_AsLong(obj1);
|
arg2 = (Window) PyInt_AsLong(obj1);
|
||||||
if (PyErr_Occurred()) SWIG_fail;
|
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);
|
resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__ScreenInfo, 0);
|
||||||
return resultobj;
|
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(!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;
|
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);
|
resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__RenderControl, 0);
|
||||||
return resultobj;
|
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) {
|
static PyObject *_wrap_new_KeyData(PyObject *self, PyObject *args) {
|
||||||
PyObject *resultobj;
|
PyObject *resultobj;
|
||||||
int arg1 ;
|
int arg1 ;
|
||||||
|
@ -11781,6 +11815,8 @@ static PyMethodDef SwigMethods[] = {
|
||||||
{ (char *)"KeyData_state_get", _wrap_KeyData_state_get, METH_VARARGS },
|
{ (char *)"KeyData_state_get", _wrap_KeyData_state_get, METH_VARARGS },
|
||||||
{ (char *)"KeyData_key_set", _wrap_KeyData_key_set, METH_VARARGS },
|
{ (char *)"KeyData_key_set", _wrap_KeyData_key_set, METH_VARARGS },
|
||||||
{ (char *)"KeyData_key_get", _wrap_KeyData_key_get, 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 *)"new_KeyData", _wrap_new_KeyData, METH_VARARGS },
|
||||||
{ (char *)"KeyData_swigregister", KeyData_swigregister, METH_VARARGS },
|
{ (char *)"KeyData_swigregister", KeyData_swigregister, METH_VARARGS },
|
||||||
{ (char *)"mbind", _wrap_mbind, 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 *)"EventCloseWindow", (long) ob::EventCloseWindow, 0, 0, 0},
|
||||||
{ SWIG_PY_INT, (char *)"EventStartup", (long) ob::EventStartup, 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 *)"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 *)"EventFocus", (long) ob::EventFocus, 0, 0, 0},
|
||||||
{ SWIG_PY_INT, (char *)"EventBell", (long) ob::EventBell, 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},
|
{ SWIG_PY_INT, (char *)"NUM_EVENTS", (long) ob::NUM_EVENTS, 0, 0, 0},
|
||||||
|
|
|
@ -61,6 +61,7 @@ enum EventAction {
|
||||||
EventCloseWindow,
|
EventCloseWindow,
|
||||||
EventStartup,
|
EventStartup,
|
||||||
EventShutdown,
|
EventShutdown,
|
||||||
|
EventKey,
|
||||||
EventFocus,
|
EventFocus,
|
||||||
EventBell,
|
EventBell,
|
||||||
NUM_EVENTS
|
NUM_EVENTS
|
||||||
|
@ -147,6 +148,7 @@ public:
|
||||||
Time time;
|
Time time;
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
std::string key;
|
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,
|
KeyData(int screen, Client *client, Time time, unsigned int state,
|
||||||
unsigned int key) {
|
unsigned int key) {
|
||||||
|
@ -156,6 +158,7 @@ public:
|
||||||
this->state = state;
|
this->state = state;
|
||||||
this->key = XKeysymToString(XKeycodeToKeysym(**otk::display,
|
this->key = XKeysymToString(XKeycodeToKeysym(**otk::display,
|
||||||
key, 0));
|
key, 0));
|
||||||
|
this->action = EventKey;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue