cocoa_common: split window creation into helper functions
[mplayer.git] / mp_fifo.c
blob701b7a0bc3b3d81e3ced1b37363360130b954b54
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <assert.h>
21 #include <stdbool.h>
22 #include "osdep/timer.h"
23 #include "input/input.h"
24 #include "input/keycodes.h"
25 #include "mp_fifo.h"
26 #include "talloc.h"
27 #include "options.h"
30 struct mp_fifo {
31 struct MPOpts *opts;
32 struct input_ctx *input;
33 int last_key_down;
34 unsigned last_down_time;
37 struct mp_fifo *mp_fifo_create(struct input_ctx *input, struct MPOpts *opts)
39 struct mp_fifo *fifo = talloc_zero(NULL, struct mp_fifo);
40 fifo->input = input;
41 fifo->opts = opts;
42 return fifo;
45 static void put_double(struct mp_fifo *fifo, int code)
47 if (code >= MOUSE_BTN0 && code < MOUSE_BTN_END)
48 mp_input_feed_key(fifo->input, code - MOUSE_BTN0 + MOUSE_BTN0_DBL);
51 void mplayer_put_key(struct mp_fifo *fifo, int code)
53 unsigned now = GetTimerMS();
54 int doubleclick_time = fifo->opts->doubleclick_time;
55 // ignore system-doubleclick if we generate these events ourselves
56 if (doubleclick_time
57 && (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL
58 && (code & ~MP_KEY_DOWN) < MOUSE_BTN_DBL_END)
59 return;
60 mp_input_feed_key(fifo->input, code);
61 if (code & MP_KEY_DOWN) {
62 code &= ~MP_KEY_DOWN;
63 if (fifo->last_key_down == code
64 && now - fifo->last_down_time < doubleclick_time)
65 put_double(fifo, code);
66 fifo->last_key_down = code;
67 fifo->last_down_time = now;
71 void mplayer_put_key_utf8(struct mp_fifo *fifo, int mods, struct bstr t)
73 while (t.len) {
74 int code = bstr_decode_utf8(t, &t);
75 if (code < 0)
76 break;
77 mplayer_put_key(fifo, code | mods);