event.h 5.36 KB
Newer Older
1 2 3 4 5 6 7 8
/*****************************************************************************
 * event.h: vout event
 *****************************************************************************
 * Copyright (C) 2009 Laurent Aimar
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
9 10 11
 * This program 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
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *****************************************************************************/

#include <vlc_common.h>
#include <math.h>

#include "vout_control.h"

/* TODO/FIXME
 *
 * It should be converted to something like input_thread_t:
 * one intf-event can be grabbed by a callback, all others
 * variable only var_Change
 *
 * Maybe a intf-mouse can be used too (don't like it).
 *
 * (Some case may infinite loop otherwise here)
 */

static inline void vout_SendEventClose(vout_thread_t *vout)
{
42 43 44
#warning FIXME: implement video close event
    /* FIXME: this code is disabled as it breaks the non-playlist cases */
    //playlist_Stop(pl_Get(vout));
45
    (void) vout;
46 47 48
}
static inline void vout_SendEventKey(vout_thread_t *vout, int key)
{
49
    var_SetInteger(vout->obj.libvlc, "key-pressed", key);
50 51 52
}
static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
{
53
    var_SetCoords(vout, "mouse-moved", x, y);
54
}
55 56 57 58 59 60 61 62
static inline void vout_SendEventViewpointMoved(vout_thread_t *vout,
                                                const vlc_viewpoint_t *p_viewpoint)
{
    var_SetAddress(vout, "viewpoint-moved", (void *) p_viewpoint);
    /* This variable can only be read from callbacks */
    var_Change(vout, "viewpoint-moved", VLC_VAR_SETVALUE,
               &(vlc_value_t) { .p_address = NULL }, NULL);
}
63 64
static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
{
65
    int key = KEY_UNSET;
66
    var_OrInteger(vout, "mouse-button-down", 1 << button);
67

68 69 70
    switch (button)
    {
    case MOUSE_BUTTON_LEFT:
71 72 73 74 75
    {
        /* FIXME? */
        int x, y;
        var_GetCoords(vout, "mouse-moved", &x, &y);
        var_SetCoords(vout, "mouse-clicked", x, y);
76
        var_SetBool(vout->obj.libvlc, "intf-popupmenu", false);
77
        return;
78
    }
79
    case MOUSE_BUTTON_CENTER:
80
        var_ToggleBool(vout->obj.libvlc, "intf-toggle-fscontrol");
81
        return;
82
    case MOUSE_BUTTON_RIGHT:
83
#if !defined(_WIN32)
84
        var_SetBool(vout->obj.libvlc, "intf-popupmenu", true);
85
#endif
86 87 88 89 90
        return;
    case MOUSE_BUTTON_WHEEL_UP:    key = KEY_MOUSEWHEELUP;    break;
    case MOUSE_BUTTON_WHEEL_DOWN:  key = KEY_MOUSEWHEELDOWN;  break;
    case MOUSE_BUTTON_WHEEL_LEFT:  key = KEY_MOUSEWHEELLEFT;  break;
    case MOUSE_BUTTON_WHEEL_RIGHT: key = KEY_MOUSEWHEELRIGHT; break;
91
    }
92
    vout_SendEventKey(vout, key);
93 94 95
}
static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
{
96
    var_NAndInteger(vout, "mouse-button-down", 1 << button);
97 98 99 100 101 102 103 104
#if defined(_WIN32)
    switch (button)
    {
    case MOUSE_BUTTON_RIGHT:
        var_SetBool(vout->obj.libvlc, "intf-popupmenu", true);
        return;
    }
#endif
105 106 107 108
}
static inline void vout_SendEventMouseDoubleClick(vout_thread_t *vout)
{
    //vout_ControlSetFullscreen(vout, !var_GetBool(vout, "fullscreen"));
109
    var_ToggleBool(vout, "fullscreen");
110
}
111 112 113 114 115
static inline void vout_SendEventViewpointChangeable(vout_thread_t *vout,
                                                     bool b_can_change)
{
    var_SetBool(vout, "viewpoint-changeable", b_can_change);
}
116 117 118 119

#if 0
static inline void vout_SendEventSnapshot(vout_thread_t *vout, const char *filename)
{
120
    /* signal creation of a new snapshot file */
121
    var_SetString(vout->obj.libvlc, "snapshot-file", filename);
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
}

#warning "FIXME clean up postproc event"

extern void vout_InstallDeprecatedPostProcessing(vout_thread_t *);
extern void vout_UninstallDeprecatedPostProcessing(vout_thread_t *);

static inline void vout_SendEventPostProcessing(vout_thread_t *vout, bool is_available)
{
    if (is_available)
        vout_InstallDeprecatedPostProcessing(vout);
    else
        vout_UninstallDeprecatedPostProcessing(vout);
}

static inline void vout_SendEventFilters(vout_thread_t *vout)
{
    vout_filter_t **filter;
    int           filter_count;

    vout_ControlGetFilters(vout, &filter, &filter_count);

    char *list = strdup("");
    for (int i = 0; i < filter_count; i++) {
        char *psz;

        if (asprintf(&psz, "%s%s%s",
                     list, i > 0 ? ":" : "", filter[i]->name) < 0) {
            free(list);
            list = NULL;
            break;
        }
        free(list);
        list = psz;
    }

    if (list) {
        vlc_value_t val;
        val.psz_string = list;
        var_Change(vout, "video-filter", VLC_VAR_SETVALUE, &val, NULL);
        free(list);
    }

    for (int i = 0; i < filter_count; i++)
        vout_filter_Delete(filter[i]);
    free(filter);
}
#endif