Remove redundant control boolean

The controller is NULL if and only if control is disabled, so an
additional control boolean is redundant.
raw_video_stream
Romain Vimont 2 years ago
parent 557daf280e
commit 855819bbd8

@ -124,8 +124,8 @@ is_shortcut_mod(struct sc_input_manager *im, uint16_t sdl_mod) {
void void
sc_input_manager_init(struct sc_input_manager *im, sc_input_manager_init(struct sc_input_manager *im,
const struct sc_input_manager_params *params) { const struct sc_input_manager_params *params) {
assert(!params->control || (params->kp && params->kp->ops)); assert(!params->controller || (params->kp && params->kp->ops));
assert(!params->control || (params->mp && params->mp->ops)); assert(!params->controller || (params->mp && params->mp->ops));
im->controller = params->controller; im->controller = params->controller;
im->fp = params->fp; im->fp = params->fp;
@ -133,7 +133,6 @@ sc_input_manager_init(struct sc_input_manager *im,
im->kp = params->kp; im->kp = params->kp;
im->mp = params->mp; im->mp = params->mp;
im->control = params->control;
im->forward_all_clicks = params->forward_all_clicks; im->forward_all_clicks = params->forward_all_clicks;
im->legacy_paste = params->legacy_paste; im->legacy_paste = params->legacy_paste;
im->clipboard_autosync = params->clipboard_autosync; im->clipboard_autosync = params->clipboard_autosync;
@ -434,9 +433,7 @@ inverse_point(struct sc_point point, struct sc_size size) {
static void static void
sc_input_manager_process_key(struct sc_input_manager *im, sc_input_manager_process_key(struct sc_input_manager *im,
const SDL_KeyboardEvent *event) { const SDL_KeyboardEvent *event) {
// control: indicates the state of the command-line option --no-control // controller is NULL if --no-control is requested
bool control = im->control;
struct sc_controller *controller = im->controller; struct sc_controller *controller = im->controller;
SDL_Keycode keycode = event->keysym.sym; SDL_Keycode keycode = event->keysym.sym;
@ -463,33 +460,33 @@ sc_input_manager_process_key(struct sc_input_manager *im,
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP; enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
switch (keycode) { switch (keycode) {
case SDLK_h: case SDLK_h:
if (control && !shift && !repeat) { if (controller && !shift && !repeat) {
action_home(controller, action); action_home(controller, action);
} }
return; return;
case SDLK_b: // fall-through case SDLK_b: // fall-through
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
if (control && !shift && !repeat) { if (controller && !shift && !repeat) {
action_back(controller, action); action_back(controller, action);
} }
return; return;
case SDLK_s: case SDLK_s:
if (control && !shift && !repeat) { if (controller && !shift && !repeat) {
action_app_switch(controller, action); action_app_switch(controller, action);
} }
return; return;
case SDLK_m: case SDLK_m:
if (control && !shift && !repeat) { if (controller && !shift && !repeat) {
action_menu(controller, action); action_menu(controller, action);
} }
return; return;
case SDLK_p: case SDLK_p:
if (control && !shift && !repeat) { if (controller && !shift && !repeat) {
action_power(controller, action); action_power(controller, action);
} }
return; return;
case SDLK_o: case SDLK_o:
if (control && !repeat && down) { if (controller && !repeat && down) {
enum screen_power_mode mode = shift enum screen_power_mode mode = shift
? SCREEN_POWER_MODE_NORMAL ? SCREEN_POWER_MODE_NORMAL
: SCREEN_POWER_MODE_OFF; : SCREEN_POWER_MODE_OFF;
@ -497,13 +494,13 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_DOWN: case SDLK_DOWN:
if (control && !shift) { if (controller && !shift) {
// forward repeated events // forward repeated events
action_volume_down(controller, action); action_volume_down(controller, action);
} }
return; return;
case SDLK_UP: case SDLK_UP:
if (control && !shift) { if (controller && !shift) {
// forward repeated events // forward repeated events
action_volume_up(controller, action); action_volume_up(controller, action);
} }
@ -519,19 +516,19 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_c: case SDLK_c:
if (control && !shift && !repeat && down) { if (controller && !shift && !repeat && down) {
get_device_clipboard(controller, get_device_clipboard(controller,
GET_CLIPBOARD_COPY_KEY_COPY); GET_CLIPBOARD_COPY_KEY_COPY);
} }
return; return;
case SDLK_x: case SDLK_x:
if (control && !shift && !repeat && down) { if (controller && !shift && !repeat && down) {
get_device_clipboard(controller, get_device_clipboard(controller,
GET_CLIPBOARD_COPY_KEY_CUT); GET_CLIPBOARD_COPY_KEY_CUT);
} }
return; return;
case SDLK_v: case SDLK_v:
if (control && !repeat && down) { if (controller && !repeat && down) {
if (shift || im->legacy_paste) { if (shift || im->legacy_paste) {
// inject the text as input events // inject the text as input events
clipboard_paste(controller); clipboard_paste(controller);
@ -564,7 +561,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_n: case SDLK_n:
if (control && !repeat && down) { if (controller && !repeat && down) {
if (shift) { if (shift) {
collapse_panels(controller); collapse_panels(controller);
} else if (im->key_repeat == 0) { } else if (im->key_repeat == 0) {
@ -575,7 +572,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_r: case SDLK_r:
if (control && !shift && !repeat && down) { if (controller && !shift && !repeat && down) {
rotate_device(controller); rotate_device(controller);
} }
return; return;
@ -584,7 +581,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
return; return;
} }
if (!control) { if (!controller) {
return; return;
} }
@ -701,7 +698,7 @@ sc_input_manager_process_touch(struct sc_input_manager *im,
static void static void
sc_input_manager_process_mouse_button(struct sc_input_manager *im, sc_input_manager_process_mouse_button(struct sc_input_manager *im,
const SDL_MouseButtonEvent *event) { const SDL_MouseButtonEvent *event) {
bool control = im->control; struct sc_controller *controller = im->controller;
if (event->which == SDL_TOUCH_MOUSEID) { if (event->which == SDL_TOUCH_MOUSEID) {
// simulated from touch events, so it's a duplicate // simulated from touch events, so it's a duplicate
@ -712,24 +709,24 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,
if (!im->forward_all_clicks) { if (!im->forward_all_clicks) {
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP; enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
if (control && event->button == SDL_BUTTON_X1) { if (controller && event->button == SDL_BUTTON_X1) {
action_app_switch(im->controller, action); action_app_switch(controller, action);
return; return;
} }
if (control && event->button == SDL_BUTTON_X2 && down) { if (controller && event->button == SDL_BUTTON_X2 && down) {
if (event->clicks < 2) { if (event->clicks < 2) {
expand_notification_panel(im->controller); expand_notification_panel(controller);
} else { } else {
expand_settings_panel(im->controller); expand_settings_panel(controller);
} }
return; return;
} }
if (control && event->button == SDL_BUTTON_RIGHT) { if (controller && event->button == SDL_BUTTON_RIGHT) {
press_back_or_turn_screen_on(im->controller, action); press_back_or_turn_screen_on(controller, action);
return; return;
} }
if (control && event->button == SDL_BUTTON_MIDDLE) { if (controller && event->button == SDL_BUTTON_MIDDLE) {
action_home(im->controller, action); action_home(controller, action);
return; return;
} }
@ -751,7 +748,7 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,
// otherwise, send the click event to the device // otherwise, send the click event to the device
} }
if (!control) { if (!controller) {
return; return;
} }
@ -865,9 +862,10 @@ sc_input_manager_process_file(struct sc_input_manager *im,
void void
sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) { sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) {
bool control = im->controller;
switch (event->type) { switch (event->type) {
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
if (!im->control) { if (!control) {
break; break;
} }
sc_input_manager_process_text_input(im, &event->text); sc_input_manager_process_text_input(im, &event->text);
@ -879,13 +877,13 @@ sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) {
sc_input_manager_process_key(im, &event->key); sc_input_manager_process_key(im, &event->key);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (!im->control) { if (!control) {
break; break;
} }
sc_input_manager_process_mouse_motion(im, &event->motion); sc_input_manager_process_mouse_motion(im, &event->motion);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
if (!im->control) { if (!control) {
break; break;
} }
sc_input_manager_process_mouse_wheel(im, &event->wheel); sc_input_manager_process_mouse_wheel(im, &event->wheel);
@ -899,13 +897,13 @@ sc_input_manager_handle_event(struct sc_input_manager *im, SDL_Event *event) {
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
case SDL_FINGERDOWN: case SDL_FINGERDOWN:
case SDL_FINGERUP: case SDL_FINGERUP:
if (!im->control) { if (!control) {
break; break;
} }
sc_input_manager_process_touch(im, &event->tfinger); sc_input_manager_process_touch(im, &event->tfinger);
break; break;
case SDL_DROPFILE: { case SDL_DROPFILE: {
if (!im->control) { if (!control) {
break; break;
} }
sc_input_manager_process_file(im, &event->drop); sc_input_manager_process_file(im, &event->drop);

@ -22,7 +22,6 @@ struct sc_input_manager {
struct sc_key_processor *kp; struct sc_key_processor *kp;
struct sc_mouse_processor *mp; struct sc_mouse_processor *mp;
bool control;
bool forward_all_clicks; bool forward_all_clicks;
bool legacy_paste; bool legacy_paste;
bool clipboard_autosync; bool clipboard_autosync;
@ -51,7 +50,6 @@ struct sc_input_manager_params {
struct sc_key_processor *kp; struct sc_key_processor *kp;
struct sc_mouse_processor *mp; struct sc_mouse_processor *mp;
bool control;
bool forward_all_clicks; bool forward_all_clicks;
bool legacy_paste; bool legacy_paste;
bool clipboard_autosync; bool clipboard_autosync;

@ -525,6 +525,9 @@ aoa_hid_end:
} }
// There is a controller if and only if control is enabled
assert(options->control == !!controller);
if (options->display) { if (options->display) {
const char *window_title = const char *window_title =
options->window_title ? options->window_title : info->device_name; options->window_title ? options->window_title : info->device_name;
@ -534,7 +537,6 @@ aoa_hid_end:
.fp = fp, .fp = fp,
.kp = kp, .kp = kp,
.mp = mp, .mp = mp,
.control = options->control,
.forward_all_clicks = options->forward_all_clicks, .forward_all_clicks = options->forward_all_clicks,
.legacy_paste = options->legacy_paste, .legacy_paste = options->legacy_paste,
.clipboard_autosync = options->clipboard_autosync, .clipboard_autosync = options->clipboard_autosync,

@ -489,7 +489,6 @@ sc_screen_init(struct sc_screen *screen,
.screen = screen, .screen = screen,
.kp = params->kp, .kp = params->kp,
.mp = params->mp, .mp = params->mp,
.control = params->control,
.forward_all_clicks = params->forward_all_clicks, .forward_all_clicks = params->forward_all_clicks,
.legacy_paste = params->legacy_paste, .legacy_paste = params->legacy_paste,
.clipboard_autosync = params->clipboard_autosync, .clipboard_autosync = params->clipboard_autosync,

@ -74,7 +74,6 @@ struct sc_screen_params {
struct sc_key_processor *kp; struct sc_key_processor *kp;
struct sc_mouse_processor *mp; struct sc_mouse_processor *mp;
bool control;
bool forward_all_clicks; bool forward_all_clicks;
bool legacy_paste; bool legacy_paste;
bool clipboard_autosync; bool clipboard_autosync;

Loading…
Cancel
Save