Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL2: handle SDL_WINDOWEVENT_EXPOSED #624

Merged
merged 2 commits into from
Mar 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions ffi/SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ local function genEmuEvent(evtype, code, value)
table.insert(inputQueue, ev)
end

local function handleWindowEvent(event_window)
-- The next buffer might always contain garbage, and on X11 without
-- compositing the buffers will be damaged just by moving the window
-- partly offscreen, minimizing it, or putting another window
-- (partially) on top of it.
-- Handling `SDL_WINDOWEVENT_EXPOSED` is the only way to deal with
-- this without sending regular updates.
if event_window.event == SDL.SDL_WINDOWEVENT_EXPOSED then
SDL.SDL_RenderCopy(S.renderer, S.texture, nil, nil)
SDL.SDL_RenderPresent(S.renderer)
elseif (event_window.event == SDL.SDL_WINDOWEVENT_RESIZED
or event_window.event == SDL.SDL_WINDOWEVENT_SIZE_CHANGED) then
local w = 0
local h = 1
local new_size_w = event_window.data1
local new_size_h = event_window.data2

if new_size_w and new_size_h then
genEmuEvent(ffi.C.EV_MSC, w, new_size_w)
genEmuEvent(ffi.C.EV_MSC, h, new_size_h)
genEmuEvent(ffi.C.EV_MSC, SDL.SDL_WINDOWEVENT_RESIZED, 0)
end
end
end

local is_in_touch = false
local dropped_file_path

Expand Down Expand Up @@ -185,19 +210,8 @@ function S.waitForEvent(usecs)
elseif event.type == SDL.SDL_DROPFILE then
dropped_file_path = ffi.string(event.drop.file)
genEmuEvent(ffi.C.EV_MSC, SDL.SDL_DROPFILE, 0)
elseif event.type == SDL.SDL_WINDOWEVENT
and (event.window.event == SDL.SDL_WINDOWEVENT_RESIZED
or event.window.event == SDL.SDL_WINDOWEVENT_SIZE_CHANGED) then
local w = 0
local h = 1
local new_size_w = event.window.data1
local new_size_h = event.window.data2

if new_size_w and new_size_h then
genEmuEvent(ffi.C.EV_MSC, w, new_size_w)
genEmuEvent(ffi.C.EV_MSC, h, new_size_h)
genEmuEvent(ffi.C.EV_MSC, SDL.SDL_WINDOWEVENT_RESIZED, 0)
end
elseif event.type == SDL.SDL_WINDOWEVENT then
handleWindowEvent(event.window)
elseif event.type == SDL.SDL_QUIT then
-- send Alt + F4
genEmuEvent(ffi.C.EV_KEY, 226, 1)
Expand Down