1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /* XXX: disable VLC here */
27 /*****************************************************************************
29 *****************************************************************************/
42 #ifdef HAVE_MOZILLA_CONFIG_H
43 # include <mozilla-config.h>
45 #include <nsISupports.h>
48 #include <npruntime.h>
50 /* This is from mozilla java, do we really need it? */
55 #include "vlcplugin.h"
56 #include "vlcruntime.h"
59 # define WINDOW_TEXT "(no picture)"
61 # define WINDOW_TEXT "(no libvlc)"
64 /* Enable/disable debugging printf's for X11 resizing */
65 #undef X11_RESIZE_DEBUG
67 /*****************************************************************************
68 * Unix-only declarations
69 ******************************************************************************/
71 # define VOUT_PLUGINS "xvideo,x11,dummy"
72 # define AOUT_PLUGINS "esd,arts,alsa,oss,dummy"
74 static unsigned int i_previous_height = 100000;
75 static unsigned int i_previous_width = 100000;
77 static void Redraw( Widget w, XtPointer closure, XEvent *event );
78 static void Resize( Widget w, XtPointer closure, XEvent *event );
81 /*****************************************************************************
82 * MacOS-only declarations
83 ******************************************************************************/
85 # define VOUT_PLUGINS "opengl,macosx,dummy"
86 # define AOUT_PLUGINS "auhal,macosx,dummy"
90 /*****************************************************************************
91 * Windows-only declarations
92 *****************************************************************************/
94 # define VOUT_PLUGINS "directx,wingdi,dummy"
95 # define AOUT_PLUGINS "directx,waveout,dummy"
97 #if defined(XP_WIN) && !USE_LIBVLC
98 LRESULT CALLBACK Manage( HWND, UINT, WPARAM, LPARAM );
102 /******************************************************************************
103 * UNIX-only API calls
104 *****************************************************************************/
105 char * NPP_GetMIMEDescription( void )
107 return PLUGIN_MIMETYPES;
110 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
113 static nsIID nsid = VLCINTF_IID;
114 static char psz_desc[1000];
118 case NPPVpluginNameString:
119 *((char **)value) = PLUGIN_NAME;
120 return NPERR_NO_ERROR;
122 case NPPVpluginDescriptionString:
124 snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, VLC_Version() );
125 #else /* USE_LIBVLC */
126 snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, "(disabled)" );
127 #endif /* USE_LIBVLC */
128 psz_desc[1000-1] = 0;
129 *((char **)value) = psz_desc;
130 return NPERR_NO_ERROR;
137 if( instance == NULL )
139 return NPERR_INVALID_INSTANCE_ERROR;
142 VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
146 case NPPVpluginScriptableInstance:
147 *(nsISupports**)value = p_plugin->GetPeer();
148 if( *(nsISupports**)value == NULL )
150 return NPERR_OUT_OF_MEMORY_ERROR;
154 case NPPVpluginScriptableIID:
155 *(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
156 if( *(nsIID**)value == NULL )
158 return NPERR_OUT_OF_MEMORY_ERROR;
160 **(nsIID**)value = nsid;
163 case NPPVpluginScriptableNPObject:
164 static VlcRuntimeClass<VlcRuntimeRootObject> *rootClass = new VlcRuntimeClass<VlcRuntimeRootObject>;
165 *(NPObject**)value = NPN_CreateObject(instance, rootClass);
166 if( *(NPObject**)value == NULL )
168 return NPERR_OUT_OF_MEMORY_ERROR;
173 return NPERR_GENERIC_ERROR;
176 return NPERR_NO_ERROR;
179 /******************************************************************************
181 *****************************************************************************/
183 int16 NPP_HandleEvent( NPP instance, void * event )
185 if( instance == NULL )
190 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
191 EventRecord *myEvent = (EventRecord*)event;
193 switch( myEvent->what )
206 NPWindow *npwindow = p_plugin->window;
208 /* draw the beautiful "No Picture" */
210 ForeColor(blackColor);
216 rect.right = npwindow->width;
217 rect.bottom = npwindow->height;
220 ForeColor(whiteColor);
221 char *text = strdup( WINDOW_TEXT );
222 MoveTo( (npwindow->width-80)/ 2 , npwindow->height / 2 );
223 DrawText( text , 0 , strlen(text) );
230 case NPEventType_GetFocusEvent:
231 case NPEventType_LoseFocusEvent:
233 case NPEventType_AdjustCursorEvent:
235 case NPEventType_MenuCommandEvent:
237 case NPEventType_ClippingChangedEvent:
239 case NPEventType_ScrollingBeginsEvent:
240 case NPEventType_ScrollingEndsEvent:
247 #endif /* XP_MACOSX */
249 /******************************************************************************
250 * General Plug-in Calls
251 *****************************************************************************/
252 NPError NPP_Initialize( void )
254 return NPERR_NO_ERROR;
257 jref NPP_GetJavaClass( void )
262 void NPP_Shutdown( void )
267 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
268 char* argn[], char* argv[], NPSavedData* saved )
276 #endif /* USE_LIBVLC */
278 if( instance == NULL )
280 return NPERR_INVALID_INSTANCE_ERROR;
283 VlcPlugin * p_plugin = new VlcPlugin( instance );
285 if( p_plugin == NULL )
287 return NPERR_OUT_OF_MEMORY_ERROR;
290 instance->pdata = p_plugin;
293 p_plugin->p_hwnd = NULL;
294 p_plugin->pf_wndproc = NULL;
298 p_plugin->window = 0;
299 p_plugin->p_display = NULL;
302 p_plugin->p_npwin = NULL;
303 p_plugin->i_npmode = mode;
304 p_plugin->i_width = 0;
305 p_plugin->i_height = 0;
308 p_plugin->i_vlc = VLC_Create();
309 if( p_plugin->i_vlc < 0 )
314 return NPERR_GENERIC_ERROR;
324 "/Library/Internet Plug-Ins/VLC Plugin.plugin/"
325 "Contents/MacOS/modules"
328 #elif defined(XP_WIN)
329 char *ppsz_argv[] = { NULL, "-vv" };
331 DWORD i_type, i_data = MAX_PATH + 1;
332 char p_data[MAX_PATH + 1];
333 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
334 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
336 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
337 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
339 if( i_type == REG_SZ )
341 strcat( p_data, "\\vlc" );
342 ppsz_argv[0] = p_data;
345 RegCloseKey( h_key );
348 if( !ppsz_argv[0] ) ppsz_argv[0] = "vlc";
350 #else /* XP_MACOSX */
355 /*, "--plugin-path", ""*/
358 #endif /* XP_MACOSX */
360 /* HACK: special case for loop, to have it set before playlist startup
362 for( i = 0; i < argc ; i++ )
364 if( !strcmp( argn[i], "loop" ) )
366 if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "yes" ) )
368 value.b_bool = VLC_TRUE;
369 VLC_VariableSet( p_plugin->i_vlc, "conf::loop", value );
374 i_ret = VLC_Init( p_plugin->i_vlc, sizeof(ppsz_argv)/sizeof(char*),
381 VLC_Destroy( p_plugin->i_vlc );
385 return NPERR_GENERIC_ERROR;
388 value.psz_string = "dummy";
389 VLC_VariableSet( p_plugin->i_vlc, "conf::intf", value );
390 value.psz_string = VOUT_PLUGINS;
391 VLC_VariableSet( p_plugin->i_vlc, "conf::vout", value );
392 value.psz_string = AOUT_PLUGINS;
393 VLC_VariableSet( p_plugin->i_vlc, "conf::aout", value );
395 #else /* USE_LIBVLC */
398 #endif /* USE_LIBVLC */
400 p_plugin->b_stream = VLC_FALSE;
401 p_plugin->b_autoplay = VLC_FALSE;
402 p_plugin->psz_target = NULL;
404 for( i = 0; i < argc ; i++ )
406 if( !strcmp( argn[i], "target" ) )
408 p_plugin->psz_target = argv[i];
410 else if( !strcmp( argn[i], "autoplay" ) )
412 if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "yes" ) )
414 p_plugin->b_autoplay = 1;
417 else if( !strcmp( argn[i], "autostart" ) )
419 if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "true" ) )
421 p_plugin->b_autoplay = 1;
424 else if( !strcmp( argn[i], "filename" ) )
426 p_plugin->psz_target = argv[i];
428 else if( !strcmp( argn[i], "src" ) )
430 p_plugin->psz_target = argv[i];
434 else if( !strcmp( argn[i], "fullscreen" ) )
436 if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "yes" ) )
438 value.b_bool = VLC_TRUE;
439 VLC_VariableSet( p_plugin->i_vlc, "conf::fullscreen", value );
442 else if( !strcmp( argn[i], "mute" ) )
444 if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "yes" ) )
446 VLC_VolumeMute( p_plugin->i_vlc );
449 #endif /* USE_LIBVLC */
452 if( p_plugin->psz_target )
454 p_plugin->psz_target = strdup( p_plugin->psz_target );
457 return NPERR_NO_ERROR;
461 /* This is really ugly but there is a deadlock when stopping a stream
462 * (in VLC_CleanUp()) because the video output is a child of the drawable but
463 * is in a different thread. */
464 static void HackStopVout( VlcPlugin* p_plugin )
470 VLC_VariableGet( p_plugin->i_vlc, "drawable", &value );
472 hwnd = FindWindowEx( (HWND)value.i_int, 0, 0, 0 );
475 PostMessage( hwnd, WM_CLOSE, 0, 0 );
479 while( PeekMessage( &msg, (HWND)value.i_int, 0, 0, PM_REMOVE ) )
481 TranslateMessage(&msg);
482 DispatchMessage(&msg);
484 if( FindWindowEx( (HWND)value.i_int, 0, 0, 0 ) ) Sleep( 10 );
486 while( (hwnd = FindWindowEx( (HWND)value.i_int, 0, 0, 0 )) );
490 NPError NPP_Destroy( NPP instance, NPSavedData** save )
492 if( instance == NULL )
494 return NPERR_INVALID_INSTANCE_ERROR;
497 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
499 if( p_plugin != NULL )
501 if( p_plugin->i_vlc )
505 HackStopVout( p_plugin );
507 VLC_CleanUp( p_plugin->i_vlc );
508 VLC_Destroy( p_plugin->i_vlc );
509 #endif /* USE_LIBVLC */
513 if( p_plugin->psz_target )
515 free( p_plugin->psz_target );
516 p_plugin->psz_target = NULL;
522 instance->pdata = NULL;
524 return NPERR_NO_ERROR;
527 NPError NPP_SetWindow( NPP instance, NPWindow* window )
539 vlc_value_t valueportx;
540 vlc_value_t valueporty;
541 vlc_value_t valueredraw;
542 #endif /* XP_MACOSX */
544 if( instance == NULL )
546 return NPERR_INVALID_INSTANCE_ERROR;
549 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
551 /* Write the window ID for vlc */
555 value.i_int = (int)(((NP_Port*) (window->window))->port);
556 VLC_VariableSet( p_plugin->i_vlc, "drawable", value );
558 valueportx.i_int = ((NP_Port*) (window->window))->portx;
559 valueporty.i_int = ((NP_Port*) (window->window))->porty;
560 VLC_VariableSet( p_plugin->i_vlc, "drawableportx", valueportx );
561 VLC_VariableSet( p_plugin->i_vlc, "drawableporty", valueporty );
563 valuex.i_int = window->x;
564 valuey.i_int = window->y;
565 valuew.i_int = window->width;
566 valueh.i_int = window->height;
567 valuet.i_int = window->clipRect.top;
568 valuel.i_int = window->clipRect.left;
569 valueb.i_int = window->clipRect.bottom;
570 valuer.i_int = window->clipRect.right;
572 VLC_VariableSet( p_plugin->i_vlc, "drawablet", valuet );
573 VLC_VariableSet( p_plugin->i_vlc, "drawablel", valuel );
574 VLC_VariableSet( p_plugin->i_vlc, "drawableb", valueb );
575 VLC_VariableSet( p_plugin->i_vlc, "drawabler", valuer );
576 VLC_VariableSet( p_plugin->i_vlc, "drawablex", valuex );
577 VLC_VariableSet( p_plugin->i_vlc, "drawabley", valuey );
578 VLC_VariableSet( p_plugin->i_vlc, "drawablew", valuew );
579 VLC_VariableSet( p_plugin->i_vlc, "drawableh", valueh );
581 p_plugin->window = window;
583 valueredraw.i_int = 1;
584 VLC_VariableSet( p_plugin->i_vlc, "drawableredraw", valueredraw );
586 #else /* XP_MACOSX */
587 /* FIXME: this cast sucks */
588 value.i_int = (int) (ptrdiff_t) (void *) window->window;
589 VLC_VariableSet( p_plugin->i_vlc, "drawable", value );
591 #endif /* XP_MACOSX */
593 #endif /* USE_LIBVLC */
597 * Before setting window to point to the
598 * new window, you may wish to compare the new window
599 * info to the previous window (if any) to note window
604 if( !window || !window->window )
606 /* Window was destroyed. Invalidate everything. */
607 if( p_plugin->p_npwin )
610 SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
611 (LONG)p_plugin->pf_wndproc );
612 #endif /* !USE_LIBVLC */
613 p_plugin->pf_wndproc = NULL;
614 p_plugin->p_hwnd = NULL;
617 p_plugin->p_npwin = window;
618 return NPERR_NO_ERROR;
621 if( p_plugin->p_npwin )
623 if( p_plugin->p_hwnd == (HWND)window->window )
625 /* Same window, but something may have changed. First we
626 * update the plugin structure, then we redraw the window */
627 p_plugin->i_width = window->width;
628 p_plugin->i_height = window->height;
629 p_plugin->p_npwin = window;
631 InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
632 UpdateWindow( p_plugin->p_hwnd );
633 #endif /* !USE_LIBVLC */
634 return NPERR_NO_ERROR;
637 /* Window has changed. Destroy the one we have, and go
638 * on as if it was a real initialization. */
640 SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
641 (LONG)p_plugin->pf_wndproc );
642 #endif /* !USE_LIBVLC */
643 p_plugin->pf_wndproc = NULL;
644 p_plugin->p_hwnd = NULL;
648 p_plugin->pf_wndproc = (WNDPROC)SetWindowLong( (HWND)window->window,
649 GWL_WNDPROC, (LONG)Manage );
650 #endif /* !USE_LIBVLC */
652 p_plugin->p_hwnd = (HWND)window->window;
653 SetProp( p_plugin->p_hwnd, "w00t", (HANDLE)p_plugin );
654 InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
655 UpdateWindow( p_plugin->p_hwnd );
658 p_plugin->i_width = window->width;
659 p_plugin->i_height = window->height;
660 p_plugin->p_npwin = window;
663 p_plugin->window = (Window) window->window;
664 p_plugin->p_display =
665 ((NPSetWindowCallbackStruct *)window->ws_info)->display;
667 XResizeWindow( p_plugin->p_display, p_plugin->window,
668 p_plugin->i_width, p_plugin->i_height );
669 Widget w = XtWindowToWidget( p_plugin->p_display, p_plugin->window );
671 XtAddEventHandler( w, ExposureMask, FALSE,
672 (XtEventHandler)Redraw, p_plugin );
673 XtAddEventHandler( w, StructureNotifyMask, FALSE,
674 (XtEventHandler)Resize, p_plugin );
675 Redraw( w, (XtPointer)p_plugin, NULL );
678 if( !p_plugin->b_stream )
680 int i_mode = PLAYLIST_APPEND;
682 if( p_plugin->b_autoplay )
684 i_mode |= PLAYLIST_GO;
687 if( p_plugin->psz_target )
690 VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target,
691 0, 0, i_mode, -666 );
693 p_plugin->b_stream = VLC_TRUE;
697 return NPERR_NO_ERROR;
700 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
701 NPBool seekable, uint16 *stype )
703 if( instance == NULL )
705 return NPERR_INVALID_INSTANCE_ERROR;
709 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
712 /* fprintf(stderr, "NPP_NewStream - FILE mode !!\n"); */
714 /* We want a *filename* ! */
718 if( !p_plugin->b_stream )
720 p_plugin->psz_target = strdup( stream->url );
721 p_plugin->b_stream = VLC_TRUE;
725 return NPERR_NO_ERROR;
728 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
729 * mode so we can take any size stream in our
730 * write call (since we ignore it) */
732 #define SARASS_SIZE (1024*1024)
734 int32 NPP_WriteReady( NPP instance, NPStream *stream )
738 /* fprintf(stderr, "NPP_WriteReady\n"); */
740 if (instance != NULL)
742 p_plugin = (VlcPlugin*) instance->pdata;
743 /* Muahahahahahahaha */
744 return STREAMBUFSIZE;
745 /*return SARASS_SIZE;*/
748 /* Number of bytes ready to accept in NPP_Write() */
749 return STREAMBUFSIZE;
754 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
755 int32 len, void *buffer )
757 /* fprintf(stderr, "NPP_Write %i\n", (int)len); */
759 if( instance != NULL )
761 /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
764 return len; /* The number of bytes accepted */
768 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
770 if( instance == NULL )
772 return NPERR_INVALID_INSTANCE_ERROR;
775 return NPERR_NO_ERROR;
779 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
781 if( instance == NULL )
786 /* fprintf(stderr, "NPP_StreamAsFile %s\n", fname); */
789 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
791 VLC_AddTarget( p_plugin->i_vlc, fname, 0, 0,
792 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
793 #endif /* USE_LIBVLC */
797 void NPP_URLNotify( NPP instance, const char* url,
798 NPReason reason, void* notifyData )
800 /***** Insert NPP_URLNotify code here *****\
801 PluginInstance* p_plugin;
802 if (instance != NULL)
803 p_plugin = (PluginInstance*) instance->pdata;
804 \*********************************************/
808 void NPP_Print( NPP instance, NPPrint* printInfo )
810 if( printInfo == NULL )
815 if( instance != NULL )
817 /***** Insert NPP_Print code here *****\
818 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
819 \**************************************/
821 if( printInfo->mode == NP_FULL )
825 * If your plugin would like to take over
826 * printing completely when it is in full-screen mode,
827 * set printInfo->pluginPrinted to TRUE and print your
828 * plugin as you see fit. If your plugin wants Netscape
829 * to handle printing in this case, set
830 * printInfo->pluginPrinted to FALSE (the default) and
831 * do nothing. If you do want to handle printing
832 * yourself, printOne is true if the print button
833 * (as opposed to the print menu) was clicked.
834 * On the Macintosh, platformPrint is a THPrint; on
835 * Windows, platformPrint is a structure
836 * (defined in npapi.h) containing the printer name, port,
840 /***** Insert NPP_Print code here *****\
841 void* platformPrint =
842 printInfo->print.fullPrint.platformPrint;
844 printInfo->print.fullPrint.printOne;
845 \**************************************/
848 printInfo->print.fullPrint.pluginPrinted = FALSE;
852 /* If not fullscreen, we must be embedded */
855 * If your plugin is embedded, or is full-screen
856 * but you returned false in pluginPrinted above, NPP_Print
857 * will be called with mode == NP_EMBED. The NPWindow
858 * in the printInfo gives the location and dimensions of
859 * the embedded plugin on the printed page. On the
860 * Macintosh, platformPrint is the printer port; on
861 * Windows, platformPrint is the handle to the printing
865 /***** Insert NPP_Print code here *****\
866 NPWindow* printWindow =
867 &(printInfo->print.embedPrint.window);
868 void* platformPrint =
869 printInfo->print.embedPrint.platformPrint;
870 \**************************************/
875 /******************************************************************************
876 * Windows-only methods
877 *****************************************************************************/
878 #if defined(XP_WIN) && !USE_LIBVLC
879 LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
881 VlcPlugin* p_plugin = (VlcPlugin*) GetProp( p_hwnd, "w00t" );
887 PAINTSTRUCT paintstruct;
891 hdc = BeginPaint( p_hwnd, &paintstruct );
893 GetClientRect( p_hwnd, &rect );
894 FillRect( hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH) );
895 TextOut( hdc, p_plugin->i_width / 2 - 40, p_plugin->i_height / 2,
896 WINDOW_TEXT, strlen(WINDOW_TEXT) );
898 EndPaint( p_hwnd, &paintstruct );
902 p_plugin->pf_wndproc( p_hwnd, i_msg, wpar, lpar );
909 /******************************************************************************
911 *****************************************************************************/
913 static void Redraw( Widget w, XtPointer closure, XEvent *event )
915 VlcPlugin* p_plugin = (VlcPlugin*)closure;
919 gcv.foreground = BlackPixel( p_plugin->p_display, 0 );
920 gc = XCreateGC( p_plugin->p_display, p_plugin->window, GCForeground, &gcv );
922 XFillRectangle( p_plugin->p_display, p_plugin->window, gc,
923 0, 0, p_plugin->i_width, p_plugin->i_height );
925 gcv.foreground = WhitePixel( p_plugin->p_display, 0 );
926 XChangeGC( p_plugin->p_display, gc, GCForeground, &gcv );
928 XDrawString( p_plugin->p_display, p_plugin->window, gc,
929 p_plugin->i_width / 2 - 40, p_plugin->i_height / 2,
930 WINDOW_TEXT, strlen(WINDOW_TEXT) );
932 XFreeGC( p_plugin->p_display, gc );
935 static void Resize ( Widget w, XtPointer closure, XEvent *event )
937 VlcPlugin* p_plugin = (VlcPlugin*)closure;
939 Window root_return, parent_return, * children_return;
941 unsigned int i_nchildren;
943 #ifdef X11_RESIZE_DEBUG
944 XWindowAttributes attr;
946 if( event && event->type == ConfigureNotify )
948 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
949 "send_event ? %s\n", event->xconfigure.width,
950 event->xconfigure.height,
951 event->xconfigure.send_event ? "TRUE" : "FALSE" );
953 #endif /* X11_RESIZE_DEBUG */
955 if( p_plugin->i_height == i_previous_height &&
956 p_plugin->i_width == i_previous_width )
960 i_previous_height = p_plugin->i_height;
961 i_previous_width = p_plugin->i_width;
964 i_ret = XResizeWindow( p_plugin->p_display, p_plugin->window,
965 p_plugin->i_width, p_plugin->i_height );
967 #ifdef X11_RESIZE_DEBUG
969 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
971 XGetWindowAttributes ( p_plugin->p_display, p_plugin->window, &attr );
973 /* X is asynchronous, so the current size reported here is not
974 necessarily the requested size as the Resize request may not
975 yet have been handled by the plugin host */
976 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
977 attr.width, attr.height );
978 #endif /* X11_RESIZE_DEBUG */
980 XQueryTree( p_plugin->p_display, p_plugin->window,
981 &root_return, &parent_return, &children_return,
984 if( i_nchildren > 0 )
986 /* XXX: Make assumptions related to the window parenting structure in
987 vlc/modules/video_output/x11/xcommon.c */
988 base_window = children_return[i_nchildren - 1];
990 #ifdef X11_RESIZE_DEBUG
991 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
992 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
994 #endif /* X11_RESIZE_DEBUG */
996 i_ret = XResizeWindow( p_plugin->p_display, base_window,
997 p_plugin->i_width, p_plugin->i_height );
999 #ifdef X11_RESIZE_DEBUG
1001 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1004 XGetWindowAttributes( p_plugin->p_display, base_window, &attr );
1006 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1007 attr.width, attr.height );
1008 #endif /* X11_RESIZE_DEBUG */
1012 #endif /* XP_UNIX */