2009-02-08 03:27:30 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer 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.
|
|
|
|
*
|
|
|
|
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2001-04-15 20:31:58 +00:00
|
|
|
|
2001-03-03 21:47:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-10-29 20:27:47 +00:00
|
|
|
#include <math.h>
|
2002-06-12 22:57:58 +00:00
|
|
|
#include <inttypes.h>
|
2008-11-15 19:06:25 +00:00
|
|
|
#include <limits.h>
|
2001-04-15 18:35:17 +00:00
|
|
|
|
2001-04-15 20:31:58 +00:00
|
|
|
#include "config.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/bstr.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/input.h"
|
2009-01-09 15:25:24 +00:00
|
|
|
#include "libavutil/common.h"
|
2002-06-12 22:57:58 +00:00
|
|
|
#include "x11_common.h"
|
2008-04-29 13:22:33 +00:00
|
|
|
#include "talloc.h"
|
2001-04-15 20:31:58 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2001-03-03 21:47:37 +00:00
|
|
|
#include <unistd.h>
|
2004-06-02 02:34:39 +00:00
|
|
|
#include <assert.h>
|
2001-03-03 21:47:37 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "vo.h"
|
2003-09-20 10:24:10 +00:00
|
|
|
#include "aspect.h"
|
2004-10-28 01:15:53 +00:00
|
|
|
#include "osdep/timer.h"
|
2001-03-03 21:47:37 +00:00
|
|
|
|
2001-04-10 00:00:04 +00:00
|
|
|
#include <X11/Xmd.h>
|
2001-03-03 21:47:37 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
2012-01-13 08:25:12 +00:00
|
|
|
#include <X11/keysym.h>
|
2013-04-03 23:13:56 +00:00
|
|
|
#include <X11/XKBlib.h>
|
2001-03-03 21:47:37 +00:00
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XSS
|
2007-12-22 18:51:05 +00:00
|
|
|
#include <X11/extensions/scrnsaver.h>
|
|
|
|
#endif
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XEXT
|
2001-04-15 20:31:58 +00:00
|
|
|
#include <X11/extensions/dpms.h>
|
2001-07-19 18:47:22 +00:00
|
|
|
#endif
|
2001-04-15 20:31:58 +00:00
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XINERAMA
|
2001-10-10 01:48:54 +00:00
|
|
|
#include <X11/extensions/Xinerama.h>
|
|
|
|
#endif
|
2001-08-28 17:52:20 +00:00
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XF86VM
|
2002-01-31 00:37:27 +00:00
|
|
|
#include <X11/extensions/xf86vmode.h>
|
2005-02-02 14:07:13 +00:00
|
|
|
#endif
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XF86XK
|
2003-04-04 15:04:26 +00:00
|
|
|
#include <X11/XF86keysym.h>
|
2002-01-31 00:37:27 +00:00
|
|
|
#endif
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ZLIB
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
#include <zlib.h>
|
|
|
|
#endif
|
|
|
|
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/input.h"
|
|
|
|
#include "input/keycodes.h"
|
2002-02-11 11:44:50 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
#define vo_wm_LAYER 1
|
|
|
|
#define vo_wm_FULLSCREEN 2
|
|
|
|
#define vo_wm_STAYS_ON_TOP 4
|
|
|
|
#define vo_wm_ABOVE 8
|
|
|
|
#define vo_wm_BELOW 16
|
2013-08-11 21:57:00 +00:00
|
|
|
#define vo_wm_MWM 32
|
2013-02-13 15:33:01 +00:00
|
|
|
#define vo_wm_NETWM (vo_wm_FULLSCREEN | vo_wm_STAYS_ON_TOP | vo_wm_ABOVE | \
|
|
|
|
vo_wm_BELOW)
|
2013-01-26 21:37:47 +00:00
|
|
|
|
|
|
|
/* EWMH state actions, see
|
|
|
|
http://freedesktop.org/Standards/wm-spec/index.html#id2768769 */
|
|
|
|
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
|
|
|
|
#define _NET_WM_STATE_ADD 1 /* add/set property */
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
|
|
|
|
|
2002-12-30 18:50:15 +00:00
|
|
|
#define WIN_LAYER_ONBOTTOM 2
|
|
|
|
#define WIN_LAYER_NORMAL 4
|
|
|
|
#define WIN_LAYER_ONTOP 6
|
This time the patch is fixing much more that breaking :-)
It includes ugly hack for OpenBox, swaps checking for netwm
with layers (and makes fvwm work -> they have also broken
_NET_WM_STATE_FULLSCREEN but also supports layers) and changes
back fullscreen layer to 10, afterstep doesn't like 12 :-)
Tested with: sawfish, metacity, kwin, blackbox, openbox, waimea,
windowmaker, afterstep, icewm, mwm, fvwm
Filip Kalinski <filon@pld.org.pl>
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8670 b3059339-0415-0410-9bf9-f77b7e298cf2
2002-12-30 23:59:53 +00:00
|
|
|
#define WIN_LAYER_ABOVE_DOCK 10
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
// ----- Motif header: -------
|
|
|
|
|
|
|
|
#define MWM_HINTS_FUNCTIONS (1L << 0)
|
|
|
|
#define MWM_HINTS_DECORATIONS (1L << 1)
|
|
|
|
#define MWM_HINTS_INPUT_MODE (1L << 2)
|
|
|
|
#define MWM_HINTS_STATUS (1L << 3)
|
|
|
|
|
|
|
|
#define MWM_FUNC_ALL (1L << 0)
|
|
|
|
#define MWM_FUNC_RESIZE (1L << 1)
|
|
|
|
#define MWM_FUNC_MOVE (1L << 2)
|
|
|
|
#define MWM_FUNC_MINIMIZE (1L << 3)
|
|
|
|
#define MWM_FUNC_MAXIMIZE (1L << 4)
|
|
|
|
#define MWM_FUNC_CLOSE (1L << 5)
|
2003-01-09 21:23:54 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
#define MWM_DECOR_ALL (1L << 0)
|
|
|
|
#define MWM_DECOR_BORDER (1L << 1)
|
|
|
|
#define MWM_DECOR_RESIZEH (1L << 2)
|
|
|
|
#define MWM_DECOR_TITLE (1L << 3)
|
|
|
|
#define MWM_DECOR_MENU (1L << 4)
|
|
|
|
#define MWM_DECOR_MINIMIZE (1L << 5)
|
|
|
|
#define MWM_DECOR_MAXIMIZE (1L << 6)
|
2002-05-27 11:19:56 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
#define MWM_INPUT_MODELESS 0
|
|
|
|
#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
|
|
|
|
#define MWM_INPUT_SYSTEM_MODAL 2
|
|
|
|
#define MWM_INPUT_FULL_APPLICATION_MODAL 3
|
|
|
|
#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
|
2001-04-10 00:00:04 +00:00
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
#define MWM_TEAROFF_WINDOW (1L << 0)
|
2001-04-13 00:54:05 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long flags;
|
|
|
|
long functions;
|
|
|
|
long decorations;
|
|
|
|
long input_mode;
|
|
|
|
long state;
|
|
|
|
} MotifWmHints;
|
2003-01-07 20:58:25 +00:00
|
|
|
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
static const char x11_icon[] =
|
|
|
|
#include "video/out/x11_icon.inc"
|
|
|
|
;
|
|
|
|
|
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
|
|
|
static void vo_x11_update_geometry(struct vo *vo);
|
2013-05-16 12:02:28 +00:00
|
|
|
static void vo_x11_fullscreen(struct vo *vo);
|
2013-01-26 21:37:47 +00:00
|
|
|
static int vo_x11_get_fs_type(struct vo *vo);
|
2013-03-01 10:17:56 +00:00
|
|
|
static void xscreensaver_heartbeat(struct vo_x11_state *x11);
|
2013-01-26 21:37:47 +00:00
|
|
|
static void saver_on(struct vo_x11_state *x11);
|
|
|
|
static void saver_off(struct vo_x11_state *x11);
|
2013-03-04 16:40:21 +00:00
|
|
|
static void vo_x11_selectinput_witherr(struct vo *vo, Display *display,
|
|
|
|
Window w, long event_mask);
|
2013-01-26 21:37:47 +00:00
|
|
|
static void vo_x11_setlayer(struct vo *vo, Window vo_window, int layer);
|
2003-05-30 18:05:49 +00:00
|
|
|
|
2004-06-02 02:34:39 +00:00
|
|
|
/*
|
|
|
|
* Sends the EWMH fullscreen state event.
|
2007-01-18 09:03:42 +00:00
|
|
|
*
|
|
|
|
* action: could be one of _NET_WM_STATE_REMOVE -- remove state
|
|
|
|
* _NET_WM_STATE_ADD -- add state
|
|
|
|
* _NET_WM_STATE_TOGGLE -- toggle
|
2004-06-02 02:34:39 +00:00
|
|
|
*/
|
2013-01-26 21:37:47 +00:00
|
|
|
static void vo_x11_ewmh_fullscreen(struct vo_x11_state *x11, int action)
|
2004-06-02 02:34:39 +00:00
|
|
|
{
|
2013-02-13 15:33:01 +00:00
|
|
|
assert(action == _NET_WM_STATE_REMOVE || action == _NET_WM_STATE_ADD ||
|
|
|
|
action == _NET_WM_STATE_TOGGLE);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
if (x11->fs_type & vo_wm_FULLSCREEN) {
|
2004-06-14 04:53:03 +00:00
|
|
|
XEvent xev;
|
|
|
|
|
2007-01-18 09:03:42 +00:00
|
|
|
/* init X event structure for _NET_WM_FULLSCREEN client message */
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.xclient.type = ClientMessage;
|
|
|
|
xev.xclient.serial = 0;
|
|
|
|
xev.xclient.send_event = True;
|
2008-09-20 13:13:33 +00:00
|
|
|
xev.xclient.message_type = x11->XA_NET_WM_STATE;
|
2008-04-21 00:14:37 +00:00
|
|
|
xev.xclient.window = x11->window;
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.xclient.format = 32;
|
|
|
|
xev.xclient.data.l[0] = action;
|
2008-09-20 13:13:33 +00:00
|
|
|
xev.xclient.data.l[1] = x11->XA_NET_WM_STATE_FULLSCREEN;
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.xclient.data.l[2] = 0;
|
|
|
|
xev.xclient.data.l[3] = 0;
|
|
|
|
xev.xclient.data.l[4] = 0;
|
|
|
|
|
|
|
|
/* finally send that damn thing */
|
2008-04-21 00:14:37 +00:00
|
|
|
if (!XSendEvent(x11->display, DefaultRootWindow(x11->display), False,
|
2004-06-14 04:53:03 +00:00
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask,
|
|
|
|
&xev))
|
|
|
|
{
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_ERR(x11, "Couldn't send EWMH fullscreen event!\n");
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
2004-06-02 02:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 21:24:56 +00:00
|
|
|
static void vo_set_cursor_hidden(struct vo *vo, bool cursor_hidden)
|
2001-04-13 00:54:05 +00:00
|
|
|
{
|
2004-06-14 04:53:03 +00:00
|
|
|
Cursor no_ptr;
|
|
|
|
Pixmap bm_no;
|
|
|
|
XColor black, dummy;
|
|
|
|
Colormap colormap;
|
2013-02-13 15:33:01 +00:00
|
|
|
const char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
2013-05-16 21:24:56 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
Display *disp = x11->display;
|
|
|
|
Window win = x11->window;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-05-16 21:24:56 +00:00
|
|
|
if (cursor_hidden == x11->mouse_cursor_hidden)
|
|
|
|
return;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-05-16 21:24:56 +00:00
|
|
|
x11->mouse_cursor_hidden = cursor_hidden;
|
2001-04-13 00:54:05 +00:00
|
|
|
|
2013-05-16 21:24:56 +00:00
|
|
|
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);
|
|
|
|
}
|
2002-05-03 20:57:13 +00:00
|
|
|
}
|
2001-04-13 00:54:05 +00:00
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
static int x11_errorhandler(Display *display, XErrorEvent *event)
|
2002-02-17 12:34:29 +00:00
|
|
|
{
|
2013-02-13 15:33:01 +00:00
|
|
|
char msg[60];
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
XGetErrorText(display, event->error_code, (char *) &msg, sizeof(msg));
|
2004-06-14 04:53:03 +00:00
|
|
|
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "X11 error: %s\n", msg);
|
|
|
|
|
|
|
|
mp_msg(MSGT_VO, MSGL_V,
|
2006-01-12 20:04:36 +00:00
|
|
|
"Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
|
2004-06-14 04:53:03 +00:00
|
|
|
event->type, event->display, event->resourceid, event->serial);
|
|
|
|
mp_msg(MSGT_VO, MSGL_V,
|
|
|
|
"Error code: %x, request code: %x, minor code: %x\n",
|
|
|
|
event->error_code, event->request_code, event->minor_code);
|
|
|
|
|
2007-01-05 11:57:06 +00:00
|
|
|
// abort();
|
2007-06-24 10:46:40 +00:00
|
|
|
return 0;
|
2002-02-17 12:34:29 +00:00
|
|
|
}
|
2001-08-28 17:52:20 +00:00
|
|
|
|
2013-10-28 21:41:16 +00:00
|
|
|
struct fstype {
|
|
|
|
int type;
|
|
|
|
const char *sym;
|
|
|
|
const char *help;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct fstype fstypes[] = {
|
|
|
|
{0, "none", "don't set fullscreen window layer"},
|
|
|
|
{vo_wm_LAYER, "layer", "use _WIN_LAYER, set layer with layer=<0..15>"},
|
|
|
|
{vo_wm_ABOVE, "above", "use _NETWM_STATE_ABOVE"},
|
|
|
|
{vo_wm_FULLSCREEN, "fullscreen", "use _NETWM_STATE_FULLSCREEN"},
|
|
|
|
{vo_wm_STAYS_ON_TOP, "stays_on_top", "use _NETWM_STATE_STAYS_ON_TOP"},
|
|
|
|
{vo_wm_BELOW, "below", "use _NETWM_STATE_BELOW"},
|
|
|
|
{vo_wm_NETWM, "netwm", "force NETWM style"},
|
|
|
|
{vo_wm_MWM, "mwm_hack", "enable MWM hack"},
|
|
|
|
{0},
|
|
|
|
};
|
|
|
|
|
2003-02-07 19:38:39 +00:00
|
|
|
void fstype_help(void)
|
|
|
|
{
|
2013-12-16 19:40:02 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "Available fullscreen layer change modes:\n");
|
2013-10-28 21:41:16 +00:00
|
|
|
for (int n = 0; fstypes[n].sym; n++) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", fstypes[n].sym,
|
|
|
|
fstypes[n].help);
|
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_INFO,
|
|
|
|
"You can also negate the settings with simply putting '-' in the beginning");
|
2006-03-04 17:33:56 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "\n");
|
2003-08-25 18:13:51 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 22:56:41 +00:00
|
|
|
static void fstype_dump(struct vo_x11_state *x11)
|
2003-08-25 18:13:51 +00:00
|
|
|
{
|
2013-09-11 22:56:41 +00:00
|
|
|
int fstype = x11->fs_type;
|
2013-02-13 15:33:01 +00:00
|
|
|
if (fstype) {
|
2013-10-28 21:41:16 +00:00
|
|
|
MP_VERBOSE(x11, "Current fstype setting honours:");
|
|
|
|
for (int n = 0; fstypes[n].sym; n++) {
|
|
|
|
if (fstypes[n].type & fstype)
|
|
|
|
MP_VERBOSE(x11, " %s", fstypes[n].sym);
|
|
|
|
}
|
|
|
|
MP_VERBOSE(x11, "\n");
|
2013-02-13 15:33:01 +00:00
|
|
|
} else {
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Current fstype setting doesn't honour any X atoms\n");
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
2003-02-07 19:38:39 +00:00
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-10-28 21:41:16 +00:00
|
|
|
static int vo_x11_get_fs_type(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
unsigned int type = x11->wm_type;
|
|
|
|
char **fstype_list = vo->opts->fstype_list;
|
|
|
|
|
|
|
|
if (fstype_list) {
|
|
|
|
for (int i = 0; fstype_list[i]; i++) {
|
|
|
|
int neg = 0;
|
|
|
|
char *arg = fstype_list[i];
|
|
|
|
unsigned int flag = 0xFF;
|
|
|
|
|
|
|
|
if (arg[0] == '-') {
|
|
|
|
neg = 1;
|
|
|
|
arg = arg + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int n = 0; fstypes[n].sym; n++) {
|
|
|
|
if (strcmp(arg, fstypes[n].sym) == 0)
|
|
|
|
flag = fstypes[n].type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(arg, "layer=", 6) == 0) {
|
|
|
|
char *endptr = NULL;
|
|
|
|
int layer = strtol(arg + 6, &endptr, 10);
|
|
|
|
|
|
|
|
if (endptr && *endptr == '\0' && layer >= 0 && layer <= 15)
|
|
|
|
x11->fs_layer = layer;
|
|
|
|
|
|
|
|
flag = vo_wm_LAYER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag == 0xFF) {
|
|
|
|
MP_ERR(x11, "fstype '%s' unknown\n", arg);
|
|
|
|
} else if (flag == 0) {
|
|
|
|
type = 0;
|
|
|
|
} else {
|
|
|
|
type = neg ? (type & ~flag) : (type | flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2008-04-20 23:50:40 +00:00
|
|
|
static int net_wm_support_state_test(struct vo_x11_state *x11, Atom atom)
|
2002-12-30 00:47:43 +00:00
|
|
|
{
|
2013-02-13 15:33:01 +00:00
|
|
|
#define NET_WM_STATE_TEST(x) { \
|
|
|
|
if (atom == x11->XA_NET_WM_STATE_##x) { \
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Detected wm supports " #x " state.\n" ); \
|
2013-02-13 15:33:01 +00:00
|
|
|
return vo_wm_##x; \
|
|
|
|
} \
|
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
|
|
|
|
NET_WM_STATE_TEST(FULLSCREEN);
|
|
|
|
NET_WM_STATE_TEST(ABOVE);
|
|
|
|
NET_WM_STATE_TEST(STAYS_ON_TOP);
|
|
|
|
NET_WM_STATE_TEST(BELOW);
|
|
|
|
return 0;
|
2002-12-30 00:47:43 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
static int x11_get_property(struct vo_x11_state *x11, Atom type, Atom **args,
|
2008-04-20 06:34:27 +00:00
|
|
|
unsigned long *nitems)
|
2003-01-03 15:30:57 +00:00
|
|
|
{
|
2004-06-14 04:53:03 +00:00
|
|
|
int format;
|
|
|
|
unsigned long bytesafter;
|
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
return Success ==
|
|
|
|
XGetWindowProperty(x11->display, x11->rootwin, type, 0, 16384, False,
|
|
|
|
AnyPropertyType, &type, &format, nitems,
|
|
|
|
&bytesafter, (unsigned char **) args)
|
|
|
|
&& *nitems > 0;
|
2003-01-03 15:30:57 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 06:34:27 +00:00
|
|
|
static int vo_wm_detect(struct vo *vo)
|
2002-05-07 13:31:29 +00:00
|
|
|
{
|
2008-04-20 23:50:40 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2004-06-14 04:53:03 +00:00
|
|
|
int i;
|
|
|
|
int wm = 0;
|
|
|
|
unsigned long nitems;
|
|
|
|
Atom *args = NULL;
|
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0)
|
2004-06-14 04:53:03 +00:00
|
|
|
return 0;
|
This time the patch is fixing much more that breaking :-)
It includes ugly hack for OpenBox, swaps checking for netwm
with layers (and makes fvwm work -> they have also broken
_NET_WM_STATE_FULLSCREEN but also supports layers) and changes
back fullscreen layer to 10, afterstep doesn't like 12 :-)
Tested with: sawfish, metacity, kwin, blackbox, openbox, waimea,
windowmaker, afterstep, icewm, mwm, fvwm
Filip Kalinski <filon@pld.org.pl>
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8670 b3059339-0415-0410-9bf9-f77b7e298cf2
2002-12-30 23:59:53 +00:00
|
|
|
|
2004-06-14 04:53:03 +00:00
|
|
|
// -- supports layers
|
2013-02-13 15:33:01 +00:00
|
|
|
if (x11_get_property(x11, x11->XA_WIN_PROTOCOLS, &args, &nitems)) {
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Detected wm supports layers.\n");
|
2013-02-13 15:33:01 +00:00
|
|
|
for (i = 0; i < nitems; i++) {
|
2013-10-30 21:02:51 +00:00
|
|
|
if (args[i] == x11->XA_WIN_LAYER)
|
2004-06-14 04:53:03 +00:00
|
|
|
wm |= vo_wm_LAYER;
|
|
|
|
}
|
|
|
|
XFree(args);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
// --- netwm
|
2013-02-13 15:33:01 +00:00
|
|
|
if (x11_get_property(x11, x11->XA_NET_SUPPORTED, &args, &nitems)) {
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Detected wm supports NetWM.\n");
|
2004-06-14 04:53:03 +00:00
|
|
|
for (i = 0; i < nitems; i++)
|
2008-04-20 23:50:40 +00:00
|
|
|
wm |= net_wm_support_state_test(vo->x11, args[i]);
|
2004-06-14 04:53:03 +00:00
|
|
|
XFree(args);
|
|
|
|
}
|
2003-02-07 19:38:39 +00:00
|
|
|
|
2004-06-14 04:53:03 +00:00
|
|
|
if (wm == 0)
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Unknown wm type...\n");
|
2004-06-14 04:53:03 +00:00
|
|
|
return wm;
|
|
|
|
}
|
2002-05-07 13:31:29 +00:00
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
#define XA_INIT(x) x11->XA ## x = XInternAtom(x11->display, # x, False)
|
2008-04-20 23:50:40 +00:00
|
|
|
static void init_atoms(struct vo_x11_state *x11)
|
2003-01-03 15:30:57 +00:00
|
|
|
{
|
2004-06-14 04:53:03 +00:00
|
|
|
XA_INIT(_NET_SUPPORTED);
|
|
|
|
XA_INIT(_NET_WM_STATE);
|
|
|
|
XA_INIT(_NET_WM_STATE_FULLSCREEN);
|
|
|
|
XA_INIT(_NET_WM_STATE_ABOVE);
|
|
|
|
XA_INIT(_NET_WM_STATE_STAYS_ON_TOP);
|
|
|
|
XA_INIT(_NET_WM_STATE_BELOW);
|
|
|
|
XA_INIT(_NET_WM_PID);
|
2011-12-06 17:48:31 +00:00
|
|
|
XA_INIT(_NET_WM_NAME);
|
|
|
|
XA_INIT(_NET_WM_ICON_NAME);
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
XA_INIT(_NET_WM_ICON);
|
2004-06-14 04:53:03 +00:00
|
|
|
XA_INIT(_WIN_PROTOCOLS);
|
|
|
|
XA_INIT(_WIN_LAYER);
|
|
|
|
XA_INIT(_WIN_HINTS);
|
2006-04-19 15:58:10 +00:00
|
|
|
XA_INIT(WM_PROTOCOLS);
|
|
|
|
XA_INIT(WM_DELETE_WINDOW);
|
2011-12-06 17:48:31 +00:00
|
|
|
XA_INIT(UTF8_STRING);
|
2012-07-27 00:40:38 +00:00
|
|
|
char buf[50];
|
|
|
|
sprintf(buf, "_NET_WM_CM_S%d", x11->screen);
|
|
|
|
x11->XA_NET_WM_CM = XInternAtom(x11->display, buf, False);
|
2003-01-03 15:30:57 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 12:02:28 +00:00
|
|
|
static void vo_x11_update_screeninfo(struct vo *vo)
|
2013-02-13 15:33:01 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-02-15 18:47:34 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2013-07-18 12:05:39 +00:00
|
|
|
bool all_screens = opts->fullscreen && opts->fsscreen_id == -2;
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->xinerama_x = vo->xinerama_y = 0;
|
2013-02-17 15:35:44 +00:00
|
|
|
if (all_screens) {
|
2013-03-04 21:41:27 +00:00
|
|
|
opts->screenwidth = x11->ws_width;
|
|
|
|
opts->screenheight = x11->ws_height;
|
2013-02-17 15:35:44 +00:00
|
|
|
}
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XINERAMA
|
2013-10-30 20:58:55 +00:00
|
|
|
if (opts->screen_id >= -1 && XineramaIsActive(x11->display) && !all_screens)
|
2013-02-17 15:35:44 +00:00
|
|
|
{
|
2013-07-18 12:05:39 +00:00
|
|
|
int screen = opts->fullscreen ? opts->fsscreen_id : opts->screen_id;
|
2006-04-16 13:38:28 +00:00
|
|
|
XineramaScreenInfo *screens;
|
|
|
|
int num_screens;
|
|
|
|
|
2013-02-15 18:47:34 +00:00
|
|
|
screens = XineramaQueryScreens(x11->display, &num_screens);
|
2008-04-19 09:58:01 +00:00
|
|
|
if (screen >= num_screens)
|
|
|
|
screen = num_screens - 1;
|
|
|
|
if (screen == -1) {
|
2013-02-15 18:47:34 +00:00
|
|
|
int x = x11->win_x + x11->win_width / 2;
|
|
|
|
int y = x11->win_y + x11->win_height / 2;
|
2008-04-19 09:58:01 +00:00
|
|
|
for (screen = num_screens - 1; screen > 0; screen--) {
|
2013-02-13 15:33:01 +00:00
|
|
|
int left = screens[screen].x_org;
|
|
|
|
int right = left + screens[screen].width;
|
|
|
|
int top = screens[screen].y_org;
|
|
|
|
int bottom = top + screens[screen].height;
|
|
|
|
if (left <= x && x <= right && top <= y && y <= bottom)
|
|
|
|
break;
|
2008-04-19 09:58:01 +00:00
|
|
|
}
|
2008-04-13 11:15:08 +00:00
|
|
|
}
|
2006-04-16 13:38:28 +00:00
|
|
|
if (screen < 0)
|
|
|
|
screen = 0;
|
2013-03-04 21:41:27 +00:00
|
|
|
opts->screenwidth = screens[screen].width;
|
|
|
|
opts->screenheight = screens[screen].height;
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->xinerama_x = screens[screen].x_org;
|
|
|
|
vo->xinerama_y = screens[screen].y_org;
|
2006-04-16 13:38:28 +00:00
|
|
|
|
|
|
|
XFree(screens);
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-04 21:41:27 +00:00
|
|
|
aspect_save_screenres(vo, opts->screenwidth, opts->screenheight);
|
2006-04-16 13:38:28 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
int vo_x11_init(struct vo *vo)
|
2001-03-03 21:47:37 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2004-06-14 04:53:03 +00:00
|
|
|
char *dispName;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
assert(!vo->x11);
|
2012-08-03 03:55:02 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
struct vo_x11_state *x11 = talloc_ptrtype(NULL, x11);
|
|
|
|
*x11 = (struct vo_x11_state){
|
2013-09-11 22:56:41 +00:00
|
|
|
.log = mp_log_new(x11, vo->log, "x11"),
|
2013-01-26 21:37:47 +00:00
|
|
|
.olddecor = MWM_DECOR_ALL,
|
|
|
|
.oldfuncs = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE |
|
|
|
|
MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE,
|
|
|
|
.old_gravity = NorthWestGravity,
|
|
|
|
.fs_layer = WIN_LAYER_ABOVE_DOCK,
|
|
|
|
};
|
|
|
|
vo->x11 = x11;
|
2012-08-03 03:55:02 +00:00
|
|
|
|
2004-06-14 04:53:03 +00:00
|
|
|
XSetErrorHandler(x11_errorhandler);
|
2002-02-22 19:36:21 +00:00
|
|
|
|
2012-11-15 14:38:02 +00:00
|
|
|
dispName = XDisplayName(NULL);
|
2002-02-22 19:36:21 +00:00
|
|
|
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "X11 opening display: %s\n", dispName);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2008-04-20 06:34:27 +00:00
|
|
|
x11->display = XOpenDisplay(dispName);
|
2013-02-13 15:33:01 +00:00
|
|
|
if (!x11->display) {
|
2013-09-10 16:33:43 +00:00
|
|
|
MP_MSG(x11, vo->probing ? MSGL_V : MSGL_ERR,
|
2013-09-19 22:02:49 +00:00
|
|
|
"couldn't open the X11 display (%s)!\n", dispName);
|
2013-09-10 16:33:43 +00:00
|
|
|
|
2012-08-03 03:55:02 +00:00
|
|
|
talloc_free(x11);
|
|
|
|
vo->x11 = NULL;
|
2004-06-14 04:53:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-04-21 01:59:00 +00:00
|
|
|
x11->screen = DefaultScreen(x11->display); // screen ID
|
|
|
|
x11->rootwin = RootWindow(x11->display, x11->screen); // root window ID
|
2001-05-31 22:32:58 +00:00
|
|
|
|
2013-04-03 23:13:56 +00:00
|
|
|
if (!opts->native_keyrepeat) {
|
|
|
|
Bool ok = False;
|
|
|
|
XkbSetDetectableAutoRepeat(x11->display, True, &ok);
|
|
|
|
x11->no_autorepeat = ok;
|
|
|
|
}
|
|
|
|
|
2012-01-14 13:09:44 +00:00
|
|
|
x11->xim = XOpenIM(x11->display, NULL, NULL, NULL);
|
2013-09-20 12:45:49 +00:00
|
|
|
if (!x11->xim)
|
|
|
|
MP_WARN(x11, "XOpenIM() failed. Unicode input will not work.\n");
|
2012-01-14 13:09:44 +00:00
|
|
|
|
2008-04-20 23:50:40 +00:00
|
|
|
init_atoms(vo->x11);
|
2001-10-10 01:48:54 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
x11->ws_width = opts->screenwidth;
|
|
|
|
x11->ws_height = opts->screenheight;
|
2013-02-17 15:35:44 +00:00
|
|
|
|
|
|
|
if (!x11->ws_width)
|
|
|
|
x11->ws_width = DisplayWidth(x11->display, x11->screen);
|
|
|
|
if (!x11->ws_height)
|
|
|
|
x11->ws_height = DisplayHeight(x11->display, x11->screen);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
opts->screenwidth = x11->ws_width;
|
|
|
|
opts->screenheight = x11->ws_height;
|
2013-02-13 15:33:01 +00:00
|
|
|
|
2004-06-14 04:53:03 +00:00
|
|
|
if (strncmp(dispName, "unix:", 5) == 0)
|
|
|
|
dispName += 4;
|
|
|
|
else if (strncmp(dispName, "localhost:", 10) == 0)
|
|
|
|
dispName += 9;
|
2013-10-30 20:58:55 +00:00
|
|
|
x11->display_is_local = dispName[0] == ':' && atoi(dispName + 1) < 10;
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "X11 running at %dx%d (\"%s\" => %s display)\n",
|
|
|
|
opts->screenwidth, opts->screenheight, dispName,
|
|
|
|
x11->display_is_local ? "local" : "remote");
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2008-04-21 01:50:29 +00:00
|
|
|
x11->wm_type = vo_wm_detect(vo);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
x11->fs_type = vo_x11_get_fs_type(vo);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-09-11 22:56:41 +00:00
|
|
|
fstype_dump(x11);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
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
|
|
|
vo->event_fd = ConnectionNumber(x11->display);
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
return 1;
|
2002-05-08 16:41:44 +00:00
|
|
|
}
|
2002-01-31 11:04:41 +00:00
|
|
|
|
2010-04-23 10:22:44 +00:00
|
|
|
static const struct mp_keymap keymap[] = {
|
2008-12-20 11:12:45 +00:00
|
|
|
// special keys
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_Pause, MP_KEY_PAUSE}, {XK_Escape, MP_KEY_ESC},
|
|
|
|
{XK_BackSpace, MP_KEY_BS}, {XK_Tab, MP_KEY_TAB}, {XK_Return, MP_KEY_ENTER},
|
|
|
|
{XK_Menu, MP_KEY_MENU}, {XK_Print, MP_KEY_PRINT},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
|
|
|
// cursor keys
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_Left, MP_KEY_LEFT}, {XK_Right, MP_KEY_RIGHT}, {XK_Up, MP_KEY_UP},
|
|
|
|
{XK_Down, MP_KEY_DOWN},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
|
|
|
// navigation block
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_Insert, MP_KEY_INSERT}, {XK_Delete, MP_KEY_DELETE},
|
|
|
|
{XK_Home, MP_KEY_HOME}, {XK_End, MP_KEY_END}, {XK_Page_Up, MP_KEY_PAGE_UP},
|
|
|
|
{XK_Page_Down, MP_KEY_PAGE_DOWN},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
|
|
|
// F-keys
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_F1, MP_KEY_F+1}, {XK_F2, MP_KEY_F+2}, {XK_F3, MP_KEY_F+3},
|
|
|
|
{XK_F4, MP_KEY_F+4}, {XK_F5, MP_KEY_F+5}, {XK_F6, MP_KEY_F+6},
|
|
|
|
{XK_F7, MP_KEY_F+7}, {XK_F8, MP_KEY_F+8}, {XK_F9, MP_KEY_F+9},
|
|
|
|
{XK_F10, MP_KEY_F+10}, {XK_F11, MP_KEY_F+11}, {XK_F12, MP_KEY_F+12},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
|
|
|
// numpad independent of numlock
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_KP_Subtract, '-'}, {XK_KP_Add, '+'}, {XK_KP_Multiply, '*'},
|
|
|
|
{XK_KP_Divide, '/'}, {XK_KP_Enter, MP_KEY_KPENTER},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
|
|
|
// numpad with numlock
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_KP_0, MP_KEY_KP0}, {XK_KP_1, MP_KEY_KP1}, {XK_KP_2, MP_KEY_KP2},
|
|
|
|
{XK_KP_3, MP_KEY_KP3}, {XK_KP_4, MP_KEY_KP4}, {XK_KP_5, MP_KEY_KP5},
|
|
|
|
{XK_KP_6, MP_KEY_KP6}, {XK_KP_7, MP_KEY_KP7}, {XK_KP_8, MP_KEY_KP8},
|
|
|
|
{XK_KP_9, MP_KEY_KP9}, {XK_KP_Decimal, MP_KEY_KPDEC},
|
|
|
|
{XK_KP_Separator, MP_KEY_KPDEC},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
|
|
|
// numpad without numlock
|
2013-02-12 00:34:04 +00:00
|
|
|
{XK_KP_Insert, MP_KEY_KPINS}, {XK_KP_End, MP_KEY_KP1},
|
|
|
|
{XK_KP_Down, MP_KEY_KP2}, {XK_KP_Page_Down, MP_KEY_KP3},
|
|
|
|
{XK_KP_Left, MP_KEY_KP4}, {XK_KP_Begin, MP_KEY_KP5},
|
|
|
|
{XK_KP_Right, MP_KEY_KP6}, {XK_KP_Home, MP_KEY_KP7}, {XK_KP_Up, MP_KEY_KP8},
|
|
|
|
{XK_KP_Page_Up, MP_KEY_KP9}, {XK_KP_Delete, MP_KEY_KPDEL},
|
2008-12-20 11:12:45 +00:00
|
|
|
|
2012-01-14 13:09:44 +00:00
|
|
|
#ifdef XF86XK_AudioPause
|
2013-02-12 00:34:04 +00:00
|
|
|
{XF86XK_MenuKB, MP_KEY_MENU},
|
|
|
|
{XF86XK_AudioPlay, MP_KEY_PLAY}, {XF86XK_AudioPause, MP_KEY_PAUSE},
|
|
|
|
{XF86XK_AudioStop, MP_KEY_STOP}, {XF86XK_AudioPrev, MP_KEY_PREV},
|
|
|
|
{XF86XK_AudioNext, MP_KEY_NEXT}, {XF86XK_AudioMute, MP_KEY_MUTE},
|
|
|
|
{XF86XK_AudioLowerVolume, MP_KEY_VOLUME_DOWN},
|
|
|
|
{XF86XK_AudioRaiseVolume, MP_KEY_VOLUME_UP},
|
2013-09-01 17:59:38 +00:00
|
|
|
{XF86XK_HomePage, MP_KEY_HOMEPAGE}, {XF86XK_WWW, MP_KEY_WWW},
|
|
|
|
{XF86XK_Mail, MP_KEY_MAIL}, {XF86XK_Favorites, MP_KEY_FAVORITES},
|
|
|
|
{XF86XK_Search, MP_KEY_SEARCH}, {XF86XK_Sleep, MP_KEY_SLEEP},
|
2012-01-14 13:09:44 +00:00
|
|
|
#endif
|
2008-12-20 11:12:45 +00:00
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
{0, 0}
|
2008-12-20 11:12:45 +00:00
|
|
|
};
|
|
|
|
|
2012-01-14 13:09:44 +00:00
|
|
|
static int vo_x11_lookupkey(int key)
|
2004-06-14 04:53:03 +00:00
|
|
|
{
|
2008-12-20 10:25:13 +00:00
|
|
|
static const char *passthrough_keys = " -+*/<>`~!@#$%^&()_{}:;\"\',.?\\|=[]";
|
2008-12-20 11:12:45 +00:00
|
|
|
int mpkey = 0;
|
2008-12-20 10:25:13 +00:00
|
|
|
if ((key >= 'a' && key <= 'z') ||
|
|
|
|
(key >= 'A' && key <= 'Z') ||
|
|
|
|
(key >= '0' && key <= '9') ||
|
2013-02-13 15:33:01 +00:00
|
|
|
(key > 0 && key < 256 && strchr(passthrough_keys, key)))
|
2008-12-20 11:12:45 +00:00
|
|
|
mpkey = key;
|
2008-12-20 10:25:13 +00:00
|
|
|
|
2008-12-20 11:52:11 +00:00
|
|
|
if (!mpkey)
|
2008-12-21 04:11:51 +00:00
|
|
|
mpkey = lookup_keymap_table(keymap, key);
|
2001-04-12 00:05:41 +00:00
|
|
|
|
2012-01-14 13:09:44 +00:00
|
|
|
return mpkey;
|
2001-03-03 21:47:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
static void vo_x11_decoration(struct vo *vo, int d)
|
2001-03-03 21:47:37 +00:00
|
|
|
{
|
2008-04-21 01:09:26 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2004-06-14 04:53:03 +00:00
|
|
|
Atom mtype;
|
|
|
|
int mformat;
|
|
|
|
unsigned long mn, mb;
|
2013-01-26 21:37:47 +00:00
|
|
|
Atom vo_MotifHints;
|
|
|
|
MotifWmHints vo_MotifWmHints;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (!vo->opts->WinID)
|
2004-06-14 04:53:03 +00:00
|
|
|
return;
|
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->fsmode & 8) {
|
2008-04-21 01:09:26 +00:00
|
|
|
XSetTransientForHint(x11->display, x11->window,
|
2008-04-21 01:59:00 +00:00
|
|
|
RootWindow(x11->display, x11->screen));
|
2002-03-08 20:14:08 +00:00
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2008-04-21 01:09:26 +00:00
|
|
|
vo_MotifHints = XInternAtom(x11->display, "_MOTIF_WM_HINTS", 0);
|
2013-02-13 15:33:01 +00:00
|
|
|
if (vo_MotifHints != None) {
|
2013-10-27 22:22:46 +00:00
|
|
|
if (!x11->got_motif_hints) {
|
2004-06-14 04:53:03 +00:00
|
|
|
MotifWmHints *mhints = NULL;
|
|
|
|
|
2008-04-21 01:09:26 +00:00
|
|
|
XGetWindowProperty(x11->display, x11->window,
|
|
|
|
vo_MotifHints, 0, 20, False,
|
2004-06-14 04:53:03 +00:00
|
|
|
vo_MotifHints, &mtype, &mformat, &mn,
|
|
|
|
&mb, (unsigned char **) &mhints);
|
2013-02-13 15:33:01 +00:00
|
|
|
if (mhints) {
|
2004-06-14 04:53:03 +00:00
|
|
|
if (mhints->flags & MWM_HINTS_DECORATIONS)
|
2008-04-21 01:09:26 +00:00
|
|
|
x11->olddecor = mhints->decorations;
|
2004-06-14 04:53:03 +00:00
|
|
|
if (mhints->flags & MWM_HINTS_FUNCTIONS)
|
2008-04-21 01:09:26 +00:00
|
|
|
x11->oldfuncs = mhints->functions;
|
2004-06-14 04:53:03 +00:00
|
|
|
XFree(mhints);
|
|
|
|
}
|
|
|
|
}
|
2013-10-27 22:22:46 +00:00
|
|
|
x11->got_motif_hints = true;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
|
|
|
memset(&vo_MotifWmHints, 0, sizeof(MotifWmHints));
|
|
|
|
vo_MotifWmHints.flags =
|
|
|
|
MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
|
2013-02-13 15:33:01 +00:00
|
|
|
if (d) {
|
2008-04-21 01:09:26 +00:00
|
|
|
vo_MotifWmHints.functions = x11->oldfuncs;
|
|
|
|
d = x11->olddecor;
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
|
|
|
vo_MotifWmHints.decorations =
|
2013-03-04 21:41:27 +00:00
|
|
|
d | ((vo->opts->fsmode & 2) ? MWM_DECOR_MENU : 0);
|
2008-04-21 01:09:26 +00:00
|
|
|
XChangeProperty(x11->display, x11->window, vo_MotifHints,
|
|
|
|
vo_MotifHints, 32,
|
2004-06-14 04:53:03 +00:00
|
|
|
PropModeReplace,
|
|
|
|
(unsigned char *) &vo_MotifWmHints,
|
2013-03-04 21:41:27 +00:00
|
|
|
(vo->opts->fsmode & 4) ? 4 : 5);
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
2001-03-03 21:47:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
static void vo_x11_classhint(struct vo *vo, Window window, const char *name)
|
2004-06-14 04:53:03 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2008-04-20 23:50:40 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2004-06-14 04:53:03 +00:00
|
|
|
XClassHint wmClass;
|
|
|
|
pid_t pid = getpid();
|
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
wmClass.res_name = opts->winname ? opts->winname : (char *)name;
|
2012-10-11 00:04:08 +00:00
|
|
|
wmClass.res_class = "mpv";
|
2008-04-20 23:50:40 +00:00
|
|
|
XSetClassHint(x11->display, window, &wmClass);
|
|
|
|
XChangeProperty(x11->display, window, x11->XA_NET_WM_PID, XA_CARDINAL,
|
|
|
|
32, PropModeReplace, (unsigned char *) &pid, 1);
|
2001-06-17 01:22:09 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 06:34:27 +00:00
|
|
|
void vo_x11_uninit(struct vo *vo)
|
2002-01-31 11:15:54 +00:00
|
|
|
{
|
2008-04-21 00:14:37 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2013-01-26 21:37:47 +00:00
|
|
|
assert(x11);
|
|
|
|
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_INPUT_RELEASE_ALL);
|
2013-04-03 23:13:56 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
saver_on(x11);
|
2008-04-21 00:14:37 +00:00
|
|
|
if (x11->window != None)
|
2013-05-16 21:24:56 +00:00
|
|
|
vo_set_cursor_hidden(vo, false);
|
2002-02-17 12:34:29 +00:00
|
|
|
|
2010-06-14 19:17:38 +00:00
|
|
|
if (x11->f_gc != None)
|
2008-04-21 01:19:43 +00:00
|
|
|
XFreeGC(vo->x11->display, x11->f_gc);
|
2013-01-26 21:37:47 +00:00
|
|
|
if (x11->vo_gc != None)
|
|
|
|
XFreeGC(vo->x11->display, x11->vo_gc);
|
2013-10-30 21:09:40 +00:00
|
|
|
if (x11->window != None && x11->window != x11->rootwin) {
|
2013-01-26 21:37:47 +00:00
|
|
|
XClearWindow(x11->display, x11->window);
|
2013-02-24 22:35:13 +00:00
|
|
|
XUnmapWindow(x11->display, x11->window);
|
|
|
|
|
|
|
|
XSelectInput(x11->display, x11->window, StructureNotifyMask);
|
|
|
|
XDestroyWindow(x11->display, x11->window);
|
|
|
|
XEvent xev;
|
|
|
|
do {
|
|
|
|
XNextEvent(x11->display, &xev);
|
|
|
|
} while (xev.type != DestroyNotify ||
|
2013-10-30 20:58:55 +00:00
|
|
|
xev.xdestroywindow.event != x11->window);
|
2013-01-26 21:37:47 +00:00
|
|
|
}
|
|
|
|
if (x11->xic)
|
|
|
|
XDestroyIC(x11->xic);
|
2013-01-27 11:01:08 +00:00
|
|
|
if (x11->colormap != None)
|
|
|
|
XFreeColormap(vo->x11->display, x11->colormap);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "uninit ...\n");
|
2013-01-26 21:37:47 +00:00
|
|
|
if (x11->xim)
|
|
|
|
XCloseIM(x11->xim);
|
|
|
|
XSetErrorHandler(NULL);
|
|
|
|
XCloseDisplay(x11->display);
|
2012-01-14 13:09:44 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
talloc_free(x11);
|
2012-08-03 03:55:02 +00:00
|
|
|
vo->x11 = NULL;
|
2002-01-31 11:15:54 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 18:47:34 +00:00
|
|
|
static void update_vo_size(struct vo *vo)
|
2010-07-01 19:48:00 +00:00
|
|
|
{
|
2013-02-15 18:47:34 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
|
|
|
|
if (x11->win_width != vo->dwidth || x11->win_height != vo->dheight) {
|
|
|
|
vo->dwidth = x11->win_width;
|
|
|
|
vo->dheight = x11->win_height;
|
|
|
|
x11->pending_vo_events |= VO_EVENT_RESIZE;
|
|
|
|
}
|
2010-07-01 19:48:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-21 16:07:09 +00:00
|
|
|
static int get_mods(unsigned int state)
|
|
|
|
{
|
|
|
|
int modifiers = 0;
|
|
|
|
if (state & ShiftMask)
|
|
|
|
modifiers |= MP_KEY_MODIFIER_SHIFT;
|
|
|
|
if (state & ControlMask)
|
|
|
|
modifiers |= MP_KEY_MODIFIER_CTRL;
|
|
|
|
if (state & Mod1Mask)
|
|
|
|
modifiers |= MP_KEY_MODIFIER_ALT;
|
|
|
|
if (state & Mod4Mask)
|
|
|
|
modifiers |= MP_KEY_MODIFIER_META;
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
2008-04-20 06:34:27 +00:00
|
|
|
int vo_x11_check_events(struct vo *vo)
|
2004-06-14 04:53:03 +00:00
|
|
|
{
|
2008-04-20 23:50:40 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2008-04-20 06:34:27 +00:00
|
|
|
Display *display = vo->x11->display;
|
2004-06-14 04:53:03 +00:00
|
|
|
XEvent Event;
|
2002-04-16 17:41:29 +00:00
|
|
|
|
2013-03-01 10:17:56 +00:00
|
|
|
xscreensaver_heartbeat(vo->x11);
|
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID > 0)
|
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
|
|
|
vo_x11_update_geometry(vo);
|
2013-02-13 15:33:01 +00:00
|
|
|
while (XPending(display)) {
|
2008-04-20 06:34:27 +00:00
|
|
|
XNextEvent(display, &Event);
|
2002-05-14 23:44:35 +00:00
|
|
|
// printf("\rEvent.type=%X \n",Event.type);
|
2013-02-13 15:33:01 +00:00
|
|
|
switch (Event.type) {
|
|
|
|
case Expose:
|
2013-02-15 18:47:34 +00:00
|
|
|
x11->pending_vo_events |= VO_EVENT_EXPOSE;
|
2013-02-13 15:33:01 +00:00
|
|
|
break;
|
|
|
|
case ConfigureNotify:
|
|
|
|
if (x11->window == None)
|
2004-06-14 04:53:03 +00:00
|
|
|
break;
|
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
|
|
|
vo_x11_update_geometry(vo);
|
2013-02-13 15:33:01 +00:00
|
|
|
break;
|
|
|
|
case KeyPress: {
|
|
|
|
char buf[100];
|
|
|
|
KeySym keySym = 0;
|
2013-07-21 16:07:09 +00:00
|
|
|
int modifiers = get_mods(Event.xkey.state);
|
2013-04-03 23:13:56 +00:00
|
|
|
if (x11->no_autorepeat)
|
|
|
|
modifiers |= MP_KEY_STATE_DOWN;
|
2013-02-13 15:33:01 +00:00
|
|
|
if (x11->xic) {
|
|
|
|
Status status;
|
|
|
|
int len = Xutf8LookupString(x11->xic, &Event.xkey, buf,
|
|
|
|
sizeof(buf), &keySym, &status);
|
|
|
|
int mpkey = vo_x11_lookupkey(keySym);
|
|
|
|
if (mpkey) {
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, mpkey | modifiers);
|
2013-02-13 15:33:01 +00:00
|
|
|
} else if (status == XLookupChars || status == XLookupBoth) {
|
|
|
|
struct bstr t = { buf, len };
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key_utf8(vo->input_ctx, modifiers, t);
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
2013-02-13 15:33:01 +00:00
|
|
|
} else {
|
|
|
|
XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
|
|
|
|
&x11->compose_status);
|
|
|
|
int mpkey = vo_x11_lookupkey(keySym);
|
|
|
|
if (mpkey)
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, mpkey | modifiers);
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
2013-04-03 23:13:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Releasing all keys in these situations is simpler and ensures no
|
|
|
|
// keys can be get "stuck".
|
|
|
|
case FocusOut:
|
|
|
|
case KeyRelease:
|
|
|
|
{
|
|
|
|
if (x11->no_autorepeat)
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_INPUT_RELEASE_ALL);
|
2013-04-03 23:13:56 +00:00
|
|
|
break;
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
|
|
|
case MotionNotify:
|
|
|
|
vo_mouse_movement(vo, Event.xmotion.x, Event.xmotion.y);
|
|
|
|
break;
|
2013-06-19 16:19:45 +00:00
|
|
|
case LeaveNotify:
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_MOUSE_LEAVE);
|
2013-06-19 16:19:45 +00:00
|
|
|
break;
|
2013-02-13 15:33:01 +00:00
|
|
|
case ButtonPress:
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx,
|
2013-07-21 16:07:09 +00:00
|
|
|
(MP_MOUSE_BTN0 + Event.xbutton.button - 1) |
|
|
|
|
get_mods(Event.xbutton.state) | MP_KEY_STATE_DOWN);
|
2013-02-13 15:33:01 +00:00
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx,
|
2013-07-21 16:07:09 +00:00
|
|
|
(MP_MOUSE_BTN0 + Event.xbutton.button - 1) |
|
|
|
|
get_mods(Event.xbutton.state) | MP_KEY_STATE_UP);
|
2013-02-13 15:33:01 +00:00
|
|
|
break;
|
|
|
|
case PropertyNotify: {
|
|
|
|
char *name = XGetAtomName(display, Event.xproperty.atom);
|
|
|
|
if (!name)
|
2004-06-14 04:53:03 +00:00
|
|
|
break;
|
2013-02-13 15:33:01 +00:00
|
|
|
XFree(name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MapNotify:
|
|
|
|
x11->vo_hint.win_gravity = x11->old_gravity;
|
|
|
|
XSetWMNormalHints(display, x11->window, &x11->vo_hint);
|
|
|
|
x11->fs_flip = 0;
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_WARN(x11, "Our window was destroyed, exiting\n");
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_CLOSE_WIN);
|
2013-02-13 15:33:01 +00:00
|
|
|
break;
|
|
|
|
case ClientMessage:
|
|
|
|
if (Event.xclient.message_type == x11->XAWM_PROTOCOLS &&
|
|
|
|
Event.xclient.data.l[0] == x11->XAWM_DELETE_WINDOW)
|
2013-07-02 12:04:36 +00:00
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_CLOSE_WIN);
|
2013-02-13 15:33:01 +00:00
|
|
|
break;
|
2013-01-02 11:55:52 +00:00
|
|
|
default:
|
2013-02-13 15:33:01 +00:00
|
|
|
if (Event.type == x11->ShmCompletionEvent) {
|
|
|
|
if (x11->ShmCompletionWaitCount > 0)
|
|
|
|
x11->ShmCompletionWaitCount--;
|
|
|
|
}
|
|
|
|
break;
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-02 21:50:09 +00:00
|
|
|
|
2013-02-15 18:47:34 +00:00
|
|
|
update_vo_size(vo);
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0 && (x11->pending_vo_events & VO_EVENT_RESIZE)) {
|
2013-02-15 18:47:34 +00:00
|
|
|
int x = x11->win_x, y = x11->win_y;
|
|
|
|
unsigned int w = x11->win_width, h = x11->win_height;
|
2013-02-24 22:35:13 +00:00
|
|
|
XMoveResizeWindow(x11->display, x11->window, x, y, w, h);
|
|
|
|
}
|
2013-02-15 18:47:34 +00:00
|
|
|
int ret = x11->pending_vo_events;
|
|
|
|
x11->pending_vo_events = 0;
|
2004-06-14 04:53:03 +00:00
|
|
|
return ret;
|
2001-03-03 21:47:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
static void vo_x11_sizehint(struct vo *vo, int x, int y, int width, int height,
|
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 override_pos)
|
2002-03-08 20:14:08 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2008-04-21 00:14:37 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
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
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
bool force_pos = opts->geometry.xy_valid || // explicitly forced by user
|
|
|
|
opts->force_window_position || // resize -> reset position
|
|
|
|
opts->screen_id >= 0 || // force onto screen area
|
|
|
|
opts->WinID >= 0 || // force to fill parent
|
|
|
|
override_pos; // for fullscreen and such
|
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
|
|
|
|
2008-04-21 01:19:43 +00:00
|
|
|
x11->vo_hint.flags = 0;
|
2013-03-04 21:41:27 +00:00
|
|
|
if (opts->keepaspect) {
|
2008-04-21 01:19:43 +00:00
|
|
|
x11->vo_hint.flags |= PAspect;
|
|
|
|
x11->vo_hint.min_aspect.x = width;
|
|
|
|
x11->vo_hint.min_aspect.y = height;
|
|
|
|
x11->vo_hint.max_aspect.x = width;
|
|
|
|
x11->vo_hint.max_aspect.y = height;
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
x11->vo_hint.flags |= PSize | (force_pos ? PPosition : 0);
|
2008-04-21 01:19:43 +00:00
|
|
|
x11->vo_hint.x = x;
|
|
|
|
x11->vo_hint.y = y;
|
|
|
|
x11->vo_hint.width = width;
|
|
|
|
x11->vo_hint.height = height;
|
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
|
|
|
x11->vo_hint.max_width = 0;
|
|
|
|
x11->vo_hint.max_height = 0;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
libvo, libao: remove useless video and audio output drivers
Some of these have only limited use, and some of these have no use at
all. Remove them. They make maintainance harder and nobody needs them.
It's possible that many of the removed drivers were very useful a dozen
of years ago, but now it's 2012.
Note that some of these could be added back, in case they were more
useful than I thought. But right now, they are just a burden.
Reason for removal for each module:
vo_3dfx, vo_dfbmga, vo_dxr3, vo_ivtv, vo_mga, vo_s3fb,
vo_tdfxfb, vo_xmga, vo_tdfx_vid:
All of these are for very specific and outdated hardware. Some
of them require non-standard kernel drivers or do direct HW
access.
vo_dga: the most crappy and ancient way to get fast output on X.
vo_aa: there's vo_caca for the same purpose.
vo_ggi: this never lived, and is entirely useless.
vo_mpegpes: for DVB cards, I can't test this and it's crappy.
vo_fbdev, vo_fbdev2: there's vo_directfb2
vo_bl: what is this even? But it's neither important, nor alive.
vo_svga, vo_vesa: you want to use this? You can't be serious.
vo_wii: I can't test this, and who the hell uses this?
vo_xvr100: some Sun thing.
vo_xover: only useful in connection with xvr100.
ao_nas: still alive, but I doubt it has any meaning today.
ao_sun: Sun.
ao_win32: use ao_dsound or ao_portaudio instead.
ao_ivtv: removed along vo_ivtv.
Also get rid of anything SDL related. SDL 1.x is total crap for video
output, and will be replaced with SDL 2.x soon (perhaps), so if you
want to use SDL, write output drivers for SDL 2.x.
Additionally, I accidentally damaged Sun support, which made me
completely remove Sun/Solaris support. Nobody cares about this anyway.
Some left overs from previous commits removing modules were cleaned up.
2012-07-28 18:20:17 +00:00
|
|
|
// Set minimum height/width to 4 to avoid off-by-one errors.
|
2008-04-21 01:19:43 +00:00
|
|
|
x11->vo_hint.flags |= PMinSize;
|
|
|
|
x11->vo_hint.min_width = x11->vo_hint.min_height = 4;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2008-12-05 19:01:49 +00:00
|
|
|
// Set the base size. A window manager might display the window
|
|
|
|
// size to the user relative to this.
|
|
|
|
// Setting these to width/height might be nice, but e.g. fluxbox can't handle it.
|
2008-12-06 00:16:51 +00:00
|
|
|
x11->vo_hint.flags |= PBaseSize;
|
|
|
|
x11->vo_hint.base_width = 0 /*width*/;
|
|
|
|
x11->vo_hint.base_height = 0 /*height*/;
|
2008-12-05 19:01:49 +00:00
|
|
|
|
2008-04-21 01:19:43 +00:00
|
|
|
x11->vo_hint.flags |= PWinGravity;
|
|
|
|
x11->vo_hint.win_gravity = StaticGravity;
|
|
|
|
XSetWMNormalHints(x11->display, x11->window, &x11->vo_hint);
|
2002-03-08 20:14:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static void vo_x11_move_resize(struct vo *vo, bool move, bool resize,
|
|
|
|
int x, int y, int w, int h)
|
2013-01-26 21:37:47 +00:00
|
|
|
{
|
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
|
|
|
XWindowChanges req = {.x = x, .y = y, .width = w, .height = h};
|
|
|
|
unsigned mask = (move ? CWX | CWY : 0) | (resize ? CWWidth | CWHeight : 0);
|
|
|
|
if (mask)
|
|
|
|
XConfigureWindow(vo->x11->display, vo->x11->window, mask, &req);
|
|
|
|
vo_x11_sizehint(vo, x, y, w, h, false);
|
2013-01-26 21:37:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 23:50:40 +00:00
|
|
|
static int vo_x11_get_gnome_layer(struct vo_x11_state *x11, Window win)
|
2003-01-09 21:23:54 +00:00
|
|
|
{
|
2004-06-14 04:53:03 +00:00
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytesafter;
|
|
|
|
unsigned short *args = NULL;
|
|
|
|
|
2008-04-20 23:50:40 +00:00
|
|
|
if (XGetWindowProperty(x11->display, win, x11->XA_WIN_LAYER, 0, 16384,
|
2004-06-14 04:53:03 +00:00
|
|
|
False, AnyPropertyType, &type, &format, &nitems,
|
|
|
|
&bytesafter,
|
|
|
|
(unsigned char **) &args) == Success
|
|
|
|
&& nitems > 0 && args)
|
|
|
|
{
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "original window layer is %d.\n", *args);
|
2004-06-14 04:53:03 +00:00
|
|
|
return *args;
|
|
|
|
}
|
|
|
|
return WIN_LAYER_NORMAL;
|
2003-01-09 21:23:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 01:01:22 +00:00
|
|
|
// set a X text property that expects a UTF8_STRING type
|
|
|
|
static void vo_x11_set_property_utf8(struct vo *vo, Atom name, const char *t)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
|
|
|
|
XChangeProperty(x11->display, x11->window, name, x11->XAUTF8_STRING, 8,
|
|
|
|
PropModeReplace, t, strlen(t));
|
|
|
|
}
|
|
|
|
|
2011-12-26 16:15:11 +00:00
|
|
|
// set a X text property that expects a STRING or COMPOUND_TEXT type
|
2011-12-06 17:48:31 +00:00
|
|
|
static void vo_x11_set_property_string(struct vo *vo, Atom name, const char *t)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
XTextProperty prop = {0};
|
|
|
|
|
2011-12-26 16:15:11 +00:00
|
|
|
if (Xutf8TextListToTextProperty(x11->display, (char **)&t, 1,
|
|
|
|
XStdICCTextStyle, &prop) == Success)
|
|
|
|
{
|
2011-12-06 17:48:31 +00:00
|
|
|
XSetTextProperty(x11->display, x11->window, &prop, name);
|
2012-01-25 01:01:22 +00:00
|
|
|
} else {
|
|
|
|
// Strictly speaking this violates the ICCCM, but there's no way we
|
|
|
|
// can do this correctly.
|
|
|
|
vo_x11_set_property_utf8(vo, name, t);
|
2011-12-26 16:15:11 +00:00
|
|
|
}
|
2011-12-06 17:48:31 +00:00
|
|
|
|
2012-01-25 01:01:22 +00:00
|
|
|
if (prop.value)
|
|
|
|
XFree(prop.value);
|
2011-12-06 17:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vo_x11_update_window_title(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
|
2013-06-15 17:04:20 +00:00
|
|
|
if (!x11->window)
|
|
|
|
return;
|
|
|
|
|
2011-12-06 17:48:31 +00:00
|
|
|
const char *title = vo_get_window_title(vo);
|
|
|
|
vo_x11_set_property_string(vo, XA_WM_NAME, title);
|
|
|
|
vo_x11_set_property_string(vo, XA_WM_ICON_NAME, title);
|
|
|
|
vo_x11_set_property_utf8(vo, x11->XA_NET_WM_NAME, title);
|
|
|
|
vo_x11_set_property_utf8(vo, x11->XA_NET_WM_ICON_NAME, title);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ZLIB
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
static bstr decompress_gz(bstr in)
|
|
|
|
{
|
|
|
|
bstr res = {0};
|
|
|
|
z_stream zstream;
|
|
|
|
uint8_t *dest;
|
|
|
|
size_t size = in.len;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
zstream.zalloc = (alloc_func) 0;
|
|
|
|
zstream.zfree = (free_func) 0;
|
|
|
|
zstream.opaque = (voidpf) 0;
|
|
|
|
// 32 for gzip header, 15 for max. window bits
|
|
|
|
if (inflateInit2(&zstream, 32 + 15) != Z_OK)
|
|
|
|
goto error;
|
|
|
|
zstream.next_in = (Bytef *) in.start;
|
|
|
|
zstream.avail_in = size;
|
|
|
|
|
|
|
|
dest = NULL;
|
|
|
|
zstream.avail_out = size;
|
|
|
|
do {
|
|
|
|
size += 4000;
|
|
|
|
dest = talloc_realloc_size(NULL, dest, size);
|
|
|
|
zstream.next_out = (Bytef *) (dest + zstream.total_out);
|
|
|
|
result = inflate(&zstream, Z_NO_FLUSH);
|
|
|
|
if (result != Z_OK && result != Z_STREAM_END) {
|
|
|
|
talloc_free(dest);
|
|
|
|
dest = NULL;
|
|
|
|
inflateEnd(&zstream);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
zstream.avail_out += 4000;
|
|
|
|
} while (zstream.avail_out == 4000 && zstream.avail_in != 0
|
|
|
|
&& result != Z_STREAM_END);
|
|
|
|
|
|
|
|
size = zstream.total_out;
|
|
|
|
inflateEnd(&zstream);
|
|
|
|
|
|
|
|
res.start = dest;
|
|
|
|
res.len = size;
|
|
|
|
error:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static bstr decompress_gz(bstr in)
|
|
|
|
{
|
|
|
|
return (bstr){0};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_ICONS 10
|
|
|
|
|
|
|
|
static void vo_x11_set_wm_icon(struct vo_x11_state *x11)
|
|
|
|
{
|
|
|
|
int num_icons = 0;
|
|
|
|
void *icon_data[MAX_ICONS];
|
|
|
|
int icon_w[MAX_ICONS], icon_h[MAX_ICONS];
|
|
|
|
|
|
|
|
bstr uncompressed = decompress_gz((bstr){(char *)x11_icon, sizeof(x11_icon)});
|
|
|
|
bstr data = uncompressed;
|
|
|
|
while (data.len && num_icons < MAX_ICONS) {
|
|
|
|
bstr line = bstr_getline(data, &data);
|
|
|
|
if (bstr_eatstart0(&line, "icon: ")) {
|
|
|
|
int w, h;
|
|
|
|
if (bstr_sscanf(line, "%d %d", &w, &h) == 2) {
|
|
|
|
int size = w * h * 4;
|
|
|
|
icon_w[num_icons] = w;
|
|
|
|
icon_h[num_icons] = h;
|
|
|
|
icon_data[num_icons] = data.start;
|
|
|
|
num_icons++;
|
|
|
|
data = bstr_cut(data, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 11:37:38 +00:00
|
|
|
int icon_size = 0;
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
for (int n = 0; n < num_icons; n++)
|
2013-09-04 11:37:38 +00:00
|
|
|
icon_size += 2 + icon_w[n] * icon_h[n];
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
long *icon = talloc_array(NULL, long, icon_size);
|
|
|
|
long *cur = icon;
|
|
|
|
for (int n = 0; n < num_icons; n++) {
|
|
|
|
*cur++ = icon_w[n];
|
|
|
|
*cur++ = icon_h[n];
|
|
|
|
uint32_t *src = icon_data[n];
|
|
|
|
for (int i = 0; i < icon_h[n] * icon_w[n]; i++)
|
|
|
|
*cur++ = src[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
XChangeProperty(x11->display, x11->window, x11->XA_NET_WM_ICON,
|
2013-09-04 11:37:38 +00:00
|
|
|
XA_CARDINAL, 32, PropModeReplace,
|
|
|
|
(unsigned char *)icon, icon_size);
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
talloc_free(icon);
|
|
|
|
talloc_free(uncompressed.start);
|
|
|
|
}
|
|
|
|
|
2013-01-27 11:01:08 +00:00
|
|
|
static void find_default_visual(struct vo_x11_state *x11, XVisualInfo *vis)
|
|
|
|
{
|
|
|
|
Display *display = x11->display;
|
|
|
|
XWindowAttributes attribs;
|
|
|
|
XGetWindowAttributes(display, DefaultRootWindow(display), &attribs);
|
|
|
|
XMatchVisualInfo(display, x11->screen, attribs.depth, TrueColor, vis);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static void vo_x11_create_window(struct vo *vo, XVisualInfo *vis, int x, int y,
|
|
|
|
unsigned int w, unsigned int h)
|
2013-01-27 11:01:08 +00:00
|
|
|
{
|
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
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
|
|
|
|
assert(x11->window == None);
|
|
|
|
assert(!x11->xic);
|
|
|
|
|
|
|
|
XVisualInfo vinfo_storage;
|
|
|
|
if (!vis) {
|
|
|
|
vis = &vinfo_storage;
|
|
|
|
find_default_visual(x11, vis);
|
|
|
|
}
|
|
|
|
|
2013-09-29 22:37:44 +00:00
|
|
|
if (x11->colormap == None) {
|
|
|
|
x11->colormap = XCreateColormap(x11->display, x11->rootwin,
|
|
|
|
vis->visual, AllocNone);
|
|
|
|
}
|
|
|
|
|
2013-04-15 19:18:46 +00:00
|
|
|
unsigned long xswamask = CWBorderPixel | CWColormap;
|
|
|
|
XSetWindowAttributes xswa = {
|
|
|
|
.border_pixel = 0,
|
|
|
|
.colormap = x11->colormap,
|
|
|
|
};
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
Window parent = vo->opts->WinID >= 0 ? vo->opts->WinID : x11->rootwin;
|
2013-02-24 22:35:13 +00:00
|
|
|
|
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
|
|
|
x11->window =
|
|
|
|
XCreateWindow(x11->display, parent, x, y, w, h, 0, vis->depth,
|
2013-02-24 22:35:13 +00:00
|
|
|
CopyFromParent, vis->visual, xswamask, &xswa);
|
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
|
|
|
XSetWMProtocols(x11->display, x11->window, &x11->XAWM_DELETE_WINDOW, 1);
|
|
|
|
x11->f_gc = XCreateGC(x11->display, x11->window, 0, 0);
|
|
|
|
x11->vo_gc = XCreateGC(x11->display, x11->window, 0, NULL);
|
2008-04-21 01:19:43 +00:00
|
|
|
XSetForeground(x11->display, x11->f_gc, 0);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-05-16 21:24:56 +00:00
|
|
|
if (x11->mouse_cursor_hidden) {
|
|
|
|
x11->mouse_cursor_hidden = false;
|
|
|
|
vo_set_cursor_hidden(vo, true);
|
|
|
|
}
|
2013-09-20 12:45:49 +00:00
|
|
|
if (x11->xim) {
|
|
|
|
x11->xic = XCreateIC(x11->xim,
|
|
|
|
XNInputStyle, XIMPreeditNone | XIMStatusNone,
|
|
|
|
XNClientWindow, x11->window,
|
|
|
|
XNFocusWindow, x11->window,
|
|
|
|
NULL);
|
|
|
|
}
|
2013-06-15 17:04:20 +00:00
|
|
|
|
x11: add window icon
The png file added to etc/ are taken from the link mentioned in commit
303096b, except that they have been converted to 16 bit, sRGB (with
color profile info dropped, if there was one), and transparent pixels
reset for better compression.
The file x11_icon.bin is generated by gen-x11-icon.sh. I'm adding it to
the git repo directly, because the script requires ImageMagick, and we
don't want to make building even more complicated.
The way how this is done is basically a compromise between effort
required in x11_common.c and in gen-x11-icon.sh. Ideally, x11_icon.bin
would be directly in the format as required by _NET_WM_ICON, but trying
to write the binary width/height values from shell would probably be a
nightmare, so here we go.
The zlib code in x11_common.c is lifted from demux_mkv.c, with some
modifications (like accepting a gzip header, because I don't know how to
make gzip write raw compressed data).
2013-09-01 21:26:44 +00:00
|
|
|
vo_x11_set_wm_icon(x11);
|
2013-06-15 17:04:20 +00:00
|
|
|
vo_x11_update_window_title(vo);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void vo_x11_map_window(struct vo *vo, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
|
|
|
|
x11->window_hidden = false;
|
|
|
|
vo_x11_move_resize(vo, true, true, x, y, w, h);
|
2013-03-04 21:41:27 +00:00
|
|
|
if (!vo->opts->border)
|
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
|
|
|
vo_x11_decoration(vo, 0);
|
|
|
|
// map window
|
2013-03-04 16:40:21 +00:00
|
|
|
vo_x11_selectinput_witherr(vo, x11->display, x11->window,
|
2013-06-19 16:19:45 +00:00
|
|
|
StructureNotifyMask | ExposureMask |
|
2013-04-03 23:13:56 +00:00
|
|
|
KeyPressMask | KeyReleaseMask |
|
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
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
2013-10-15 19:49:01 +00:00
|
|
|
PointerMotionMask | LeaveWindowMask);
|
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
|
|
|
XMapWindow(x11->display, x11->window);
|
|
|
|
vo_x11_clearwindow(vo, x11->window);
|
2003-08-31 22:27:10 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 18:51:46 +00:00
|
|
|
static void vo_x11_highlevel_resize(struct vo *vo, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
|
|
|
|
bool reset_pos = opts->force_window_position;
|
|
|
|
if (reset_pos) {
|
|
|
|
x11->nofs_x = x;
|
|
|
|
x11->nofs_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
x11->nofs_width = w;
|
|
|
|
x11->nofs_height = h;
|
|
|
|
|
|
|
|
if (opts->fullscreen) {
|
|
|
|
x11->size_changed_during_fs = true;
|
|
|
|
x11->pos_changed_during_fs = reset_pos;
|
|
|
|
vo_x11_sizehint(vo, x, y, w, h, false);
|
|
|
|
} else {
|
|
|
|
vo_x11_move_resize(vo, reset_pos, true, x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
vo_x11_update_geometry(vo);
|
|
|
|
update_vo_size(vo);
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
/* Create and setup a window suitable for display
|
|
|
|
* vis: Visual to use for creating the window (NULL for default)
|
|
|
|
* x, y: position of window (might be ignored)
|
|
|
|
* width, height: size of window
|
|
|
|
* flags: flags for window creation (VOFLAG_*)
|
|
|
|
* classname: name to use for the X11 classhint
|
2007-06-27 10:26:13 +00:00
|
|
|
*
|
2013-02-13 15:33:01 +00:00
|
|
|
* If the window already exists, it just moves and resizes it.
|
2007-06-27 10:26:13 +00:00
|
|
|
*/
|
2013-02-24 22:32:51 +00:00
|
|
|
void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y,
|
2007-06-27 10:26:13 +00:00
|
|
|
unsigned int width, unsigned int height, int flags,
|
2013-01-27 11:01:08 +00:00
|
|
|
const char *classname)
|
2007-06-27 10:26:13 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-02-13 15:33:01 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
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
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if (opts->WinID >= 0) {
|
2013-10-30 21:09:40 +00:00
|
|
|
if (opts->WinID == 0)
|
|
|
|
x11->window = x11->rootwin;
|
2013-03-04 21:41:27 +00:00
|
|
|
XSelectInput(x11->display, opts->WinID, StructureNotifyMask);
|
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
|
|
|
vo_x11_update_geometry(vo);
|
2013-02-15 18:47:34 +00:00
|
|
|
x = x11->win_x; y = x11->win_y;
|
|
|
|
width = x11->win_width; height = x11->win_height;
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
|
|
|
if (x11->window == None) {
|
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
|
|
|
vo_x11_create_window(vo, vis, x, y, width, height);
|
|
|
|
vo_x11_classhint(vo, x11->window, classname);
|
|
|
|
x11->window_hidden = true;
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
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
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
if (flags & VOFLAG_HIDDEN)
|
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
|
|
|
return;
|
|
|
|
|
2013-10-31 18:51:46 +00:00
|
|
|
bool reset_size = x11->old_dwidth != width || x11->old_dheight != height;
|
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
|
|
|
x11->old_dwidth = width;
|
|
|
|
x11->old_dheight = height;
|
|
|
|
|
2013-10-31 18:51:46 +00:00
|
|
|
if (x11->window_hidden) {
|
|
|
|
x11->nofs_x = x;
|
|
|
|
x11->nofs_y = y;
|
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
|
|
|
x11->nofs_width = width;
|
|
|
|
x11->nofs_height = height;
|
|
|
|
vo_x11_map_window(vo, x, y, width, height);
|
|
|
|
} else if (reset_size) {
|
2013-10-31 18:51:46 +00:00
|
|
|
vo_x11_highlevel_resize(vo, x, y, width, height);
|
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
|
|
|
}
|
|
|
|
|
2013-08-13 22:34:49 +00:00
|
|
|
if (opts->ontop)
|
|
|
|
vo_x11_setlayer(vo, x11->window, opts->ontop);
|
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
vo_x11_fullscreen(vo);
|
2011-05-29 23:05:57 +00:00
|
|
|
|
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
|
|
|
XSync(x11->display, False);
|
2013-02-15 18:47:34 +00:00
|
|
|
|
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
|
|
|
vo_x11_update_geometry(vo);
|
2013-02-15 18:47:34 +00:00
|
|
|
update_vo_size(vo);
|
|
|
|
x11->pending_vo_events &= ~VO_EVENT_RESIZE; // implicitly done by the VO
|
2007-06-27 10:26:13 +00:00
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
static void fill_rect(struct vo *vo, GC gc, int x0, int y0, int x1, int y1)
|
2003-08-31 22:27:10 +00:00
|
|
|
{
|
2008-04-21 01:19:43 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
x0 = FFMAX(x0, 0);
|
|
|
|
y0 = FFMAX(y0, 0);
|
|
|
|
x1 = FFMIN(x1, x11->win_width);
|
|
|
|
y1 = FFMIN(y1, x11->win_height);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
if (x11->window && x1 > x0 && y1 > y0)
|
|
|
|
XFillRectangle(x11->display, x11->window, gc, x0, y0, x1 - x0, y1 - y0);
|
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
// Clear everything outside of rc with the background color
|
|
|
|
void vo_x11_clear_background(struct vo *vo, const struct mp_rect *rc)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
GC gc = x11->f_gc;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
int w = x11->win_width;
|
|
|
|
int h = x11->win_height;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
fill_rect(vo, gc, 0, 0, w, rc->y0); // top
|
|
|
|
fill_rect(vo, gc, 0, rc->y1, w, h); // bottom
|
|
|
|
fill_rect(vo, gc, 0, rc->y0, rc->x0, rc->y1); // left
|
|
|
|
fill_rect(vo, gc, rc->x1, rc->y0, w, rc->y1); // right
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-03-17 22:01:33 +00:00
|
|
|
XFlush(x11->display);
|
2003-08-31 22:27:10 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 23:18:28 +00:00
|
|
|
void vo_x11_clearwindow(struct vo *vo, Window vo_window)
|
2003-08-31 22:27:10 +00:00
|
|
|
{
|
2008-04-21 01:19:43 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2010-06-14 19:17:38 +00:00
|
|
|
if (x11->f_gc == None)
|
2004-06-14 04:53:03 +00:00
|
|
|
return;
|
2008-04-21 01:19:43 +00:00
|
|
|
XFillRectangle(x11->display, vo_window, x11->f_gc, 0, 0,
|
2013-03-04 21:41:27 +00:00
|
|
|
opts->screenwidth, opts->screenheight);
|
2008-04-21 01:19:43 +00:00
|
|
|
XFlush(x11->display);
|
2003-08-31 22:27:10 +00:00
|
|
|
}
|
|
|
|
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
static void vo_x11_setlayer(struct vo *vo, Window vo_window, int layer)
|
2002-05-06 15:05:07 +00:00
|
|
|
{
|
2008-04-20 23:50:40 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0)
|
2004-06-14 04:53:03 +00:00
|
|
|
return;
|
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
if (x11->fs_type & vo_wm_LAYER) {
|
2004-06-14 04:53:03 +00:00
|
|
|
XClientMessageEvent xev;
|
|
|
|
|
2008-04-21 01:37:46 +00:00
|
|
|
if (!x11->orig_layer)
|
|
|
|
x11->orig_layer = vo_x11_get_gnome_layer(x11, vo_window);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.display = x11->display;
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.window = vo_window;
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.message_type = x11->XA_WIN_LAYER;
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.format = 32;
|
2013-01-26 21:37:47 +00:00
|
|
|
// if not fullscreen, stay on default layer
|
|
|
|
xev.data.l[0] = layer ? x11->fs_layer : x11->orig_layer;
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.data.l[1] = CurrentTime;
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Layered style stay on top (layer %ld).\n",
|
|
|
|
xev.data.l[0]);
|
2008-04-21 01:59:00 +00:00
|
|
|
XSendEvent(x11->display, x11->rootwin, False, SubstructureNotifyMask,
|
2013-02-13 15:33:01 +00:00
|
|
|
(XEvent *) &xev);
|
|
|
|
} else if (x11->fs_type & vo_wm_NETWM) {
|
2004-06-14 04:53:03 +00:00
|
|
|
XClientMessageEvent xev;
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.type = ClientMessage;
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.message_type = x11->XA_NET_WM_STATE;
|
|
|
|
xev.display = x11->display;
|
2004-06-14 04:53:03 +00:00
|
|
|
xev.window = vo_window;
|
|
|
|
xev.format = 32;
|
|
|
|
xev.data.l[0] = layer;
|
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
if (x11->fs_type & vo_wm_STAYS_ON_TOP) {
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.data.l[1] = x11->XA_NET_WM_STATE_STAYS_ON_TOP;
|
2013-02-13 15:33:01 +00:00
|
|
|
} else if (x11->fs_type & vo_wm_ABOVE) {
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.data.l[1] = x11->XA_NET_WM_STATE_ABOVE;
|
2013-02-13 15:33:01 +00:00
|
|
|
} else if (x11->fs_type & vo_wm_FULLSCREEN) {
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.data.l[1] = x11->XA_NET_WM_STATE_FULLSCREEN;
|
2013-02-13 15:33:01 +00:00
|
|
|
} else if (x11->fs_type & vo_wm_BELOW) {
|
2007-01-18 09:03:42 +00:00
|
|
|
// This is not fallback. We can safely assume that the situation
|
|
|
|
// where only NETWM_STATE_BELOW is supported doesn't exist.
|
2008-04-20 23:50:40 +00:00
|
|
|
xev.data.l[1] = x11->XA_NET_WM_STATE_BELOW;
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2008-04-21 01:59:00 +00:00
|
|
|
XSendEvent(x11->display, x11->rootwin, False, SubstructureRedirectMask,
|
2013-02-13 15:33:01 +00:00
|
|
|
(XEvent *) &xev);
|
2008-04-20 23:50:40 +00:00
|
|
|
state = XGetAtomName(x11->display, xev.data.l[1]);
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "NET style stay on top (layer %d). Using state %s.\n",
|
|
|
|
layer, state);
|
2004-06-14 04:53:03 +00:00
|
|
|
XFree(state);
|
|
|
|
}
|
2002-05-06 15:05:07 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 18:47:34 +00:00
|
|
|
// update x11->win_x, x11->win_y, x11->win_width and x11->win_height with current values of vo->x11->window
|
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
|
|
|
static void vo_x11_update_geometry(struct vo *vo)
|
2008-11-17 18:50:23 +00:00
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2013-01-26 21:37:47 +00:00
|
|
|
unsigned w, h, dummy_uint;
|
2008-11-15 17:45:55 +00:00
|
|
|
int dummy_int;
|
|
|
|
Window dummy_win;
|
2013-10-30 21:09:40 +00:00
|
|
|
Window win = vo->opts->WinID > 0 ? vo->opts->WinID : x11->window;
|
2013-02-24 22:35:13 +00:00
|
|
|
XGetGeometry(x11->display, win, &dummy_win, &dummy_int, &dummy_int,
|
2013-01-26 21:37:47 +00:00
|
|
|
&w, &h, &dummy_int, &dummy_uint);
|
2008-11-17 18:50:23 +00:00
|
|
|
if (w <= INT_MAX && h <= INT_MAX) {
|
2013-02-15 18:47:34 +00:00
|
|
|
x11->win_width = w;
|
|
|
|
x11->win_height = h;
|
2008-11-17 18:50:23 +00:00
|
|
|
}
|
2013-03-04 21:41:27 +00:00
|
|
|
if (vo->opts->WinID >= 0) {
|
2013-02-15 18:47:34 +00:00
|
|
|
x11->win_x = 0;
|
|
|
|
x11->win_y = 0;
|
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
|
|
|
} else {
|
2011-02-03 19:49:12 +00:00
|
|
|
XTranslateCoordinates(x11->display, x11->window, x11->rootwin, 0, 0,
|
2013-02-15 18:47:34 +00:00
|
|
|
&x11->win_x, &x11->win_y, &dummy_win);
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
2008-11-15 17:45:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 12:02:28 +00:00
|
|
|
static void vo_x11_fullscreen(struct vo *vo)
|
2002-03-07 17:50:25 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2008-04-20 06:34:27 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2004-06-14 04:53:03 +00:00
|
|
|
int x, y, w, h;
|
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
if (opts->fullscreen == x11->fs)
|
|
|
|
return;
|
2013-03-04 21:41:27 +00:00
|
|
|
if (opts->WinID >= 0) {
|
2013-07-18 12:05:39 +00:00
|
|
|
x11->fs = opts->fullscreen;
|
2009-08-27 12:03:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-04 16:49:35 +00:00
|
|
|
if (x11->fs_flip)
|
2004-06-14 04:53:03 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
if (!opts->fullscreen) {
|
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
|
|
|
// fs->win
|
2013-07-18 12:05:39 +00:00
|
|
|
opts->fullscreen = x11->fs = 0;
|
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
|
|
|
|
|
|
|
x = x11->nofs_x;
|
|
|
|
y = x11->nofs_y;
|
|
|
|
w = x11->nofs_width;
|
|
|
|
h = x11->nofs_height;
|
|
|
|
|
2008-04-21 00:14:37 +00:00
|
|
|
vo_x11_ewmh_fullscreen(x11, _NET_WM_STATE_REMOVE); // removes fullscreen state if wm supports EWMH
|
2013-03-04 21:41:27 +00:00
|
|
|
if ((x11->fs_type & vo_wm_FULLSCREEN) && opts->fsscreen_id != -1) {
|
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
|
|
|
x11->size_changed_during_fs = true;
|
|
|
|
x11->pos_changed_during_fs = true;
|
2013-02-17 15:35:44 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
if (x11->fs_type & vo_wm_FULLSCREEN) {
|
|
|
|
vo_x11_move_resize(vo, x11->pos_changed_during_fs,
|
|
|
|
x11->size_changed_during_fs, x, y, w, h);
|
2013-02-13 15:33:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-06-14 04:53:03 +00:00
|
|
|
// win->fs
|
2013-07-18 12:05:39 +00:00
|
|
|
opts->fullscreen = x11->fs = 1;
|
2013-02-17 15:35:44 +00:00
|
|
|
|
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
|
|
|
vo_x11_update_geometry(vo);
|
|
|
|
x11->nofs_x = x11->win_x;
|
|
|
|
x11->nofs_y = x11->win_y;
|
|
|
|
x11->nofs_width = x11->win_width;
|
|
|
|
x11->nofs_height = x11->win_height;
|
2013-02-17 15:35:44 +00:00
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
vo_x11_update_screeninfo(vo);
|
2013-02-17 15:35:44 +00:00
|
|
|
|
2013-03-04 16:40:21 +00:00
|
|
|
x = vo->xinerama_x;
|
|
|
|
y = vo->xinerama_y;
|
2013-03-04 21:41:27 +00:00
|
|
|
w = opts->screenwidth;
|
|
|
|
h = opts->screenheight;
|
2013-02-17 15:35:44 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
if ((x11->fs_type & vo_wm_FULLSCREEN) && opts->fsscreen_id != -1) {
|
2013-02-17 15:35:44 +00:00
|
|
|
// The EWMH fullscreen hint always works on the current screen, so
|
|
|
|
// change the current screen forcibly.
|
|
|
|
// This was observed to work under IceWM, but not Unity/Compiz and
|
|
|
|
// awesome (but --screen etc. doesn't really work on these either).
|
|
|
|
XMoveResizeWindow(x11->display, x11->window, x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2013-10-30 20:58:55 +00:00
|
|
|
// sends fullscreen state to be added if wm supports EWMH
|
|
|
|
vo_x11_ewmh_fullscreen(x11, _NET_WM_STATE_ADD);
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 20:58:55 +00:00
|
|
|
XGetWMNormalHints(x11->display, x11->window, &x11->vo_hint, &(long){0});
|
|
|
|
if (!(x11->vo_hint.flags & PWinGravity))
|
|
|
|
x11->old_gravity = NorthWestGravity;
|
|
|
|
else
|
|
|
|
x11->old_gravity = x11->vo_hint.win_gravity;
|
|
|
|
|
2013-08-11 21:57:00 +00:00
|
|
|
if (x11->fs_type & vo_wm_MWM) {
|
2008-04-21 00:14:37 +00:00
|
|
|
XUnmapWindow(x11->display, x11->window); // required for MWM
|
2008-04-21 01:59:00 +00:00
|
|
|
XWithdrawWindow(x11->display, x11->window, x11->screen);
|
2008-04-21 01:50:29 +00:00
|
|
|
x11->fs_flip = 1;
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:33:01 +00:00
|
|
|
if (!(x11->fs_type & vo_wm_FULLSCREEN)) { // not needed with EWMH fs
|
2013-07-18 12:05:39 +00:00
|
|
|
vo_x11_decoration(vo, opts->border && !x11->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
|
|
|
vo_x11_sizehint(vo, x, y, w, h, true);
|
2013-07-18 12:05:39 +00:00
|
|
|
vo_x11_setlayer(vo, x11->window, x11->fs);
|
2004-06-14 04:53:03 +00:00
|
|
|
|
|
|
|
|
2008-04-21 00:14:37 +00:00
|
|
|
XMoveResizeWindow(x11->display, x11->window, x, y, w, h);
|
2004-07-11 22:16:52 +00:00
|
|
|
}
|
2007-01-18 09:03:42 +00:00
|
|
|
/* some WMs lose ontop after fullscreen */
|
2013-07-18 12:05:39 +00:00
|
|
|
if ((!(x11->fs)) & opts->ontop)
|
2013-03-04 21:41:27 +00:00
|
|
|
vo_x11_setlayer(vo, x11->window, opts->ontop);
|
2004-12-27 11:09:49 +00:00
|
|
|
|
2008-04-21 00:14:37 +00:00
|
|
|
XMapRaised(x11->display, x11->window);
|
2013-02-13 15:33:01 +00:00
|
|
|
if (!(x11->fs_type & vo_wm_FULLSCREEN)) // some WMs change window pos on map
|
2008-04-21 00:14:37 +00:00
|
|
|
XMoveResizeWindow(x11->display, x11->window, x, y, w, h);
|
|
|
|
XRaiseWindow(x11->display, x11->window);
|
2008-04-20 06:34:27 +00:00
|
|
|
XFlush(x11->display);
|
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
|
|
|
|
|
|
|
x11->size_changed_during_fs = false;
|
|
|
|
x11->pos_changed_during_fs = false;
|
2002-03-07 17:50:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 12:02:28 +00:00
|
|
|
static void vo_x11_ontop(struct vo *vo)
|
2003-11-30 16:36:10 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
opts->ontop = !opts->ontop;
|
2003-11-30 16:36:10 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
vo_x11_setlayer(vo, vo->x11->window, opts->ontop);
|
2003-11-30 16:36:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 12:02:28 +00:00
|
|
|
static void vo_x11_border(struct vo *vo)
|
2008-07-22 18:46:07 +00:00
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->opts->border = !vo->opts->border;
|
2013-10-27 22:22:46 +00:00
|
|
|
vo_x11_decoration(vo, vo->opts->border);
|
2008-07-22 18:46:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-15 16:17:18 +00:00
|
|
|
int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
|
|
|
|
{
|
2013-06-13 22:24:41 +00:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2013-05-15 16:17:18 +00:00
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_CHECK_EVENTS:
|
|
|
|
*events |= vo_x11_check_events(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
|
|
|
vo_x11_fullscreen(vo);
|
|
|
|
*events |= VO_EVENT_RESIZE;
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_ONTOP:
|
|
|
|
vo_x11_ontop(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_BORDER:
|
|
|
|
vo_x11_border(vo);
|
|
|
|
*events |= VO_EVENT_RESIZE;
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_UPDATE_SCREENINFO:
|
|
|
|
vo_x11_update_screeninfo(vo);
|
|
|
|
return VO_TRUE;
|
2013-10-31 19:19:40 +00:00
|
|
|
case VOCTRL_GET_WINDOW_SIZE: {
|
|
|
|
int *s = arg;
|
|
|
|
if (!x11->window)
|
|
|
|
return VO_FALSE;
|
2013-11-02 16:32:03 +00:00
|
|
|
s[0] = x11->fs ? x11->nofs_width : x11->win_width;
|
|
|
|
s[1] = x11->fs ? x11->nofs_height : x11->win_height;
|
2013-10-31 19:19:40 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
case VOCTRL_SET_WINDOW_SIZE: {
|
|
|
|
int *s = arg;
|
|
|
|
vo_x11_highlevel_resize(vo, x11->win_x, x11->win_y, s[0], s[1]);
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-05-16 21:24:56 +00:00
|
|
|
case VOCTRL_SET_CURSOR_VISIBILITY:
|
|
|
|
vo_set_cursor_hidden(vo, !(*(bool *)arg));
|
|
|
|
return VO_TRUE;
|
2013-06-13 22:24:41 +00:00
|
|
|
case VOCTRL_KILL_SCREENSAVER:
|
|
|
|
saver_off(x11);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_RESTORE_SCREENSAVER:
|
|
|
|
saver_on(x11);
|
|
|
|
return VO_TRUE;
|
2013-06-15 17:04:20 +00:00
|
|
|
case VOCTRL_UPDATE_WINDOW_TITLE:
|
|
|
|
vo_x11_update_window_title(vo);
|
|
|
|
return VO_TRUE;
|
2013-05-15 16:17:18 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-03-01 10:17:56 +00:00
|
|
|
static void xscreensaver_heartbeat(struct vo_x11_state *x11)
|
2003-03-26 17:02:28 +00:00
|
|
|
{
|
2013-05-25 16:31:06 +00:00
|
|
|
double time = mp_time_sec();
|
2003-03-26 17:02:28 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
if (x11->display && x11->screensaver_off &&
|
2013-10-25 18:30:01 +00:00
|
|
|
(time - x11->screensaver_time_last) >= 10)
|
2004-06-14 04:53:03 +00:00
|
|
|
{
|
2013-01-26 21:37:47 +00:00
|
|
|
x11->screensaver_time_last = time;
|
2004-06-14 04:53:03 +00:00
|
|
|
|
2008-04-20 06:34:27 +00:00
|
|
|
XResetScreenSaver(x11->display);
|
2003-03-26 17:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-20 06:34:27 +00:00
|
|
|
static int xss_suspend(Display *mDisplay, Bool suspend)
|
2007-12-22 11:09:43 +00:00
|
|
|
{
|
2013-07-16 11:28:28 +00:00
|
|
|
#if !HAVE_XSS
|
2007-12-22 11:09:43 +00:00
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
int event, error, major, minor;
|
|
|
|
if (XScreenSaverQueryExtension(mDisplay, &event, &error) != True ||
|
|
|
|
XScreenSaverQueryVersion(mDisplay, &major, &minor) != True)
|
|
|
|
return 0;
|
2008-06-15 11:11:39 +00:00
|
|
|
if (major < 1 || (major == 1 && minor < 1))
|
2007-12-22 11:09:43 +00:00
|
|
|
return 0;
|
|
|
|
XScreenSaverSuspend(mDisplay, suspend);
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
static void saver_on(struct vo_x11_state *x11)
|
2004-06-14 04:53:03 +00:00
|
|
|
{
|
2013-01-26 21:37:47 +00:00
|
|
|
Display *mDisplay = x11->display;
|
|
|
|
if (!x11->screensaver_off)
|
2008-01-07 12:18:17 +00:00
|
|
|
return;
|
2013-01-26 21:37:47 +00:00
|
|
|
x11->screensaver_off = 0;
|
2008-04-20 06:34:27 +00:00
|
|
|
if (xss_suspend(mDisplay, False))
|
2007-12-22 11:09:43 +00:00
|
|
|
return;
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XEXT
|
2013-01-26 21:37:47 +00:00
|
|
|
if (x11->dpms_disabled) {
|
2007-12-20 12:51:24 +00:00
|
|
|
int nothing;
|
2013-01-26 21:37:47 +00:00
|
|
|
if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) {
|
|
|
|
if (!DPMSEnable(mDisplay)) { // restoring power saving settings
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_WARN(x11, "DPMS not available?\n");
|
2013-01-26 21:37:47 +00:00
|
|
|
} else {
|
2001-05-09 20:15:37 +00:00
|
|
|
// DPMS does not seem to be enabled unless we call DPMSInfo
|
2004-06-14 04:53:03 +00:00
|
|
|
BOOL onoff;
|
|
|
|
CARD16 state;
|
|
|
|
|
|
|
|
DPMSForceLevel(mDisplay, DPMSModeOn);
|
|
|
|
DPMSInfo(mDisplay, &state, &onoff);
|
2013-02-13 15:33:01 +00:00
|
|
|
if (onoff) {
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Successfully enabled DPMS\n");
|
2013-02-13 15:33:01 +00:00
|
|
|
} else {
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_WARN(x11, "Could not enable DPMS\n");
|
2001-05-09 20:15:37 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
2013-01-26 21:37:47 +00:00
|
|
|
x11->dpms_disabled = 0;
|
2001-04-10 00:00:04 +00:00
|
|
|
}
|
2001-07-19 18:47:22 +00:00
|
|
|
#endif
|
2001-04-10 00:00:04 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
static void saver_off(struct vo_x11_state *x11)
|
2004-06-14 04:53:03 +00:00
|
|
|
{
|
2013-01-26 21:37:47 +00:00
|
|
|
Display *mDisplay = x11->display;
|
2001-07-19 18:47:22 +00:00
|
|
|
int nothing;
|
2001-04-10 00:00:04 +00:00
|
|
|
|
2013-01-26 21:37:47 +00:00
|
|
|
if (x11->screensaver_off)
|
2008-01-07 12:18:17 +00:00
|
|
|
return;
|
2013-01-26 21:37:47 +00:00
|
|
|
x11->screensaver_off = 1;
|
2008-04-20 06:34:27 +00:00
|
|
|
if (xss_suspend(mDisplay, True))
|
2007-12-22 11:09:43 +00:00
|
|
|
return;
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XEXT
|
2013-02-13 15:33:01 +00:00
|
|
|
if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) {
|
2004-06-14 04:53:03 +00:00
|
|
|
BOOL onoff;
|
|
|
|
CARD16 state;
|
|
|
|
|
|
|
|
DPMSInfo(mDisplay, &state, &onoff);
|
2013-02-13 15:33:01 +00:00
|
|
|
if (onoff) {
|
2004-06-14 04:53:03 +00:00
|
|
|
Status stat;
|
|
|
|
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "Disabling DPMS\n");
|
2013-01-26 21:37:47 +00:00
|
|
|
x11->dpms_disabled = 1;
|
2004-06-14 04:53:03 +00:00
|
|
|
stat = DPMSDisable(mDisplay); // monitor powersave off
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_VERBOSE(x11, "DPMSDisable stat: %d\n", stat);
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
2001-04-10 00:00:04 +00:00
|
|
|
}
|
2001-07-19 18:47:22 +00:00
|
|
|
#endif
|
2001-04-10 02:29:38 +00:00
|
|
|
}
|
2001-04-15 20:31:58 +00:00
|
|
|
|
2013-03-04 16:40:21 +00:00
|
|
|
static void vo_x11_selectinput_witherr(struct vo *vo,
|
|
|
|
Display *display,
|
|
|
|
Window w,
|
2013-01-26 21:37:47 +00:00
|
|
|
long event_mask)
|
2002-08-09 17:43:49 +00:00
|
|
|
{
|
2013-09-08 00:12:36 +00:00
|
|
|
if (!vo->opts->enable_mouse_movements)
|
2013-01-27 05:33:58 +00:00
|
|
|
event_mask &= ~(ButtonPressMask | ButtonReleaseMask);
|
|
|
|
|
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
|
|
|
XSelectInput(display, w, NoEventMask);
|
|
|
|
|
2013-01-27 05:33:58 +00:00
|
|
|
// NOTE: this can raise BadAccess, which should be ignored by the X error
|
|
|
|
// handler; also see below
|
|
|
|
XSelectInput(display, w, event_mask);
|
|
|
|
|
|
|
|
// Test whether setting the event mask failed (with a BadAccess X error,
|
|
|
|
// although we don't know whether this really happened).
|
|
|
|
// This is needed for obscure situations like using --rootwin with a window
|
|
|
|
// manager active.
|
|
|
|
XWindowAttributes a;
|
|
|
|
if (XGetWindowAttributes(display, w, &a)) {
|
|
|
|
long bad = ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
|
|
|
|
if ((event_mask & bad) && (a.all_event_masks & bad) &&
|
|
|
|
((a.your_event_mask & bad) != (event_mask & bad)))
|
|
|
|
{
|
2013-09-11 22:56:41 +00:00
|
|
|
MP_ERR(vo->x11, "X11 error: error during XSelectInput "
|
2013-01-27 05:33:58 +00:00
|
|
|
"call, trying without mouse events\n");
|
|
|
|
XSelectInput(display, w, event_mask & ~bad);
|
|
|
|
}
|
2004-06-14 04:53:03 +00:00
|
|
|
}
|
2002-08-09 17:43:49 +00:00
|
|
|
}
|
2002-01-05 08:49:46 +00:00
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XF86VM
|
2013-01-27 06:21:10 +00:00
|
|
|
double vo_x11_vm_get_fps(struct vo *vo)
|
2009-11-15 02:39:22 +00:00
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
int clock;
|
|
|
|
XF86VidModeModeLine modeline;
|
|
|
|
if (!XF86VidModeGetModeLine(x11->display, x11->screen, &clock, &modeline))
|
|
|
|
return 0;
|
|
|
|
if (modeline.privsize)
|
2009-11-15 13:21:40 +00:00
|
|
|
XFree(modeline.private);
|
2009-11-15 02:39:22 +00:00
|
|
|
return 1e3 * clock / modeline.htotal / modeline.vtotal;
|
|
|
|
}
|
2013-07-16 11:28:28 +00:00
|
|
|
#else /* HAVE_XF86VM */
|
2013-05-19 13:47:34 +00:00
|
|
|
double vo_x11_vm_get_fps(struct vo *vo)
|
2013-01-27 06:21:10 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-01-31 00:37:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-27 00:40:38 +00:00
|
|
|
bool vo_x11_screen_is_composited(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
|
|
|
return XGetSelectionOwner(x11->display, x11->XA_NET_WM_CM) != None;
|
|
|
|
}
|