mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
x11: set window titles as UTF-8
Always set the X11 window title properties as UTF-8. This is a bit tricky for X11 window properties which are not specified to use UTF-8, such as WM_NAME. We also properly set WM_ICON_NAME, which means the window caption and the text used in the task bar (of the WM has one) will be the same on most window managers. Before this commit, WM_ICON_NAME was always hardcoded to "MPlayer", even if --title or --use-filename-title was used. Also update the window title only on reconfigure, like it is done in mplayer-svn commit 34380.
This commit is contained in:
parent
d4de92e808
commit
3df6dc718a
@ -327,11 +327,14 @@ static void init_atoms(struct vo_x11_state *x11)
|
|||||||
XA_INIT(_NET_WM_STATE_STAYS_ON_TOP);
|
XA_INIT(_NET_WM_STATE_STAYS_ON_TOP);
|
||||||
XA_INIT(_NET_WM_STATE_BELOW);
|
XA_INIT(_NET_WM_STATE_BELOW);
|
||||||
XA_INIT(_NET_WM_PID);
|
XA_INIT(_NET_WM_PID);
|
||||||
|
XA_INIT(_NET_WM_NAME);
|
||||||
|
XA_INIT(_NET_WM_ICON_NAME);
|
||||||
XA_INIT(_WIN_PROTOCOLS);
|
XA_INIT(_WIN_PROTOCOLS);
|
||||||
XA_INIT(_WIN_LAYER);
|
XA_INIT(_WIN_LAYER);
|
||||||
XA_INIT(_WIN_HINTS);
|
XA_INIT(_WIN_HINTS);
|
||||||
XA_INIT(WM_PROTOCOLS);
|
XA_INIT(WM_PROTOCOLS);
|
||||||
XA_INIT(WM_DELETE_WINDOW);
|
XA_INIT(WM_DELETE_WINDOW);
|
||||||
|
XA_INIT(UTF8_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_xinerama_info(struct vo *vo) {
|
void update_xinerama_info(struct vo *vo) {
|
||||||
@ -990,6 +993,56 @@ static int vo_x11_get_gnome_layer(struct vo_x11_state *x11, Window win)
|
|||||||
return WIN_LAYER_NORMAL;
|
return WIN_LAYER_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set a X text property that expects a STRING type
|
||||||
|
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};
|
||||||
|
int success;
|
||||||
|
|
||||||
|
success = Xutf8TextListToTextProperty(x11->display, (char **)&t, 1,
|
||||||
|
XStringStyle, &prop);
|
||||||
|
|
||||||
|
// The call can fail if the string uses characters not in the STRING
|
||||||
|
// encoding (which is latin-1 as far as I can tell). Try COMPOUND_TEXT
|
||||||
|
// instead. (It is possible that COMPOUND_TEXT always works, but since the
|
||||||
|
// difference in the type used for the property is visible to the Window
|
||||||
|
// manager and the ICCCM seems to specify STRING, we're trying to be careful
|
||||||
|
// and try STRING first.)
|
||||||
|
// GTK seems to follow about the same fallback mechanism.
|
||||||
|
if (success != Success) {
|
||||||
|
XFree(prop.value);
|
||||||
|
prop.value = NULL;
|
||||||
|
success = Xutf8TextListToTextProperty(x11->display, (char **)&t, 1,
|
||||||
|
XCompoundTextStyle, &prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success == Success)
|
||||||
|
XSetTextProperty(x11->display, x11->window, &prop, name);
|
||||||
|
|
||||||
|
XFree(prop.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vo_x11_update_window_title(struct vo *vo)
|
||||||
|
{
|
||||||
|
struct vo_x11_state *x11 = vo->x11;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
static Window vo_x11_create_smooth_window(struct vo_x11_state *x11, Window mRoot,
|
static Window vo_x11_create_smooth_window(struct vo_x11_state *x11, Window mRoot,
|
||||||
Visual * vis, int x, int y,
|
Visual * vis, int x, int y,
|
||||||
@ -1088,8 +1141,7 @@ void vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y,
|
|||||||
hint.flags = PSize;
|
hint.flags = PSize;
|
||||||
if (geometry_xy_changed)
|
if (geometry_xy_changed)
|
||||||
hint.flags |= PPosition;
|
hint.flags |= PPosition;
|
||||||
const char *title = "MPlayer";
|
XSetWMNormalHints(mDisplay, x11->window, &hint);
|
||||||
XSetStandardProperties(mDisplay, x11->window, title, title, None, NULL, 0, &hint);
|
|
||||||
if (!vo_border) vo_x11_decoration(vo, 0);
|
if (!vo_border) vo_x11_decoration(vo, 0);
|
||||||
// map window
|
// map window
|
||||||
XSelectInput(mDisplay, x11->window, NoEventMask);
|
XSelectInput(mDisplay, x11->window, NoEventMask);
|
||||||
@ -1099,6 +1151,7 @@ void vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y,
|
|||||||
XMapWindow(mDisplay, x11->window);
|
XMapWindow(mDisplay, x11->window);
|
||||||
vo_x11_clearwindow(vo, x11->window);
|
vo_x11_clearwindow(vo, x11->window);
|
||||||
}
|
}
|
||||||
|
vo_x11_update_window_title(vo);
|
||||||
if (opts->vo_ontop) vo_x11_setlayer(vo, x11->window, opts->vo_ontop);
|
if (opts->vo_ontop) vo_x11_setlayer(vo, x11->window, opts->vo_ontop);
|
||||||
vo_x11_update_geometry(vo, !geometry_xy_changed);
|
vo_x11_update_geometry(vo, !geometry_xy_changed);
|
||||||
vo_x11_nofs_sizepos(vo, vo->dx, vo->dy, width, height);
|
vo_x11_nofs_sizepos(vo, vo->dx, vo->dy, width, height);
|
||||||
@ -1316,7 +1369,6 @@ int vo_x11_update_geometry(struct vo *vo, bool update_pos)
|
|||||||
if (update_pos)
|
if (update_pos)
|
||||||
XTranslateCoordinates(x11->display, x11->window, x11->rootwin, 0, 0,
|
XTranslateCoordinates(x11->display, x11->window, x11->rootwin, 0, 0,
|
||||||
&vo->dx, &vo->dy, &dummy_win);
|
&vo->dx, &vo->dy, &dummy_win);
|
||||||
XStoreName(x11->display, x11->window, vo_get_window_title(vo));
|
|
||||||
|
|
||||||
return depth <= INT_MAX ? depth : 0;
|
return depth <= INT_MAX ? depth : 0;
|
||||||
}
|
}
|
||||||
|
@ -85,11 +85,14 @@ struct vo_x11_state {
|
|||||||
Atom XA_NET_WM_STATE_STAYS_ON_TOP;
|
Atom XA_NET_WM_STATE_STAYS_ON_TOP;
|
||||||
Atom XA_NET_WM_STATE_BELOW;
|
Atom XA_NET_WM_STATE_BELOW;
|
||||||
Atom XA_NET_WM_PID;
|
Atom XA_NET_WM_PID;
|
||||||
|
Atom XA_NET_WM_NAME;
|
||||||
|
Atom XA_NET_WM_ICON_NAME;
|
||||||
Atom XA_WIN_PROTOCOLS;
|
Atom XA_WIN_PROTOCOLS;
|
||||||
Atom XA_WIN_LAYER;
|
Atom XA_WIN_LAYER;
|
||||||
Atom XA_WIN_HINTS;
|
Atom XA_WIN_HINTS;
|
||||||
Atom XAWM_PROTOCOLS;
|
Atom XAWM_PROTOCOLS;
|
||||||
Atom XAWM_DELETE_WINDOW;
|
Atom XAWM_DELETE_WINDOW;
|
||||||
|
Atom XAUTF8_STRING;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(CONFIG_GL) || defined(CONFIG_X11) || defined(CONFIG_XV)
|
#if defined(CONFIG_GL) || defined(CONFIG_X11) || defined(CONFIG_XV)
|
||||||
|
Loading…
Reference in New Issue
Block a user