summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-16 23:24:56 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:44:19 +0200
commitc76c65441adbd4301c7f4f86ff906d7b30c5c3d1 (patch)
treeb1b09ce78749080ee493f05c9de0b0bda9aa8542 /video
parent3c8f8b7714331746233e288206b247366257cb99 (diff)
downloadmpv-c76c65441adbd4301c7f4f86ff906d7b30c5c3d1.tar.bz2
mpv-c76c65441adbd4301c7f4f86ff906d7b30c5c3d1.tar.xz
x11: remove cursor hiding logic, use VOCTRL_SET_CURSOR_VISIBILITY
Diffstat (limited to 'video')
-rw-r--r--video/out/x11_common.c78
-rw-r--r--video/out/x11_common.h3
2 files changed, 33 insertions, 48 deletions
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index b171605e2d..571bc9032c 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -177,34 +177,39 @@ static void vo_x11_ewmh_fullscreen(struct vo_x11_state *x11, int action)
}
}
-static void vo_hidecursor(struct vo *vo, Display *disp, Window win)
+static void vo_set_cursor_hidden(struct vo *vo, bool cursor_hidden)
{
Cursor no_ptr;
Pixmap bm_no;
XColor black, dummy;
Colormap colormap;
const char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
+ struct vo_x11_state *x11 = vo->x11;
+ Display *disp = x11->display;
+ Window win = x11->window;
- if (vo->opts->WinID == 0)
- return; // do not hide if playing on the root window
+ if (cursor_hidden == x11->mouse_cursor_hidden)
+ return;
- colormap = DefaultColormap(disp, DefaultScreen(disp));
- if (!XAllocNamedColor(disp, colormap, "black", &black, &dummy))
- return; // color alloc failed, give up
- bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8);
- no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0);
- XDefineCursor(disp, win, no_ptr);
- XFreeCursor(disp, no_ptr);
- if (bm_no != None)
- XFreePixmap(disp, bm_no);
- XFreeColors(disp, colormap, &black.pixel, 1, 0);
-}
+ x11->mouse_cursor_hidden = cursor_hidden;
-static void vo_showcursor(struct vo *vo, Display *disp, Window win)
-{
- if (vo->opts->WinID == 0)
- return;
- XDefineCursor(disp, win, 0);
+ if (vo->opts->WinID == 0 || win == 0)
+ return; // do not hide if playing on the root window
+
+ if (x11->mouse_cursor_hidden) {
+ colormap = DefaultColormap(disp, DefaultScreen(disp));
+ if (!XAllocNamedColor(disp, colormap, "black", &black, &dummy))
+ return; // color alloc failed, give up
+ bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8);
+ no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0);
+ XDefineCursor(disp, win, no_ptr);
+ XFreeCursor(disp, no_ptr);
+ if (bm_no != None)
+ XFreePixmap(disp, bm_no);
+ XFreeColors(disp, colormap, &black.pixel, 1, 0);
+ } else {
+ XDefineCursor(x11->display, x11->window, 0);
+ }
}
static int x11_errorhandler(Display *display, XErrorEvent *event)
@@ -641,7 +646,7 @@ void vo_x11_uninit(struct vo *vo)
saver_on(x11);
if (x11->window != None)
- vo_showcursor(vo, x11->display, x11->window);
+ vo_set_cursor_hidden(vo, false);
if (x11->f_gc != None)
XFreeGC(vo->x11->display, x11->f_gc);
@@ -675,20 +680,6 @@ void vo_x11_uninit(struct vo *vo)
vo->x11 = NULL;
}
-static void vo_x11_unhide_cursor(struct vo *vo)
-{
- struct vo_x11_state *x11 = vo->x11;
- struct mp_vo_opts *opts = vo->opts;
-
- if (opts->cursor_autohide_delay > -2) {
- vo_showcursor(vo, x11->display, x11->window);
- if (opts->cursor_autohide_delay >= 0) {
- x11->mouse_waiting_hide = 1;
- x11->mouse_timer = GetTimerMS() + opts->cursor_autohide_delay;
- }
- }
-}
-
static void update_vo_size(struct vo *vo)
{
struct vo_x11_state *x11 = vo->x11;
@@ -706,11 +697,6 @@ int vo_x11_check_events(struct vo *vo)
Display *display = vo->x11->display;
XEvent Event;
- if (x11->mouse_waiting_hide && GetTimerMS() >= x11->mouse_timer) {
- vo_hidecursor(vo, display, x11->window);
- x11->mouse_waiting_hide = 0;
- }
-
xscreensaver_heartbeat(vo->x11);
if (vo->opts->WinID > 0)
@@ -772,16 +758,13 @@ int vo_x11_check_events(struct vo *vo)
}
case MotionNotify:
vo_mouse_movement(vo, Event.xmotion.x, Event.xmotion.y);
- vo_x11_unhide_cursor(vo);
break;
case ButtonPress:
- vo_x11_unhide_cursor(vo);
mplayer_put_key(vo->key_fifo,
(MP_MOUSE_BTN0 + Event.xbutton.button - 1)
| MP_KEY_STATE_DOWN);
break;
case ButtonRelease:
- vo_x11_unhide_cursor(vo);
mplayer_put_key(vo->key_fifo,
MP_MOUSE_BTN0 + Event.xbutton.button - 1);
break;
@@ -815,9 +798,6 @@ int vo_x11_check_events(struct vo *vo)
}
}
- if (x11->mouse_waiting_hide)
- vo->next_wakeup_time = FFMIN(vo->next_wakeup_time, x11->mouse_timer);
-
update_vo_size(vo);
if (vo->opts->WinID >= 0 && (x11->pending_vo_events & VO_EVENT_RESIZE)) {
int x = x11->win_x, y = x11->win_y;
@@ -984,7 +964,10 @@ static void vo_x11_create_window(struct vo *vo, XVisualInfo *vis, int x, int y,
x11->vo_gc = XCreateGC(x11->display, x11->window, 0, NULL);
XSetForeground(x11->display, x11->f_gc, 0);
- vo_hidecursor(vo, x11->display, x11->window);
+ if (x11->mouse_cursor_hidden) {
+ x11->mouse_cursor_hidden = false;
+ vo_set_cursor_hidden(vo, true);
+ }
x11->xic = XCreateIC(x11->xim,
XNInputStyle, XIMPreeditNone | XIMStatusNone,
XNClientWindow, x11->window,
@@ -1406,6 +1389,9 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
case VOCTRL_UPDATE_SCREENINFO:
vo_x11_update_screeninfo(vo);
return VO_TRUE;
+ case VOCTRL_SET_CURSOR_VISIBILITY:
+ vo_set_cursor_hidden(vo, !(*(bool *)arg));
+ return VO_TRUE;
}
return VO_NOTIMPL;
}
diff --git a/video/out/x11_common.h b/video/out/x11_common.h
index ec41f56b4f..8717c225e2 100644
--- a/video/out/x11_common.h
+++ b/video/out/x11_common.h
@@ -57,8 +57,7 @@ struct vo_x11_state {
int fs_layer;
XSizeHints vo_hint;
- unsigned int mouse_timer;
- int mouse_waiting_hide;
+ bool mouse_cursor_hidden;
int orig_layer;
int old_gravity;