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:
|
||||
LOGD("User requested to quit");
|
||||
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:
|
||||
if (!options->control) {
|
||||
break;
|
||||
|
@ -244,6 +229,10 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool consumed = screen_handle_event(&screen, event);
|
||||
(void) consumed;
|
||||
|
||||
return EVENT_RESULT_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "events.h"
|
||||
#include "icon.xpm"
|
||||
#include "scrcpy.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) {
|
||||
const AVFrame *frame = video_buffer_take_rendering_frame(screen->vb);
|
||||
struct size new_frame_size = {frame->width, frame->height};
|
||||
|
@ -540,7 +541,7 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
|||
content_size.height);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
screen_handle_window_event(struct screen *screen,
|
||||
const SDL_WindowEvent *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
|
||||
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
|
|
|
@ -91,10 +91,6 @@ screen_show_window(struct screen *screen);
|
|||
void
|
||||
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
|
||||
//
|
||||
// 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
|
||||
screen_set_rotation(struct screen *screen, unsigned rotation);
|
||||
|
||||
// react to window events
|
||||
void
|
||||
screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event);
|
||||
// react to SDL events
|
||||
bool
|
||||
screen_handle_event(struct screen *screen, SDL_Event *event);
|
||||
|
||||
// convert point from window coordinates to frame coordinates
|
||||
// x and y are expressed in pixels
|
||||
|
|
Loading…
Reference in a new issue