context-menu.h (6034B)
1 #pragma once 2 3 #include "../plugin.h" 4 5 // This extension lets the host and plugin exchange menu items and let the plugin ask the host to 6 // show its context menu. 7 8 static CLAP_CONSTEXPR const char CLAP_EXT_CONTEXT_MENU[] = "clap.context-menu/1"; 9 10 // The latest draft is 100% compatible. 11 // This compat ID may be removed in 2026. 12 static CLAP_CONSTEXPR const char CLAP_EXT_CONTEXT_MENU_COMPAT[] = "clap.context-menu.draft/0"; 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 // There can be different target kind for a context menu 19 enum { 20 CLAP_CONTEXT_MENU_TARGET_KIND_GLOBAL = 0, 21 CLAP_CONTEXT_MENU_TARGET_KIND_PARAM = 1, 22 }; 23 24 // Describes the context menu target 25 typedef struct clap_context_menu_target { 26 uint32_t kind; 27 clap_id id; 28 } clap_context_menu_target_t; 29 30 enum { 31 // Adds a clickable menu entry. 32 // data: const clap_context_menu_item_entry_t* 33 CLAP_CONTEXT_MENU_ITEM_ENTRY, 34 35 // Adds a clickable menu entry which will feature both a checkmark and a label. 36 // data: const clap_context_menu_item_check_entry_t* 37 CLAP_CONTEXT_MENU_ITEM_CHECK_ENTRY, 38 39 // Adds a separator line. 40 // data: NULL 41 CLAP_CONTEXT_MENU_ITEM_SEPARATOR, 42 43 // Starts a sub menu with the given label. 44 // data: const clap_context_menu_item_begin_submenu_t* 45 CLAP_CONTEXT_MENU_ITEM_BEGIN_SUBMENU, 46 47 // Ends the current sub menu. 48 // data: NULL 49 CLAP_CONTEXT_MENU_ITEM_END_SUBMENU, 50 51 // Adds a title entry 52 // data: const clap_context_menu_item_title_t * 53 CLAP_CONTEXT_MENU_ITEM_TITLE, 54 }; 55 typedef uint32_t clap_context_menu_item_kind_t; 56 57 typedef struct clap_context_menu_entry { 58 // text to be displayed 59 const char *label; 60 61 // if false, then the menu entry is greyed out and not clickable 62 bool is_enabled; 63 clap_id action_id; 64 } clap_context_menu_entry_t; 65 66 typedef struct clap_context_menu_check_entry { 67 // text to be displayed 68 const char *label; 69 70 // if false, then the menu entry is greyed out and not clickable 71 bool is_enabled; 72 73 // if true, then the menu entry will be displayed as checked 74 bool is_checked; 75 clap_id action_id; 76 } clap_context_menu_check_entry_t; 77 78 typedef struct clap_context_menu_item_title { 79 // text to be displayed 80 const char *title; 81 82 // if false, then the menu entry is greyed out 83 bool is_enabled; 84 } clap_context_menu_item_title_t; 85 86 typedef struct clap_context_menu_submenu { 87 // text to be displayed 88 const char *label; 89 90 // if false, then the menu entry is greyed out and won't show submenu 91 bool is_enabled; 92 } clap_context_menu_submenu_t; 93 94 // Context menu builder. 95 // This object isn't thread-safe and must be used on the same thread as it was provided. 96 typedef struct clap_context_menu_builder { 97 void *ctx; 98 99 // Adds an entry to the menu. 100 // item_data type is determined by item_kind. 101 // Returns true on success. 102 bool(CLAP_ABI *add_item)(const struct clap_context_menu_builder *builder, 103 clap_context_menu_item_kind_t item_kind, 104 const void *item_data); 105 106 // Returns true if the menu builder supports the given item kind 107 bool(CLAP_ABI *supports)(const struct clap_context_menu_builder *builder, 108 clap_context_menu_item_kind_t item_kind); 109 } clap_context_menu_builder_t; 110 111 typedef struct clap_plugin_context_menu { 112 // Insert plugin's menu items into the menu builder. 113 // If target is null, assume global context. 114 // Returns true on success. 115 // [main-thread] 116 bool(CLAP_ABI *populate)(const clap_plugin_t *plugin, 117 const clap_context_menu_target_t *target, 118 const clap_context_menu_builder_t *builder); 119 120 // Performs the given action, which was previously provided to the host via populate(). 121 // If target is null, assume global context. 122 // Returns true on success. 123 // [main-thread] 124 bool(CLAP_ABI *perform)(const clap_plugin_t *plugin, 125 const clap_context_menu_target_t *target, 126 clap_id action_id); 127 } clap_plugin_context_menu_t; 128 129 typedef struct clap_host_context_menu { 130 // Insert host's menu items into the menu builder. 131 // If target is null, assume global context. 132 // Returns true on success. 133 // [main-thread] 134 bool(CLAP_ABI *populate)(const clap_host_t *host, 135 const clap_context_menu_target_t *target, 136 const clap_context_menu_builder_t *builder); 137 138 // Performs the given action, which was previously provided to the plugin via populate(). 139 // If target is null, assume global context. 140 // Returns true on success. 141 // [main-thread] 142 bool(CLAP_ABI *perform)(const clap_host_t *host, 143 const clap_context_menu_target_t *target, 144 clap_id action_id); 145 146 // Returns true if the host can display a popup menu for the plugin. 147 // This may depend upon the current windowing system used to display the plugin, so the 148 // return value is invalidated after creating the plugin window. 149 // [main-thread] 150 bool(CLAP_ABI *can_popup)(const clap_host_t *host); 151 152 // Shows the host popup menu for a given parameter. 153 // If the plugin is using embedded GUI, then x and y are relative to the plugin's window, 154 // otherwise they're absolute coordinate, and screen index might be set accordingly. 155 // If target is null, assume global context. 156 // Returns true on success. 157 // [main-thread] 158 bool(CLAP_ABI *popup)(const clap_host_t *host, 159 const clap_context_menu_target_t *target, 160 int32_t screen_index, 161 int32_t x, 162 int32_t y); 163 } clap_host_context_menu_t; 164 165 #ifdef __cplusplus 166 } 167 #endif