Switch to the new button handling API (instead of awful.button)

This commit is contained in:
Emmanuel Lepage Vallee 2014-02-16 23:55:44 -05:00
parent 5713f00e1b
commit 5cebb6a961
5 changed files with 56 additions and 26 deletions

View File

@ -235,11 +235,14 @@ here is the list:
| append | Append an existing (but unused) item | the item | --- |
###Signals
Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`.
Some others are `item::moved`, `item::swapped`, `item::removed`, `item::appended`
Most item_layout also repackage the default widget signals. It usually does the
same as using the `buttonX` menu attributes, but is preferrable in some scenarios
like when a modifier is applied.
| Name | Description | Arguments |
| ----------------- | ----------------------------- | ------------------------ |
@ -256,8 +259,15 @@ An example of how to use them:
```lua
local menubar = radical.bar{}
menubar:connect_signal("button::press",function(data,item,button)
print("Foo!",item.text,button,data.rowcount)
menubar:connect_signal("button::press",function(data,item,button,mods)
if mods.Control then
print("Foo menu pressed!",item.text,button,data.rowcount)
end
end)
-- Also work on items
menubar:add_item{text="bar"}:connect_signal("button::release",function(d,i,b,m)
print("bar click released!")
end)
```

17
bar.lua
View File

@ -82,7 +82,7 @@ local function setup_buttons(data,item,args)
local buttons = {}
for i=1,10 do
if args["button"..i] then
buttons[#buttons+1] = button({},i,args["button"..i])
buttons[i] = args["button"..i]
end
end
@ -93,18 +93,23 @@ local function setup_buttons(data,item,args)
-- Scrool up
if not buttons[4] then
buttons[#buttons+1] = button({},4,function()
buttons[4] = function()
data:scroll_up()
end)
end
end
-- Scroll down
if not buttons[5] then
buttons[#buttons+1] = button({},5,function()
buttons[5] = function()
data:scroll_down()
end)
end
item.widget:buttons( util.table.join(unpack(buttons)))
end
item:connect_signal("button::press",function(_m,_i,button_id,mods)
if #mods == 0 and buttons[button_id] then
buttons[button_id]()
end
end)
end
local function setup_item(data,item,args)

View File

@ -10,7 +10,6 @@ local beautiful = require( "beautiful" )
local cairo = require( "lgi" ).cairo
local awful = require( "awful" )
local util = require( "awful.util" )
local button = require( "awful.button" )
local layout = require( "radical.layout" )
local checkbox = require( "radical.widgets.checkbox" )
local arrow_style = require( "radical.style.arrow" )
@ -178,39 +177,44 @@ local function setup_buttons(data,item,args)
local buttons = {}
for i=1,10 do
if args["button"..i] then
buttons[#buttons+1] = button({},i,args["button"..i])
buttons[i] = args["button"..i]
end
end
-- Click to open sub_menu
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)
buttons[1] = function() base._execute_sub_menu(data,item) end
end
--Hide on right click
if not buttons[3] then
buttons[#buttons+1] = button({},3,function()
buttons[3] = function()
data.visible = false
if data.parent_geometry and data.parent_geometry.is_menu then
data.parent_geometry.visible = false
end
end)
end
end
-- Scroll up
if not buttons[4] then
buttons[#buttons+1] = button({},4,function()
buttons[4] = function()
data:scroll_up()
end)
end
end
-- Scroll down
if not buttons[5] then
buttons[#buttons+1] = button({},5,function()
buttons[5] = function()
data:scroll_down()
end)
end
item.widget:buttons( util.table.join(unpack(buttons)))
end
item:connect_signal("button::press",function(_m,_i,button_id,mods)
if #mods == 0 and buttons[button_id] then
buttons[button_id]()
end
end)
end
local function setup_item(data,item,args)

View File

@ -43,28 +43,33 @@ local function setup_item(data,item,args)
local buttons = {}
for i=1,10 do
if args["button"..i] then
buttons[#buttons+1] = button({},i,args["button"..i])
buttons[i] = args["button"..i]
end
end
if not buttons[3] then --Hide on right click
buttons[#buttons+1] = button({},3,function()
buttons[3] = function()
data.visible = false
if data.parent_geometry and data.parent_geometry.is_menu then
data.parent_geometry.visible = false
end
end)
end
end
if not buttons[4] then
buttons[#buttons+1] = button({},4,function()
buttons[4] = function()
data:scroll_up()
end)
end
end
if not buttons[5] then
buttons[#buttons+1] = button({},5,function()
buttons[5] = function()
data:scroll_down()
end)
end
item.widget:buttons( util.table.join(unpack(buttons)))
end
item:connect_signal("button::press",function(_m,_i,button_id,mods)
if #mods == 0 and buttons[button_id] then
buttons[button_id]()
end
end)
end
local function new(args)

View File

@ -95,12 +95,15 @@ end
-- Proxy all events to the parent
function module.setup_event(data,item,widget)
local widget = widget or item.widget
-- Setup data signals
widget:connect_signal("button::press",function(_,__,___,id,mod)
local mods_invert = {}
for k,v in ipairs(mod) do
mods_invert[v] = i
end
data:emit_signal("button::press",item,id,mods_invert)
item:emit_signal("button::press",item,id,mods_invert)
end)
widget:connect_signal("button::release",function(_,__,___,id,mod)
local mods_invert = {}
@ -108,12 +111,15 @@ function module.setup_event(data,item,widget)
mods_invert[v] = i
end
data:emit_signal("button::release",item,id,mods_invert)
item:emit_signal("button::release",item,id,mods_invert)
end)
widget:connect_signal("mouse::enter",function(b,t)
data:emit_signal("mouse::enter",item)
item:emit_signal("mouse::enter",item)
end)
widget:connect_signal("mouse::leave",function(b,t)
data:emit_signal("mouse::leave",item)
item:emit_signal("mouse::leave",item)
end)
end