Skip to content

Commit

Permalink
Acquire the WM_Sn selection during startup
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 b34a653 commit 5a17b39
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions awesome.c
Expand Up @@ -47,6 +47,7 @@

#include <xcb/bigreq.h>
#include <xcb/randr.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
#include <xcb/xinerama.h>
Expand Down Expand Up @@ -221,6 +222,42 @@ scan(xcb_query_tree_cookie_t tree_c)
restore_client_order(prop_cookie);
}

static void
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 */
globalconf.selection_owner_window = xcb_generate_id(globalconf.connection);
xcb_create_window(globalconf.connection, globalconf.screen->root_depth,
globalconf.selection_owner_window, globalconf.screen->root,
-1, -1, 1, 1, 0,
XCB_COPY_FROM_PARENT, globalconf.screen->root_visual,
0, NULL);

atom_name = xcb_atom_name_by_screen("WM_S", globalconf.default_screen);
if(!atom_name)
fatal("error getting WM_Sn atom name");

atom_q = xcb_intern_atom_unchecked(globalconf.connection, false,
a_strlen(atom_name), atom_name);

p_delete(&atom_name);

atom_r = xcb_intern_atom_reply(globalconf.connection, atom_q, NULL);
if(!atom_r)
fatal("error getting WM_Sn atom");

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);
}

static void
a_xcb_check(void)
{
Expand Down Expand Up @@ -506,6 +543,9 @@ main(int argc, char **argv)
/* Did we get some usable data from the above X11 setup? */
draw_test_cairo_xcb();

/* Acquire the WM_Sn selection */
acquire_WM_Sn();

/* initialize dbus */
a_dbus_init();

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;
/** Window owning the WM_Sn selection */
xcb_window_t selection_owner_window;
/** Modifiers masks */
uint16_t numlockmask, shiftlockmask, capslockmask, modeswitchmask;
/** Check for XTest extension */
Expand Down

0 comments on commit 5a17b39

Please sign in to comment.