annotate src/video/cocoa/SDL_cocoashape.m @ 5080:6d94060d16a9

Fixed bug #1011 Daniel Ellis 2010-06-25 15:20:31 PDT SDL based applications sometimes display the wrong application name in the Sound Preferences dialog when using pulseaudio. I can see from the code that the SDL pulse module is initiating a new pulse audio context and passing an application name using the function get_progname(). The get_progname() function returns the name of the current process. However, the process name is often not a suitable name to use. For example, the OpenShot video editor is a python application, and so "python" is displayed in the Sound Preferences window (see Bug #596504), when it should be displaying "OpenShot". PulseAudio allows applications to specify the application name, either at the time the context is created (as SDL does currently), or by special environment variables (see http://www.pulseaudio.org/wiki/ApplicationProperties). If no name is specified, then pulseaudio will determine the name based on the process. If you specify the application name when initiating the pulseaudio context, then that will override any application name specified using an environment variable. As libsdl is a library, I believe the solution is for libsdl to not specify any application name when initiating a pulseaudio context, which will enable applications to specify the application name using environment variables. In the case that the applications do not specify anything, pulseaudio will fall back to using the process name anyway. The attached patch removes the get_progname() function and passes NULL as the application name when creating the pulseaudio context, which fixes the issue.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 23 Jan 2011 21:55:04 -0800
parents 8f1994e8d886
children a2cf0174e5ab
rev   line source
4809
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
1 /*
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
3 Copyright (C) 2010 Eli Gottlieb
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
4
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
9
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
14
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
18
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
19 Eli Gottlieb
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
20 eligottlieb@gmail.com
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
21 */
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
22
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
23 #include "SDL_cocoavideo.h"
4809
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
24 #include "SDL_shape.h"
4810
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
25 #include "SDL_cocoashape.h"
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
26 #include "../src/video/SDL_sysvideo.h"
4809
329708ffe2a7 Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
27
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
28 SDL_WindowShaper*
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
29 Cocoa_CreateShaper(SDL_Window* window) {
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
30 SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
31 [windata->nswindow setOpaque:NO];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
32 [windata->nswindow setStyleMask:NSBorderlessWindowMask];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
33 SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
34 result->window = window;
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
35 result->mode.mode = ShapeModeDefault;
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
36 result->mode.parameters.binarizationCutoff = 1;
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
37 result->userx = result->usery = 0;
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
38 window->shaper = result;
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
39
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
40 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
41 result->driverdata = data;
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
42 data->context = [windata->nswindow graphicsContext];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
43 data->saved = SDL_FALSE;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
44 data->shape = NULL;
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
45
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
46 int resized_properly = Cocoa_ResizeWindowShape(window);
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
47 assert(resized_properly == 0);
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
48 return result;
4829
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
49 }
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
50
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
51 typedef struct {
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
52 NSView* view;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
53 NSBezierPath* path;
4860
8f1994e8d886 Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents: 4859
diff changeset
54 SDL_Window* window;
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
55 } SDL_CocoaClosure;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
56
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
57 void
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
58 ConvertRects(SDL_ShapeTree* tree,void* closure) {
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
59 SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
60 if(tree->kind == OpaqueShape) {
4860
8f1994e8d886 Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents: 4859
diff changeset
61 NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
62 [data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
63 }
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
64 }
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
65
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
66 int
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
67 Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
68 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
69 SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
70 SDL_CocoaClosure closure;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
71 NSAutoreleasePool *pool = NULL;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
72 if(data->saved == SDL_TRUE) {
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
73 [data->context restoreGraphicsState];
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
74 data->saved = SDL_FALSE;
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
75 }
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
76
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
77 //[data->context saveGraphicsState];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
78 //data->saved = SDL_TRUE;
4860
8f1994e8d886 Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents: 4859
diff changeset
79 [NSGraphicsContext setCurrentContext:data->context];
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
80
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
81 [[NSColor clearColor] set];
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
82 NSRectFill([[windata->nswindow contentView] frame]);
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
83 data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
84
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
85 pool = [[NSAutoreleasePool alloc] init];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
86 closure.view = [windata->nswindow contentView];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
87 closure.path = [[NSBezierPath bezierPath] autorelease];
4860
8f1994e8d886 Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents: 4859
diff changeset
88 closure.window = shaper->window;
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
89 SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
4860
8f1994e8d886 Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents: 4859
diff changeset
90 [closure.path addClip];
4829
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
91 }
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
92
4838
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
93 int
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
94 Cocoa_ResizeWindowShape(SDL_Window *window) {
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
95 SDL_ShapeData* data = window->shaper->driverdata;
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
96 assert(data != NULL);
1f9915666afd Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4811
diff changeset
97 return 0;
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
98 }