File: SCREENPreference.c

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (514 lines) | stat: -rw-r--r-- 27,471 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/*
    SCREENPreference.c

    AUTHORS:

    Allen.Ingling@nyu.edu           awi
    mario.kleiner.de@gmail.com      mk

    PLATFORMS:

        All.

    HISTORY:

        2/28/04     awi     Created.
        10/29/04    awi     Fixed two warnings, one where a const char should have been been char, the other the other way around.
        1/20/05     awi     Added a preference for debugging MakeTexture
        5/30/05     mk      New preference setting screenSkipSyncTests -- allow skipping/shortening of some internal tests.
        5/30/05     mk      New preference setting screenVisualDebugLevel.
        3/07/05     awi     New preference SuppressAllWarnings.
        11/15/06    mk      New preference vbl & flip timestamping mode.

    DESCRIPTION:

        Read and set preferences.

        Note that we do don't do sanity checking on arguments provided in conjunction for unsuported preferences.  That might be conveivably be a mildly
        useful feature for catching cross-platform errors if we detect argument type errors before detecting the error of using a platform unsupported preference.
*/


#include "Screen.h"

#if PSYCH_SYSTEM != PSYCH_WINDOWS

// for getpid()
#include <sys/types.h>
#include <unistd.h>

#else

// Windows doesn't have getpid() - We create a pseudo-getpid:
psych_uint64 getpid(void)
{
  HANDLE p;
  p=GetCurrentProcess();
  return((psych_uint64) p);
}
#endif

/*
OS 9 Psychtoolbox preferences:

	Supported
oldBool=Screen('Preference', 'IgnoreCase' [,psych_bool])
tick0Secs=Screen('Preference', 'Tick0Secs', tick0Secs)
psychTableVersion=Screen('Preference', 'PsychTableVersion')
mexFunctionName=Screen('Preference', 'PsychTableCreator')
proc=Screen('Preference', 'Process', signature)   //returns PID and does not accept the signature 


	Read supported but will not accept set:
oldBool=Screen('Preference','Backgrounding',[psych_bool])
oldSecondsMultiplier=Screen('Preference', 'SecondsMultiplier' [,secondsMultiplier])
	
	Unsupported and we should
oldBool=Screen('Preference' ',AllowMirroring' [,psych_bool])
psych_bool=Screen('Preference' ',MirroringIsOn')
oldBits=Screen(windowPtrOrScreenNumber, 'Preference', 'DacBits', bits) 

	Unsupported
available=Screen('Preference','Available')
nextProc=Screen('Preference','NextProcess',[proc])
oldBool=Screen('Preference','UseNewHideMenuBar',[psych_bool])

	Unsupported OS 9 Mac video driver specific 
psych_bool=Screen(windowPtrOrScreenNumber,'Preference','FixedClut')
oldBool=Screen(windowPtrOrScreenNumber,'Preference','SetClutDriverWaitsForBlanking',[psych_bool])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','AskSetClutDriverToWaitForBlanking',[psych_bool])
oldValue=Screen(windowPtrOrScreenNumber,'Preference','SetClutSAI',[value])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','SetClutCallsWaitBlanking',[psych_bool])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','SetClutPunchesBlankingClock',[psych_bool])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','InterruptPunchesBlankingClock',[psych_bool])
oldPriority=Screen(windowPtrOrScreenNumber,'Preference','MaxPriorityForBlankingInterrupt',[priority])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','WaitBlankingAlwaysCallsSetClut',[psych_bool])
oldSecs=Screen(windowPtrOrScreenNumber,'Preference','BlankingDuration',[secs])
oldN=Screen(windowPtrOrScreenNumber,'Preference','MinimumEntriesForSetClutToWaitForBlanking',[n])
oldPriority=Screen(windowPtrOrScreenNumber,'Preference','MinimumSetClutPriority',[priority])
oldPriority=Screen(windowPtrOrScreenNumber,'Preference','MaximumSetClutPriority',[priority])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','DipPriorityAfterSetClut',[psych_bool])
oldBool=Screen(windowPtrOrScreenNumber,'Preference','UsesHighGammaBits',[psych_bool])

*/

