From d8e220a7bb05ffa0f66f93d95697283d48e18b29 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 21 Mar 2014 23:20:50 -0400 Subject: [PATCH] Fix bugs with sub menu, embed menu and scrolling --- base.lua | 8 ++++++ embed.lua | 28 ++++++++++++------ impl/taglist/init.lua | 1 - impl/taglist/tracker.lua | 62 ++++++++++++++++++++++++++++++++++++++++ item/init.lua | 21 ++++++++------ 5 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 impl/taglist/tracker.lua diff --git a/base.lua b/base.lua index b9fcb74..bf8a4dd 100644 --- a/base.lua +++ b/base.lua @@ -505,6 +505,10 @@ local function new(args) function data:scroll_up() if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1) > 1 then + local current_item = data._current_item + if current_item then + current_item.selected = false + end data._start_at = (data._start_at or 1) - 1 internal.items[data._start_at][1]._hidden = false data:emit_signal("_hidden::changed",internal.items[data._start_at][1]) @@ -516,6 +520,10 @@ local function new(args) function data:scroll_down() if data.max_items ~= nil and data.rowcount >= data.max_items and (data._start_at or 1)+data.max_items <= data.rowcount then + local current_item = data._current_item + if current_item then + current_item.selected = false + end data._start_at = (data._start_at or 1) + 1 internal.items[data._start_at-1][1]._hidden = true data:emit_signal("_hidden::changed",internal.items[data._start_at-1][1]) diff --git a/embed.lua b/embed.lua index 121578d..03c142b 100644 --- a/embed.lua +++ b/embed.lua @@ -26,9 +26,9 @@ local function setup_drawable(data) data.set_visible = function(_,v) if data._embeded_parent then data._embeded_parent.visible = v end end -- Enumate geometry --BUG this is fake, but better than nothing - data.get_width = function() return data._embeded_parent and (data._embeded_parent.width + (internal.current_width or 0))end - data.get_y = function() return data._embeded_parent and (data._embeded_parent.y + (internal.current_y or 0)) end - data.get_x = function() return data._embeded_parent and (data._embeded_parent.x + (internal.current_x or 0)) end + data.get_width = function() return data._embeded_parent and (data._embeded_parent.width --[[+ (internal.current_width or 0)]])end + data.get_y = function() return data._embeded_parent and (data._embeded_parent.y--[[ + (internal.current_y or 0)]]) end + data.get_x = function() return data._embeded_parent and (data._embeded_parent.x--[[ + (internal.current_x or 0)]]) end if not data.layout then data.layout = layout.vertical end @@ -36,9 +36,19 @@ local function setup_drawable(data) data.width,data.height = data._internal.layout:fit() data.margins={left=0,right=0,bottom=0,top=0} internal.layout:connect_signal("mouse::enter",function(_,geo) - internal.current_x = geo.x - internal.current_y = geo.y - internal.current_width = geo.width +-- internal.current_x = geo.x +-- internal.current_y = geo.y +-- internal.current_width = geo.width + if data._embeded_parent._current_item then + data._embeded_parent._current_item.state[base.item_flags.SELECTED] = nil + data._embeded_parent._current_item.selected = false + end + end) + internal.layout:connect_signal("mouse::leave",function(_,geo) + if data._current_item then + data._current_item.selected = false + data._current_item.state[base.item_flags.SELECTED] = nil + end end) end @@ -76,9 +86,9 @@ local function setup_item(data,item,args) end end) --- item.widget:connect_signal("mouse::enter",function(_,geo) --- item._internal.tmp_y --- end) + item.widget:connect_signal("mouse::enter",function(_,geo) + item.y = geo.y + end) end local function new(args) diff --git a/impl/taglist/init.lua b/impl/taglist/init.lua index 51d9c05..32c0400 100644 --- a/impl/taglist/init.lua +++ b/impl/taglist/init.lua @@ -217,7 +217,6 @@ end capi.tag.connect_signal("property::selected" , select) capi.tag.connect_signal("property::index2",function(t,i) - print("FOO",t,i) if t then local s = tag.getscreen(t) local item = cache[t] diff --git a/impl/taglist/tracker.lua b/impl/taglist/tracker.lua new file mode 100644 index 0000000..6a2fcf6 --- /dev/null +++ b/impl/taglist/tracker.lua @@ -0,0 +1,62 @@ +-- This module try to track tags relative index +-- It will emit signals the widget can rely on +local capi = {tag=tag} +local tag = require( "awful.tag" ) +local object = require( "radical.object" ) + +local cache = {} +local init = false +local screen_cache = setmetatable({}, { __mode = 'k' })--TODO this suck + +local function reload(t,s) + local s = s or tag.getscreen(t) or screen_cache[t] + local tracker = cache[s] + + if not tracker then return end + + local old_tags = tracker._internal.old_tags or {} + + local new_tags = tag.gettags(s) + for k,v in ipairs(new_tags) do + if v ~= old_tags[k] then + v:emit_signal("property::index2",k) + screen_cache[v] = s + end + end + tracker._internal.old_tags = new_tags +end + +local function new(s) + if cache[s] then return cache[s] end + + local tracker,private_data = object({ + private_data = { + widget = widget, + selected = false, + }, + autogen_getmap = true, + autogen_setmap = true, + autogen_signals = true, + }) + tracker._internal = {} + + cache[s] = tracker + + if not init then + capi.tag.connect_signal("property::screen" , reload ) + capi.tag.connect_signal("property::activated", reload ) + end + + tracker.reload = function() + reload(nil,s) + end + + return tracker +end + + +capi.tag.add_signal("property::index2") + + +return setmetatable({}, { __call = function(_, ...) return new(...) end }) +-- kate: space-indent on; indent-width 2; replace-tabs on; \ No newline at end of file diff --git a/item/init.lua b/item/init.lua index 6d4c1e2..f35156b 100644 --- a/item/init.lua +++ b/item/init.lua @@ -48,7 +48,6 @@ local module = { } local function load_async(tab,key) - print("here",key) if key == "style" then module.style = require("radical.item.style") return module.style @@ -138,26 +137,30 @@ local function new_item(data,args) -- Setters item.set_selected = function(_,value) private_data.selected = value - if value == false then - data.item_style(item,{}) - return - end + + -- Hide the sub-menu local current_item = data._current_item - if current_item and current_item ~= item then + if current_item and current_item ~= item or not value then current_item.state[module.item_flags.SELECTED] = nil if current_item._tmp_menu then current_item._tmp_menu.visible = false current_item._tmp_menu = nil data._tmp_menu = nil + current_item:emit_signal("state::changed") end - data.item_style(current_item,{}) --- current_item.selected = false end + + -- Unselect item + if value == false then + item.state[module.item_flags.SELECTED] = nil + return + end + + -- Select the new one if data.sub_menu_on == module.event.SELECTED and current_item ~= item then module.execute_sub_menu(data,item) end item.state[module.item_flags.SELECTED] = true - data.item_style(item,{}) data._current_item = item end