X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=vid_sdl.c;h=dd68d3aaa8a35916749a6470defdba15236a3dc9;hb=refs%2Fheads%2FJuhu%2Fsdl2_taskbar_icon;hp=e3c934a7adac167d2e208bc99650f645e43f38d5;hpb=3d324afb8b99e708a1b6f07b52433fa98ca6bb37;p=xonotic%2Fdarkplaces.git diff --git a/vid_sdl.c b/vid_sdl.c index e3c934a7..dd68d3aa 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -84,10 +84,10 @@ static int win_half_height = 50; static int video_bpp; #if SDL_MAJOR_VERSION == 1 -static SDL_Surface *screen; +static SDL_Surface *video_screen; static int video_flags; #else -static SDL_GLContext *context; +static SDL_GLContext context; static SDL_Window *window; static int window_flags; #endif @@ -787,7 +787,6 @@ static void IN_Move_TouchScreen_SteelStorm(void) float move[3], aim[3]; static qboolean oldbuttons[128]; static qboolean buttons[128]; - static keydest_t oldkeydest; keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest; memcpy(oldbuttons, buttons, sizeof(oldbuttons)); memset(multitouchs, 0, sizeof(multitouchs)); @@ -810,17 +809,6 @@ static void IN_Move_TouchScreen_SteelStorm(void) multitouch[MAXFINGERS-1][0] = 0; }*/ - if (oldkeydest != keydest) - { - switch(keydest) - { - case key_game: VID_ShowKeyboard(false);break; - case key_console: VID_ShowKeyboard(true);break; - case key_message: VID_ShowKeyboard(true);break; - default: break; /* qc extensions control the other cases */ - } - } - oldkeydest = keydest; // TODO: make touchscreen areas controlled by a config file or the VMs. THIS IS A MESS! // TODO: can't just clear buttons[] when entering a new keydest, some keys would remain pressed // SS:BR menuqc has many peculiarities, including that it can't accept more than one command per frame and pressing and releasing on the same frame @@ -979,11 +967,27 @@ void IN_Move( void ) { static int old_x = 0, old_y = 0; static int stuck = 0; + static keydest_t oldkeydest; + static qboolean oldshowkeyboard; int x, y; vid_joystate_t joystate; + keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest; scr_numtouchscreenareas = 0; + // Only apply the new keyboard state if the input changes. + if (keydest != oldkeydest || !!vid_touchscreen_showkeyboard.integer != oldshowkeyboard) + { + switch(keydest) + { + case key_console: VID_ShowKeyboard(true);break; + case key_message: VID_ShowKeyboard(true);break; + default: VID_ShowKeyboard(!!vid_touchscreen_showkeyboard.integer); break; + } + } + oldkeydest = keydest; + oldshowkeyboard = !!vid_touchscreen_showkeyboard.integer; + if (vid_touchscreen.integer) { switch(gamemode) @@ -1150,7 +1154,7 @@ void Sys_SendKeyEvents( void ) vid.width = event.resize.w; vid.height = event.resize.h; if (!vid_isfullscreen) - screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags); + video_screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags); if (vid_softsurface) { SDL_FreeSurface(vid_softsurface); @@ -1214,12 +1218,14 @@ void Sys_SendKeyEvents( void ) static qboolean sound_active = true; int keycode; int i; + qboolean isdown; Uchar unicode; SDL_Event event; VID_EnableJoystick(true); while( SDL_PollEvent( &event ) ) + loop_start: switch( event.type ) { case SDL_QUIT: #ifdef DEBUGSDLEVENTS @@ -1236,8 +1242,31 @@ void Sys_SendKeyEvents( void ) Con_DPrintf("SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym); #endif keycode = MapKey(event.key.keysym.sym); + isdown = (event.key.state == SDL_PRESSED); + unicode = 0; + if(isdown) + { + if(SDL_PollEvent(&event)) + { + if(event.type == SDL_TEXTINPUT) + { + // combine key code from SDL_KEYDOWN event and character + // from SDL_TEXTINPUT event in a single Key_Event call +#ifdef DEBUGSDLEVENTS + Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text); +#endif + unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL); + } + else + { + if (!VID_JoyBlockEmulatedKeys(keycode)) + Key_Event(keycode, 0, isdown); + goto loop_start; + } + } + } if (!VID_JoyBlockEmulatedKeys(keycode)) - Key_Event(keycode, 0, (event.key.state == SDL_PRESSED)); + Key_Event(keycode, unicode, isdown); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: @@ -1948,7 +1977,8 @@ void GLES_Init(void) Calling them just threw an exception. Android developer relations confirmed that they forgot to implement these. (yeah...) It's apparently been fixed in 2.2, though I haven't tested." */ - vid.support.ext_framebuffer_object = false;//true; + // LadyHavoc: Android 2.1 is way old now, enabling this again, it's going to be required soon. + vid.support.ext_framebuffer_object = true; vid.support.ext_packed_depth_stencil = false; vid.support.ext_stencil_two_side = false; @@ -1957,6 +1987,9 @@ void GLES_Init(void) vid.support.ext_texture_edge_clamp = true; // GLES2 core vid.support.ext_texture_filter_anisotropic = false; // probably don't want to use it... vid.support.ext_texture_srgb = false; + vid.support.arb_texture_float = SDL_GL_ExtensionSupported("GL_OES_texture_float") != 0; + vid.support.arb_half_float_pixel = SDL_GL_ExtensionSupported("GL_OES_texture_half_float") != 0; + vid.support.arb_half_float_vertex = SDL_GL_ExtensionSupported("GL_OES_vertex_half_float") != 0; // NOTE: On some devices, a value of 512 gives better FPS than the maximum. qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d); @@ -2453,11 +2486,15 @@ static void AdjustWindowBounds(viddef_mode_t *mode, RECT *rect) else { rect->left = workArea.left + max(0, (workWidth - width) / 2); - rect->top = workArea.top + (0, (workHeight - height) / 2); + rect->top = workArea.top + max(0, (workHeight - height) / 2); } } #endif +#if SDL_MAJOR_VERSION != 1 +#include +#endif + static qboolean VID_InitModeGL(viddef_mode_t *mode) { #if SDL_MAJOR_VERSION == 1 @@ -2465,6 +2502,8 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) int flags = SDL_OPENGL; #else int windowflags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL; + int xPos = SDL_WINDOWPOS_UNDEFINED; + int yPos = SDL_WINDOWPOS_UNDEFINED; #endif #ifndef USE_GLES2 int i; @@ -2527,8 +2566,6 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) // Knghtbrd: should do platform-specific extension string function here vid_isfullscreen = false; - int xPos = SDL_WINDOWPOS_UNDEFINED; - int yPos = SDL_WINDOWPOS_UNDEFINED; #if SDL_MAJOR_VERSION == 1 { const SDL_VideoInfo *vi = SDL_GetVideoInfo(); @@ -2564,7 +2601,6 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) } else { #ifdef WIN32 - DWORD windowStyle = 0; RECT rect; AdjustWindowBounds(mode, &rect); xPos = rect.left; @@ -2616,15 +2652,15 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) video_bpp = mode->bitsperpixel; #if SDL_MAJOR_VERSION == 1 video_flags = flags; - screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags); - if (screen == NULL) + video_screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags); + if (video_screen == NULL) { Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError()); VID_Shutdown(); return false; } - mode->width = screen->w; - mode->height = screen->h; + mode->width = video_screen->w; + mode->height = video_screen->h; #else window_flags = windowflags; window = SDL_CreateWindow(gamename, xPos, yPos, mode->width, mode->height, windowflags); @@ -2634,6 +2670,62 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) VID_Shutdown(); return false; } + + { + static SDL_Surface *icon = NULL; + int j; + char *data; + SDL_version version; + + if (icon) + SDL_FreeSurface(icon); + icon = NULL; + SDL_GetVersion(&version); + + if(version.major >= 2 || (version.major == 1 && version.minor >= 3)) + { + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + if(SDL_GetWindowWMInfo(window, &info) == 1 && info.subsystem == SDL_SYSWM_X11) + { + data = (char *) loadimagepixelsbgra("darkplaces-icon", false, false, false, NULL); + if(data) + { + // use _NET_WM_ICON too + static long netwm_icon[MAX_NETWM_ICON]; + int pos = 0; + int i = 1; + char vabuf[1024]; + + while(data) + { + if(pos + 2 * image_width * image_height < MAX_NETWM_ICON) + { + netwm_icon[pos++] = image_width; + netwm_icon[pos++] = image_height; + for(i = 0; i < image_height; ++i) + for(j = 0; j < image_width; ++j) + netwm_icon[pos++] = BuffLittleLong((unsigned char *) &data[(i*image_width+j)*4]); + } + else + { + Con_Printf("Skipping NETWM icon #%d because there is no space left\n", i); + } + ++i; + Mem_Free(data); + data = (char *) loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "darkplaces-icon%d", i), false, false, false, NULL); + } + + { + Atom net_wm_icon = XInternAtom(info.info.x11.display, "_NET_WM_ICON", false); + XChangeProperty(info.info.x11.display, info.info.x11.window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (const unsigned char *) netwm_icon, pos); + //SDL_SetWindowIcon(window, icon); + } + } + } + } + } + SDL_GetWindowSize(window, &mode->width, &mode->height); context = SDL_GL_CreateContext(window); if (context == NULL) @@ -2728,15 +2820,15 @@ static qboolean VID_InitModeSoft(viddef_mode_t *mode) video_bpp = mode->bitsperpixel; #if SDL_MAJOR_VERSION == 1 video_flags = flags; - screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags); - if (screen == NULL) + video_screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags); + if (video_screen == NULL) { Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError()); VID_Shutdown(); return false; } - mode->width = screen->w; - mode->height = screen->h; + mode->width = video_screen->w; + mode->height = video_screen->h; #else window_flags = windowflags; window = SDL_CreateWindow(gamename, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mode->width, mode->height, windowflags); @@ -2817,7 +2909,6 @@ void VID_Shutdown (void) { VID_EnableJoystick(false); VID_SetMouse(false, false, false); - VID_RestoreSystemGamma(); #if SDL_MAJOR_VERSION == 1 #ifndef WIN32 @@ -2850,24 +2941,6 @@ void VID_Shutdown (void) gl_platformextensions = ""; } -int VID_SetGamma (unsigned short *ramps, int rampsize) -{ -#if SDL_MAJOR_VERSION == 1 - return !SDL_SetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2); -#else - return !SDL_SetWindowGammaRamp (window, ramps, ramps + rampsize, ramps + rampsize*2); -#endif -} - -int VID_GetGamma (unsigned short *ramps, int rampsize) -{ -#if SDL_MAJOR_VERSION == 1 - return !SDL_GetGammaRamp (ramps, ramps + rampsize, ramps + rampsize*2); -#else - return !SDL_GetWindowGammaRamp (window, ramps, ramps + rampsize, ramps + rampsize*2); -#endif -} - void VID_Finish (void) { #if SDL_MAJOR_VERSION == 1 @@ -2881,7 +2954,7 @@ void VID_Finish (void) #endif vid_activewindow = !vid_hidden && vid_hasfocus; - VID_UpdateGamma(false, 256); + VID_UpdateGamma(); if (!vid_hidden) { @@ -2921,8 +2994,8 @@ void VID_Finish (void) #if SDL_MAJOR_VERSION == 1 // if (!r_test.integer) { - SDL_BlitSurface(vid_softsurface, NULL, screen, NULL); - SDL_Flip(screen); + SDL_BlitSurface(vid_softsurface, NULL, video_screen, NULL); + SDL_Flip(video_screen); } #else {