From c0c57eff161b89d489933ed576c6f2fe6414848c Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 5 Feb 2014 22:48:26 -0500 Subject: [PATCH] Partially implement issue #8 --- README.md | 7 ++++--- bar.lua | 10 ++++++---- base.lua | 11 +++++++---- context.lua | 2 +- layout/horizontal.lua | 10 ++++++++-- layout/vertical.lua | 12 +++++++++--- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b584555..58d8487 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,8 @@ Multiple items can have multiple sets of options. | disable_markup | Disable pango markup in items text | boolean | | x | X position (absolute) | number | | y | Y position (absolute) | number | -| sub_menu_on | Show submenu on selection or when clicking | see "sub_menu_on" enum | +| sub_menu_on | Show submenu on selection or when clicking | see "event" enum | +| select_on | The event used to trigger item selection | see "event" enum | ###Item options @@ -229,8 +230,8 @@ here is the list: | remove | Remove the item | the item | --- | -Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`. The exeptions are -`item::moved`, `item::swapped`, `item::removed` +Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`. The +exeptions are `item::moved`, `item::swapped`, `item::removed` ###Beautiful options diff --git a/bar.lua b/bar.lua index 6453db5..073bea7 100644 --- a/bar.lua +++ b/bar.lua @@ -82,7 +82,7 @@ local function setup_buttons(data,item,args) end -- Setup sub_menu - if (item.sub_menu_m or item.sub_menu_f) and data.sub_menu_on >= base.sub_menu_on.BUTTON1 and data.sub_menu_on <= base.sub_menu_on.BUTTON3 then + if (item.sub_menu_m or item.sub_menu_f) and data.sub_menu_on >= base.event.BUTTON1 and data.sub_menu_on <= base.event.BUTTON3 then buttons[data.sub_menu_on] = item.widget:set_menu(item.sub_menu_m or item.sub_menu_f,data.sub_menu_on) end @@ -105,8 +105,10 @@ end local function setup_item(data,item,args) -- Add widgets data._internal.layout:add(item_layout(item,data,args)) - item.widget:connect_signal("mouse::enter", function() item.selected = true end) - item.widget:connect_signal("mouse::leave", function() item.selected = false end) + if data.select_on == base.event.HOVER then + item.widget:connect_signal("mouse::enter", function() item.selected = true end) + item.widget:connect_signal("mouse::leave", function() item.selected = false end) + end -- Setup buttons setup_buttons(data,item,args) @@ -121,7 +123,7 @@ local function new(args) args.internal.setup_item = args.internal.setup_item or setup_item -- args.style = args.style or arrow_style args.item_style = item_style - args.sub_menu_on = base.sub_menu_on.BUTTON1 + args.sub_menu_on = args.sub_menu_on or base.event.BUTTON1 local ret = base(args) ret:connect_signal("clear::menu",function(_,vis) ret._internal.layout:reset() diff --git a/base.lua b/base.lua index 6d11506..a5fb496 100644 --- a/base.lua +++ b/base.lua @@ -17,12 +17,14 @@ local module = { PRETTY = 1, CENTERED = 2, }, - sub_menu_on ={ + event ={ NEVER = 0, BUTTON1 = 1, BUTTON2 = 2, BUTTON3 = 3, SELECTED = 100, + HOVER = 1000, + LEAVE = 1001, }, item_flags = { SELECTED = 1, @@ -101,7 +103,7 @@ local function activateKeyboard(data) end if (key == 'Return') and data._current_item and data._current_item.button1 then - if data.sub_menu_on == module.sub_menu_on.BUTTON1 then + if data.sub_menu_on == module.event.BUTTON1 then execute_sub_menu(data,data._current_item) else data._current_item.button1() @@ -199,7 +201,7 @@ local function add_item(data,args) end data._current_item.selected = false end - if data.sub_menu_on == module.sub_menu_on.SELECTED and data._current_item ~= item then + if data.sub_menu_on == module.event.SELECTED and data._current_item ~= item then execute_sub_menu(data,item) end data.item_style(data,item,{module.item_flags.SELECTED}) @@ -315,7 +317,8 @@ local function new(args) disable_markup = args.disable_markup or false, x = args.x or 0, y = args.y or 0, - sub_menu_on = args.sub_menu_on or module.sub_menu_on.SELECTED, + sub_menu_on = args.sub_menu_on or module.event.SELECTED, + select_on = args.select_on or module.event.HOVER, }, get_map = { is_menu = function() return true end, diff --git a/context.lua b/context.lua index 2571ef3..053f7fc 100644 --- a/context.lua +++ b/context.lua @@ -183,7 +183,7 @@ local function setup_buttons(data,item,args) end -- Click to open sub_menu - if not buttons[1] and data.sub_menu_on == base.sub_menu_on.BUTTON1 then + if not buttons[1] and data.sub_menu_on == base.event.BUTTON1 then buttons[#buttons+1] = button({},1,function() base._execute_sub_menu(data,item) end) end diff --git a/layout/horizontal.lua b/layout/horizontal.lua index bc601b2..6d82d90 100644 --- a/layout/horizontal.lua +++ b/layout/horizontal.lua @@ -6,6 +6,7 @@ local button = require( "awful.button" ) local checkbox = require( "radical.widgets.checkbox" ) local wibox = require( "wibox" ) local item_layout = require("radical.item_layout.icon") +local base = nil local module = {} @@ -51,8 +52,10 @@ end local function setup_event(data,item,args) --Event handling - item.widget:connect_signal("mouse::enter", function() item.selected = true end) - item.widget:connect_signal("mouse::leave", function() item.selected = false end) + if data.select_on == base.event.HOVER then + item.widget:connect_signal("mouse::enter", function() item.selected = true end) + item.widget:connect_signal("mouse::leave", function() item.selected = false end) + end data._internal.layout:add(item) local buttons = {} for i=1,10 do @@ -133,6 +136,9 @@ local function item_fit(data,item,...) end local function new(data) + if not base then + base = require( "radical.base" ) + end local l = wibox.layout.fixed.horizontal() l.fit = function(a1,a2,a3) local result,r2 = wibox.layout.fixed.fit(a1,99999,99999) diff --git a/layout/vertical.lua b/layout/vertical.lua index 899e634..5284299 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -3,7 +3,8 @@ local print,ipairs = print,ipairs local scroll = require( "radical.widgets.scroll" ) local filter = require( "radical.widgets.filter" ) local wibox = require( "wibox" ) -local cairo = require( "lgi" ).cairo +local cairo = require( "lgi" ).cairo +local base = nil local horizontal_item_layout= require( "radical.item_layout.horizontal" ) local module = {} @@ -123,8 +124,10 @@ function module:setup_item(data,item,args) cache_pixmap(item) --Event handling - item.widget:connect_signal("mouse::enter", function() item.selected = true end) - item.widget:connect_signal("mouse::leave", function() item.selected = false end) + if data.select_on == base.event.HOVER then + item.widget:connect_signal("mouse::enter", function() item.selected = true end) + item.widget:connect_signal("mouse::leave", function() item.selected = false end) + end data._internal.layout:add(item) --Be sure to always hide sub menus, even when data.visible is set manually @@ -202,6 +205,9 @@ local function compute_geo(data) end local function new(data) + if not base then + base = require( "radical.base" ) + end local l,real_l = wibox.layout.fixed.vertical(),nil real_l = wibox.layout.fixed.vertical() if data.max_items then