/*
 * eventHandler
 *  Callback handler for Xplugin events.
 */
static void eventHandler(unsigned int type, const void *arg,
                         unsigned int arg_size, void *data) {
    
    switch (type) {
        case XP_EVENT_DISPLAY_CHANGED:
            DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
            DarwinSendDDXEvent(kXquartzDisplayChanged, 0);
            break;
            
        case XP_EVENT_WINDOW_STATE_CHANGED:
            if (arg_size >= sizeof(xp_window_state_event)) {
                const xp_window_state_event *ws_arg = arg;
                
                DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
                DarwinSendDDXEvent(kXquartzWindowState, 2,
                                          ws_arg->id, ws_arg->state);
            } else {
                DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
            }
            break;
            
        case XP_EVENT_WINDOW_MOVED:
            DEBUG_LOG("XP_EVENT_WINDOW_MOVED\n");
            if (arg_size == sizeof(xp_window_id))  {
                xp_window_id id = * (xp_window_id *) arg;
                DarwinSendDDXEvent(kXquartzWindowMoved, 1, id);
            }
            break;
            
        case XP_EVENT_SURFACE_DESTROYED:
            DEBUG_LOG("XP_EVENT_SURFACE_DESTROYED\n");
        case XP_EVENT_SURFACE_CHANGED:
            DEBUG_LOG("XP_EVENT_SURFACE_CHANGED\n");
            if (arg_size == sizeof(xp_surface_id)) {
                int kind;
                
                if (type == XP_EVENT_SURFACE_DESTROYED)
                    kind = AppleDRISurfaceNotifyDestroyed;
                else
                    kind = AppleDRISurfaceNotifyChanged;
                
                DRISurfaceNotify(*(xp_surface_id *) arg, kind);
            }
            break;
#ifdef XP_EVENT_SPACE_CHANGED
        case  XP_EVENT_SPACE_CHANGED:
            DEBUG_LOG("XP_EVENT_SPACE_CHANGED\n");
            if(arg_size == sizeof(uint32_t)) {
                uint32_t space_id = *(uint32_t *)arg;
                DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id);
            }
            break;
#endif
        default:
            ErrorF("Unknown XP_EVENT type (%d) in xprScreen:eventHandler\n", type);
    }
}
Exemplo n.º 2
0
static void *
DarwinProcessFDAdditionQueue_thread(void *args)
{
    /* TODO: Possibly adjust this to no longer be a race... maybe trigger this
     *       once a client connects and claims to be the WM.
     *
     * From ajax:
     * There's already an internal callback chain for setting selection [in 1.5]
     * ownership.  See the CallSelectionCallback at the bottom of
     * ProcSetSelectionOwner, and xfixes/select.c for an example of how to hook
     * into it.
     */

    struct timespec sleep_for;
    struct timespec sleep_remaining;

    sleep_for.tv_sec = 3;
    sleep_for.tv_nsec = 0;

    ErrorF(
        "X11.app: DarwinProcessFDAdditionQueue_thread: Sleeping to allow xinitrc to catchup.\n");
    while (nanosleep(&sleep_for, &sleep_remaining) != 0) {
        sleep_for = sleep_remaining;
    }

    pthread_mutex_lock(&fd_add_lock);
    while (true) {
        while (fd_add_count) {
            DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1,
                               fd_add[--fd_add_count]);
        }
        pthread_cond_wait(&fd_add_ready_cond, &fd_add_lock);
    }

    return NULL;
}