static char useString[] = "oldPreferenceValue = Screen('Preference', preferenceName, [newPreferenceValue])";
//                                                         0             1                2
static char synopsisString[] = 
    "Get or set a Psychtoolbox preference."
    "Preference settings are global - they affect all operations of a module until changed."
    ""
    "\noldBool = Screen('Preference', 'IgnoreCase', [psych_bool]);"
    "\ntick0Secs = Screen('Preference', 'Tick0Secs', tick0Secs);"
    "\npsychTableVersion = Screen('Preference', 'PsychTableVersion');"
    "\nmexFunctionName = Screen('Preference', 'PsychTableCreator');"
    "\nproc = Screen('Preference', 'Process', signature);"
    "\nproc = Screen('Preference', 'DebugMakeTexture', enableDebugging);"
    "\noldEnableFlag = Screen('Preference', 'TextAlphaBlending', [enableFlag]);"
    "\noldSize = Screen('Preference', 'DefaultFontSize', [fontSize]);"
    "\noldStyleFlag = Screen('Preference', 'DefaultFontStyle', [styleFlag]);"
    "\noldfontName = Screen('Preference', 'DefaultFontName', [fontName]);"
    "\noldEnableFlag = Screen('Preference', 'DefaultTextYPositionIsBaseline', [enableFlag]);"
    "\noldEnableFlag = Screen('Preference', 'TextAntiAliasing', [enableFlag=-1 (System setting), 0 = Disable, 1 = Enable, 2 = EnableHighQuality]);"
    "\noldEnableFlag = Screen('Preference', 'TextRenderer', [enableFlag=0 (Legacy OS-specific), 1 = HighQ OS-specific (Default), 2 = Linux renderer plugin]);"
    "\noldLocaleNameString = Screen('Preference', 'TextEncodingLocale', [newLocalenNameString]);"
    "\noldEnableFlag = Screen('Preference', 'SkipSyncTests', [enableFlag]);"
    "\n[maxStddev, minSamples, maxDeviation, maxDuration] = Screen('Preference', 'SyncTestSettings' [, maxStddev=0.001 secs][, minSamples=50][, maxDeviation=0.1][, maxDuration=5 secs]);"
    "\noldEnableFlag = Screen('Preference', 'FrameRectCorrection', [enableFlag=1]);"
    "\noldLevel = Screen('Preference', 'VisualDebugLevel', level);"
    "\n\nWorkaround flags to work around all kind of deficient drivers and hardware:\n"
    "See 'help ConserveVRAMSettings' for settings and their effect.\n"
    "\noldMode = Screen('Preference', 'ConserveVRAM', mode);"
    "\n\nActivate compatibility mode: Try to behave like the old MacOS-9 Psychtoolbox:"
    "\noldEnableFlag = Screen('Preference', 'EmulateOldPTB', [enableFlag]);\n"
    "\noldEnableFlags = Screen('Preference', 'Enable3DGraphics', [enableFlags]);"
    "\noldEnableFlag = Screen('Preference', 'SuppressAllWarnings', [enableFlag]);"
    "\noldMode = Screen('Preference', 'VBLTimestampingMode', [newmode]);"
    "\n[oldVTOTAL, oldmaxVTOTALFactor] = Screen('Preference', 'VBLEndlineOverride' [, newVTOTAL=auto][, maxVTOTALFactor=1.25]);"
    "\noldMode = Screen('Preference', 'DefaultVideocaptureEngine', [newmode (0=Quicktime - unsupported, 1=LibDC1394-Firewire, 2=LibARVideo - unsupported, 3=GStreamer)]);"
    "\noldMode = Screen('Preference', 'OverrideMultimediaEngine', [newmode (0=Legacy-Quicktime - unsupported, 1=GStreamer)]);"
    "\noldLevel = Screen('Preference', 'WindowShieldingLevel', [newLevel (0 = Behind all other windows - 2000 = In front of all other windows, the default)]);"
    "\nresiduals = Screen('Preference', 'SynchronizeDisplays', syncMethod [, screenId]);"
    "\noldMappings = Screen('Preference', 'ScreenToHead', screenId [, newHeadId, newCrtcId][, rank=0]);"

    "\noldLevel = Screen('Preference', 'Verbosity' [,level]);";

