macdrv_main.c 21.5 KB
Newer Older
1
/*
2
 * MACDRV initialization code
3 4 5
 *
 * Copyright 1998 Patrik Stridvall
 * Copyright 2000 Alexandre Julliard
6
 * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
22 23 24 25 26

#if 0
#pragma makedep unix
#endif

27 28
#include "config.h"

29
#include <Security/AuthSession.h>
30
#include <IOKit/pwr_mgt/IOPMLib.h>
31

32 33
#include "ntstatus.h"
#define WIN32_NO_STATUS
34
#include "macdrv.h"
35
#include "wine/server.h"
36 37

WINE_DEFAULT_DEBUG_CHANNEL(macdrv);
38

39 40 41 42 43 44
#ifndef kIOPMAssertionTypePreventUserIdleDisplaySleep
#define kIOPMAssertionTypePreventUserIdleDisplaySleep CFSTR("PreventUserIdleDisplaySleep")
#endif
#ifndef kCFCoreFoundationVersionNumber10_7
#define kCFCoreFoundationVersionNumber10_7      635.00
#endif
45

46 47 48
#define IS_OPTION_TRUE(ch) \
    ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')

49 50
C_ASSERT(NUM_EVENT_TYPES <= sizeof(macdrv_event_mask) * 8);

51
int topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONFULLSCREEN;
52
int capture_displays_for_fullscreen = 0;
53
BOOL skip_single_buffer_flushes = FALSE;
54
BOOL allow_vsync = TRUE;
55
BOOL allow_set_gamma = TRUE;
56 57
int left_option_is_alt = 0;
int right_option_is_alt = 0;
58 59
int left_command_is_ctrl = 0;
int right_command_is_ctrl = 0;
60
BOOL allow_software_rendering = FALSE;
61
BOOL disable_window_decorations = FALSE;
62
int allow_immovable_windows = TRUE;
63
int use_confinement_cursor_clipping = TRUE;
64
int cursor_clipping_locks_windows = TRUE;
65
int use_precise_scrolling = TRUE;
66
int gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
67
int retina_enabled = FALSE;
68
int enable_app_nap = FALSE;
69

70 71
CFDictionaryRef localized_strings;

72 73
NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,
                                             BOOLEAN,const LARGE_INTEGER*);
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
/**************************************************************************
 *              debugstr_cf
 */
const char* debugstr_cf(CFTypeRef t)
{
    CFStringRef s;
    const char* ret;

    if (!t) return "(null)";

    if (CFGetTypeID(t) == CFStringGetTypeID())
        s = t;
    else
        s = CFCopyDescription(t);
    ret = CFStringGetCStringPtr(s, kCFStringEncodingUTF8);
    if (ret) ret = debugstr_a(ret);
    if (!ret)
    {
        const UniChar* u = CFStringGetCharactersPtr(s);
        if (u)
            ret = debugstr_wn((const WCHAR*)u, CFStringGetLength(s));
    }
    if (!ret)
    {
        UniChar buf[200];
100
        int len = min(CFStringGetLength(s), ARRAY_SIZE(buf));
101 102 103 104 105 106 107 108
        CFStringGetCharacters(s, CFRangeMake(0, len), buf);
        ret = debugstr_wn(buf, len);
    }
    if (s != t) CFRelease(s);
    return ret;
}


109
HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len)
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
{
    UNICODE_STRING nameW = { name_len, name_len, (WCHAR *)name };
    OBJECT_ATTRIBUTES attr;
    HANDLE ret;

    attr.Length = sizeof(attr);
    attr.RootDirectory = root;
    attr.ObjectName = &nameW;
    attr.Attributes = 0;
    attr.SecurityDescriptor = NULL;
    attr.SecurityQualityOfService = NULL;

    return NtOpenKeyEx(&ret, MAXIMUM_ALLOWED, &attr, 0) ? 0 : ret;
}


