# Path: modules/sdl2/common/events.py
# def events_for(subsystem):
#     """ Get all pending events relevant for a certain subsystem. """
#     _pump_events()
#     if subsystem in _pending_events:
#         return _pending_events.pop(subsystem)
#     return []
# 
# def handle_events():
#     """ Handle system events. """
#     for ev in events_for('system'):
#         if ev.type == sdl2.SDL_APP_WILLENTERBACKGROUND:
#             rave.events.emit('game.suspend')
#         elif ev.type == sdl2.SDL_APP_DIDENTERBACKGROUND:
#             rave.events.emit('game.suspended')
#         elif ev.type == sdl2.SDL_APP_WILLENTERFOREGROUND:
#             rave.events.emit('game.resume')
#         elif ev.type == sdl2.SDL_APP_DIDENTERFOREGROUND:
#             rave.events.emit('game.resumed')


import sdl2
import rave.log
import rave.events
from ..common import events_for, handle_events as handle_system_events
def handle_events():
    # Handle system events.
    handle_system_events()

    for ev in events_for('video'):
        # Dispatch events.
        if ev.type == sdl2.SDL_WINDOWEVENT:
            window = ev.window.windowID

            if ev.window.event == sdl2.SDL_WINDOWEVENT_SHOWN:
                rave.events.emit('video.window.shown', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_HIDDEN:
                rave.events.emit('video.window.hidden', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_EXPOSED:
                rave.events.emit('video.window.exposed', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_MOVED:
                rave.events.emit('video.window.moved', window, ev.window.data1, ev.window.data2)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_SIZE_CHANGED:
                # Handled in SDL_WINDOWEVENT_RESIZED.
                pass
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_RESIZED:
                rave.events.emit('video.window.resized', window, ev.window.data1, ev.window.data2)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_MINIMIZED:
                rave.events.emit('video.window.minimized', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_MAXIMIZED:
                rave.events.emit('video.window.maximized', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_RESTORED:
                rave.events.emit('video.window.restored', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_ENTER:
                rave.events.emit('video.window.focused', window, 'mouse')

# Path: modules/sdl2/common/events.py
# def events_for(subsystem):
#     """ Get all pending events relevant for a certain subsystem. """
#     _pump_events()
#     if subsystem in _pending_events:
#         return _pending_events.pop(subsystem)
#     return []
# 
# def handle_events():
#     """ Handle system events. """
#     for ev in events_for('system'):
#         if ev.type == sdl2.SDL_APP_WILLENTERBACKGROUND:
#             rave.events.emit('game.suspend')
#         elif ev.type == sdl2.SDL_APP_DIDENTERBACKGROUND:
#             rave.events.emit('game.suspended')
#         elif ev.type == sdl2.SDL_APP_WILLENTERFOREGROUND:
#             rave.events.emit('game.resume')
#         elif ev.type == sdl2.SDL_APP_DIDENTERFOREGROUND:
#             rave.events.emit('game.resumed')


# Path: modules/sdl2/video/events.py
import sdl2
import rave.log
import rave.events
from ..common import events_for, handle_events as handle_system_events

def handle_events():
    # Handle system events.
    handle_system_events()

    for ev in events_for('video'):
        # Dispatch events.
        if ev.type == sdl2.SDL_WINDOWEVENT:
            window = ev.window.windowID

            if ev.window.event == sdl2.SDL_WINDOWEVENT_SHOWN:
                rave.events.emit('video.window.shown', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_HIDDEN:
                rave.events.emit('video.window.hidden', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_EXPOSED:
                rave.events.emit('video.window.exposed', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_MOVED:
                rave.events.emit('video.window.moved', window, ev.window.data1, ev.window.data2)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_SIZE_CHANGED:
                # Handled in SDL_WINDOWEVENT_RESIZED.
                pass
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_RESIZED:
                rave.events.emit('video.window.resized', window, ev.window.data1, ev.window.data2)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_MINIMIZED:
                rave.events.emit('video.window.minimized', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_MAXIMIZED:
                rave.events.emit('video.window.maximized', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_RESTORED:
                rave.events.emit('video.window.restored', window)
            elif ev.window.event == sdl2.SDL_WINDOWEVENT_ENTER:
                rave.events.emit('video.window.focused', window, 'mouse')

            elif ev.window.event == sdl2.SDL_WINDOWEVENT_LEAVE: