diff options
| author | Dana Jansens <danakj@orodu.net> | 2003-01-23 09:01:40 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2003-01-23 09:01:40 +0000 |
| commit | 707f70682abe0dfaadbf76843a0dccb33f0eaeda (patch) | |
| tree | c34a8ef58c0a24afa6018a31dff54a973563db9f /scripts | |
| parent | 9a64438a5a53624e5f5c7c3dbb5123e246693e5e (diff) | |
linear focus cycling
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Makefile.am | 2 | ||||
| -rw-r--r-- | scripts/builtins.py | 30 | ||||
| -rw-r--r-- | scripts/focus.py | 86 |
3 files changed, 89 insertions, 29 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am index cafe6928..ee0287a4 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -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: diff --git a/scripts/builtins.py b/scripts/builtins.py index e3424001..4ae4587b 100644 --- a/scripts/builtins.py +++ b/scripts/builtins.py @@ -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 index 00000000..084faeba --- /dev/null +++ b/scripts/focus.py @@ -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" |