126
HKEY open_hkcu_key(const char *name)
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
{
    WCHAR bufferW[256];
    static HKEY hkcu;

    if (!hkcu)
    {
        char buffer[256];
        DWORD_PTR sid_data[(sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE) / sizeof(DWORD_PTR)];
        DWORD i, len = sizeof(sid_data);
        SID *sid;

        if (NtQueryInformationToken(GetCurrentThreadEffectiveToken(), TokenUser, sid_data, len, &len))
            return 0;

        sid = ((TOKEN_USER *)sid_data)->User.Sid;
        len = sprintf(buffer, "\\Registry\\User\\S-%u-%u", sid->Revision,
                       MAKELONG(MAKEWORD(sid->IdentifierAuthority.Value[5],
                                         sid->IdentifierAuthority.Value[4]),
                                MAKEWORD(sid->IdentifierAuthority.Value[3],
                                         sid->IdentifierAuthority.Value[2])));
        for (i = 0; i < sid->SubAuthorityCount; i++)
            len += sprintf(buffer + len, "-%u", sid->SubAuthority[i]);

        ascii_to_unicode(bufferW, buffer, len);
        hkcu = reg_open_key(NULL, bufferW, len * sizeof(WCHAR));
    }

    return reg_open_key(hkcu, bufferW, asciiz_to_unicode(bufferW, name) - sizeof(WCHAR));
}


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
/* wrapper for NtCreateKey that creates the key recursively if necessary */
HKEY reg_create_key(HKEY root, const WCHAR *name, ULONG name_len,
                    DWORD options, DWORD *disposition)
{
    UNICODE_STRING nameW = { name_len, name_len, (WCHAR *)name };
    OBJECT_ATTRIBUTES attr;
    NTSTATUS status;
    HANDLE ret;

    attr.Length = sizeof(attr);
    attr.RootDirectory = root;
    attr.ObjectName = &nameW;
    attr.Attributes = 0;
    attr.SecurityDescriptor = NULL;
    attr.SecurityQualityOfService = NULL;

    status = NtCreateKey(&ret, MAXIMUM_ALLOWED, &attr, 0, NULL, options, disposition);
    if (status == STATUS_OBJECT_NAME_NOT_FOUND)
    {
        static const WCHAR registry_rootW[] = { '\\','R','e','g','i','s','t','r','y','\\' };
        DWORD pos = 0, i = 0, len = name_len / sizeof(WCHAR);

        /* don't try to create registry root */
        if (!root && len > ARRAY_SIZE(registry_rootW) &&
            !memcmp(name, registry_rootW, sizeof(registry_rootW)))
            i += ARRAY_SIZE(registry_rootW);

        while (i < len && name[i] != '\\') i++;
        if (i == len) return 0;
        for (;;)
        {
            unsigned int subkey_options = options;
            if (i < len) subkey_options &= ~(REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK);
            nameW.Buffer = (WCHAR *)name + pos;
            nameW.Length = (i - pos) * sizeof(WCHAR);
            status = NtCreateKey(&ret, MAXIMUM_ALLOWED, &attr, 0, NULL, subkey_options, disposition);

            if (attr.RootDirectory != root) NtClose(attr.RootDirectory);
            if (!NT_SUCCESS(status)) return 0;
            if (i == len) break;
            attr.RootDirectory = ret;
            while (i < len && name[i] == '\\') i++;
            pos = i;
            while (i < len && name[i] != '\\') i++;
        }
    }
    return ret;
}


HKEY reg_create_ascii_key(HKEY root, const char *name, DWORD options, DWORD *disposition)
{
    WCHAR buf[256];
    return reg_create_key(root, buf, asciiz_to_unicode(buf, name) - sizeof(WCHAR),
                          options, disposition);
}


BOOL reg_delete_tree(HKEY parent, const WCHAR *name, ULONG name_len)
{
    char buffer[4096];
    KEY_NODE_INFORMATION *key_info = (KEY_NODE_INFORMATION *)buffer;
    DWORD size;
    HKEY key;
    BOOL ret = TRUE;

    if (!(key = reg_open_key(parent, name, name_len))) return FALSE;

    while (ret && !NtEnumerateKey(key, 0, KeyNodeInformation, key_info, sizeof(buffer), &size))
        ret = reg_delete_tree(key, key_info->Name, key_info->NameLength);

    if (ret) ret = !NtDeleteKey(key);
    NtClose(key);
    return ret;
}


