comparison libvo/x11_common.c @ 32:9e66f722790e

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