vlcplugin_xlib.cpp 4.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*****************************************************************************
 * vlcplugin_xlib.cpp: a VLC plugin for Mozilla (X interface)
 *****************************************************************************
 * Copyright (C) 2011 the VideoLAN team
 * $Id$
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *          Damien Fouilleul <damienf@videolan.org>
 *          Jean-Paul Saman <jpsaman@videolan.org>
 *          Cheng Sun <chengsun9@gmail.com>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
#include "vlcplugin_xlib.h"
#include <cstring>

VlcPluginXlib::VlcPluginXlib(NPP instance, NPuint16_t mode) :
    VlcPluginBase(instance, mode)
{
    memset(&npparent, 0, sizeof(Window));
    memset(&npvideo, 0, sizeof(Window));
}

VlcPluginXlib::~VlcPluginXlib()
{
}

Display *VlcPluginXlib::getDisplay()
{
        return ((NPSetWindowCallbackStruct *) npwindow.ws_info)->display;
}

void VlcPluginXlib::set_player_window()
{
    libvlc_media_player_set_xwindow(libvlc_media_player,
                                    (uint32_t)npvideo);
}

void VlcPluginXlib::toggle_fullscreen()
{
    if (playlist_isplaying())
        libvlc_toggle_fullscreen(libvlc_media_player);
}

void VlcPluginXlib::set_fullscreen(int yes)
{
    if (playlist_isplaying())
        libvlc_set_fullscreen(libvlc_media_player,yes);
}

int  VlcPluginXlib::get_fullscreen()
{
    int r = 0;
    if (playlist_isplaying())
        r = libvlc_get_fullscreen(libvlc_media_player);
    return r;
}

bool VlcPluginXlib::create_windows()
{

    Display *p_display = getDisplay();
    Window socket = (Window) npwindow.window;

    unsigned long xembed_info_buf[2] =
            { PLUGIN_XEMBED_PROTOCOL_VERSION, XEMBED_MAPPED };
    Atom xembed_info_atom = XInternAtom( p_display, "_XEMBED_INFO", 1);

    int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));

    /* create windows */
    npparent = XCreateSimpleWindow( p_display, socket, 0, 0,
                   1, 1,
                   0, i_blackColor, i_blackColor );
    XChangeProperty( p_display, npparent, xembed_info_atom,
                     xembed_info_atom, 32, PropModeReplace,
                     (unsigned char *)xembed_info_buf, 2);

    npvideo = XCreateSimpleWindow( p_display, npparent, 0, 0,
                   1, 1,
                   0, i_blackColor, i_blackColor );

    XMapWindow( p_display, npvideo );

    return true;
}

bool VlcPluginXlib::resize_windows()
{
    Display *p_display = getDisplay();

    int i_ret;

    i_ret = XMoveResizeWindow( p_display, npparent, 0, 0,
                               npwindow.width, npwindow.height );
    i_ret = XMoveResizeWindow( p_display, npvideo, 0, 0,
                               npwindow.width, npwindow.height );

    Window root_return, parent_return, *children_return;
    unsigned int i_nchildren;
    XQueryTree( p_display, npvideo,
                &root_return, &parent_return, &children_return,
                &i_nchildren );

    if( i_nchildren > 0 )
    {
        /* XXX: Make assumptions related to the window parenting structure in
           vlc/modules/video_output/x11/xcommon.c */
        Window base_window = children_return[i_nchildren - 1];

        i_ret = XResizeWindow( p_display, base_window,
                npwindow.width, ( npwindow.height ) );
    }

    return true;
}

bool VlcPluginXlib::destroy_windows()
{
    /* TODO */
}