2007-10-26 18:23:15 +02:00
|
|
|
/*
|
|
|
|
* window.c - window handling functions
|
|
|
|
*
|
2008-01-26 17:58:01 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-10-26 18:23:15 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
|
|
|
#include <xcb/shape.h>
|
|
|
|
#include <xcb/xcb_keysyms.h>
|
2008-04-29 08:58:36 +02:00
|
|
|
#include <xcb/xcb_aux.h>
|
2007-10-26 18:23:15 +02:00
|
|
|
|
2008-01-26 17:58:01 +01:00
|
|
|
#include "structs.h"
|
2007-10-26 18:23:15 +02:00
|
|
|
#include "window.h"
|
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-03-06 16:04:58 +01:00
|
|
|
/** Mask shorthands */
|
2008-03-21 16:50:17 +01:00
|
|
|
#define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE)
|
2008-01-23 15:18:37 +01:00
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
/** Set client state (WM_STATE) property.
|
|
|
|
* \param win The window to set state.
|
|
|
|
* \param state The state to set.
|
2007-10-26 18:23:15 +02:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
void
|
|
|
|
window_setstate(xcb_window_t win, long state)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
long data[] = { state, XCB_NONE };
|
2008-05-11 00:30:20 +02:00
|
|
|
const xcb_atom_t wm_state_atom = xutil_intern_atom_reply(globalconf.connection, &globalconf.atoms,
|
|
|
|
xutil_intern_atom(globalconf.connection,
|
|
|
|
&globalconf.atoms,
|
|
|
|
"WM_STATE"));
|
2007-10-26 18:23:15 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win,
|
2008-05-11 00:30:20 +02:00
|
|
|
wm_state_atom, wm_state_atom, 32, 2, data);
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
/** Get a window state (WM_STATE).
|
|
|
|
* \param w A client window.
|
2008-04-30 11:01:42 +02:00
|
|
|
* \return The current state of the window, or -1 on error.
|
2007-10-26 18:23:15 +02:00
|
|
|
*/
|
|
|
|
long
|
2008-03-21 16:50:17 +01:00
|
|
|
window_getstate(xcb_window_t w)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
|
|
|
long result = -1;
|
|
|
|
unsigned char *p = NULL;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_get_property_cookie_t prop_c;
|
2008-05-11 00:30:20 +02:00
|
|
|
xcb_atom_t wm_state_atom = xutil_intern_atom_reply(globalconf.connection, &globalconf.atoms,
|
|
|
|
xutil_intern_atom(globalconf.connection,
|
|
|
|
&globalconf.atoms,
|
|
|
|
"WM_STATE"));
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_get_property_reply_t *prop_r;
|
|
|
|
|
|
|
|
prop_c = xcb_get_property_unchecked(globalconf.connection, false, w,
|
|
|
|
wm_state_atom, wm_state_atom,
|
|
|
|
0L, 2L);
|
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
if(!(prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)))
|
2007-10-26 18:23:15 +02:00
|
|
|
return -1;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
p = xcb_get_property_value(prop_r);
|
|
|
|
if(xcb_get_property_value_length(prop_r) != 0)
|
2007-10-26 18:23:15 +02:00
|
|
|
result = *p;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
p_delete(&prop_r);
|
|
|
|
|
2007-10-26 18:23:15 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
/** Configure a window with its new geometry and border size.
|
2008-06-13 19:17:35 +02:00
|
|
|
* \param win The X window id to configure.
|
2008-04-29 08:58:36 +02:00
|
|
|
* \param geometry The new window geometry.
|
|
|
|
* \param border The new border size.
|
2008-03-06 16:04:58 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
void
|
|
|
|
window_configure(xcb_window_t win, area_t geometry, int border)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_notify_event_t ce;
|
2007-10-26 18:23:15 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
ce.response_type = XCB_CONFIGURE_NOTIFY;
|
2007-10-26 18:23:15 +02:00
|
|
|
ce.event = win;
|
|
|
|
ce.window = win;
|
2008-01-05 20:25:55 +01:00
|
|
|
ce.x = geometry.x;
|
|
|
|
ce.y = geometry.y;
|
|
|
|
ce.width = geometry.width;
|
|
|
|
ce.height = geometry.height;
|
2007-10-26 18:23:15 +02:00
|
|
|
ce.border_width = border;
|
2008-03-21 16:50:17 +01:00
|
|
|
ce.above_sibling = XCB_NONE;
|
|
|
|
ce.override_redirect = false;
|
|
|
|
xcb_send_event(globalconf.connection, false, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *) &ce);
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
/** Grab or ungrab buttons on a window.
|
|
|
|
* \param win The window.
|
|
|
|
* \param phys_screen Physical screen number.
|
2008-06-13 19:17:35 +02:00
|
|
|
* \param buttons The buttons to grab.
|
2007-10-26 19:45:33 +02:00
|
|
|
*/
|
|
|
|
void
|
2008-06-13 15:35:47 +02:00
|
|
|
window_grabbuttons(xcb_window_t win, int phys_screen, button_t *buttons)
|
2007-10-26 19:45:33 +02:00
|
|
|
{
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *b;
|
2007-11-12 10:53:48 +01:00
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
for(b = buttons; b; b = b->next)
|
2008-01-25 12:55:44 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
2008-05-26 16:17:57 +02:00
|
|
|
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
2008-03-21 16:50:17 +01:00
|
|
|
b->button, b->mod);
|
|
|
|
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
2008-05-26 16:17:57 +02:00
|
|
|
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
2008-03-21 16:50:17 +01:00
|
|
|
b->button, b->mod | XCB_MOD_MASK_LOCK);
|
|
|
|
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
2008-05-26 16:17:57 +02:00
|
|
|
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
2008-03-21 16:50:17 +01:00
|
|
|
b->button, b->mod | globalconf.numlockmask);
|
|
|
|
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
|
2008-05-26 16:17:57 +02:00
|
|
|
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
|
2008-03-21 16:50:17 +01:00
|
|
|
b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
2007-10-26 19:45:33 +02:00
|
|
|
}
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
|
|
|
|
ANY_MODIFIER);
|
2008-01-25 12:55:44 +01:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/** Grab all buttons on the root window.
|
2008-03-06 16:04:58 +01:00
|
|
|
*/
|
2008-01-25 12:55:44 +01:00
|
|
|
void
|
2008-05-20 15:39:47 +02:00
|
|
|
window_root_grabbuttons(void)
|
2008-01-25 12:55:44 +01:00
|
|
|
{
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *b;
|
2008-05-20 15:39:47 +02:00
|
|
|
xcb_screen_t *s;
|
|
|
|
int phys_screen = globalconf.default_screen;
|
2008-01-25 12:55:44 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
do
|
2007-10-26 19:45:33 +02:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
|
|
|
|
for(b = globalconf.buttons.root; b; b = b->next)
|
|
|
|
{
|
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod);
|
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod | XCB_MOD_MASK_LOCK);
|
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod | globalconf.numlockmask);
|
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
|
|
|
}
|
|
|
|
phys_screen++;
|
|
|
|
} while(!globalconf.screens_info->xinerama_is_active
|
|
|
|
&& phys_screen < globalconf.screens_info->nscreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Grab button on the root window.
|
|
|
|
* \param b The button binding.
|
|
|
|
*/
|
|
|
|
void
|
2008-05-23 13:35:46 +02:00
|
|
|
window_root_grabbutton(button_t *b)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
xcb_screen_t *s;
|
|
|
|
int phys_screen = globalconf.default_screen;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
2008-03-21 16:50:17 +01:00
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
2008-03-21 16:50:17 +01:00
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod | XCB_MOD_MASK_LOCK);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
2008-03-21 16:50:17 +01:00
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod | globalconf.numlockmask);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_button(globalconf.connection, false, s->root, BUTTONMASK,
|
2008-03-21 16:50:17 +01:00
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
|
|
|
|
b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
2008-05-20 15:39:47 +02:00
|
|
|
phys_screen++;
|
|
|
|
} while(!globalconf.screens_info->xinerama_is_active
|
|
|
|
&& phys_screen < globalconf.screens_info->nscreen);
|
2007-10-26 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/** Grab key on the root windows.
|
|
|
|
* \param k The keybinding.
|
2008-03-06 16:16:39 +01:00
|
|
|
*/
|
|
|
|
void
|
2008-05-20 15:39:47 +02:00
|
|
|
window_root_grabkey(keybinding_t *k)
|
2008-03-06 16:16:39 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
int phys_screen = globalconf.default_screen;
|
|
|
|
xcb_screen_t *s;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_keycode_t kc;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
if((kc = k->keycode)
|
|
|
|
|| (k->keysym && (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym))))
|
|
|
|
do
|
2008-03-06 16:16:39 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_key(globalconf.connection, true, s->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_key(globalconf.connection, true, s->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
k->mod | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_key(globalconf.connection, true, s->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
k->mod | globalconf.numlockmask, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_grab_key(globalconf.connection, true, s->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC,
|
|
|
|
XCB_GRAB_MODE_ASYNC);
|
2008-05-20 15:39:47 +02:00
|
|
|
phys_screen++;
|
|
|
|
} while(!globalconf.screens_info->xinerama_is_active
|
|
|
|
&& phys_screen < globalconf.screens_info->nscreen);
|
2008-05-28 12:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Ungrab key on the root windows.
|
|
|
|
* \param k The keybinding.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
window_root_ungrabkey(keybinding_t *k)
|
|
|
|
{
|
|
|
|
int phys_screen = globalconf.default_screen;
|
|
|
|
xcb_screen_t *s;
|
|
|
|
xcb_keycode_t kc;
|
|
|
|
|
|
|
|
if((kc = k->keycode)
|
|
|
|
|| (k->keysym && (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym))))
|
|
|
|
do
|
|
|
|
{
|
|
|
|
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
|
|
|
|
xcb_ungrab_key(globalconf.connection, kc, s->root,
|
|
|
|
k->mod);
|
|
|
|
xcb_ungrab_key(globalconf.connection, kc, s->root,
|
|
|
|
k->mod | XCB_MOD_MASK_LOCK);
|
|
|
|
xcb_ungrab_key(globalconf.connection, kc, s->root,
|
|
|
|
k->mod | globalconf.numlockmask);
|
|
|
|
xcb_ungrab_key(globalconf.connection, kc, s->root,
|
|
|
|
k->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
|
|
|
|
phys_screen++;
|
|
|
|
} while(!globalconf.screens_info->xinerama_is_active
|
|
|
|
&& phys_screen < globalconf.screens_info->nscreen);
|
2008-03-06 16:16:39 +01:00
|
|
|
}
|
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
/** Set shape property on window.
|
|
|
|
* \param win The window.
|
|
|
|
* \param phys_screen Physical screen number.
|
|
|
|
*/
|
2007-10-26 19:35:07 +02:00
|
|
|
void
|
2008-03-21 16:50:17 +01:00
|
|
|
window_setshape(xcb_window_t win, int phys_screen)
|
2007-10-26 19:35:07 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_shape_query_extents_reply_t *r;
|
2008-03-21 11:33:50 +01:00
|
|
|
|
2007-10-26 19:35:07 +02:00
|
|
|
/* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
|
2008-03-21 16:50:17 +01:00
|
|
|
if((r = xcb_shape_query_extents_reply(globalconf.connection,
|
|
|
|
xcb_shape_query_extents_unchecked(globalconf.connection, win),
|
|
|
|
NULL)) && r->bounding_shaped)
|
|
|
|
xcb_shape_combine(globalconf.connection, XCB_SHAPE_SO_SET,
|
|
|
|
XCB_SHAPE_SK_BOUNDING, XCB_SHAPE_SK_BOUNDING,
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
0, 0, win);
|
|
|
|
|
2008-04-30 11:01:42 +02:00
|
|
|
p_delete(&r);
|
2007-10-26 19:35:07 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 08:58:36 +02:00
|
|
|
/** Set transparency of a window.
|
|
|
|
* \param win The window.
|
|
|
|
* \param opacity Opacity of the window, between 0 and 1.
|
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
void
|
|
|
|
window_settrans(xcb_window_t win, double opacity)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
|
|
|
unsigned int real_opacity = 0xffffffff;
|
2008-05-11 00:30:20 +02:00
|
|
|
const xcb_atom_t wopacity_atom = xutil_intern_atom_reply(globalconf.connection,
|
|
|
|
&globalconf.atoms,
|
|
|
|
xutil_intern_atom(globalconf.connection,
|
|
|
|
&globalconf.atoms,
|
|
|
|
"_NET_WM_WINDOW_OPACITY"));
|
2007-10-26 18:23:15 +02:00
|
|
|
|
2008-03-24 07:47:07 +01:00
|
|
|
if(opacity >= 0 && opacity <= 1)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
2008-03-24 07:47:07 +01:00
|
|
|
real_opacity = opacity * 0xffffffff;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win,
|
2008-05-11 00:30:20 +02:00
|
|
|
wopacity_atom, CARDINAL, 32, 1L, &real_opacity);
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
else
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_delete_property(globalconf.connection, win,
|
2008-05-11 00:30:20 +02:00
|
|
|
wopacity_atom);
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|