client: move window function into window.c
This should light client.c a bit. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
904502552f
commit
e53c77540d
61
client.c
61
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_EQ(client_t, client, "client")
|
||||||
DO_LUA_GC(client_t, client, "client", client_unref)
|
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.
|
/** Change the clients urgency flag.
|
||||||
* \param c The client
|
* \param c The client
|
||||||
* \param urgent The new flag state
|
* \param urgent The new flag state
|
||||||
|
@ -185,21 +139,6 @@ client_getbywin(xcb_window_t w)
|
||||||
return c;
|
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.
|
/** Record that a client lost focus.
|
||||||
* \param c Client being unfocused
|
* \param c Client being unfocused
|
||||||
*/
|
*/
|
||||||
|
|
61
window.c
61
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);
|
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
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
3
window.h
3
window.h
|
@ -32,6 +32,9 @@ void window_buttons_grab(xcb_window_t, button_array_t *);
|
||||||
double window_opacity_get(xcb_window_t);
|
double window_opacity_get(xcb_window_t);
|
||||||
void window_opacity_set(xcb_window_t, double);
|
void window_opacity_set(xcb_window_t, double);
|
||||||
void window_grabbuttons(xcb_window_t, xcb_window_t, button_array_t *);
|
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
|
#endif
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue