mpv/video/out/x11_common.h

133 lines
3.7 KiB
C
Raw Normal View History

/*
* This file is part of mpv.
*
* mpv is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MPLAYER_X11_COMMON_H
#define MPLAYER_X11_COMMON_H
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "osdep/atomics.h"
#include "osdep/semaphore.h"
#include "common/common.h"
struct vo;
struct mp_log;
#define MAX_DISPLAYS 32 // ought to be enough for everyone
struct xrandr_display {
struct mp_rect rc;
double fps;
char *name;
bool overlaps;
};
struct vo_x11_state {
struct mp_log *log;
Display *display;
2008-04-21 00:14:37 +00:00
Window window;
Window rootwin;
Window parent; // embedded in this foreign window
int screen;
int display_is_local;
int ws_width;
int ws_height;
struct mp_rect screenrc;
struct xrandr_display displays[MAX_DISPLAYS];
int num_displays;
int xrandr_event;
bool screensaver_enabled;
bool dpms_touched;
double screensaver_time_last;
pthread_t screensaver_thread;
bool screensaver_thread_running;
sem_t screensaver_sem;
atomic_bool screensaver_terminate;
XIM xim;
XIC xic;
bool no_autorepeat;
Colormap colormap;
2008-04-21 01:19:43 +00:00
int wm_type;
2014-09-15 16:42:09 +00:00
bool window_hidden; // the window was mapped at least once
bool pseudo_mapped; // not necessarily mapped, but known window size
int fs; // whether we assume the window is in fullscreen mode
bool mouse_cursor_hidden;
long orig_layer;
// Current actual window position (updated on window move/resize events).
2014-05-17 01:29:36 +00:00
struct mp_rect winrc;
double current_display_fps;
int pending_vo_events;
x11_common: fix window mapping, refactor window creation/resize handling vo_opengl creates an invisible window with VOFLAG_HIDDEN in order to test whether the OpenGL context is useable. The visible window is created at a later point. This has been broken forever (in vo_gl, now called vo_opengl_old, it could be avoided by disabling auto- detection explicitly using the "yuv" sub-option). Avoiding VOFLAG_HIDDEN only mitigates the issue, and a related bug can still happen with some window managers (see below). As a hack, code was added to vo_gl to destroy the (hidden) window so that all state was destroyed. Later, more hacks were added to deal with some caveats that came with recreating the window, such as probing for the context up to 4 times. Attempt to fix the problem properly. There were two problems: first, the window was not resized to video size before mapping. This was the main cause for the placement issue, e.g. mapping the window as 320x200, and then resizing it. Second, mpv tried to force the window position with XSetWMNormalHints and PPosition with values it just read with XGetGeometry. This messes up the window manager's default placement. It seems to be a race condition, and behavior is different across various WMs too: with IceWM, the window manager's placement is usually preferred, and with Fluxbox, mpv's position is preferred. mpv's default position is centering the window on the screen, which is much nicer for video in general than typical WM default placement, so it's possible that this bug was perceived as a feature. (Users who want this have to use --geometry="50%:50%", doing this by default is probably not safe with all WMs.) Since the old code was hard to follow and full of issues, it's easier to redo it. Move general window creation stuff out of the vo_x11_config_vo_window function, and move the resize logic into it. This has been tested on IcwWM, Fluxbox, awesome, Unity/Compiz.
2013-03-02 16:08:37 +00:00
// last non-fullscreen extends (updated on fullscreen or reinitialization)
2014-05-17 01:29:36 +00:00
struct mp_rect nofsrc;
x11_common: fix window mapping, refactor window creation/resize handling vo_opengl creates an invisible window with VOFLAG_HIDDEN in order to test whether the OpenGL context is useable. The visible window is created at a later point. This has been broken forever (in vo_gl, now called vo_opengl_old, it could be avoided by disabling auto- detection explicitly using the "yuv" sub-option). Avoiding VOFLAG_HIDDEN only mitigates the issue, and a related bug can still happen with some window managers (see below). As a hack, code was added to vo_gl to destroy the (hidden) window so that all state was destroyed. Later, more hacks were added to deal with some caveats that came with recreating the window, such as probing for the context up to 4 times. Attempt to fix the problem properly. There were two problems: first, the window was not resized to video size before mapping. This was the main cause for the placement issue, e.g. mapping the window as 320x200, and then resizing it. Second, mpv tried to force the window position with XSetWMNormalHints and PPosition with values it just read with XGetGeometry. This messes up the window manager's default placement. It seems to be a race condition, and behavior is different across various WMs too: with IceWM, the window manager's placement is usually preferred, and with Fluxbox, mpv's position is preferred. mpv's default position is centering the window on the screen, which is much nicer for video in general than typical WM default placement, so it's possible that this bug was perceived as a feature. (Users who want this have to use --geometry="50%:50%", doing this by default is probably not safe with all WMs.) Since the old code was hard to follow and full of issues, it's easier to redo it. Move general window creation stuff out of the vo_x11_config_vo_window function, and move the resize logic into it. This has been tested on IcwWM, Fluxbox, awesome, Unity/Compiz.
2013-03-02 16:08:37 +00:00
/* Keep track of original video width/height to determine when to
* resize window when reconfiguring. Resize window when video size
* changes, but don't force window size changes as long as video size
* stays the same (even if that size is different from the current
* window size after the user modified the latter). */
2014-05-17 01:29:36 +00:00
int old_dw, old_dh;
/* Video size changed during fullscreen when we couldn't tell the new
* size to the window manager. Must set window size when turning
* fullscreen off. */
bool size_changed_during_fs;
x11_common: fix window mapping, refactor window creation/resize handling vo_opengl creates an invisible window with VOFLAG_HIDDEN in order to test whether the OpenGL context is useable. The visible window is created at a later point. This has been broken forever (in vo_gl, now called vo_opengl_old, it could be avoided by disabling auto- detection explicitly using the "yuv" sub-option). Avoiding VOFLAG_HIDDEN only mitigates the issue, and a related bug can still happen with some window managers (see below). As a hack, code was added to vo_gl to destroy the (hidden) window so that all state was destroyed. Later, more hacks were added to deal with some caveats that came with recreating the window, such as probing for the context up to 4 times. Attempt to fix the problem properly. There were two problems: first, the window was not resized to video size before mapping. This was the main cause for the placement issue, e.g. mapping the window as 320x200, and then resizing it. Second, mpv tried to force the window position with XSetWMNormalHints and PPosition with values it just read with XGetGeometry. This messes up the window manager's default placement. It seems to be a race condition, and behavior is different across various WMs too: with IceWM, the window manager's placement is usually preferred, and with Fluxbox, mpv's position is preferred. mpv's default position is centering the window on the screen, which is much nicer for video in general than typical WM default placement, so it's possible that this bug was perceived as a feature. (Users who want this have to use --geometry="50%:50%", doing this by default is probably not safe with all WMs.) Since the old code was hard to follow and full of issues, it's easier to redo it. Move general window creation stuff out of the vo_x11_config_vo_window function, and move the resize logic into it. This has been tested on IcwWM, Fluxbox, awesome, Unity/Compiz.
2013-03-02 16:08:37 +00:00
bool pos_changed_during_fs;
2008-04-21 01:19:43 +00:00
XComposeStatus compose_status;
/* XShm stuff */
int ShmCompletionEvent;
/* Number of outstanding XShmPutImage requests */
/* Decremented when ShmCompletionEvent is received */
/* Increment it before XShmPutImage */
int ShmCompletionWaitCount;
/* drag and drop */
Atom dnd_requested_format;
Atom dnd_requested_action;
Window dnd_src_window;
/* dragging the window */
bool win_drag_button1_down;
Atom icc_profile_property;
};
int vo_x11_init(struct vo *vo);
void vo_x11_uninit(struct vo *vo);
int vo_x11_check_events(struct vo *vo);
bool vo_x11_screen_is_composited(struct vo *vo);
void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int flags,
const char *classname);
int vo_x11_control(struct vo *vo, int *events, int request, void *arg);
#endif /* MPLAYER_X11_COMMON_H */