mirror of https://github.com/mpv-player/mpv
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:
parent
970606e491
commit
9db50c6760
|
@ -106,6 +106,8 @@ struct vo_cocoa_state {
|
|||
int frame_w, frame_h; // dimensions of the frame rendered
|
||||
|
||||
NSCursor *blankCursor;
|
||||
|
||||
char *window_title;
|
||||
};
|
||||
|
||||
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;
|
||||
if (s->embedded)
|
||||
return VO_NOTIMPL;
|
||||
|
||||
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];
|
||||
if (nstitle) {
|
||||
[s->window setTitle: nstitle];
|
||||
|
@ -584,7 +587,7 @@ int vo_cocoa_config_window(struct vo *vo)
|
|||
queue_new_video_size(vo, width, height);
|
||||
vo_cocoa_fullscreen(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);
|
||||
}
|
||||
|
||||
|
@ -763,8 +766,12 @@ static int vo_cocoa_control_on_main_thread(struct vo *vo, int request, void *arg
|
|||
}
|
||||
case VOCTRL_SET_CURSOR_VISIBILITY:
|
||||
return vo_cocoa_set_cursor_visibility(vo, arg);
|
||||
case VOCTRL_UPDATE_WINDOW_TITLE:
|
||||
return cocoa_set_window_title(vo, (const char *) arg);
|
||||
case VOCTRL_UPDATE_WINDOW_TITLE: {
|
||||
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:
|
||||
enable_power_management(vo->cocoa);
|
||||
return VO_TRUE;
|
||||
|
|
|
@ -166,9 +166,6 @@ struct vo_internal {
|
|||
int req_frames; // VO's requested value of num_frames
|
||||
|
||||
double display_fps;
|
||||
|
||||
// --- The following fields can be accessed from the VO thread only
|
||||
char *window_title;
|
||||
};
|
||||
|
||||
static void forget_frames(struct vo *vo);
|
||||
|
@ -550,8 +547,6 @@ static void run_control(void *p)
|
|||
struct vo *vo = pp[0];
|
||||
uint32_t request = *(int *)pp[1];
|
||||
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 *)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);
|
||||
}
|
||||
|
||||
// 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.
|
||||
// (For vo_vdpau, which does its own timing.)
|
||||
// num_req_frames set the requested number of requested vo_frame.frames.
|
||||
|
|
|
@ -357,8 +357,6 @@ double vo_get_delay(struct vo *vo);
|
|||
|
||||
void vo_wakeup(struct vo *vo);
|
||||
|
||||
const char *vo_get_window_title(struct vo *vo);
|
||||
|
||||
struct mp_keymap {
|
||||
int from;
|
||||
int to;
|
||||
|
|
|
@ -190,6 +190,7 @@ struct priv {
|
|||
double osd_pts;
|
||||
int mouse_hidden;
|
||||
int brightness, contrast;
|
||||
char *window_title;
|
||||
Uint32 wakeup_event;
|
||||
|
||||
// options
|
||||
|
@ -353,6 +354,9 @@ static bool try_create_renderer(struct vo *vo, int i, const char *driver,
|
|||
vc->renderer_index = i;
|
||||
}
|
||||
|
||||
if (vc->window_title)
|
||||
SDL_SetWindowTitle(vc->window, vc->window_title);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -519,8 +523,6 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
|
|||
|
||||
set_fullscreen(vo);
|
||||
|
||||
SDL_SetWindowTitle(vc->window, vo_get_window_title(vo));
|
||||
|
||||
SDL_ShowWindow(vc->window);
|
||||
|
||||
check_resize(vo);
|
||||
|
@ -1012,8 +1014,10 @@ static int control(struct vo *vo, uint32_t request, void *data)
|
|||
SDL_ShowCursor(*(bool *)data);
|
||||
return true;
|
||||
case VOCTRL_UPDATE_WINDOW_TITLE:
|
||||
if (vc->window)
|
||||
SDL_SetWindowTitle(vc->window, vo_get_window_title(vo));
|
||||
talloc_free(vc->window_title);
|
||||
vc->window_title = talloc_strdup(vc, (char *)data);
|
||||
if (vc->window && vc->window_title)
|
||||
SDL_SetWindowTitle(vc->window, vc->window_title);
|
||||
return true;
|
||||
}
|
||||
return VO_NOTIMPL;
|
||||
|
|
|
@ -1194,14 +1194,13 @@ static void vo_x11_update_window_title(struct vo *vo)
|
|||
{
|
||||
struct vo_x11_state *x11 = vo->x11;
|
||||
|
||||
if (!x11->window)
|
||||
if (!x11->window || !x11->window_title)
|
||||
return;
|
||||
|
||||
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, XA(x11, _NET_WM_NAME), title);
|
||||
vo_x11_set_property_utf8(vo, XA(x11, _NET_WM_ICON_NAME), title);
|
||||
vo_x11_set_property_string(vo, XA_WM_NAME, x11->window_title);
|
||||
vo_x11_set_property_string(vo, XA_WM_ICON_NAME, x11->window_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_ICON_NAME), x11->window_title);
|
||||
}
|
||||
|
||||
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);
|
||||
return VO_TRUE;
|
||||
case VOCTRL_UPDATE_WINDOW_TITLE:
|
||||
talloc_free(x11->window_title);
|
||||
x11->window_title = talloc_strdup(x11, (char *)arg);
|
||||
if (!x11->parent)
|
||||
vo_x11_update_window_title(vo);
|
||||
return VO_TRUE;
|
||||
|
|
|
@ -52,6 +52,7 @@ struct vo_x11_state {
|
|||
int ws_width;
|
||||
int ws_height;
|
||||
struct mp_rect screenrc;
|
||||
char *window_title;
|
||||
|
||||
struct xrandr_display displays[MAX_DISPLAYS];
|
||||
int num_displays;
|
||||
|
|
Loading…
Reference in New Issue