0
|
1 /* XMMS - Cross-platform multimedia player
|
|
2 * Copyright (C) 1998-2000 Zinx Verituse
|
|
3 *
|
|
4 * This program is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public Licensse as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
17 */
|
|
18 #ifdef HAVE_CONFIG_H
|
|
19 # include "config.h"
|
|
20 #endif
|
|
21
|
|
22 #include "fullscreen.h"
|
|
23
|
|
24 #include "libaudacious/util.h"
|
|
25
|
|
26 #include <X11/Xlib.h>
|
|
27 #include <X11/Xatom.h>
|
|
28 #include <X11/Xmd.h>
|
|
29
|
|
30 #ifndef XF86VIDMODE
|
|
31
|
|
32 gboolean
|
|
33 xmms_fullscreen_available(Display * dpy)
|
|
34 {
|
|
35 return FALSE;
|
|
36 }
|
|
37
|
|
38 gboolean
|
|
39 xmms_fullscreen_init(GtkWidget * win)
|
|
40 {
|
|
41 return FALSE;
|
|
42 }
|
|
43
|
|
44 gboolean
|
|
45 xmms_fullscreen_enter(GtkWidget * win, gint * w, gint * h)
|
|
46 {
|
|
47 return FALSE;
|
|
48 }
|
|
49
|
|
50 void
|
|
51 xmms_fullscreen_leave(GtkWidget * win)
|
|
52 {
|
|
53 return;
|
|
54 }
|
|
55
|
|
56 gboolean
|
|
57 xmms_fullscreen_in(GtkWidget * win)
|
|
58 {
|
|
59 return FALSE;
|
|
60 }
|
|
61
|
|
62 gboolean
|
|
63 xmms_fullscreen_mark(GtkWidget * win)
|
|
64 {
|
|
65 return FALSE;
|
|
66 }
|
|
67
|
|
68 void
|
|
69 xmms_fullscreen_unmark(GtkWidget * win)
|
|
70 {
|
|
71 return;
|
|
72 }
|
|
73
|
|
74 void
|
|
75 xmms_fullscreen_cleanup(GtkWidget * win)
|
|
76 {
|
|
77 return;
|
|
78 }
|
|
79
|
|
80 GSList *
|
|
81 xmms_fullscreen_modelist(GtkWidget * win)
|
|
82 {
|
|
83 return NULL;
|
|
84 }
|
|
85
|
|
86 void
|
|
87 xmms_fullscreen_modelist_free(GSList * modes)
|
|
88 {
|
|
89 return;
|
|
90 }
|
|
91
|
|
92 #else /* XF86VIDMODE */
|
|
93
|
|
94 #include <X11/extensions/xf86vmode.h>
|
|
95 #include <X11/extensions/xf86vmstr.h>
|
|
96
|
|
97 gboolean
|
|
98 xmms_fullscreen_available(Display * dpy)
|
|
99 {
|
|
100 int event_base, error_base, num_modes;
|
|
101 XF86VidModeModeInfo **dummy;
|
|
102
|
|
103 if (!XF86VidModeQueryExtension(dpy, &event_base, &error_base))
|
|
104 return FALSE;
|
|
105
|
|
106 XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &num_modes, &dummy);
|
|
107 XFree(dummy);
|
|
108
|
|
109 return (num_modes > 1);
|
|
110 }
|
|
111
|
|
112 typedef struct {
|
|
113 Display *display;
|
|
114 XF86VidModeModeInfo **modes, *origmode;
|
|
115 gboolean is_full, can_full;
|
|
116 gint num_modes;
|
|
117 } fullscreen_display_t;
|
|
118
|
|
119 static fullscreen_display_t **displays = NULL;
|
|
120
|
|
121 typedef struct {
|
|
122 GtkWidget *window;
|
|
123 gint is_full;
|
|
124 gint ox, oy, owidth, oheight;
|
|
125 fullscreen_display_t *display;
|
|
126 } fullscreen_window_t;
|
|
127 static fullscreen_window_t **windows = NULL;
|
|
128
|
|
129 G_LOCK_DEFINE_STATIC(full_mutex);
|
|
130
|
|
131 #define FULL_LOCK() G_LOCK(full_mutex);
|
|
132 #define FULL_UNLOCK() G_UNLOCK(full_mutex);
|
|
133
|
|
134 static fullscreen_display_t *
|
|
135 getdisplay(Display * dpy)
|
|
136 {
|
|
137 gint i;
|
|
138
|
|
139 if (displays) {
|
|
140 for (i = 0; displays[i]; i++) {
|
|
141 if (displays[i]->display == dpy)
|
|
142 return displays[i];
|
|
143 }
|
|
144 displays = g_realloc(displays, sizeof(*displays) * (i + 2));
|
|
145 }
|
|
146 else {
|
|
147 displays = g_malloc(sizeof(*displays) * 2);
|
|
148 i = 0;
|
|
149 }
|
|
150 displays[i + 1] = NULL;
|
|
151 displays[i] = g_malloc(sizeof(**displays));
|
|
152 displays[i]->display = dpy;
|
|
153 displays[i]->modes = NULL;
|
|
154 displays[i]->origmode = NULL;
|
|
155 displays[i]->num_modes = 0;
|
|
156 displays[i]->is_full = FALSE;
|
|
157 displays[i]->can_full = FALSE;
|
|
158 return displays[i];
|
|
159 }
|
|
160
|
|
161 static fullscreen_window_t *
|
|
162 getwindow(GtkWidget * win)
|
|
163 {
|
|
164 gint i;
|
|
165
|
|
166 if (windows) {
|
|
167 for (i = 0; windows[i]; i++) {
|
|
168 if (windows[i]->window == win)
|
|
169 return windows[i];
|
|
170 }
|
|
171 windows = g_realloc(windows, sizeof(*windows) * (i + 2));
|
|
172 }
|
|
173 else {
|
|
174 windows = g_malloc(sizeof(*windows) * 2);
|
|
175 i = 0;
|
|
176 }
|
|
177 windows[i + 1] = NULL;
|
|
178 windows[i] = g_malloc(sizeof(**windows));
|
|
179 windows[i]->window = win;
|
|
180 windows[i]->ox = 0;
|
|
181 windows[i]->oy = 0;
|
|
182 windows[i]->owidth = 0;
|
|
183 windows[i]->oheight = 0;
|
|
184 windows[i]->display = getdisplay(GDK_WINDOW_XDISPLAY(win->window));
|
|
185 windows[i]->is_full = 0;
|
|
186 return windows[i];
|
|
187 }
|
|
188
|
|
189 gboolean
|
|
190 xmms_fullscreen_init(GtkWidget * win)
|
|
191 {
|
|
192 int event_base, error_base, dummy;
|
|
193 fullscreen_window_t *fwin;
|
|
194 gint i;
|
|
195 XF86VidModeModeLine origmode;
|
|
196
|
|
197 FULL_LOCK();
|
|
198 fwin = getwindow(win);
|
|
199
|
|
200 if (!XF86VidModeQueryExtension
|
|
201 (fwin->display->display, &event_base, &error_base)) {
|
|
202 FULL_UNLOCK();
|
|
203 return FALSE;
|
|
204 }
|
|
205
|
|
206 if (!fwin->display->modes) {
|
|
207 XF86VidModeGetAllModeLines(fwin->display->display,
|
|
208 DefaultScreen(fwin->display->display),
|
|
209 &fwin->display->num_modes,
|
|
210 &fwin->display->modes);
|
|
211
|
|
212 if (!fwin->display->origmode) {
|
|
213 XF86VidModeGetModeLine(fwin->display->display,
|
|
214 DefaultScreen(fwin->display->display),
|
|
215 &dummy, &origmode);
|
|
216 for (i = 0; i < fwin->display->num_modes; i++) {
|
|
217 if (fwin->display->modes[i]->hdisplay ==
|
|
218 origmode.hdisplay
|
|
219 && fwin->display->modes[i]->vdisplay ==
|
|
220 origmode.vdisplay) {
|
|
221 fwin->display->origmode = fwin->display->modes[i];
|
|
222 break;
|
|
223 }
|
|
224 }
|
|
225
|
|
226 if (!fwin->display->origmode) {
|
|
227 fprintf(stderr,
|
|
228 "ERROR: Could not determine original mode.\n");
|
|
229 FULL_UNLOCK();
|
|
230 return FALSE;
|
|
231 }
|
|
232
|
|
233 }
|
|
234
|
|
235 fwin->display->can_full = (fwin->display->num_modes > 1);
|
|
236 }
|
|
237 FULL_UNLOCK();
|
|
238 return fwin->display->can_full;
|
|
239 }
|
|
240
|
|
241 gboolean
|
|
242 xmms_fullscreen_enter(GtkWidget * win, gint * w, gint * h)
|
|
243 {
|
|
244 gint i, close, how_close = -1, t, dummy;
|
|
245 gboolean retval = FALSE;
|
|
246 fullscreen_window_t *fwin;
|
|
247
|
|
248 FULL_LOCK();
|
|
249 fwin = getwindow(win);
|
|
250
|
|
251 if (!fwin->display->is_full && !fwin->is_full && fwin->display->can_full) {
|
|
252 for (close = 0; close < fwin->display->num_modes; close++) {
|
|
253 if ((fwin->display->modes[close]->hdisplay >= *w) &&
|
|
254 (fwin->display->modes[close]->vdisplay >= *h)) {
|
|
255 how_close = fwin->display->modes[close]->hdisplay - *w;
|
|
256 break;
|
|
257 }
|
|
258 }
|
|
259
|
|
260 for (i = close + 1; i < fwin->display->num_modes; i++) {
|
|
261 if (fwin->display->modes[i]->vdisplay < *h)
|
|
262 continue;
|
|
263 t = fwin->display->modes[i]->hdisplay - *w;
|
|
264 if (t >= 0 && t < how_close) {
|
|
265 close = i;
|
|
266 how_close = t;
|
|
267 }
|
|
268 }
|
|
269
|
|
270 if (close < fwin->display->num_modes) {
|
|
271 *w = fwin->display->modes[close]->hdisplay;
|
|
272 *h = fwin->display->modes[close]->vdisplay;
|
|
273
|
|
274 /* Save the old position/size */
|
|
275 gdk_window_get_root_origin(fwin->window->window, &fwin->ox,
|
|
276 &fwin->oy);
|
|
277 gdk_window_get_size(fwin->window->window, &fwin->owidth,
|
|
278 &fwin->oheight);
|
|
279
|
|
280 /* Move it. */
|
|
281 gdk_window_move_resize(fwin->window->window, 0, 0,
|
|
282 fwin->display->modes[close]->hdisplay,
|
|
283 fwin->display->modes[close]->vdisplay);
|
|
284
|
|
285 /* Tell the WM not to mess with this window (no more decor) */
|
|
286 gdk_window_hide(fwin->window->window);
|
|
287 gdk_window_set_override_redirect(fwin->window->window, TRUE);
|
|
288 gdk_window_show(fwin->window->window);
|
|
289
|
|
290 /*
|
|
291 * XXX: HACK
|
|
292 * Something is ungrabbing the pointer shortly
|
|
293 * after the above unmap/override_redirect=TRUE/map
|
|
294 * is done. I don't know what at this time, only
|
|
295 * that it's not XMMS, and that it's very very evil.
|
|
296 */
|
|
297 gdk_flush();
|
|
298 xmms_usleep(50000);
|
|
299
|
|
300 /* Steal the keyboard/mouse */
|
|
301 /* XXX: FIXME, use timeouts.. */
|
|
302 for (t = 0; t < 10; t++) {
|
|
303 dummy = gdk_pointer_grab(fwin->window->window,
|
|
304 TRUE, 0,
|
|
305 fwin->window->window,
|
|
306 NULL, GDK_CURRENT_TIME);
|
|
307
|
|
308 if (dummy == GrabSuccess)
|
|
309 break;
|
|
310
|
|
311 gtk_main_iteration_do(FALSE);
|
|
312 xmms_usleep(10000);
|
|
313 }
|
|
314 gdk_keyboard_grab(fwin->window->window, TRUE, GDK_CURRENT_TIME);
|
|
315
|
|
316 /* Do the video mode switch.. */
|
|
317 XF86VidModeSwitchToMode(fwin->display->display,
|
|
318 DefaultScreen(fwin->display->display),
|
|
319 fwin->display->modes[close]);
|
|
320
|
|
321 XF86VidModeSetViewPort(fwin->display->display,
|
|
322 DefaultScreen(fwin->display->display),
|
|
323 0, 0);
|
|
324
|
|
325 retval = TRUE;
|
|
326
|
|
327 fwin->is_full = TRUE;
|
|
328 fwin->display->is_full = TRUE;
|
|
329 }
|
|
330 }
|
|
331
|
|
332 FULL_UNLOCK();
|
|
333
|
|
334 return retval;
|
|
335 }
|
|
336
|
|
337 void
|
|
338 xmms_fullscreen_leave(GtkWidget * win)
|
|
339 {
|
|
340 fullscreen_window_t *fwin;
|
|
341
|
|
342 FULL_LOCK();
|
|
343 fwin = getwindow(win);
|
|
344
|
|
345 if (fwin->is_full && fwin->display->is_full) {
|
|
346 /* Release our grabs */
|
|
347 gdk_pointer_ungrab(GDK_CURRENT_TIME);
|
|
348 gdk_keyboard_ungrab(GDK_CURRENT_TIME);
|
|
349
|
|
350 /* Let the WM manage this window again */
|
|
351 gdk_window_hide(fwin->window->window);
|
|
352 gdk_window_set_override_redirect(fwin->window->window, FALSE);
|
|
353 gdk_window_show(fwin->window->window);
|
|
354
|
|
355 /* Restore size/position */
|
|
356 gdk_window_move_resize(fwin->window->window, fwin->ox, fwin->oy,
|
|
357 fwin->owidth, fwin->oheight);
|
|
358
|
|
359 XF86VidModeSwitchToMode(fwin->display->display,
|
|
360 DefaultScreen(fwin->display->display),
|
|
361 fwin->display->origmode);
|
|
362 fwin->display->is_full = FALSE;
|
|
363 }
|
|
364 fwin->is_full = FALSE;
|
|
365 FULL_UNLOCK();
|
|
366 }
|
|
367
|
|
368 gboolean
|
|
369 xmms_fullscreen_in(GtkWidget * win)
|
|
370 {
|
|
371 fullscreen_window_t *fwin;
|
|
372
|
|
373 FULL_LOCK();
|
|
374 fwin = getwindow(win);
|
|
375 FULL_UNLOCK();
|
|
376
|
|
377 if (fwin->display->is_full)
|
|
378 return TRUE;
|
|
379 else
|
|
380 return FALSE;
|
|
381 }
|
|
382
|
|
383 gboolean
|
|
384 xmms_fullscreen_mark(GtkWidget * win)
|
|
385 {
|
|
386 fullscreen_window_t *fwin;
|
|
387
|
|
388 FULL_LOCK();
|
|
389 fwin = getwindow(win);
|
|
390
|
|
391 if (fwin->display->is_full) {
|
|
392 FULL_UNLOCK();
|
|
393 return FALSE;
|
|
394 }
|
|
395 else {
|
|
396 fwin->is_full = TRUE;
|
|
397 fwin->display->is_full = TRUE;
|
|
398 FULL_UNLOCK();
|
|
399 return TRUE;
|
|
400 }
|
|
401 }
|
|
402
|
|
403 void
|
|
404 xmms_fullscreen_unmark(GtkWidget * win)
|
|
405 {
|
|
406 fullscreen_window_t *fwin;
|
|
407
|
|
408 FULL_LOCK();
|
|
409 fwin = getwindow(win);
|
|
410
|
|
411 if (fwin->is_full) {
|
|
412 fwin->is_full = FALSE;
|
|
413 fwin->display->is_full = FALSE;
|
|
414 }
|
|
415 FULL_UNLOCK();
|
|
416 }
|
|
417
|
|
418 void
|
|
419 xmms_fullscreen_cleanup(GtkWidget * win)
|
|
420 {
|
|
421 gint i, j;
|
|
422 fullscreen_display_t *display;
|
|
423
|
|
424 FULL_LOCK();
|
|
425 if (!windows)
|
|
426 goto unlock_return;
|
|
427
|
|
428 for (i = 0; windows[i]; i++) {
|
|
429 if (windows[i]->window == win) {
|
|
430 display = windows[i]->display;
|
|
431 for (j = i + 1; windows[j]; j++);
|
|
432 windows[i] = windows[j - 1];
|
|
433 windows = g_realloc(windows, sizeof(*windows) * (j + 1));
|
|
434 windows[j] = NULL;
|
|
435
|
|
436 for (i = 0; windows[i]; i++) {
|
|
437 if (windows[i]->display == display)
|
|
438 goto unlock_return;
|
|
439 }
|
|
440 /* bugger all, kill the display */
|
|
441 for (i = 0; displays[i]; i++) {
|
|
442 if (displays[i] == display) {
|
|
443 XFree(displays[i]->modes);
|
|
444 for (j = i + 1; displays[j]; j++);
|
|
445 displays[i] = displays[j - 1];
|
|
446 displays =
|
|
447 g_realloc(displays, sizeof(*displays) * (j + 1));
|
|
448 displays[j] = NULL;
|
|
449 break;
|
|
450 }
|
|
451 }
|
|
452 }
|
|
453 }
|
|
454 unlock_return:
|
|
455 FULL_UNLOCK();
|
|
456 }
|
|
457
|
|
458 GSList *
|
|
459 xmms_fullscreen_modelist(GtkWidget * win)
|
|
460 {
|
|
461 fullscreen_window_t *fwin;
|
|
462 xmms_fullscreen_mode_t *ent;
|
|
463 GSList *retlist = NULL;
|
|
464 int i;
|
|
465
|
|
466 FULL_LOCK();
|
|
467 fwin = getwindow(win);
|
|
468
|
|
469 for (i = 0; i < fwin->display->num_modes; i++) {
|
|
470 ent = g_malloc(sizeof(*ent));
|
|
471 ent->width = fwin->display->modes[i]->hdisplay;
|
|
472 ent->height = fwin->display->modes[i]->vdisplay;
|
|
473 retlist = g_slist_append(retlist, ent);
|
|
474 }
|
|
475 FULL_UNLOCK();
|
|
476
|
|
477 return retlist;
|
|
478 }
|
|
479
|
|
480 void
|
|
481 xmms_fullscreen_modelist_free(GSList * modes)
|
|
482 {
|
|
483 g_slist_foreach(modes, (GFunc) g_free_func, NULL);
|
|
484 g_slist_free(modes);
|
|
485 }
|
|
486
|
|
487 #endif /* XF86VIDMODE */
|