Commit 23047cb4 authored by Cheng Sun's avatar Cheng Sun Committed by Jean-Baptiste Kempf

Ported the Xlib plugin to use XCB instead, and make it actually work.

parent 95115dab
......@@ -249,8 +249,8 @@ AS_IF([ test "${SYS}" != "mingw32" -a "${SYS}" != "darwin" ], [
])
AS_IF([ test "x$gtk_found" == "xno" ],
[
PKG_CHECK_MODULES(XPM, [xpm],, [
AC_MSG_ERROR([Please install the libXpm development files, or re-run configure with --with-gtk])
PKG_CHECK_MODULES(XCB, [xcb],, [
AC_MSG_ERROR([Please install the libxcb development files, or re-run configure with --with-gtk])
])
])
])
......
......@@ -55,14 +55,12 @@ SOURCES_support = \
vlcplugin_gtk.cpp \
vlcplugin_gtk.h
else # !USE_GTK
AM_CPPFLAGS += $(X_CFLAGS) $(XPM_CFLAGS)
libvlcplugin_la_LIBADD += $(X_LIBS) $(X_PRE_LIBS) \
$(XT_LIBS) -lX11 -lSM -lICE -lXpm \
$(XPM_LIBS)
AM_CPPFLAGS += $(XCB_CFLAGS)
libvlcplugin_la_LIBADD += $(XCB_LIBS)
SOURCES_support = \
support/npunix.cpp \
vlcplugin_xlib.cpp \
vlcplugin_xlib.h
vlcplugin_xcb.cpp \
vlcplugin_xcb.h
endif # !USE_GTK
else # Win32
......
......@@ -7,8 +7,8 @@
# include "vlcplugin_gtk.h"
typedef VlcPluginGtk VlcPlugin;
# else
# include "vlcplugin_xlib.h"
typedef VlcPluginXlib VlcPlugin;
# include "vlcplugin_xcb.h"
typedef VlcPluginXcb VlcPlugin;
# endif
#elif defined(XP_WIN)
# include "vlcplugin_win.h"
......
/*****************************************************************************
* vlcplugin_xlib.cpp: a VLC plugin for Mozilla (X interface)
* vlcplugin_xcb.cpp: a VLC plugin for Mozilla (X interface)
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
......@@ -24,46 +24,43 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "vlcplugin_xlib.h"
#include "vlcplugin_xcb.h"
#include <cstring>
#include <cstdlib>
VlcPluginXlib::VlcPluginXlib(NPP instance, NPuint16_t mode) :
VlcPluginXcb::VlcPluginXcb(NPP instance, NPuint16_t mode) :
VlcPluginBase(instance, mode)
{
memset(&npparent, 0, sizeof(Window));
memset(&npvideo, 0, sizeof(Window));
}
VlcPluginXlib::~VlcPluginXlib()
{
memset(&parent, 0, sizeof(Window));
memset(&video, 0, sizeof(Window));
}
Display *VlcPluginXlib::getDisplay()
VlcPluginXcb::~VlcPluginXcb()
{
return ((NPSetWindowCallbackStruct *) npwindow.ws_info)->display;
}
void VlcPluginXlib::set_player_window()
void VlcPluginXcb::set_player_window()
{
libvlc_media_player_set_xwindow(libvlc_media_player,
(uint32_t)npvideo);
(uint32_t) video);
}
void VlcPluginXlib::toggle_fullscreen()
void VlcPluginXcb::toggle_fullscreen()
{
if (!b_allowfullscreen) return;
if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player);
}
void VlcPluginXlib::set_fullscreen(int yes)
void VlcPluginXcb::set_fullscreen(int yes)
{
if (!b_allowfullscreen) return;
if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player,yes);
}
int VlcPluginXlib::get_fullscreen()
int VlcPluginXcb::get_fullscreen()
{
int r = 0;
if (playlist_isplaying())
......@@ -71,66 +68,70 @@ int VlcPluginXlib::get_fullscreen()
return r;
}
bool VlcPluginXlib::create_windows()
bool VlcPluginXcb::create_windows()
{
Display *p_display = getDisplay();
Display *npdisplay = ( (NPSetWindowCallbackStruct *) npwindow.ws_info )->display;
Window socket = (Window) npwindow.window;
conn = xcb_connect(XDisplayString(npdisplay), NULL);
unsigned long xembed_info_buf[2] =
{ PLUGIN_XEMBED_PROTOCOL_VERSION, XEMBED_MAPPED };
Atom xembed_info_atom = XInternAtom( p_display, "_XEMBED_INFO", 1);
const xcb_setup_t *setup = xcb_get_setup(conn);
xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
uint32_t xembed_info_buf[2] =
{ PLUGIN_XEMBED_PROTOCOL_VERSION, XEMBED_MAPPED };
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(conn, 0, strlen("_XEMBED_INFO"), "_XEMBED_INFO");
xcb_atom_t xembed_info_atom = xcb_intern_atom_reply(conn, cookie, NULL)->atom;
/* 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 );
/* TODO: respect psz_bgcolor */
const uint32_t parent_values[] = {0x0FFFFF};
parent = xcb_generate_id(conn);
xcb_create_window(conn, XCB_COPY_FROM_PARENT, parent, socket,
/* FIXME: figure out why the window refuses to be resized larger than initial size */
0, 0, 20000, 20000, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual, XCB_CW_EVENT_MASK, parent_values);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, parent,
xembed_info_atom, xembed_info_atom,
32, 2, (void *) xembed_info_buf);
const uint32_t video_values[] = {screen->black_pixel, 0x0FFFFF};
video = xcb_generate_id(conn);
xcb_create_window(conn, 0, video, parent,
0, 0, 1, 1, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, video_values);
xcb_map_window(conn, video);
xcb_flush(conn);
return true;
}
bool VlcPluginXlib::resize_windows()
bool VlcPluginXcb::resize_windows()
{
Display *p_display = getDisplay();
int i_ret;
const uint32_t dims[] = {npwindow.width, npwindow.height};
xcb_configure_window(conn, video, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, dims);
xcb_configure_window(conn, parent, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, dims);
i_ret = XMoveResizeWindow( p_display, npparent, 0, 0,
npwindow.width, npwindow.height );
i_ret = XMoveResizeWindow( p_display, npvideo, 0, 0,
npwindow.width, npwindow.height );
xcb_query_tree_cookie_t query_cookie = xcb_query_tree(conn, video);
xcb_query_tree_reply_t *query_reply = xcb_query_tree_reply(conn, query_cookie, NULL);
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 )
{
if (query_reply) {
/* 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 ) );
xcb_window_t *children = xcb_query_tree_children(query_reply);
xcb_configure_window(conn, children[query_reply->children_len - 1], XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, dims);
}
xcb_flush(conn);
free(query_reply);
return true;
}
bool VlcPluginXlib::destroy_windows()
bool VlcPluginXcb::destroy_windows()
{
/* TODO */
/* destroy x window */
xcb_destroy_window(conn, parent);
/* close connection */
xcb_disconnect(conn);
}
/*****************************************************************************
* vlcplugin_xlib.h: a VLC plugin for Mozilla (X interface)
* vlcplugin_xcb.h: a VLC plugin for Mozilla (X interface)
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
......@@ -24,18 +24,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __VLCPLUGIN_XLIB_H__
#define __VLCPLUGIN_XLIB_H__
#ifndef __VLCPLUGIN_XCB_H__
#define __VLCPLUGIN_XCB_H__
#include "vlcplugin_base.h"
#include <X11/Xlib.h>
#include <xcb/xcb.h>
#include "xembed.h"
class VlcPluginXlib : public VlcPluginBase
class VlcPluginXcb : public VlcPluginBase
{
public:
VlcPluginXlib(NPP, NPuint16_t);
virtual ~VlcPluginXlib();
VlcPluginXcb(NPP, NPuint16_t);
virtual ~VlcPluginXcb();
int setSize(unsigned width, unsigned height);
......@@ -52,14 +52,15 @@ public:
void update_controls() {/* STUB */}
void popup_menu() {/* STUB */}
Display *getDisplay();
private:
void set_player_window();
unsigned int i_width, i_height;
Window npparent, npvideo;
xcb_connection_t *conn;
xcb_window_t parent, video;
pthread_t thread;
int i_last_position;
};
#endif /* __VLCPLUGIN_XLIB_H__ */
#endif /* __VLCPLUGIN_XCB_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment