Beispiel #1
0
/* ctk_event_emit_string() - Emits signal(s) on a registered ctk_event object.
 * This function is primarily used to simulate NV-CONTROL events such
 * that various parts of nvidia-settings can communicate (internally)
 */
void ctk_event_emit_string(CtkEvent *ctk_event,
                    unsigned int mask, int attrib)
{
    CtkEventStruct event;
    CtkEventSource *source;
    Display *dpy = NvCtrlGetDisplayPtr(ctk_event->handle);


    if (attrib > NV_CTRL_STRING_LAST_ATTRIBUTE) return;


    /* Find the event source */
    source = event_sources;
    while (source) {
        if (source->dpy == dpy) {
            break;
        }
        source = source->next;
    }
    if (!source) return;


    /* Broadcast event to all relevant ctk_event objects */

    event.attribute = attrib;
    event.value = 0;
    event.display_mask = mask;

    CTK_EVENT_BROADCAST(source,
                        string_signals[attrib],
                        &event,
                        NvCtrlGetTargetType(ctk_event->handle),
                        NvCtrlGetTargetId(ctk_event->handle));

} /* ctk_event_emit_string() */
Beispiel #2
0
/* ctk_event_emit() - Emits signal(s) on a registered ctk_event object.
 * This function is primarily used to simulate NV-CONTROL events such
 * that various parts of nvidia-settings can communicate (internally)
 */
