Hi,
attached is a (shitty) patch which removes the need to start a seperate process
to get your really, really, REALLY important xeyes back.
Uli
Who doesn't have his GPG key with him. :(
From 294b8d25f8201ff75444bc4bc5bec904bdf45d8e Mon Sep 17 00:00:00 2001
From: Uli Schlachter <[email protected]>
Date: Mon, 28 Dec 2009 00:20:17 +0100
Subject: [PATCH 1/2] Import obvious.eyes
Who needs a separate process for xeyes anyway? :P
Signed-off-by: Uli Schlachter <[email protected]>
---
eyes/init.lua | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
init.lua | 1 +
2 files changed, 159 insertions(+), 0 deletions(-)
create mode 100644 eyes/init.lua
diff --git a/eyes/init.lua b/eyes/init.lua
new file mode 100644
index 0000000..dfe00b7
--- /dev/null
+++ b/eyes/init.lua
@@ -0,0 +1,158 @@
+-----------------------------------
+-- Author: Uli Schlachter --
+-- Copyright 2009 Uli Schlachter --
+-----------------------------------
+
+local capi = {
+ widget = widget,
+ wibox = wibox,
+ image = image,
+ timer = timer,
+ mouse = mouse
+}
+local math = math
+local setmetatable = setmetatable
+
+module("obvious.eyes")
+
+local function draw_eye_ball(obj, _x, _y, width, height)
+ local mouse = capi.mouse.coords()
+ local ball_size = width * 0.1
+ local imgbox = obj.imgbox
+ local img = obj.imgbox.image
+
+ -- Calculate the distance from the center of the window
+ local dx = mouse.x - obj.x - _x - width / 2
+ local dy = mouse.y - obj.y - _y - height / 2
+
+ local cx
+ local cy
+ if dx == 0 and dy == 0 then
+ -- Mouse in the middle of the wibox
+ cx = 0
+ cy = 0
+ else
+ -- Calculate the angle to the mouse pointer
+ local a = math.atan2(dy, dx)
+
+ -- w and h are the max allowed argument for the eye
+ local w = width / 2 - ball_size
+ local h = height / 2 - ball_size
+
+ -- We have this ellipse:
+ -- x = h * cos(a)
+ -- y = w * cos(a)
+ --
+ -- We want to know (x, y) at the angle "angle" (angle != a), thus:
+ -- tan(angle) = y / x
+ local tan_angle = (w * math.sin(a)) / (h * math.cos(a))
+ local angle = math.atan(tan_angle)
+ cx = w * math.cos(angle)
+ cy = h * math.sin(angle)
+
+ -- Above angle is between 0 and 180 degree, we have to "fix" this
+ if dx < 0 then
+ cx = -cx
+ cy = -cy
+ end
+
+ -- If the distance to the mouse pointer is smaller than the distance to
+ -- the eye's edge...
+ if cx * cx + cy * cy > dx * dx + dy * dy then
+ -- Mouse pointer is inside the eye, use the exact mouse position
instead
+ cx = dx
+ cy = dy
+ end
+ end
+
+ cx = cx + width / 2
+ cy = cy + height / 2
+
+ img:draw_circle(_x + cx, _y + cy, ball_size, ball_size, true, "#000000")
+
+ -- force an update
+ imgbox.image = img
+end
+
+local function update(obj)
+ local width = obj.width
+ local height = obj.height
+ local img = obj.imgbox.image
+ local border = obj.width * 0.1
+ local pad = obj.width * 0.03
+
+ -- Everything gray
+ img:draw_rectangle(0, 0, width, height, true, "gray")
+
+ -- We added 1px of free space on each side in new()
+ local width = width - 2
+ local height = height - 2
+
+ -- Now draw the eye's border
+ img:draw_circle(1 + width / 2, 1 + height / 2, width / 2, height / 2,
true, "#000000")
+
+ local x = border + 1
+ local y = border + 1
+ local width = width - border * 2
+ local height = height - border * 2
+ img:draw_circle(x + width / 2, y + height / 2, width / 2, height / 2,
true, "#ffffff")
+
+ local x = x + pad
+ local y = y + pad
+ local height = height - pad * 2
+ local width = width - pad * 2
+ draw_eye_ball(obj, x, y, width, height)
+end
+
+local function destroy(obj)
+ obj.timer:stop()
+ obj.wibox.screen = nil
+
+ obj.wibox = nil
+ obj.imgbox = nil
+ obj.update = nil
+ obj.destroy = nil
+ obj.timer = nil
+end
+
+local function new(x, y, orig_width, orig_height, screen)
+ -- Draw circle is stupid, 1px space to fix this
+ local width = orig_width + 2
+ local height = orig_height + 2
+
+ local screen = screen or 1
+ local obj = { x = x, y = y, width = width, height = height }
+
+ -- Add a function for getting rid of this again
+ obj.destroy = destroy
+
+ local img = capi.image.argb32(width, height, nil)
+ local imgbox = capi.widget{ type = "imagebox" }
+ imgbox.image = img
+
+ local wibox = capi.wibox{}
+ wibox.widgets = { imgbox }
+ wibox:geometry{ x = x, y = y, width = width, height = height }
+ wibox.screen = screen
+ wibox.ontop = true
+
+ obj.imgbox = imgbox
+ obj.wibox = wibox
+ obj.update = function() update(obj) end
+
+ -- Now set a shape so that the "border" is hidden
+ local img_shape = capi.image.argb32(width, height, nil)
+ img_shape:draw_rectangle(0, 0, width, height, true, "#ffffff")
+ img_shape:draw_circle(1 + orig_width / 2, 1 + orig_height / 2, orig_width
/ 2, orig_height / 2, true, "#000000")
+ wibox.shape_bounding = img_shape
+
+ obj.timer = capi.timer({ timeout = 0.1 })
+ obj.timer:add_signal("timeout", obj.update)
+ obj.timer:start()
+
+ return obj
+end
+
+setmetatable(_M, { __call = function (_, ...) return new(...) end })
+
+-- vim:
filetype=lua:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:encoding=utf-8:textwidth=80
diff --git a/init.lua b/init.lua
index 9d13a61..d73bc66 100644
--- a/init.lua
+++ b/init.lua
@@ -15,5 +15,6 @@ require("obvious.net")
require("obvious.popup_run_prompt")
require("obvious.volume_alsa")
require("obvious.wlan")
+require("obvious.eyes")
module("obvious")
--
1.6.5.7
From 59faad02515f68abcd65b9f6510f71842e74fb78 Mon Sep 17 00:00:00 2001
From: Uli Schlachter <[email protected]>
Date: Mon, 28 Dec 2009 00:21:11 +0100
Subject: [PATCH 2/2] Import (fake-)README
I'd propose to NOT merge this. :P
Not-Signed-off-by: Uli Schlachter <[email protected]>
---
eyes/README | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 eyes/README
diff --git a/eyes/README b/eyes/README
new file mode 100644
index 0000000..822e76f
--- /dev/null
+++ b/eyes/README
@@ -0,0 +1 @@
+ask farhaven :P
--
1.6.5.7