Mercurial > sdl-ios-xcode
annotate test/testsem.c @ 4391:07b330419439 SDL-1.2
Fixed bug #849 some more:
Tim Angus 2009-11-26 14:41:04 PST
Fix to the cursor not being responsive when the app doesn't have
SDL_APPINPUTFOCUS
The problems with the directx driver are similar to the ones I introduced in
the windib driver with r4478. Basically if the application did not have focus,
the mouse position is not updated. It's not really that the mouse cursor was
invisible, it's that it is stuck underneath another window where you can't see
it. This behaviour predates my r4478 changes and is the reason I unwittingly
broke the windib driver as I had been replicating the way the directx driver
deals with focus. Prior to r4478 the directx driver could not be used in
windowed mode, so the broken focusing would not have actually been observable.
Anyway, the attached patch makes the directx driver behaves like the windib
driver in terms of focus.
Time for 1.2.15? ;)
I've added an additional change of moving the calls to WIN_GrabInput that are
made on WM_ACTIVATE messages so that they only occur when the state is
SDL_APPINPUTFOCUS. When a fullscreen application is minimised using alt-tab, it
still receives WM_ACTIVATE messages when other applications are selected. If
WIN_GrabInput is called when the SDL application doesn't have input focus, bad
things happen; it shouldn't be being called at all.
I've also added a line to make sure that SDL_APPMOUSEFOCUS state is dropped
when the application is minimised following an alt-tab.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 11 Dec 2009 15:24:53 +0000 |
parents | 290b5baf2fca |
children | 782fd950bd46 c121d94672cb 99acf3d856cb |
rev | line source |
---|---|
0 | 1 |
2 /* Simple test of the SDL semaphore code */ | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <signal.h> | |
7 | |
8 #include "SDL.h" | |
9 #include "SDL_thread.h" | |
10 | |
11 #define NUM_THREADS 10 | |
12 | |
13 static SDL_sem *sem; | |
14 int alive = 1; | |
15 | |
1769 | 16 int SDLCALL ThreadFunc(void *data) |
0 | 17 { |
1615
d5298e8f22b3
Ugh, more 64-bit cleanup
Sam Lantinga <slouken@libsdl.org>
parents:
1495
diff
changeset
|
18 int threadnum = (int)(uintptr_t)data; |
0 | 19 while ( alive ) { |
20 SDL_SemWait(sem); | |
1495
1dd8bf30a109
Might have fixed 64-bit issues. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1439
diff
changeset
|
21 fprintf(stderr, "Thread number %d has got the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem)); |
0 | 22 SDL_Delay(200); |
23 SDL_SemPost(sem); | |
1495
1dd8bf30a109
Might have fixed 64-bit issues. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1439
diff
changeset
|
24 fprintf(stderr, "Thread number %d has released the semaphore (value = %d)!\n", threadnum, SDL_SemValue(sem)); |
0 | 25 SDL_Delay(1); /* For the scheduler */ |
26 } | |
1495
1dd8bf30a109
Might have fixed 64-bit issues. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1439
diff
changeset
|
27 printf("Thread number %d exiting.\n", threadnum); |
0 | 28 return 0; |
29 } | |
30 | |
31 static void killed(int sig) | |
32 { | |
33 alive = 0; | |
34 } | |
35 | |
36 int main(int argc, char **argv) | |
37 { | |
38 SDL_Thread *threads[NUM_THREADS]; | |
1495
1dd8bf30a109
Might have fixed 64-bit issues. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1439
diff
changeset
|
39 uintptr_t i; |
1dd8bf30a109
Might have fixed 64-bit issues. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1439
diff
changeset
|
40 int init_sem; |
0 | 41 |
42 if(argc < 2) { | |
43 fprintf(stderr,"Usage: %s init_value\n", argv[0]); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
44 return(1); |
0 | 45 } |
46 | |
47 /* Load the SDL library */ | |
48 if ( SDL_Init(0) < 0 ) { | |
49 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
50 return(1); |
0 | 51 } |
52 signal(SIGTERM, killed); | |
53 signal(SIGINT, killed); | |
54 | |
55 init_sem = atoi(argv[1]); | |
56 sem = SDL_CreateSemaphore(init_sem); | |
57 | |
58 printf("Running %d threads, semaphore value = %d\n", NUM_THREADS, init_sem); | |
59 /* Create all the threads */ | |
60 for( i = 0; i < NUM_THREADS; ++i ) { | |
61 threads[i] = SDL_CreateThread(ThreadFunc, (void*)i); | |
62 } | |
63 | |
64 /* Wait 10 seconds */ | |
65 SDL_Delay(10 * 1000); | |
66 | |
67 /* Wait for all threads to finish */ | |
68 printf("Waiting for threads to finish\n"); | |
69 alive = 0; | |
70 for( i = 0; i < NUM_THREADS; ++i ) { | |
71 SDL_WaitThread(threads[i], NULL); | |
72 } | |
73 printf("Finished waiting for threads\n"); | |
74 | |
75 SDL_DestroySemaphore(sem); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
76 SDL_Quit(); |
0 | 77 return(0); |
78 } |