comparison src/video/x11/SDL_x11window.c @ 2875:91a7e08cd238

* Implemented X11 fullscreen input grab * Progress towards being able to toggle in and out of fullscreen mode
author Sam Lantinga <slouken@libsdl.org>
date Wed, 17 Dec 2008 07:17:54 +0000
parents 99210400e8b9
children 3fcb0d447bcd
comparison
equal deleted inserted replaced
2874:36e312e0fac0 2875:91a7e08cd238
285 XCreateColormap(data->display, 285 XCreateColormap(data->display,
286 RootWindow(data->display, displaydata->screen), 286 RootWindow(data->display, displaydata->screen),
287 visual, AllocNone); 287 visual, AllocNone);
288 } 288 }
289 289
290 if (window->x == SDL_WINDOWPOS_CENTERED) { 290 if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->x == SDL_WINDOWPOS_CENTERED) {
291 x = (DisplayWidth(data->display, displaydata->screen) - 291 x = (DisplayWidth(data->display, displaydata->screen) -
292 window->w) / 2; 292 window->w) / 2;
293 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { 293 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
294 x = 0; 294 x = 0;
295 } else { 295 } else {
296 x = window->x; 296 x = window->x;
297 } 297 }
298 if (window->y == SDL_WINDOWPOS_CENTERED) { 298 if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->y == SDL_WINDOWPOS_CENTERED) {
299 y = (DisplayHeight(data->display, displaydata->screen) - 299 y = (DisplayHeight(data->display, displaydata->screen) -
300 window->h) / 2; 300 window->h) / 2;
301 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) { 301 } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
302 y = 0; 302 y = 0;
303 } else { 303 } else {
319 return -1; 319 return -1;
320 } 320 }
321 321
322 sizehints = XAllocSizeHints(); 322 sizehints = XAllocSizeHints();
323 if (sizehints) { 323 if (sizehints) {
324 if (window->flags & SDL_WINDOW_RESIZABLE) { 324 if ((window->flags & SDL_WINDOW_RESIZABLE) && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
325 sizehints->min_width = 32; 325 sizehints->min_width = 32;
326 sizehints->min_height = 32; 326 sizehints->min_height = 32;
327 sizehints->max_height = 4096; 327 sizehints->max_height = 4096;
328 sizehints->max_width = 4096; 328 sizehints->max_width = 4096;
329 } else { 329 } else {
340 } 340 }
341 XSetWMNormalHints(data->display, w, sizehints); 341 XSetWMNormalHints(data->display, w, sizehints);
342 XFree(sizehints); 342 XFree(sizehints);
343 } 343 }
344 344
345 if (window->flags & SDL_WINDOW_BORDERLESS) { 345 if (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN)) {
346 SDL_bool set; 346 SDL_bool set;
347 Atom WM_HINTS; 347 Atom WM_HINTS;
348 348
349 /* We haven't modified the window manager hints yet */ 349 /* We haven't modified the window manager hints yet */
350 set = SDL_FALSE; 350 set = SDL_FALSE;
599 { 599 {
600 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; 600 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
601 SDL_DisplayData *displaydata = 601 SDL_DisplayData *displaydata =
602 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata; 602 (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
603 Display *display = data->videodata->display; 603 Display *display = data->videodata->display;
604 604 int x, y;
605 XMoveWindow(display, data->window, window->x, window->y); 605
606 if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->x == SDL_WINDOWPOS_CENTERED) {
607 x = (DisplayWidth(display, displaydata->screen) - window->w) / 2;
608 } else {
609 x = window->x;
610 }
611 if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->y == SDL_WINDOWPOS_CENTERED) {
612 y = (DisplayHeight(display, displaydata->screen) - window->h) / 2;
613 } else {
614 y = window->y;
615 }
616 XMoveWindow(display, data->window, x, y);
606 } 617 }
607 618
608 void 619 void
609 X11_SetWindowSize(_THIS, SDL_Window * window) 620 X11_SetWindowSize(_THIS, SDL_Window * window)
610 { 621 {
660 } 671 }
661 672
662 void 673 void
663 X11_SetWindowGrab(_THIS, SDL_Window * window) 674 X11_SetWindowGrab(_THIS, SDL_Window * window)
664 { 675 {
665 /* FIXME */ 676 SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
677 Display *display = data->videodata->display;
678
679 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) &&
680 (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
681 /* Try to grab the mouse */
682 for ( ; ; ) {
683 int result = XGrabPointer(display, data->window, True, 0, GrabModeAsync, GrabModeAsync, data->window, None, CurrentTime);
684 if ( result == GrabSuccess ) {
685 break;
686 }
687 SDL_Delay(100);
688 }
689
690 /* Raise the window if we grab the mouse */
691 XRaiseWindow(display, data->window);
692
693 /* Now grab the keyboard */
694 XGrabKeyboard(display, data->window, True, GrabModeAsync, GrabModeAsync, CurrentTime);
695 } else {
696 XUngrabPointer(display, CurrentTime);
697 XUngrabKeyboard(display, CurrentTime);
698 }
666 } 699 }
667 700
668 void 701 void
669 X11_DestroyWindow(_THIS, SDL_Window * window) 702 X11_DestroyWindow(_THIS, SDL_Window * window)
670 { 703 {