bar_cmd_bindsym implemented

And comments removed
And tabs instead of spaces
This commit is contained in:
Yacine Hmito 2015-12-14 00:44:21 +01:00
parent 9b83222b47
commit bd9ad18a80
3 changed files with 81 additions and 51 deletions

View file

@ -26,6 +26,14 @@ struct sway_binding {
char *command; char *command;
}; };
/**
* A mouse binding and an associated command.
*/
struct sway_mouse_binding {
uint32_t button;
char *command;
};
/** /**
* A "mode" of keybindings created via the `mode` command. * A "mode" of keybindings created via the `mode` command.
*/ */
@ -73,6 +81,7 @@ struct bar_config {
*/ */
char *hidden_state; char *hidden_state;
uint32_t modifier; uint32_t modifier;
list_t *bindings;
enum desktop_shell_panel_position position; enum desktop_shell_panel_position position;
char *status_command; char *status_command;
char *font; char *font;
@ -153,6 +162,10 @@ int sway_binding_cmp(const void *a, const void *b);
int sway_binding_cmp_keys(const void *a, const void *b); int sway_binding_cmp_keys(const void *a, const void *b);
void free_sway_binding(struct sway_binding *sb); void free_sway_binding(struct sway_binding *sb);
int sway_mouse_binding_cmp(const void *a, const void *b);
int sway_mouse_binding_cmp_buttons(const void *a, const void *b);
void free_sway_mouse_binding(struct sway_mouse_binding *smb);
/** /**
* Global config singleton. * Global config singleton.
*/ */

View file

@ -63,22 +63,7 @@ static sway_cmd cmd_sticky;
static sway_cmd cmd_workspace; static sway_cmd cmd_workspace;
static sway_cmd cmd_ws_auto_back_and_forth; static sway_cmd cmd_ws_auto_back_and_forth;
/* static sway_cmd bar_cmd_binding_mode_indicator; */ static sway_cmd bar_cmd_bindsym;
/* static sway_cmd bar_cmd_bindsym; */
/* static sway_cmd bar_cmd_colors; */
/* static sway_cmd bar_cmd_font; */
/* static sway_cmd bar_cmd_hidden_state; */
/* static sway_cmd bar_cmd_id; */
/* static sway_cmd bar_cmd_mode; */
/* static sway_cmd bar_cmd_modifier; */
/* static sway_cmd bar_cmd_output; */
/* static sway_cmd bar_cmd_position; */
/* static sway_cmd bar_cmd_seperator_symbol; */
/* static sway_cmd bar_cmd_status_command; */
/* static sway_cmd bar_cmd_strip_workspace_numbers; */
/* static sway_cmd bar_cmd_tray_output; */
/* static sway_cmd bar_cmd_tray_padding; */
/* static sway_cmd bar_cmd_workspace_buttons; */
swayc_t *sp_view; swayc_t *sp_view;
int sp_index = 0; int sp_index = 0;
@ -1496,56 +1481,58 @@ static struct cmd_handler handlers[] = {
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
}; };
/* static struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv); */ static struct cmd_results *bar_cmd_bindsym(int argc, char **argv) {
/* static struct cmd_results *bar_cmd_bindsym(int argc, char **argv); */ struct cmd_results *error = NULL;
/* static struct cmd_results *bar_cmd_colors(int argc, char **argv); */ if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) {
/* static struct cmd_results *bar_cmd_font(int argc, char **argv); */ return error;
/* static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv); */ } else if (!config->reading) {
/* static struct cmd_results *bar_cmd_id(int argc, char **argv); */ return cmd_results_new(CMD_FAILURE, "bindsym", "Can only be used in config file.");
/* static struct cmd_results *bar_cmd_mode(int argc, char **argv); */ }
/* static struct cmd_results *bar_cmd_modifier(int argc, char **argv); */
/* static struct cmd_results *bar_cmd_output(int argc, char **argv); */ /* TODO: The bit that requires to be checked */
/* static struct cmd_results *bar_cmd_position(int argc, char **argv); */ if (strlen(argv[1]) != 7) {
/* static struct cmd_results *bar_cmd_seperator_symbol(int argc, char **argv); */ return ; //TODO: error case
/* static struct cmd_results *bar_cmd_status_command(int argc, char **argv); */ }
/* static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv); */ uint32_t numbutton = (uint32_t) strtol(argv[1] + 6, NULL, 10);
/* static struct cmd_results *bar_cmd_tray_output(int argc, char **argv); */ if (numbutton < 1 || numbutton > 5) {
/* static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv); */ return ; //TODO: error case
/* static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv); */ }
struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding));
binding->button = numbutton;
binding->command = join_args(argv + 1, argc - 1);
struct bar_config bar = config->bar;
int i = list_seq_find(bar.bindings, sway_mouse_binding_cmp_buttons, binding);
if (i > -1) {
sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]);
struct sway_mouse_binding *dup = bar.bindings->items[i];
free_sway_mouse_binding(dup);
list_del(bar.bindings, i);
}
list_add(bar.bindings, binding);
list_sort(bar.bindings, sway_mouse_binding_cmp);
sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
static struct cmd_handler bar_handlers[] = { static struct cmd_handler bar_handlers[] = {
{ "binding_mode_indicator", NULL }, { "binding_mode_indicator", NULL },
/* { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, */ { "bindsym", bar_cmd_bindsym },
{ "bindsym", NULL },
/* { "bindsym", bar_cmd_bindsym }, */
{ "colors", NULL }, { "colors", NULL },
/* { "colors", bar_cmd_colors }, */
{ "font", NULL }, { "font", NULL },
/* { "font", bar_cmd_font }, */
{ "hidden_state", NULL }, { "hidden_state", NULL },
/* { "hidden_state", bar_cmd_hidden_state }, */
{ "id", NULL }, { "id", NULL },
/* { "id", bar_cmd_id }, */
{ "mode", NULL }, { "mode", NULL },
/* { "mode", bar_cmd_mode }, */
{ "modifier", NULL }, { "modifier", NULL },
/* { "modifier", bar_cmd_modifier }, */
{ "output", NULL }, { "output", NULL },
/* { "output", bar_cmd_output }, */
{ "position", NULL }, { "position", NULL },
/* { "position", bar_cmd_position }, */
{ "seperator_symbol", NULL }, { "seperator_symbol", NULL },
/* { "seperator_symbol", bar_cmd_seperator_symbol }, */
{ "status_command", NULL }, { "status_command", NULL },
/* { "status_command", bar_cmd_status_command }, */
{ "strip_workspace_numbers", NULL }, { "strip_workspace_numbers", NULL },
/* { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, */
{ "tray_output", NULL }, { "tray_output", NULL },
/* { "tray_output", bar_cmd_tray_output }, */
{ "tray_padding", NULL }, { "tray_padding", NULL },
/* { "tray_padding", bar_cmd_tray_padding }, */
{ "workspace_buttons", NULL }, { "workspace_buttons", NULL },
/* { "workspace_buttons", bar_cmd_workspace_buttons }, */
}; };

View file

@ -489,3 +489,33 @@ void free_sway_binding(struct sway_binding *binding) {
} }
free(binding); free(binding);
} }
int sway_mouse_binding_cmp_buttons(const void *a, const void *b) {
const struct sway_mouse_binding *binda = a, *bindb = b;
if (binda->button > bindb->button) {
return 1;
}
if (binda->button < bindb->button) {
return -1;
}
return 0;
}
int sway_mouse_binding_cmp(const void *a, const void *b) {
int cmp = 0;
if ((cmp = sway_binding_cmp_keys(a, b)) != 0) {
return cmp;
}
const struct sway_mouse_binding *binda = a, *bindb = b;
return lenient_strcmp(binda->command, bindb->command);
}
void free_sway_mouse_binding(struct sway_mouse_binding *binding) {
//TODO: AFAIK freeing the button field doesn't make sense
//but better be safe than sorry, so ask first
if (binding->command) {
free(binding->command);
}
free(binding);
}