19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM SDL video driver
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Window manager functions
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Patrice Mandin
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Mint includes */
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <gem.h>
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_gemwm_c.h"
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Defines */
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ICONWIDTH 64
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ICONHEIGHT 64
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Functions */
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid GEM_SetCaption(_THIS, const char *title, const char *icon)
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (title) {
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		GEM_title_name = title;
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		GEM_refresh_name = SDL_TRUE;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (icon) {
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		GEM_icon_name = icon;
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		GEM_refresh_name = SDL_TRUE;
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid GEM_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Surface *sicon;
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Rect bounds;
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if 0
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0) {
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (icon == NULL) {
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Convert icon to the screen format */
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, 0);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( sicon == NULL ) {
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bounds.x = 0;
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bounds.y = 0;
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bounds.w = icon->w;
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bounds.h = icon->h;
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 ) {
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_FreeSurface(sicon);
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_icon = sicon;
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint GEM_IconifyWindow(_THIS)
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0)
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return 0;
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[0] = WM_ICONIFY;
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[1] = gl_apid;
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[2] = 0;
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[3] = GEM_handle;
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[4] = 0;
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[5] = GEM_desk_h-ICONHEIGHT;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[6] = ICONWIDTH;
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	GEM_message[7] = ICONHEIGHT;
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	appl_write(gl_apid, sizeof(GEM_message), GEM_message);
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 1;
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_GrabMode GEM_GrabInput(_THIS, SDL_GrabMode mode)
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (this->screen == NULL) {
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return SDL_GRAB_OFF;
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return mode;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
117