Handle screen-related events from screen.c
This commit is contained in:
parent
ea2369f568
commit
50b4a730e3
3 changed files with 37 additions and 24 deletions
|
@ -173,21 +173,6 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
LOGD("User requested to quit");
|
LOGD("User requested to quit");
|
||||||
return EVENT_RESULT_STOPPED_BY_USER;
|
return EVENT_RESULT_STOPPED_BY_USER;
|
||||||
case EVENT_NEW_FRAME:
|
|
||||||
if (!screen.has_frame) {
|
|
||||||
screen.has_frame = true;
|
|
||||||
// this is the very first frame, show the window
|
|
||||||
screen_show_window(&screen);
|
|
||||||
}
|
|
||||||
if (!screen_update_frame(&screen)) {
|
|
||||||
return EVENT_RESULT_CONTINUE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
if (screen.has_frame) {
|
|
||||||
screen_handle_window_event(&screen, &event->window);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_TEXTINPUT:
|
case SDL_TEXTINPUT:
|
||||||
if (!options->control) {
|
if (!options->control) {
|
||||||
break;
|
break;
|
||||||
|
@ -244,6 +229,10 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool consumed = screen_handle_event(&screen, event);
|
||||||
|
(void) consumed;
|
||||||
|
|
||||||
return EVENT_RESULT_CONTINUE;
|
return EVENT_RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "events.h"
|
||||||
#include "icon.xpm"
|
#include "icon.xpm"
|
||||||
#include "scrcpy.h"
|
#include "scrcpy.h"
|
||||||
#include "tiny_xpm.h"
|
#include "tiny_xpm.h"
|
||||||
|
@ -446,7 +447,7 @@ update_texture(struct screen *screen, const AVFrame *frame) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
screen_update_frame(struct screen *screen) {
|
screen_update_frame(struct screen *screen) {
|
||||||
const AVFrame *frame = video_buffer_take_rendering_frame(screen->vb);
|
const AVFrame *frame = video_buffer_take_rendering_frame(screen->vb);
|
||||||
struct size new_frame_size = {frame->width, frame->height};
|
struct size new_frame_size = {frame->width, frame->height};
|
||||||
|
@ -540,7 +541,7 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||||
content_size.height);
|
content_size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
screen_handle_window_event(struct screen *screen,
|
screen_handle_window_event(struct screen *screen,
|
||||||
const SDL_WindowEvent *event) {
|
const SDL_WindowEvent *event) {
|
||||||
switch (event->event) {
|
switch (event->event) {
|
||||||
|
@ -567,6 +568,33 @@ screen_handle_window_event(struct screen *screen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
screen_handle_event(struct screen *screen, SDL_Event *event) {
|
||||||
|
switch (event->type) {
|
||||||
|
case EVENT_NEW_FRAME:
|
||||||
|
if (!screen->has_frame) {
|
||||||
|
screen->has_frame = true;
|
||||||
|
// this is the very first frame, show the window
|
||||||
|
screen_show_window(screen);
|
||||||
|
}
|
||||||
|
bool ok = screen_update_frame(screen);
|
||||||
|
if (!ok) {
|
||||||
|
LOGW("Frame update failed\n");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
if (!screen->has_frame) {
|
||||||
|
// Do nothing
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
screen_handle_window_event(screen, &event->window);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
struct point
|
struct point
|
||||||
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||||
int32_t x, int32_t y) {
|
int32_t x, int32_t y) {
|
||||||
|
|
|
@ -91,10 +91,6 @@ screen_show_window(struct screen *screen);
|
||||||
void
|
void
|
||||||
screen_destroy(struct screen *screen);
|
screen_destroy(struct screen *screen);
|
||||||
|
|
||||||
// resize if necessary and write the rendered frame into the texture
|
|
||||||
bool
|
|
||||||
screen_update_frame(struct screen *screen);
|
|
||||||
|
|
||||||
// render the texture to the renderer
|
// render the texture to the renderer
|
||||||
//
|
//
|
||||||
// Set the update_content_rect flag if the window or content size may have
|
// Set the update_content_rect flag if the window or content size may have
|
||||||
|
@ -118,9 +114,9 @@ screen_resize_to_pixel_perfect(struct screen *screen);
|
||||||
void
|
void
|
||||||
screen_set_rotation(struct screen *screen, unsigned rotation);
|
screen_set_rotation(struct screen *screen, unsigned rotation);
|
||||||
|
|
||||||
// react to window events
|
// react to SDL events
|
||||||
void
|
bool
|
||||||
screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event);
|
screen_handle_event(struct screen *screen, SDL_Event *event);
|
||||||
|
|
||||||
// convert point from window coordinates to frame coordinates
|
// convert point from window coordinates to frame coordinates
|
||||||
// x and y are expressed in pixels
|
// x and y are expressed in pixels
|
||||||
|
|
Loading…
Reference in a new issue