mirror of
https://github.com/mpv-player/mpv
synced 2025-01-03 13:32:16 +00:00
Add a context for mp_fifo
Store data in an allocated context and take it as an argument instead of using static variables.
This commit is contained in:
parent
f59cda84b1
commit
77ec83e351
@ -3074,7 +3074,7 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
break;
|
||||
|
||||
case MP_CMD_KEYDOWN_EVENTS:
|
||||
mplayer_put_key(cmd->args[0].v.i);
|
||||
mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
|
||||
break;
|
||||
|
||||
case MP_CMD_SET_MOUSE_POS:{
|
||||
|
@ -293,7 +293,8 @@ void list_video_out(void)
|
||||
mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
|
||||
}
|
||||
|
||||
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11)
|
||||
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
|
||||
struct mp_fifo *key_fifo)
|
||||
{
|
||||
char **vo_list = opts->video_driver_list;
|
||||
int i;
|
||||
@ -316,7 +317,8 @@ struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11)
|
||||
const vo_info_t *info = video_driver->info;
|
||||
if (!strcmp(info->short_name, name)) {
|
||||
// name matches, try it
|
||||
*vo = (struct vo){.opts = opts, .x11 = x11};
|
||||
*vo = (struct vo){.opts = opts, .x11 = x11,
|
||||
.key_fifo = key_fifo};
|
||||
vo->driver = video_driver;
|
||||
if (!vo_preinit(vo, vo_subdevice)) {
|
||||
free(name);
|
||||
@ -334,7 +336,7 @@ struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11)
|
||||
vo_subdevice = NULL;
|
||||
for (i = 0; video_out_drivers[i]; i++) {
|
||||
const struct vo_driver *video_driver = video_out_drivers[i];
|
||||
*vo = (struct vo){.opts = opts, .x11 = x11};
|
||||
*vo = (struct vo){.opts = opts, .x11 = x11, key_fifo = key_fifo};
|
||||
vo->driver = video_driver;
|
||||
if (!vo_preinit(vo, vo_subdevice))
|
||||
return vo; // success!
|
||||
|
@ -213,6 +213,7 @@ struct vo {
|
||||
void *priv;
|
||||
struct MPOpts *opts;
|
||||
struct vo_x11_state *x11;
|
||||
struct mp_fifo *key_fifo;
|
||||
|
||||
// requested position/resolution
|
||||
int dx;
|
||||
@ -221,7 +222,8 @@ struct vo {
|
||||
int dheight;
|
||||
};
|
||||
|
||||
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11);
|
||||
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
|
||||
struct mp_fifo *key_fifo);
|
||||
int vo_config(struct vo *vo, uint32_t width, uint32_t height,
|
||||
uint32_t d_width, uint32_t d_height, uint32_t flags,
|
||||
char *title, uint32_t format);
|
||||
|
@ -718,8 +718,9 @@ static void uninit(struct vo *vo)
|
||||
|
||||
static int x11_fd_callback(void *ctx, int fd)
|
||||
{
|
||||
check_events(ctx);
|
||||
return mplayer_get_key(NULL, 0);
|
||||
struct vo *vo = ctx;
|
||||
check_events(vo);
|
||||
return mplayer_get_key(vo->key_fifo, 0);
|
||||
}
|
||||
|
||||
static int preinit(struct vo *vo, const char *arg)
|
||||
|
@ -537,27 +537,28 @@ void vo_uninit(struct vo_x11_state *x11)
|
||||
#include "wskeys.h"
|
||||
|
||||
#ifdef XF86XK_AudioPause
|
||||
static void vo_x11_putkey_ext(int keysym)
|
||||
static void vo_x11_putkey_ext(struct vo *vo, int keysym)
|
||||
{
|
||||
struct mp_fifo *f = vo->key_fifo;
|
||||
switch (keysym)
|
||||
{
|
||||
case XF86XK_AudioPause:
|
||||
mplayer_put_key(KEY_PAUSE);
|
||||
mplayer_put_key(f, KEY_PAUSE);
|
||||
break;
|
||||
case XF86XK_AudioStop:
|
||||
mplayer_put_key(KEY_STOP);
|
||||
mplayer_put_key(f, KEY_STOP);
|
||||
break;
|
||||
case XF86XK_AudioPrev:
|
||||
mplayer_put_key(KEY_PREV);
|
||||
mplayer_put_key(f, KEY_PREV);
|
||||
break;
|
||||
case XF86XK_AudioNext:
|
||||
mplayer_put_key(KEY_NEXT);
|
||||
mplayer_put_key(f, KEY_NEXT);
|
||||
break;
|
||||
case XF86XK_AudioLowerVolume:
|
||||
mplayer_put_key(KEY_VOLUME_DOWN);
|
||||
mplayer_put_key(f, KEY_VOLUME_DOWN);
|
||||
break;
|
||||
case XF86XK_AudioRaiseVolume:
|
||||
mplayer_put_key(KEY_VOLUME_UP);
|
||||
mplayer_put_key(f, KEY_VOLUME_UP);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -565,248 +566,249 @@ static void vo_x11_putkey_ext(int keysym)
|
||||
}
|
||||
#endif
|
||||
|
||||
void vo_x11_putkey(int key)
|
||||
void vo_x11_putkey(struct vo *vo, int key)
|
||||
{
|
||||
struct mp_fifo *f = vo->key_fifo;
|
||||
switch (key)
|
||||
{
|
||||
case wsLeft:
|
||||
mplayer_put_key(KEY_LEFT);
|
||||
mplayer_put_key(f, KEY_LEFT);
|
||||
break;
|
||||
case wsRight:
|
||||
mplayer_put_key(KEY_RIGHT);
|
||||
mplayer_put_key(f, KEY_RIGHT);
|
||||
break;
|
||||
case wsUp:
|
||||
mplayer_put_key(KEY_UP);
|
||||
mplayer_put_key(f, KEY_UP);
|
||||
break;
|
||||
case wsDown:
|
||||
mplayer_put_key(KEY_DOWN);
|
||||
mplayer_put_key(f, KEY_DOWN);
|
||||
break;
|
||||
case wsSpace:
|
||||
mplayer_put_key(' ');
|
||||
mplayer_put_key(f, ' ');
|
||||
break;
|
||||
case wsEscape:
|
||||
mplayer_put_key(KEY_ESC);
|
||||
mplayer_put_key(f, KEY_ESC);
|
||||
break;
|
||||
case wsTab:
|
||||
mplayer_put_key(KEY_TAB);
|
||||
mplayer_put_key(f, KEY_TAB);
|
||||
break;
|
||||
case wsEnter:
|
||||
mplayer_put_key(KEY_ENTER);
|
||||
mplayer_put_key(f, KEY_ENTER);
|
||||
break;
|
||||
case wsBackSpace:
|
||||
mplayer_put_key(KEY_BS);
|
||||
mplayer_put_key(f, KEY_BS);
|
||||
break;
|
||||
case wsDelete:
|
||||
mplayer_put_key(KEY_DELETE);
|
||||
mplayer_put_key(f, KEY_DELETE);
|
||||
break;
|
||||
case wsInsert:
|
||||
mplayer_put_key(KEY_INSERT);
|
||||
mplayer_put_key(f, KEY_INSERT);
|
||||
break;
|
||||
case wsHome:
|
||||
mplayer_put_key(KEY_HOME);
|
||||
mplayer_put_key(f, KEY_HOME);
|
||||
break;
|
||||
case wsEnd:
|
||||
mplayer_put_key(KEY_END);
|
||||
mplayer_put_key(f, KEY_END);
|
||||
break;
|
||||
case wsPageUp:
|
||||
mplayer_put_key(KEY_PAGE_UP);
|
||||
mplayer_put_key(f, KEY_PAGE_UP);
|
||||
break;
|
||||
case wsPageDown:
|
||||
mplayer_put_key(KEY_PAGE_DOWN);
|
||||
mplayer_put_key(f, KEY_PAGE_DOWN);
|
||||
break;
|
||||
case wsF1:
|
||||
mplayer_put_key(KEY_F + 1);
|
||||
mplayer_put_key(f, KEY_F + 1);
|
||||
break;
|
||||
case wsF2:
|
||||
mplayer_put_key(KEY_F + 2);
|
||||
mplayer_put_key(f, KEY_F + 2);
|
||||
break;
|
||||
case wsF3:
|
||||
mplayer_put_key(KEY_F + 3);
|
||||
mplayer_put_key(f, KEY_F + 3);
|
||||
break;
|
||||
case wsF4:
|
||||
mplayer_put_key(KEY_F + 4);
|
||||
mplayer_put_key(f, KEY_F + 4);
|
||||
break;
|
||||
case wsF5:
|
||||
mplayer_put_key(KEY_F + 5);
|
||||
mplayer_put_key(f, KEY_F + 5);
|
||||
break;
|
||||
case wsF6:
|
||||
mplayer_put_key(KEY_F + 6);
|
||||
mplayer_put_key(f, KEY_F + 6);
|
||||
break;
|
||||
case wsF7:
|
||||
mplayer_put_key(KEY_F + 7);
|
||||
mplayer_put_key(f, KEY_F + 7);
|
||||
break;
|
||||
case wsF8:
|
||||
mplayer_put_key(KEY_F + 8);
|
||||
mplayer_put_key(f, KEY_F + 8);
|
||||
break;
|
||||
case wsF9:
|
||||
mplayer_put_key(KEY_F + 9);
|
||||
mplayer_put_key(f, KEY_F + 9);
|
||||
break;
|
||||
case wsF10:
|
||||
mplayer_put_key(KEY_F + 10);
|
||||
mplayer_put_key(f, KEY_F + 10);
|
||||
break;
|
||||
case wsF11:
|
||||
mplayer_put_key(KEY_F + 11);
|
||||
mplayer_put_key(f, KEY_F + 11);
|
||||
break;
|
||||
case wsF12:
|
||||
mplayer_put_key(KEY_F + 12);
|
||||
mplayer_put_key(f, KEY_F + 12);
|
||||
break;
|
||||
case wsMinus:
|
||||
case wsGrayMinus:
|
||||
mplayer_put_key('-');
|
||||
mplayer_put_key(f, '-');
|
||||
break;
|
||||
case wsPlus:
|
||||
case wsGrayPlus:
|
||||
mplayer_put_key('+');
|
||||
mplayer_put_key(f, '+');
|
||||
break;
|
||||
case wsGrayMul:
|
||||
case wsMul:
|
||||
mplayer_put_key('*');
|
||||
mplayer_put_key(f, '*');
|
||||
break;
|
||||
case wsGrayDiv:
|
||||
case wsDiv:
|
||||
mplayer_put_key('/');
|
||||
mplayer_put_key(f, '/');
|
||||
break;
|
||||
case wsLess:
|
||||
mplayer_put_key('<');
|
||||
mplayer_put_key(f, '<');
|
||||
break;
|
||||
case wsMore:
|
||||
mplayer_put_key('>');
|
||||
mplayer_put_key(f, '>');
|
||||
break;
|
||||
case wsGray0:
|
||||
mplayer_put_key(KEY_KP0);
|
||||
mplayer_put_key(f, KEY_KP0);
|
||||
break;
|
||||
case wsGrayEnd:
|
||||
case wsGray1:
|
||||
mplayer_put_key(KEY_KP1);
|
||||
mplayer_put_key(f, KEY_KP1);
|
||||
break;
|
||||
case wsGrayDown:
|
||||
case wsGray2:
|
||||
mplayer_put_key(KEY_KP2);
|
||||
mplayer_put_key(f, KEY_KP2);
|
||||
break;
|
||||
case wsGrayPgDn:
|
||||
case wsGray3:
|
||||
mplayer_put_key(KEY_KP3);
|
||||
mplayer_put_key(f, KEY_KP3);
|
||||
break;
|
||||
case wsGrayLeft:
|
||||
case wsGray4:
|
||||
mplayer_put_key(KEY_KP4);
|
||||
mplayer_put_key(f, KEY_KP4);
|
||||
break;
|
||||
case wsGray5Dup:
|
||||
case wsGray5:
|
||||
mplayer_put_key(KEY_KP5);
|
||||
mplayer_put_key(f, KEY_KP5);
|
||||
break;
|
||||
case wsGrayRight:
|
||||
case wsGray6:
|
||||
mplayer_put_key(KEY_KP6);
|
||||
mplayer_put_key(f, KEY_KP6);
|
||||
break;
|
||||
case wsGrayHome:
|
||||
case wsGray7:
|
||||
mplayer_put_key(KEY_KP7);
|
||||
mplayer_put_key(f, KEY_KP7);
|
||||
break;
|
||||
case wsGrayUp:
|
||||
case wsGray8:
|
||||
mplayer_put_key(KEY_KP8);
|
||||
mplayer_put_key(f, KEY_KP8);
|
||||
break;
|
||||
case wsGrayPgUp:
|
||||
case wsGray9:
|
||||
mplayer_put_key(KEY_KP9);
|
||||
mplayer_put_key(f, KEY_KP9);
|
||||
break;
|
||||
case wsGrayDecimal:
|
||||
mplayer_put_key(KEY_KPDEC);
|
||||
mplayer_put_key(f, KEY_KPDEC);
|
||||
break;
|
||||
case wsGrayInsert:
|
||||
mplayer_put_key(KEY_KPINS);
|
||||
mplayer_put_key(f, KEY_KPINS);
|
||||
break;
|
||||
case wsGrayDelete:
|
||||
mplayer_put_key(KEY_KPDEL);
|
||||
mplayer_put_key(f, KEY_KPDEL);
|
||||
break;
|
||||
case wsGrayEnter:
|
||||
mplayer_put_key(KEY_KPENTER);
|
||||
mplayer_put_key(f, KEY_KPENTER);
|
||||
break;
|
||||
case wsGrave:
|
||||
mplayer_put_key('`');
|
||||
mplayer_put_key(f, '`');
|
||||
break;
|
||||
case wsTilde:
|
||||
mplayer_put_key('~');
|
||||
mplayer_put_key(f, '~');
|
||||
break;
|
||||
case wsExclSign:
|
||||
mplayer_put_key('!');
|
||||
mplayer_put_key(f, '!');
|
||||
break;
|
||||
case wsAt:
|
||||
mplayer_put_key('@');
|
||||
mplayer_put_key(f, '@');
|
||||
break;
|
||||
case wsHash:
|
||||
mplayer_put_key('#');
|
||||
mplayer_put_key(f, '#');
|
||||
break;
|
||||
case wsDollar:
|
||||
mplayer_put_key('$');
|
||||
mplayer_put_key(f, '$');
|
||||
break;
|
||||
case wsPercent:
|
||||
mplayer_put_key('%');
|
||||
mplayer_put_key(f, '%');
|
||||
break;
|
||||
case wsCircumflex:
|
||||
mplayer_put_key('^');
|
||||
mplayer_put_key(f, '^');
|
||||
break;
|
||||
case wsAmpersand:
|
||||
mplayer_put_key('&');
|
||||
mplayer_put_key(f, '&');
|
||||
break;
|
||||
case wsobracket:
|
||||
mplayer_put_key('(');
|
||||
mplayer_put_key(f, '(');
|
||||
break;
|
||||
case wscbracket:
|
||||
mplayer_put_key(')');
|
||||
mplayer_put_key(f, ')');
|
||||
break;
|
||||
case wsUnder:
|
||||
mplayer_put_key('_');
|
||||
mplayer_put_key(f, '_');
|
||||
break;
|
||||
case wsocbracket:
|
||||
mplayer_put_key('{');
|
||||
mplayer_put_key(f, '{');
|
||||
break;
|
||||
case wsccbracket:
|
||||
mplayer_put_key('}');
|
||||
mplayer_put_key(f, '}');
|
||||
break;
|
||||
case wsColon:
|
||||
mplayer_put_key(':');
|
||||
mplayer_put_key(f, ':');
|
||||
break;
|
||||
case wsSemicolon:
|
||||
mplayer_put_key(';');
|
||||
mplayer_put_key(f, ';');
|
||||
break;
|
||||
case wsDblQuote:
|
||||
mplayer_put_key('\"');
|
||||
mplayer_put_key(f, '\"');
|
||||
break;
|
||||
case wsAcute:
|
||||
mplayer_put_key('\'');
|
||||
mplayer_put_key(f, '\'');
|
||||
break;
|
||||
case wsComma:
|
||||
mplayer_put_key(',');
|
||||
mplayer_put_key(f, ',');
|
||||
break;
|
||||
case wsPoint:
|
||||
mplayer_put_key('.');
|
||||
mplayer_put_key(f, '.');
|
||||
break;
|
||||
case wsQuestSign:
|
||||
mplayer_put_key('?');
|
||||
mplayer_put_key(f, '?');
|
||||
break;
|
||||
case wsBSlash:
|
||||
mplayer_put_key('\\');
|
||||
mplayer_put_key(f, '\\');
|
||||
break;
|
||||
case wsPipe:
|
||||
mplayer_put_key('|');
|
||||
mplayer_put_key(f, '|');
|
||||
break;
|
||||
case wsEqual:
|
||||
mplayer_put_key('=');
|
||||
mplayer_put_key(f, '=');
|
||||
break;
|
||||
case wsosbrackets:
|
||||
mplayer_put_key('[');
|
||||
mplayer_put_key(f, '[');
|
||||
break;
|
||||
case wscsbrackets:
|
||||
mplayer_put_key(']');
|
||||
mplayer_put_key(f, ']');
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') ||
|
||||
(key >= '0' && key <= '9'))
|
||||
mplayer_put_key(key);
|
||||
mplayer_put_key(f, key);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1045,12 +1047,12 @@ int vo_x11_check_events(struct vo *vo)
|
||||
XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
|
||||
&x11->compose_status);
|
||||
#ifdef XF86XK_AudioPause
|
||||
vo_x11_putkey_ext(keySym);
|
||||
vo_x11_putkey_ext(vo, keySym);
|
||||
#endif
|
||||
key =
|
||||
((keySym & 0xff00) !=
|
||||
0 ? ((keySym & 0x00ff) + 256) : (keySym));
|
||||
vo_x11_putkey(key);
|
||||
vo_x11_putkey(vo, key);
|
||||
ret |= VO_EVENT_KEYPRESS;
|
||||
}
|
||||
break;
|
||||
@ -1082,8 +1084,9 @@ int vo_x11_check_events(struct vo *vo)
|
||||
&& (Event.xbutton.button <= 3))
|
||||
break;
|
||||
#endif
|
||||
mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button -
|
||||
1) | MP_KEY_DOWN);
|
||||
mplayer_put_key(vo->key_fifo,
|
||||
(MOUSE_BTN0 + Event.xbutton.button - 1)
|
||||
| MP_KEY_DOWN);
|
||||
break;
|
||||
case ButtonRelease:
|
||||
if (x11->vo_mouse_autohide)
|
||||
@ -1098,7 +1101,8 @@ int vo_x11_check_events(struct vo *vo)
|
||||
&& (Event.xbutton.button <= 3))
|
||||
break;
|
||||
#endif
|
||||
mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1);
|
||||
mplayer_put_key(vo->key_fifo,
|
||||
MOUSE_BTN0 + Event.xbutton.button - 1);
|
||||
break;
|
||||
case PropertyNotify:
|
||||
{
|
||||
@ -1121,7 +1125,7 @@ int vo_x11_check_events(struct vo *vo)
|
||||
case ClientMessage:
|
||||
if (Event.xclient.message_type == x11->XAWM_PROTOCOLS &&
|
||||
Event.xclient.data.l[0] == x11->XAWM_DELETE_WINDOW)
|
||||
mplayer_put_key(KEY_CLOSE_WIN);
|
||||
mplayer_put_key(vo->key_fifo, KEY_CLOSE_WIN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ void xv_setup_colorkeyhandling(struct vo *vo, const char *ck_method_str, const c
|
||||
int xv_test_ck( void * arg );
|
||||
int xv_test_ckm( void * arg );
|
||||
|
||||
extern void vo_x11_putkey(int key);
|
||||
void vo_x11_putkey(struct vo *vo, int key);
|
||||
|
||||
#ifdef HAVE_XF86VM
|
||||
void vo_vm_switch(struct vo *vo, uint32_t, uint32_t, int*, int*);
|
||||
|
@ -225,7 +225,8 @@ int mp_input_check_interrupt(int time) {
|
||||
return 0;
|
||||
}
|
||||
// Needed by getch2
|
||||
void mplayer_put_key(int code)
|
||||
struct mp_fifo;
|
||||
void mplayer_put_key(struct mp_fifo *fifo, int code)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ typedef struct MPContext {
|
||||
struct MPOpts opts;
|
||||
struct m_config *mconfig;
|
||||
struct vo_x11_state *x11_state;
|
||||
struct mp_fifo *key_fifo;
|
||||
int osd_show_percentage;
|
||||
int osd_function;
|
||||
const ao_functions_t *audio_out;
|
||||
|
89
mp_fifo.c
89
mp_fifo.c
@ -3,70 +3,81 @@
|
||||
#include "input/input.h"
|
||||
#include "input/mouse.h"
|
||||
#include "mp_fifo.h"
|
||||
#include "talloc.h"
|
||||
|
||||
|
||||
int key_fifo_size = 7;
|
||||
static int *key_fifo_data = NULL;
|
||||
static int key_fifo_read=0;
|
||||
static int key_fifo_write=0;
|
||||
struct mp_fifo {
|
||||
int *data;
|
||||
int readpos;
|
||||
int writepos;
|
||||
int size;
|
||||
unsigned last_key_time[2];
|
||||
int last_key[2];
|
||||
};
|
||||
|
||||
static void mplayer_put_key_internal(int code){
|
||||
int fifo_free = key_fifo_read - key_fifo_write - 1;
|
||||
if (fifo_free < 0) fifo_free += key_fifo_size;
|
||||
// printf("mplayer_put_key(%d)\n",code);
|
||||
if (key_fifo_data == NULL)
|
||||
key_fifo_data = malloc(key_fifo_size * sizeof(int));
|
||||
if(!fifo_free) return; // FIFO FULL!!
|
||||
struct mp_fifo *mp_fifo_create(void)
|
||||
{
|
||||
struct mp_fifo *fifo = talloc_zero(NULL, struct mp_fifo);
|
||||
fifo->size = key_fifo_size;
|
||||
fifo->data = talloc_array_ptrtype(fifo, fifo->data, fifo->size);
|
||||
return fifo;
|
||||
}
|
||||
|
||||
static void mplayer_put_key_internal(struct mp_fifo *fifo, int code)
|
||||
{
|
||||
int fifo_free = fifo->readpos - fifo->writepos - 1;
|
||||
if (fifo_free < 0)
|
||||
fifo_free += fifo->size;
|
||||
if (!fifo_free)
|
||||
return; // FIFO FULL!!
|
||||
// reserve some space for key release events to avoid stuck keys
|
||||
if((code & MP_KEY_DOWN) && fifo_free < (key_fifo_size >> 1))
|
||||
if((code & MP_KEY_DOWN) && fifo_free < (fifo->size >> 1))
|
||||
return;
|
||||
key_fifo_data[key_fifo_write]=code;
|
||||
key_fifo_write=(key_fifo_write+1)%key_fifo_size;
|
||||
fifo->data[fifo->writepos++] = code;
|
||||
fifo->writepos %= fifo->size;
|
||||
}
|
||||
|
||||
int mplayer_get_key(void *ctx, int fd)
|
||||
{
|
||||
int key;
|
||||
// printf("mplayer_get_key(%d)\n",fd);
|
||||
if (key_fifo_data == NULL)
|
||||
struct mp_fifo *fifo = ctx;
|
||||
if (fifo->writepos == fifo->readpos)
|
||||
return MP_INPUT_NOTHING;
|
||||
if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
|
||||
key=key_fifo_data[key_fifo_read];
|
||||
key_fifo_read=(key_fifo_read+1)%key_fifo_size;
|
||||
// printf("mplayer_get_key => %d\n",key);
|
||||
int key = fifo->data[fifo->readpos++];
|
||||
fifo->readpos %= fifo->size;
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
unsigned doubleclick_time = 300;
|
||||
|
||||
static void put_double(int code) {
|
||||
static void put_double(struct mp_fifo *fifo, int code)
|
||||
{
|
||||
if (code >= MOUSE_BTN0 && code <= MOUSE_BTN9)
|
||||
mplayer_put_key_internal(code - MOUSE_BTN0 + MOUSE_BTN0_DBL);
|
||||
mplayer_put_key_internal(fifo, code - MOUSE_BTN0 + MOUSE_BTN0_DBL);
|
||||
}
|
||||
|
||||
void mplayer_put_key(int code) {
|
||||
static unsigned last_key_time[2];
|
||||
static int last_key[2];
|
||||
void mplayer_put_key(struct mp_fifo *fifo, int code)
|
||||
{
|
||||
unsigned now = GetTimerMS();
|
||||
// ignore system-doubleclick if we generate these events ourselves
|
||||
if (doubleclick_time &&
|
||||
(code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL &&
|
||||
(code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL)
|
||||
if (doubleclick_time
|
||||
&& (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL
|
||||
&& (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL)
|
||||
return;
|
||||
mplayer_put_key_internal(code);
|
||||
mplayer_put_key_internal(fifo, code);
|
||||
if (code & MP_KEY_DOWN) {
|
||||
code &= ~MP_KEY_DOWN;
|
||||
last_key[1] = last_key[0];
|
||||
last_key[0] = code;
|
||||
last_key_time[1] = last_key_time[0];
|
||||
last_key_time[0] = now;
|
||||
if (last_key[1] == code &&
|
||||
now - last_key_time[1] < doubleclick_time)
|
||||
put_double(code);
|
||||
fifo->last_key[1] = fifo->last_key[0];
|
||||
fifo->last_key[0] = code;
|
||||
fifo->last_key_time[1] = fifo->last_key_time[0];
|
||||
fifo->last_key_time[0] = now;
|
||||
if (fifo->last_key[1] == code
|
||||
&& now - fifo->last_key_time[1] < doubleclick_time)
|
||||
put_double(fifo, code);
|
||||
return;
|
||||
}
|
||||
if (last_key[0] == code && last_key[1] == code &&
|
||||
now - last_key_time[1] < doubleclick_time)
|
||||
put_double(code);
|
||||
if (fifo->last_key[0] == code && fifo->last_key[1] == code
|
||||
&& now - fifo->last_key_time[1] < doubleclick_time)
|
||||
put_double(fifo, code);
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
#ifndef MPLAYER_MP_FIFO_H
|
||||
#define MPLAYER_MP_FIFO_H
|
||||
|
||||
struct mp_fifo;
|
||||
int mplayer_get_key(void *ctx, int fd);
|
||||
void mplayer_put_key(int code);
|
||||
void mplayer_put_key(struct mp_fifo *fifo, int code);
|
||||
// Can be freed with talloc_free()
|
||||
struct mp_fifo *mp_fifo_create(void);
|
||||
|
||||
#ifdef IS_OLD_VO
|
||||
#define mplayer_put_key(key) mplayer_put_key(global_vo->key_fifo, key)
|
||||
#endif
|
||||
|
||||
#endif /* MPLAYER_MP_FIFO_H */
|
||||
|
12
mplayer.c
12
mplayer.c
@ -691,6 +691,7 @@ void exit_player_with_rc(struct MPContext *mpctx, const char* how, int rc){
|
||||
if(mpctx->playtree)
|
||||
play_tree_free(mpctx->playtree, 1);
|
||||
|
||||
talloc_free(mpctx->key_fifo);
|
||||
|
||||
if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
|
||||
if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how);
|
||||
@ -2143,7 +2144,7 @@ int reinit_video_chain(struct MPContext *mpctx)
|
||||
|
||||
//shouldn't we set dvideo->id=-2 when we fail?
|
||||
//if((mpctx->video_out->preinit(vo_subdevice))!=0){
|
||||
if(!(mpctx->video_out=init_best_video_out(opts, mpctx->x11_state))){
|
||||
if(!(mpctx->video_out=init_best_video_out(opts, mpctx->x11_state, mpctx->key_fifo))){
|
||||
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
|
||||
goto err_out;
|
||||
}
|
||||
@ -2536,8 +2537,8 @@ static int seek(MPContext *mpctx, double amount, int style)
|
||||
|
||||
static int read_keys(void *ctx, int fd)
|
||||
{
|
||||
getch2();
|
||||
return mplayer_get_key(NULL, 0);
|
||||
getch2(ctx);
|
||||
return mplayer_get_key(ctx, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -2633,6 +2634,7 @@ int gui_no_filename=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
mpctx->key_fifo = mp_fifo_create();
|
||||
|
||||
#if defined(WIN32) && defined(HAVE_NEW_GUI)
|
||||
void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
|
||||
@ -2875,11 +2877,11 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){
|
||||
// Init input system
|
||||
current_module = "init_input";
|
||||
mp_input_init(use_gui);
|
||||
mp_input_add_key_fd(-1,0,mplayer_get_key,NULL, NULL);
|
||||
mp_input_add_key_fd(-1,0,mplayer_get_key,NULL, mpctx->key_fifo);
|
||||
if(slave_mode)
|
||||
mp_input_add_cmd_fd(0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL);
|
||||
else if(!noconsolecontrols)
|
||||
mp_input_add_key_fd(0, 1, read_keys, NULL, NULL);
|
||||
mp_input_add_key_fd(0, 1, read_keys, NULL, mpctx->key_fifo);
|
||||
// Set the libstream interrupt callback
|
||||
stream_set_interrupt_callback(mp_input_check_interrupt);
|
||||
|
||||
|
@ -164,13 +164,13 @@ static int getch2_internal( void )
|
||||
return -1;
|
||||
}
|
||||
|
||||
void getch2( void )
|
||||
void getch2(struct mp_fifo *fifo)
|
||||
{
|
||||
int key;
|
||||
|
||||
key = getch2_internal();
|
||||
if( key != -1 )
|
||||
mplayer_put_key( key );
|
||||
mplayer_put_key(fifo, key);
|
||||
}
|
||||
|
||||
void getch2_enable( void )
|
||||
|
@ -121,11 +121,11 @@ static int getch2_internal(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void getch2(void)
|
||||
void getch2(struct mp_fifo *fifo)
|
||||
{
|
||||
int r = getch2_internal();
|
||||
if (r >= 0)
|
||||
mplayer_put_key(r);
|
||||
mplayer_put_key(fifo, r);
|
||||
}
|
||||
|
||||
void getch2_enable(){
|
||||
|
@ -135,7 +135,7 @@ void get_screen_size(void){
|
||||
#endif
|
||||
}
|
||||
|
||||
void getch2(void)
|
||||
void getch2(struct mp_fifo *fifo)
|
||||
{
|
||||
int retval = read(0, &getch2_buf[getch2_len], BUF_LEN-getch2_len);
|
||||
if (retval < 1)
|
||||
@ -244,7 +244,7 @@ void getch2(void)
|
||||
getch2_len -= len;
|
||||
for (i = 0; i < getch2_len; i++)
|
||||
getch2_buf[i] = getch2_buf[len+i];
|
||||
mplayer_put_key(code);
|
||||
mplayer_put_key(fifo, code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@ extern void getch2_enable(void);
|
||||
extern void getch2_disable(void);
|
||||
|
||||
/* Read a character or a special key code (see keycodes.h) */
|
||||
extern void getch2(void);
|
||||
struct mp_fifo;
|
||||
extern void getch2(struct mp_fifo *fifo);
|
||||
|
||||
/* slave cmd function for Windows and OS/2 */
|
||||
extern int mp_input_slave_cmd_func(int fd,char* dest,int size);
|
||||
|
Loading…
Reference in New Issue
Block a user