2015-03-15 06:16:31 +01:00
|
|
|
local capi = {screen = screen}
|
2014-11-05 05:56:30 +01:00
|
|
|
local math = math
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local beautiful = require( "beautiful" )
|
2014-12-16 06:36:48 +01:00
|
|
|
local glib = require("lgi").GLib
|
2015-02-19 06:17:42 +01:00
|
|
|
local cairo = require( "lgi" ).cairo
|
2014-10-04 08:53:01 +02:00
|
|
|
|
2014-10-16 07:20:41 +02:00
|
|
|
local module = {settings={}}
|
2014-10-04 08:53:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
local rr,rg,rb
|
|
|
|
function module.get_rgb()
|
|
|
|
if not rr then
|
|
|
|
local pat = color(beautiful.fg_normal)
|
|
|
|
local s,r,g,b,a = pat:get_rgba()
|
|
|
|
rr,rg,rb = r,g,b
|
|
|
|
end
|
|
|
|
return rr,rg,rb
|
|
|
|
end
|
|
|
|
|
2015-02-25 02:03:17 +01:00
|
|
|
function module.arrow_path(cr, width, sidesize)
|
|
|
|
cr:rel_move_to( 0 , -width/2 )
|
|
|
|
cr:rel_line_to( width/2 , width/2 )
|
|
|
|
cr:rel_line_to( -sidesize , 0 )
|
|
|
|
cr:rel_line_to( 0 , width/2 )
|
|
|
|
cr:rel_line_to( (-width)+2*sidesize , 0 )
|
|
|
|
cr:rel_line_to( 0 , -width/2 )
|
|
|
|
cr:rel_line_to( -sidesize , 0 )
|
|
|
|
cr:rel_line_to( width/2 , -width/2 )
|
2015-02-19 06:17:42 +01:00
|
|
|
cr:close_path()
|
|
|
|
end
|
|
|
|
|
2015-02-25 02:03:17 +01:00
|
|
|
function module.arrow(width, sidesize, margin, bg_color, fg_color)
|
|
|
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, width+2*margin, width+2*margin)
|
2015-02-19 06:17:42 +01:00
|
|
|
local cr = cairo.Context(img)
|
2015-02-25 02:03:17 +01:00
|
|
|
cr:set_source(color(bg_color))
|
2015-02-19 06:17:42 +01:00
|
|
|
cr:paint()
|
2015-02-25 02:03:17 +01:00
|
|
|
cr:set_source(color(fg_color))
|
|
|
|
cr:set_antialias(cairo.Antialias.NONE)
|
|
|
|
cr:move_to(margin+width/2, margin+width/2)
|
|
|
|
module.arrow_path(cr, width, sidesize)
|
2015-02-19 06:17:42 +01:00
|
|
|
cr:fill()
|
|
|
|
return cairo.Pattern.create_for_surface(img)
|
|
|
|
end
|
|
|
|
|
2014-10-04 23:00:51 +02:00
|
|
|
function module.draw_round_rect(cr,x,y,w,h,radius)
|
|
|
|
cr:save()
|
|
|
|
cr:translate(x,y)
|
|
|
|
cr:move_to(0,radius)
|
|
|
|
cr:arc(radius,radius,radius,math.pi,3*(math.pi/2))
|
|
|
|
cr:arc(w-radius,radius,radius,3*(math.pi/2),math.pi*2)
|
|
|
|
cr:arc(w-radius,h-radius,radius,math.pi*2,math.pi/2)
|
|
|
|
cr:arc(radius,h-radius,radius,math.pi/2,math.pi)
|
|
|
|
cr:close_path()
|
|
|
|
cr:restore()
|
|
|
|
end
|
2014-12-16 06:36:48 +01:00
|
|
|
|
|
|
|
local function refresh_dt(last_sec,last_usec,callback,delay)
|
|
|
|
local tv = glib.TimeVal()
|
|
|
|
glib.get_current_time(tv)
|
|
|
|
local dt = (tv.tv_sec*1000000+tv.tv_usec)-(last_sec*1000000+last_usec)
|
|
|
|
if dt < delay then
|
|
|
|
callback()
|
|
|
|
end
|
|
|
|
return tv.tv_sec,tv.tv_usec
|
|
|
|
end
|
|
|
|
|
|
|
|
function module.double_click(callback,delay)
|
|
|
|
delay = delay or 250000
|
|
|
|
local ds,du = 0,0
|
|
|
|
return function()
|
|
|
|
ds,du = refresh_dt(ds,du,callback,delay)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-15 06:16:31 +01:00
|
|
|
-- Screen order is not always geometrical, sort them
|
|
|
|
local screens,screens_inv
|
|
|
|
function module.get_ordered_screens()
|
|
|
|
if screens then return screens,screens_inv end
|
|
|
|
|
|
|
|
screens = {}
|
|
|
|
for i=1,capi.screen.count() do
|
|
|
|
local geom = capi.screen[i].geometry
|
|
|
|
if #screens == 0 then
|
|
|
|
screens[1] = i
|
|
|
|
elseif geom.x < capi.screen[screens[1]].geometry.x then
|
|
|
|
table.insert(screens,1,i)
|
|
|
|
else
|
|
|
|
for j=#screens,1,-1 do
|
|
|
|
if geom.x > capi.screen[screens[j]].geometry.x then
|
|
|
|
table.insert(screens,j+1,i)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
screens_inv = {}
|
|
|
|
for k,v in ipairs(screens) do
|
|
|
|
screens_inv[v] = k
|
|
|
|
end
|
|
|
|
|
|
|
|
return screens,screens_inv
|
|
|
|
end
|
|
|
|
|
2014-10-04 08:53:01 +02:00
|
|
|
return module
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|