Skip to content

Instantly share code, notes, and snippets.

@jjgod
Created January 19, 2010 03:53
Show Gist options
  • Save jjgod/280647 to your computer and use it in GitHub Desktop.
Save jjgod/280647 to your computer and use it in GitHub Desktop.
From 80b1f3402a767aa9cc4f8a32a303b2e99c5f3b20 Mon Sep 17 00:00:00 2001
From: Jjgod Jiang <gzjjgod@gmail.com>
Date: Mon, 18 Jan 2010 17:46:35 +0800
Subject: [PATCH] Polish text input handling for Mac OS X
- Prevent crash caused by uninitialized video data
- Prevent beeping caused by unhandled Cocoa selectors (like moveUp:
moveDown:, etc.)
---
src/video/SDL_video.c | 6 +++---
src/video/cocoa/SDL_cocoaevents.m | 1 -
src/video/cocoa/SDL_cocoakeyboard.m | 16 ++++++++++------
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 1561fac..6907fbf 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -3583,7 +3583,7 @@ SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
void
SDL_StartTextInput(void)
{
- if (_this->StartTextInput) {
+ if (_this && _this->StartTextInput) {
_this->StartTextInput(_this);
}
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
@@ -3593,7 +3593,7 @@ SDL_StartTextInput(void)
void
SDL_StopTextInput(void)
{
- if (_this->StopTextInput) {
+ if (_this && _this->StopTextInput) {
_this->StopTextInput(_this);
}
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
@@ -3603,7 +3603,7 @@ SDL_StopTextInput(void)
void
SDL_SetTextInputRect(SDL_Rect *rect)
{
- if (_this->SetTextInputRect) {
+ if (_this && _this->SetTextInputRect) {
_this->SetTextInputRect(_this, rect);
}
}
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index befe3a9..d833400 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -212,7 +212,6 @@ Cocoa_PumpEvents(_THIS)
case NSFlagsChanged:
Cocoa_HandleKeyEvent(_this, event);
/* Fall through to pass event to NSApp; er, nevermind... */
- /* FIXME: Find a way to stop the beeping, using delegate */
/* Add to support system-wide keyboard shortcuts like CMD+Space */
if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged)
diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m
index c837442..d03a525 100644
--- a/src/video/cocoa/SDL_cocoakeyboard.m
+++ b/src/video/cocoa/SDL_cocoakeyboard.m
@@ -109,7 +109,9 @@ typedef unsigned int NSUInteger;
- (void) doCommandBySelector:(SEL) myselector
{
- [super doCommandBySelector: myselector];
+ // No need to do anything since we are not using Cocoa
+ // selectors to handle special keys, instead we use SDL
+ // key events to do the same job.
}
- (BOOL) hasMarkedText
@@ -659,11 +661,13 @@ Cocoa_StopTextInput(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [data->fieldEdit removeFromSuperview];
- [data->fieldEdit release];
- data->fieldEdit = nil;
- [pool release];
+ if (data && data->fieldEdit) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ [data->fieldEdit removeFromSuperview];
+ [data->fieldEdit release];
+ data->fieldEdit = nil;
+ [pool release];
+ }
}
void
--
1.6.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment