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" ], [ ...@@ -249,8 +249,8 @@ AS_IF([ test "${SYS}" != "mingw32" -a "${SYS}" != "darwin" ], [
]) ])
AS_IF([ test "x$gtk_found" == "xno" ], AS_IF([ test "x$gtk_found" == "xno" ],
[ [
PKG_CHECK_MODULES(XPM, [xpm],, [ PKG_CHECK_MODULES(XCB, [xcb],, [
AC_MSG_ERROR([Please install the libXpm development files, or re-run configure with --with-gtk]) AC_MSG_ERROR([Please install the libxcb development files, or re-run configure with --with-gtk])
]) ])
]) ])
]) ])
......
...@@ -55,14 +55,12 @@ SOURCES_support = \ ...@@ -55,14 +55,12 @@ SOURCES_support = \
vlcplugin_gtk.cpp \ vlcplugin_gtk.cpp \
vlcplugin_gtk.h vlcplugin_gtk.h
else # !USE_GTK else # !USE_GTK
AM_CPPFLAGS += $(X_CFLAGS) $(XPM_CFLAGS) AM_CPPFLAGS += $(XCB_CFLAGS)
libvlcplugin_la_LIBADD += $(X_LIBS) $(X_PRE_LIBS) \ libvlcplugin_la_LIBADD += $(XCB_LIBS)
$(XT_LIBS) -lX11 -lSM -lICE -lXpm \
$(XPM_LIBS)
SOURCES_support = \ SOURCES_support = \
support/npunix.cpp \ support/npunix.cpp \
vlcplugin_xlib.cpp \ vlcplugin_xcb.cpp \
vlcplugin_xlib.h vlcplugin_xcb.h
endif # !USE_GTK endif # !USE_GTK
else # Win32 else # Win32
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
# include "vlcplugin_gtk.h" # include "vlcplugin_gtk.h"
typedef VlcPluginGtk VlcPlugin; typedef VlcPluginGtk VlcPlugin;
# else # else
# include "vlcplugin_xlib.h" # include "vlcplugin_xcb.h"
typedef VlcPluginXlib VlcPlugin; typedef VlcPluginXcb VlcPlugin;
# endif # endif
#elif defined(XP_WIN) #elif defined(XP_WIN)
# include "vlcplugin_win.h" # 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 * Copyright (C) 2011 the VideoLAN team
* $Id$ * $Id$
...@@ -24,46 +24,43 @@ ...@@ -24,46 +24,43 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "vlcplugin_xlib.h" #include "vlcplugin_xcb.h"
#include <cstring> #include <cstring>
#include <cstdlib>
VlcPluginXlib::VlcPluginXlib(NPP instance, NPuint16_t mode) : VlcPluginXcb::VlcPluginXcb(NPP instance, NPuint16_t mode) :
VlcPluginBase(instance, mode) VlcPluginBase(instance, mode)
{ {
memset(&npparent, 0, sizeof(Window)); memset(&parent, 0, sizeof(Window));
memset(&npvideo, 0, sizeof(Window)); memset(&video, 0, sizeof(Window));
}
VlcPluginXlib::~VlcPluginXlib()
{
} }
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, 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 (!b_allowfullscreen) return;
if (playlist_isplaying()) if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player); libvlc_toggle_fullscreen(libvlc_media_player);
} }
void VlcPluginXlib::set_fullscreen(int yes) void VlcPluginXcb::set_fullscreen(int yes)
{ {
if (!b_allowfullscreen) return; if (!b_allowfullscreen) return;
if (playlist_isplaying()) if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player,yes); libvlc_set_fullscreen(libvlc_media_player,yes);
} }
int VlcPluginXlib::get_fullscreen() int VlcPluginXcb::get_fullscreen()
{ {
int r = 0; int r = 0;
if (playlist_isplaying()) if (playlist_isplaying())
...@@ -71,66 +68,70 @@ int VlcPluginXlib::get_fullscreen() ...@@ -71,66 +68,70 @@ int VlcPluginXlib::get_fullscreen()
return r; return r;
} }
bool VlcPluginXlib::create_windows() bool VlcPluginXcb::create_windows()
{ {
Display *npdisplay = ( (NPSetWindowCallbackStruct *) npwindow.ws_info )->display;
Display *p_display = getDisplay();
Window socket = (Window) npwindow.window; Window socket = (Window) npwindow.window;
conn = xcb_connect(XDisplayString(npdisplay), NULL);
unsigned long xembed_info_buf[2] = const xcb_setup_t *setup = xcb_get_setup(conn);
{ PLUGIN_XEMBED_PROTOCOL_VERSION, XEMBED_MAPPED }; xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
Atom xembed_info_atom = XInternAtom( p_display, "_XEMBED_INFO", 1);
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 */ /* create windows */
npparent = XCreateSimpleWindow( p_display, socket, 0, 0, /* TODO: respect psz_bgcolor */
1, 1, const uint32_t parent_values[] = {0x0FFFFF};
0, i_blackColor, i_blackColor ); parent = xcb_generate_id(conn);
XChangeProperty( p_display, npparent, xembed_info_atom, xcb_create_window(conn, XCB_COPY_FROM_PARENT, parent, socket,
xembed_info_atom, 32, PropModeReplace, /* FIXME: figure out why the window refuses to be resized larger than initial size */
(unsigned char *)xembed_info_buf, 2); 0, 0, 20000, 20000, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
npvideo = XCreateSimpleWindow( p_display, npparent, 0, 0, screen->root_visual, XCB_CW_EVENT_MASK, parent_values);
1, 1, xcb_change_property(conn, XCB_PROP_MODE_REPLACE, parent,
0, i_blackColor, i_blackColor ); xembed_info_atom, xembed_info_atom,
32, 2, (void *) xembed_info_buf);
XMapWindow( p_display, npvideo ); 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; return true;
} }
bool VlcPluginXlib::resize_windows() bool VlcPluginXcb::resize_windows()
{ {
Display *p_display = getDisplay(); const uint32_t dims[] = {npwindow.width, npwindow.height};
xcb_configure_window(conn, video, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, dims);
int i_ret; xcb_configure_window(conn, parent, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, dims);
i_ret = XMoveResizeWindow( p_display, npparent, 0, 0, xcb_query_tree_cookie_t query_cookie = xcb_query_tree(conn, video);
npwindow.width, npwindow.height ); xcb_query_tree_reply_t *query_reply = xcb_query_tree_reply(conn, query_cookie, NULL);
i_ret = XMoveResizeWindow( p_display, npvideo, 0, 0,
npwindow.width, npwindow.height );
Window root_return, parent_return, *children_return; if (query_reply) {
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 /* XXX: Make assumptions related to the window parenting structure in
vlc/modules/video_output/x11/xcommon.c */ vlc/modules/video_output/x11/xcommon.c */
Window base_window = children_return[i_nchildren - 1]; 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);
i_ret = XResizeWindow( p_display, base_window,
npwindow.width, ( npwindow.height ) );
} }
xcb_flush(conn);
free(query_reply);
return true; 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 * Copyright (C) 2011 the VideoLAN team
* $Id$ * $Id$
...@@ -24,18 +24,18 @@ ...@@ -24,18 +24,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef __VLCPLUGIN_XLIB_H__ #ifndef __VLCPLUGIN_XCB_H__
#define __VLCPLUGIN_XLIB_H__ #define __VLCPLUGIN_XCB_H__
#include "vlcplugin_base.h" #include "vlcplugin_base.h"
#include <X11/Xlib.h> #include <xcb/xcb.h>
#include "xembed.h" #include "xembed.h"
class VlcPluginXlib : public VlcPluginBase class VlcPluginXcb : public VlcPluginBase
{ {
public: public:
VlcPluginXlib(NPP, NPuint16_t); VlcPluginXcb(NPP, NPuint16_t);
virtual ~VlcPluginXlib(); virtual ~VlcPluginXcb();
int setSize(unsigned width, unsigned height); int setSize(unsigned width, unsigned height);
...@@ -52,14 +52,15 @@ public: ...@@ -52,14 +52,15 @@ public:
void update_controls() {/* STUB */} void update_controls() {/* STUB */}
void popup_menu() {/* STUB */} void popup_menu() {/* STUB */}
Display *getDisplay();
private:
void set_player_window(); void set_player_window();
unsigned int i_width, i_height; 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; 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