diff --git a/client.c b/client.c index 9703069aa..0144c915d 100644 --- a/client.c +++ b/client.c @@ -40,52 +40,6 @@ DO_LUA_NEW(extern, client_t, client, "client", client_ref) DO_LUA_EQ(client_t, client, "client") DO_LUA_GC(client_t, client, "client", client_unref) -/** Check if client supports protocol a protocole in WM_PROTOCOL. - * \param win The window. - * \return True if client has the atom in protocol, false otherwise. - */ -static bool -window_hasproto(xcb_window_t win, xcb_atom_t atom) -{ - uint32_t i; - xcb_get_wm_protocols_reply_t protocols; - bool ret = false; - - if(xcb_get_wm_protocols_reply(globalconf.connection, - xcb_get_wm_protocols_unchecked(globalconf.connection, - win, WM_PROTOCOLS), - &protocols, NULL)) - { - for(i = 0; !ret && i < protocols.atoms_len; i++) - if(protocols.atoms[i] == atom) - ret = true; - xcb_get_wm_protocols_reply_wipe(&protocols); - } - return ret; -} - -/** Send WM_TAKE_FOCUS client message to window - * \param win destination window - */ -static void -window_takefocus(xcb_window_t win) -{ - xcb_client_message_event_t ev; - - /* Initialize all of event's fields first */ - p_clear(&ev, 1); - - ev.response_type = XCB_CLIENT_MESSAGE; - ev.window = win; - ev.format = 32; - ev.data.data32[1] = XCB_CURRENT_TIME; - ev.type = WM_PROTOCOLS; - ev.data.data32[0] = WM_TAKE_FOCUS; - - xcb_send_event(globalconf.connection, false, win, - XCB_EVENT_MASK_NO_EVENT, (char *) &ev); -} - /** Change the clients urgency flag. * \param c The client * \param urgent The new flag state @@ -185,21 +139,6 @@ client_getbywin(xcb_window_t w) return c; } -/** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS - * \param w Window that should get focus - * \param set_input_focus Should we call xcb_set_input_focus - */ -static void -window_setfocus(xcb_window_t w, bool set_input_focus) -{ - bool takefocus = window_hasproto(w, WM_TAKE_FOCUS); - if(set_input_focus) - xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_PARENT, - w, XCB_CURRENT_TIME); - if(takefocus) - window_takefocus(w); -} - /** Record that a client lost focus. * \param c Client being unfocused */ diff --git a/window.c b/window.c index 7f8bc2454..bd7e9d45d 100644 --- a/window.c +++ b/window.c @@ -172,4 +172,65 @@ window_opacity_set(xcb_window_t win, double opacity) xcb_delete_property(globalconf.connection, win, _NET_WM_WINDOW_OPACITY); } +/** Check if client supports protocol a protocole in WM_PROTOCOL. + * \param win The window. + * \return True if client has the atom in protocol, false otherwise. + */ +bool +window_hasproto(xcb_window_t win, xcb_atom_t atom) +{ + uint32_t i; + xcb_get_wm_protocols_reply_t protocols; + bool ret = false; + + if(xcb_get_wm_protocols_reply(globalconf.connection, + xcb_get_wm_protocols_unchecked(globalconf.connection, + win, WM_PROTOCOLS), + &protocols, NULL)) + { + for(i = 0; !ret && i < protocols.atoms_len; i++) + if(protocols.atoms[i] == atom) + ret = true; + xcb_get_wm_protocols_reply_wipe(&protocols); + } + return ret; +} + +/** Send WM_TAKE_FOCUS client message to window + * \param win destination window + */ +void +window_takefocus(xcb_window_t win) +{ + xcb_client_message_event_t ev; + + /* Initialize all of event's fields first */ + p_clear(&ev, 1); + + ev.response_type = XCB_CLIENT_MESSAGE; + ev.window = win; + ev.format = 32; + ev.data.data32[1] = XCB_CURRENT_TIME; + ev.type = WM_PROTOCOLS; + ev.data.data32[0] = WM_TAKE_FOCUS; + + xcb_send_event(globalconf.connection, false, win, + XCB_EVENT_MASK_NO_EVENT, (char *) &ev); +} + +/** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS + * \param w Window that should get focus + * \param set_input_focus Should we call xcb_set_input_focus + */ +void +window_setfocus(xcb_window_t w, bool set_input_focus) +{ + bool takefocus = window_hasproto(w, WM_TAKE_FOCUS); + if(set_input_focus) + xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_PARENT, + w, XCB_CURRENT_TIME); + if(takefocus) + window_takefocus(w); +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/window.h b/window.h index c566d0365..dc05593fb 100644 --- a/window.h +++ b/window.h @@ -32,6 +32,9 @@ void window_buttons_grab(xcb_window_t, button_array_t *); double window_opacity_get(xcb_window_t); void window_opacity_set(xcb_window_t, double); void window_grabbuttons(xcb_window_t, xcb_window_t, button_array_t *); +void window_takefocus(xcb_window_t); +bool window_hasproto(xcb_window_t, xcb_atom_t); +void window_setfocus(xcb_window_t, bool); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80