2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// AutoSpace Window System for Linux/Win32 v0.85
|
|
|
|
// Writed by pontscho/fresh!mindworkz
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/Xatom.h>
|
2001-10-04 19:11:24 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
#include <stdio.h>
|
2001-10-04 19:11:24 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2001-08-25 21:04:29 +00:00
|
|
|
|
2001-11-06 12:32:27 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2002-02-23 15:12:55 +00:00
|
|
|
#include "../../config.h"
|
2003-01-09 20:47:14 +00:00
|
|
|
#include "../../libvo/x11_common.h"
|
2001-08-25 21:04:29 +00:00
|
|
|
#include "ws.h"
|
2002-08-11 13:12:38 +00:00
|
|
|
#include "wsxdnd.h"
|
2003-05-23 17:39:33 +00:00
|
|
|
#include "../../cpudetect.h"
|
|
|
|
#include "../../postproc/swscale.h"
|
2001-11-06 12:32:27 +00:00
|
|
|
#include "../../postproc/rgb2rgb.h"
|
2003-06-01 21:59:29 +00:00
|
|
|
#include "../../libmpcodecs/vf_scale.h"
|
2002-05-01 09:29:06 +00:00
|
|
|
#include "../../mp_msg.h"
|
2002-05-06 15:05:07 +00:00
|
|
|
#include "../../mplayer.h"
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
#include <X11/extensions/XShm.h>
|
2001-10-25 23:34:14 +00:00
|
|
|
#ifdef HAVE_XSHAPE
|
2001-08-25 21:04:29 +00:00
|
|
|
#include <X11/extensions/shape.h>
|
2001-10-25 23:34:14 +00:00
|
|
|
#endif
|
|
|
|
|
2003-05-26 08:45:43 +00:00
|
|
|
#ifdef HAVE_XINERAMA
|
|
|
|
#include <X11/extensions/Xinerama.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
|
2003-01-09 20:47:14 +00:00
|
|
|
#undef ENABLE_DPMS
|
2002-12-16 19:09:34 +00:00
|
|
|
|
2003-05-26 08:45:43 +00:00
|
|
|
#ifdef HAVE_XINERAMA
|
|
|
|
extern int xinerama_screen;
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-11-21 17:43:57 +00:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long functions;
|
|
|
|
unsigned long decorations;
|
2001-08-25 21:04:29 +00:00
|
|
|
long input_mode;
|
2001-11-21 17:43:57 +00:00
|
|
|
unsigned long status;
|
2001-08-25 21:04:29 +00:00
|
|
|
} MotifWmHints;
|
|
|
|
|
|
|
|
Atom wsMotifHints;
|
|
|
|
|
2002-02-01 16:34:22 +00:00
|
|
|
int wsMaxX = 0; // Screen width.
|
|
|
|
int wsMaxY = 0; // Screen height.
|
2003-05-26 08:45:43 +00:00
|
|
|
int wsOrgX = 0; // Screen origin x.
|
|
|
|
int wsOrgY = 0; // Screen origin y.
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
Display * wsDisplay;
|
|
|
|
int wsScreen;
|
|
|
|
Window wsRootWin;
|
|
|
|
XEvent wsEvent;
|
|
|
|
int wsWindowDepth;
|
|
|
|
GC wsHGC;
|
|
|
|
MotifWmHints wsMotifWmHints;
|
|
|
|
Atom wsTextProperlyAtom = None;
|
2002-05-06 15:05:07 +00:00
|
|
|
int wsLayer = 0;
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
int wsDepthOnScreen = 0;
|
|
|
|
int wsRedMask = 0;
|
|
|
|
int wsGreenMask = 0;
|
|
|
|
int wsBlueMask = 0;
|
|
|
|
int wsOutMask = 0;
|
|
|
|
|
|
|
|
int wsTrue = True;
|
|
|
|
|
2003-01-13 23:38:49 +00:00
|
|
|
#define wsWLCount 5
|
|
|
|
wsTWindow * wsWindowList[wsWLCount] = { NULL,NULL,NULL,NULL,NULL };
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
unsigned long wsKeyTable[512];
|
|
|
|
|
|
|
|
int wsUseXShm = 1;
|
|
|
|
int wsUseXShape = 1;
|
|
|
|
|
|
|
|
int XShmGetEventBase( Display* );
|
|
|
|
inline int wsSearch( Window win );
|
|
|
|
|
2002-08-31 17:04:59 +00:00
|
|
|
// ---
|
|
|
|
|
|
|
|
#define PACK_RGB16(r,g,b,pixel) pixel=(b>>3);\
|
|
|
|
pixel<<=6;\
|
|
|
|
pixel|=(g>>2);\
|
|
|
|
pixel<<=5;\
|
|
|
|
pixel|=(r>>3)
|
|
|
|
|
|
|
|
#define PACK_RGB15(r,g,b,pixel) pixel=(b>>3);\
|
|
|
|
pixel<<=5;\
|
|
|
|
pixel|=(g>>3);\
|
|
|
|
pixel<<=5;\
|
|
|
|
pixel|=(r>>3)
|
|
|
|
|
|
|
|
typedef void(*wsTConvFunc)( const unsigned char * in_pixels, unsigned char * out_pixels, unsigned num_pixels );
|
|
|
|
wsTConvFunc wsConvFunc = NULL;
|
2002-10-10 14:06:49 +00:00
|
|
|
|
|
|
|
void rgb32torgb32( const unsigned char * src, unsigned char * dst,unsigned int src_size )
|
2002-08-31 17:04:59 +00:00
|
|
|
{ memcpy( dst,src,src_size ); }
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
#define MWM_HINTS_FUNCTIONS (1L << 0)
|
|
|
|
#define MWM_HINTS_DECORATIONS (1L << 1)
|
|
|
|
#define MWM_HINTS_INPUT_MODE (1L << 2)
|
|
|
|
#define MWM_HINTS_STATUS (1L << 3)
|
|
|
|
|
|
|
|
#define MWM_FUNC_ALL (1L << 0)
|
|
|
|
#define MWM_FUNC_RESIZE (1L << 1)
|
|
|
|
#define MWM_FUNC_MOVE (1L << 2)
|
|
|
|
#define MWM_FUNC_MINIMIZE (1L << 3)
|
|
|
|
#define MWM_FUNC_MAXIMIZE (1L << 4)
|
|
|
|
#define MWM_FUNC_CLOSE (1L << 5)
|
|
|
|
|
|
|
|
#define MWM_DECOR_ALL (1L << 0)
|
|
|
|
#define MWM_DECOR_BORDER (1L << 1)
|
|
|
|
#define MWM_DECOR_RESIZEH (1L << 2)
|
|
|
|
#define MWM_DECOR_TITLE (1L << 3)
|
|
|
|
#define MWM_DECOR_MENU (1L << 4)
|
|
|
|
#define MWM_DECOR_MINIMIZE (1L << 5)
|
|
|
|
#define MWM_DECOR_MAXIMIZE (1L << 6)
|
|
|
|
|
|
|
|
#define MWM_INPUT_MODELESS 0
|
|
|
|
#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
|
|
|
|
#define MWM_INPUT_SYSTEM_MODAL 2
|
|
|
|
#define MWM_INPUT_FULL_APPLICATION_MODAL 3
|
|
|
|
#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
|
|
|
|
|
|
|
|
#define MWM_TEAROFF_WINDOW (1L<<0)
|
|
|
|
|
|
|
|
void wsWindowDecoration( wsTWindow * win,long d )
|
|
|
|
{
|
|
|
|
wsMotifHints=XInternAtom( wsDisplay,"_MOTIF_WM_HINTS",0 );
|
2001-11-21 17:43:57 +00:00
|
|
|
if ( wsMotifHints == None ) return;
|
|
|
|
|
|
|
|
memset( &wsMotifWmHints,0,sizeof( MotifWmHints ) );
|
2002-03-10 23:05:44 +00:00
|
|
|
wsMotifWmHints.flags=MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
|
|
|
|
if ( d )
|
|
|
|
{
|
|
|
|
wsMotifWmHints.functions=MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
|
|
|
|
wsMotifWmHints.decorations=MWM_DECOR_ALL;
|
|
|
|
}
|
2001-11-21 17:43:57 +00:00
|
|
|
XChangeProperty( wsDisplay,win->WindowID,wsMotifHints,wsMotifHints,32,
|
|
|
|
PropModeReplace,(unsigned char *)&wsMotifWmHints,5 );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Init X Window System.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int wsIOErrorHandler( Display * dpy )
|
|
|
|
{
|
|
|
|
fprintf( stderr,"[ws] io error in display.\n" );
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int wsErrorHandler( Display * dpy,XErrorEvent * Event )
|
|
|
|
{
|
|
|
|
char type[128];
|
|
|
|
XGetErrorText( wsDisplay,Event->error_code,type,128 );
|
|
|
|
fprintf(stderr,"[ws] Error in display.\n");
|
|
|
|
fprintf(stderr,"[ws] Error code: %d ( %s )\n",Event->error_code,type );
|
|
|
|
fprintf(stderr,"[ws] Request code: %d\n",Event->request_code );
|
|
|
|
fprintf(stderr,"[ws] Minor code: %d\n",Event->minor_code );
|
2002-10-19 19:47:16 +00:00
|
|
|
fprintf(stderr,"[ws] Modules: %s\n",current_module?current_module:"(NULL)" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
2001-08-27 23:56:44 +00:00
|
|
|
void wsXInit( void* mDisplay )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
|
|
|
int eventbase;
|
|
|
|
int errorbase;
|
|
|
|
|
2001-08-27 23:56:44 +00:00
|
|
|
if(mDisplay){
|
|
|
|
wsDisplay=mDisplay;
|
|
|
|
} else {
|
|
|
|
char * DisplayName = ":0.0";
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" );
|
|
|
|
wsDisplay=XOpenDisplay( DisplayName );
|
|
|
|
if ( !wsDisplay )
|
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] couldn't open the display !\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
2001-08-27 23:56:44 +00:00
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
|
2002-08-11 13:12:38 +00:00
|
|
|
/* enable DND atoms */
|
|
|
|
wsXDNDInitialize();
|
|
|
|
|
2001-09-02 17:49:48 +00:00
|
|
|
{ /* on remote display XShm will be disabled - LGB */
|
|
|
|
char *dispname=DisplayString(wsDisplay);
|
|
|
|
int localdisp=1;
|
|
|
|
if (dispname&&*dispname!=':') {
|
|
|
|
localdisp=0;
|
|
|
|
wsUseXShm=0;
|
|
|
|
}
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Display name: %s => %s display.\n",dispname,localdisp?"local":"REMOTE");
|
|
|
|
if (!localdisp) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Remote display, disabling XMITSHM\n");
|
2001-09-02 17:49:48 +00:00
|
|
|
}
|
2003-01-09 20:47:14 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( !XShmQueryExtension( wsDisplay ) )
|
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_ERR,"[ws] sorry, your system is not supported X shared memory extension.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
wsUseXShm=0;
|
|
|
|
}
|
2001-08-25 23:18:17 +00:00
|
|
|
#ifdef HAVE_XSHAPE
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( !XShapeQueryExtension( wsDisplay,&eventbase,&errorbase ) )
|
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_ERR,"[ws] sorry, your system is not supported XShape extension.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
wsUseXShape=0;
|
|
|
|
}
|
2001-08-25 23:18:17 +00:00
|
|
|
#else
|
2001-08-25 21:04:29 +00:00
|
|
|
wsUseXShape=0;
|
2001-08-25 23:18:17 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
XSynchronize( wsDisplay,True );
|
|
|
|
|
|
|
|
wsScreen=DefaultScreen( wsDisplay );
|
|
|
|
wsRootWin=RootWindow( wsDisplay,wsScreen );
|
2003-05-26 08:45:43 +00:00
|
|
|
#ifdef HAVE_XINERAMA
|
|
|
|
if(XineramaIsActive(wsDisplay))
|
|
|
|
{
|
|
|
|
XineramaScreenInfo *screens;
|
|
|
|
int num_screens;
|
|
|
|
|
|
|
|
screens = XineramaQueryScreens(wsDisplay, &num_screens);
|
|
|
|
if(xinerama_screen >= num_screens) xinerama_screen = 0;
|
|
|
|
wsOrgX = screens[xinerama_screen].x_org;
|
|
|
|
wsOrgY = screens[xinerama_screen].y_org;
|
|
|
|
wsMaxX=screens[xinerama_screen].width;
|
|
|
|
wsMaxY=screens[xinerama_screen].height;
|
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] screens %d Max %d, %d Org %d,%d\n",
|
|
|
|
num_screens, wsMaxX, wsMaxY, wsOrgX, wsOrgY);
|
|
|
|
XFree(screens);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
wsOrgX = wsOrgY = 0;
|
2001-08-25 21:04:29 +00:00
|
|
|
wsMaxX=DisplayWidth( wsDisplay,wsScreen );
|
|
|
|
wsMaxY=DisplayHeight( wsDisplay,wsScreen );
|
2003-05-26 08:45:43 +00:00
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
wsGetDepthOnScreen();
|
2001-08-25 23:18:17 +00:00
|
|
|
#ifdef DEBUG
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
|
|
|
int minor,major,shp;
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Screen depth: %d\n",wsDepthOnScreen );
|
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] size: %dx%d\n",wsMaxX,wsMaxY );
|
2003-05-26 08:45:43 +00:00
|
|
|
#ifdef HAVE_XINERAMA
|
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] origin: +%d+%d\n",wsOrgX,wsOrgY );
|
|
|
|
#endif
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] red mask: 0x%x\n",wsRedMask );
|
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] green mask: 0x%x\n",wsGreenMask );
|
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] blue mask: 0x%x\n",wsBlueMask );
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( wsUseXShm )
|
|
|
|
{
|
|
|
|
XShmQueryVersion( wsDisplay,&major,&minor,&shp );
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShm version is %d.%d\n",major,minor );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
#ifdef HAVE_XSHAPE
|
|
|
|
if ( wsUseXShape )
|
|
|
|
{
|
|
|
|
XShapeQueryVersion( wsDisplay,&major,&minor );
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShape version is %d.%d\n",major,minor );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2001-08-25 23:18:17 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
wsOutMask=wsGetOutMask();
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Initialized converter: " );
|
2003-07-12 17:19:18 +00:00
|
|
|
sws_rgb2rgb_init(get_sws_cpuflags());
|
2001-08-25 21:04:29 +00:00
|
|
|
switch ( wsOutMask )
|
|
|
|
{
|
|
|
|
case wsRGB32:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb32\n" );
|
2002-08-31 17:04:59 +00:00
|
|
|
wsConvFunc=rgb32torgb32;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsBGR32:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr32\n" );
|
2001-11-09 13:05:55 +00:00
|
|
|
wsConvFunc=rgb32tobgr32;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsRGB24:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb24\n" );
|
2001-11-06 12:32:27 +00:00
|
|
|
wsConvFunc=rgb32to24;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsBGR24:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr24\n" );
|
2002-08-31 17:04:59 +00:00
|
|
|
wsConvFunc=rgb32tobgr24;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsRGB16:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb16\n" );
|
2001-11-06 12:32:27 +00:00
|
|
|
wsConvFunc=rgb32to16;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsBGR16:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr16\n" );
|
2002-08-31 17:04:59 +00:00
|
|
|
wsConvFunc=rgb32tobgr16;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsRGB15:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb15\n" );
|
2001-11-06 12:32:27 +00:00
|
|
|
wsConvFunc=rgb32to15;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
case wsBGR15:
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr15\n" );
|
2002-08-31 17:04:59 +00:00
|
|
|
wsConvFunc=rgb32tobgr15;
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-05-06 15:05:07 +00:00
|
|
|
XSetErrorHandler( wsErrorHandler );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Create window.
|
|
|
|
// X,Y : window position
|
|
|
|
// wX,wY : size of window
|
|
|
|
// bW : border width
|
|
|
|
// cV : visible mouse cursor on window
|
|
|
|
// D : visible frame, title, etc.
|
|
|
|
// sR : screen ratio
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
XClassHint wsClassHint;
|
|
|
|
XTextProperty wsTextProperty;
|
|
|
|
Window LeaderWindow;
|
|
|
|
|
|
|
|
void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label )
|
|
|
|
{
|
2002-10-19 19:54:59 +00:00
|
|
|
int depth;
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
win->Property=D;
|
|
|
|
if ( D & wsShowFrame ) win->Decorations=1;
|
|
|
|
wsHGC=DefaultGC( wsDisplay,wsScreen );
|
|
|
|
// The window position and size.
|
|
|
|
switch ( X )
|
|
|
|
{
|
2003-05-26 08:45:43 +00:00
|
|
|
case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ) + wsOrgX; break;
|
|
|
|
case -2: win->X=wsMaxX - wX - 1 + wsOrgX; break;
|
2001-08-25 21:04:29 +00:00
|
|
|
default: win->X=X; break;
|
|
|
|
}
|
|
|
|
switch ( Y )
|
|
|
|
{
|
2003-05-26 08:45:43 +00:00
|
|
|
case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ) + wsOrgY; break;
|
|
|
|
case -2: win->Y=wsMaxY - hY - 1 + wsOrgY; break;
|
2001-08-25 21:04:29 +00:00
|
|
|
default: win->Y=Y; break;
|
|
|
|
}
|
|
|
|
win->Width=wX;
|
|
|
|
win->Height=hY;
|
|
|
|
win->OldX=win->X;
|
|
|
|
win->OldY=win->Y;
|
|
|
|
win->OldWidth=win->Width;
|
|
|
|
win->OldHeight=win->Height;
|
|
|
|
|
|
|
|
// Border size for window.
|
|
|
|
win->BorderWidth=bW;
|
|
|
|
// Hide Mouse Cursor
|
|
|
|
win->wsCursor=None;
|
|
|
|
win->wsMouseEventType=cV;
|
|
|
|
win->wsCursorData[0]=0;
|
|
|
|
win->wsCursorPixmap=XCreateBitmapFromData( wsDisplay,wsRootWin,win->wsCursorData,1,1 );
|
|
|
|
if ( !(cV & wsShowMouseCursor) ) win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 );
|
|
|
|
|
2002-10-19 19:54:59 +00:00
|
|
|
depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,NULL );
|
|
|
|
if ( depth < 15 )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] sorry, this color depth is not enough.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
2002-10-19 19:54:59 +00:00
|
|
|
XMatchVisualInfo( wsDisplay,wsScreen,depth,TrueColor,&win->VisualInfo );
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False );
|
|
|
|
win->AtomDeleteWindow=XInternAtom( wsDisplay,"WM_DELETE_WINDOW",False );
|
|
|
|
win->AtomTakeFocus=XInternAtom( wsDisplay,"WM_TAKE_FOCUS",False );
|
|
|
|
win->AtomRolle=XInternAtom( wsDisplay,"WM_WINDOW_ROLE",False );
|
2001-11-12 12:26:09 +00:00
|
|
|
win->AtomWMSizeHint=XInternAtom( wsDisplay,"WM_SIZE_HINT",False );
|
|
|
|
win->AtomWMNormalHint=XInternAtom( wsDisplay,"WM_NORMAL_HINT",False );
|
2001-08-25 21:04:29 +00:00
|
|
|
win->AtomProtocols=XInternAtom( wsDisplay,"WM_PROTOCOLS",False );
|
|
|
|
win->AtomsProtocols[0]=win->AtomDeleteWindow;
|
|
|
|
win->AtomsProtocols[1]=win->AtomTakeFocus;
|
|
|
|
win->AtomsProtocols[2]=win->AtomRolle;
|
|
|
|
// ---
|
|
|
|
|
|
|
|
win->WindowAttrib.background_pixel=BlackPixel( wsDisplay,wsScreen );
|
|
|
|
win->WindowAttrib.border_pixel=WhitePixel( wsDisplay,wsScreen );
|
|
|
|
win->WindowAttrib.colormap=XCreateColormap( wsDisplay,wsRootWin,win->VisualInfo.visual,AllocNone );
|
|
|
|
win->WindowAttrib.event_mask=StructureNotifyMask | FocusChangeMask |
|
|
|
|
ExposureMask | PropertyChangeMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
VisibilityChangeMask |
|
|
|
|
KeyPressMask | KeyReleaseMask;
|
|
|
|
if ( ( cV & wsHandleMouseButton ) ) win->WindowAttrib.event_mask|=ButtonPressMask | ButtonReleaseMask;
|
|
|
|
if ( ( cV & wsHandleMouseMove ) ) win->WindowAttrib.event_mask|=PointerMotionMask;
|
|
|
|
win->WindowAttrib.cursor=win->wsCursor;
|
|
|
|
win->WindowAttrib.override_redirect=False;
|
|
|
|
if ( D & wsOverredirect ) win->WindowAttrib.override_redirect=True;
|
|
|
|
|
|
|
|
win->WindowMask=CWBackPixel | CWBorderPixel |
|
|
|
|
CWColormap | CWEventMask | CWCursor |
|
|
|
|
CWOverrideRedirect;
|
|
|
|
|
|
|
|
win->WindowID=XCreateWindow( wsDisplay,
|
|
|
|
(win->Parent != 0?win->Parent:wsRootWin),
|
|
|
|
win->X,win->Y,win->Width,win->Height,win->BorderWidth,
|
|
|
|
win->VisualInfo.depth,
|
|
|
|
InputOutput,
|
|
|
|
win->VisualInfo.visual,
|
|
|
|
win->WindowMask,&win->WindowAttrib );
|
|
|
|
|
2002-01-29 20:39:48 +00:00
|
|
|
wsClassHint.res_name="MPlayer";
|
|
|
|
|
2001-10-01 12:28:39 +00:00
|
|
|
wsClassHint.res_class="MPlayer";
|
2001-08-25 21:04:29 +00:00
|
|
|
XSetClassHint( wsDisplay,win->WindowID,&wsClassHint );
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
win->SizeHint.flags=PPosition | PSize | PResizeInc | PWinGravity;// | PBaseSize;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->SizeHint.x=win->X;
|
|
|
|
win->SizeHint.y=win->Y;
|
|
|
|
win->SizeHint.width=win->Width;
|
|
|
|
win->SizeHint.height=win->Height;
|
2002-05-05 18:46:42 +00:00
|
|
|
|
2001-09-06 09:36:48 +00:00
|
|
|
if ( D & wsMinSize )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
2001-09-06 09:36:48 +00:00
|
|
|
win->SizeHint.flags|=PMinSize;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->SizeHint.min_width=win->Width;
|
|
|
|
win->SizeHint.min_height=win->Height;
|
|
|
|
}
|
2001-09-06 09:36:48 +00:00
|
|
|
if ( D & wsMaxSize )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
2001-09-06 09:36:48 +00:00
|
|
|
win->SizeHint.flags|=PMaxSize;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->SizeHint.max_width=win->Width;
|
|
|
|
win->SizeHint.max_height=win->Height;
|
|
|
|
}
|
2002-05-05 18:46:42 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
win->SizeHint.height_inc=1;
|
|
|
|
win->SizeHint.width_inc=1;
|
2002-05-01 09:29:06 +00:00
|
|
|
win->SizeHint.base_width=win->Width;
|
|
|
|
win->SizeHint.base_height=win->Height;
|
2001-11-12 12:26:09 +00:00
|
|
|
win->SizeHint.win_gravity=StaticGravity;
|
2001-08-25 21:04:29 +00:00
|
|
|
XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
|
|
|
|
|
|
|
|
win->WMHints.flags=InputHint | StateHint;
|
|
|
|
win->WMHints.input=True;
|
|
|
|
win->WMHints.initial_state=NormalState;
|
|
|
|
XSetWMHints( wsDisplay,win->WindowID,&win->WMHints );
|
|
|
|
|
|
|
|
wsWindowDecoration( win,win->Decorations );
|
|
|
|
XStoreName( wsDisplay,win->WindowID,label );
|
|
|
|
XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL );
|
|
|
|
|
|
|
|
XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 );
|
|
|
|
XChangeProperty( wsDisplay,win->WindowID,
|
|
|
|
win->AtomLeaderClient,
|
|
|
|
XA_WINDOW,32,PropModeReplace,
|
|
|
|
(unsigned char *)&LeaderWindow,1 );
|
|
|
|
|
|
|
|
wsTextProperty.value=label;
|
|
|
|
wsTextProperty.encoding=XA_STRING;
|
|
|
|
wsTextProperty.format=8;
|
|
|
|
wsTextProperty.nitems=strlen( label );
|
|
|
|
XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty );
|
|
|
|
|
|
|
|
win->wGC=XCreateGC( wsDisplay,win->WindowID,
|
2001-08-31 22:06:28 +00:00
|
|
|
GCForeground | GCBackground,
|
2001-08-25 21:04:29 +00:00
|
|
|
&win->wGCV );
|
|
|
|
|
|
|
|
win->Visible=0;
|
|
|
|
win->Focused=0;
|
|
|
|
win->Mapped=0;
|
|
|
|
win->Rolled=0;
|
|
|
|
if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID );
|
|
|
|
|
2001-09-05 18:17:22 +00:00
|
|
|
wsCreateImage( win,win->Width,win->Height );
|
2001-08-25 21:04:29 +00:00
|
|
|
// --- End of creating --------------------------------------------------------------------------
|
|
|
|
|
2003-01-13 23:38:49 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for ( i=0;i < wsWLCount;i++ )
|
|
|
|
if ( wsWindowList[i] == NULL ) break;
|
|
|
|
if ( i == wsWLCount )
|
2003-08-14 01:45:16 +00:00
|
|
|
{ mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] there are too many open windows\n" ); exit( 0 ); }
|
2003-01-13 23:38:49 +00:00
|
|
|
wsWindowList[i]=win;
|
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
XFlush( wsDisplay );
|
|
|
|
XSync( wsDisplay,False );
|
|
|
|
|
|
|
|
win->ReDraw=NULL;
|
|
|
|
win->ReSize=NULL;
|
|
|
|
win->Idle=NULL;
|
|
|
|
win->MouseHandler=NULL;
|
|
|
|
win->KeyHandler=NULL;
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wsDestroyWindow( wsTWindow * win )
|
|
|
|
{
|
|
|
|
int l;
|
|
|
|
l=wsSearch( win->WindowID );
|
|
|
|
wsWindowList[l]=NULL;
|
|
|
|
if ( win->wsCursor != None )
|
|
|
|
{
|
|
|
|
XFreeCursor( wsDisplay,win->wsCursor );
|
|
|
|
win->wsCursor=None;
|
|
|
|
}
|
2003-01-13 23:38:49 +00:00
|
|
|
XFreeGC( wsDisplay,win->wGC );
|
2001-08-25 21:04:29 +00:00
|
|
|
XUnmapWindow( wsDisplay,win->WindowID );
|
|
|
|
wsDestroyImage( win );
|
|
|
|
XDestroyWindow( wsDisplay,win->WindowID );
|
2003-01-13 23:38:49 +00:00
|
|
|
#if 0
|
2001-08-25 21:04:29 +00:00
|
|
|
win->ReDraw=NULL;
|
|
|
|
win->ReSize=NULL;
|
|
|
|
win->Idle=NULL;
|
|
|
|
win->MouseHandler=NULL;
|
|
|
|
win->KeyHandler=NULL;
|
|
|
|
win->Visible=0;
|
|
|
|
win->Focused=0;
|
|
|
|
win->Mapped=0;
|
|
|
|
win->Rolled=0;
|
2003-01-13 23:38:49 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Handle events.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline int wsSearch( Window win )
|
|
|
|
{
|
|
|
|
int i;
|
2003-01-13 23:38:49 +00:00
|
|
|
for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i] && wsWindowList[i]->WindowID == win ) return i;
|
2001-08-25 21:04:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool wsEvents( Display * display,XEvent * Event,XPointer arg )
|
|
|
|
{
|
|
|
|
unsigned long i = 0;
|
|
|
|
int l;
|
|
|
|
int x,y;
|
|
|
|
Window child_window = 0;
|
|
|
|
|
|
|
|
l=wsSearch( Event->xany.window );
|
|
|
|
if ( l == -1 ) return !wsTrue;
|
2001-08-30 19:44:39 +00:00
|
|
|
wsWindowList[l]->State=0;
|
2001-08-25 21:04:29 +00:00
|
|
|
switch( Event->type )
|
|
|
|
{
|
|
|
|
case ClientMessage:
|
|
|
|
if ( Event->xclient.message_type == wsWindowList[l]->AtomProtocols )
|
|
|
|
{
|
2002-10-16 15:35:28 +00:00
|
|
|
if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow )
|
2002-05-01 09:29:06 +00:00
|
|
|
{ i=wsWindowClosed; goto expose; }
|
2002-10-16 15:35:28 +00:00
|
|
|
if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus )
|
2001-08-25 21:04:29 +00:00
|
|
|
{ i=wsWindowFocusIn; wsWindowList[l]->Focused=wsFocused; goto expose; }
|
2002-10-16 15:35:28 +00:00
|
|
|
if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle )
|
2002-05-01 09:29:06 +00:00
|
|
|
{ mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] rolled.\n" ); }
|
2002-08-11 13:12:38 +00:00
|
|
|
} else {
|
|
|
|
/* try to process DND events */
|
|
|
|
wsXDNDProcessClientMessage(wsWindowList[l],&Event->xclient);
|
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MapNotify: i=wsWindowMapped; wsWindowList[l]->Mapped=wsMapped; goto expose;
|
|
|
|
case UnmapNotify: i=wsWindowUnmapped; wsWindowList[l]->Mapped=wsNone; goto expose;
|
|
|
|
case FocusIn:
|
|
|
|
if ( wsWindowList[l]->Focused == wsFocused ) break;
|
2001-11-12 12:26:09 +00:00
|
|
|
i=wsWindowFocusIn;
|
|
|
|
wsWindowList[l]->Focused=wsFocused;
|
|
|
|
goto expose;
|
2001-08-25 21:04:29 +00:00
|
|
|
case FocusOut:
|
|
|
|
if ( wsWindowList[l]->Focused == wsNone ) break;
|
2001-11-12 12:26:09 +00:00
|
|
|
i=wsWindowFocusOut;
|
|
|
|
wsWindowList[l]->Focused=wsNone;
|
|
|
|
goto expose;
|
2001-08-25 21:04:29 +00:00
|
|
|
case VisibilityNotify:
|
|
|
|
switch( Event->xvisibility.state )
|
|
|
|
{
|
|
|
|
case VisibilityUnobscured: i=wsWindowVisible; wsWindowList[l]->Visible=wsVisible; goto expose;
|
|
|
|
case VisibilityFullyObscured: i=wsWindowNotVisible; wsWindowList[l]->Visible=wsNotVisible; goto expose;
|
|
|
|
case VisibilityPartiallyObscured: i=wsWindowPartialVisible; wsWindowList[l]->Visible=wsPVisible; goto expose;
|
|
|
|
}
|
|
|
|
expose:
|
|
|
|
wsWindowList[l]->State=i;
|
2002-11-02 20:10:18 +00:00
|
|
|
if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw();
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Expose:
|
|
|
|
wsWindowList[l]->State=wsWindowExpose;
|
2002-11-02 20:10:18 +00:00
|
|
|
if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw();
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ConfigureNotify:
|
|
|
|
XTranslateCoordinates( wsDisplay,wsWindowList[l]->WindowID,wsRootWin,0,0,&x,&y,&child_window );
|
|
|
|
if ( ( wsWindowList[l]->X != x )||( wsWindowList[l]->Y != y )||( wsWindowList[l]->Width != Event->xconfigure.width )||( wsWindowList[l]->Height != Event->xconfigure.height ) )
|
|
|
|
{
|
|
|
|
wsWindowList[l]->X=x; wsWindowList[l]->Y=y;
|
|
|
|
wsWindowList[l]->Width=Event->xconfigure.width; wsWindowList[l]->Height=Event->xconfigure.height;
|
|
|
|
if ( wsWindowList[l]->ReSize ) wsWindowList[l]->ReSize( wsWindowList[l]->X,wsWindowList[l]->Y,wsWindowList[l]->Width,wsWindowList[l]->Height );
|
|
|
|
}
|
|
|
|
|
|
|
|
wsWindowList[l]->Rolled=wsNone;
|
|
|
|
if ( Event->xconfigure.y < 0 )
|
|
|
|
{ i=wsWindowRolled; wsWindowList[l]->Rolled=wsRolled; goto expose; }
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyPress: i=wsKeyPressed; goto keypressed;
|
|
|
|
case KeyRelease: i=wsKeyReleased;
|
|
|
|
keypressed:
|
|
|
|
wsWindowList[l]->Alt=0;
|
|
|
|
wsWindowList[l]->Shift=0;
|
|
|
|
wsWindowList[l]->NumLock=0;
|
|
|
|
wsWindowList[l]->Control=0;
|
|
|
|
wsWindowList[l]->CapsLock=0;
|
|
|
|
if ( Event->xkey.state & Mod1Mask ) wsWindowList[l]->Alt=1;
|
|
|
|
if ( Event->xkey.state & Mod2Mask ) wsWindowList[l]->NumLock=1;
|
|
|
|
if ( Event->xkey.state & ControlMask ) wsWindowList[l]->Control=1;
|
|
|
|
if ( Event->xkey.state & ShiftMask ) wsWindowList[l]->Shift=1;
|
|
|
|
if ( Event->xkey.state & LockMask ) wsWindowList[l]->CapsLock=1;
|
2002-05-14 11:41:02 +00:00
|
|
|
#if 0
|
2002-05-25 09:46:37 +00:00
|
|
|
{
|
|
|
|
KeySym keySym;
|
|
|
|
keySym=XKeycodeToKeysym( wsDisplay,Event->xkey.keycode,0 );
|
|
|
|
if ( keySym != NoSymbol )
|
|
|
|
{
|
|
|
|
keySym=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) );
|
|
|
|
wsKeyTable[ keySym ]=i;
|
|
|
|
if ( wsWindowList[l]->KeyHandler )
|
|
|
|
wsWindowList[l]->KeyHandler( Event->xkey.state,i,keySym );
|
|
|
|
}
|
|
|
|
}
|
2002-05-14 11:41:02 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
char buf[100];
|
|
|
|
KeySym keySym;
|
|
|
|
static XComposeStatus stat;
|
|
|
|
|
|
|
|
XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat );
|
|
|
|
key=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) );
|
|
|
|
wsKeyTable[ key ]=i;
|
2002-05-25 09:46:37 +00:00
|
|
|
if ( wsWindowList[l]->KeyHandler ) wsWindowList[l]->KeyHandler( Event->xkey.keycode,i,key );
|
2002-05-14 11:41:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
break;
|
|
|
|
|
2003-01-12 17:34:46 +00:00
|
|
|
case MotionNotify:
|
|
|
|
i=wsMoveMouse;
|
|
|
|
{
|
|
|
|
/* pump all motion events from the display queue:
|
|
|
|
this way it works faster when moving the window */
|
2003-01-17 22:39:43 +00:00
|
|
|
static XEvent e;
|
|
|
|
if ( Event->xmotion.state )
|
|
|
|
{
|
|
|
|
while(XCheckTypedWindowEvent(display,Event->xany.window,MotionNotify,&e)){
|
2003-01-12 17:34:46 +00:00
|
|
|
/* FIXME: need to make sure we didn't release/press the button in between...*/
|
|
|
|
/* FIXME: do we need some timeout here to make sure we don't spend too much time
|
|
|
|
removing events from the queue? */
|
|
|
|
Event = &e;
|
2003-01-17 22:39:43 +00:00
|
|
|
}
|
2003-01-12 17:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
goto buttonreleased;
|
2001-08-25 21:04:29 +00:00
|
|
|
case ButtonRelease: i=Event->xbutton.button + 128; goto buttonreleased;
|
|
|
|
case ButtonPress: i=Event->xbutton.button; goto buttonreleased;
|
|
|
|
case EnterNotify: i=wsEnterWindow; goto buttonreleased;
|
|
|
|
case LeaveNotify: i=wsLeaveWindow;
|
|
|
|
buttonreleased:
|
|
|
|
if ( wsWindowList[l]->MouseHandler )
|
|
|
|
wsWindowList[l]->MouseHandler( i,Event->xbutton.x,Event->xbutton.y,Event->xmotion.x_root,Event->xmotion.y_root );
|
|
|
|
break;
|
|
|
|
|
2002-08-11 13:12:38 +00:00
|
|
|
case SelectionNotify:
|
|
|
|
/* Handle DandD */
|
|
|
|
wsXDNDProcessSelection(wsWindowList[l],Event);
|
|
|
|
break;
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
XFlush( wsDisplay );
|
|
|
|
XSync( wsDisplay,False );
|
|
|
|
return !wsTrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool wsDummyEvents( Display * display,XEvent * Event,XPointer arg )
|
|
|
|
{ return True; }
|
|
|
|
|
2002-02-23 15:12:55 +00:00
|
|
|
void wsHandleEvents( void ){
|
2001-08-27 00:55:25 +00:00
|
|
|
// handle pending events
|
|
|
|
while ( XPending(wsDisplay) ){
|
|
|
|
XNextEvent( wsDisplay,&wsEvent );
|
|
|
|
// printf("### X event: %d [%d]\n",wsEvent.type,delay);
|
|
|
|
wsEvents( wsDisplay,&wsEvent,NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
void wsMainLoop( void )
|
|
|
|
{
|
2001-08-25 23:18:17 +00:00
|
|
|
int delay=20;
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] init threads: %d\n",XInitThreads() );
|
2001-08-25 21:04:29 +00:00
|
|
|
XSynchronize( wsDisplay,False );
|
|
|
|
XLockDisplay( wsDisplay );
|
|
|
|
// XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL );
|
2001-08-25 23:18:17 +00:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
|
|
while(wsTrue){
|
|
|
|
// handle pending events
|
|
|
|
while ( XPending(wsDisplay) ){
|
|
|
|
XNextEvent( wsDisplay,&wsEvent );
|
|
|
|
wsEvents( wsDisplay,&wsEvent,NULL );
|
2001-08-26 00:35:51 +00:00
|
|
|
delay=0;
|
2001-08-25 23:18:17 +00:00
|
|
|
}
|
|
|
|
usleep(delay*1000); // FIXME!
|
2001-08-26 00:35:51 +00:00
|
|
|
if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity)
|
2001-08-25 23:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
while( wsTrue )
|
|
|
|
{
|
|
|
|
XIfEvent( wsDisplay,&wsEvent,wsDummyEvents,NULL );
|
|
|
|
wsEvents( wsDisplay,&wsEvent,NULL );
|
|
|
|
}
|
2001-08-25 23:18:17 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
XUnlockDisplay( wsDisplay );
|
|
|
|
}
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Move window to selected layer
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define WIN_LAYER_ONBOTTOM 2
|
|
|
|
#define WIN_LAYER_NORMAL 4
|
2002-11-11 16:57:09 +00:00
|
|
|
#define WIN_LAYER_ONTOP 10
|
2002-05-06 15:05:07 +00:00
|
|
|
|
|
|
|
void wsSetLayer( Display * wsDisplay, Window win, int layer )
|
2003-01-09 20:47:14 +00:00
|
|
|
{ vo_x11_setlayer( wsDisplay,win,layer ); }
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Switch to fullscreen.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsFullScreen( wsTWindow * win )
|
|
|
|
{
|
|
|
|
int decoration = 0;
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( win->isFullScreen )
|
|
|
|
{
|
|
|
|
win->X=win->OldX;
|
|
|
|
win->Y=win->OldY;
|
|
|
|
win->Width=win->OldWidth;
|
|
|
|
win->Height=win->OldHeight;
|
|
|
|
win->isFullScreen=False;
|
|
|
|
decoration=win->Decorations;
|
2002-12-16 19:09:34 +00:00
|
|
|
#ifdef ENABLE_DPMS
|
2001-08-25 21:04:29 +00:00
|
|
|
wsScreenSaverOn( wsDisplay );
|
2002-12-16 19:09:34 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
win->OldX=win->X; win->OldY=win->Y;
|
|
|
|
win->OldWidth=win->Width; win->OldHeight=win->Height;
|
2003-05-26 08:45:43 +00:00
|
|
|
win->X=wsOrgX; win->Y=wsOrgY;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->Width=wsMaxX; win->Height=wsMaxY;
|
|
|
|
win->isFullScreen=True;
|
2002-12-16 19:09:34 +00:00
|
|
|
#ifdef ENABLE_DPMS
|
2001-08-25 21:04:29 +00:00
|
|
|
wsScreenSaverOff( wsDisplay );
|
2002-12-16 19:09:34 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
2003-02-07 19:38:39 +00:00
|
|
|
vo_x11_decoration( wsDisplay,win->WindowID,decoration );
|
|
|
|
vo_x11_sizehint( win->X,win->Y,win->Width,win->Height,0 );
|
2003-01-09 20:47:14 +00:00
|
|
|
vo_x11_setlayer( wsDisplay,win->WindowID,win->isFullScreen );
|
2003-02-07 19:38:39 +00:00
|
|
|
if ( vo_wm_type == 0 && !(vo_fsmode&16) )
|
|
|
|
XWithdrawWindow( wsDisplay,win->WindowID,wsScreen );
|
|
|
|
XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height );
|
2002-04-29 22:00:50 +00:00
|
|
|
XMapRaised( wsDisplay,win->WindowID );
|
2001-08-25 21:04:29 +00:00
|
|
|
XRaiseWindow( wsDisplay,win->WindowID );
|
2003-01-09 20:47:14 +00:00
|
|
|
XFlush( wsDisplay );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Redraw screen.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsPostRedisplay( wsTWindow * win )
|
|
|
|
{
|
|
|
|
if ( win->ReDraw )
|
|
|
|
{
|
2002-07-25 20:26:38 +00:00
|
|
|
win->State=wsWindowExpose;
|
2002-11-02 20:10:18 +00:00
|
|
|
win->ReDraw();
|
2001-08-25 21:04:29 +00:00
|
|
|
XFlush( wsDisplay );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Do Exit.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsDoExit( void )
|
|
|
|
{ wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); }
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Put 'Image' to window.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size )
|
2001-11-06 12:32:27 +00:00
|
|
|
{ if ( wsConvFunc ) wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height * 4 ); }
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
void wsPutImage( wsTWindow * win )
|
|
|
|
{
|
|
|
|
if ( wsUseXShm )
|
|
|
|
{
|
|
|
|
XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage,
|
|
|
|
0,0,
|
|
|
|
( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2,
|
|
|
|
win->xImage->width,win->xImage->height,0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
XPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage,
|
|
|
|
0,0,
|
|
|
|
( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2,
|
|
|
|
win->xImage->width,win->xImage->height );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Move window to x, y.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
2001-11-12 15:16:13 +00:00
|
|
|
void wsMoveWindow( wsTWindow * win,int b,int x, int y )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
2001-11-12 15:16:13 +00:00
|
|
|
if ( b )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
2001-11-12 15:16:13 +00:00
|
|
|
switch ( x )
|
|
|
|
{
|
2003-05-26 08:45:43 +00:00
|
|
|
case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ) + wsOrgX; break;
|
|
|
|
case -2: win->X=wsMaxX - win->Width + wsOrgX; break;
|
2001-11-12 15:16:13 +00:00
|
|
|
default: win->X=x; break;
|
|
|
|
}
|
|
|
|
switch ( y )
|
|
|
|
{
|
2003-05-26 08:45:43 +00:00
|
|
|
case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ) + wsOrgY; break;
|
|
|
|
case -2: win->Y=wsMaxY - win->Height + wsOrgY; break;
|
2001-11-12 15:16:13 +00:00
|
|
|
default: win->Y=y; break;
|
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
2001-11-12 15:16:13 +00:00
|
|
|
else { win->X=x; win->Y=y; }
|
2001-08-25 21:04:29 +00:00
|
|
|
|
2001-11-12 12:26:09 +00:00
|
|
|
win->SizeHint.flags=PPosition | PWinGravity;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->SizeHint.x=win->X;
|
|
|
|
win->SizeHint.y=win->Y;
|
2001-11-12 12:26:09 +00:00
|
|
|
win->SizeHint.win_gravity=StaticGravity;
|
2001-08-25 21:04:29 +00:00
|
|
|
XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
|
|
|
|
|
|
|
|
XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y );
|
2001-08-31 21:16:58 +00:00
|
|
|
if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Resize window to sx, sy.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsResizeWindow( wsTWindow * win,int sx, int sy )
|
|
|
|
{
|
|
|
|
win->Width=sx;
|
|
|
|
win->Height=sy;
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
win->SizeHint.flags=PPosition | PSize | PWinGravity;// | PBaseSize;
|
2002-05-05 18:46:42 +00:00
|
|
|
win->SizeHint.x=win->X;
|
|
|
|
win->SizeHint.y=win->Y;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->SizeHint.width=win->Width;
|
|
|
|
win->SizeHint.height=win->Height;
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( win->Property & wsMinSize )
|
|
|
|
{
|
|
|
|
win->SizeHint.flags|=PMinSize;
|
|
|
|
win->SizeHint.min_width=win->Width;
|
|
|
|
win->SizeHint.min_height=win->Height;
|
|
|
|
}
|
|
|
|
if ( win->Property & wsMaxSize )
|
|
|
|
{
|
|
|
|
win->SizeHint.flags|=PMaxSize;
|
|
|
|
win->SizeHint.max_width=win->Width;
|
|
|
|
win->SizeHint.max_height=win->Height;
|
|
|
|
}
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2001-11-12 12:26:09 +00:00
|
|
|
win->SizeHint.win_gravity=StaticGravity;
|
2002-05-05 18:46:42 +00:00
|
|
|
win->SizeHint.base_width=sx; win->SizeHint.base_height=sy;
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2003-02-07 19:38:39 +00:00
|
|
|
if ( vo_wm_type == 0 ) XUnmapWindow( wsDisplay,win->WindowID );
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
|
|
|
|
XResizeWindow( wsDisplay,win->WindowID,sx,sy );
|
2002-05-05 18:46:42 +00:00
|
|
|
XMapRaised( wsDisplay,win->WindowID );
|
2001-08-31 21:16:58 +00:00
|
|
|
if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Iconify window.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsIconify( wsTWindow win )
|
|
|
|
{ XIconifyWindow( wsDisplay,win.WindowID,0 ); }
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Move top the window.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
2002-05-20 13:56:16 +00:00
|
|
|
void wsMoveTopWindow( Display * wsDisplay,Window win )
|
2001-11-12 12:26:09 +00:00
|
|
|
{
|
2003-01-09 20:47:14 +00:00
|
|
|
// XUnmapWindow( wsDisplay,win );
|
|
|
|
// XMapWindow( wsDisplay,win );
|
|
|
|
XMapRaised( wsDisplay,win );
|
|
|
|
XRaiseWindow( wsDisplay,win );
|
2001-10-02 15:01:56 +00:00
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Set window background to 'color'.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsSetBackground( wsTWindow * win,int color )
|
|
|
|
{ XSetWindowBackground( wsDisplay,win->WindowID,color ); }
|
|
|
|
|
|
|
|
void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b )
|
|
|
|
{
|
|
|
|
int color = 0;
|
|
|
|
switch ( wsOutMask )
|
|
|
|
{
|
|
|
|
case wsRGB32:
|
|
|
|
case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break;
|
|
|
|
case wsBGR32:
|
|
|
|
case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break;
|
2001-11-06 12:32:27 +00:00
|
|
|
case wsRGB16: PACK_RGB16( b,g,r,color ); break;
|
|
|
|
case wsBGR16: PACK_RGB16( r,g,b,color ); break;
|
|
|
|
case wsRGB15: PACK_RGB15( b,g,r,color ); break;
|
|
|
|
case wsBGR15: PACK_RGB15( r,g,b,color ); break;
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
XSetWindowBackground( wsDisplay,win->WindowID,color );
|
|
|
|
}
|
|
|
|
|
2001-08-31 22:06:28 +00:00
|
|
|
void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b )
|
|
|
|
{
|
|
|
|
int color = 0;
|
|
|
|
switch ( wsOutMask )
|
|
|
|
{
|
|
|
|
case wsRGB32:
|
|
|
|
case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break;
|
|
|
|
case wsBGR32:
|
|
|
|
case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break;
|
2001-11-06 12:32:27 +00:00
|
|
|
case wsRGB16: PACK_RGB16( b,g,r,color ); break;
|
|
|
|
case wsBGR16: PACK_RGB16( r,g,b,color ); break;
|
|
|
|
case wsRGB15: PACK_RGB15( b,g,r,color ); break;
|
|
|
|
case wsBGR15: PACK_RGB15( r,g,b,color ); break;
|
2001-08-31 22:06:28 +00:00
|
|
|
}
|
|
|
|
XSetForeground( wsDisplay,win->wGC,color );
|
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Draw string at x,y with fc ( foreground color ) and bc ( background color ).
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc )
|
|
|
|
{
|
|
|
|
XSetForeground( wsDisplay,win.wGC,bc );
|
|
|
|
XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y,
|
|
|
|
XTextWidth( win.Font,str,strlen( str ) ) + 20,
|
|
|
|
win.FontHeight + 2 );
|
|
|
|
XSetForeground( wsDisplay,win.wGC,fc );
|
|
|
|
XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Calculation string width.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
int wsTextWidth( wsTWindow win,char * str )
|
|
|
|
{ return XTextWidth( win.Font,str,strlen( str ) ) + 20; }
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Show / hide mouse cursor.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsVisibleMouse( wsTWindow * win,int m )
|
|
|
|
{
|
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case wsShowMouseCursor:
|
|
|
|
if ( win->wsCursor != None )
|
|
|
|
{
|
|
|
|
XFreeCursor( wsDisplay,win->wsCursor );
|
|
|
|
win->wsCursor=None;
|
|
|
|
}
|
|
|
|
XDefineCursor( wsDisplay,win->WindowID,0 );
|
|
|
|
break;
|
|
|
|
case wsHideMouseCursor:
|
|
|
|
win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 );
|
|
|
|
XDefineCursor( wsDisplay,win->WindowID,win->wsCursor );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
XFlush( wsDisplay );
|
|
|
|
}
|
|
|
|
|
|
|
|
int wsGetDepthOnScreen( void )
|
|
|
|
{
|
2002-10-19 19:54:59 +00:00
|
|
|
int depth;
|
|
|
|
XImage * mXImage;
|
|
|
|
Visual * visual;
|
|
|
|
|
|
|
|
if( (depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,&visual )) > 0 )
|
|
|
|
{
|
|
|
|
mXImage = XCreateImage( wsDisplay,visual,depth,ZPixmap,0,NULL,
|
|
|
|
1,1,32,0 );
|
|
|
|
wsDepthOnScreen = mXImage->bits_per_pixel;
|
|
|
|
wsRedMask=mXImage->red_mask;
|
|
|
|
wsGreenMask=mXImage->green_mask;
|
|
|
|
wsBlueMask=mXImage->blue_mask;
|
|
|
|
XDestroyImage( mXImage );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int bpp,ibpp;
|
|
|
|
XWindowAttributes attribs;
|
|
|
|
|
|
|
|
mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
|
|
|
|
bpp=mXImage->bits_per_pixel;
|
|
|
|
|
|
|
|
XGetWindowAttributes( wsDisplay,wsRootWin,&attribs );
|
|
|
|
ibpp=attribs.depth;
|
|
|
|
mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
|
|
|
|
bpp=mXImage->bits_per_pixel;
|
|
|
|
if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp;
|
|
|
|
wsDepthOnScreen=ibpp;
|
|
|
|
wsRedMask=mXImage->red_mask;
|
|
|
|
wsGreenMask=mXImage->green_mask;
|
|
|
|
wsBlueMask=mXImage->blue_mask;
|
|
|
|
XDestroyImage( mXImage );
|
|
|
|
}
|
|
|
|
return wsDepthOnScreen;
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wsXDone( void )
|
|
|
|
{
|
|
|
|
XCloseDisplay( wsDisplay );
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsVisibleWindow( wsTWindow * win,int show )
|
|
|
|
{
|
|
|
|
switch( show )
|
|
|
|
{
|
2002-05-06 15:05:07 +00:00
|
|
|
case wsShowWindow: XMapRaised( wsDisplay,win->WindowID ); break;
|
2001-08-25 21:04:29 +00:00
|
|
|
case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break;
|
|
|
|
}
|
|
|
|
XFlush( wsDisplay );
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsDestroyImage( wsTWindow * win )
|
|
|
|
{
|
|
|
|
if ( win->xImage )
|
|
|
|
{
|
|
|
|
XDestroyImage( win->xImage );
|
|
|
|
if ( wsUseXShm )
|
|
|
|
{
|
|
|
|
XShmDetach( wsDisplay,&win->Shminfo );
|
|
|
|
shmdt( win->Shminfo.shmaddr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
win->xImage=NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-05 18:17:22 +00:00
|
|
|
void wsCreateImage( wsTWindow * win,int Width,int Height )
|
2001-08-25 21:04:29 +00:00
|
|
|
{
|
|
|
|
int CompletionType = -1;
|
|
|
|
if ( wsUseXShm )
|
|
|
|
{
|
|
|
|
CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion;
|
|
|
|
win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual,
|
2002-10-19 19:54:59 +00:00
|
|
|
win->VisualInfo.depth,ZPixmap,NULL,&win->Shminfo,Width,Height );
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( win->xImage == NULL )
|
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 );
|
|
|
|
if ( win->Shminfo.shmid < 0 )
|
|
|
|
{
|
|
|
|
XDestroyImage( win->xImage );
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 );
|
|
|
|
|
|
|
|
if ( win->Shminfo.shmaddr == ((char *) -1) )
|
|
|
|
{
|
|
|
|
XDestroyImage( win->xImage );
|
|
|
|
if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr );
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
win->xImage->data=win->Shminfo.shmaddr;
|
|
|
|
win->Shminfo.readOnly=0;
|
|
|
|
XShmAttach( wsDisplay,&win->Shminfo );
|
|
|
|
shmctl( win->Shminfo.shmid,IPC_RMID,0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-19 19:54:59 +00:00
|
|
|
win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->VisualInfo.depth,
|
2001-09-05 18:17:22 +00:00
|
|
|
ZPixmap,0,0,Width,Height,
|
2001-08-25 21:04:29 +00:00
|
|
|
(wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen,
|
|
|
|
0 );
|
|
|
|
if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL )
|
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] sorry, not enough memory for draw buffer.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
win->ImageData=(unsigned char *)win->xImage->data;
|
|
|
|
win->ImageDataw=(unsigned short int *)win->xImage->data;
|
|
|
|
win->ImageDatadw=(unsigned int *)win->xImage->data;
|
|
|
|
}
|
|
|
|
|
2001-09-05 18:17:22 +00:00
|
|
|
void wsResizeImage( wsTWindow * win,int Width,int Height )
|
|
|
|
{ wsDestroyImage( win ); wsCreateImage( win,Width,Height ); }
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
int wsGetOutMask( void )
|
|
|
|
{
|
|
|
|
if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32;
|
|
|
|
if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32;
|
|
|
|
if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24;
|
|
|
|
if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24;
|
|
|
|
if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB16;
|
|
|
|
if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16;
|
|
|
|
if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB15;
|
|
|
|
if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsSetTitle( wsTWindow * win,char * name )
|
|
|
|
{ XStoreName( wsDisplay,win->WindowID,name ); }
|
|
|
|
|
|
|
|
void wsSetMousePosition( wsTWindow * win,int x, int y )
|
|
|
|
{ XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); }
|
|
|
|
|
2002-12-16 19:09:34 +00:00
|
|
|
#ifdef ENABLE_DPMS
|
2001-08-25 21:04:29 +00:00
|
|
|
static int dpms_disabled=0;
|
|
|
|
static int timeout_save=0;
|
|
|
|
|
|
|
|
void wsScreenSaverOn( Display *mDisplay )
|
|
|
|
{
|
|
|
|
int nothing;
|
2002-02-07 12:27:19 +00:00
|
|
|
#ifdef HAVE_XDPMS
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( dpms_disabled )
|
|
|
|
{
|
|
|
|
if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) )
|
|
|
|
{
|
2002-05-01 09:29:06 +00:00
|
|
|
if ( !DPMSEnable( mDisplay ) ) mp_msg( MSGT_GPLAYER,MSGL_ERR,"DPMS not available ?\n" ); // restoring power saving settings
|
2001-08-25 21:04:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// DPMS does not seem to be enabled unless we call DPMSInfo
|
|
|
|
BOOL onoff;
|
|
|
|
CARD16 state;
|
|
|
|
DPMSInfo( mDisplay,&state,&onoff );
|
2002-05-01 09:29:06 +00:00
|
|
|
if ( onoff ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"Successfully enabled DPMS.\n" );
|
|
|
|
else mp_msg( MSGT_GPLAYER,MSGL_STATUS,"Could not enable DPMS.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-07 12:27:19 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( timeout_save )
|
|
|
|
{
|
|
|
|
int dummy, interval, prefer_blank, allow_exp;
|
|
|
|
XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp );
|
|
|
|
XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp );
|
|
|
|
XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsScreenSaverOff( Display * mDisplay )
|
|
|
|
{
|
|
|
|
int interval,prefer_blank,allow_exp,nothing;
|
2002-02-07 12:27:19 +00:00
|
|
|
#ifdef HAVE_XDPMS
|
2001-08-25 21:04:29 +00:00
|
|
|
if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) )
|
|
|
|
{
|
|
|
|
BOOL onoff;
|
|
|
|
CARD16 state;
|
|
|
|
DPMSInfo( mDisplay,&state,&onoff );
|
|
|
|
if ( onoff )
|
|
|
|
{
|
|
|
|
Status stat;
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"Disabling DPMS.\n" );
|
2001-08-25 21:04:29 +00:00
|
|
|
dpms_disabled=1;
|
|
|
|
stat=DPMSDisable( mDisplay ); // monitor powersave off
|
2002-05-01 09:29:06 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"stat: %d.\n",stat );
|
2001-08-25 21:04:29 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-07 12:27:19 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp );
|
|
|
|
if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver
|
|
|
|
}
|
2002-12-16 19:09:34 +00:00
|
|
|
#endif
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
void wsSetShape( wsTWindow * win,char * data )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XSHAPE
|
2001-09-04 15:21:00 +00:00
|
|
|
if ( !wsUseXShape ) return;
|
|
|
|
if ( data )
|
|
|
|
{
|
|
|
|
win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height );
|
|
|
|
XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet );
|
|
|
|
XFreePixmap( wsDisplay,win->Mask );
|
|
|
|
}
|
|
|
|
else XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,None,ShapeSet );
|
2001-08-25 21:04:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-07-05 23:47:00 +00:00
|
|
|
void wsSetIcon( Display * dsp,Window win,Pixmap icon,Pixmap mask )
|
|
|
|
{
|
|
|
|
XWMHints * wm;
|
|
|
|
long data[2];
|
|
|
|
Atom iconatom;
|
|
|
|
|
|
|
|
wm=XGetWMHints( dsp,win );
|
|
|
|
if ( !wm ) wm=XAllocWMHints();
|
|
|
|
|
|
|
|
wm->icon_pixmap=icon;
|
|
|
|
wm->icon_mask=mask;
|
|
|
|
wm->flags|=IconPixmapHint | IconMaskHint;
|
|
|
|
|
|
|
|
XSetWMHints( dsp,win,wm );
|
|
|
|
|
|
|
|
data[0]=icon;
|
|
|
|
data[1]=mask;
|
|
|
|
iconatom=XInternAtom( dsp,"KWM_WIN_ICON",0 );
|
|
|
|
XChangeProperty( dsp,win,iconatom,iconatom,32,PropModeReplace,(unsigned char *)data,2 );
|
|
|
|
|
|
|
|
XFree( wm );
|
|
|
|
}
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
#include "wsmkeys.h"
|