Commit 4c0e43c1 authored by Cyril Deguet's avatar Cyril Deguet

* modules/gui/skins/x11/x11_api.cpp: fixed OSAPI_GetScreenSize

* all: added locks around X calls to make them thread safe (will be
  useful in the next commit ;-)
parent 2c90cd6d
......@@ -2,7 +2,7 @@
* skin_common.h: Private Skin interface description
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: skin_common.h,v 1.11 2003/06/01 16:39:49 asmax Exp $
* $Id: skin_common.h,v 1.12 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -88,6 +88,7 @@ struct intf_sys_t
#ifdef X11_SKINS
Display *display;
Window mainWin; // Window which receives "broadcast" events
vlc_mutex_t xlock;
#endif
#ifdef WIN32
......
......@@ -2,7 +2,7 @@
* skin-main.cpp: skins plugin for VLC
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: skin_main.cpp,v 1.29 2003/06/01 16:39:49 asmax Exp $
* $Id: skin_main.cpp,v 1.30 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -128,6 +128,7 @@ static int Open ( vlc_object_t *p_this )
#elif defined X11_SKINS
// Initialize X11
p_intf->p_sys->display = XOpenDisplay( NULL );
vlc_mutex_init( p_intf, &p_intf->p_sys->xlock );
#elif defined WIN32
// We dynamically load msimg32.dll to get a pointer to TransparentBlt()
......@@ -191,6 +192,8 @@ static void Close ( vlc_object_t *p_this )
FreeLibrary( p_intf->p_sys->h_msimg32_dll );
if( p_intf->p_sys->h_user32_dll )
FreeLibrary( p_intf->p_sys->h_user32_dll );
#elif defined X11_SKINS
vlc_mutex_destroy( &p_intf->p_sys->xlock );
#endif
// Destroy structure
......
......@@ -2,7 +2,7 @@
* x11_api.cpp: Various x11-specific functions
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_api.cpp,v 1.4 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_api.cpp,v 1.5 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -32,6 +32,7 @@
#include "../src/skin_common.h"
#include "../src/theme.h"
#include "../src/window.h"
#include "../os_theme.h"
#include "../os_window.h"
#include "../os_api.h"
#include "../src/event.h" // for MAX_PARAM_SIZE
......@@ -74,7 +75,10 @@ void OSAPI_PostMessage( SkinWindow *win, unsigned int message, unsigned int para
{
event.xclient.window = (( X11Window *)win)->GetHandle();
}
XSendEvent( g_pIntf->p_sys->display, event.xclient.window, False, 0, &event );
XLOCK;
XSendEvent( g_pIntf->p_sys->display, event.xclient.window, False, 0,
&event );
XUNLOCK;
}
//---------------------------------------------------------------------------
......@@ -117,8 +121,10 @@ int OSAPI_GetTime()
//---------------------------------------------------------------------------
void OSAPI_GetScreenSize( int &w, int &h )
{
/* w = GetSystemMetrics(SM_CXSCREEN);
h = GetSystemMetrics(SM_CYSCREEN);*/
Display *display = g_pIntf->p_sys->display;
int screen = DefaultScreen( display );
w = DisplayWidth( display, screen );
h = DisplayHeight( display, screen );
}
//---------------------------------------------------------------------------
void OSAPI_GetMousePos( int &x, int &y )
......@@ -129,8 +135,10 @@ void OSAPI_GetMousePos( int &x, int &y )
unsigned int xmask;
Window root = DefaultRootWindow( g_pIntf->p_sys->display );
XLOCK;
XQueryPointer( g_pIntf->p_sys->display, root, &rootReturn, &childReturn,
&rootx, &rooty, &winx, &winy, &xmask );
XUNLOCK;
x = rootx;
y = rooty;
}
......
......@@ -2,7 +2,7 @@
* x11_bitmap.cpp: X11 implementation of the Bitmap class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_bitmap.cpp,v 1.8 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_bitmap.cpp,v 1.9 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -74,6 +74,7 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
AlphaColor = (AColor & 0xff) << 16 | (AColor & 0xff00) |
(AColor & 0xff0000) >> 16;
XLOCK;
imlib_context_set_display( display );
imlib_context_set_visual( visual );
imlib_context_set_colormap( DefaultColormap( display, screen ) );
......@@ -107,6 +108,7 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
imlib_image_set_has_alpha( 1 );
imlib_image_set_irrelevant_alpha( 0 );
imlib_image_put_back_data( data );
XUNLOCK;
}
//---------------------------------------------------------------------------
X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, Graphics *from, int x, int y,
......@@ -151,8 +153,10 @@ X11Bitmap::~X11Bitmap()
{
if( Img )
{
XLOCK;
imlib_context_set_image( Img );
imlib_free_image();
XUNLOCK;
}
}
//---------------------------------------------------------------------------
......@@ -161,10 +165,12 @@ void X11Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
{
if( Img )
{
XLOCK;
Drawable destImg = ( (X11Graphics *)dest )->GetImage();
imlib_context_set_image( Img );
imlib_context_set_drawable( destImg );
imlib_render_image_part_on_drawable_at_size( x, y, w, h, xRef, yRef, w, h );
XUNLOCK;
}
}
//---------------------------------------------------------------------------
......
......@@ -2,7 +2,7 @@
* x11_font.cpp: X11 implementation of the Font class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_font.cpp,v 1.4 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_font.cpp,v 1.5 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -36,9 +36,8 @@
#include "../os_graphics.h"
#include "../src/font.h"
#include "../os_font.h"
// FIXME ...
extern intf_thread_t *g_pIntf;
#include "../src/theme.h"
#include "../os_theme.h"
//---------------------------------------------------------------------------
// Font object
......@@ -50,7 +49,9 @@ X11Font::X11Font( intf_thread_t *_p_intf, string fontname, int size,
display = g_pIntf->p_sys->display;
// FIXME: just a beginning...
XLOCK;
font = XLoadFont( display, "-misc-fixed-*-*-*-*-*-*-*-*-*-*-*-*" );
XUNLOCK;
}
//---------------------------------------------------------------------------
X11Font::~X11Font()
......@@ -66,8 +67,10 @@ void X11Font::GetSize( string text, int &w, int &h )
int direction, fontAscent, fontDescent;
XCharStruct overall;
XQueryTextExtents( display, font, text.c_str(), text.size(), &direction,
&fontAscent, &fontDescent, &overall );
XLOCK;
XQueryTextExtents( display, font, text.c_str(), text.size(),
&direction, &fontAscent, &fontDescent, &overall );
XUNLOCK;
w = overall.rbearing - overall.lbearing;
h = overall.ascent + overall.descent;
......@@ -83,10 +86,13 @@ void X11Font::GenericPrint( Graphics *dest, string text, int x, int y,
XGCValues gcVal;
gcVal.foreground = (color == 0 ? 10 : color);
gcVal.font = font;
XChangeGC( display, gc, GCForeground|GCFont, &gcVal );
// Render text on buffer
XDrawString( display, drawable, gc, x, y+h, text.c_str(), text.size());
XLOCK;
XChangeGC( display, gc, GCForeground|GCFont, &gcVal );
XDrawString( display, drawable, gc, x, y+h, text.c_str(),
text.size());
XUNLOCK;
}
//---------------------------------------------------------------------------
......
......@@ -2,7 +2,7 @@
* x11_graphics.cpp: X11 implementation of the Graphics and Region classes
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_graphics.cpp,v 1.5 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_graphics.cpp,v 1.6 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -35,6 +35,8 @@
#include "../src/graphics.h"
#include "../src/window.h"
#include "../os_window.h"
#include "../src/theme.h"
#include "../os_theme.h"
#include "x11_graphics.h"
#include "../src/skin_common.h"
......@@ -55,36 +57,45 @@ X11Graphics::X11Graphics( intf_thread_t *p_intf, int w, int h,
Window fromWnd = ( (X11Window *)from )->GetHandle();
XWindowAttributes attr;
XLOCK;
XGetWindowAttributes( display, fromWnd, &attr);
Image = XCreatePixmap( display, fromWnd, w, h, attr.depth );
XUNLOCK;
Gc = DefaultGC( display, screen );
}
else
{
Window root = DefaultRootWindow( display );
XLOCK;
Image = XCreatePixmap( display, root, w, h,
DefaultDepth( display, screen ) );
XUNLOCK;
Gc = DefaultGC( display, screen );
}
// Set the background color to black
XGCValues gcVal;
gcVal.foreground = 0;
XLOCK;
XChangeGC( display, Gc, GCForeground, &gcVal );
XFillRectangle( display, Image, Gc, 0, 0, w, h );
XUNLOCK;
}
//---------------------------------------------------------------------------
X11Graphics::~X11Graphics()
{
XLOCK;
XFreePixmap( display, Image );
XUNLOCK;
}
//---------------------------------------------------------------------------
void X11Graphics::CopyFrom( int dx, int dy, int dw, int dh, Graphics *Src,
int sx, int sy, int Flag )
{
XLOCK;
XCopyArea( display, (( X11Graphics* )Src )->GetImage(), Image, Gc,
sx, sy, dw, dh, dx, dy );
XUNLOCK;
}
//---------------------------------------------------------------------------
void X11Graphics::DrawRect( int x, int y, int w, int h, int color )
......
......@@ -2,7 +2,7 @@
* x11_run.cpp:
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_run.cpp,v 1.12 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_run.cpp,v 1.13 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -276,10 +276,19 @@ void OSRun( intf_thread_t *p_intf )
while( !close )
{
XEvent event;
while( !close && XPending( display ) > 0 )
int nPending;
XLOCK;
nPending = XPending( display );
XUNLOCK;
while( !close && nPending > 0 )
{
XLOCK;
XNextEvent( display, &event );
XUNLOCK;
close = ProcessEvent( p_intf, proc, &event );
XLOCK;
nPending = XPending( display );
XUNLOCK;
}
msleep( 1000 );
......
......@@ -2,7 +2,7 @@
* x11_theme.cpp: X11 implementation of the Theme class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_theme.cpp,v 1.8 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_theme.cpp,v 1.9 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -90,9 +90,11 @@ void X11Theme::OnLoadTheme()
CreateSystemMenu();
*/
Window root = DefaultRootWindow( display );
p_intf->p_sys->mainWin = XCreateSimpleWindow( display, root, 0, 0, 1, 1,
0, 0, 0 );
XLOCK;
p_intf->p_sys->mainWin = XCreateSimpleWindow( display, root, 0, 0,
1, 1, 0, 0, 0 );
XStoreName( display, p_intf->p_sys->mainWin, "VLC Media Player" );
XUNLOCK;
}
//---------------------------------------------------------------------------
void X11Theme::AddSystemMenu( string name, Event *event )
......@@ -110,7 +112,9 @@ void X11Theme::AddSystemMenu( string name, Event *event )
//---------------------------------------------------------------------------
void X11Theme::ChangeClientWindowName( string name )
{
XLOCK;
XStoreName( display, p_intf->p_sys->mainWin, name.c_str() );
XUNLOCK;
}
//---------------------------------------------------------------------------
void X11Theme::AddWindow( string name, int x, int y, bool visible,
......@@ -119,11 +123,14 @@ void X11Theme::AddWindow( string name, int x, int y, bool visible,
// Create the window
Window root = DefaultRootWindow( display );
XSetWindowAttributes attr;
XLOCK;
Window wnd = XCreateWindow( display, root, 0, 0, 1, 1, 0, 0, InputOutput,
CopyFromParent, 0, &attr );
XSelectInput( display, wnd, ExposureMask|StructureNotifyMask|
KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|
PointerMotionMask|EnterWindowMask|LeaveWindowMask);
KeyPressMask|KeyReleaseMask|ButtonPressMask|
ButtonReleaseMask|PointerMotionMask|EnterWindowMask|
LeaveWindowMask);
XUNLOCK;
// Changing decorations
struct {
......@@ -138,6 +145,7 @@ void X11Theme::AddWindow( string name, int x, int y, bool visible,
motifWmHints.flags = 2; // MWM_HINTS_DECORATIONS;
motifWmHints.decorations = 0;
XLOCK;
XChangeProperty( display, wnd, hints_atom, hints_atom, 32,
PropModeReplace, (unsigned char *)&motifWmHints,
sizeof( motifWmHints ) / sizeof( long ) );
......@@ -153,6 +161,7 @@ void X11Theme::AddWindow( string name, int x, int y, bool visible,
{
XNextEvent( display, &evt );
} while( evt.type != MapNotify );
XUNLOCK;
WindowList.push_back( (SkinWindow *)new OSWindow( p_intf, wnd, x, y,
visible, fadetime, alpha, movealpha, dragdrop, name ) ) ;
......
......@@ -2,7 +2,7 @@
* x11_theme.h: X11 implementation of the Theme class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_theme.h,v 1.2 2003/06/01 16:39:49 asmax Exp $
* $Id: x11_theme.h,v 1.3 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -33,6 +33,12 @@ using namespace std;
//--- X11 -------------------------------------------------------------------
#include <X11/Xlib.h>
// macros to make X calls thread safe
extern intf_thread_t *g_pIntf;
#define XLOCK vlc_mutex_lock( &g_pIntf->p_sys->xlock )
#define XUNLOCK vlc_mutex_unlock( &g_pIntf->p_sys->xlock )
//---------------------------------------------------------------------------
struct intf_thread_t;
class SkinWindow;
......@@ -40,6 +46,7 @@ class EventBank;
class BitmapBank;
class FontBank;
//---------------------------------------------------------------------------
class X11Theme : public Theme
{
......
......@@ -2,7 +2,7 @@
* x11_window.cpp: X11 implementation of the Window class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_window.cpp,v 1.8 2003/06/01 17:13:04 asmax Exp $
* $Id: x11_window.cpp,v 1.9 2003/06/01 22:11:24 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -46,6 +46,7 @@
#include "../os_graphics.h"
#include "../src/skin_common.h"
#include "../src/theme.h"
#include "../os_theme.h"
//---------------------------------------------------------------------------
......@@ -112,10 +113,6 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
attr.wclass = GDK_INPUT_OUTPUT;
gint mask = 0;
ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
Open();
//fprintf(stderr, "kludge in x11_window.cpp\n");
}
//---------------------------------------------------------------------------
X11Window::~X11Window()
......@@ -149,13 +146,16 @@ void X11Window::OSShow( bool show )
{
if( show )
{
XLOCK;
XMapWindow( display, Wnd );
XMoveWindow( display, Wnd, Left, Top );
XUNLOCK;
}
else
{
//XWithdrawWindow( display, Wnd, 0 );
XLOCK;
XUnmapWindow( display, Wnd );
XUNLOCK;
}
}
//---------------------------------------------------------------------------
......@@ -190,7 +190,9 @@ bool X11Window::ProcessOSEvent( Event *evt )
p_intf->p_sys->p_theme->WindowList.begin();
win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
{
XLOCK;
XRaiseWindow( display, ( (X11Window *)(*win) )->GetHandle() );
XUNLOCK;
}
switch( ( (XButtonEvent *)p2 )->button )
......@@ -280,6 +282,7 @@ void X11Window::RefreshFromImage( int x, int y, int w, int h )
{
Drawable drawable = (( X11Graphics* )Image )->GetImage();
XLOCK;
XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
......@@ -317,6 +320,7 @@ void X11Window::RefreshFromImage( int x, int y, int w, int h )
XDestroyRegion( region );
XSync( display, 0);
XUNLOCK;
}
//---------------------------------------------------------------------------
void X11Window::WindowManualMove()
......
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