Skip to content

Commit

Permalink
Exit when we loose the WM_Sn selection
Browse files Browse the repository at this point in the history
Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information
psychon committed Oct 10, 2015
1 parent 5a17b39 commit e824f8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions awesome.c
Expand Up @@ -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 */
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions event.c
Expand Up @@ -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).
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions globalconf.h
Expand Up @@ -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 */
Expand Down

0 comments on commit e824f8f

Please sign in to comment.