void ctk_event_emit(CtkEvent *ctk_event,
                    unsigned int mask,
                    int attrib,
                    int value)
{
    CtrlEvent event;
    CtkEventSource *source;
    CtrlTarget *ctrl_target = ctk_event->ctrl_target;
    NvCtrlEventHandle *event_handle = NvCtrlGetEventHandle(ctrl_target);


    if (attrib > NV_CTRL_LAST_ATTRIBUTE) return;


    /* Find the event source */
    source = event_sources;
    while (source) {
        if (source->event_handle == event_handle) {
            break;
        }
        source = source->next;
    }
    if (!source) return;


    /* Broadcast event to all relevant ctk_event objects */
    memset(&event, 0, sizeof(CtrlEvent));

    event.type        = CTRL_EVENT_TYPE_INTEGER_ATTRIBUTE;
    event.target_type = NvCtrlGetTargetType(ctrl_target);
    event.target_id   = NvCtrlGetTargetId(ctrl_target);

    event.int_attr.attribute = attrib;
    event.int_attr.value     = value;

    CTK_EVENT_BROADCAST(source, signals[attrib], &event);

} /* ctk_event_emit() */
Beispiel #3
0
static gboolean ctk_event_dispatch(GSource *source,
                                   GSourceFunc callback, gpointer user_data)
{
    XEvent event;
    CtkEventSource *event_source = (CtkEventSource *) source;
    CtkEventStruct event_struct;

    memset(&event_struct, 0, sizeof(event_struct));

    /*
     * if ctk_event_dispatch() is called, then either
     * ctk_event_prepare() or ctk_event_check() returned TRUE, so we
     * know there is an event pending
     */
    
    XNextEvent(event_source->dpy, &event);

    /* 
     * Handle the ATTRIBUTE_CHANGED_EVENT NV-CONTROL event
     */

    if (event_source->event_base != -1 &&
        (event.type == (event_source->event_base + ATTRIBUTE_CHANGED_EVENT))) {

        XNVCtrlAttributeChangedEvent *nvctrlevent =
            (XNVCtrlAttributeChangedEvent *) &event;

        /* make sure the attribute is in our signal array */

        if ((nvctrlevent->attribute <= NV_CTRL_LAST_ATTRIBUTE) &&
            (signals[nvctrlevent->attribute] != 0)) {
            
            event_struct.attribute    = nvctrlevent->attribute;
            event_struct.value        = nvctrlevent->value;
            event_struct.display_mask = nvctrlevent->display_mask;

            /*
             * XXX Is emitting a signal with g_signal_emit() really
             * the "correct" way of dispatching the event?
             */

            CTK_EVENT_BROADCAST(event_source,
                                signals[nvctrlevent->attribute],
                                &event_struct,
                                NV_CTRL_TARGET_TYPE_X_SCREEN,
                                nvctrlevent->screen);
        }

    /* 
     * Handle the TARGET_ATTRIBUTE_CHANGED_EVENT NV-CONTROL event
     */

    } else if (event_source->event_base != -1 &&
               (event.type == (event_source->event_base
                               +TARGET_ATTRIBUTE_CHANGED_EVENT))) {

        XNVCtrlAttributeChangedEventTarget *nvctrlevent =
            (XNVCtrlAttributeChangedEventTarget *) &event;

        /* make sure the attribute is in our signal array */

        if ((nvctrlevent->attribute <= NV_CTRL_LAST_ATTRIBUTE) &&
            (signals[nvctrlevent->attribute] != 0)) {
            
            event_struct.attribute    = nvctrlevent->attribute;
            event_struct.value        = nvctrlevent->value;
            event_struct.display_mask = nvctrlevent->display_mask;

            /*
             * XXX Is emitting a signal with g_signal_emit() really
             * the "correct" way of dispatching the event?
             */

            CTK_EVENT_BROADCAST(event_source,
                                signals[nvctrlevent->attribute],
                                &event_struct,
                                nvctrlevent->target_type,
                                nvctrlevent->target_id);
        }

        /*
         * Handle the TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT
         * NV-CONTROL event.
         */

    } else if (event_source->event_base != -1 &&
               (event.type == (event_source->event_base
                               + TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT))) {

        XNVCtrlAttributeChangedEventTargetAvailability *nvctrlevent =
            (XNVCtrlAttributeChangedEventTargetAvailability *) &event;

        /* make sure the attribute is in our signal array */

        if ((nvctrlevent->attribute <= NV_CTRL_LAST_ATTRIBUTE) &&
            (signals[nvctrlevent->attribute] != 0)) {
            
            event_struct.attribute    = nvctrlevent->attribute;
            event_struct.value        = nvctrlevent->value;
            event_struct.display_mask = nvctrlevent->display_mask;
            event_struct.is_availability_changed = TRUE;
            event_struct.availability = nvctrlevent->availability;

            /*
             * XXX Is emitting a signal with g_signal_emit() really
             * the "correct" way of dispatching the event?
             */

            CTK_EVENT_BROADCAST(event_source,
                                signals[nvctrlevent->attribute],
                                &event_struct,
                                nvctrlevent->target_type,
                                nvctrlevent->target_id);
        }
        /*
         * Handle the TARGET_STRING_ATTRIBUTE_CHANGED_EVENT
         * NV-CONTROL event.
         */
    } else if (event_source->event_base != -1 &&
               (event.type == (event_source->event_base
                               + TARGET_STRING_ATTRIBUTE_CHANGED_EVENT))) {
        XNVCtrlStringAttributeChangedEventTarget *nvctrlevent =
            (XNVCtrlStringAttributeChangedEventTarget *) &event;

        /* make sure the attribute is in our signal array */
        
        if ((nvctrlevent->attribute <= NV_CTRL_STRING_LAST_ATTRIBUTE) &&
            (string_signals[nvctrlevent->attribute] != 0)) {

            event_struct.attribute    = nvctrlevent->attribute;
            event_struct.value        = 0;
            event_struct.display_mask = nvctrlevent->display_mask;
            /*
             * XXX Is emitting a signal with g_signal_emit() really
             * the "correct" way of dispatching the event
             */

            CTK_EVENT_BROADCAST(event_source,
                                string_signals[nvctrlevent->attribute],
                                &event_struct,
                                nvctrlevent->target_type,
                                nvctrlevent->target_id);
        }
         /*
          * Handle the TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT
          * NV-CONTROL event.
          */
    } else if (event_source->event_base != -1 &&
               (event.type == (event_source->event_base
                               + TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT))) {
        XNVCtrlBinaryAttributeChangedEventTarget *nvctrlevent =
            (XNVCtrlBinaryAttributeChangedEventTarget *) &event;

        /* make sure the attribute is in our signal array */
        if ((nvctrlevent->attribute <= NV_CTRL_BINARY_DATA_LAST_ATTRIBUTE) &&
            (binary_signals[nvctrlevent->attribute] != 0)) {

            event_struct.attribute    = nvctrlevent->attribute;
            event_struct.value        = 0;
            event_struct.display_mask = nvctrlevent->display_mask;
            /*
             * XXX Is emitting a signal with g_signal_emit() really
             * the "correct" way of dispatching the event
             */

            CTK_EVENT_BROADCAST(event_source,
                                binary_signals[nvctrlevent->attribute],
                                &event_struct,
                                nvctrlevent->target_type,
                                nvctrlevent->target_id);
        }


        /*
         * Also handle XRandR events.
         */

    } else if (event_source->randr_event_base != -1 &&
               (event.type ==
                (event_source->randr_event_base + RRScreenChangeNotify))) {
        
        XRRScreenChangeNotifyEvent *xrandrevent =
            (XRRScreenChangeNotifyEvent *)&event;
        int screen;
        
        /* Find the screen the window belongs to */
        screen = get_screen_of_root(xrandrevent->display, xrandrevent->root);
        if (screen >= 0) {
            CTK_EVENT_BROADCAST(event_source,
                                signal_RRScreenChangeNotify,
                                &event,
                                NV_CTRL_TARGET_TYPE_X_SCREEN,
                                screen);
        }

    /*
     * Trap events that get registered but are not handled
     * properly.
     */

    } else {
        nv_warning_msg("Unknown event type %d.", event.type);
    }
    
    return TRUE;

} /* ctk_event_dispatch() */
Beispiel #4
0
static gboolean ctk_event_dispatch(GSource *source,
                                   GSourceFunc callback,
                                   gpointer user_data)
{
    ReturnStatus status;
    CtrlEvent event;
    CtkEventSource *event_source = (CtkEventSource *) source;

    /*
     * if ctk_event_dispatch() is called, then either
     * ctk_event_prepare() or ctk_event_check() returned TRUE, so we
     * know there is an event pending
     */
    status = NvCtrlEventHandleNextEvent(event_source->event_handle, &event);
    if (status != NvCtrlSuccess) {
        return FALSE;
    }

    if (event.type != CTRL_EVENT_TYPE_UNKNOWN) {

        /* 
         * Handle the CTRL_EVENT_TYPE_INTEGER_ATTRIBUTE event
         */
        if (event.type == CTRL_EVENT_TYPE_INTEGER_ATTRIBUTE) {

            /* make sure the attribute is in our signal array */
            if ((event.int_attr.attribute <= NV_CTRL_LAST_ATTRIBUTE) &&
                (signals[event.int_attr.attribute] != 0)) {

                /*
                 * XXX Is emitting a signal with g_signal_emit() really
                 * the "correct" way of dispatching the event?
                 */
                CTK_EVENT_BROADCAST(event_source,
                                    signals[event.int_attr.attribute],
                                    &event);
            }
        }
        
        /* 
         * Handle the CTRL_EVENT_TYPE_STRING_ATTRIBUTE event
         */
        else if (event.type == CTRL_EVENT_TYPE_STRING_ATTRIBUTE) {

            /* make sure the attribute is in our string signal array */

            if ((event.str_attr.attribute <= NV_CTRL_STRING_LAST_ATTRIBUTE) &&
                (string_signals[event.str_attr.attribute] != 0)) {

                /*
                 * XXX Is emitting a signal with g_signal_emit() really
                 * the "correct" way of dispatching the event
                 */
                CTK_EVENT_BROADCAST(event_source,
                                    string_signals[event.str_attr.attribute],
                                    &event);
            }
        }

        /*
         * Handle the CTRL_EVENT_TYPE_BINARY_ATTRIBUTE event
         */
        else if (event.type == CTRL_EVENT_TYPE_BINARY_ATTRIBUTE) {

            /* make sure the attribute is in our binary signal array */
            if ((event.bin_attr.attribute <= NV_CTRL_BINARY_DATA_LAST_ATTRIBUTE) &&
                (binary_signals[event.bin_attr.attribute] != 0)) {

                /*
                 * XXX Is emitting a signal with g_signal_emit() really
                 * the "correct" way of dispatching the event
                 */
                CTK_EVENT_BROADCAST(event_source,
                                    binary_signals[event.bin_attr.attribute],
                                    &event);
            }
        }

        /*
         * Handle the CTRL_EVENT_TYPE_SCREEN_CHANGE event
         */
        else if (event.type == CTRL_EVENT_TYPE_SCREEN_CHANGE) {

            /* make sure the target_id is valid */
            if (event.target_id >= 0) {
                CTK_EVENT_BROADCAST(event_source,
                                    signal_RRScreenChangeNotify,
                                    &event);
            }
        }
    }
    
    return TRUE;

} /* ctk_event_dispatch() */