static char seeAlsoString[] = "";

#define kPsychNumUnsupportedMacVideoPreferences         14
static char *unsupportedMacVideoPreferenceNames[]={
    "FixedClut"
    "SetClutDriverWaitsForBlanking",
    "AskSetClutDriverToWaitForBlanking",
    "SetClutSAI SetClutCallsWaitBlanking",
    "SetClutPunchesBlankingClock",
    "InterruptPunchesBlankingClock",
    "MaxPriorityForBlankingInterrupt",
    "WaitBlankingAlwaysCallsSetClut",
    "BlankingDuration",
    "MinimumEntriesForSetClutToWaitForBlanking",
    "MinimumSetClutPriority",
    "MaximumSetClutPriority",
    "DipPriorityAfterSetClut",
    "UsesHighGammaBits"
};

#define kPsychNumUnsupportedMacNonVideoPreferences      6
static char *unsupportedMacNonVideoPreferenceNames[]={
    "AllowMirroring",
    "MirroringIsOn",
    "DacBits",
    "Available",
    "NextProcess",
    "UseNewHideMenuBar"
};

PsychError SCREENPreference(void)  
{
    PsychArgFormatType  arg1Type;
    char                *preferenceName, *newFontName;
    const char          *tableCreator, *oldDefaultFontName;
    psych_bool          preferenceNameArgumentValid, booleanInput, ignoreCase, tempFlag, textAlphaBlendingFlag, suppressAllWarningsFlag;
    int                 numInputArgs, i, newFontStyleNumber, newFontSize, tempInt, tempInt2, tempInt3, tempInt4;
    double              returnDoubleValue, inputDoubleValue;
    double              maxStddev, maxDeviation, maxDuration;
    int                 minSamples;
    double              *dheads = NULL;

    //all sub functions should have these two lines
    PsychPushHelp(useString, synopsisString,seeAlsoString);
    if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};

    //check for superfluous or missing arguments
    PsychErrorExit(PsychCapNumInputArgs(5));
    PsychErrorExit(PsychRequireNumInputArgs(1));
    PsychErrorExit(PsychCapNumOutputArgs(4));

    numInputArgs=PsychGetNumInputArgs();
    arg1Type=PsychGetArgType(1);
    preferenceNameArgumentValid=FALSE;

    //Cases which require both a window pointer or screen number and preference name.  Argument 1 is the wposn and argument 2 is the preference name.
    if( numInputArgs >= 2 && (PsychIsScreenNumberArg(1) || PsychIsScreenNumberArg(1)) && PsychGetArgType(2)==PsychArgType_char ){
        PsychAllocInCharArg(2, kPsychArgRequired, &preferenceName);
        //preferences which require window pointer or screen number argument which we DO NOT support
        for(i = 0; i < kPsychNumUnsupportedMacVideoPreferences; i++) {
            if(PsychMatch(preferenceName, unsupportedMacVideoPreferenceNames[i])) {
                PsychErrorExit(PsychError_unsupportedOS9Preference);
                return(PsychError_unsupportedOS9Preference);
            }
        }
        //insert here conditionals  to act on prefernces which accept a window pointer or screen number argument which we DO support.
        PsychErrorExit(PsychError_unrecognizedPreferenceName);
    }

    //Cases which do not require a wposn.  Argument 1 is the preference name.  if present Argument 2 is the new value
    if(arg1Type==PsychArgType_char){
        PsychAllocInCharArg(1, kPsychArgRequired, &preferenceName);
        //Preferernces which we do not support and which do not require a wposn
        for(i=0;i<kPsychNumUnsupportedMacNonVideoPreferences;i++){
            if(PsychMatch(preferenceName, unsupportedMacNonVideoPreferenceNames[i]))
                PsychErrorExit(PsychError_unsupportedOS9Preference);
        }
        //Preferences which we do support
        if(PsychMatch(preferenceName, "IgnoreCase")){
            ignoreCase=!PsychIsPsychMatchCaseSensitive();
            PsychCopyOutFlagArg(1, kPsychArgOptional, ignoreCase);
            if(numInputArgs==2){
                PsychCopyInFlagArg(2, kPsychArgRequired, &booleanInput);
                PsychSetPsychMatchCaseSenstive(!booleanInput);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "Tick0Secs")){
            if(PsychCopyInDoubleArg(2, kPsychArgOptional, &inputDoubleValue) && inputDoubleValue==PsychGetNanValue())
                PsychEstimateGetSecsValueAtTickCountZero();
            returnDoubleValue=PsychGetEstimatedSecsValueAtTickCountZero();
            PsychCopyOutDoubleArg(1, kPsychArgOptional, returnDoubleValue);
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "PsychTableVersion")){
            if(numInputArgs==2)
                PsychErrorExit(PsychError_extraInputArg);
            PsychCopyOutDoubleArg(1, kPsychArgOptional, (double)PsychPrefStateGet_PsychTableVersion());
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "PsychTableCreator")){
            if(numInputArgs==2)
                PsychErrorExit(PsychError_extraInputArg);
            tableCreator=PsychPrefStateGet_PsychTableCreator();
            PsychCopyOutCharArg(1, kPsychArgOptional, tableCreator);
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "Process")){
            if(numInputArgs==2)
                PsychErrorExit(PsychError_extraInputArg);
            PsychCopyOutDoubleArg(1, kPsychArgOptional, (double) (psych_int64) getpid());
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "DefaultFontName")){
            PsychPrefStateGet_DefaultFontName(&oldDefaultFontName);
            PsychCopyOutCharArg(1, kPsychArgOptional, oldDefaultFontName);
            if(numInputArgs==2){
                PsychAllocInCharArg(2, kPsychArgRequired, &newFontName);
                PsychPrefStateSet_DefaultFontName(newFontName);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "TextEncodingLocale")){
            PsychCopyOutCharArg(1, kPsychArgOptional, PsychGetUnicodeTextConversionLocale());
            if(numInputArgs==2){
                PsychAllocInCharArg(2, kPsychArgRequired, &newFontName);
                if (!PsychSetUnicodeTextConversionLocale(newFontName)) PsychErrorExitMsg(PsychError_user, "Setting the 'TextEncodingLocale' failed, most likely because you provided an invalid/unknown locale setting string.");
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "DefaultFontStyle")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_DefaultTextStyle());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &newFontStyleNumber);
                PsychPrefStateSet_DefaultTextStyle(newFontStyleNumber);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "OverrideMultimediaEngine")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_UseGStreamer());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                PsychPrefStateSet_UseGStreamer(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "DefaultTextYPositionIsBaseline")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_TextYPositionIsBaseline());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                PsychPrefStateSet_TextYPositionIsBaseline(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "TextAntiAliasing")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_TextAntiAliasing());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                PsychPrefStateSet_TextAntiAliasing(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "TextRenderer")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_TextRenderer());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                PsychPrefStateSet_TextRenderer(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "DefaultFontSize")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_DefaultTextSize());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &newFontSize);
                PsychPrefStateSet_DefaultTextSize(newFontSize);
            }
            preferenceNameArgumentValid=TRUE;
        }else
        if(PsychMatch(preferenceName, "DebugMakeTexture")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_DebugMakeTexture());
            if(numInputArgs==2){
                PsychCopyInFlagArg(2, kPsychArgRequired, &tempFlag);
                PsychPrefStateSet_DebugMakeTexture(tempFlag);
            }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "SkipSyncTests")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_SkipSyncTests());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                PsychPrefStateSet_SkipSyncTests(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "VisualDebugLevel")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_VisualDebugLevel());
            if(numInputArgs==2){
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                PsychPrefStateSet_VisualDebugLevel(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "VBLTimestampingMode")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_VBLTimestampingMode());
            if(numInputArgs>=2){
                            PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                            PsychPrefStateSet_VBLTimestampingMode(tempInt);
            }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "SyncTestSettings")){
            PsychPrefStateGet_SynctestThresholds(&maxStddev, &minSamples, &maxDeviation, &maxDuration);
            PsychCopyOutDoubleArg(1, kPsychArgOptional, maxStddev);
            PsychCopyOutDoubleArg(2, kPsychArgOptional, minSamples);
            PsychCopyOutDoubleArg(3, kPsychArgOptional, maxDeviation);
            PsychCopyOutDoubleArg(4, kPsychArgOptional, maxDuration);
            if(numInputArgs>=2){
                            PsychCopyInDoubleArg( 2, kPsychArgOptional, &maxStddev);
                            PsychCopyInIntegerArg(3, kPsychArgOptional, &minSamples);
                            PsychCopyInDoubleArg( 4, kPsychArgOptional, &maxDeviation);
                            PsychCopyInDoubleArg( 5, kPsychArgOptional, &maxDuration);
                            PsychPrefStateSet_SynctestThresholds(maxStddev, minSamples, maxDeviation, maxDuration);
            }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "VBLEndlineOverride")){
            PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_VBLEndlineOverride());
            PsychCopyOutDoubleArg(2, kPsychArgOptional, PsychPrefStateGet_VBLEndlineMaxFactor());

            if (PsychCopyInIntegerArg(2, kPsychArgOptional, &tempInt)) {
                PsychPrefStateSet_VBLEndlineOverride(tempInt);
            }

            if (PsychCopyInDoubleArg(3, kPsychArgOptional, &inputDoubleValue)) {
                PsychPrefStateSet_VBLEndlineMaxFactor(inputDoubleValue);
            }

            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "DefaultVideocaptureEngine")){
                PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_VideoCaptureEngine());
                if(numInputArgs==2){
                    PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                    PsychPrefStateSet_VideoCaptureEngine(tempInt);
                }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "WindowShieldingLevel")){
                PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_WindowShieldingLevel());
                if(numInputArgs==2){
                    PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                    PsychPrefStateSet_WindowShieldingLevel(tempInt);
                }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "ConserveVRAM") || PsychMatch(preferenceName, "Workarounds1")){
                    PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_ConserveVRAM());
                    if(numInputArgs==2){
                        PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                        PsychPrefStateSet_ConserveVRAM(tempInt);
                    }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "Verbosity")){
                    PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_Verbosity());
                    if(numInputArgs==2){
                        PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                        PsychPrefStateSet_Verbosity(tempInt);
                    }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "FrameRectCorrection")){
                    PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_FrameRectCorrection());
                    if(numInputArgs==2){
                        PsychCopyInDoubleArg(2, kPsychArgRequired, &inputDoubleValue);
                        PsychPrefStateSet_FrameRectCorrection(inputDoubleValue);
                    }
            preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "EmulateOldPTB")){
                PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_EmulateOldPTB());
                if(numInputArgs==2){
                    PsychCopyInFlagArg(2, kPsychArgRequired, &tempFlag);
                    PsychPrefStateSet_EmulateOldPTB(tempFlag);
                }
                preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "Enable3DGraphics")){
                PsychCopyOutDoubleArg(1, kPsychArgOptional, PsychPrefStateGet_3DGfx());
                if(numInputArgs==2){
                    PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                    PsychPrefStateSet_3DGfx(tempInt);
                }
                preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "TextAlphaBlending")){
                textAlphaBlendingFlag=PsychPrefStateGet_TextAlphaBlending();
                PsychCopyOutFlagArg(1, kPsychArgOptional, textAlphaBlendingFlag);
                if(numInputArgs==2){
                    PsychCopyInFlagArg(2, kPsychArgRequired, &booleanInput);
                    PsychPrefStateSet_TextAlphaBlending(booleanInput);
                }
                preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "SuppressAllWarnings")){
                suppressAllWarningsFlag=PsychPrefStateGet_SuppressAllWarnings();
                PsychCopyOutFlagArg(1, kPsychArgOptional, suppressAllWarningsFlag);
                if(numInputArgs==2){
                    PsychCopyInFlagArg(2, kPsychArgRequired, &booleanInput);
                    PsychPrefStateSet_SuppressAllWarnings(booleanInput);
                }
                preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "SynchronizeDisplays")){
                if(numInputArgs >= 2) {
                    // This is a special call: It currently doesn't set a preference setting,
                    // but instead triggers an instantaneous synchronization of all available
                    // display heads, if possible. We may have a more clever and "standard" interface
                    // interface for this later on, but for first tests this will do.
                    // Syncmethod is hard-coded to 0 -> Use whatever's available to sync.
                    // timeout for retries is 5.0 seconds.
                    // Acceptable residual offset is +/- 2 scanlines.
                    // Returns the real residual offset after sync.
                    PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                    if (!PsychCopyInIntegerArg(3, kPsychArgOptional, &tempInt3)) {
                        // No screenId specified: Resync default screen or whatever...
                        tempInt2 = 0;
                        if (PsychSynchronizeDisplayScreens(&tempInt2, NULL, &tempInt, tempInt, 5.0, 2)!=PsychError_none) PsychErrorExitMsg(PsychError_user, "Sync failed for reasons mentioned above.");
                    } else {
                        // Specific screenId provided: Resync crtc's associated with this screenId if possible:
                        tempInt2 = 1;
                        if (PsychSynchronizeDisplayScreens(&tempInt2, &tempInt3, &tempInt, tempInt, 5.0, 2)!=PsychError_none) PsychErrorExitMsg(PsychError_user, "Sync failed for reasons mentioned above.");
                    }
                    PsychCopyOutDoubleArg(1, kPsychArgOptional, tempInt);
                }
                preferenceNameArgumentValid=TRUE;
        }else
            if(PsychMatch(preferenceName, "ScreenToHead")){
                // screenId is required:
                PsychCopyInIntegerArg(2, kPsychArgRequired, &tempInt);
                if (tempInt < 0 || tempInt >= PsychGetNumDisplays() || tempInt >= kPsychMaxPossibleDisplays) PsychErrorExitMsg(PsychError_user, "Invalid screenId provided. Out of valid range!");

                // Return old mappings for this screenId:
                for (tempInt2 = 0; (tempInt2 < kPsychMaxPossibleCrtcs) && (PsychPrefStateGet_ScreenToHead(tempInt, tempInt2) >= 0); tempInt2++);
                PsychAllocOutDoubleMatArg(1, kPsychArgOptional, 2, tempInt2, 1, &dheads);

                tempInt4 = 0;
                for (tempInt3 = 0; tempInt3 < tempInt2; tempInt3++) {
                    dheads[tempInt4++] = (double) PsychPrefStateGet_ScreenToHead(tempInt, tempInt3);
                    dheads[tempInt4++] = (double) PsychPrefStateGet_ScreenToCrtcId(tempInt, tempInt3);
                }

                // Optionally retrieve and set new mappings for this screenId:
                if(numInputArgs>=3) {
                    // Set new headId for screenId:
                    PsychCopyInIntegerArg(3, kPsychArgRequired, &tempInt2);
                    if (tempInt2 < 0) PsychErrorExitMsg(PsychError_user, "Invalid negative headId provided!");

                    // Set new crtcId for screenId:
                    PsychCopyInIntegerArg(4, kPsychArgRequired, &tempInt3);
                    if (tempInt3 < 0) PsychErrorExitMsg(PsychError_user, "Invalid negative crtcId provided!");

                    // Assign primary head by default (index 0), but allow optionally others as well:
                    tempInt4 = 0;
                    PsychCopyInIntegerArg(5, kPsychArgOptional, &tempInt4);
                    if (tempInt4 < 0 || tempInt4 >= kPsychMaxPossibleCrtcs) PsychErrorExitMsg(PsychError_user, "Invalid rankId provided! Too many heads for one screen!");

                    PsychPrefStateSet_ScreenToHead(tempInt, tempInt2, tempInt3, tempInt4);
                }
                preferenceNameArgumentValid=TRUE;
        }else
            PsychErrorExit(PsychError_unrecognizedPreferenceName);
    }

    if(!preferenceNameArgumentValid)
        PsychErrorExitMsg(PsychError_user, "Invalid arguments to preferences command");

    return(PsychError_none);
}