### Install Radical Menu System Source: https://github.com/elv13/radical/blob/master/README.md This snippet shows how to clone the Radical repository into the AwesomeWM configuration directory. Ensure you are in the correct directory before cloning. ```sh cd ~/.config/awesome git clone https://github.com/Elv13/radical.git ``` -------------------------------- ### Dynamic Property Creation and Signal Handling in Radical (Lua) Source: https://github.com/elv13/radical/blob/master/README.md Demonstrates how to dynamically create properties (setters and getters) and signals for Radical objects in Lua. This allows for custom data management and event notifications, enhancing extensibility. It covers setting and getting property values and connecting to signal changes. ```lua local menu = radical.context{} -- Create the setter menu.set_foo = function(m,value) print("Setting value to:",value) m._foo_real = value end -- Create the getter menu.get_foo = function(m) print("Getter called, returning",m._foo_real) end -- The property is now created, this will call the setter: menu.foo = "my foo value" -- This will call the getter: print(menu.foo) -- The signals will be automatically generated data:connect_signal("foo::changed",function(m,value) print("foo changed:",value) end) -- New signals don't need to be registered and can be called right away data:connect_signal("my_new_signal::action_name",function(m,value1,value2,value3) print("Callback",m,value1,value2,value3) end) -- Manually emiting a signal menu:emit_signal("my_new_signal::action_name",value1,value2,value3) ``` -------------------------------- ### Common Menu Methods Source: https://github.com/elv13/radical/blob/master/README.md This section covers the common methods available for interacting with menus, including adding items, widgets, and managing menu content. ```APIDOC ## Common Menu Methods ### Description Provides a collection of methods for adding, modifying, and clearing menu items and widgets, as well as controlling menu visibility and scrolling. ### Methods - **add_item** (array of options) - Returns: item Adds a new item to a menu with specified options. - **add_items** (array of items arrays) - Returns: array Adds multiple new items to a menu. - **add_widget** (a widget, args) - Returns: --- Adds a new widget to the menu in place of an item. - **add_widgets** (array of widgets) - Returns: --- Adds multiple new widgets to the menu. - **add_embeded_menu** (an "embed" menu) - Returns: --- Embeds another menu inline within the current menu. - **add_key_binding** (mod array, key) - Returns: --- Adds a global key binding to the menu. - **add_key_hook** (mod, key, event, func) - Returns: --- Adds a callback function to be executed when a specific key is pressed. - **clear** - Returns: --- Removes all items from the menu. - **scroll_down** - Returns: --- Scrolls the menu content down if it is cropped. - **scroll_up** - Returns: --- Scrolls the menu content up if it is cropped. - **hide** - Returns: --- Hides the menu and all its sub-menus. - **swap** (both items) - Returns: --- Swaps the positions of two items in the menu. - **move** (the item, the new idx) - Returns: --- Moves an item to a new index within the menu. - **remove** (the item) - Returns: --- Removes a specific item from the menu. - **append** (the item) - Returns: --- Appends an existing, unused item to the menu. - **add_prefix_widget** (the widget) - Returns: --- Adds a widget to the beginning of the menu. - **add_suffix_widget** (the widget) - Returns: --- Adds a widget to the end of the menu. - **add_colors_namespace** (the namespace name) - Returns: --- Uses prefixed colors from the 'beautiful' library. - **add_colors_group** (the group name) - Returns: --- Adds a new color group for styling. ### Request Example ```lua -- Example for add_item menubar:add_item{text="My Item", callback=function() print("Item clicked!") end} -- Example for add_widget menubar:add_widget(my_custom_widget) -- Example for hide menubar:hide() ``` ### Response Most methods do not return significant data, indicated by '---'. ``` -------------------------------- ### Create and Configure Context Menu Source: https://github.com/elv13/radical/blob/master/README.md This Lua snippet illustrates how to create a basic context menu using the Radical module. It includes adding items with text, actions, icons, and dynamically generated submenus. It also shows how to attach the menu to a widget and set a key binding. ```lua local menu = radical.context{} menu:add_item {text="Screen 1",button1=function(_menu,item,mods) print("Hello World! ") end} menu:add_item {text="Screen 9",icon= beautiful.awesome_icon} menu:add_item {text="Sub Menu",sub_menu = function() local smenu = radical.context{} smenu:add_item{text="item 1"} smenu:add_item{text="item 2"} return smenu end} -- To add the menu to a widget: local mytextbox = wibox.widget.textbox() mytextbox:set_menu(menu, "button::pressed", 3) -- 3 = right mouse button, 1 = left mouse button -- To add a key binding on a "box" menu (and every other types) menu:add_key_binding({"Mod4"},",") ``` -------------------------------- ### Apply Styles and Layouts to Context Menu Source: https://github.com/elv13/radical/blob/master/README.md This Lua snippet shows how to create a context menu with specific styles and layouts applied. It demonstrates setting the menu style, item style, and the overall item layout for the menu. ```lua local radical = require("radical") local m = radical.context { style = radical.style.classic , item_style = radical.item.style.classic , layout = radical.layout.vertical } ``` -------------------------------- ### Menu Signals Source: https://github.com/elv13/radical/blob/master/README.md This section details the signals emitted by menus for various events, allowing for reactive programming and custom event handling. ```APIDOC ## Menu Signals ### Description Menus emit signals to notify about changes or events, such as property changes, item movements, or button interactions. These signals can be connected to callback functions for custom handling. ### Signals - **PROPERTY_NAME::changed**: Emitted when a menu property changes. - **item::moved**: Emitted when an item's position is changed. - **item::swapped**: Emitted when two items are swapped. - **item::removed**: Emitted when an item is removed. - **item::appended**: Emitted when an item is appended. ### Widget Signals Item layouts often repackage default widget signals, providing a more unified way to handle events. - **button::press** (menu, item, button_id, mods, geo) - Emitted on a button press. - **button::release** (menu, item, button_id, mods, geo) - Emitted on a button release. - **mouse::enter** (menu, item) - Emitted when the mouse pointer enters an item. - **mouse::leave** (menu, item) - Emitted when the mouse pointer leaves an item. - **long::hover** (menu, item) - Emitted when the mouse hovers over an item for 1.5 seconds. - **long::press** (menu, item) - Emitted when the mouse is pressed on an item for 1.5 seconds. ### Modifiers (`mods` argument) The `mods` argument is an array where keys represent applied modifiers. A `nil` value indicates the modifier is not present. Common modifiers include `Control`, `Shift`, `mod1` (Alt), and `mod4`. ### Request Example ```lua -- Connecting to an opacity change signal menubar:connect_signal("opacity::changed", function(value) print("Menu opacity changed to:", value) end) -- Connecting to a button press signal on the menu bar menubar:connect_signal("button::press", function(data, item, button, mods) if mods.Control then print("Control-clicked item:", item.text, "with button:", button) end end) -- Connecting to a button release signal on a specific item menubar:add_item{text="Bar Item"}:connect_signal("button::release", function(data, item, button, mods) print("Bar Item click released!") end) ``` ### Response Signals do not have direct responses in terms of return values. Instead, they trigger the execution of connected callback functions. ``` -------------------------------- ### Set Tooltip for Widget in Lua Source: https://github.com/elv13/radical/blob/master/README.md Demonstrates how to attach a tooltip to a widget using the `set_tooltip` method in Radical. This method is available for various widgets, including textboxes, allowing for contextual help or information display. ```lua local mytextbox = wibox.widget.textbox() mytextbox:set_tooltip("foo bar") ``` -------------------------------- ### Toggle Item State in Lua Source: https://github.com/elv13/radical/blob/master/README.md Demonstrates how to activate and deactivate states for an item using the `item.state` meta table in Lua. Radical manages state selection and item redrawing based on these changes. ```lua local my_state_name = 9999 -- <== The ID local menu = radical.context{} local item = menu:add_item{text="text"} -- Activate a state item.state[my_state_name] = true -- Desactivate a state item.state[my_state_name] = nil ``` -------------------------------- ### Require Radical Module in rc.lua Source: https://github.com/elv13/radical/blob/master/README.md This Lua snippet demonstrates how to include the Radical module at the beginning of your AwesomeWM rc.lua configuration file, making its functions available for use. ```lua local radical = require("radical") ``` -------------------------------- ### Set Menu Margins Programmatically Source: https://github.com/elv13/radical/blob/master/README.md This Lua snippet demonstrates how to adjust the margins of a menu and its individual items using programmatic access to the `margins` property. This allows for fine-tuning the spacing and visual appearance. ```lua my_menu.margins.left = 12 local item = my_menu:add_item {test="Need room"} item.margins.top = 3 ``` -------------------------------- ### Connect to Menu Signal in Lua Source: https://github.com/elv13/radical/blob/master/README.md Connects a callback function to a menu signal, such as 'opacity::changed'. This allows for dynamic updates or actions when a specific menu property changes. The callback function receives the new value of the property. ```lua mymenu:connect_signal("opacity::changed",function(value) -- Do something end) ``` -------------------------------- ### Connect to Item Button Release Signal in Lua Source: https://github.com/elv13/radical/blob/master/README.md Connects a callback function to a 'button::release' signal on a specific menu item. This callback is executed when the button associated with the item is released, printing a confirmation message. It shows how to attach signals directly to individual items. ```lua menubar:add_item{text="bar"}:connect_signal("button::release",function(d,i,b,m) print("bar click released!") end) ``` -------------------------------- ### Handle Button Press Signal with Modifiers in Lua Source: https://github.com/elv13/radical/blob/master/README.md Connects a callback function to a 'button::press' signal on a menu bar. The callback checks for modifier keys (e.g., Control) and prints information about the button press event, including item text, button ID, and data row count. This demonstrates how to access event-specific data and modifiers. ```lua local menubar = radical.bar{} 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) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.