235
ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size)
236 237 238 239 240 241 242 243 244 245 246
{
    UNICODE_STRING str;

    RtlInitUnicodeString(&str, name);
    if (NtQueryValueKey(hkey, &str, KeyValuePartialInformation, info, size, &size))
        return 0;

    return size - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
}


247 248 249 250 251 252
/***********************************************************************
 *              get_config_key
 *
 * Get a config key from either the app-specific or the default config
 */
static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char *name,
253
                                   WCHAR *buffer, DWORD size)
254
{
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    WCHAR nameW[128];
    char buf[2048];
    KEY_VALUE_PARTIAL_INFORMATION *info = (void *)buf;

    asciiz_to_unicode(nameW, name);

    if (appkey && query_reg_value(appkey, nameW, info, sizeof(buf)))
    {
        size = min(info->DataLength, size - sizeof(WCHAR));
        memcpy(buffer, info->Data, size);
        buffer[size / sizeof(WCHAR)] = 0;
        return 0;
    }

    if (defkey && query_reg_value(defkey, nameW, info, sizeof(buf)))
    {
        size = min(info->DataLength, size - sizeof(WCHAR));
        memcpy(buffer, info->Data, size);
        buffer[size / sizeof(WCHAR)] = 0;
        return 0;
    }

277 278 279 280 281 282 283 284 285 286 287
    return ERROR_FILE_NOT_FOUND;
}


/***********************************************************************
 *              setup_options
 *
 * Set up the Mac driver options.
 */
