Skip to content

Instantly share code, notes, and snippets.

@Tosainu
Last active November 20, 2016 14:24
Show Gist options
  • Save Tosainu/f1a3d486e0ef92fad01020a81e47769e to your computer and use it in GitHub Desktop.
Save Tosainu/f1a3d486e0ef92fad01020a81e47769e to your computer and use it in GitHub Desktop.

awesome-sushiwidget

Imgur

Installation

  1. Clone this repositry:

    git clone https://gist.github.com/f1a3d486e0ef92fad01020a81e47769e.git ~/.config/awesome/sushiwidget
  2. Download sushi image

    wget -O sushi.png https://github.com/twitter/twemoji/raw/gh-pages/72x72/1f363.png
  3. Create new wibox and insert sushiwidget!

    local sushiwidget = require('sushiwidget/sushiwidget')
    local sushi = sushiwidget({
      image = awful.util.getdir('config') .. '/sushi.png'
    })
    
    local sushiwibox = {}
    
    for s = 1, screen.count() do
      local sushilayout = wibox.layout.fixed.horizontal()
      sushilayout:add(sushi)
    
      sushiwibox[s] = awful.wibox({ position = 'bottom', height = 36, screen = s })
      sushiwibox[s]:set_widget(sushilayout)
    end

License

MIT

local awful = require("awful")
local base = require("wibox.widget.base")
local surface = require("gears.surface")
local sushiwidget = { mt = {} }
function sushiwidget:draw(wibox, cr, width, height)
if not self._image then return end
if width == 0 or height == 0 then return end
local image_width = self._image:get_height()
local ratio = height / image_width
cr:save()
cr:scale(ratio, ratio)
for i = 0, math.floor(width / ratio) + self._loop_width, self._loop_width do
cr:set_source_surface(self._image, i + self._counter, 0)
cr:paint()
end
cr:restore()
end
function sushiwidget:fit(width, height)
local size = math.max(width, height)
return size, size
end
function sushiwidget.new(args)
local args = args or {}
local widget = base.make_widget()
widget.draw = sushiwidget.draw
widget.fit = sushiwidget.fit
widget._counter = 0
widget._image = surface.load(args.image)
widget._loop_width = widget._image.width * 3
local timer = timer({ timeout = args.timeout or 0.1 })
timer:connect_signal("timeout", function()
widget._counter = widget._counter - 4
if widget._counter <= -widget._loop_width then
widget._counter = 0
end
widget:emit_signal("widget::updated")
end)
timer:start()
return widget
end
function sushiwidget.mt:__call(...)
return sushiwidget.new(...)
end
return setmetatable(sushiwidget, sushiwidget.mt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment