]> git.madduck.net Git - etc/awesome.git/blobdiff - layout/centerwork.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

widget.calendar reimplemented and renamed to widget.cal; util.quake: simpler geometri...
[etc/awesome.git] / layout / centerwork.lua
index cb8370933b660ae496cf562780f7c477f871f4f4..2b38a69f0378ff5e095e45266b0d1fd4183a49c1 100644 (file)
@@ -1,6 +1,7 @@
 --[[
 
      Licensed under GNU General Public License v2
+      * (c) 2018,      Eugene Pakhomov
       * (c) 2016,      Henrik Antonsson
       * (c) 2015,      Joerg Jaspert
       * (c) 2014,      projektile
@@ -9,7 +10,7 @@
 
 --]]
 
-local floor, max, screen = math.floor, math.max, screen
+local floor, max, mouse, mousegrabber, screen = math.floor, math.max, mouse, mousegrabber, screen
 
 local centerwork = {
     name       = "centerwork",
@@ -124,6 +125,56 @@ local function arrange(p, layout)
     end
 end
 
+local function mouse_resize_handler(c, corner, x, y, orientation)
+    local wa     = c.screen.workarea
+    local mwfact = c.screen.selected_tag.master_width_factor
+    local g      = c:geometry()
+    local offset = 0
+    local cursor = "cross"
+
+    local corner_coords
+
+    if orientation == 'vertical' then
+        if g.height + 15 >= wa.height then
+            offset = g.height * .5
+            cursor = "sb_h_double_arrow"
+        elseif not (g.y + g.height + 15 > wa.y + wa.height) then
+            offset = g.height
+        end
+        corner_coords = { x = wa.x + wa.width * (1 - mwfact) / 2, y = g.y + offset }
+    else
+        if g.width + 15 >= wa.width then
+            offset = g.width * .5
+            cursor = "sb_v_double_arrow"
+        elseif not (g.x + g.width + 15 > wa.x + wa.width) then
+            offset = g.width
+        end
+        corner_coords = { y = wa.y + wa.height * (1 - mwfact) / 2, x = g.x + offset }
+    end
+
+    mouse.coords(corner_coords)
+
+    local prev_coords = {}
+
+    mousegrabber.run(function(_mouse)
+        if not c.valid then return false end
+        for _, v in ipairs(_mouse.buttons) do
+            if v then
+                prev_coords = { x = _mouse.x, y = _mouse.y }
+                local new_mwfact
+                if orientation == 'vertical' then
+                    new_mwfact = 1 - (_mouse.x - wa.x) / wa.width * 2
+                else
+                    new_mwfact = 1 - (_mouse.y - wa.y) / wa.height * 2
+                end
+                c.screen.selected_tag.master_width_factor = math.min(math.max(new_mwfact, 0.01), 0.99)
+                return true
+            end
+        end
+        return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y
+    end, cursor)
+end
+
 function centerwork.arrange(p)
     return arrange(p, centerwork)
 end
@@ -132,4 +183,12 @@ function centerwork.horizontal.arrange(p)
     return arrange(p, centerwork.horizontal)
 end
 
+function centerwork.mouse_resize_handler(c, corner, x, y)
+    return mouse_resize_handler(c, corner, x, y, 'vertical')
+end
+
+function centerwork.horizontal.mouse_resize_handler(c, corner, x, y)
+    return mouse_resize_handler(c, corner, x, y, 'horizontal')
+end
+
 return centerwork