📄 events.c
字号:
/***************************************************************************** * events.c: Windows DirectX video output events handler ***************************************************************************** * Copyright (C) 2001-2004 VideoLAN * $Id: events.c 10831 2005-04-26 14:27:47Z gbazin $ * * Authors: Gildas Bazin <gbazin@videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble: This file contains the functions related to the creation of * a window and the handling of its messages (events). *****************************************************************************/#include <errno.h> /* ENOMEM */#include <stdlib.h> /* free() */#include <ctype.h> /* tolower() */#include <string.h> /* strerror() */#ifndef _WIN32_WINNT# define _WIN32_WINNT 0x0400#endif#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/input.h>#include <vlc/vout.h>#include <windows.h>#include <windowsx.h>#include <shellapi.h>#include <ddraw.h>#include "vlc_keys.h"#include "vout.h"/***************************************************************************** * Local prototypes. *****************************************************************************/static int DirectXCreateWindow( vout_thread_t *p_vout );static void DirectXCloseWindow ( vout_thread_t *p_vout );static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );static int Control( vout_thread_t *p_vout, int i_query, va_list args );static void DirectXPopupMenu( event_thread_t *p_event, vlc_bool_t b_open ){ playlist_t *p_playlist = vlc_object_find( p_event, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist != NULL ) { vlc_value_t val; val.b_bool = b_open; var_Set( p_playlist, "intf-popupmenu", val ); vlc_object_release( p_playlist ); }}static int DirectXConvertKey( int i_key );/***************************************************************************** * DirectXEventThread: Create video window & handle its messages ***************************************************************************** * This function creates a video window and then enters an infinite loop * that handles the messages sent to that window. * The main goal of this thread is to isolate the Win32 PeekMessage function * because this one can block for a long time. *****************************************************************************/void E_(DirectXEventThread)( event_thread_t *p_event ){ MSG msg; POINT old_mouse_pos = {0,0}, mouse_pos; vlc_value_t val; int i_width, i_height, i_x, i_y; HMODULE hkernel32; /* Initialisation */ p_event->p_vout->pf_control = Control; /* Create a window for the video */ /* Creating a window under Windows also initializes the thread's event * message queue */ if( DirectXCreateWindow( p_event->p_vout ) ) { msg_Err( p_event, "out of memory" ); p_event->b_dead = VLC_TRUE; } /* Signal the creation of the window */ vlc_thread_ready( p_event ); /* Set power management stuff */ if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) ) { ULONG (WINAPI* OurSetThreadExecutionState)( ULONG ); OurSetThreadExecutionState = (ULONG (WINAPI*)( ULONG )) GetProcAddress( hkernel32, _T("SetThreadExecutionState") ); if( OurSetThreadExecutionState ) /* Prevent monitor from powering off */ OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS ); else msg_Dbg( p_event, "no support for SetThreadExecutionState()" ); } /* Main loop */ /* GetMessage will sleep if there's no message in the queue */ while( !p_event->b_die && GetMessage( &msg, 0, 0, 0 ) ) { /* Check if we are asked to exit */ if( p_event->b_die ) break; switch( msg.message ) { case WM_MOUSEMOVE: vout_PlacePicture( p_event->p_vout, p_event->p_vout->p_sys->i_window_width, p_event->p_vout->p_sys->i_window_height, &i_x, &i_y, &i_width, &i_height ); if( msg.hwnd == p_event->p_vout->p_sys->hvideownd ) { /* Child window */ i_x = i_y = 0; } if( i_width && i_height ) { val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x ) * p_event->p_vout->render.i_width / i_width; var_Set( p_event->p_vout, "mouse-x", val ); val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y ) * p_event->p_vout->render.i_height / i_height; var_Set( p_event->p_vout, "mouse-y", val ); val.b_bool = VLC_TRUE; var_Set( p_event->p_vout, "mouse-moved", val ); } case WM_NCMOUSEMOVE: GetCursorPos( &mouse_pos ); if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 || (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) ) { GetCursorPos( &old_mouse_pos ); p_event->p_vout->p_sys->i_lastmoved = mdate(); if( p_event->p_vout->p_sys->b_cursor_hidden ) { p_event->p_vout->p_sys->b_cursor_hidden = 0; ShowCursor( TRUE ); } } break; case WM_VLC_HIDE_MOUSE: if( p_event->p_vout->p_sys->b_cursor_hidden ) break; p_event->p_vout->p_sys->b_cursor_hidden = VLC_TRUE; GetCursorPos( &old_mouse_pos ); ShowCursor( FALSE ); break; case WM_VLC_SHOW_MOUSE: if( !p_event->p_vout->p_sys->b_cursor_hidden ) break; p_event->p_vout->p_sys->b_cursor_hidden = VLC_FALSE; GetCursorPos( &old_mouse_pos ); ShowCursor( TRUE ); break; case WM_LBUTTONDOWN: var_Get( p_event->p_vout, "mouse-button-down", &val ); val.i_int |= 1; var_Set( p_event->p_vout, "mouse-button-down", val ); DirectXPopupMenu( p_event, VLC_FALSE ); break; case WM_LBUTTONUP: var_Get( p_event->p_vout, "mouse-button-down", &val ); val.i_int &= ~1; var_Set( p_event->p_vout, "mouse-button-down", val ); val.b_bool = VLC_TRUE; var_Set( p_event->p_vout, "mouse-clicked", val ); break; case WM_LBUTTONDBLCLK: p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE; break; case WM_MBUTTONDOWN: var_Get( p_event->p_vout, "mouse-button-down", &val ); val.i_int |= 2; var_Set( p_event->p_vout, "mouse-button-down", val ); DirectXPopupMenu( p_event, VLC_FALSE ); break; case WM_MBUTTONUP: var_Get( p_event->p_vout, "mouse-button-down", &val ); val.i_int &= ~2; var_Set( p_event->p_vout, "mouse-button-down", val ); break; case WM_RBUTTONDOWN: var_Get( p_event->p_vout, "mouse-button-down", &val ); val.i_int |= 4; var_Set( p_event->p_vout, "mouse-button-down", val ); DirectXPopupMenu( p_event, VLC_FALSE ); break; case WM_RBUTTONUP: var_Get( p_event->p_vout, "mouse-button-down", &val ); val.i_int &= ~4; var_Set( p_event->p_vout, "mouse-button-down", val ); DirectXPopupMenu( p_event, VLC_TRUE ); break; case WM_KEYDOWN: case WM_SYSKEYDOWN: /* The key events are first processed here and not translated * into WM_CHAR events because we need to know the status of the * modifier keys. */ val.i_int = DirectXConvertKey( msg.wParam ); if( !val.i_int ) { /* This appears to be a "normal" (ascii) key */ val.i_int = tolower( MapVirtualKey( msg.wParam, 2 ) ); } if( val.i_int ) { if( GetKeyState(VK_CONTROL) & 0x8000 ) { val.i_int |= KEY_MODIFIER_CTRL; } if( GetKeyState(VK_SHIFT) & 0x8000 ) { val.i_int |= KEY_MODIFIER_SHIFT; } if( GetKeyState(VK_MENU) & 0x8000 ) { val.i_int |= KEY_MODIFIER_ALT; } var_Set( p_event->p_vlc, "key-pressed", val ); } break; case WM_MOUSEWHEEL: if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 ) { val.i_int = KEY_MOUSEWHEELUP; } else { val.i_int = KEY_MOUSEWHEELDOWN; } if( val.i_int ) { if( GetKeyState(VK_CONTROL) & 0x8000 ) { val.i_int |= KEY_MODIFIER_CTRL; } if( GetKeyState(VK_SHIFT) & 0x8000 ) { val.i_int |= KEY_MODIFIER_SHIFT; } if( GetKeyState(VK_MENU) & 0x8000 ) { val.i_int |= KEY_MODIFIER_ALT; } var_Set( p_event->p_vlc, "key-pressed", val ); } break; case WM_VLC_CHANGE_TEXT: var_Get( p_event->p_vout, "video-title", &val ); if( !val.psz_string || !*val.psz_string ) /* Default video title */ {#ifdef MODULE_NAME_IS_glwin32 SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE) _T(" (OpenGL output)") );#else if( p_event->p_vout->p_sys->b_using_overlay ) SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE) _T(" (hardware YUV overlay DirectX output)") ); else if( p_event->p_vout->p_sys->b_hw_yuv ) SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE) _T(" (hardware YUV DirectX output)") ); else SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE) _T(" (software RGB DirectX output)") );#endif } else { SetWindowText( p_event->p_vout->p_sys->hwnd, val.psz_string );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -