vo: get rid of vo_get_window_title()

It always was a weird artifact - VOCTRLs are meant _not_ to require
special handling in the code that passes them through (like in vo.c).
Removing it is also interesting to further reduce the dependency of
backends on struct vo. Just get rid of it.

Removing it is somewhat inconvenient, because in many situations the UI
window is created after the first VOCTRL_UPDATE_WINDOW_TITLE. This means
these backends have to store it in a new field in their own context.
This commit is contained in:
wm4 2015-12-06 18:39:09 +01:00
parent 970606e491
commit 9db50c6760
6 changed files with 28 additions and 34 deletions

View File

@ -106,6 +106,8 @@ struct vo_cocoa_state {
int frame_w, frame_h; // dimensions of the frame rendered int frame_w, frame_h; // dimensions of the frame rendered
NSCursor *blankCursor; NSCursor *blankCursor;
char *window_title;
}; };
static void run_on_main_thread(struct vo *vo, void(^block)(void)) static void run_on_main_thread(struct vo *vo, void(^block)(void))
@ -504,14 +506,15 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
} }
} }
static int cocoa_set_window_title(struct vo *vo, const char *title) static int cocoa_set_window_title(struct vo *vo)
{ {
struct vo_cocoa_state *s = vo->cocoa; struct vo_cocoa_state *s = vo->cocoa;
if (s->embedded) if (s->embedded)
return VO_NOTIMPL; return VO_NOTIMPL;
void *talloc_ctx = talloc_new(NULL); void *talloc_ctx = talloc_new(NULL);
struct bstr btitle = bstr_sanitize_utf8_latin1(talloc_ctx, bstr0(title)); struct bstr btitle =
bstr_sanitize_utf8_latin1(talloc_ctx, bstr0(s->window_title));
NSString *nstitle = [NSString stringWithUTF8String:btitle.start]; NSString *nstitle = [NSString stringWithUTF8String:btitle.start];
if (nstitle) { if (nstitle) {
[s->window setTitle: nstitle]; [s->window setTitle: nstitle];
@ -584,7 +587,7 @@ int vo_cocoa_config_window(struct vo *vo)
queue_new_video_size(vo, width, height); queue_new_video_size(vo, width, height);
vo_cocoa_fullscreen(vo); vo_cocoa_fullscreen(vo);
cocoa_add_fs_screen_profile_observer(vo); cocoa_add_fs_screen_profile_observer(vo);
cocoa_set_window_title(vo, vo_get_window_title(vo)); cocoa_set_window_title(vo);
vo_set_level(vo, vo->opts->ontop); vo_set_level(vo, vo->opts->ontop);
} }
@ -763,8 +766,12 @@ static int vo_cocoa_control_on_main_thread(struct vo *vo, int request, void *arg
} }
case VOCTRL_SET_CURSOR_VISIBILITY: case VOCTRL_SET_CURSOR_VISIBILITY:
return vo_cocoa_set_cursor_visibility(vo, arg); return vo_cocoa_set_cursor_visibility(vo, arg);
case VOCTRL_UPDATE_WINDOW_TITLE: case VOCTRL_UPDATE_WINDOW_TITLE: {
return cocoa_set_window_title(vo, (const char *) arg); struct vo_cocoa_state *s = vo->cocoa;
talloc_free(s->window_title);
s->window_title = talloc_strdup(s, (char *) arg);
return cocoa_set_window_title(vo);
}
case VOCTRL_RESTORE_SCREENSAVER: case VOCTRL_RESTORE_SCREENSAVER:
enable_power_management(vo->cocoa); enable_power_management(vo->cocoa);
return VO_TRUE; return VO_TRUE;

View File

@ -166,9 +166,6 @@ struct vo_internal {
int req_frames; // VO's requested value of num_frames int req_frames; // VO's requested value of num_frames
double display_fps; double display_fps;
// --- The following fields can be accessed from the VO thread only
char *window_title;
}; };
static void forget_frames(struct vo *vo); static void forget_frames(struct vo *vo);
@ -550,8 +547,6 @@ static void run_control(void *p)
struct vo *vo = pp[0]; struct vo *vo = pp[0];
uint32_t request = *(int *)pp[1]; uint32_t request = *(int *)pp[1];
void *data = pp[2]; void *data = pp[2];
if (request == VOCTRL_UPDATE_WINDOW_TITLE) // legacy fallback
vo->in->window_title = talloc_strdup(vo, data);
int ret = vo->driver->control(vo, request, data); int ret = vo->driver->control(vo, request, data);
*(int *)pp[3] = ret; *(int *)pp[3] = ret;
} }
@ -1063,18 +1058,6 @@ void vo_get_src_dst_rects(struct vo *vo, struct mp_rect *out_src,
out_src, out_dst, out_osd); out_src, out_dst, out_osd);
} }
// Return the window title the VO should set. Always returns a null terminated
// string. The string is valid until frontend code is invoked again. Copy it if
// you need to keep the string for an extended period of time.
// Must be called from the VO thread only.
// Don't use for new code.
const char *vo_get_window_title(struct vo *vo)
{
if (!vo->in->window_title)
vo->in->window_title = talloc_strdup(vo, "");
return vo->in->window_title;
}
// flip_page[_timed] will be called offset_us microseconds too early. // flip_page[_timed] will be called offset_us microseconds too early.
// (For vo_vdpau, which does its own timing.) // (For vo_vdpau, which does its own timing.)
// num_req_frames set the requested number of requested vo_frame.frames. // num_req_frames set the requested number of requested vo_frame.frames.

