1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Jean-Paul Saman <jpsaman@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
35 #ifdef HAVE_MOZILLA_CONFIG_H
36 # include <mozilla-config.h>
39 /* This is from mozilla java, do we really need it? */
44 #include "vlcplugin.h"
46 /* Enable/disable debugging printf's for X11 resizing */
47 #undef X11_RESIZE_DEBUG
49 #define WINDOW_TEXT "Video is loading..."
51 /*****************************************************************************
52 * Unix-only declarations
53 ******************************************************************************/
56 static void Redraw( Widget w, XtPointer closure, XEvent *event );
57 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
58 static void Resize( Widget w, XtPointer closure, XEvent *event );
62 /*****************************************************************************
63 * MacOS-only declarations
64 ******************************************************************************/
68 /*****************************************************************************
69 * Windows-only declarations
70 *****************************************************************************/
73 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
77 /******************************************************************************
79 *****************************************************************************/
80 char * NPP_GetMIMEDescription( void )
82 return PLUGIN_MIMETYPES;
85 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
88 static char psz_desc[1000];
90 /* plugin class variables */
93 case NPPVpluginNameString:
94 *((char **)value) = PLUGIN_NAME;
95 return NPERR_NO_ERROR;
97 case NPPVpluginDescriptionString:
98 snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION,
99 libvlc_get_version() );
100 *((char **)value) = psz_desc;
101 return NPERR_NO_ERROR;
104 /* move on to instance variables ... */
108 if( instance == NULL )
110 return NPERR_INVALID_INSTANCE_ERROR;
113 /* plugin instance variables */
115 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
116 if( NULL == p_plugin )
118 // plugin has not been initialized yet !
119 return NPERR_INVALID_INSTANCE_ERROR;
124 case NPPVpluginScriptableNPObject:
126 /* retrieve plugin root class */
127 NPClass *scriptClass = p_plugin->getScriptClass();
130 /* create an instance and return it */
131 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
132 return NPERR_NO_ERROR;
140 return NPERR_GENERIC_ERROR;
144 * there is some confusion in gecko headers regarding definition of this API
145 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
148 NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
150 return NPERR_GENERIC_ERROR;
153 /******************************************************************************
155 *****************************************************************************/
157 int16 NPP_HandleEvent( NPP instance, void * event )
159 static UInt32 lastMouseUp = 0;
161 if( instance == NULL )
166 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
168 if( p_plugin == NULL )
173 EventRecord *myEvent = (EventRecord*)event;
175 switch( myEvent->what )
181 if( (myEvent->when - lastMouseUp) < GetDblTime() )
184 libvlc_instance_t *p_vlc = p_plugin->getVLC();
188 if( libvlc_playlist_isplaying(p_vlc, NULL) )
190 libvlc_media_player_t *p_md =
191 libvlc_playlist_get_media_player(p_vlc, NULL);
194 libvlc_toggle_fullscreen(p_md, NULL);
195 libvlc_media_player_release(p_md);
203 lastMouseUp = myEvent->when;
211 const NPWindow& npwindow = p_plugin->getWindow();
212 if( npwindow.window )
215 libvlc_instance_t *p_vlc = p_plugin->getVLC();
219 if( libvlc_playlist_isplaying(p_vlc, NULL) )
221 libvlc_media_player_t *p_md =
222 libvlc_playlist_get_media_player(p_vlc, NULL);
225 hasVout = libvlc_media_player_has_vout(p_md,
229 libvlc_rectangle_t area;
232 area.right = npwindow.width;
233 area.bottom = npwindow.height;
234 libvlc_video_redraw_rectangle(p_md, &area,
237 libvlc_media_player_release(p_md);
244 /* draw the beautiful "No Picture" */
246 ForeColor(blackColor);
249 /* seems that firefox forgets to set the following
250 * on occasion (reload) */
251 SetOrigin(((NP_Port *)npwindow.window)->portx,
252 ((NP_Port *)npwindow.window)->porty);
257 rect.right = npwindow.width;
258 rect.bottom = npwindow.height;
261 ForeColor(whiteColor);
262 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
263 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
270 case NPEventType_GetFocusEvent:
271 case NPEventType_LoseFocusEvent:
273 case NPEventType_AdjustCursorEvent:
275 case NPEventType_MenuCommandEvent:
277 case NPEventType_ClippingChangedEvent:
279 case NPEventType_ScrollingBeginsEvent:
281 case NPEventType_ScrollingEndsEvent:
288 #endif /* XP_MACOSX */
290 /******************************************************************************
291 * General Plug-in Calls
292 *****************************************************************************/
293 NPError NPP_Initialize( void )
295 return NPERR_NO_ERROR;
298 jref NPP_GetJavaClass( void )
303 void NPP_Shutdown( void )
308 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
309 char* argn[], char* argv[], NPSavedData* saved )
313 if( instance == NULL )
315 return NPERR_INVALID_INSTANCE_ERROR;
318 VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
319 if( NULL == p_plugin )
321 return NPERR_OUT_OF_MEMORY_ERROR;
324 status = p_plugin->init(argc, argn, argv);
325 if( NPERR_NO_ERROR == status )
327 instance->pdata = reinterpret_cast<void*>(p_plugin);
329 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
330 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
340 NPError NPP_Destroy( NPP instance, NPSavedData** save )
342 if( NULL == instance )
343 return NPERR_INVALID_INSTANCE_ERROR;
345 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
346 if( NULL == p_plugin )
347 return NPERR_NO_ERROR;
349 instance->pdata = NULL;
352 HWND win = (HWND)p_plugin->getWindow().window;
353 WNDPROC winproc = p_plugin->getWindowProc();
357 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
363 return NPERR_NO_ERROR;
366 NPError NPP_SetWindow( NPP instance, NPWindow* window )
368 #ifdef XP_UNIX && !defined(__APPLE__)
370 unsigned int i_control_height = 0, i_control_width = 0;
375 return NPERR_INVALID_INSTANCE_ERROR;
378 /* NPP_SetWindow may be called before NPP_New (Opera) */
379 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
380 if( NULL == p_plugin )
382 /* we should probably show a splash screen here */
383 return NPERR_NO_ERROR;
385 #ifdef XP_UNIX && !defined(__APPLE__)
386 control = p_plugin->getControlWindow();
388 libvlc_instance_t *p_vlc = p_plugin->getVLC();
392 * Before setting window to point to the
393 * new window, you may wish to compare the new window
394 * info to the previous window (if any) to note window
398 /* retrieve current window */
399 NPWindow& curwin = p_plugin->getWindow();
402 if( window && window->window )
404 /* check if plugin has a new parent window */
405 CGrafPtr drawable = (((NP_Port*) (window->window))->port);
406 if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
408 /* set/change parent window */
409 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
412 /* as MacOS X video output is windowless, set viewport */
413 libvlc_rectangle_t view, clip;
416 ** browser sets port origin to top-left location of plugin
417 ** relative to GrafPort window origin is set relative to document,
418 ** which of little use for drawing
420 view.top = ((NP_Port*) (window->window))->porty;
421 view.left = ((NP_Port*) (window->window))->portx;
422 view.bottom = window->height+view.top;
423 view.right = window->width+view.left;
424 /* clipRect coordinates are also relative to GrafPort */
425 clip.top = window->clipRect.top;
426 clip.left = window->clipRect.left;
427 clip.bottom = window->clipRect.bottom;
428 clip.right = window->clipRect.right;
430 libvlc_video_set_viewport(p_vlc, &view, &clip, NULL);
432 /* remember new window */
433 p_plugin->setWindow(*window);
435 else if( curwin.window ) {
436 /* change/set parent */
437 libvlc_video_set_parent(p_vlc, 0, NULL);
438 curwin.window = NULL;
440 #endif /* XP_MACOSX */
443 if( window && window->window )
445 /* check if plugin has a new parent window */
446 HWND drawable = (HWND) (window->window);
447 if( !curwin.window || drawable != curwin.window )
449 /* reset previous window settings */
450 HWND oldwin = (HWND)p_plugin->getWindow().window;
451 WNDPROC oldproc = p_plugin->getWindowProc();
455 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
457 /* attach our plugin object */
458 SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
459 reinterpret_cast<LONG_PTR>(p_plugin));
461 /* install our WNDPROC */
462 p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
463 GWL_WNDPROC, (LONG)Manage ) );
465 /* change window style to our liking */
466 LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
467 style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
468 SetWindowLong((HWND)drawable, GWL_STYLE, style);
470 /* change/set parent */
471 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
473 /* remember new window */
474 p_plugin->setWindow(*window);
477 InvalidateRect( (HWND)drawable, NULL, TRUE );
478 UpdateWindow( (HWND)drawable );
481 else if ( curwin.window )
484 HWND oldwin = (HWND)curwin.window;
485 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
486 p_plugin->setWindowProc(NULL);
487 /* change/set parent */
488 libvlc_video_set_parent(p_vlc, 0, NULL);
489 curwin.window = NULL;
494 /* default to hidden toolbar, shown at the end of this method if asked *
495 * developers note : getToolbarSize need to wait the end of this method
497 i_control_height = 0;
498 i_control_width = window->width;
500 if( window && window->window )
502 Window parent = (Window) window->window;
503 if( !curwin.window || (parent != (Window)curwin.window) )
505 Display *p_display = ( (NPSetWindowCallbackStruct *)
506 window->ws_info )->display;
508 XResizeWindow( p_display, parent, window->width, window->height );
510 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
513 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
514 window->width, window->height - i_control_height,
515 0, i_blackColor, i_blackColor );
516 Window controls = (Window) NULL;
517 controls = XCreateSimpleWindow( p_display, parent,
518 0, window->height - i_control_height-1,
519 window->width, i_control_height-1,
520 0, i_blackColor, i_blackColor );
522 XMapWindow( p_display, parent );
523 XMapWindow( p_display, video );
524 if( controls ) { XMapWindow( p_display, controls ); }
529 Widget w = XtWindowToWidget( p_display, parent );
531 XtAddEventHandler( w, ExposureMask, FALSE,
532 (XtEventHandler)Redraw, p_plugin );
533 XtAddEventHandler( w, StructureNotifyMask, FALSE,
534 (XtEventHandler)Resize, p_plugin );
535 XtAddEventHandler( w, ButtonReleaseMask, FALSE,
536 (XtEventHandler)ControlHandler, p_plugin );
540 libvlc_media_player_t *p_md;
542 libvlc_exception_t ex;
543 libvlc_exception_init(& ex );
544 p_md = libvlc_playlist_get_media_player( p_plugin->getVLC(), &ex );
545 libvlc_exception_init( &ex );
546 libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ),
547 libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex );
550 /* set/change parent window */
551 libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL );
553 /* remember window */
554 p_plugin->setWindow( *window );
555 p_plugin->setVideoWindow( video );
556 if( controls ) { p_plugin->setControlWindow( controls ); }
558 Redraw( w, (XtPointer)p_plugin, NULL );
560 /* now display toolbar if asked through parameters */
561 if( p_plugin->b_toolbar )
563 p_plugin->showToolbar();
567 else if ( curwin.window )
569 /* change/set parent */
570 libvlc_video_set_parent(p_vlc, 0, NULL);
571 curwin.window = NULL;
575 if( !p_plugin->b_stream )
577 if( p_plugin->psz_target )
579 if( libvlc_playlist_add( p_vlc, p_plugin->psz_target,
582 if( p_plugin->b_autoplay )
584 libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
587 p_plugin->b_stream = true;
590 return NPERR_NO_ERROR;
593 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
594 NPBool seekable, uint16 *stype )
596 if( NULL == instance )
598 return NPERR_INVALID_INSTANCE_ERROR;
601 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
602 if( NULL == p_plugin )
604 return NPERR_INVALID_INSTANCE_ERROR;
608 ** Firefox/Mozilla may decide to open a stream from the URL specified
609 ** in the SRC parameter of the EMBED tag and pass it to us
611 ** since VLC will open the SRC URL as well, we're not interested in
612 ** that stream. Otherwise, we'll take it and queue it up in the playlist
614 if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
616 /* TODO: use pipes !!!! */
617 *stype = NP_ASFILEONLY;
618 return NPERR_NO_ERROR;
620 return NPERR_GENERIC_ERROR;
623 int32 NPP_WriteReady( NPP instance, NPStream *stream )
630 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
631 int32 len, void *buffer )
638 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
640 if( instance == NULL )
642 return NPERR_INVALID_INSTANCE_ERROR;
644 return NPERR_NO_ERROR;
648 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
650 if( instance == NULL )
655 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
656 if( NULL == p_plugin )
661 if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL )
664 if( p_plugin->b_autoplay )
666 libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL);
672 void NPP_URLNotify( NPP instance, const char* url,
673 NPReason reason, void* notifyData )
675 /***** Insert NPP_URLNotify code here *****\
676 PluginInstance* p_plugin;
677 if (instance != NULL)
678 p_plugin = (PluginInstance*) instance->pdata;
679 \*********************************************/
683 void NPP_Print( NPP instance, NPPrint* printInfo )
685 if( printInfo == NULL )
690 if( instance != NULL )
692 /***** Insert NPP_Print code here *****\
693 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
694 \**************************************/
696 if( printInfo->mode == NP_FULL )
700 * If your plugin would like to take over
701 * printing completely when it is in full-screen mode,
702 * set printInfo->pluginPrinted to TRUE and print your
703 * plugin as you see fit. If your plugin wants Netscape
704 * to handle printing in this case, set
705 * printInfo->pluginPrinted to FALSE (the default) and
706 * do nothing. If you do want to handle printing
707 * yourself, printOne is true if the print button
708 * (as opposed to the print menu) was clicked.
709 * On the Macintosh, platformPrint is a THPrint; on
710 * Windows, platformPrint is a structure
711 * (defined in npapi.h) containing the printer name, port,
715 /***** Insert NPP_Print code here *****\
716 void* platformPrint =
717 printInfo->print.fullPrint.platformPrint;
719 printInfo->print.fullPrint.printOne;
720 \**************************************/
723 printInfo->print.fullPrint.pluginPrinted = FALSE;
727 /* If not fullscreen, we must be embedded */
730 * If your plugin is embedded, or is full-screen
731 * but you returned false in pluginPrinted above, NPP_Print
732 * will be called with mode == NP_EMBED. The NPWindow
733 * in the printInfo gives the location and dimensions of
734 * the embedded plugin on the printed page. On the
735 * Macintosh, platformPrint is the printer port; on
736 * Windows, platformPrint is the handle to the printing
740 /***** Insert NPP_Print code here *****\
741 NPWindow* printWindow =
742 &(printInfo->print.embedPrint.window);
743 void* platformPrint =
744 printInfo->print.embedPrint.platformPrint;
745 \**************************************/
750 /******************************************************************************
751 * Windows-only methods
752 *****************************************************************************/
754 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
756 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
765 PAINTSTRUCT paintstruct;
769 hdc = BeginPaint( p_hwnd, &paintstruct );
771 GetClientRect( p_hwnd, &rect );
773 FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
774 SetTextColor(hdc, RGB(255, 255, 255));
775 SetBkColor(hdc, RGB(0, 0, 0));
776 DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
777 DT_CENTER|DT_VCENTER|DT_SINGLELINE);
779 EndPaint( p_hwnd, &paintstruct );
783 /* delegate to default handler */
784 return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
790 /******************************************************************************
792 *****************************************************************************/
794 static void Redraw( Widget w, XtPointer closure, XEvent *event )
796 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
797 Window control = p_plugin->getControlWindow();
798 const NPWindow& window = p_plugin->getWindow();
801 unsigned int i_control_height, i_control_width;
803 if( p_plugin->b_toolbar )
804 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
806 i_control_height = i_control_width = 0;
808 Window video = p_plugin->getVideoWindow();
809 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
811 gcv.foreground = BlackPixel( p_display, 0 );
812 gc = XCreateGC( p_display, video, GCForeground, &gcv );
814 XFillRectangle( p_display, video, gc,
815 0, 0, window.width, window.height - i_control_height);
817 gcv.foreground = WhitePixel( p_display, 0 );
818 XChangeGC( p_display, gc, GCForeground, &gcv );
820 XDrawString( p_display, video, gc,
821 window.width / 2 - 40, (window.height - i_control_height) / 2,
822 WINDOW_TEXT, strlen(WINDOW_TEXT) );
823 XFreeGC( p_display, gc );
825 p_plugin->redrawToolbar();
828 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
830 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
831 const NPWindow& window = p_plugin->getWindow();
833 int i_height = window.height;
834 int i_width = window.width;
835 int i_xPos = event->xbutton.x;
836 int i_yPos = event->xbutton.y;
838 if( p_plugin && p_plugin->b_toolbar )
841 libvlc_exception_t ex;
843 libvlc_exception_init( &ex );
844 libvlc_media_player_t *p_md =
845 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
846 if( libvlc_exception_raised(&ex) )
847 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
848 libvlc_exception_clear( &ex );
850 libvlc_exception_init( &ex );
851 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
852 if( libvlc_exception_raised(&ex) )
853 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
854 libvlc_exception_clear( &ex );
856 vlc_toolbar_clicked_t clicked;
857 clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
863 libvlc_exception_init( &ex );
865 libvlc_playlist_pause( p_plugin->getVLC(), &ex );
867 libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
869 if( libvlc_exception_raised(&ex) )
870 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
871 libvlc_exception_clear( &ex );
877 libvlc_exception_init( &ex );
878 libvlc_playlist_stop( p_plugin->getVLC(), &ex );
879 if( libvlc_exception_raised(&ex) )
880 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
881 libvlc_exception_clear( &ex );
885 case clicked_Fullscreen:
887 if( (i_playing == 1) && p_md )
889 libvlc_exception_init( &ex );
890 libvlc_set_fullscreen( p_md, 1, &ex );
891 if( libvlc_exception_raised(&ex) )
892 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
893 libvlc_exception_clear( &ex );
901 libvlc_exception_init( &ex );
902 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
903 if( libvlc_exception_raised(&ex) )
904 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
905 libvlc_exception_clear( &ex );
909 case clicked_timeline:
911 /* if a movie is loaded */
915 libvlc_exception_init( &ex );
916 f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
917 libvlc_exception_clear( &ex );
919 f_length = (float)f_length *
920 ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
922 libvlc_exception_init( &ex );
923 libvlc_media_player_set_time( p_md, f_length, &ex );
924 if( libvlc_exception_raised(&ex) )
925 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
926 libvlc_exception_clear( &ex );
933 /* Not implemented yet*/
937 default: /* button_Unknown */
940 if( p_md ) libvlc_media_player_release( p_md );
942 Redraw( w, closure, event );
945 static void Resize ( Widget w, XtPointer closure, XEvent *event )
947 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
948 Window control = p_plugin->getControlWindow();
949 const NPWindow& window = p_plugin->getWindow();
950 Window drawable = p_plugin->getVideoWindow();
951 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
954 Window root_return, parent_return, * children_return;
956 unsigned int i_nchildren;
957 unsigned int i_control_height, i_control_width;
959 if( p_plugin->b_toolbar )
961 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
965 i_control_height = i_control_width = 0;
968 #ifdef X11_RESIZE_DEBUG
969 XWindowAttributes attr;
971 if( event && event->type == ConfigureNotify )
973 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
974 "send_event ? %s\n", event->xconfigure.width,
975 event->xconfigure.height,
976 event->xconfigure.send_event ? "TRUE" : "FALSE" );
978 #endif /* X11_RESIZE_DEBUG */
980 if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) )
982 /* size already set */
986 i_ret = XResizeWindow( p_display, drawable,
987 window.width, (window.height - i_control_height) );
989 #ifdef X11_RESIZE_DEBUG
991 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
993 XGetWindowAttributes ( p_display, drawable, &attr );
995 /* X is asynchronous, so the current size reported here is not
996 necessarily the requested size as the Resize request may not
997 yet have been handled by the plugin host */
998 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
999 attr.width, attr.height );
1000 #endif /* X11_RESIZE_DEBUG */
1002 XQueryTree( p_display, drawable,
1003 &root_return, &parent_return, &children_return,
1006 if( i_nchildren > 0 )
1008 /* XXX: Make assumptions related to the window parenting structure in
1009 vlc/modules/video_output/x11/xcommon.c */
1010 base_window = children_return[i_nchildren - 1];
1012 #ifdef X11_RESIZE_DEBUG
1013 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
1014 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
1016 #endif /* X11_RESIZE_DEBUG */
1018 i_ret = XResizeWindow( p_display, base_window,
1019 window.width, ( window.height - i_control_height ) );
1021 #ifdef X11_RESIZE_DEBUG
1023 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1026 XGetWindowAttributes( p_display, base_window, &attr );
1028 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1029 attr.width, attr.height );
1030 #endif /* X11_RESIZE_DEBUG */
1034 #endif /* XP_UNIX */