annotate libvo/x11_common.c @ 142:300fea6ea86a

applied Walken's MB stuffing patch
author arpi_esp
date Sun, 18 Mar 2001 19:41:31 +0000
parents 9e66f722790e
children 720c640332c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
3 #include <string.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
4
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
6 #include <sys/mman.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
7
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
8 #include "config.h"
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
9 #include "video_out.h"
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
10
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
11 #ifdef X11_FULLSCREEN
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
12
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
13 #include <X11/Xlib.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
14 #include <X11/Xutil.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
15 #include <X11/Xatom.h>
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
16
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
17 int vo_depthonscreen=0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
18 int vo_screenwidth=0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
19 int vo_screenheight=0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
20 int vo_dwidth=0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
21 int vo_dheight=0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
22
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
23 int vo_init( void )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
24 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
25 int CompletionType = -1;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
26 int mScreen;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
27 int bpp;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
28 char * DisplayName = ":0.0";
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
29 Display * mDisplay;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
30 XImage * mXImage;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
31 Window mRootWin;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
32 static XWindowAttributes attribs;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
33
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
34 if(vo_depthonscreen) return 1; // already called
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
35
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
36 if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
37 mDisplay=XOpenDisplay( DisplayName );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
38 if ( !mDisplay )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
39 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
40 fprintf( stderr,"vo: couldn't open the X11 display!\n" );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
41 return 0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
42 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
43 mScreen=DefaultScreen( mDisplay ); // Screen ID.
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
44 mRootWin=RootWindow( mDisplay,mScreen );// Root window ID.
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
45 vo_screenwidth=DisplayWidth( mDisplay,mScreen );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
46 vo_screenheight=DisplayHeight( mDisplay,mScreen );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
47 // get color depth:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
48 // XGetWindowAttributes(mydisplay, DefaultRootWindow(mDisplay), &attribs);
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
49 XGetWindowAttributes(mDisplay, mRootWin, &attribs);
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
50 vo_depthonscreen=attribs.depth;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
51 // get bits/pixel:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
52 mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
53 bpp=mXImage->bits_per_pixel;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
54 XDestroyImage( mXImage );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
55 if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
56 XCloseDisplay( mDisplay );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
57 printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen);
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
58 return 1;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
59 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
60
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
61 #include "../linux/keycodes.h"
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
62 #include "wskeys.h"
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
63
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
64 extern void mplayer_put_key(int code);
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
65
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
66 void vo_x11_putkey(int key){
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
67 switch ( key )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
68 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
69 case wsLeft: mplayer_put_key(KEY_LEFT); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
70 case wsRight: mplayer_put_key(KEY_RIGHT); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
71 case wsUp: mplayer_put_key(KEY_UP); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
72 case wsDown: mplayer_put_key(KEY_DOWN); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
73 case wsSpace: mplayer_put_key(' '); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
74 case wsEscape: mplayer_put_key(KEY_ESC); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
75 case wsEnter: mplayer_put_key(KEY_ENTER); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
76 case wsq:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
77 case wsQ: mplayer_put_key('q'); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
78 case wsp:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
79 case wsP: mplayer_put_key('p'); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
80 case wsMinus:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
81 case wsGrayMinus: mplayer_put_key('-'); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
82 case wsPlus:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
83 case wsGrayPlus: mplayer_put_key('+'); break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
84 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
85 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
86
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
87
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
88 // ----- Motif header: -------
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
89
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
90 #define MWM_HINTS_DECORATIONS 2
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
91
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
92 typedef struct
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
93 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
94 long flags;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
95 long functions;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
96 long decorations;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
97 long input_mode;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
98 } MotifWmHints;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
99
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
100 extern MotifWmHints vo_MotifWmHints;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
101 extern Atom vo_MotifHints;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
102 extern int vo_depthonscreen;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
103 extern int vo_screenwidth;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
104 extern int vo_screenheight;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
105
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
106 static MotifWmHints vo_MotifWmHints;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
107 static Atom vo_MotifHints = None;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
108
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
109 void vo_x11_decoration( Display * vo_Display,Window w,int d )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
110 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
111 vo_MotifHints=XInternAtom( vo_Display,"_MOTIF_WM_HINTS",0 );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
112 if ( vo_MotifHints != None )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
113 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
114 vo_MotifWmHints.flags=2;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
115 vo_MotifWmHints.decorations=d;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
116 XChangeProperty( vo_Display,w,vo_MotifHints,vo_MotifHints,32,
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
117 PropModeReplace,(unsigned char *)&vo_MotifWmHints,4 );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
118 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
119 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
120
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
121 int vo_x11_check_events(Display *mydisplay){
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
122 int ret=0;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
123 XEvent Event;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
124 char buf[100];
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
125 KeySym keySym;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
126 XComposeStatus stat;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
127 // unsigned long vo_KeyTable[512];
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
128
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
129 while ( XPending( mydisplay ) )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
130 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
131 XNextEvent( mydisplay,&Event );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
132 switch( Event.type )
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
133 {
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
134 case Expose:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
135 ret|=VO_EVENT_EXPOSE;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
136 break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
137 case ConfigureNotify:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
138 vo_dwidth=Event.xconfigure.width;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
139 vo_dheight=Event.xconfigure.height;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
140 ret|=VO_EVENT_RESIZE;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
141 break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
142 case KeyPress:
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
143 XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
144 vo_x11_putkey( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
145 ret|=VO_EVENT_KEYPRESS;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
146 break;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
147 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
148 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
149
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
150 return ret;
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
151 }
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
152
9e66f722790e the common x11 stuff
arpi_esp
parents:
diff changeset
153 #endif