From e824f8f30d3f797374f6597baf4fb70f48f51b25 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 10 Oct 2015 21:59:12 +0200 Subject: [PATCH] Exit when we loose the WM_Sn selection Signed-off-by: Uli Schlachter --- awesome.c | 6 +++--- event.c | 11 +++++++++++ globalconf.h | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/awesome.c b/awesome.c index 0a19a792c..5953f811e 100644 --- a/awesome.c +++ b/awesome.c @@ -227,7 +227,6 @@ acquire_WM_Sn(void) { xcb_intern_atom_cookie_t atom_q; xcb_intern_atom_reply_t *atom_r; - xcb_atom_t atom; char *atom_name; /* Get the WM_Sn atom */ @@ -251,11 +250,12 @@ acquire_WM_Sn(void) if(!atom_r) fatal("error getting WM_Sn atom"); - atom = atom_r->atom; + globalconf.selection_atom = atom_r->atom; p_delete(&atom_r); /* Acquire the selection */ - xcb_set_selection_owner(globalconf.connection, globalconf.selection_owner_window, atom, XCB_CURRENT_TIME); + xcb_set_selection_owner(globalconf.connection, globalconf.selection_owner_window, + globalconf.selection_atom, XCB_CURRENT_TIME); } static void diff --git a/event.c b/event.c index 1246772d1..44139ccf2 100644 --- a/event.c +++ b/event.c @@ -862,6 +862,16 @@ event_handle_reparentnotify(xcb_reparent_notify_event_t *ev) } } +static void +event_handle_selectionclear(xcb_selection_clear_event_t *ev) +{ + if(ev->selection == globalconf.selection_atom) + { + warn("Lost WM_Sn selection, exiting..."); + g_main_loop_quit(globalconf.loop); + } +} + /** \brief awesome xerror function. * There's no way to check accesses to destroyed windows, thus those cases are * ignored (especially on UnmapNotify's). @@ -921,6 +931,7 @@ void event_handle(xcb_generic_event_t *event) EVENT(XCB_PROPERTY_NOTIFY, property_handle_propertynotify); EVENT(XCB_REPARENT_NOTIFY, event_handle_reparentnotify); EVENT(XCB_UNMAP_NOTIFY, event_handle_unmapnotify); + EVENT(XCB_SELECTION_CLEAR, event_handle_selectionclear); #undef EVENT } diff --git a/globalconf.h b/globalconf.h index 2299a502e..344cfe5f4 100644 --- a/globalconf.h +++ b/globalconf.h @@ -84,6 +84,8 @@ typedef struct key_array_t keys; /** Root window mouse bindings */ button_array_t buttons; + /** Atom for WM_Sn */ + xcb_atom_t selection_atom; /** Window owning the WM_Sn selection */ xcb_window_t selection_owner_window; /** Modifiers masks */