at master 3.3 kB view raw
1local capi = { 2 client = client, 3 mouse = mouse, 4 screen = screen, 5 mousegrabber = mousegrabber, 6} 7local awful = require("awful") 8 9local function mouse_resize_handler(m, c) 10 awful.client.incwfact(0, c) -- needed to fix normalization at start 11 local start = m(capi.mouse.coords()) 12 local x, y = start.x, start.y 13 local wa = m(c.screen.workarea) 14 local idx = awful.client.idx(c) 15 local c_above, c_below 16 local idx_above, idx_below 17 local wfact_above, wfact_below 18 local jump_to = { x = x, y = y } 19 local move_mwfact = false 20 21 do 22 local g = m(c:geometry()) 23 24 local v_border = 0.2 * g.height 25 26 if idx.idx > 1 and y >= g.y and y <= g.y + v_border then 27 -- we are near the top edge of the window 28 c_above = awful.client.next(-1, c) 29 c_below = c 30 jump_to.y = g.y 31 idx_above = idx.idx - 1 32 idx_below = idx.idx 33 elseif idx.idx < idx.num and y >= g.y + g.height - v_border then 34 -- we are near the bottom edge of the window 35 c_above = c 36 c_below = awful.client.next(1, c) 37 idx_above = idx.idx 38 idx_below = idx.idx + 1 39 jump_to.y = g.y + g.height 40 end 41 42 local mw_split = wa.x + wa.width * c.screen.selected_tag.master_width_factor 43 44 if math.abs(mw_split - x) > wa.width / 6 then 45 move_mwfact = false 46 else 47 move_mwfact = true 48 jump_to.x = mw_split 49 end 50 end 51 52 if idx_above then 53 local t = c.screen.selected_tag 54 local data = t.windowfact or {} 55 local colfact = data[idx.col] or {} 56 wfact_above = colfact[idx_above] or 1 57 wfact_below = colfact[idx_below] or 1 58 end 59 60 if idx_above and move_mwfact then 61 cursor = "cross" 62 elseif idx_above then 63 cursor = m({ y = "sb_v_double_arrow", x = "sb_h_double_arrow" }).y 64 elseif move_mwfact then 65 cursor = m({ y = "sb_v_double_arrow", x = "sb_h_double_arrow" }).x 66 else 67 return false 68 end 69 70 capi.mouse.coords(m(jump_to)) 71 72 capi.mousegrabber.run(function(_mouse) 73 if not c.valid then 74 return false 75 end 76 77 local pressed = false 78 for _, v in ipairs(_mouse.buttons) do 79 if v then 80 pressed = true 81 break 82 end 83 end 84 85 _mouse = m(_mouse) 86 87 if pressed then 88 if move_mwfact then 89 c.screen.selected_tag.master_width_factor = math.min(math.max((_mouse.x - wa.x) / wa.width, 0.01), 0.99) 90 end 91 92 if idx_above then 93 local factor_delta = (_mouse.y - jump_to.y) / wa.height 94 95 if factor_delta < 0 then 96 factor_delta = math.max(factor_delta, -(wfact_above - 0.05)) 97 else 98 factor_delta = math.min(factor_delta, wfact_below - 0.05) 99 end 100 101 local t = c.screen.selected_tag 102 local data = t.windowfact or {} 103 local colfact = data[idx.col] or {} 104 colfact[idx_above] = wfact_above + factor_delta 105 colfact[idx_below] = wfact_below - factor_delta 106 awful.client.incwfact(0, c_above) -- just in case 107 end 108 return true 109 else 110 return false 111 end 112 end, cursor) 113 114 return true 115end 116 117awful.layout.suit.tile.mouse_resize_handler = function(c) 118 return mouse_resize_handler(function(x) 119 return x 120 end, c) 121end 122awful.layout.suit.tile.bottom.mouse_resize_handler = function(c) 123 return mouse_resize_handler(function(q) 124 return { x = q.y, y = q.x, width = q.height, height = q.width } 125 end, c) 126end 127 128-- local old_coords = mouse.coords 129 130-- mouse.coords = function(...) 131-- if select(1, ...) and not(select(1, ...).blah) then 132-- print("set mouse!!!") 133-- print(debug.traceback()) 134 135-- end 136-- return old_coords(...) 137-- end