Mercurial > mplayer.hg
annotate libvo/x11_common.c @ 983:cb0e3b29a0dd
Several small changes (like driver selection).
author | atmosfear |
---|---|
date | Mon, 04 Jun 2001 00:27:55 +0000 |
parents | db06ae8967eb |
children | b36fb1ae4b53 |
rev | line source |
---|---|
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
1 |
32 | 2 #include <stdio.h> |
3 #include <stdlib.h> | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
4 |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
5 #include "config.h" |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
6 |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
7 #ifdef X11_FULLSCREEN |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
8 |
440
d19a3da6ac13
Pontscho's mixer, select, and hell-a-lot-of-stuff patch ;)
gabucino
parents:
416
diff
changeset
|
9 #include <string.h> |
32 | 10 #include <unistd.h> |
11 #include <sys/mman.h> | |
12 | |
13 #include "video_out.h" | |
14 | |
324 | 15 #include <X11/Xmd.h> |
32 | 16 #include <X11/Xlib.h> |
17 #include <X11/Xutil.h> | |
18 #include <X11/Xatom.h> | |
19 | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
20 #include <X11/extensions/dpms.h> |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
21 |
324 | 22 static int dpms_disabled=0; |
23 static int timeout_save=0; | |
24 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
25 char* mDisplayName=NULL; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
26 Display* mDisplay; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
27 Window mRootWin; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
28 int mScreen; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
29 int mLocalDisplay; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
30 |
384 | 31 |
32 void vo_hidecursor ( Display *disp , Window win ) | |
33 { | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
34 Cursor no_ptr; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
35 Pixmap bm_no; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
36 XColor black,dummy; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
37 Colormap colormap; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
38 static unsigned char bm_no_data[] = { 0,0,0,0, 0,0,0,0 }; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
39 |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
40 colormap = DefaultColormap(disp,DefaultScreen(disp)); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
41 XAllocNamedColor(disp,colormap,"black",&black,&dummy); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
42 bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8,8); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
43 no_ptr=XCreatePixmapCursor(disp, bm_no, bm_no,&black, &black,0, 0); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
44 XDefineCursor(disp,win,no_ptr); |
384 | 45 } |
46 | |
47 | |
32 | 48 int vo_init( void ) |
49 { | |
50 int CompletionType = -1; | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
51 // int mScreen; |
32 | 52 int bpp; |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
53 // char * DisplayName = ":0.0"; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
54 // Display * mDisplay; |
32 | 55 XImage * mXImage; |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
56 // Window mRootWin; |
32 | 57 static XWindowAttributes attribs; |
58 | |
59 if(vo_depthonscreen) return 1; // already called | |
60 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
61 if (!mDisplayName) |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
62 if (!(mDisplayName=getenv("DISPLAY"))) |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
63 mDisplayName=strdup(":0.0"); |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
64 |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
65 mDisplay=XOpenDisplay(mDisplayName); |
32 | 66 if ( !mDisplay ) |
67 { | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
68 printf( "vo: couldn't open the X11 display (%s)!\n",mDisplayName ); |
32 | 69 return 0; |
70 } | |
71 mScreen=DefaultScreen( mDisplay ); // Screen ID. | |
72 mRootWin=RootWindow( mDisplay,mScreen );// Root window ID. | |
73 vo_screenwidth=DisplayWidth( mDisplay,mScreen ); | |
74 vo_screenheight=DisplayHeight( mDisplay,mScreen ); | |
75 // get color depth: | |
76 // XGetWindowAttributes(mydisplay, DefaultRootWindow(mDisplay), &attribs); | |
77 XGetWindowAttributes(mDisplay, mRootWin, &attribs); | |
78 vo_depthonscreen=attribs.depth; | |
79 // get bits/pixel: | |
80 mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
81 bpp=mXImage->bits_per_pixel; | |
82 XDestroyImage( mXImage ); | |
83 if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
84 // XCloseDisplay( mDisplay ); |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
85 #warning Better local display detection method is needed. |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
86 if (*mDisplayName==':') mLocalDisplay=1; else mLocalDisplay=0; |
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
741
diff
changeset
|
87 printf("X11 running at %dx%d depth: %d (\"%s\" => %s display)\n",vo_screenwidth,vo_screenheight,vo_depthonscreen,mDisplayName,mLocalDisplay?"local":"remote"); |
32 | 88 return 1; |
89 } | |
90 | |
91 #include "../linux/keycodes.h" | |
92 #include "wskeys.h" | |
93 | |
94 extern void mplayer_put_key(int code); | |
95 | |
96 void vo_x11_putkey(int key){ | |
97 switch ( key ) | |
98 { | |
99 case wsLeft: mplayer_put_key(KEY_LEFT); break; | |
100 case wsRight: mplayer_put_key(KEY_RIGHT); break; | |
101 case wsUp: mplayer_put_key(KEY_UP); break; | |
102 case wsDown: mplayer_put_key(KEY_DOWN); break; | |
103 case wsSpace: mplayer_put_key(' '); break; | |
104 case wsEscape: mplayer_put_key(KEY_ESC); break; | |
105 case wsEnter: mplayer_put_key(KEY_ENTER); break; | |
651 | 106 case wsPageUp: mplayer_put_key(KEY_PAGE_UP); break; |
107 case wsPageDown: mplayer_put_key(KEY_PAGE_DOWN); break; | |
32 | 108 case wsq: |
109 case wsQ: mplayer_put_key('q'); break; | |
110 case wsp: | |
111 case wsP: mplayer_put_key('p'); break; | |
112 case wsMinus: | |
113 case wsGrayMinus: mplayer_put_key('-'); break; | |
114 case wsPlus: | |
115 case wsGrayPlus: mplayer_put_key('+'); break; | |
464 | 116 case wsGrayMul: |
117 case wsMul: mplayer_put_key('*'); break; | |
118 case wsGrayDiv: | |
119 case wsDiv: mplayer_put_key('/'); break; | |
516 | 120 case wsm: |
121 case wsM: mplayer_put_key('m'); break; | |
655 | 122 case wso: |
123 case wsO: mplayer_put_key('o'); break; | |
369 | 124 default: if((key>='a' && key<='z')||(key>='A' && key<='Z')) mplayer_put_key(key); |
32 | 125 } |
369 | 126 |
32 | 127 } |
128 | |
129 | |
130 // ----- Motif header: ------- | |
131 | |
132 #define MWM_HINTS_DECORATIONS 2 | |
133 | |
134 typedef struct | |
135 { | |
136 long flags; | |
137 long functions; | |
138 long decorations; | |
139 long input_mode; | |
140 } MotifWmHints; | |
141 | |
142 extern MotifWmHints vo_MotifWmHints; | |
143 extern Atom vo_MotifHints; | |
144 extern int vo_depthonscreen; | |
145 extern int vo_screenwidth; | |
146 extern int vo_screenheight; | |
147 | |
148 static MotifWmHints vo_MotifWmHints; | |
149 static Atom vo_MotifHints = None; | |
150 | |
151 void vo_x11_decoration( Display * vo_Display,Window w,int d ) | |
152 { | |
153 vo_MotifHints=XInternAtom( vo_Display,"_MOTIF_WM_HINTS",0 ); | |
154 if ( vo_MotifHints != None ) | |
155 { | |
156 vo_MotifWmHints.flags=2; | |
157 vo_MotifWmHints.decorations=d; | |
158 XChangeProperty( vo_Display,w,vo_MotifHints,vo_MotifHints,32, | |
159 PropModeReplace,(unsigned char *)&vo_MotifWmHints,4 ); | |
160 } | |
161 } | |
162 | |
723 | 163 #ifdef HAVE_GUI |
164 Window vo_window = None; | |
165 GC vo_gc; | |
166 int vo_xeventhandling = 1; | |
167 int vo_resize = 0; | |
168 int vo_expose = 0; | |
169 | |
170 void vo_setwindow( Window w,GC g ) | |
171 { vo_window=w; vo_gc=g; } | |
172 #endif | |
173 | |
32 | 174 int vo_x11_check_events(Display *mydisplay){ |
175 int ret=0; | |
176 XEvent Event; | |
177 char buf[100]; | |
178 KeySym keySym; | |
179 XComposeStatus stat; | |
180 // unsigned long vo_KeyTable[512]; | |
181 | |
723 | 182 #ifdef HAVE_GUI |
183 if ( vo_xeventhandling ) | |
184 { | |
185 #endif | |
186 while ( XPending( mydisplay ) ) | |
187 { | |
188 XNextEvent( mydisplay,&Event ); | |
189 switch( Event.type ) | |
190 { | |
191 case Expose: | |
192 ret|=VO_EVENT_EXPOSE; | |
193 break; | |
194 case ConfigureNotify: | |
195 vo_dwidth=Event.xconfigure.width; | |
196 vo_dheight=Event.xconfigure.height; | |
197 ret|=VO_EVENT_RESIZE; | |
198 break; | |
199 case KeyPress: | |
200 XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat ); | |
201 vo_x11_putkey( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) ); | |
202 ret|=VO_EVENT_KEYPRESS; | |
203 break; | |
204 } | |
205 } | |
206 #ifdef HAVE_GUI | |
32 | 207 } |
723 | 208 else |
209 { | |
210 if ( vo_resize ) | |
211 { | |
212 vo_resize=0; | |
213 ret|=VO_EVENT_RESIZE; | |
214 } | |
215 if ( vo_expose ) | |
216 { | |
217 vo_expose=0; | |
218 ret|=VO_EVENT_EXPOSE; | |
219 } | |
220 } | |
221 #endif | |
32 | 222 |
223 return ret; | |
224 } | |
225 | |
324 | 226 void saver_on(Display *mDisplay) { |
227 | |
228 int nothing; | |
229 if (dpms_disabled) | |
230 { | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
231 if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
232 { |
741 | 233 if (!DPMSEnable(mDisplay)) { // restoring power saving settings |
234 printf("DPMS not available?\n"); | |
235 } else { | |
236 // DPMS does not seem to be enabled unless we call DPMSInfo | |
237 BOOL onoff; | |
238 CARD16 state; | |
239 DPMSInfo(mDisplay, &state, &onoff); | |
240 if (onoff) { | |
241 printf ("Successfully enabled DPMS\n"); | |
242 } else { | |
243 printf ("Could not enable DPMS\n"); | |
244 } | |
245 } | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
246 } |
324 | 247 } |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
248 |
324 | 249 if (timeout_save) |
250 { | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
251 int dummy, interval, prefer_blank, allow_exp; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
252 XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank, &allow_exp); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
253 XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank, allow_exp); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
254 XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); |
324 | 255 } |
256 | |
257 } | |
258 | |
259 void saver_off(Display *mDisplay) { | |
260 | |
261 int interval, prefer_blank, allow_exp, nothing; | |
262 | |
263 if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) | |
264 { | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
265 BOOL onoff; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
266 CARD16 state; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
267 DPMSInfo(mDisplay, &state, &onoff); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
268 if (onoff) |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
269 { |
741 | 270 Status stat; |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
271 printf ("Disabling DPMS\n"); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
272 dpms_disabled=1; |
741 | 273 stat = DPMSDisable(mDisplay); // monitor powersave off |
274 printf ("stat: %d\n", stat); | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
275 } |
324 | 276 } |
277 XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); | |
278 if (timeout_save) | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
279 XSetScreenSaver(mDisplay, 0, interval, prefer_blank, allow_exp); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
456
diff
changeset
|
280 // turning off screensaver |
326 | 281 } |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
282 |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
440
diff
changeset
|
283 #endif |