Clean up fallthrough issues

master
Drew DeVault 7 years ago
parent 8208e2505a
commit 03af90d302

@ -452,6 +452,7 @@ static bool handle_view_created(wlc_handle handle) {
wlc_view_focus(handle); wlc_view_focus(handle);
wlc_view_bring_to_front(handle); wlc_view_bring_to_front(handle);
newview = new_floating_view(handle); newview = new_floating_view(handle);
/* fallthrough */
case WLC_BIT_POPUP: case WLC_BIT_POPUP:
wlc_view_bring_to_front(handle); wlc_view_bring_to_front(handle);
break; break;
@ -934,15 +935,15 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
struct sway_binding *binding = mode->bindings->items[i]; struct sway_binding *binding = mode->bindings->items[i];
if ((modifiers->mods ^ binding->modifiers) == 0) { if ((modifiers->mods ^ binding->modifiers) == 0) {
switch (state) { switch (state) {
case WLC_BUTTON_STATE_PRESSED: { case WLC_BUTTON_STATE_PRESSED:
if (!binding->release && handle_bindsym(binding, button, 0)) { if (!binding->release && handle_bindsym(binding, button, 0)) {
return EVENT_HANDLED; return EVENT_HANDLED;
} }
break;
case WLC_BUTTON_STATE_RELEASED:
if (binding->release && handle_bindsym(binding, button, 0)) {
return EVENT_HANDLED;
} }
case WLC_BUTTON_STATE_RELEASED:
if (binding->release && handle_bindsym(binding, button, 0)) {
return EVENT_HANDLED;
}
break; break;
} }
} }

@ -152,10 +152,11 @@ bool verify_password() {
void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) {
int redraw_screen = 0; int redraw_screen = 0;
char *password_realloc; char *password_realloc;
int i;
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
switch (sym) { switch (sym) {
case XKB_KEY_KP_Enter: // fallthrough case XKB_KEY_KP_Enter:
case XKB_KEY_Return: case XKB_KEY_Return:
render_data.auth_state = AUTH_STATE_VALIDATING; render_data.auth_state = AUTH_STATE_VALIDATING;
@ -166,6 +167,7 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
if (verify_password()) { if (verify_password()) {
exit(0); exit(0);
} }
render_data.auth_state = AUTH_STATE_INVALID; render_data.auth_state = AUTH_STATE_INVALID;
redraw_screen = 1; redraw_screen = 1;
@ -174,73 +176,65 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
password[0] = '\0'; password[0] = '\0';
break; break;
case XKB_KEY_BackSpace: case XKB_KEY_BackSpace:
{ i = strlen(password);
int i = strlen(password); if (i > 0) {
if (i > 0) { password[i - 1] = '\0';
password[i - 1] = '\0'; render_data.auth_state = AUTH_STATE_BACKSPACE;
render_data.auth_state = AUTH_STATE_BACKSPACE; redraw_screen = 1;
redraw_screen = 1;
}
break;
} }
case XKB_KEY_Control_L: // fallthrough break;
case XKB_KEY_Control_R: // fallthrough case XKB_KEY_Control_L:
case XKB_KEY_Shift_L: // fallthrough case XKB_KEY_Control_R:
case XKB_KEY_Shift_R: // fallthrough case XKB_KEY_Shift_L:
case XKB_KEY_Caps_Lock: // fallthrough case XKB_KEY_Shift_R:
case XKB_KEY_Shift_Lock: // fallthrough case XKB_KEY_Caps_Lock:
case XKB_KEY_Meta_L: // fallthrough case XKB_KEY_Shift_Lock:
case XKB_KEY_Meta_R: // fallthrough case XKB_KEY_Meta_L:
case XKB_KEY_Alt_L: // fallthrough case XKB_KEY_Meta_R:
case XKB_KEY_Alt_R: // fallthrough case XKB_KEY_Alt_L:
case XKB_KEY_Super_L: // fallthrough case XKB_KEY_Alt_R:
case XKB_KEY_Super_R: // fallthrough case XKB_KEY_Super_L:
case XKB_KEY_Hyper_L: // fallthrough case XKB_KEY_Super_R:
case XKB_KEY_Hyper_L:
case XKB_KEY_Hyper_R: case XKB_KEY_Hyper_R:
{ break; // don't draw screen on modifier keys
// don't draw screen on modifier keys case XKB_KEY_Escape:
break; case XKB_KEY_u:
}
case XKB_KEY_Escape: // fallthrough
case XKB_KEY_u: // fallthrough
case XKB_KEY_U: case XKB_KEY_U:
{ // clear password buffer on ctrl-u (or escape for i3lock compatibility)
// clear password buffer on ctrl-u (or escape for i3lock compatibility) if (sym == XKB_KEY_Escape || xkb_state_mod_name_is_active(registry->input->xkb.state,
if (sym == XKB_KEY_Escape || xkb_state_mod_name_is_active(registry->input->xkb.state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) {
XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) { render_data.auth_state = AUTH_STATE_BACKSPACE;
render_data.auth_state = AUTH_STATE_BACKSPACE; redraw_screen = 1;
redraw_screen = 1;
password_size = 1024;
free(password);
password = malloc(password_size);
password[0] = '\0';
break;
}
/* fallthrough */
default:
render_data.auth_state = AUTH_STATE_INPUT;
redraw_screen = 1;
i = strlen(password);
if (i + 1 == password_size) {
password_size += 1024;
password_realloc = realloc(password, password_size);
// reset password if realloc fails.
if (password_realloc == NULL) {
password_size = 1024; password_size = 1024;
free(password); free(password);
password = malloc(password_size); password = malloc(password_size);
password[0] = '\0'; password[0] = '\0';
break; break;
} else {
password = password_realloc;
} }
} }
default: password[i] = (char)codepoint;
{ password[i + 1] = '\0';
render_data.auth_state = AUTH_STATE_INPUT; break;
redraw_screen = 1;
int i = strlen(password);
if (i + 1 == password_size) {
password_size += 1024;
password_realloc = realloc(password, password_size);
// reset password if realloc fails.
if (password_realloc == NULL) {
password_size = 1024;
free(password);
password = malloc(password_size);
password[0] = '\0';
break;
} else {
password = password_realloc;
}
}
password[i] = (char)codepoint;
password[i + 1] = '\0';
break;
}
} }
if (redraw_screen) { if (redraw_screen) {
render(&render_data, config); render(&render_data, config);

Loading…
Cancel
Save