Check if WM_Sn is already owned before acquiring it
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
86313e0afd
commit
19111121ce
26
awesome.c
26
awesome.c
|
@ -223,11 +223,12 @@ scan(xcb_query_tree_cookie_t tree_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
acquire_WM_Sn(void)
|
acquire_WM_Sn(bool replace)
|
||||||
{
|
{
|
||||||
xcb_intern_atom_cookie_t atom_q;
|
xcb_intern_atom_cookie_t atom_q;
|
||||||
xcb_intern_atom_reply_t *atom_r;
|
xcb_intern_atom_reply_t *atom_r;
|
||||||
char *atom_name;
|
char *atom_name;
|
||||||
|
xcb_get_selection_owner_reply_t *get_sel_reply;
|
||||||
xcb_client_message_event_t ev;
|
xcb_client_message_event_t ev;
|
||||||
|
|
||||||
/* Get the WM_Sn atom */
|
/* Get the WM_Sn atom */
|
||||||
|
@ -254,9 +255,28 @@ acquire_WM_Sn(void)
|
||||||
globalconf.selection_atom = atom_r->atom;
|
globalconf.selection_atom = atom_r->atom;
|
||||||
p_delete(&atom_r);
|
p_delete(&atom_r);
|
||||||
|
|
||||||
|
/* Is the selection already owned? */
|
||||||
|
get_sel_reply = xcb_get_selection_owner_reply(globalconf.connection,
|
||||||
|
xcb_get_selection_owner(globalconf.connection, globalconf.selection_atom),
|
||||||
|
NULL);
|
||||||
|
if (!replace && get_sel_reply->owner != XCB_NONE)
|
||||||
|
fatal("another window manager is already running (selection owned)");
|
||||||
|
|
||||||
/* Acquire the selection */
|
/* Acquire the selection */
|
||||||
xcb_set_selection_owner(globalconf.connection, globalconf.selection_owner_window,
|
xcb_set_selection_owner(globalconf.connection, globalconf.selection_owner_window,
|
||||||
globalconf.selection_atom, XCB_CURRENT_TIME);
|
globalconf.selection_atom, XCB_CURRENT_TIME);
|
||||||
|
if (get_sel_reply->owner != XCB_NONE)
|
||||||
|
{
|
||||||
|
/* Wait for the old owner to go away */
|
||||||
|
xcb_get_geometry_reply_t *geom_reply = NULL;
|
||||||
|
do {
|
||||||
|
p_delete(&geom_reply);
|
||||||
|
geom_reply = xcb_get_geometry_reply(globalconf.connection,
|
||||||
|
xcb_get_geometry(globalconf.connection, get_sel_reply->owner),
|
||||||
|
NULL);
|
||||||
|
} while (geom_reply != NULL);
|
||||||
|
}
|
||||||
|
p_delete(&get_sel_reply);
|
||||||
|
|
||||||
/* Announce that we are the new owner */
|
/* Announce that we are the new owner */
|
||||||
p_clear(&ev, 1);
|
p_clear(&ev, 1);
|
||||||
|
@ -558,7 +578,7 @@ main(int argc, char **argv)
|
||||||
draw_test_cairo_xcb();
|
draw_test_cairo_xcb();
|
||||||
|
|
||||||
/* Acquire the WM_Sn selection */
|
/* Acquire the WM_Sn selection */
|
||||||
acquire_WM_Sn();
|
acquire_WM_Sn(true);
|
||||||
|
|
||||||
/* initialize dbus */
|
/* initialize dbus */
|
||||||
a_dbus_init();
|
a_dbus_init();
|
||||||
|
@ -581,7 +601,7 @@ main(int argc, char **argv)
|
||||||
globalconf.screen->root,
|
globalconf.screen->root,
|
||||||
XCB_CW_EVENT_MASK, &select_input_val);
|
XCB_CW_EVENT_MASK, &select_input_val);
|
||||||
if (xcb_request_check(globalconf.connection, cookie))
|
if (xcb_request_check(globalconf.connection, cookie))
|
||||||
fatal("another window manager is already running");
|
fatal("another window manager is already running (can't select SubstructureRedirect)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prefetch the maximum request length */
|
/* Prefetch the maximum request length */
|
||||||
|
|
Loading…
Reference in New Issue