View File

@ -357,8 +357,6 @@ double vo_get_delay(struct vo *vo);
void vo_wakeup(struct vo *vo); void vo_wakeup(struct vo *vo);
const char *vo_get_window_title(struct vo *vo);
struct mp_keymap { struct mp_keymap {
int from; int from;
int to; int to;

View File

@ -190,6 +190,7 @@ struct priv {
double osd_pts; double osd_pts;
int mouse_hidden; int mouse_hidden;
int brightness, contrast; int brightness, contrast;
char *window_title;
Uint32 wakeup_event; Uint32 wakeup_event;
// options // options
@ -353,6 +354,9 @@ static bool try_create_renderer(struct vo *vo, int i, const char *driver,
vc->renderer_index = i; vc->renderer_index = i;
} }
if (vc->window_title)
SDL_SetWindowTitle(vc->window, vc->window_title);
return true; return true;
} }
@ -519,8 +523,6 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
set_fullscreen(vo); set_fullscreen(vo);
SDL_SetWindowTitle(vc->window, vo_get_window_title(vo));
SDL_ShowWindow(vc->window); SDL_ShowWindow(vc->window);
check_resize(vo); check_resize(vo);
@ -1012,8 +1014,10 @@ static int control(struct vo *vo, uint32_t request, void *data)
SDL_ShowCursor(*(bool *)data); SDL_ShowCursor(*(bool *)data);
return true; return true;
case VOCTRL_UPDATE_WINDOW_TITLE: case VOCTRL_UPDATE_WINDOW_TITLE:
if (vc->window) talloc_free(vc->window_title);
SDL_SetWindowTitle(vc->window, vo_get_window_title(vo)); vc->window_title = talloc_strdup(vc, (char *)data);
if (vc->window && vc->window_title)
SDL_SetWindowTitle(vc->window, vc->window_title);
return true; return true;
} }
return VO_NOTIMPL; return VO_NOTIMPL;

View File

@ -1194,14 +1194,13 @@ static void vo_x11_update_window_title(struct vo *vo)
{ {
struct vo_x11_state *x11 = vo->x11; struct vo_x11_state *x11 = vo->x11;
if (!x11->window) if (!x11->window || !x11->window_title)
return; return;
const char *title = vo_get_window_title(vo); vo_x11_set_property_string(vo, XA_WM_NAME, x11->window_title);
vo_x11_set_property_string(vo, XA_WM_NAME, title); vo_x11_set_property_string(vo, XA_WM_ICON_NAME, x11->window_title);
vo_x11_set_property_string(vo, XA_WM_ICON_NAME, title); vo_x11_set_property_utf8(vo, XA(x11, _NET_WM_NAME), x11->window_title);
vo_x11_set_property_utf8(vo, XA(x11, _NET_WM_NAME), title); vo_x11_set_property_utf8(vo, XA(x11, _NET_WM_ICON_NAME), x11->window_title);
vo_x11_set_property_utf8(vo, XA(x11, _NET_WM_ICON_NAME), title);
} }
static void vo_x11_xembed_update(struct vo_x11_state *x11, int flags) static void vo_x11_xembed_update(struct vo_x11_state *x11, int flags)
@ -1804,6 +1803,8 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
set_screensaver(x11, true); set_screensaver(x11, true);
return VO_TRUE; return VO_TRUE;
case VOCTRL_UPDATE_WINDOW_TITLE: case VOCTRL_UPDATE_WINDOW_TITLE:
talloc_free(x11->window_title);
x11->window_title = talloc_strdup(x11, (char *)arg);
if (!x11->parent) if (!x11->parent)
vo_x11_update_window_title(vo); vo_x11_update_window_title(vo);
return VO_TRUE; return VO_TRUE;

View File

@ -52,6 +52,7 @@ struct vo_x11_state {
int ws_width; int ws_width;
int ws_height; int ws_height;
struct mp_rect screenrc; struct mp_rect screenrc;
char *window_title;
struct xrandr_display displays[MAX_DISPLAYS]; struct xrandr_display displays[MAX_DISPLAYS];
int num_displays; int num_displays;