2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 12:44:21 +02:00
|
|
|
--- Magnifier layout module for awful
|
|
|
|
--
|
2008-11-25 17:01:06 +01:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
2016-12-10 02:24:22 +01:00
|
|
|
-- @module awful.layout
|
2008-11-25 17:01:06 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local ipairs = ipairs
|
|
|
|
local math = math
|
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
client = client,
|
2014-10-23 01:30:19 +02:00
|
|
|
screen = screen,
|
|
|
|
mouse = mouse,
|
|
|
|
mousegrabber = mousegrabber
|
2008-11-25 17:01:06 +01:00
|
|
|
}
|
|
|
|
|
2016-08-14 07:34:43 +02:00
|
|
|
--- The magnifier layout layoutbox icon.
|
|
|
|
-- @beautiful beautiful.layout_magnifier
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
local magnifier = {}
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2014-10-23 01:30:19 +02:00
|
|
|
function magnifier.mouse_resize_handler(c, corner, x, y)
|
|
|
|
capi.mouse.coords({ x = x, y = y })
|
|
|
|
|
2016-09-11 08:08:26 +02:00
|
|
|
local wa = c.screen.workarea
|
2014-10-23 01:30:19 +02:00
|
|
|
local center_x = wa.x + wa.width / 2
|
|
|
|
local center_y = wa.y + wa.height / 2
|
|
|
|
local maxdist_pow = (wa.width^2 + wa.height^2) / 4
|
|
|
|
|
2015-07-13 20:52:16 +02:00
|
|
|
local prev_coords = {}
|
2014-10-23 01:30:19 +02:00
|
|
|
capi.mousegrabber.run(function (_mouse)
|
2016-04-28 01:48:03 +02:00
|
|
|
if not c.valid then return false end
|
|
|
|
|
2016-02-07 15:24:08 +01:00
|
|
|
for _, v in ipairs(_mouse.buttons) do
|
2014-10-23 01:30:19 +02:00
|
|
|
if v then
|
2015-07-13 20:52:16 +02:00
|
|
|
prev_coords = { x =_mouse.x, y = _mouse.y }
|
2014-10-23 01:30:19 +02:00
|
|
|
local dx = center_x - _mouse.x
|
|
|
|
local dy = center_y - _mouse.y
|
|
|
|
local dist = dx^2 + dy^2
|
|
|
|
|
|
|
|
-- New master width factor
|
|
|
|
local mwfact = dist / maxdist_pow
|
2016-04-11 06:30:05 +02:00
|
|
|
c.screen.selected_tag.master_width_factor
|
|
|
|
= math.min(math.max(0.01, mwfact), 0.99)
|
2014-10-23 01:30:19 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2015-07-13 20:52:16 +02:00
|
|
|
return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y
|
2014-10-23 01:30:19 +02:00
|
|
|
end, corner .. "_corner")
|
|
|
|
end
|
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
function magnifier.arrange(p)
|
2009-09-28 14:41:54 +02:00
|
|
|
-- Fullscreen?
|
2009-02-24 21:50:46 +01:00
|
|
|
local area = p.workarea
|
|
|
|
local cls = p.clients
|
2014-10-13 21:07:31 +02:00
|
|
|
local focus = p.focus or capi.client.focus
|
2016-04-05 09:02:00 +02:00
|
|
|
local t = p.tag or capi.screen[p.screen].selected_tag
|
2016-04-11 06:30:05 +02:00
|
|
|
local mwfact = t.master_width_factor
|
2009-03-13 22:23:35 +01:00
|
|
|
local fidx
|
2009-03-10 07:56:48 +01:00
|
|
|
|
|
|
|
-- Check that the focused window is on the right screen
|
2009-03-13 22:23:35 +01:00
|
|
|
if focus and focus.screen ~= p.screen then focus = nil end
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2016-09-23 09:52:46 +02:00
|
|
|
-- If no window is focused or focused window is not tiled, take the first tiled one.
|
|
|
|
if (not focus or focus.floating) and #cls > 0 then
|
2009-09-28 14:41:54 +02:00
|
|
|
focus = cls[1]
|
|
|
|
fidx = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Abort if no clients are present
|
2009-08-31 10:32:53 +02:00
|
|
|
if not focus then return end
|
|
|
|
|
2008-11-25 17:01:06 +01:00
|
|
|
local geometry = {}
|
2009-03-10 07:56:48 +01:00
|
|
|
if #cls > 1 then
|
2008-11-25 17:01:06 +01:00
|
|
|
geometry.width = area.width * math.sqrt(mwfact)
|
|
|
|
geometry.height = area.height * math.sqrt(mwfact)
|
|
|
|
geometry.x = area.x + (area.width - geometry.width) / 2
|
|
|
|
geometry.y = area.y + (area.height - geometry.height) /2
|
|
|
|
else
|
|
|
|
geometry.x = area.x
|
|
|
|
geometry.y = area.y
|
2008-12-12 00:01:43 +01:00
|
|
|
geometry.width = area.width
|
|
|
|
geometry.height = area.height
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
2010-05-28 19:43:46 +02:00
|
|
|
|
|
|
|
local g = {
|
|
|
|
x = geometry.x,
|
|
|
|
y = geometry.y,
|
2015-02-15 17:25:11 +01:00
|
|
|
width = geometry.width,
|
|
|
|
height = geometry.height
|
2010-05-28 19:43:46 +02:00
|
|
|
}
|
2015-02-15 17:25:11 +01:00
|
|
|
p.geometries[focus] = g
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2009-03-10 07:56:48 +01:00
|
|
|
if #cls > 1 then
|
2008-11-25 17:01:06 +01:00
|
|
|
geometry.x = area.x
|
|
|
|
geometry.y = area.y
|
|
|
|
geometry.height = area.height / (#cls - 1)
|
|
|
|
geometry.width = area.width
|
|
|
|
|
2014-03-14 22:30:51 +01:00
|
|
|
-- We don't know the focus window index. Try to find it.
|
2009-03-10 07:56:48 +01:00
|
|
|
if not fidx then
|
|
|
|
for k, c in ipairs(cls) do
|
|
|
|
if c == focus then
|
|
|
|
fidx = k
|
|
|
|
break
|
|
|
|
end
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
end
|
2009-01-21 13:45:39 +01:00
|
|
|
|
|
|
|
-- First move clients that are before focused client.
|
|
|
|
for k = fidx + 1, #cls do
|
2015-02-15 17:25:11 +01:00
|
|
|
p.geometries[cls[k]] = {
|
|
|
|
x = geometry.x,
|
|
|
|
y = geometry.y,
|
|
|
|
width = geometry.width,
|
|
|
|
height = geometry.height
|
|
|
|
}
|
2009-01-21 13:45:39 +01:00
|
|
|
geometry.y = geometry.y + geometry.height
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Then move clients that are after focused client.
|
|
|
|
-- So the next focused window will be the one at the top of the screen.
|
|
|
|
for k = 1, fidx - 1 do
|
2016-02-07 15:24:08 +01:00
|
|
|
p.geometries[cls[k]] = {
|
2010-05-28 19:43:46 +02:00
|
|
|
x = geometry.x,
|
|
|
|
y = geometry.y,
|
2015-02-15 17:25:11 +01:00
|
|
|
width = geometry.width,
|
|
|
|
height = geometry.height
|
2010-05-28 19:43:46 +02:00
|
|
|
}
|
2009-01-21 13:45:39 +01:00
|
|
|
geometry.y = geometry.y + geometry.height
|
|
|
|
end
|
2008-11-25 17:01:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-10 02:24:22 +01:00
|
|
|
--- The magnifier layout.
|
|
|
|
-- @clientlayout awful.layout.suit.magnifier
|
|
|
|
|
2012-06-14 02:45:17 +02:00
|
|
|
magnifier.name = "magnifier"
|
|
|
|
|
|
|
|
return magnifier
|
2015-12-12 17:42:33 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|