2009-09-10 12:30:11 +02:00
|
|
|
|
-------------------------------------------------------------------------
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Mouse finder for awful
|
2014-05-20 13:02:39 +02:00
|
|
|
|
--
|
2015-02-20 15:45:53 +01:00
|
|
|
|
-- Find the mouse pointer on the screen.
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- Mouse finder highlights the mouse cursor on the screen
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- To enable this feature, a `awful.mouse.finder` object needs to be bound to a
|
|
|
|
|
-- key:
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- mymousefinder = awful.mouse.finder()
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- Then bind the `find` function a key binding.
|
|
|
|
|
--
|
|
|
|
|
-- Some configuration variable can be set in the theme:
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- The mouse_finder display duration
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- theme.mouse_finder_timeout = 3
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- The animation speed
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- theme.mouse_finder_animate_timeout = 0.05
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- The mouse_finder radius
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- theme.mouse_finder_radius = 20
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- The growth factor
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- theme.mouse_finder_factor = 2
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- The mouse_finder color
|
2015-02-22 22:26:25 +01:00
|
|
|
|
--
|
2014-05-20 13:02:39 +02:00
|
|
|
|
-- theme.mouse_finder_color = "#ff0000"
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--
|
|
|
|
|
-- @author Sébastien Gross <seb•ɱɩɲʋʃ•awesome•ɑƬ•chezwam•ɖɵʈ•org>
|
|
|
|
|
-- @copyright 2009 Sébastien Gross
|
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
|
-- @module awful.mouse.finder
|
|
|
|
|
-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local timer = require("gears.timer")
|
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
local a_placement = require("awful.placement")
|
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
local setmetatable = setmetatable
|
2012-06-14 01:33:27 +02:00
|
|
|
|
|
|
|
|
|
local finder = { mt = {} }
|
2009-09-10 12:30:11 +02:00
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Mouse finder private data.
|
2015-02-22 22:26:39 +01:00
|
|
|
|
-- @table data
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- @field color Background color.
|
|
|
|
|
-- @field hide The hide() function.
|
|
|
|
|
-- @field show The show() function.
|
|
|
|
|
-- @field timer Timer to hide the mouse finder.
|
|
|
|
|
-- @field animate_timer Timer to animate the mouse finder.
|
|
|
|
|
-- @field wibox The mouse finder wibox show on the screen.
|
|
|
|
|
local data = setmetatable({}, { __mode = 'k' })
|
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Place a mouse finder on the screen.
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- @param self A mouse finder object.
|
|
|
|
|
local function place(self)
|
|
|
|
|
a_placement.under_mouse(data[self].wibox)
|
|
|
|
|
a_placement.no_offscreen(data[self].wibox)
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Animate a mouse finder.
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- @param self A mouse finder object.
|
|
|
|
|
local function animate(self)
|
|
|
|
|
local r = data[self].wibox:geometry().width
|
|
|
|
|
-- Check if the object should be grown or shrinked
|
|
|
|
|
-- the minimum radius is -data[self].factor because:
|
|
|
|
|
-- 1. factor is alway negative when shrinking
|
2015-04-24 22:47:06 +02:00
|
|
|
|
-- 2. geometry() does not handle negative values
|
2009-09-10 12:30:11 +02:00
|
|
|
|
if data[self].factor > 0 and r >= data[self].radius
|
|
|
|
|
or data[self].factor < 0 and r <= -data[self].factor then
|
|
|
|
|
data[self].factor = -data[self].factor
|
|
|
|
|
end
|
|
|
|
|
data[self].wibox:geometry({width = r + data[self].factor,
|
|
|
|
|
height = r + data[self].factor })
|
|
|
|
|
-- need -1 to the radius to draw a full circle
|
2015-01-10 20:28:26 +01:00
|
|
|
|
-- FIXME: The rounded_corners() API was removed
|
|
|
|
|
-- a_wibox.rounded_corners(data[self].wibox, (r + data[self].factor)/2 -1)
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- make sure the mouse finder follows the pointer. Uh!
|
|
|
|
|
place(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Show a mouse finder.
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- @param self The mouse finder to show.
|
|
|
|
|
local function show(self)
|
|
|
|
|
-- do nothing if the mouse finder is already shown
|
|
|
|
|
if data[self].wibox.visible then return end
|
|
|
|
|
if not data[self].timer.started then
|
|
|
|
|
data[self].wibox:geometry({width = data[self].radius, height = data[self].radius })
|
2015-01-10 20:28:26 +01:00
|
|
|
|
-- FIXME: The rounded_corners() API was removed
|
|
|
|
|
-- a_wibox.rounded_corners(data[self].wibox, data[self].radius/2 -1)
|
2009-09-10 12:30:11 +02:00
|
|
|
|
data[self].timer:start()
|
|
|
|
|
data[self].animate_timer:start()
|
|
|
|
|
end
|
|
|
|
|
place(self)
|
|
|
|
|
data[self].wibox.visible = true
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Hide a mouse finder.
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- @param self The mouse finder to hide.
|
|
|
|
|
local function hide(self)
|
|
|
|
|
-- do nothing if the mouse finder is already hidden
|
|
|
|
|
if not data[self].wibox.visible then return end
|
|
|
|
|
if data[self].timer.started then
|
|
|
|
|
data[self].timer:stop()
|
|
|
|
|
data[self].animate_timer:stop()
|
|
|
|
|
end
|
|
|
|
|
data[self].wibox.visible = false
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
|
--- Load Default values.
|
2009-09-10 12:30:11 +02:00
|
|
|
|
-- @param self A mouse finder object.
|
|
|
|
|
local function set_defaults(self)
|
|
|
|
|
data[self].wibox.border_width = 0
|
|
|
|
|
data[self].wibox.opacity = beautiful.mouse_finder_opacity or 1
|
2015-12-06 02:26:15 +01:00
|
|
|
|
data[self].wibox:set_bg(beautiful.mouse_finder_color or beautiful.bg_focus or "#ff0000")
|
2009-09-10 12:30:11 +02:00
|
|
|
|
data[self].timeout = beautiful.mouse_finder_timeout or 3
|
|
|
|
|
data[self].animate_timeout = beautiful.mouse_finder_animate_timeout or 0.05
|
|
|
|
|
data[self].radius = beautiful.mouse_finder_radius or 20
|
|
|
|
|
data[self].factor = beautiful.mouse_finder_factor or 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Find the mouse on the screen
|
|
|
|
|
-- @param self A mouse finder object.
|
2012-06-14 01:33:27 +02:00
|
|
|
|
function finder.find(self)
|
2009-09-10 12:30:11 +02:00
|
|
|
|
show(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Create a new mouse finder.
|
|
|
|
|
local function new()
|
|
|
|
|
local self = { }
|
|
|
|
|
-- private data
|
|
|
|
|
data[self] = {
|
|
|
|
|
wibox = wibox({ }),
|
|
|
|
|
show = function() show(self) end,
|
|
|
|
|
hide = function() hide(self) end,
|
|
|
|
|
animate = function() animate(self) end,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- export functions
|
|
|
|
|
self.find = find
|
|
|
|
|
|
|
|
|
|
set_defaults(self)
|
|
|
|
|
|
|
|
|
|
-- setup the timer action only if needed
|
|
|
|
|
data[self].timer = timer { timeout = data[self].timeout }
|
|
|
|
|
data[self].animate_timer = timer { timeout = data[self].animate_timeout }
|
2009-10-09 20:39:55 +02:00
|
|
|
|
data[self].timer:connect_signal("timeout", data[self].hide)
|
|
|
|
|
data[self].animate_timer:connect_signal("timeout", data[self].animate)
|
2009-09-10 12:30:11 +02:00
|
|
|
|
data[self].wibox.ontop = true
|
|
|
|
|
data[self].wibox.visible = false
|
|
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
|
2012-06-14 01:33:27 +02:00
|
|
|
|
function finder.mt:__call(...)
|
|
|
|
|
return new(...)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return setmetatable(finder, finder.mt)
|
2009-09-10 12:30:11 +02:00
|
|
|
|
|
2015-12-12 17:42:33 +01:00
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|