Created
May 17, 2019 21:40
-
-
Save Elv13/3bb509de1e5c3e441aca0cfe48698aae to your computer and use it in GitHub Desktop.
Radical menu system fix for Awesome 4.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/radical/box.lua b/radical/box.lua | |
index 197b5cc..75ff7f7 100644 | |
--- a/radical/box.lua | |
+++ b/radical/box.lua | |
@@ -24,7 +24,7 @@ local function new(args) | |
local s = w.screen | |
w:connect_signal("property::geometry", function() | |
if w.screen ~= s then | |
- w:move_by_parent() | |
+ w:move_next_to() | |
end | |
end) | |
diff --git a/radical/context.lua b/radical/context.lua | |
index 0fc1abe..fb1578d 100644 | |
--- a/radical/context.lua | |
+++ b/radical/context.lua | |
@@ -4,7 +4,7 @@ local wibox = require( "wibox" ) | |
local beautiful = require( "beautiful" ) | |
local layout = require( "radical.layout" ) | |
local arrow_style = require( "radical.style.arrow" ) | |
-local smart_wibox = require( "radical.smart_wibox" ) | |
+local popup = require( "awful.popup" ) | |
local common = require( "radical.common" ) | |
local capi, module = { keygrabber = keygrabber },{} | |
@@ -13,7 +13,7 @@ local function set_visible(i, value) | |
local w, pg = i.w, i.private_data.parent_geometry | |
if value and pg then | |
- w:move_by_parent(pg, "widget") | |
+ w:move_next_to(pg, "widget") | |
end | |
w.visible = value | |
@@ -31,7 +31,7 @@ local function new(args) | |
local data = base(args) | |
data:connect_signal("parent_geometry::changed", function() | |
- args.internal.w:move_by_parent(data.parent_geometry, "widget") | |
+ args.internal.w:move_next_to(data.parent_geometry, "widget") | |
end) | |
local internal = data._internal | |
@@ -43,7 +43,8 @@ local function new(args) | |
internal.margin = wibox.container.margin(internal.layout) | |
-- Init | |
- internal.w = smart_wibox(internal.margin, { | |
+ internal.w = popup { | |
+ widget = internal.margin , | |
visible = false , | |
ontop = true , | |
opacity = data.opacity , | |
@@ -54,7 +55,7 @@ local function new(args) | |
or beautiful.menu_outline_color | |
or beautiful.menu_border_color | |
or beautiful.fg_normal | |
- }) | |
+ } | |
-- Accessors | |
data.get_wibox = function() return internal.w end | |
diff --git a/radical/impl/taglist/init.lua b/radical/impl/taglist/init.lua | |
index e195860..44f3bb8 100644 | |
--- a/radical/impl/taglist/init.lua | |
+++ b/radical/impl/taglist/init.lua | |
@@ -40,8 +40,9 @@ module.buttons = { [1] = function(t) t:view_only() end, | |
[3] = function(t,menu,item,button_id,mod,geo) | |
local m = tag_menu(t) | |
m.parent_geometry = geo | |
+ m._internal.w:move_next_to(geo) | |
m.visible = true | |
- m._internal.w:move_by_parent(geo, "cursor") | |
+ print("\n\nHERE", geo.x, geo.drawable) | |
end, | |
[4] = function(t) awful.tag.viewnext(t.screen) end, | |
[5] = function(t) awful.tag.viewprev(t.screen) end, | |
@@ -299,9 +300,9 @@ local function new(s) | |
create_item(t,capi.screen[s]) | |
end | |
- instances[capi.screen[s]]:connect_signal("button::press",function(m,item,button_id,mod) | |
+ instances[capi.screen[s]]:connect_signal("button::press",function(m,item,button_id,mod,geo) | |
if module.buttons and module.buttons[button_id] then | |
- module.buttons[button_id](item.tag[1],m,item,button_id,mod) | |
+ module.buttons[button_id](item.tag[1],m,item,button_id,mod,geo) | |
end | |
end) | |
@@ -317,6 +318,9 @@ function module.get_positions(s) | |
if not taglist then return end | |
local wb = wiboxes[taglist] | |
+ | |
+ if not wb then return end | |
+ | |
local geo = wb:geometry() | |
local add_x, add_y = geo.x, geo.y | |
diff --git a/radical/impl/tasklist/init.lua b/radical/impl/tasklist/init.lua | |
index 56d5c07..2702c66 100644 | |
--- a/radical/impl/tasklist/init.lua | |
+++ b/radical/impl/tasklist/init.lua | |
@@ -46,7 +46,8 @@ module.buttons = { | |
local m = client_menu() | |
-- menu.parent_geometry = geo | |
m.visible = not m.visible | |
- m._internal.w:move_by_parent(nil, "cursor") | |
+ print("\n\nTASKLIST", geo, geo.x) | |
+ m._internal.w:move_next_to(geo) | |
end, | |
[4] = function(c,menu,item,button_id,mod, geo) | |
client.focus.byidx(1) | |
diff --git a/radical/init.lua b/radical/init.lua | |
index 5296f55..b53bea2 100644 | |
--- a/radical/init.lua | |
+++ b/radical/init.lua | |
@@ -22,7 +22,7 @@ end | |
-- @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) | |
--- @tparam[opt=widget] The position mode (see `radical.placement`) | |
+-- @tparam[opt=widget] The position mode (see `awful.placement.next_to`) | |
local function set_menu(self,menu, event, button_id, mode) | |
if not menu then return end | |
@@ -51,7 +51,7 @@ local function set_menu(self,menu, event, button_id, mode) | |
if not m then return end | |
m.parent_geometry = geo | |
- m._internal.w:move_by_parent(geo, mode) | |
+ m._internal.w:move_next_to(geo, mode) | |
m.visible = not m.visible | |
end | |
diff --git a/radical/layout/grid.lua b/radical/layout/grid.lua | |
index a3608f8..7a2b396 100644 | |
--- a/radical/layout/grid.lua | |
+++ b/radical/layout/grid.lua | |
@@ -43,11 +43,11 @@ end | |
local function new(data) | |
return wibox.layout { | |
- column_count = data.column, | |
- row_count = data.row or (not data.column and 2 or nil), | |
+ forced_num_cols = data.column, | |
+ forced_num_rows = data.row or (not data.column and 2 or nil), | |
item_fit = item_fit, | |
setup_key_hooks = module.setup_key_hooks, | |
- layout = wibox.layout.grid --FIXME this is monkeypatched | |
+ layout = wibox.layout.grid.vertical | |
} | |
end | |
diff --git a/radical/style/arrow.lua b/radical/style/arrow.lua | |
index 3e32992..995bc00 100644 | |
--- a/radical/style/arrow.lua | |
+++ b/radical/style/arrow.lua | |
@@ -51,22 +51,22 @@ local function gen_arrow_x(data, direction, width, height) | |
if direction == "left" then | |
--TODO | |
elseif direction == "right" then | |
- data._internal.w:set_yoffset(-(20) + arrow_height) | |
+ data._internal.w:set_offset {y = -(20) + arrow_height , x = 0 } | |
elseif direction == "bottom" then | |
- data._internal.w:set_xoffset(-(20) - arrow_height) | |
+ data._internal.w:set_offset {x = -(20) + arrow_height , y = 0 } | |
elseif direction == "top" then | |
- data._internal.w:set_xoffset(-data._internal.w.width + (20) + arrow_height) | |
+ data._internal.w:set_offset {x = -data._internal.w.width + (20) + arrow_height, y = 0} | |
end | |
elseif at == base.arrow_type.CENTERED then | |
if direction == "left" or direction == "right" then | |
data._arrow_x = height/2 - arrow_height | |
- data._internal.w:set_yoffset(data._internal.w.height/2 - arrow_height) | |
+ data._internal.w:set_offset { y = data._internal.w.height/2 - arrow_height } | |
else | |
data._arrow_x = width/2 - arrow_height | |
if pg then | |
- data._internal.w:set_xoffset(-data._internal.w.width/2 + arrow_height + pg.width/2) | |
+ data._internal.w:set_offset { x = -data._internal.w.width/2 + arrow_height + pg.width/2 } | |
else | |
- data._internal.w:set_xoffset(data._internal.w.width/2 - arrow_height) | |
+ data._internal.w:set_offset { x = data._internal.w.width/2 - arrow_height } | |
end | |
end | |
end | |
@@ -93,9 +93,9 @@ local function draw_roundedrect_path(cr, width, height, rad, data, direction) | |
if data.arrow_type == base.arrow_type.NONE then | |
if direction == "left" then | |
- data._internal.w:set_yoffset(-rad) | |
+ data._internal.w:set_offset {y = -rad, x = 0 } | |
elseif direction == "right" then | |
- data._internal.w:set_yoffset(rad) | |
+ data._internal.w:set_offset {y = rad, x = 0 } | |
end | |
return shape.rounded_rect(cr, width, height, rad) | |
end | |
@@ -124,11 +124,14 @@ end | |
local function draw(data) | |
if not data._internal.arrow_setup then | |
- data._internal.w:set_shape_border_width(data.border_width or 1) | |
- data._internal.w:set_shape_border_color(color(beautiful.menu_outline_color or beautiful.menu_border_color or beautiful.fg_normal)) | |
+ data._internal.w.border_width = data.border_width or 1 | |
+-- data._internal.w.border_color = color(beautiful.menu_outline_color or beautiful.menu_border_color or beautiful.fg_normal) | |
data._internal.w:set_shape(data.shape or shape.infobubble, unpack(data.shape_args or {})) | |
- data._internal.w:connect_signal("property::direction", function(_, dir) | |
+ data._internal.w:connect_signal("property::current_position", function(_, dir) | |
+ print("\n\n\nANAHCOR!!!", dir) | |
+ dir = "top" --FIXME | |
+ | |
data.direction = dir | |
data._internal.w:set_shape(function(cr, w, h) draw_roundedrect_path(cr, w, h, data.radius or radius, data, dir) end) | |
update_margins(data, dir) | |
diff --git a/radical/theme/init.lua b/radical/theme/init.lua | |
index 4dbe8b0..759d9c1 100644 | |
--- a/radical/theme/init.lua | |
+++ b/radical/theme/init.lua | |
@@ -24,19 +24,19 @@ function module.update_colors(item, current_state_override) | |
item.widget:set_bg ( item.bg_focus ) | |
item.widget:set_bgimage( item.bgimage_focus ) | |
item.widget:set_fg ( item.fg_focus ) | |
- item.widget:set_shape_border_color(item.border_color_focus | |
- or item["border_color"]) | |
+ item.widget.border_color = item.border_color_focus | |
+ or item["border_color"] | |
elseif state_name then | |
item.widget:set_bg (item["bg_"..state_name] ) | |
item.widget:set_bgimage(item["bgimage_"..state_name] ) | |
item.widget:set_fg (item["fg_"..state_name] ) | |
- item.widget:set_shape_border_color(item["border_color_"..state_name] | |
- or item["border_color"]) | |
+ item.widget.border_color = item["border_color_"..state_name] | |
+ or item["border_color"] | |
else | |
item.widget:set_bg ( nil ) | |
item.widget:set_bgimage( nil ) | |
item.widget:set_fg ( item["fg"] ) | |
- item.widget:set_shape_border_color(item["border_color"]) | |
+ item.widget.border_color = item["border_color"] | |
end | |
end | |
diff --git a/radical/widgets/grid.lua b/radical/widgets/grid.lua | |
deleted file mode 100644 | |
index c1c5165..0000000 | |
--- a/radical/widgets/grid.lua | |
+++ /dev/null | |
@@ -1,352 +0,0 @@ | |
---------------------------------------------------------------------------- | |
--- A two dimension layout disposing the widgets in a grid pattern. | |
--- | |
---@DOC_wibox_layout_defaults_grid_EXAMPLE@ | |
--- @author Emmanuel Lepage Valle | |
--- @copyright 2016 Emmanuel Lepage Vallee | |
--- @release @AWESOME_VERSION@ | |
--- @classmod wibox.layout.grid | |
---------------------------------------------------------------------------- | |
- | |
-local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) | |
-local base = require("wibox.widget.base") | |
-local table = table | |
-local pairs = pairs | |
-local util = require("awful.util") | |
- | |
-local grid = {} | |
- | |
-local function get_cell_sizes(self, context, orig_width, orig_height) | |
- local width, height = orig_width, orig_height | |
- | |
- local max_col, max_row = {}, {} | |
- | |
- --TODO include spacing | |
- --TODO compute the current sum for each column to have a "less wrong" | |
- -- widget width. | |
- | |
- local max_h = 0 | |
- for row_idx, row in ipairs(self._private.rows) do | |
- for col_idx, v in ipairs(row) do | |
- local w, h = base.fit_widget(self, context, v, width, height) | |
- max_col[col_idx] = math.max(max_col[col_idx] or 0, w) | |
- max_row[row_idx] = math.max(max_row[row_idx] or 0, h) | |
- max_h = math.max(max_h, h) | |
- end | |
- height = height - max_h | |
- end | |
- | |
- return max_col, max_row | |
-end | |
- | |
--- TODO | |
--- @param context The context in which we are drawn. | |
--- @param width The available width. | |
--- @param height The available height. | |
-function grid:layout(context, width, height) | |
- local max_col, max_row = get_cell_sizes(self, context, width, height) | |
- | |
- local result = {} | |
- local spacing = self._private.spacing --TODO support spacing | |
- | |
- local y = 0 | |
- for row_idx = 1, #max_row do -- Vertical | |
- local x = 0 | |
- for col_idx = 1, #max_col do -- Horizontal | |
- local v = self._private.rows[row_idx][col_idx] | |
- | |
- if v then | |
- table.insert(result, base.place_widget_at(v, x, y, max_col[col_idx], max_row[row_idx])) | |
- x = x + max_col[col_idx] | |
- else | |
- break | |
- end | |
- end | |
- | |
- y = y + max_row[row_idx] | |
- end | |
- | |
- return result | |
-end | |
- | |
-local function get_next_empty(self, row, column) | |
- row, column = row or 1, column or 1 | |
- local cc = self._private.column_count | |
- for i = row, math.huge do | |
- local r = self._private.rows[i] | |
- | |
- if not r then | |
- r = {} | |
- self._private.rows[i] = r | |
- self._private.row_count = i | |
- end | |
- | |
- for j = column, cc do | |
- if not r[j] then | |
- return i, j | |
- end | |
- end | |
- end | |
-end | |
- | |
-local function index_to_point(data, index) | |
- return math.floor(index / data._private.row_count) + 1, | |
- index % data._private.column_count + 1 | |
-end | |
- | |
---- Add some widgets to the given grid layout | |
--- @param ... Widgets that should be added (must at least be one) | |
-function grid:add(...) | |
- -- No table.pack in Lua 5.1 :-( | |
- local args = { n=select('#', ...), ... } | |
- assert(args.n > 0, "need at least one widget to add") | |
- | |
- local row, column | |
- | |
- for i=1, args.n do | |
- row, column = get_next_empty(self, row, column) | |
- | |
- base.check_widget(args[i]) | |
- | |
- self._private.rows[row][column] = args[i] | |
- end | |
- | |
- self:emit_signal("widget::layout_changed") | |
-end | |
- | |
-function grid:set_cell_widget(row, column, widget) | |
- if row < self._private.row_count then | |
- grid:set_row_count(row) | |
- end | |
- | |
- if column < self._private.column_count then | |
- grid:set_column_count(column) | |
- end | |
- | |
- self._private.rows[row] = self._private.rows[row] or {} | |
- | |
- self:emit_signal("widget::layout_changed") | |
-end | |
- | |
-function grid:set_row_count(count) | |
- self._private.row_count = count | |
-end | |
- | |
-function grid:set_column_count(count) | |
- self._private.column_count = count | |
-end | |
- | |
---- Re-pack all the widget according to the current `row_count` and `column_count`. | |
-function grid:reflow() | |
- --TODO | |
- self:emit_signal("widget::layout_changed") | |
-end | |
- | |
---- Remove a widget from the layout | |
--- @tparam number index The widget index to remove | |
--- @treturn boolean index If the operation is successful | |
-function grid:remove(index, reclaim) | |
- local TODO_TOTAL = math.huge --FIXME | |
- if not index or index < 1 or index > TODO_TOTAL then return false end | |
- | |
- local r, c = index_to_point(data, index) | |
- | |
- self._private.rows[r][c] = nil | |
- | |
- self:emit_signal("widget::layout_changed") | |
- | |
- return true | |
-end | |
- | |
---- Remove one or more widgets from the layout | |
--- The last parameter can be a boolean, forcing a recursive seach of the | |
--- widget(s) to remove. | |
--- @param widget ... Widgets that should be removed (must at least be one) | |
--- @treturn boolean If the operation is successful | |
-function grid:remove_widgets(...) | |
- local args = { ... } | |
- | |
- local recursive = type(args[#args]) == "boolean" and args[#args] | |
- | |
- local ret = true | |
- for k, rem_widget in ipairs(args) do | |
- if recursive and k == #args then break end | |
- | |
- local idx, l = self:index(rem_widget, recursive) | |
- | |
- if idx and l and l.remove then | |
- l:remove(idx, false) | |
- else | |
- ret = false | |
- end | |
- end | |
- | |
- return #args > (recursive and 1 or 0) and ret | |
-end | |
- | |
-function grid:get_children() | |
- --TODO | |
- return self._private.rows | |
-end | |
- | |
-function grid:set_children(children) | |
- self:reset() | |
- if #children > 0 then | |
- self:add(unpack(children)) | |
- end | |
-end | |
- | |
---- Replace the first instance of `widget` in the layout with `widget2` | |
--- @param widget The widget to replace | |
--- @param widget2 The widget to replace `widget` with | |
--- @tparam[opt=false] boolean recursive Digg in all compatible layouts to find the widget. | |
--- @treturn boolean If the operation is successful | |
-function grid:replace_widget(widget, widget2, recursive) | |
- local idx, l = self:index(widget, recursive) | |
- | |
- if idx and l then | |
- l:set(idx, widget2) | |
- return true | |
- end | |
- | |
- return false | |
-end | |
- | |
-function grid:swap_widgets(widget1, widget2, recursive) | |
- base.check_widget(widget1) | |
- base.check_widget(widget2) | |
- | |
- local idx1, l1 = self:index(widget1, recursive) | |
- local idx2, l2 = self:index(widget2, recursive) | |
- | |
- if idx1 and l1 and idx2 and l2 and (l1.set or l1.set_widget) and (l2.set or l2.set_widget) then | |
- if l1.set then | |
- l1:set(idx1, widget2) | |
- elseif l1.set_widget then | |
- l1:set_widget(widget2) | |
- end | |
- if l2.set then | |
- l2:set(idx2, widget1) | |
- elseif l2.set_widget then | |
- l2:set_widget(widget1) | |
- end | |
- | |
- return true | |
- end | |
- | |
- return false | |
-end | |
- | |
-function grid:set(index, widget2) | |
- if (not widget2) or (not self._private.rows[index]) then return false end | |
- | |
- base.check_widget(widget2) | |
- | |
- self._private.rows[index] = widget2 | |
- | |
- self:emit_signal("widget::layout_changed") | |
- | |
- return true | |
-end | |
- | |
---- Insert a new widget in the layout at position `index` | |
--- @tparam number index The position | |
--- @param widget The widget | |
--- @treturn boolean If the operation is successful | |
-function grid:insert(index, widget) | |
- local TODO_TOTAL = math.huge --FIXME | |
- if not index or index < 1 or index > TODO_TOTAL then return false end | |
- | |
- base.check_widget(widget) | |
- table.insert(self._private.rows, index, widget) --FIXME | |
- self:emit_signal("widget::layout_changed") | |
- | |
- return true | |
-end | |
- | |
--- Fit the grid layout into the given space | |
--- @param context The context in which we are fit. | |
--- @param orig_width The available width. | |
--- @param orig_height The available height. | |
-function grid:fit(context, orig_width, orig_height) | |
- local max_col, max_row = get_cell_sizes(self, context, orig_width, orig_height) | |
- | |
- -- Now that all fit is done, get the maximum | |
- local used_max_h, used_max_w = 0, 0 | |
- | |
- for row_idx = 1, #max_row do | |
- -- The other widgets will be discarded | |
- if used_max_h + max_row[row_idx] > orig_height then | |
- break | |
- end | |
- | |
- used_max_h = used_max_h + max_row[row_idx] | |
- end | |
- | |
- for col_idx = 1, #max_col do | |
- -- The other widgets will be discarded | |
- if used_max_w + max_col[col_idx] > orig_width then | |
- break | |
- end | |
- | |
- used_max_w = used_max_w + max_col[col_idx] | |
- end | |
- | |
- return used_max_w, used_max_h | |
-end | |
- | |
-function grid:reset() | |
- self._private.rows = {} | |
- self:emit_signal("widget::layout_changed") | |
-end | |
- | |
---- Set the layout's fill_space property. If this property is true, the last | |
--- widget will get all the space that is left. If this is false, the last widget | |
--- won't be handled specially and there can be space left unused. | |
--- @property fill_space | |
- | |
-function grid:set_fill_space(val) | |
- if self._private.fill_space ~= val then | |
- self._private.fill_space = not not val | |
- self:emit_signal("widget::layout_changed") | |
- end | |
-end | |
- | |
-local function get_layout(dir, widget1, ...) | |
- local ret = base.make_widget(nil, nil, {enable_properties = true}) | |
- | |
- util.table.crush(ret, grid, true) | |
- | |
- ret._private.widgets = {} | |
- ret:set_spacing(0) | |
- ret:set_fill_space(false) | |
- | |
- if widget1 then | |
- ret:add(widget1, ...) | |
- end | |
- | |
- return ret | |
-end | |
- | |
---- Add spacing between each layout widgets | |
--- @property spacing | |
--- @tparam number spacing Spacing between widgets. | |
- | |
-function grid:set_spacing(spacing) | |
- if self._private.spacing ~= spacing then | |
- self._private.spacing = spacing | |
- self:emit_signal("widget::layout_changed") | |
- end | |
-end | |
- | |
-function grid:get_spacing() | |
- return self._private.spacing or 0 | |
-end | |
- | |
---@DOC_widget_COMMON@ | |
- | |
---@DOC_object_COMMON@ | |
- | |
-return setmetatable(grid, {__call=function(_, ...) return get_layout(...) end}) | |
- | |
--- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 | |
diff --git a/radical/widgets/init.lua b/radical/widgets/init.lua | |
index 7da9887..fe89568 100644 | |
--- a/radical/widgets/init.lua | |
+++ b/radical/widgets/init.lua | |
@@ -1,10 +1,6 @@ | |
-- Do some evil monkeypatching for upstreamable widgets | |
local wibox = require("wibox") | |
---wibox.layout.grid = require( "radical.widgets.grid" ) | |
--- wibox.widget.checkbox = require( "radical.widgets.checkbox" ) | |
--- wibox.widget.slider = require( "radical.widgets.slider" ) | |
- | |
return { | |
scroll = require( "radical.widgets.scroll" ), | |
filter = require( "radical.widgets.filter" ), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment