int f_div(int arglist){ int arg,res; checkarg(NUMLIST_TEST, "/", arglist); res = GET_NUMBER(car(arglist)); arglist = cdr(arglist); while(!(IS_NIL(arglist))){ arg = GET_NUMBER(car(arglist)); arglist = cdr(arglist); res = res / arg; } return(makenum(res)); }
int f_oblist(int arglist){ int addr,addr1,res; checkarg(LEN0_TEST, "oblist", arglist); res = NIL; addr = ep; while(!(nullp(addr))){ addr1 = caar(addr); res = cons(addr1,res); addr = cdr(addr); } return(res); }
int f_if(int arglist){ int arg1,arg2,arg3; checkarg(LEN3_TEST, "if", arglist); arg1 = car(arglist); arg2 = cadr(arglist); arg3 = car(cdr(cdr(arglist))); if(! (nullp(eval(arg1)))) return(eval(arg2)); else return(eval(arg3)); }
struct cmd_results *cmd_resize(int argc, char **argv) { struct cmd_results *error = NULL; if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); if (strcasecmp(argv[0], "set") == 0) { return cmd_resize_set(argc - 1, &argv[1]); } if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { return error; } int dim_arg = argc - 1; enum resize_dim_types dim_type = RESIZE_DIM_DEFAULT; if (strcasecmp(argv[dim_arg], "ppt") == 0) { dim_type = RESIZE_DIM_PPT; dim_arg--; } else if (strcasecmp(argv[dim_arg], "px") == 0) { dim_type = RESIZE_DIM_PX; dim_arg--; } int amount = (int)strtol(argv[dim_arg], NULL, 10); if (errno == ERANGE || amount == 0) { errno = 0; amount = 10; // this is the default resize dimension used by i3 for both px and ppt sway_log(L_DEBUG, "Tried to get resize dimension out of '%s' but failed; setting dimension to default %d", argv[dim_arg], amount); } bool use_width = false; if (strcasecmp(argv[1], "width") == 0) { use_width = true; } else if (strcasecmp(argv[1], "height") != 0) { return cmd_results_new(CMD_INVALID, "resize", "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'"); } if (strcasecmp(argv[0], "shrink") == 0) { amount *= -1; } else if (strcasecmp(argv[0], "grow") != 0) { return cmd_results_new(CMD_INVALID, "resize", "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'"); } resize(amount, use_width, dim_type); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { return error; } struct input_config *ic = config->handler_context.input_config; if (!ic) { return cmd_results_new(CMD_FAILURE, "No input device defined."); } ic->natural_scroll = parse_boolean(argv[0], true); return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *bar_cmd_height(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) { return error; } int height = atoi(argv[0]); if (height < 0) { return cmd_results_new(CMD_INVALID, "Invalid height value: %s", argv[0]); } config->current_bar->height = height; sway_log(SWAY_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id); return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *cmd_workspace_layout(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "workspace_layout", EXPECTED_AT_LEAST, 1))) { return error; } if (strcasecmp(argv[0], "default") == 0) { config->default_layout = L_NONE; } else if (strcasecmp(argv[0], "stacking") == 0) { config->default_layout = L_STACKED; } else if (strcasecmp(argv[0], "tabbed") == 0) { config->default_layout = L_TABBED; } else if (strcasecmp(argv[0], "auto") == 0) { if (argc == 1) { config->default_layout = L_AUTO_FIRST; } else { if ((error = checkarg(argc, "workspace_layout auto", EXPECTED_EQUAL_TO, 2))) { return error; } if (strcasecmp(argv[1], "left") == 0) { config->default_layout = L_AUTO_LEFT; } else if (strcasecmp(argv[1], "right") == 0) { config->default_layout = L_AUTO_RIGHT; } else if (strcasecmp(argv[1], "top") == 0) { config->default_layout = L_AUTO_TOP; } else if (strcasecmp(argv[1], "bottom") == 0) { config->default_layout = L_AUTO_BOTTOM; } else { return cmd_results_new(CMD_INVALID, "workspace_layout auto", "Expected 'workspace_layout auto <left|right|top|bottom>'"); } } } else { return cmd_results_new(CMD_INVALID, "workspace_layout", "Expected 'workspace_layout <default|stacking|tabbed|auto|auto left|auto right|auto top|auto bottom>'"); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *cmd_reload(int argc, char **argv) { struct cmd_results *error = NULL; if (config->reading) return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file."); if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { return error; } if (!load_main_config(config->current_config, true)) { return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); } load_swaybars(); arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
int f_cond(int arglist){ int arg1,arg2,arg3; if(nullp(arglist)) return(NIL); arg1 = car(arglist); checkarg(LIST_TEST, "cond", arg1); arg2 = car(arg1); arg3 = cdr(arg1); if(! (nullp(eval(arg2)))) return(f_begin(arg3)); else return(f_cond(cdr(arglist))); }
struct cmd_results *cmd_smart_gaps(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) { return error; } if (strcasecmp(argv[0], "on") == 0) { config->smart_gaps = true; } else if (strcasecmp(argv[0], "off") == 0) { config->smart_gaps = false; } else { return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'"); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *cmd_commands(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "commands", EXPECTED_EQUAL_TO, 1))) { return error; } if (strcmp(argv[0], "{") != 0) { return cmd_results_new(CMD_FAILURE, "commands", "Expected block declaration"); } if (!config->reading) { return cmd_results_new(CMD_FAILURE, "commands", "Can only be used in config file."); } return cmd_results_new(CMD_BLOCK_COMMANDS, NULL, NULL); }
struct cmd_results *cmd_default_orientation(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "default_orientation", EXPECTED_EQUAL_TO, 1))) { return error; } if (strcasecmp(argv[0], "horizontal") == 0) { config->default_orientation = L_HORIZ; } else if (strcasecmp(argv[0], "vertical") == 0) { config->default_orientation = L_VERT; } else if (strcasecmp(argv[0], "auto") == 0) { // Do nothing } else { return cmd_results_new(CMD_INVALID, "Expected 'orientation <horizontal|vertical|auto>'"); } return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { return error; } struct input_config *ic = config->handler_context.input_config; if (!ic) { return cmd_results_new(CMD_FAILURE, "No input device defined."); } int repeat_rate = atoi(argv[0]); if (repeat_rate < 0) { return cmd_results_new(CMD_INVALID, "Repeat rate cannot be negative"); } ic->repeat_rate = repeat_rate; return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *cmd_reject(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "reject", EXPECTED_MORE_THAN, 1))) { return error; } struct feature_policy *policy = get_policy(argv[0]); policy->features &= ~get_features(argc, argv, &error); if (error) { return error; } sway_log(L_DEBUG, "Permissions granted to %s for features %d", policy->program, policy->features); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *cmd_bar(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { return error; } if (config->reading && strcmp("{", argv[0]) != 0) { return cmd_results_new(CMD_INVALID, "bar", "Expected '{' at start of bar config definition."); } if (!config->reading) { if (argc > 1) { if (strcasecmp("mode", argv[0]) == 0) { return bar_cmd_mode(argc-1, argv + 1); } if (strcasecmp("hidden_state", argv[0]) == 0) { return bar_cmd_hidden_state(argc-1, argv + 1); } } return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); } // Create new bar with default values struct bar_config *bar = default_bar_config(); // set bar id int i; for (i = 0; i < config->bars->length; ++i) { if (bar == config->bars->items[i]) { const int len = 5 + numlen(i); // "bar-" + i + \0 bar->id = malloc(len * sizeof(char)); snprintf(bar->id, len, "bar-%d", i); break; } } // Set current bar config->current_bar = bar; sway_log(L_DEBUG, "Configuring bar %s", bar->id); return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); }
struct cmd_results *bar_cmd_output(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) { return error; } if (!config->current_bar) { return cmd_results_new(CMD_FAILURE, "output", "No bar defined."); } const char *output = argv[0]; list_t *outputs = config->current_bar->outputs; if (!outputs) { outputs = create_list(); config->current_bar->outputs = outputs; } int i; int add_output = 1; if (strcmp("*", output) == 0) { // remove all previous defined outputs and replace with '*' for (i = 0; i < outputs->length; ++i) { free(outputs->items[i]); list_del(outputs, i); } } else { // only add output if not already defined with either the same // name or as '*' for (i = 0; i < outputs->length; ++i) { const char *find = outputs->items[i]; if (strcmp("*", find) == 0 || strcmp(output, find) == 0) { add_output = 0; break; } } } if (add_output) { list_add(outputs, strdup(output)); sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) { return error; } if (!config->current_bar) { return cmd_results_new(CMD_FAILURE, "No bar defined."); } config->current_bar->wrap_scroll = parse_boolean(argv[0], config->current_bar->wrap_scroll); if (config->current_bar->wrap_scroll) { sway_log(SWAY_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id); } else { sway_log(SWAY_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id); } return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *cmd_title_format(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "title_format", EXPECTED_AT_LEAST, 1))) { return error; } struct sway_container *container = config->handler_context.container; if (!container || !container->view) { return cmd_results_new(CMD_INVALID, "Only views can have a title_format"); } struct sway_view *view = container->view; char *format = join_args(argv, argc); if (view->title_format) { free(view->title_format); } view->title_format = format; view_update_title(view, true); config_update_font_height(true); return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *cmd_debuglog(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "debuglog", EXPECTED_EQUAL_TO, 1))) { return error; } else if (strcasecmp(argv[0], "toggle") == 0) { if (config->reading) { return cmd_results_new(CMD_FAILURE, "debuglog toggle", "Can't be used in config file."); } if (toggle_debug_logging()) { sway_log(L_DEBUG, "Debuglog turned on."); } } else if (strcasecmp(argv[0], "on") == 0) { set_log_level(L_DEBUG); sway_log(L_DEBUG, "Debuglog turned on."); } else if (strcasecmp(argv[0], "off") == 0) { reset_log_level(); } else { return cmd_results_new(CMD_FAILURE, "debuglog", "Expected 'debuglog on|off|toggle'"); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { return error; } if (!current_input_config) { return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined."); } struct input_config *new_config = new_input_config(current_input_config->identifier); if (strcasecmp(argv[0], "enabled") == 0) { new_config->natural_scroll = 1; } else if (strcasecmp(argv[0], "disabled") == 0) { new_config->natural_scroll = 0; } else { return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll <enabled|disabled>'"); } input_cmd_apply(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { return error; } if (!current_input_config) { return cmd_results_new(CMD_FAILURE, "accel_profile", "No input device defined."); } struct input_config *new_config = new_input_config(current_input_config->identifier); if (strcasecmp(argv[0], "adaptive") == 0) { new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; } else if (strcasecmp(argv[0], "flat") == 0) { new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; } else { return cmd_results_new(CMD_INVALID, "accel_profile", "Expected 'accel_profile <adaptive|flat>'"); } input_cmd_apply(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *input_cmd_scroll_factor(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "scroll_factor", EXPECTED_AT_LEAST, 1))) { return error; } struct input_config *ic = config->handler_context.input_config; if (!ic) { return cmd_results_new(CMD_FAILURE, "No input device defined."); } float scroll_factor = parse_float(argv[0]); if (isnan(scroll_factor)) { return cmd_results_new(CMD_INVALID, "Invalid scroll factor; expected float."); } else if (scroll_factor < 0) { return cmd_results_new(CMD_INVALID, "Scroll factor cannot be negative."); } ic->scroll_factor = scroll_factor; return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { return error; } if (!config->current_bar) { return cmd_results_new(CMD_FAILURE, "workspace_buttons", "No bar defined."); } if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->workspace_buttons = true; sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->workspace_buttons = false; sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id); } else { error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); return error; } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
struct cmd_results *cmd_focus_on_window_activation(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "focus_on_window_activation", EXPECTED_EQUAL_TO, 1))) { return error; } if (strcmp(argv[0], "smart") == 0) { config->focus_on_window_activation = FOWA_SMART; } else if (strcmp(argv[0], "urgent") == 0) { config->focus_on_window_activation = FOWA_URGENT; } else if (strcmp(argv[0], "focus") == 0) { config->focus_on_window_activation = FOWA_FOCUS; } else if (strcmp(argv[0], "none") == 0) { config->focus_on_window_activation = FOWA_NONE; } else { return cmd_results_new(CMD_INVALID, "Expected " "'focus_on_window_activation smart|urgent|focus|none'"); } return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *input_cmd_click_method(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { return error; } struct input_config *ic = config->handler_context.input_config; if (!ic) { return cmd_results_new(CMD_FAILURE, "No input device defined."); } if (strcasecmp(argv[0], "none") == 0) { ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; } else if (strcasecmp(argv[0], "button_areas") == 0) { ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; } else if (strcasecmp(argv[0], "clickfinger") == 0) { ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; } else { return cmd_results_new(CMD_INVALID, "Expected 'click_method <none|button_areas|clickfinger'>"); } return cmd_results_new(CMD_SUCCESS, NULL); }
struct cmd_results *cmd_fullscreen(int argc, char **argv) { struct cmd_results *error = NULL; if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file."); if (!config->active) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can only be used when sway is running."); if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0))) { return error; } swayc_t *container = get_focused_view(&root_container); if(container->type != C_VIEW){ return cmd_results_new(CMD_INVALID, "fullscreen", "Only views can fullscreen"); } swayc_t *workspace = swayc_parent_by_type(container, C_WORKSPACE); bool current = swayc_is_fullscreen(container); wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); if (container->is_floating) { if (current) { // set dimensions back to what they were before we fullscreened this container->x = container->cached_geometry.origin.x; container->y = container->cached_geometry.origin.y; container->width = container->cached_geometry.size.w; container->height = container->cached_geometry.size.h; } else { // cache dimensions so we can reset them after we "unfullscreen" this struct wlc_geometry geo = { .origin = { .x = container->x, .y = container->y }, .size = { .w = container->width, .h = container->height } }; container->cached_geometry = geo; } }
struct cmd_results *input_cmd_events(int argc, char **argv) { sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); struct cmd_results *error = NULL; if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { return error; } if (!current_input_config) { return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); } struct input_config *new_config = new_input_config(current_input_config->identifier); if (strcasecmp(argv[0], "enabled") == 0) { new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } else if (strcasecmp(argv[0], "disabled") == 0) { new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; } else { return cmd_results_new(CMD_INVALID, "events", "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); } input_cmd_apply(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
static struct cmd_results *cmd_resize_set(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "resize set", EXPECTED_AT_LEAST, 2))) { return error; } if (strcasecmp(argv[0], "width") == 0 || strcasecmp(argv[0], "height") == 0) { // handle `reset set width 100 px height 100 px` syntax, also allows // specifying only one dimension for a `resize set` int cmd_num = 0; int dim; while ((cmd_num + 1) < argc) { dim = (int)strtol(argv[cmd_num + 1], NULL, 10); if (errno == ERANGE || dim == 0) { errno = 0; return cmd_results_new(CMD_INVALID, "resize set", "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'"); } if (strcasecmp(argv[cmd_num], "width") == 0) { set_size(dim, true); } else if (strcasecmp(argv[cmd_num], "height") == 0) { set_size(dim, false); } else { return cmd_results_new(CMD_INVALID, "resize set", "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'"); } cmd_num += 2; if (cmd_num < argc && strcasecmp(argv[cmd_num], "px") == 0) { // if this was `resize set width 400 px height 300 px`, disregard the `px` arg cmd_num++; } } } else { // handle `reset set 100 px 100 px` syntax int width = (int)strtol(argv[0], NULL, 10); if (errno == ERANGE || width == 0) { errno = 0; return cmd_results_new(CMD_INVALID, "resize set", "Expected 'resize set <width> [px] <height> [px]'"); } int height_arg = 1; if (strcasecmp(argv[1], "px") == 0) { height_arg = 2; } int height = (int)strtol(argv[height_arg], NULL, 10); if (errno == ERANGE || height == 0) { errno = 0; return cmd_results_new(CMD_INVALID, "resize set", "Expected 'resize set <width> [px] <height> [px]'"); } set_size(width, true); set_size(height, false); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }
PLRUBY_EXPORT OCIAnyData * extproc_ruby(OCIExtProcContext *with_context, short *ret_ind, int rettype, const char *obj, short obj_ind, const char *meth, short meth_ind, const char *argtype, int argtype_len, OCIString *v1, short v1_ind, OCIString *v2, short v2_ind, OCIString *v3, short v3_ind, OCIString *v4, short v4_ind, OCIString *v5, short v5_ind, OCIString *v6, short v6_ind, OCIString *v7, short v7_ind, OCIString *v8, short v8_ind, OCIString *v9, short v9_ind, OCIString *v10, short v10_ind, OCINumber *n1, short n1_ind, OCINumber *n2, short n2_ind, OCINumber *n3, short n3_ind, OCINumber *n4, short n4_ind, OCINumber *n5, short n5_ind, OCINumber *n6, short n6_ind, OCINumber *n7, short n7_ind, OCINumber *n8, short n8_ind, OCINumber *n9, short n9_ind, OCINumber *n10, short n10_ind, double d1, short d1_ind, double d2, short d2_ind, double d3, short d3_ind, double d4, short d4_ind, double d5, short d5_ind, double d6, short d6_ind, double d7, short d7_ind, double d8, short d8_ind, double d9, short d9_ind, double d10, short d10_ind) { plruby_context_t ctx; OCIAnyData *sdata = NULL; static int ruby_initialized = 0; OCIExtProcGetEnv(with_context, &ctx.envhp, &ctx.svchp, &ctx.errhp); ctx.obj = obj_ind ? NULL : obj; ctx.meth = meth_ind ? NULL : meth; ctx.rettype = rettype; ctx.argtype = argtype; ctx.args[0] = argtype_len >= 1 ? checkarg(argtype[0], v1, n1, &d1) : EMPTY; ctx.args[1] = argtype_len >= 2 ? checkarg(argtype[1], v2, n2, &d2) : EMPTY; ctx.args[2] = argtype_len >= 3 ? checkarg(argtype[2], v3, n3, &d3) : EMPTY; ctx.args[3] = argtype_len >= 4 ? checkarg(argtype[3], v4, n4, &d4) : EMPTY; ctx.args[4] = argtype_len >= 5 ? checkarg(argtype[4], v5, n5, &d5) : EMPTY; ctx.args[5] = argtype_len >= 6 ? checkarg(argtype[5], v6, n6, &d6) : EMPTY; ctx.args[6] = argtype_len >= 7 ? checkarg(argtype[6], v7, n7, &d7) : EMPTY; ctx.args[7] = argtype_len >= 8 ? checkarg(argtype[7], v8, n8, &d8) : EMPTY; ctx.args[8] = argtype_len >= 9 ? checkarg(argtype[8], v9, n9, &d9) : EMPTY; ctx.args[9] = argtype_len >= 10 ? checkarg(argtype[9], v10, n10, &d10) : EMPTY; if (!ruby_initialized) { ruby_init(); ruby_init_loadpath(); ruby_script("extproc_ruby"); ruby_initialized = 1; } { int state = 0; int plruby_initialized = 0; RUBY_INIT_STACK; if (!plruby_initialized) { rb_protect((VALUE(*)(VALUE))setup_plruby_oracle, (VALUE)&ctx, &state); if (state == 0) { plruby_initialized = 1; } } if (state == 0) { sdata = (OCIAnyData*)rb_protect((VALUE(*)(VALUE))call_ruby, (VALUE)&ctx, &state); } if (state) { int errnum = 20999; /* The last value of user-defined error number */ const char *errmsg = (const char *)rb_protect((VALUE(*)(VALUE))get_error_msg, (VALUE)&errnum, &state); if (state) { errmsg = "Failed to get an error in extproc_ruby"; } OCIExtProcRaiseExcpWithMsg(with_context, errnum, (OraText*)errmsg, 0); } } *ret_ind = (sdata != NULL) ? OCI_IND_NOTNULL : OCI_IND_NULL; return sdata; }
struct cmd_results *cmd_gaps(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { return error; } const char *expected_syntax = "Expected 'gaps edge_gaps <on|off|toggle>' or " "'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"; const char *amount_str = argv[0]; // gaps amount if (argc >= 1 && isdigit(*amount_str)) { int amount = (int)strtol(amount_str, NULL, 10); if (errno == ERANGE) { errno = 0; return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); } config->gaps_inner = config->gaps_outer = amount; arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } // gaps inner|outer n else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { int amount = (int)strtol(amount_str, NULL, 10); if (errno == ERANGE) { errno = 0; return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); } const char *target_str = argv[0]; if (strcasecmp(target_str, "inner") == 0) { config->gaps_inner = amount; } else if (strcasecmp(target_str, "outer") == 0) { config->gaps_outer = amount; } arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } else if (argc == 2 && strcasecmp(argv[0], "edge_gaps") == 0) { // gaps edge_gaps <on|off|toggle> if (strcasecmp(argv[1], "toggle") == 0) { if (config->reading) { return cmd_results_new(CMD_FAILURE, "gaps edge_gaps toggle", "Can't be used in config file."); } config->edge_gaps = !config->edge_gaps; } else { config->edge_gaps = (strcasecmp(argv[1], "yes") == 0 || strcasecmp(argv[1], "on") == 0); } arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } // gaps inner|outer current|all set|plus|minus n if (argc < 4 || config->reading) { return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); } // gaps inner|outer ... const char *inout_str = argv[0]; enum {INNER, OUTER} inout; if (strcasecmp(inout_str, "inner") == 0) { inout = INNER; } else if (strcasecmp(inout_str, "outer") == 0) { inout = OUTER; } else { return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); } // gaps ... current|all ... const char *target_str = argv[1]; enum {CURRENT, WORKSPACE, ALL} target; if (strcasecmp(target_str, "current") == 0) { target = CURRENT; } else if (strcasecmp(target_str, "all") == 0) { target = ALL; } else if (strcasecmp(target_str, "workspace") == 0) { if (inout == OUTER) { target = CURRENT; } else { // Set gap for views in workspace target = WORKSPACE; } } else { return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); } // gaps ... n amount_str = argv[3]; int amount = (int)strtol(amount_str, NULL, 10); if (errno == ERANGE) { errno = 0; return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); } // gaps ... set|plus|minus ... const char *method_str = argv[2]; enum {SET, ADD} method; if (strcasecmp(method_str, "set") == 0) { method = SET; } else if (strcasecmp(method_str, "plus") == 0) { method = ADD; } else if (strcasecmp(method_str, "minus") == 0) { method = ADD; amount *= -1; } else { return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); } if (target == CURRENT) { swayc_t *cont; if (inout == OUTER) { if ((cont = swayc_active_workspace()) == NULL) { return cmd_results_new(CMD_FAILURE, "gaps", "There's no active workspace."); } } else { if ((cont = get_focused_view(&root_container))->type != C_VIEW) { return cmd_results_new(CMD_FAILURE, "gaps", "Currently focused item is not a view."); } } cont->gaps = swayc_gap(cont); if (method == SET) { cont->gaps = amount; } else if ((cont->gaps += amount) < 0) { cont->gaps = 0; } arrange_windows(cont->parent, -1, -1); } else if (inout == OUTER) { //resize all workspace. int i,j; for (i = 0; i < root_container.children->length; ++i) { swayc_t *op = root_container.children->items[i]; for (j = 0; j < op->children->length; ++j) { swayc_t *ws = op->children->items[j]; if (method == SET) { ws->gaps = amount; } else if ((ws->gaps += amount) < 0) { ws->gaps = 0; } } } arrange_windows(&root_container, -1, -1); } else { // Resize gaps for all views in workspace swayc_t *top; if (target == WORKSPACE) { if ((top = swayc_active_workspace()) == NULL) { return cmd_results_new(CMD_FAILURE, "gaps", "There's currently no active workspace."); } } else { top = &root_container; } int top_gap = top->gaps; container_map(top, method == SET ? set_gaps : add_gaps, &amount); top->gaps = top_gap; arrange_windows(top, -1, -1); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); }