mirror of
https://github.com/mpv-player/mpv
synced 2025-01-03 13:32:16 +00:00
x11_common: use private variables for window state
Store the window state (position and size) in vo_x11_state, instead of in vo->dx/dy/dwidth/dheight. The VO variables are overwritten by vo.c on every vo_config() call, which is extremely not helpful. Now vo->dx/dy are mostly unused (except for passing the position forced by the --geometry option), and vo->dwidth/dheight are set for the VO, and otherwise read for resize detection only. In the long term, the way vo_config() handles the --geometry option should be changed, and vo->dx/dy should be removed. Remove some useless stuff: VO_EVENT_MOVE and VO_EVENT_KEYPRESS were generated, but unused. Wayland changes by Alexander Preisinger.
This commit is contained in:
parent
152a2024cf
commit
1b09f46338
@ -31,8 +31,6 @@
|
|||||||
|
|
||||||
#define VO_EVENT_EXPOSE 1
|
#define VO_EVENT_EXPOSE 1
|
||||||
#define VO_EVENT_RESIZE 2
|
#define VO_EVENT_RESIZE 2
|
||||||
#define VO_EVENT_KEYPRESS 4
|
|
||||||
#define VO_EVENT_MOVE 16
|
|
||||||
|
|
||||||
enum mp_voctrl {
|
enum mp_voctrl {
|
||||||
/* signal a device reset seek */
|
/* signal a device reset seek */
|
||||||
|
@ -131,7 +131,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
w32->event_flags |= VO_EVENT_EXPOSE;
|
w32->event_flags |= VO_EVENT_EXPOSE;
|
||||||
break;
|
break;
|
||||||
case WM_MOVE: {
|
case WM_MOVE: {
|
||||||
w32->event_flags |= VO_EVENT_MOVE;
|
|
||||||
POINT p = {0};
|
POINT p = {0};
|
||||||
ClientToScreen(w32->window, &p);
|
ClientToScreen(w32->window, &p);
|
||||||
w32->window_x = p.x;
|
w32->window_x = p.x;
|
||||||
@ -295,7 +294,6 @@ int vo_w32_check_events(struct vo *vo)
|
|||||||
ClientToScreen(w32->window, &p);
|
ClientToScreen(w32->window, &p);
|
||||||
if (p.x != w32->window_x || p.y != w32->window_y) {
|
if (p.x != w32->window_x || p.y != w32->window_y) {
|
||||||
w32->window_x = p.x; w32->window_y = p.y;
|
w32->window_x = p.x; w32->window_y = p.y;
|
||||||
w32->event_flags |= VO_EVENT_MOVE;
|
|
||||||
}
|
}
|
||||||
res = GetClientRect(WIN_ID_TO_HWND(WinID), &r);
|
res = GetClientRect(WIN_ID_TO_HWND(WinID), &r);
|
||||||
if (res && (r.right != vo->dwidth || r.bottom != vo->dheight))
|
if (res && (r.right != vo->dwidth || r.bottom != vo->dheight))
|
||||||
|
@ -319,7 +319,6 @@ static void keyboard_handle_key(void *data,
|
|||||||
int mpkey = lookupkey(sym);
|
int mpkey = lookupkey(sym);
|
||||||
if (mpkey)
|
if (mpkey)
|
||||||
mplayer_put_key(wl->vo->key_fifo, mpkey);
|
mplayer_put_key(wl->vo->key_fifo, mpkey);
|
||||||
input->events |= VO_EVENT_KEYPRESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED && key == input->repeat.key) {
|
if (state == WL_KEYBOARD_KEY_STATE_RELEASED && key == input->repeat.key) {
|
||||||
@ -952,7 +951,6 @@ int vo_wayland_check_events (struct vo *vo)
|
|||||||
int i, ret, count;
|
int i, ret, count;
|
||||||
struct epoll_event ep[16];
|
struct epoll_event ep[16];
|
||||||
|
|
||||||
wl->input->events = 0;
|
|
||||||
wl_display_dispatch_pending(wl->display->display);
|
wl_display_dispatch_pending(wl->display->display);
|
||||||
|
|
||||||
ret = wl_display_flush(wl->display->display);
|
ret = wl_display_flush(wl->display->display);
|
||||||
@ -975,10 +973,8 @@ int vo_wayland_check_events (struct vo *vo)
|
|||||||
task->run(task, ep[i].events, wl);
|
task->run(task, ep[i].events, wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = wl->input->events;
|
ret = wl->window->events;
|
||||||
ret |= wl->window->events;
|
|
||||||
|
|
||||||
wl->input->events = 0;
|
|
||||||
wl->window->events = 0;
|
wl->window->events = 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -121,7 +121,6 @@ struct vo_wayland_input {
|
|||||||
} xkb;
|
} xkb;
|
||||||
|
|
||||||
int modifiers;
|
int modifiers;
|
||||||
int events;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t sym;
|
uint32_t sym;
|
||||||
|
@ -373,26 +373,27 @@ static void init_atoms(struct vo_x11_state *x11)
|
|||||||
void vo_x11_update_screeninfo(struct vo *vo)
|
void vo_x11_update_screeninfo(struct vo *vo)
|
||||||
{
|
{
|
||||||
struct MPOpts *opts = vo->opts;
|
struct MPOpts *opts = vo->opts;
|
||||||
|
struct vo_x11_state *x11 = vo->x11;
|
||||||
bool all_screens = vo_fs && opts->vo_fsscreen_id == -2;
|
bool all_screens = vo_fs && opts->vo_fsscreen_id == -2;
|
||||||
xinerama_x = xinerama_y = 0;
|
xinerama_x = xinerama_y = 0;
|
||||||
if (all_screens) {
|
if (all_screens) {
|
||||||
opts->vo_screenwidth = vo->x11->ws_width;
|
opts->vo_screenwidth = x11->ws_width;
|
||||||
opts->vo_screenheight = vo->x11->ws_height;
|
opts->vo_screenheight = x11->ws_height;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_XINERAMA
|
#ifdef CONFIG_XINERAMA
|
||||||
if (opts->vo_screen_id >= -1 && XineramaIsActive(vo->x11->display) &&
|
if (opts->vo_screen_id >= -1 && XineramaIsActive(x11->display) &&
|
||||||
!all_screens)
|
!all_screens)
|
||||||
{
|
{
|
||||||
int screen = vo_fs ? opts->vo_fsscreen_id : opts->vo_screen_id;
|
int screen = vo_fs ? opts->vo_fsscreen_id : opts->vo_screen_id;
|
||||||
XineramaScreenInfo *screens;
|
XineramaScreenInfo *screens;
|
||||||
int num_screens;
|
int num_screens;
|
||||||
|
|
||||||
screens = XineramaQueryScreens(vo->x11->display, &num_screens);
|
screens = XineramaQueryScreens(x11->display, &num_screens);
|
||||||
if (screen >= num_screens)
|
if (screen >= num_screens)
|
||||||
screen = num_screens - 1;
|
screen = num_screens - 1;
|
||||||
if (screen == -1) {
|
if (screen == -1) {
|
||||||
int x = vo->dx + vo->dwidth / 2;
|
int x = x11->win_x + x11->win_width / 2;
|
||||||
int y = vo->dy + vo->dheight / 2;
|
int y = x11->win_y + x11->win_height / 2;
|
||||||
for (screen = num_screens - 1; screen > 0; screen--) {
|
for (screen = num_screens - 1; screen > 0; screen--) {
|
||||||
int left = screens[screen].x_org;
|
int left = screens[screen].x_org;
|
||||||
int right = left + screens[screen].width;
|
int right = left + screens[screen].width;
|
||||||
@ -662,17 +663,15 @@ void vo_x11_uninit(struct vo *vo)
|
|||||||
vo->x11 = NULL;
|
vo->x11 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_resize(struct vo *vo)
|
static void update_vo_size(struct vo *vo)
|
||||||
{
|
{
|
||||||
int old_w = vo->dwidth, old_h = vo->dheight;
|
struct vo_x11_state *x11 = vo->x11;
|
||||||
int old_x = vo->dx, old_y = vo->dy;
|
|
||||||
int rc = 0;
|
if (x11->win_width != vo->dwidth || x11->win_height != vo->dheight) {
|
||||||
vo_x11_update_geometry(vo, true);
|
vo->dwidth = x11->win_width;
|
||||||
if (vo->dwidth != old_w || vo->dheight != old_h)
|
vo->dheight = x11->win_height;
|
||||||
rc |= VO_EVENT_RESIZE;
|
x11->pending_vo_events |= VO_EVENT_RESIZE;
|
||||||
if (vo->dx != old_x || vo->dy != old_y)
|
}
|
||||||
rc |= VO_EVENT_MOVE;
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int vo_x11_check_events(struct vo *vo)
|
int vo_x11_check_events(struct vo *vo)
|
||||||
@ -680,7 +679,6 @@ int vo_x11_check_events(struct vo *vo)
|
|||||||
struct vo_x11_state *x11 = vo->x11;
|
struct vo_x11_state *x11 = vo->x11;
|
||||||
struct MPOpts *opts = vo->opts;
|
struct MPOpts *opts = vo->opts;
|
||||||
Display *display = vo->x11->display;
|
Display *display = vo->x11->display;
|
||||||
int ret = 0;
|
|
||||||
XEvent Event;
|
XEvent Event;
|
||||||
|
|
||||||
if (x11->mouse_waiting_hide && opts->cursor_autohide_delay != -1 &&
|
if (x11->mouse_waiting_hide && opts->cursor_autohide_delay != -1 &&
|
||||||
@ -693,18 +691,18 @@ int vo_x11_check_events(struct vo *vo)
|
|||||||
xscreensaver_heartbeat(vo->x11);
|
xscreensaver_heartbeat(vo->x11);
|
||||||
|
|
||||||
if (WinID > 0)
|
if (WinID > 0)
|
||||||
ret |= check_resize(vo);
|
vo_x11_update_geometry(vo, true);
|
||||||
while (XPending(display)) {
|
while (XPending(display)) {
|
||||||
XNextEvent(display, &Event);
|
XNextEvent(display, &Event);
|
||||||
// printf("\rEvent.type=%X \n",Event.type);
|
// printf("\rEvent.type=%X \n",Event.type);
|
||||||
switch (Event.type) {
|
switch (Event.type) {
|
||||||
case Expose:
|
case Expose:
|
||||||
ret |= VO_EVENT_EXPOSE;
|
x11->pending_vo_events |= VO_EVENT_EXPOSE;
|
||||||
break;
|
break;
|
||||||
case ConfigureNotify:
|
case ConfigureNotify:
|
||||||
if (x11->window == None)
|
if (x11->window == None)
|
||||||
break;
|
break;
|
||||||
ret |= check_resize(vo);
|
vo_x11_update_geometry(vo, true);
|
||||||
break;
|
break;
|
||||||
case KeyPress: {
|
case KeyPress: {
|
||||||
char buf[100];
|
char buf[100];
|
||||||
@ -736,7 +734,6 @@ int vo_x11_check_events(struct vo *vo)
|
|||||||
if (mpkey)
|
if (mpkey)
|
||||||
mplayer_put_key(vo->key_fifo, mpkey | modifiers);
|
mplayer_put_key(vo->key_fifo, mpkey | modifiers);
|
||||||
}
|
}
|
||||||
ret |= VO_EVENT_KEYPRESS;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
@ -796,11 +793,14 @@ int vo_x11_check_events(struct vo *vo)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (WinID >= 0 && (ret & (VO_EVENT_MOVE | VO_EVENT_RESIZE))) {
|
update_vo_size(vo);
|
||||||
int x = vo->dx, y = vo->dy;
|
if (WinID >= 0 && (x11->pending_vo_events & VO_EVENT_RESIZE)) {
|
||||||
unsigned int w = vo->dwidth, h = vo->dheight;
|
int x = x11->win_x, y = x11->win_y;
|
||||||
|
unsigned int w = x11->win_width, h = x11->win_height;
|
||||||
XMoveResizeWindow(x11->display, x11->window, x, y, w, h);
|
XMoveResizeWindow(x11->display, x11->window, x, y, w, h);
|
||||||
}
|
}
|
||||||
|
int ret = x11->pending_vo_events;
|
||||||
|
x11->pending_vo_events = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,8 +867,9 @@ static void vo_x11_nofs_sizepos(struct vo *vo, int x, int y,
|
|||||||
x11->vo_old_width = width;
|
x11->vo_old_width = width;
|
||||||
x11->vo_old_height = height;
|
x11->vo_old_height = height;
|
||||||
} else {
|
} else {
|
||||||
vo->dwidth = width;
|
x11->win_width = width;
|
||||||
vo->dheight = height;
|
x11->win_height = height;
|
||||||
|
update_vo_size(vo);
|
||||||
if (vo->opts->force_window_position) {
|
if (vo->opts->force_window_position) {
|
||||||
XMoveResizeWindow(vo->x11->display, vo->x11->window, x, y, width,
|
XMoveResizeWindow(vo->x11->display, vo->x11->window, x, y, width,
|
||||||
height);
|
height);
|
||||||
@ -1006,13 +1007,11 @@ void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y,
|
|||||||
if (WinID >= 0) {
|
if (WinID >= 0) {
|
||||||
XSelectInput(mDisplay, WinID, StructureNotifyMask);
|
XSelectInput(mDisplay, WinID, StructureNotifyMask);
|
||||||
vo_x11_update_geometry(vo, true);
|
vo_x11_update_geometry(vo, true);
|
||||||
x = vo->dx; y = vo->dy;
|
x = x11->win_x; y = x11->win_y;
|
||||||
width = vo->dwidth; height = vo->dheight;
|
width = x11->win_width; height = x11->win_height;
|
||||||
}
|
}
|
||||||
if (x11->window == None) {
|
if (x11->window == None) {
|
||||||
vo_fs = 0;
|
vo_fs = 0;
|
||||||
vo->dwidth = width;
|
|
||||||
vo->dheight = height;
|
|
||||||
x11->window = vo_x11_create_smooth_window(x11, vis, x, y, width, height);
|
x11->window = vo_x11_create_smooth_window(x11, vis, x, y, width, height);
|
||||||
x11->window_state = VOFLAG_HIDDEN;
|
x11->window_state = VOFLAG_HIDDEN;
|
||||||
}
|
}
|
||||||
@ -1052,14 +1051,14 @@ void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y,
|
|||||||
if (opts->vo_ontop)
|
if (opts->vo_ontop)
|
||||||
vo_x11_setlayer(vo, x11->window, opts->vo_ontop);
|
vo_x11_setlayer(vo, x11->window, opts->vo_ontop);
|
||||||
vo_x11_update_geometry(vo, !force_change_xy);
|
vo_x11_update_geometry(vo, !force_change_xy);
|
||||||
vo_x11_nofs_sizepos(vo, vo->dx, vo->dy, width, height);
|
vo_x11_nofs_sizepos(vo, x11->win_x, x11->win_y, width, height);
|
||||||
if (!!vo_fs != !!(flags & VOFLAG_FULLSCREEN)) {
|
if (!!vo_fs != !!(flags & VOFLAG_FULLSCREEN)) {
|
||||||
vo_x11_fullscreen(vo);
|
vo_x11_fullscreen(vo);
|
||||||
} else if (vo_fs) {
|
} else if (vo_fs) {
|
||||||
// if we are already in fullscreen do not switch back and forth, just
|
// if we are already in fullscreen do not switch back and forth, just
|
||||||
// set the size values right.
|
// set the size values right.
|
||||||
vo->dwidth = vo->opts->vo_screenwidth;
|
x11->win_width = vo->opts->vo_screenwidth;
|
||||||
vo->dheight = vo->opts->vo_screenheight;
|
x11->win_height = vo->opts->vo_screenheight;
|
||||||
}
|
}
|
||||||
final:
|
final:
|
||||||
if (x11->vo_gc != None)
|
if (x11->vo_gc != None)
|
||||||
@ -1068,6 +1067,9 @@ final:
|
|||||||
|
|
||||||
XSync(mDisplay, False);
|
XSync(mDisplay, False);
|
||||||
vo->event_fd = ConnectionNumber(x11->display);
|
vo->event_fd = ConnectionNumber(x11->display);
|
||||||
|
|
||||||
|
update_vo_size(vo);
|
||||||
|
x11->pending_vo_events &= ~VO_EVENT_RESIZE; // implicitly done by the VO
|
||||||
}
|
}
|
||||||
|
|
||||||
void vo_x11_clearwindow_part(struct vo *vo, Window vo_window,
|
void vo_x11_clearwindow_part(struct vo *vo, Window vo_window,
|
||||||
@ -1080,8 +1082,8 @@ void vo_x11_clearwindow_part(struct vo *vo, Window vo_window,
|
|||||||
if (x11->f_gc == None)
|
if (x11->f_gc == None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u_dheight = vo->dheight;
|
u_dheight = x11->win_height;
|
||||||
u_dwidth = vo->dwidth;
|
u_dwidth = x11->win_width;
|
||||||
if ((u_dheight <= img_height) && (u_dwidth <= img_width))
|
if ((u_dheight <= img_height) && (u_dwidth <= img_width))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1236,7 +1238,7 @@ static int vo_x11_get_fs_type(struct vo *vo)
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update vo->dx, vo->dy, vo->dwidth and vo->dheight with current values of vo->x11->window
|
// update x11->win_x, x11->win_y, x11->win_width and x11->win_height with current values of vo->x11->window
|
||||||
static void vo_x11_update_geometry(struct vo *vo, bool update_pos)
|
static void vo_x11_update_geometry(struct vo *vo, bool update_pos)
|
||||||
{
|
{
|
||||||
struct vo_x11_state *x11 = vo->x11;
|
struct vo_x11_state *x11 = vo->x11;
|
||||||
@ -1247,15 +1249,15 @@ static void vo_x11_update_geometry(struct vo *vo, bool update_pos)
|
|||||||
XGetGeometry(x11->display, win, &dummy_win, &dummy_int, &dummy_int,
|
XGetGeometry(x11->display, win, &dummy_win, &dummy_int, &dummy_int,
|
||||||
&w, &h, &dummy_int, &dummy_uint);
|
&w, &h, &dummy_int, &dummy_uint);
|
||||||
if (w <= INT_MAX && h <= INT_MAX) {
|
if (w <= INT_MAX && h <= INT_MAX) {
|
||||||
vo->dwidth = w;
|
x11->win_width = w;
|
||||||
vo->dheight = h;
|
x11->win_height = h;
|
||||||
}
|
}
|
||||||
if (WinID >= 0) {
|
if (WinID >= 0) {
|
||||||
vo->dx = 0;
|
x11->win_x = 0;
|
||||||
vo->dy = 0;
|
x11->win_y = 0;
|
||||||
} else if (update_pos) {
|
} else if (update_pos) {
|
||||||
XTranslateCoordinates(x11->display, x11->window, x11->rootwin, 0, 0,
|
XTranslateCoordinates(x11->display, x11->window, x11->rootwin, 0, 0,
|
||||||
&vo->dx, &vo->dy, &dummy_win);
|
&x11->win_x, &x11->win_y, &dummy_win);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1284,7 +1286,7 @@ void vo_x11_fullscreen(struct vo *vo)
|
|||||||
}
|
}
|
||||||
vo_fs = VO_FALSE;
|
vo_fs = VO_FALSE;
|
||||||
if (x11->size_changed_during_fs && (x11->fs_type & vo_wm_FULLSCREEN)) {
|
if (x11->size_changed_during_fs && (x11->fs_type & vo_wm_FULLSCREEN)) {
|
||||||
vo_x11_nofs_sizepos(vo, vo->dx, vo->dy, x11->last_video_width,
|
vo_x11_nofs_sizepos(vo, x11->win_x, x11->win_y, x11->last_video_width,
|
||||||
x11->last_video_height);
|
x11->last_video_height);
|
||||||
}
|
}
|
||||||
x11->size_changed_during_fs = false;
|
x11->size_changed_during_fs = false;
|
||||||
@ -1292,10 +1294,10 @@ void vo_x11_fullscreen(struct vo *vo)
|
|||||||
// win->fs
|
// win->fs
|
||||||
vo_fs = VO_TRUE;
|
vo_fs = VO_TRUE;
|
||||||
|
|
||||||
x11->vo_old_x = vo->dx;
|
x11->vo_old_x = x11->win_x;
|
||||||
x11->vo_old_y = vo->dy;
|
x11->vo_old_y = x11->win_y;
|
||||||
x11->vo_old_width = vo->dwidth;
|
x11->vo_old_width = x11->win_width;
|
||||||
x11->vo_old_height = vo->dheight;
|
x11->vo_old_height = x11->win_height;
|
||||||
|
|
||||||
vo_x11_update_screeninfo(vo);
|
vo_x11_update_screeninfo(vo);
|
||||||
|
|
||||||
|
@ -64,6 +64,14 @@ struct vo_x11_state {
|
|||||||
int vo_old_width;
|
int vo_old_width;
|
||||||
int vo_old_height;
|
int vo_old_height;
|
||||||
|
|
||||||
|
// Current actual window position (updated on window move/resize events).
|
||||||
|
int win_x;
|
||||||
|
int win_y;
|
||||||
|
unsigned int win_width;
|
||||||
|
unsigned int win_height;
|
||||||
|
|
||||||
|
int pending_vo_events;
|
||||||
|
|
||||||
/* Keep track of original video width/height to determine when to
|
/* Keep track of original video width/height to determine when to
|
||||||
* resize window when reconfiguring. Resize window when video size
|
* resize window when reconfiguring. Resize window when video size
|
||||||
* changes, but don't force window size changes as long as video size
|
* changes, but don't force window size changes as long as video size
|
||||||
|
Loading…
Reference in New Issue
Block a user