1 #ifndef _SWAY_COMMANDS_H 2 #define _SWAY_COMMANDS_H 3 4 #include <wlr/util/edges.h> 5 #include "config.h" 6 7 struct sway_container; 8 9 typedef struct cmd_results *sway_cmd(int argc, char **argv); 10 11 struct cmd_handler { 12 char *command; 13 sway_cmd *handle; 14 }; 15 16 /** 17 * Indicates the result of a command's execution. 18 */ 19 enum cmd_status { 20 CMD_SUCCESS, /**< The command was successful */ 21 CMD_FAILURE, /**< The command resulted in an error */ 22 CMD_INVALID, /**< Unknown command or parser error */ 23 CMD_DEFER, /**< Command execution deferred */ 24 CMD_BLOCK, 25 CMD_BLOCK_COMMANDS, 26 CMD_BLOCK_END 27 }; 28 29 /** 30 * Stores the result of executing a command. 31 */ 32 struct cmd_results { 33 enum cmd_status status; 34 /** 35 * Human friendly error message, or NULL on success 36 */ 37 char *error; 38 }; 39 40 enum expected_args { 41 EXPECTED_AT_LEAST, 42 EXPECTED_AT_MOST, 43 EXPECTED_EQUAL_TO 44 }; 45 46 struct cmd_results *checkarg(int argc, const char *name, 47 enum expected_args type, int val); 48 49 struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers, 50 size_t handlers_size); 51 52 /** 53 * Parse and executes a command. 54 * 55 * If the command string contains criteria then the command will be executed on 56 * all matching containers. Otherwise, it'll run on the `con` container. If 57 * `con` is NULL then it'll run on the currently focused container. 58 */ 59 list_t *execute_command(char *command, struct sway_seat *seat, 60 struct sway_container *con); 61 /** 62 * Parse and handles a command during config file loading. 63 * 64 * Do not use this under normal conditions. 65 */ 66 struct cmd_results *config_command(char *command, char **new_block); 67 /** 68 * Parse and handle a sub command 69 */ 70 struct cmd_results *config_subcommand(char **argv, int argc, 71 struct cmd_handler *handlers, size_t handlers_size); 72 /* 73 * Parses a command policy rule. 74 */ 75 struct cmd_results *config_commands_command(char *exec); 76 /** 77 * Allocates a cmd_results object. 78 */ 79 struct cmd_results *cmd_results_new(enum cmd_status status, const char *error, ...); 80 /** 81 * Frees a cmd_results object. 82 */ 83 void free_cmd_results(struct cmd_results *results); 84 /** 85 * Serializes a list of cmd_results to a JSON string. 86 * 87 * Free the JSON string later on. 88 */ 89 char *cmd_results_to_json(list_t *res_list); 90 91 /** 92 * TODO: Move this function and its dependent functions to container.c. 93 */ 94 void container_resize_tiled(struct sway_container *parent, uint32_t axis, 95 int amount); 96 97 struct sway_container *container_find_resize_parent(struct sway_container *con, 98 uint32_t edge); 99 100 sway_cmd cmd_assign; 101 sway_cmd cmd_bar; 102 sway_cmd cmd_bindcode; 103 sway_cmd cmd_bindswitch; 104 sway_cmd cmd_bindsym; 105 sway_cmd cmd_border; 106 sway_cmd cmd_client_noop; 107 sway_cmd cmd_client_focused; 108 sway_cmd cmd_client_focused_inactive; 109 sway_cmd cmd_client_unfocused; 110 sway_cmd cmd_client_urgent; 111 sway_cmd cmd_client_placeholder; 112 sway_cmd cmd_client_background; 113 sway_cmd cmd_commands; 114 sway_cmd cmd_create_output; 115 sway_cmd cmd_default_border; 116 sway_cmd cmd_default_floating_border; 117 sway_cmd cmd_default_orientation; 118 sway_cmd cmd_exec; 119 sway_cmd cmd_exec_always; 120 sway_cmd cmd_exit; 121 sway_cmd cmd_floating; 122 sway_cmd cmd_floating_maximum_size; 123 sway_cmd cmd_floating_minimum_size; 124 sway_cmd cmd_floating_modifier; 125 sway_cmd cmd_floating_scroll; 126 sway_cmd cmd_focus; 127 sway_cmd cmd_focus_follows_mouse; 128 sway_cmd cmd_focus_on_window_activation; 129 sway_cmd cmd_focus_wrapping; 130 sway_cmd cmd_font; 131 sway_cmd cmd_for_window; 132 sway_cmd cmd_force_display_urgency_hint; 133 sway_cmd cmd_force_focus_wrapping; 134 sway_cmd cmd_fullscreen; 135 sway_cmd cmd_gaps; 136 sway_cmd cmd_hide_edge_borders; 137 sway_cmd cmd_include; 138 sway_cmd cmd_inhibit_idle; 139 sway_cmd cmd_input; 140 sway_cmd cmd_seat; 141 sway_cmd cmd_ipc; 142 sway_cmd cmd_kill; 143 sway_cmd cmd_layout; 144 sway_cmd cmd_log_colors; 145 sway_cmd cmd_mark; 146 sway_cmd cmd_max_render_time; 147 sway_cmd cmd_mode; 148 sway_cmd cmd_mouse_warping; 149 sway_cmd cmd_move; 150 sway_cmd cmd_new_float; 151 sway_cmd cmd_new_window; 152 sway_cmd cmd_nop; 153 sway_cmd cmd_opacity; 154 sway_cmd cmd_new_float; 155 sway_cmd cmd_new_window; 156 sway_cmd cmd_no_focus; 157 sway_cmd cmd_output; 158 sway_cmd cmd_permit; 159 sway_cmd cmd_popup_during_fullscreen; 160 sway_cmd cmd_reject; 161 sway_cmd cmd_reload; 162 sway_cmd cmd_rename; 163 sway_cmd cmd_resize; 164 sway_cmd cmd_scratchpad; 165 sway_cmd cmd_seamless_mouse; 166 sway_cmd cmd_set; 167 sway_cmd cmd_shortcuts_inhibitor; 168 sway_cmd cmd_show_marks; 169 sway_cmd cmd_smart_borders; 170 sway_cmd cmd_smart_gaps; 171 sway_cmd cmd_split; 172 sway_cmd cmd_splith; 173 sway_cmd cmd_splitt; 174 sway_cmd cmd_splitv; 175 sway_cmd cmd_sticky; 176 sway_cmd cmd_swaybg_command; 177 sway_cmd cmd_swaynag_command; 178 sway_cmd cmd_swap; 179 sway_cmd cmd_tiling_drag; 180 sway_cmd cmd_tiling_drag_threshold; 181 sway_cmd cmd_title_align; 182 sway_cmd cmd_title_format; 183 sway_cmd cmd_titlebar_border_thickness; 184 sway_cmd cmd_titlebar_padding; 185 sway_cmd cmd_unbindcode; 186 sway_cmd cmd_unbindswitch; 187 sway_cmd cmd_unbindsym; 188 sway_cmd cmd_unmark; 189 sway_cmd cmd_urgent; 190 sway_cmd cmd_workspace; 191 sway_cmd cmd_workspace_layout; 192 sway_cmd cmd_ws_auto_back_and_forth; 193 sway_cmd cmd_xwayland; 194 195 sway_cmd bar_cmd_bindcode; 196 sway_cmd bar_cmd_binding_mode_indicator; 197 sway_cmd bar_cmd_bindsym; 198 sway_cmd bar_cmd_colors; 199 sway_cmd bar_cmd_font; 200 sway_cmd bar_cmd_gaps; 201 sway_cmd bar_cmd_mode; 202 sway_cmd bar_cmd_modifier; 203 sway_cmd bar_cmd_output; 204 sway_cmd bar_cmd_height; 205 sway_cmd bar_cmd_hidden_state; 206 sway_cmd bar_cmd_icon_theme; 207 sway_cmd bar_cmd_id; 208 sway_cmd bar_cmd_position; 209 sway_cmd bar_cmd_separator_symbol; 210 sway_cmd bar_cmd_status_command; 211 sway_cmd bar_cmd_status_edge_padding; 212 sway_cmd bar_cmd_status_padding; 213 sway_cmd bar_cmd_pango_markup; 214 sway_cmd bar_cmd_strip_workspace_numbers; 215 sway_cmd bar_cmd_strip_workspace_name; 216 sway_cmd bar_cmd_swaybar_command; 217 sway_cmd bar_cmd_tray_bindcode; 218 sway_cmd bar_cmd_tray_bindsym; 219 sway_cmd bar_cmd_tray_output; 220 sway_cmd bar_cmd_tray_padding; 221 sway_cmd bar_cmd_unbindcode; 222 sway_cmd bar_cmd_unbindsym; 223 sway_cmd bar_cmd_wrap_scroll; 224 sway_cmd bar_cmd_workspace_buttons; 225 226 sway_cmd bar_colors_cmd_active_workspace; 227 sway_cmd bar_colors_cmd_background; 228 sway_cmd bar_colors_cmd_focused_background; 229 sway_cmd bar_colors_cmd_binding_mode; 230 sway_cmd bar_colors_cmd_focused_workspace; 231 sway_cmd bar_colors_cmd_inactive_workspace; 232 sway_cmd bar_colors_cmd_separator; 233 sway_cmd bar_colors_cmd_focused_separator; 234 sway_cmd bar_colors_cmd_statusline; 235 sway_cmd bar_colors_cmd_focused_statusline; 236 sway_cmd bar_colors_cmd_urgent_workspace; 237 238 sway_cmd input_cmd_seat; 239 sway_cmd input_cmd_accel_profile; 240 sway_cmd input_cmd_calibration_matrix; 241 sway_cmd input_cmd_click_method; 242 sway_cmd input_cmd_drag; 243 sway_cmd input_cmd_drag_lock; 244 sway_cmd input_cmd_dwt; 245 sway_cmd input_cmd_events; 246 sway_cmd input_cmd_left_handed; 247 sway_cmd input_cmd_map_from_region; 248 sway_cmd input_cmd_map_to_output; 249 sway_cmd input_cmd_map_to_region; 250 sway_cmd input_cmd_middle_emulation; 251 sway_cmd input_cmd_natural_scroll; 252 sway_cmd input_cmd_pointer_accel; 253 sway_cmd input_cmd_scroll_factor; 254 sway_cmd input_cmd_repeat_delay; 255 sway_cmd input_cmd_repeat_rate; 256 sway_cmd input_cmd_scroll_button; 257 sway_cmd input_cmd_scroll_method; 258 sway_cmd input_cmd_tap; 259 sway_cmd input_cmd_tap_button_map; 260 sway_cmd input_cmd_xkb_capslock; 261 sway_cmd input_cmd_xkb_file; 262 sway_cmd input_cmd_xkb_layout; 263 sway_cmd input_cmd_xkb_model; 264 sway_cmd input_cmd_xkb_numlock; 265 sway_cmd input_cmd_xkb_options; 266 sway_cmd input_cmd_xkb_rules; 267 sway_cmd input_cmd_xkb_switch_layout; 268 sway_cmd input_cmd_xkb_variant; 269 270 sway_cmd output_cmd_adaptive_sync; 271 sway_cmd output_cmd_background; 272 sway_cmd output_cmd_disable; 273 sway_cmd output_cmd_dpms; 274 sway_cmd output_cmd_enable; 275 sway_cmd output_cmd_max_render_time; 276 sway_cmd output_cmd_mode; 277 sway_cmd output_cmd_position; 278 sway_cmd output_cmd_scale; 279 sway_cmd output_cmd_scale_filter; 280 sway_cmd output_cmd_subpixel; 281 sway_cmd output_cmd_toggle; 282 sway_cmd output_cmd_transform; 283 284 sway_cmd seat_cmd_attach; 285 sway_cmd seat_cmd_cursor; 286 sway_cmd seat_cmd_fallback; 287 sway_cmd seat_cmd_hide_cursor; 288 sway_cmd seat_cmd_idle_inhibit; 289 sway_cmd seat_cmd_idle_wake; 290 sway_cmd seat_cmd_keyboard_grouping; 291 sway_cmd seat_cmd_pointer_constraint; 292 sway_cmd seat_cmd_shortcuts_inhibitor; 293 sway_cmd seat_cmd_xcursor_theme; 294 295 sway_cmd xwayland_cmd_enable; 296 sway_cmd xwayland_cmd_disable; 297 sway_cmd xwayland_cmd_force; 298 sway_cmd xwayland_cmd_scale; 299 300 sway_cmd cmd_ipc_cmd; 301 sway_cmd cmd_ipc_events; 302 sway_cmd cmd_ipc_event_cmd; 303 304 #endif 305