0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

x11: rely on the Atom cache

XInternAtom() has a 64 entry hash table to avoid network accesses. Rely
on this cache, instead of caching these manually.
This commit is contained in:
wm4 2014-11-03 23:01:27 +01:00
parent c54f0adacd
commit dc1d851c92
2 changed files with 9 additions and 15 deletions

View File

@ -127,6 +127,7 @@ static void vo_x11_selectinput_witherr(struct vo *vo, Display *display,
static void vo_x11_setlayer(struct vo *vo, bool ontop);
#define XA(x11, s) (XInternAtom((x11)->display, # s, False))
#define XAs(x11, s) XInternAtom((x11)->display, s, False)
#define RC_W(rc) ((rc).x1 - (rc).x0)
#define RC_H(rc) ((rc).y1 - (rc).y0)
@ -678,6 +679,8 @@ void vo_x11_uninit(struct vo *vo)
vo->x11 = NULL;
}
#define DND_PROPERTY "mpv_dnd_selection"
static void vo_x11_dnd_init_window(struct vo *vo)
{
struct vo_x11_state *x11 = vo->x11;
@ -685,8 +688,6 @@ static void vo_x11_dnd_init_window(struct vo *vo)
Atom version = DND_VERSION;
XChangeProperty(x11->display, x11->window, XA(x11, XdndAware), XA_ATOM,
32, PropModeReplace, (unsigned char *)&version, 1);
x11->dnd_property = XInternAtom(x11->display, "mpv_dnd_selection", False);
}
static void dnd_select_format(struct vo_x11_state *x11, Atom *args, int items)
@ -751,7 +752,7 @@ static void vo_x11_dnd_handle_message(struct vo *vo, XClientMessageEvent *ce)
} else if (ce->message_type == XA(x11, XdndDrop)) {
x11->dnd_src_window = ce->data.l[0];
XConvertSelection(x11->display, XA(x11, XdndSelection),
x11->dnd_requested_format, x11->dnd_property,
x11->dnd_requested_format, XAs(x11, DND_PROPERTY),
x11->window, ce->data.l[2]);
} else if (ce->message_type == XA(x11, XdndLeave)) {
dnd_reset(vo);
@ -768,11 +769,11 @@ static void vo_x11_dnd_handle_selection(struct vo *vo, XSelectionEvent *se)
bool success = false;
if (se->selection == XA(x11, XdndSelection) &&
se->property == x11->dnd_property &&
se->property == XAs(x11, DND_PROPERTY) &&
se->target == x11->dnd_requested_format)
{
int nitems;
void *prop = x11_get_property(x11, x11->window, x11->dnd_property,
void *prop = x11_get_property(x11, x11->window, XAs(x11, DND_PROPERTY),
x11->dnd_requested_format, 8, &nitems);
if (prop) {
// No idea if this is guaranteed to be \0-padded, so use bstr.
@ -947,12 +948,12 @@ int vo_x11_check_events(struct vo *vo)
vo_x11_dnd_handle_selection(vo, &Event.xselection);
break;
case PropertyNotify:
if (Event.xproperty.atom == x11->atom_frame_exts) {
if (Event.xproperty.atom == XA(x11, _NET_FRAME_EXTENTS)) {
if (!x11->pseudo_mapped && vo->opts->WinID < 0) {
MP_VERBOSE(x11, "not waiting for MapNotify\n");
x11->pseudo_mapped = true;
}
} else if (Event.xproperty.atom == x11->atom_wm_state) {
} else if (Event.xproperty.atom == XA(x11, _NET_WM_STATE)) {
x11->pending_vo_events |= VO_EVENT_WIN_STATE;
}
break;
@ -1229,9 +1230,6 @@ static void vo_x11_create_window(struct vo *vo, XVisualInfo *vis,
vo_x11_update_window_title(vo);
vo_x11_dnd_init_window(vo);
}
x11->atom_frame_exts = XA(x11, _NET_FRAME_EXTENTS);
x11->atom_wm_state = XA(x11, _NET_WM_STATE);
}
static void vo_x11_map_window(struct vo *vo, struct mp_rect rc)
@ -1591,7 +1589,7 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
if (!x11->window)
return VO_FALSE;
int num_elems;
long *elems = x11_get_property(x11, x11->window, x11->atom_wm_state,
long *elems = x11_get_property(x11, x11->window, XA(x11, _NET_WM_STATE),
XA_ATOM, 32, &num_elems);
if (elems) {
Atom hidden = XA(x11, _NET_WM_STATE_HIDDEN);

View File

@ -103,13 +103,9 @@ struct vo_x11_state {
int ShmCompletionWaitCount;
/* drag and drop */
Atom dnd_property;
Atom dnd_requested_format;
Window dnd_src_window;
Atom atom_frame_exts;
Atom atom_wm_state;
/* dragging the window */
bool win_drag_button1_down;
};