From aaaadc9d6bea010f68247e0c6220aa4606980de3 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Thu, 1 Feb 2024 05:32:08 -0500 Subject: [PATCH] x11_common: support --title-bar Some X11 window managers support controlling the title bar independently from other window decorations with _MOTIF_WM_HINTS. This allows hiding the title bar while keeping other decorations like the resizing borders. Let mpv respect the --title-bar option on X11 so --no-title-bar can hide the title bar only like on win32. --- DOCS/man/options.rst | 2 +- video/out/x11_common.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 548548dfff..e887e25ba7 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3236,7 +3236,7 @@ Window default, use ``--no-border`` to disable the standard window decorations. ``--title-bar``, ``--no-title-bar`` - (Windows only) + (Windows and X11 only) Play video with the window title bar. Since this is on by default, use --no-title-bar to hide the title bar. The --no-border option takes precedence. diff --git a/video/out/x11_common.c b/video/out/x11_common.c index f4d5716bee..088e0ac34f 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -99,7 +99,9 @@ #define MWM_FUNC_MAXIMIZE (1L << 4) #define MWM_FUNC_CLOSE (1L << 5) -#define MWM_DECOR_ALL (1L << 0) +// Equals to all MWM_DECOR_* OR'd together. +#define MWM_DECOR_ALL 126 +#define MWM_DECOR_TITLE (1L << 3) typedef struct { @@ -833,7 +835,7 @@ static int vo_x11_lookupkey(int key) return mpkey; } -static void vo_x11_decoration(struct vo *vo, bool d) +static void vo_x11_decoration(struct vo *vo, bool decorations, bool title_bar) { struct vo_x11_state *x11 = vo->x11; @@ -844,8 +846,9 @@ static void vo_x11_decoration(struct vo *vo, bool d) MotifWmHints mhints = {0}; bool got = x11_get_property_copy(x11, x11->window, motif_hints, motif_hints, 32, &mhints, sizeof(mhints)); - // hints weren't set, and decorations requested -> assume WM displays them - if (!got && d) + // If hints weren't set, and decorations and title bar requested, + // assume WM displays them. + if (!got && decorations && title_bar) return; if (!got) { mhints.flags = MWM_HINTS_FUNCTIONS; @@ -853,7 +856,8 @@ static void vo_x11_decoration(struct vo *vo, bool d) MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; } mhints.flags |= MWM_HINTS_DECORATIONS; - mhints.decorations = d ? MWM_DECOR_ALL : 0; + mhints.decorations = decorations ? MWM_DECOR_ALL : 0; + mhints.decorations &= ~(!title_bar ? MWM_DECOR_TITLE : 0); XChangeProperty(x11->display, x11->window, motif_hints, motif_hints, 32, PropModeReplace, (unsigned char *) &mhints, 5); } @@ -1652,7 +1656,7 @@ static void vo_x11_map_window(struct vo *vo, struct mp_rect rc) struct vo_x11_state *x11 = vo->x11; vo_x11_move_resize(vo, true, true, rc); - vo_x11_decoration(vo, x11->opts->border); + vo_x11_decoration(vo, x11->opts->border, x11->opts->title_bar); if (x11->opts->fullscreen && (x11->wm_type & vo_wm_FULLSCREEN)) { Atom state = XA(x11, _NET_WM_STATE_FULLSCREEN); @@ -1973,7 +1977,7 @@ static void vo_x11_fullscreen(struct vo *vo) rc = x11->screenrc; } - vo_x11_decoration(vo, opts->border && !x11->fs); + vo_x11_decoration(vo, opts->border && !x11->fs, opts->title_bar); vo_x11_sizehint(vo, rc, true); XMoveResizeWindow(x11->display, x11->window, rc.x0, rc.y0, @@ -2071,8 +2075,8 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg) vo_x11_fullscreen(vo); if (opt == &opts->ontop) vo_x11_setlayer(vo, opts->ontop); - if (opt == &opts->border) - vo_x11_decoration(vo, opts->border); + if (opt == &opts->border || opt == &opts->title_bar) + vo_x11_decoration(vo, opts->border, opts->title_bar); if (opt == &opts->all_workspaces) vo_x11_sticky(vo, opts->all_workspaces); if (opt == &opts->window_minimized)