Skip to content

Instantly share code, notes, and snippets.

@qsorix
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qsorix/92269d2ea5bf8f205e97 to your computer and use it in GitHub Desktop.
Save qsorix/92269d2ea5bf8f205e97 to your computer and use it in GitHub Desktop.
-- here's the function used to actually drag & reorder tags
local function tag_drag(t)
local dr = mywibox[1]._drawable
mousegrabber.run(function (_mouse)
for k, v in ipairs(_mouse.buttons) do
if v then
local x = _mouse.x
local y = _mouse.y
local widgets = dr:find_widgets(x,y)
local target_tag = widgets[1].widget.tag
if target_tag and t ~= target_tag then
local idx = awful.tag.getidx(target_tag)
awful.tag.move(idx, t)
end
return true
end
end
return false
end, "fleur")
end
-- and to use it, simply bind it to some buttons
mytaglist.buttons = awful.util.table.join(
awful.button({ }, 1, function(t) awful.tag.viewonly(t); tag_drag(t) end),
-- .. and so on
-- copy & paste from original sources. the only change is remembering which tag corresponds to each widget
-- this needs to be passed as a parameter when creating the tag list
local function taglist_update(w, buttons, label, data, objects)
print("update, we're home")
-- update the widgets, creating them if needed
w:reset()
for i, o in ipairs(objects) do
local cache = data[o]
local ib, tb, bgb, m, l
if cache then
ib = cache.ib
tb = cache.tb
bgb = cache.bgb
m = cache.m
else
ib = wibox.widget.imagebox()
tb = wibox.widget.textbox()
bgb = wibox.widget.background()
m = wibox.layout.margin(tb, 4, 4)
l = wibox.layout.fixed.horizontal()
-- All of this is added in a fixed widget
l:fill_space(true)
l:add(ib)
l:add(m)
-- remeber for which tag this widget is created
tb.tag = o
-- And all of this gets a background
bgb:set_widget(l)
bgb:buttons(common.create_buttons(buttons, o))
data[o] = {
ib = ib,
tb = tb,
bgb = bgb,
m = m
}
end
local text, bg, bg_image, icon = label(o)
-- The text might be invalid, so use pcall
if not pcall(tb.set_markup, tb, text) then
tb:set_markup("<i>&lt;Invalid text&gt;</i>")
end
bgb:set_bg(bg)
if type(bg_image) == "function" then
bg_image = bg_image(tb,o,m,objects,i)
end
bgb:set_bgimage(bg_image)
ib:set_image(icon)
w:add(bgb)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment