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"
|
2001-08-25 21:04:29 +00:00
|
|
|
#include "ws.h"
|
2002-08-11 13:12:38 +00:00
|
|
|
#include "wsxdnd.h"
|
2001-11-06 12:32:27 +00:00
|
|
|
#include "../../postproc/rgb2rgb.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
|
|
|
|
|
2001-08-25 21:04:29 +00:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
|
|
|
|
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.
|
2001-08-25 21:04:29 +00:00
|
|
|
|
|
|
|
Display * wsDisplay;
|
|
|
|
int wsScreen;
|
|
|
|
Window wsRootWin;
|
|
|
|
XEvent wsEvent;
|
|
|
|
int wsWindowDepth;
|
2002-05-06 15:05:07 +00:00
|
|
|
int wsWMType = wsWMUnknown;
|
2001-08-25 21:04:29 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
wsTWindow * wsWindowList[5] = { NULL,NULL,NULL,NULL,NULL };
|
|
|
|
int wsWLCount = 0;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
int wsWindowManagerType( void )
|
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, bytesafter;
|
|
|
|
unsigned char * args = NULL;
|
|
|
|
|
2002-05-07 13:31:29 +00:00
|
|
|
Window win;
|
|
|
|
XEvent xev;
|
|
|
|
int c = 0;
|
|
|
|
int wm = wsWMUnknown;
|
2002-05-06 15:05:07 +00:00
|
|
|
|
|
|
|
// --- gnome
|
2002-05-14 11:41:02 +00:00
|
|
|
/*
|
2002-05-07 13:31:29 +00:00
|
|
|
type=XInternAtom( wsDisplay,"_WIN_SUPPORTING_WM_CHECK",False );
|
2002-05-23 14:46:08 +00:00
|
|
|
if ( Success == XGetWindowProperty( wsDisplay,wsRootWin,type,0,65536 / sizeof( int32_t ),False,AnyPropertyType,&type,&format,&nitems,&bytesafter,&args ) && nitems > 0 )
|
2002-05-07 13:31:29 +00:00
|
|
|
{
|
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Detected wm is Gnome\n" );
|
|
|
|
XFree( args );
|
|
|
|
return wsWMGnome;
|
|
|
|
}
|
2002-05-14 11:41:02 +00:00
|
|
|
*/
|
2002-05-06 15:05:07 +00:00
|
|
|
// --- net wm
|
|
|
|
type=XInternAtom( wsDisplay,"_NET_SUPPORTED",False );
|
2002-05-23 14:46:08 +00:00
|
|
|
if ( Success == XGetWindowProperty( wsDisplay,wsRootWin,type,0,65536 / sizeof( int32_t ),False,AnyPropertyType,&type,&format,&nitems,&bytesafter,&args ) && nitems > 0 )
|
2002-05-06 15:05:07 +00:00
|
|
|
{
|
2002-05-07 13:31:29 +00:00
|
|
|
mp_dbg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Detected wm is NetWM\n" );
|
2002-05-06 15:05:07 +00:00
|
|
|
XFree( args );
|
|
|
|
return wsWMNetWM;
|
|
|
|
}
|
2002-05-07 13:31:29 +00:00
|
|
|
|
|
|
|
// --- other wm
|
|
|
|
mp_dbg( MSGT_VO,MSGL_STATUS,"[ws] Create window for WM detect ...\n" );
|
|
|
|
win=XCreateSimpleWindow( wsDisplay,wsRootWin,wsMaxX,wsMaxY,1,1,0,0,0 );
|
|
|
|
XSelectInput( wsDisplay,win,PropertyChangeMask | StructureNotifyMask );
|
|
|
|
XMapWindow( wsDisplay,win );
|
|
|
|
XMoveWindow( wsDisplay,win,wsMaxX,wsMaxY );
|
|
|
|
do
|
|
|
|
{
|
|
|
|
XCheckWindowEvent( wsDisplay,win,PropertyChangeMask | StructureNotifyMask,&xev );
|
|
|
|
|
|
|
|
if ( xev.type == PropertyNotify )
|
|
|
|
{
|
|
|
|
char * name = XGetAtomName( wsDisplay,xev.xproperty.atom );
|
|
|
|
if ( !name ) break;
|
|
|
|
|
|
|
|
if ( !strncmp( name,"_ICEWM_TRAY",11 ) )
|
|
|
|
{ mp_dbg( MSGT_VO,MSGL_STATUS,"[ws] Detected wm is IceWM.\n" ); wm=wsWMIceWM; break; }
|
|
|
|
if ( !strncmp( name,"_KDE_",5 ) )
|
|
|
|
{ mp_dbg( MSGT_VO,MSGL_STATUS,"[ws] Detected wm is KDE.\n" ); wm=wsWMKDE; break; }
|
|
|
|
if ( !strncmp( name,"KWM_WIN_DESKTOP",15 ) )
|
|
|
|
{ mp_dbg( MSGT_VO,MSGL_STATUS,"[ws] Detected wm is WindowMaker style.\n" ); wm=wsWMWMaker; break; }
|
|
|
|
// fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",win,name,xev.xproperty.atom );
|
|
|
|
XFree( name );
|
|
|
|
}
|
|
|
|
} while( c++ < 25 );
|
2002-05-14 11:41:02 +00:00
|
|
|
XUnmapWindow( wsDisplay,win );
|
2002-05-07 13:31:29 +00:00
|
|
|
XDestroyWindow( wsDisplay,win );
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
if ( wm == wsWMUnknown ) mp_dbg( MSGT_VO,MSGL_STATUS,"[ws] Unknown wm type...\n" );
|
|
|
|
#endif
|
2002-05-06 15:05:07 +00:00
|
|
|
return wsWMUnknown;
|
|
|
|
}
|
|
|
|
|
2002-05-14 11:41:02 +00:00
|
|
|
extern int vo_wm_type;
|
2002-10-23 23:57:45 +00:00
|
|
|
extern int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return);
|
2002-05-14 11:41:02 +00:00
|
|
|
|
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
|
|
|
}
|
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 );
|
|
|
|
wsMaxX=DisplayWidth( wsDisplay,wsScreen );
|
|
|
|
wsMaxY=DisplayHeight( wsDisplay,wsScreen );
|
|
|
|
|
2002-05-14 11:41:02 +00:00
|
|
|
if ( vo_wm_type != -1 ) wsWMType=vo_wm_type;
|
|
|
|
else wsWMType=wsWindowManagerType();
|
2002-05-06 15:05:07 +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 );
|
|
|
|
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: " );
|
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 )
|
|
|
|
{
|
|
|
|
case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ); break;
|
|
|
|
case -2: win->X=wsMaxX - wX - 1; break;
|
|
|
|
default: win->X=X; break;
|
|
|
|
}
|
|
|
|
switch ( Y )
|
|
|
|
{
|
|
|
|
case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ); break;
|
|
|
|
case -2: win->Y=wsMaxY - hY - 1; break;
|
|
|
|
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 --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
wsWindowList[wsWLCount++]=win;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
XUnmapWindow( wsDisplay,win->WindowID );
|
|
|
|
wsDestroyImage( win );
|
|
|
|
XDestroyWindow( wsDisplay,win->WindowID );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Handle events.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline int wsSearch( Window win )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i]->WindowID == win ) return i;
|
|
|
|
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;
|
|
|
|
if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Expose:
|
|
|
|
wsWindowList[l]->State=wsWindowExpose;
|
|
|
|
if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window );
|
|
|
|
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;
|
|
|
|
|
|
|
|
case MotionNotify: i=wsMoveMouse; goto buttonreleased;
|
|
|
|
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;
|
|
|
|
|
|
|
|
case PropertyNotify:
|
2002-04-29 22:00:50 +00:00
|
|
|
{
|
|
|
|
char * name = XGetAtomName( wsDisplay,Event->xproperty.atom );
|
|
|
|
|
|
|
|
if ( !name ) break;
|
2002-05-06 15:05:07 +00:00
|
|
|
if ( !strncmp( name,"_ICEWM_TRAY",11 ) )
|
|
|
|
{
|
|
|
|
wsWMType=wsWMIceWM;
|
2002-07-02 21:10:42 +00:00
|
|
|
// mp_dbg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Detected wm is IceWM.\n" );
|
2002-05-06 15:05:07 +00:00
|
|
|
}
|
|
|
|
if ( !strncmp( name,"_KDE_",5 ) )
|
|
|
|
{
|
2002-07-02 21:10:42 +00:00
|
|
|
// mp_dbg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Detected wm is KDE.\n" );
|
2002-05-06 15:05:07 +00:00
|
|
|
wsWMType=wsWMKDE;
|
|
|
|
}
|
|
|
|
if ( !strncmp( name,"KWM_WIN_DESKTOP",15 ) )
|
|
|
|
{
|
2002-07-02 21:10:42 +00:00
|
|
|
// mp_dbg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Detected wm is WindowMaker style.\n" );
|
2002-05-06 15:05:07 +00:00
|
|
|
wsWMType=wsWMWMaker;
|
|
|
|
}
|
2002-05-01 09:29:06 +00:00
|
|
|
|
2002-04-29 22:00:50 +00:00
|
|
|
// fprintf(stderr,"[ws] PropertyNotify %s ( 0x%x )\n",name,Event->xproperty.atom );
|
|
|
|
|
|
|
|
XFree( name );
|
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
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
|
|
|
|
#define WIN_LAYER_ONTOP 6
|
|
|
|
|
|
|
|
void wsSetLayer( Display * wsDisplay, Window win, int layer )
|
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, bytesafter;
|
2002-10-16 15:35:28 +00:00
|
|
|
Atom * args = NULL;
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2002-05-09 17:28:09 +00:00
|
|
|
if ( wsWMType == wsWMIceWM )
|
|
|
|
{
|
|
|
|
switch ( layer )
|
|
|
|
{
|
|
|
|
case -1: layer=2; break; // WinLayerBelow
|
|
|
|
case 0: layer=4; break; // WinLayerNormal
|
|
|
|
case 1: layer=8; break; // WinLayerOnTop
|
|
|
|
}
|
|
|
|
XChangeProperty( wsDisplay,win,
|
|
|
|
XInternAtom( wsDisplay,"_WIN_LAYER",False ),XA_CARDINAL,32,PropModeReplace,(unsigned char *)&layer,1 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
type=XInternAtom( wsDisplay,"_NET_SUPPORTED",False );
|
2002-10-16 15:35:28 +00:00
|
|
|
if ( Success == XGetWindowProperty( wsDisplay,wsRootWin,type,0,65536 / sizeof( int32_t ),False,AnyPropertyType,&type,&format,&nitems,&bytesafter,(unsigned char **)&args ) && nitems > 0 )
|
2002-05-06 15:05:07 +00:00
|
|
|
{
|
2002-10-01 14:37:01 +00:00
|
|
|
int i;
|
2002-05-06 15:05:07 +00:00
|
|
|
XEvent e;
|
2002-10-01 14:37:01 +00:00
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
e.xclient.type=ClientMessage;
|
|
|
|
e.xclient.message_type=XInternAtom( wsDisplay,"_NET_WM_STATE",False );
|
|
|
|
e.xclient.display=wsDisplay;
|
|
|
|
e.xclient.window=win;
|
|
|
|
e.xclient.format=32;
|
|
|
|
e.xclient.data.l[0]=layer;
|
2002-10-01 14:37:01 +00:00
|
|
|
|
2002-09-29 09:39:25 +00:00
|
|
|
e.xclient.data.l[1]=XInternAtom( wsDisplay,"_NET_WM_STATE_STAYS_ON_TOP",False );
|
2002-10-01 14:37:01 +00:00
|
|
|
type=XInternAtom( wsDisplay,"_NET_WM_STATE_FULLSCREEN",False );
|
2002-10-16 15:35:28 +00:00
|
|
|
for ( i=0;(unsigned long)i < nitems;i++ )
|
2002-10-01 14:37:01 +00:00
|
|
|
if ( args[i] == type ) { e.xclient.data.l[1]=XInternAtom( wsDisplay,"_NET_WM_STATE_FULLSCREEN",False ); break; }
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
e.xclient.data.l[2]=0l;
|
|
|
|
e.xclient.data.l[3]=0l;
|
|
|
|
e.xclient.data.l[4]=0l;
|
|
|
|
XSendEvent( wsDisplay,wsRootWin,False,SubstructureRedirectMask,&e );
|
|
|
|
|
|
|
|
XFree( args );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
type=XInternAtom( wsDisplay,"_WIN_SUPPORTING_WM_CHECK",False );
|
2002-10-16 15:35:28 +00:00
|
|
|
if ( Success == XGetWindowProperty( wsDisplay,wsRootWin,type,0,65536 / sizeof( int32_t ),False,AnyPropertyType,&type,&format,&nitems,&bytesafter,(unsigned char **)&args ) && nitems > 0 )
|
2002-05-06 15:05:07 +00:00
|
|
|
{
|
|
|
|
XClientMessageEvent xev;
|
|
|
|
|
|
|
|
memset( &xev,0,sizeof( xev ) );
|
|
|
|
xev.type=ClientMessage;
|
|
|
|
xev.window=win;
|
|
|
|
xev.message_type=XInternAtom( wsDisplay,"_WIN_LAYER",False );
|
|
|
|
xev.format=32;
|
|
|
|
switch ( layer )
|
|
|
|
{
|
|
|
|
case -1: xev.data.l[0] = WIN_LAYER_ONBOTTOM; break;
|
|
|
|
case 0: xev.data.l[0] = WIN_LAYER_NORMAL; break;
|
|
|
|
case 1: xev.data.l[0] = WIN_LAYER_ONTOP; break;
|
|
|
|
}
|
|
|
|
XSendEvent( wsDisplay,wsRootWin,False,SubstructureNotifyMask,(XEvent*)&xev );
|
|
|
|
if ( layer ) XRaiseWindow( wsDisplay,win );
|
|
|
|
|
|
|
|
XFree( args );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
switch ( wsWMType )
|
|
|
|
{
|
|
|
|
case wsWMUnknown:
|
2002-09-28 22:52:23 +00:00
|
|
|
// XUnmapWindow( wsDisplay,win->WindowID );
|
|
|
|
XWithdrawWindow( wsDisplay,win->WindowID,wsScreen );
|
2002-05-06 15:05:07 +00:00
|
|
|
break;
|
|
|
|
case wsWMIceWM:
|
|
|
|
if ( !win->isFullScreen ) XUnmapWindow( wsDisplay,win->WindowID );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
wsScreenSaverOn( wsDisplay );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
win->OldX=win->X; win->OldY=win->Y;
|
|
|
|
win->OldWidth=win->Width; win->OldHeight=win->Height;
|
|
|
|
win->X=0; win->Y=0;
|
|
|
|
win->Width=wsMaxX; win->Height=wsMaxY;
|
|
|
|
win->isFullScreen=True;
|
|
|
|
wsScreenSaverOff( wsDisplay );
|
|
|
|
}
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
win->SizeHint.flags=PPosition | PSize | PWinGravity;// | PBaseSize;
|
2002-04-29 22:00:50 +00:00
|
|
|
win->SizeHint.x=win->X; win->SizeHint.y=win->Y;
|
|
|
|
win->SizeHint.width=win->Width; win->SizeHint.height=win->Height;
|
2002-05-09 17:28:09 +00:00
|
|
|
// win->SizeHint.base_width=win->Width; win->SizeHint.base_height=win->Height;
|
2002-05-06 15:05:07 +00:00
|
|
|
|
2002-04-29 22:00:50 +00:00
|
|
|
win->SizeHint.win_gravity=StaticGravity;
|
2001-09-06 09:36:48 +00:00
|
|
|
if ( win->Property & wsMaxSize )
|
|
|
|
{
|
|
|
|
win->SizeHint.flags|=PMaxSize;
|
|
|
|
win->SizeHint.max_width=win->Width;
|
|
|
|
win->SizeHint.max_height=win->Height;
|
|
|
|
}
|
|
|
|
if ( win->Property & wsMinSize )
|
|
|
|
{
|
|
|
|
win->SizeHint.flags|=PMinSize;
|
|
|
|
win->SizeHint.min_width=win->Width;
|
|
|
|
win->SizeHint.min_height=win->Height;
|
|
|
|
}
|
2001-08-25 21:04:29 +00:00
|
|
|
XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
|
|
|
|
|
2002-05-06 15:05:07 +00:00
|
|
|
wsSetLayer( wsDisplay,win->WindowID,win->isFullScreen );
|
2001-08-25 21:04:29 +00:00
|
|
|
XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height );
|
|
|
|
wsWindowDecoration( win,decoration );
|
2002-04-29 22:00:50 +00:00
|
|
|
XMapRaised( wsDisplay,win->WindowID );
|
2001-08-25 21:04:29 +00:00
|
|
|
XRaiseWindow( wsDisplay,win->WindowID );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
// Redraw screen.
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
|
|
|
void wsPostRedisplay( wsTWindow * win )
|
|
|
|
{
|
|
|
|
if ( win->ReDraw )
|
|
|
|
{
|
2002-07-25 20:26:38 +00:00
|
|
|
win->State=wsWindowExpose;
|
2001-08-25 21:04:29 +00:00
|
|
|
win->ReDraw( wsDisplay,win->WindowID );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ); break;
|
|
|
|
case -2: win->X=wsMaxX - win->Width; break;
|
|
|
|
default: win->X=x; break;
|
|
|
|
}
|
|
|
|
switch ( y )
|
|
|
|
{
|
|
|
|
case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ); break;
|
|
|
|
case -2: win->Y=wsMaxY - win->Height; break;
|
|
|
|
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
|
|
|
|
|
|
|
if ( wsWMType == wsWMUnknown ) XUnmapWindow( wsDisplay,win->WindowID );
|
|
|
|
|
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
|
|
|
{
|
2002-05-08 16:41:44 +00:00
|
|
|
switch ( wsWMType )
|
2002-05-06 15:05:07 +00:00
|
|
|
{
|
2002-05-08 16:41:44 +00:00
|
|
|
case wsWMIceWM:
|
2002-05-20 13:56:16 +00:00
|
|
|
XUnmapWindow( wsDisplay,win );
|
|
|
|
XMapWindow( wsDisplay,win );
|
2002-05-08 16:41:44 +00:00
|
|
|
break;
|
|
|
|
case wsWMNetWM:
|
|
|
|
case wsWMKDE:
|
|
|
|
{
|
|
|
|
XEvent e;
|
|
|
|
e.xclient.type=ClientMessage;
|
|
|
|
e.xclient.message_type=XInternAtom( wsDisplay,"_NET_ACTIVE_WINDOW",False );
|
|
|
|
e.xclient.display=wsDisplay;
|
2002-05-20 13:56:16 +00:00
|
|
|
e.xclient.window=win;
|
2002-05-08 16:41:44 +00:00
|
|
|
e.xclient.format=32;
|
|
|
|
e.xclient.data.l[0]=0;
|
2002-05-20 13:56:16 +00:00
|
|
|
XSendEvent( wsDisplay,RootWindow( wsDisplay,DefaultScreen( wsDisplay ) ),False,SubstructureRedirectMask,&e );
|
2002-05-08 16:41:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2002-05-20 13:56:16 +00:00
|
|
|
XMapRaised( wsDisplay,win );
|
|
|
|
XRaiseWindow( wsDisplay,win );
|
2002-05-08 16:41:44 +00:00
|
|
|
break;
|
2002-05-06 15:05:07 +00:00
|
|
|
}
|
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 ); }
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|