static void setup_options(void)
{
288 289
    static const WCHAR macdriverW[] = {'\\','M','a','c',' ','D','r','i','v','e','r',0};
    WCHAR buffer[MAX_PATH + 16], *p, *appname;
290 291 292 293
    HKEY hkey, appkey = 0;
    DWORD len;

    /* @@ Wine registry key: HKCU\Software\Wine\Mac Driver */
294
    hkey = open_hkcu_key("Software\\Wine\\Mac Driver");
295 296 297

    /* open the app-specific key */

298 299 300 301 302
    appname = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
    if ((p = wcsrchr(appname, '/'))) appname = p + 1;
    if ((p = wcsrchr(appname, '\\'))) appname = p + 1;
    len = lstrlenW(appname);

303 304 305
    if (len && len < MAX_PATH)
    {
        HKEY tmpkey;
306 307
        memcpy(buffer, appname, len * sizeof(WCHAR));
        memcpy(buffer + len, macdriverW, sizeof(macdriverW));
308
        /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Mac Driver */
309
        if ((tmpkey = open_hkcu_key("Software\\Wine\\AppDefaults")))
310
        {
311 312
            appkey = reg_open_key(tmpkey, buffer, lstrlenW(buffer) * sizeof(WCHAR));
            NtClose(tmpkey);
313 314 315 316 317
        }
    }

    if (!get_config_key(hkey, appkey, "WindowsFloatWhenInactive", buffer, sizeof(buffer)))
    {
318 319
        static const WCHAR noneW[] = {'n','o','n','e',0};
        static const WCHAR allW[] = {'a','l','l',0};
320
        if (!wcscmp(buffer, noneW))
321
            topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONE;
322
        else if (!wcscmp(buffer, allW))
323 324 325 326 327
            topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_ALL;
        else
            topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONFULLSCREEN;
    }

328 329 330
    if (!get_config_key(hkey, appkey, "CaptureDisplaysForFullscreen", buffer, sizeof(buffer)))
        capture_displays_for_fullscreen = IS_OPTION_TRUE(buffer[0]);

331 332 333
    if (!get_config_key(hkey, appkey, "SkipSingleBufferFlushes", buffer, sizeof(buffer)))
        skip_single_buffer_flushes = IS_OPTION_TRUE(buffer[0]);

334 335 336
    if (!get_config_key(hkey, appkey, "AllowVerticalSync", buffer, sizeof(buffer)))
        allow_vsync = IS_OPTION_TRUE(buffer[0]);

337 338 339
    if (!get_config_key(hkey, appkey, "AllowSetGamma", buffer, sizeof(buffer)))
        allow_set_gamma = IS_OPTION_TRUE(buffer[0]);

340 341 342 343 344
    if (!get_config_key(hkey, appkey, "LeftOptionIsAlt", buffer, sizeof(buffer)))
        left_option_is_alt = IS_OPTION_TRUE(buffer[0]);
    if (!get_config_key(hkey, appkey, "RightOptionIsAlt", buffer, sizeof(buffer)))
        right_option_is_alt = IS_OPTION_TRUE(buffer[0]);

345 346 347 348 349 350 351 352 353 354
    if (!get_config_key(hkey, appkey, "LeftCommandIsCtrl", buffer, sizeof(buffer)))
        left_command_is_ctrl = IS_OPTION_TRUE(buffer[0]);
    if (!get_config_key(hkey, appkey, "RightCommandIsCtrl", buffer, sizeof(buffer)))
        right_command_is_ctrl = IS_OPTION_TRUE(buffer[0]);

    if (left_command_is_ctrl && right_command_is_ctrl && !left_option_is_alt && !right_option_is_alt)
        WARN("Both Command keys have been mapped to Control. There is no way to "
             "send an Alt key to Windows applications. Consider enabling "
             "LeftOptionIsAlt or RightOptionIsAlt.\n");

355 356 357
    if (!get_config_key(hkey, appkey, "AllowSoftwareRendering", buffer, sizeof(buffer)))
        allow_software_rendering = IS_OPTION_TRUE(buffer[0]);

358 359 360 361
    /* Value name chosen to match what's used in the X11 driver. */
    if (!get_config_key(hkey, appkey, "Decorated", buffer, sizeof(buffer)))
        disable_window_decorations = !IS_OPTION_TRUE(buffer[0]);

362 363 364
    if (!get_config_key(hkey, appkey, "AllowImmovableWindows", buffer, sizeof(buffer)))
        allow_immovable_windows = IS_OPTION_TRUE(buffer[0]);

365 366 367
    if (!get_config_key(hkey, appkey, "UseConfinementCursorClipping", buffer, sizeof(buffer)))
        use_confinement_cursor_clipping = IS_OPTION_TRUE(buffer[0]);

368 369 370
    if (!get_config_key(hkey, appkey, "CursorClippingLocksWindows", buffer, sizeof(buffer)))
        cursor_clipping_locks_windows = IS_OPTION_TRUE(buffer[0]);

371 372 373
    if (!get_config_key(hkey, appkey, "UsePreciseScrolling", buffer, sizeof(buffer)))
        use_precise_scrolling = IS_OPTION_TRUE(buffer[0]);

374 375
    if (!get_config_key(hkey, appkey, "OpenGLSurfaceMode", buffer, sizeof(buffer)))
    {
376 377
        static const WCHAR transparentW[] = {'t','r','a','n','s','p','a','r','e','n','t',0};
        static const WCHAR behindW[] = {'b','e','h','i','n','d',0};
378
        if (!wcscmp(buffer, transparentW))
379
            gl_surface_mode = GL_SURFACE_IN_FRONT_TRANSPARENT;
380
        else if (!wcscmp(buffer, behindW))
381 382 383 384 385
            gl_surface_mode = GL_SURFACE_BEHIND;
        else
            gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
    }

386 387 388
    if (!get_config_key(hkey, appkey, "EnableAppNap", buffer, sizeof(buffer)))
        enable_app_nap = IS_OPTION_TRUE(buffer[0]);

389 390 391 392 393
    /* Don't use appkey.  The DPI and monitor sizes should be consistent for all
       processes in the prefix. */
    if (!get_config_key(hkey, NULL, "RetinaMode", buffer, sizeof(buffer)))
        retina_enabled = IS_OPTION_TRUE(buffer[0]);

394 395
    if (appkey) NtClose(appkey);
    if (hkey) NtClose(hkey);
396 397 398
}


399 400 401
/***********************************************************************
 *              load_strings
 */
402
static void load_strings(struct localized_string *str)
403 404 405 406 407 408 409 410 411 412 413
{
    CFMutableDictionaryRef dict;

    dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
                                     &kCFTypeDictionaryValueCallBacks);
    if (!dict)
    {
        ERR("Failed to create localized strings dictionary\n");
        return;
    }

414
    while (str->id)
