2014-01-05 00:10:35 +01:00
|
|
|
local type = type
|
|
|
|
local base = require( "wibox.widget.base" )
|
|
|
|
local tooltip = require( "radical.tooltip" )
|
|
|
|
local aw_button = require( "awful.button" )
|
2014-03-12 05:31:50 +01:00
|
|
|
local beautiful = require( "beautiful" )
|
2014-01-04 22:51:50 +01:00
|
|
|
|
|
|
|
-- Define some wibox.widget extensions
|
2016-02-01 06:15:28 +01:00
|
|
|
local function set_tooltip(self, text, args)
|
2014-01-04 22:51:50 +01:00
|
|
|
if not text then return end
|
2016-06-24 06:46:41 +02:00
|
|
|
rawset(self, "_tooltip", tooltip(self,text, args))
|
2014-01-04 22:51:50 +01:00
|
|
|
end
|
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
--- Set a menu for widget "self".
|
|
|
|
-- This function is available for all widgets.
|
|
|
|
-- Any signals can be used as trigger, the common ones are:
|
|
|
|
--
|
|
|
|
-- * "button::press" (default) Left mouse button (normal click_
|
|
|
|
-- * "mouse::enter" When the mouse enter the widget
|
|
|
|
--
|
|
|
|
-- @param self A widget (implicit parameter)
|
|
|
|
-- @param menu A radical menu or a function returning one (for lazy-loading)
|
|
|
|
-- @tparam[opt="button1::pressed"] string event The event trigger for showing
|
|
|
|
-- the menu.
|
|
|
|
-- @tparam[opt=1] button_id The mouse button 1 (1= left, 3=right)
|
2016-03-14 22:52:28 +01:00
|
|
|
-- @tparam[opt=widget] The position mode (see `radical.placement`)
|
|
|
|
local function set_menu(self,menu, event, button_id, mode)
|
2014-01-05 00:10:35 +01:00
|
|
|
if not menu then return end
|
2016-02-21 08:34:05 +01:00
|
|
|
local event = event or "button::pressed"
|
|
|
|
local button_id = button_id or 1
|
2016-03-14 22:52:28 +01:00
|
|
|
mode = mode or "widget"
|
2016-02-21 08:34:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
local function trigger(_, geo)
|
|
|
|
local geo = geo or _
|
2014-01-05 00:10:35 +01:00
|
|
|
local m = menu
|
2016-02-21 08:34:05 +01:00
|
|
|
|
|
|
|
if self._data and self._data.is_menu then
|
|
|
|
geo.parent_menu = self._data
|
|
|
|
end
|
|
|
|
|
2014-01-05 00:10:35 +01:00
|
|
|
if type(menu) == "function" then
|
|
|
|
if self._tmp_menu and self._tmp_menu.visible then
|
|
|
|
self._tmp_menu.visible = false
|
|
|
|
self._tmp_menu = nil
|
|
|
|
return
|
|
|
|
end
|
|
|
|
m = menu(self)
|
|
|
|
end
|
|
|
|
if not m then return end
|
2016-02-01 06:15:28 +01:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
m.parent_geometry = geo
|
2016-03-14 22:52:28 +01:00
|
|
|
m._internal.w:move_by_parent(geo, mode)
|
2016-02-21 08:34:05 +01:00
|
|
|
|
2014-01-05 00:10:35 +01:00
|
|
|
m.visible = not m.visible
|
2016-02-21 08:34:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if event == "button::pressed" then
|
|
|
|
local current,bt = self:buttons(),aw_button({},b,trigger)
|
|
|
|
for k, v in pairs(bt) do
|
|
|
|
current[type(k) == "number" and (#current+1) or k] = v
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self:connect_signal(event, trigger)
|
2014-01-05 00:10:35 +01:00
|
|
|
end
|
2014-01-05 23:35:23 +01:00
|
|
|
self._menu = menu
|
|
|
|
return bt
|
2014-01-05 00:10:35 +01:00
|
|
|
end
|
|
|
|
|
2015-12-29 12:21:13 +01:00
|
|
|
local function get_preferred_size(self, context, width, height)
|
|
|
|
local context = context or 1
|
|
|
|
|
|
|
|
if type(context) == "number" then
|
|
|
|
context = {dpi=beautiful.xresources.get_dpi(context)}
|
|
|
|
elseif not context.dpi then
|
|
|
|
context.dpi = beautiful.xresources.get_dpi(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
return self:fit(context, width or 9999, height or 9999)
|
|
|
|
end
|
|
|
|
|
2014-01-04 22:51:50 +01:00
|
|
|
-- Do some monkey patching to extend all wibox.widget
|
|
|
|
base._make_widget =base.make_widget
|
|
|
|
base.make_widget = function(...)
|
|
|
|
local ret = base._make_widget(...)
|
2016-06-24 06:46:41 +02:00
|
|
|
rawset(ret, "set_tooltip" , set_tooltip)
|
|
|
|
rawset(ret, "set_menu" , set_menu)
|
2015-12-29 12:21:13 +01:00
|
|
|
|
|
|
|
-- Textboxes already have it
|
2016-06-24 06:46:41 +02:00
|
|
|
if not rawget(ret, "get_preferred_size") then
|
|
|
|
rawset(ret, "get_preferred_size", get_preferred_size)
|
2015-12-29 12:21:13 +01:00
|
|
|
end
|
|
|
|
|
2014-01-04 22:51:50 +01:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2015-12-29 12:21:13 +01:00
|
|
|
|
2014-02-23 05:59:03 +01:00
|
|
|
local bar = require( "radical.bar" )
|
2014-02-07 05:47:24 +01:00
|
|
|
|
2013-05-11 21:02:42 +02:00
|
|
|
return {
|
2014-02-23 05:59:03 +01:00
|
|
|
layout = require( "radical.layout" ),
|
|
|
|
object = require( "radical.object" ),
|
|
|
|
base = require( "radical.base" ),
|
|
|
|
radial = require( "radical.radial" ),
|
|
|
|
context = require( "radical.context" ),
|
|
|
|
embed = require( "radical.embed" ),
|
|
|
|
box = require( "radical.box" ),
|
|
|
|
style = require( "radical.style" ),
|
|
|
|
widgets = require( "radical.widgets" ),
|
|
|
|
item = require( "radical.item" ),
|
2014-07-28 01:20:30 +02:00
|
|
|
dock = require( "radical.dock" ),
|
2014-02-23 05:59:03 +01:00
|
|
|
bar = bar,
|
|
|
|
flexbar = bar.flex,
|
|
|
|
tooltip = tooltip
|
2014-01-04 22:51:50 +01:00
|
|
|
}
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|