Turn screen on on right-click

The right-click is almost useless on Android, so use it to turn the
screen on.

Add a new control event type (command) to request the server to turn the
screen on.
This commit is contained in:
Romain Vimont
2018-02-02 14:52:23 +01:00
parent 228545cefd
commit a139509f11
9 changed files with 107 additions and 1 deletions

View File

@@ -52,6 +52,9 @@ int control_event_serialize(const struct control_event *event, unsigned char *bu
write32(&buf[9], (Uint32) event->scroll_event.hscroll);
write32(&buf[13], (Uint32) event->scroll_event.vscroll);
return 17;
case CONTROL_EVENT_TYPE_COMMAND:
buf[1] = event->command_event.action;
return 2;
default:
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u", (unsigned) event->type);
return 0;

View File

@@ -17,8 +17,11 @@ enum control_event_type {
CONTROL_EVENT_TYPE_TEXT,
CONTROL_EVENT_TYPE_MOUSE,
CONTROL_EVENT_TYPE_SCROLL,
CONTROL_EVENT_TYPE_COMMAND,
};
#define CONTROL_EVENT_COMMAND_SCREEN_ON 0
struct control_event {
enum control_event_type type;
union {
@@ -40,6 +43,9 @@ struct control_event {
Sint32 hscroll;
Sint32 vscroll;
} scroll_event;
struct {
int action;
} command_event;
};
};

View File

@@ -293,6 +293,18 @@ static void send_keycode(enum android_keycode keycode, const char *name) {
}
}
static void turn_screen_on(void) {
struct control_event control_event = {
.type = CONTROL_EVENT_TYPE_COMMAND,
.command_event = {
.action = CONTROL_EVENT_COMMAND_SCREEN_ON,
},
};
if (!controller_push_event(&controller, &control_event)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot turn screen on");
}
}
static SDL_bool handle_new_frame(void) {
mutex_lock(frames.mutex);
AVFrame *frame = frames.rendering_frame;
@@ -432,6 +444,10 @@ static void handle_mouse_motion(const SDL_MouseMotionEvent *event, struct size s
}
static void handle_mouse_button(const SDL_MouseButtonEvent *event, struct size screen_size) {
if (event->button == SDL_BUTTON_RIGHT) {
turn_screen_on();
return;
};
struct control_event control_event;
if (mouse_button_from_sdl_to_android(event, screen_size, &control_event)) {
if (!controller_push_event(&controller, &control_event)) {