415
    {
416
        if (str->str && str->len)
417
        {
418 419
            CFNumberRef key = CFNumberCreate(NULL, kCFNumberIntType, &str->id);
            CFStringRef value = CFStringCreateWithCharacters(NULL, (UniChar*)str->str, str->len);
420 421 422
            if (key && value)
                CFDictionarySetValue(dict, key, value);
            else
423
                ERR("Failed to add string ID 0x%04x %s\n", str->id, debugstr_wn(str->str, str->len));
424 425
        }
        else
426 427
            ERR("Failed to load string ID 0x%04x\n", str->id);
        str++;
428 429 430 431 432 433
    }

    localized_strings = dict;
}


434 435 436
static NTSTATUS CDECL unix_call( enum macdrv_funcs code, void *params );


437
/***********************************************************************
438
 *              macdrv_init
439
 */
440
static NTSTATUS macdrv_init(void *arg)
441
{
442
    struct init_params *params = arg;
443 444 445 446 447
    SessionAttributeBits attributes;
    OSStatus status;

    status = SessionGetInfo(callerSecuritySession, NULL, &attributes);
    if (status != noErr || !(attributes & sessionHasGraphicAccess))
448
        return STATUS_UNSUCCESSFUL;
449

450
    init_win_context();
451
    setup_options();
452
    load_strings(params->strings);
453

454
    macdrv_err_on = ERR_ON(macdrv);
455
    if (macdrv_start_cocoa_app(NtGetTickCount()))
456 457
    {
        ERR("Failed to start Cocoa app main loop\n");
458
        return STATUS_UNSUCCESSFUL;
459 460
    }

461
    init_user_driver();
462
    macdrv_init_display_devices(FALSE);
463

464 465
    pNtWaitForMultipleObjects = params->pNtWaitForMultipleObjects;
    params->unix_call = unix_call;
466
    return STATUS_SUCCESS;
467 468 469 470
}


/***********************************************************************
471
 *              ThreadDetach   (MACDRV.@)
472
 */
473
void macdrv_ThreadDetach(void)
474 475 476 477 478 479
{
    struct macdrv_thread_data *data = macdrv_thread_data();

    if (data)
    {
        macdrv_destroy_event_queue(data->queue);
480 481
        if (data->keyboard_layout_uchr)
            CFRelease(data->keyboard_layout_uchr);
482
        free(data);
483
        /* clear data in case we get re-entered from user32 before the thread is truly dead */
484
        NtUserGetThreadInfo()->driver_data = 0;
485 486 487 488
    }
}


489
/***********************************************************************
490 491 492
 *              set_queue_display_fd
 *
 * Store the event queue fd into the message queue
493
 */
494 495 496 497 498 499 500 501
static void set_queue_display_fd(int fd)
{
    HANDLE handle;
    int ret;

    if (wine_server_fd_to_handle(fd, GENERIC_READ | SYNCHRONIZE, 0, &handle))
    {
        MESSAGE("macdrv: Can't allocate handle for event queue fd\n");
502
        NtTerminateProcess(0, 1);
503 504 505 506 507 508 509 510 511 512
    }
    SERVER_START_REQ(set_queue_fd)
    {
        req->handle = wine_server_obj_handle(handle);
        ret = wine_server_call(req);
    }
    SERVER_END_REQ;
    if (ret)
    {
        MESSAGE("macdrv: Can't store handle for event queue fd\n");
513
        NtTerminateProcess(0, 1);
514
    }
515
    NtClose(handle);
516 517 518 519 520 521 522 523 524
}


/***********************************************************************
 *              macdrv_init_thread_data
 */
struct macdrv_thread_data *macdrv_init_thread_data(void)
{
    struct macdrv_thread_data *data = macdrv_thread_data();
525
    TISInputSourceRef input_source;
526 527 528

    if (data) return data;

529
    if (!(data = calloc(1, sizeof(*data))))
530 531
    {
        ERR("could not create data\n");
532
        NtTerminateProcess(0, 1);
533 534
    }

535
    if (!(data->queue = macdrv_create_event_queue(macdrv_handle_event)))
536 537
    {
        ERR("macdrv: Can't create event queue.\n");
538
        NtTerminateProcess(0, 1);
539 540
    }

541 542 543
    macdrv_get_input_source_info(&data->keyboard_layout_uchr, &data->keyboard_type, &data->iso_keyboard, &input_source);
    data->active_keyboard_layout = macdrv_get_hkl_from_source(input_source);
    CFRelease(input_source);
544 545
    macdrv_compute_keyboard_layout(data);

546
    set_queue_display_fd(macdrv_get_event_queue_fd(data->queue));
547
    NtUserGetThreadInfo()->driver_data = data;
548

549
    NtUserActivateKeyboardLayout(data->active_keyboard_layout, 0);
550 551 552 553
    return data;
}


