File: wrap_workspace_or_screen.lua

package info (click to toggle)
notion 4.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,656 kB
  • sloc: ansic: 47,365; sh: 2,093; makefile: 594; perl: 270
file content (80 lines) | stat: -rw-r--r-- 3,113 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Authors: Philipp Hartwig <ph@phhart.de>
-- License: MIT, see http://opensource.org/licenses/mit-license.php
-- Last Changed: 2012-09-29
--
--[[

Description: Switch focus in the specified direction, but with the following
difference to the usual ioncore.goto_next function:

* When switching focus down (resp. up) from the bottom (resp. upmost) client,
switch to the next (resp. previous) workspace.

* When switching focus right (resp. left) from the rightmost (resp. leftmost)
client, switch to the next (resp. previous) screen.

Usage: Add bindings for
    wrap_wsscr.goto_next(_sub, 'up', {no_ascend=_})
    wrap_wsscr.goto_next(_sub, 'down', {no_ascend=_})
    wrap_wsscr.goto_next(_sub, 'right')
    wrap_wsscr.goto_next(_sub, 'left')
to the "WTiling" section of cfg_tiling.lua.

If you want support for floating workspaces, add bindings for
    wrap_wsscr.goto_next(_chld, 'up', {no_ascend=_})
    wrap_wsscr.goto_next(_chld, 'down', {no_ascend=_})
    wrap_wsscr.goto_next(_chld, 'right')
    wrap_wsscr.goto_next(_chld, 'left')
to the "WScreen" section of cfg_notioncore.lua.

--]]

wrap_wsscr={}

local function next_ws(screen)
    local cur_index=screen:get_index(screen:mx_current())
    return screen:mx_nth(cur_index+1) or screen:mx_nth(0)
end

local function prev_ws(screen)
    local cur_index=screen:get_index(screen:mx_current())
    return screen:mx_nth(cur_index-1) or screen:mx_nth(screen:mx_count()-1)
end

function wrap_wsscr.goto_next(region, direction, param)
    local workspace=region:manager()
    if not param then param={} end
    param.nowrap=true
    if not ioncore.goto_next(region, direction, param) then
        local function underlying_manager(ws)
            return ws:bottom() or ws
        end
        if direction=='left' then
            local screen=ioncore.goto_prev_screen()
            local reg=ioncore.navi_first(underlying_manager(screen:current()), 'right')
            if reg then reg:goto_focus() end
        elseif direction=='right' then
            local screen=ioncore.goto_next_screen()
            local reg=ioncore.navi_first(underlying_manager(screen:current()), 'left')
            if reg then reg:goto_focus() end
        elseif direction=='up' then
            local screen=workspace:screen_of()
            local ws=underlying_manager(prev_ws(screen))
            --For floating workspaces, ioncore.navi_first only seems to work
            --when the workspace is already displayed. Can someone explain
            --this?
            ws:goto_focus()
            local reg=ioncore.navi_first(ws, 'down', {no_ascend=ws,})
            if reg then reg:goto_focus() end
        elseif direction=='down' then
            local screen=workspace:screen_of()
            local ws=underlying_manager(next_ws(screen))
            --For floating workspaces, ioncore.navi_first only seems to work
            --when the workspace is already displayed. Can someone explain
            --this?
            ws:goto_focus()
            local reg=ioncore.navi_first(ws, 'up', {no_ascend=ws,})
            if reg then reg:goto_focus() end
        end
    end
end