554 555 556
/***********************************************************************
 *              SystemParametersInfo (MACDRV.@)
 */
557
BOOL macdrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param, UINT flags )
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
{
    switch (action)
    {
    case SPI_GETSCREENSAVEACTIVE:
        if (ptr_param)
        {
            CFDictionaryRef assertionStates;
            IOReturn status = IOPMCopyAssertionsStatus(&assertionStates);
            if (status == kIOReturnSuccess)
            {
                CFNumberRef count = CFDictionaryGetValue(assertionStates, kIOPMAssertionTypeNoDisplaySleep);
                CFNumberRef count2 = CFDictionaryGetValue(assertionStates, kIOPMAssertionTypePreventUserIdleDisplaySleep);
                long longCount = 0, longCount2 = 0;

                if (count)
                    CFNumberGetValue(count, kCFNumberLongType, &longCount);
                if (count2)
                    CFNumberGetValue(count2, kCFNumberLongType, &longCount2);

                *(BOOL *)ptr_param = !longCount && !longCount2;
                CFRelease(assertionStates);
            }
            else
            {
                WARN("Could not determine screen saver state, error code %d\n", status);
                *(BOOL *)ptr_param = TRUE;
            }
            return TRUE;
        }
        break;

    case SPI_SETSCREENSAVEACTIVE:
        {
            static IOPMAssertionID powerAssertion = kIOPMNullAssertionID;
            if (int_param)
            {
                if (powerAssertion != kIOPMNullAssertionID)
                {
                    IOPMAssertionRelease(powerAssertion);
                    powerAssertion = kIOPMNullAssertionID;
                }
            }
            else if (powerAssertion == kIOPMNullAssertionID)
            {
                CFStringRef assertName;
                /*Are we running Lion or later?*/
                if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7)
                    assertName = kIOPMAssertionTypePreventUserIdleDisplaySleep;
                else
                    assertName = kIOPMAssertionTypeNoDisplaySleep;
                IOPMAssertionCreateWithName( assertName, kIOPMAssertionLevelOn,
                                             CFSTR("Wine Process requesting no screen saver"),
                                             &powerAssertion);
            }
        }
        break;
    }
    return FALSE;
}
617 618


619 620
NTSTATUS macdrv_client_func(enum macdrv_client_funcs id, const void *params, ULONG size)
{
621 622 623
    void *ret_ptr;
    ULONG ret_len;
    return KeUserModeCallback(id, params, size, &ret_ptr, &ret_len);
624 625 626
}


627 628 629 630 631 632 633
static NTSTATUS macdrv_ime_clear(void *arg)
{
    macdrv_clear_ime_text();
    return 0;
}


634 635 636 637 638 639
static NTSTATUS macdrv_ime_using_input_method(void *arg)
{
    return macdrv_using_input_method();
}


640 641 642 643 644 645 646 647
static NTSTATUS macdrv_quit_result(void *arg)
{
    struct quit_result_params *params = arg;
    macdrv_quit_reply(params->result);
    return 0;
}


648 649
const unixlib_entry_t __wine_unix_call_funcs[] =
{
650
    macdrv_dnd_get_data,
651 652 653 654
    macdrv_dnd_get_formats,
    macdrv_dnd_have_format,
    macdrv_dnd_release,
    macdrv_dnd_retain,
655
    macdrv_ime_clear,
656 657
    macdrv_ime_process_text_input,
    macdrv_ime_using_input_method,
658
    macdrv_init,
659
    macdrv_notify_icon,
660
    macdrv_quit_result,
661 662 663 664 665 666
};

C_ASSERT( ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count );


/* FIXME: Use __wine_unix_call instead */
667
static NTSTATUS CDECL unix_call(enum macdrv_funcs code, void *params)
668 669 670
{
    return __wine_unix_call_funcs[code]( params );
}