2007-10-03 17:26:14 +02:00
|
|
|
/*
|
2007-09-12 14:29:51 +02:00
|
|
|
* event.c - event handlers
|
2007-10-03 17:26:14 +02:00
|
|
|
*
|
2008-01-02 16:59:43 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-10-03 17:26:14 +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.
|
|
|
|
*
|
2007-09-12 14:29:51 +02:00
|
|
|
*/
|
|
|
|
|
2008-06-26 18:10:45 +02:00
|
|
|
#include <xcb/xcb.h>
|
2008-06-26 22:42:58 +02:00
|
|
|
#include <xcb/randr.h>
|
2008-09-16 15:36:44 +02:00
|
|
|
#include <xcb/xcb_atom.h>
|
2008-07-28 17:54:33 +02:00
|
|
|
#include <xcb/xcb_icccm.h>
|
2008-09-16 15:36:44 +02:00
|
|
|
#include <xcb/xcb_event.h>
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-09-02 17:12:10 +02:00
|
|
|
#include "awesome.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "event.h"
|
2008-06-27 22:50:10 +02:00
|
|
|
#include "tag.h"
|
2007-10-26 18:23:15 +02:00
|
|
|
#include "window.h"
|
2007-12-27 20:49:38 +01:00
|
|
|
#include "ewmh.h"
|
2008-01-01 17:25:48 +01:00
|
|
|
#include "client.h"
|
2008-01-07 18:12:38 +01:00
|
|
|
#include "widget.h"
|
2008-03-15 16:38:51 +01:00
|
|
|
#include "titlebar.h"
|
2008-12-18 11:33:19 +01:00
|
|
|
#include "key.h"
|
2008-06-10 16:50:55 +02:00
|
|
|
#include "keygrabber.h"
|
2008-11-13 16:08:34 +01:00
|
|
|
#include "mousegrabber.h"
|
2008-09-17 16:38:38 +02:00
|
|
|
#include "luaa.h"
|
2008-06-14 18:12:16 +02:00
|
|
|
#include "systray.h"
|
2008-09-03 22:37:43 +02:00
|
|
|
#include "screen.h"
|
2008-06-30 18:55:14 +02:00
|
|
|
#include "common/atoms.h"
|
2009-04-17 16:52:25 +02:00
|
|
|
#include "common/xutil.h"
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2009-04-27 17:46:15 +02:00
|
|
|
#define DO_EVENT_HOOK_CALLBACK(xcbtype, xcbeventprefix, type, arraytype, match) \
|
|
|
|
static void \
|
|
|
|
event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
|
|
|
|
arraytype *arr, \
|
2009-04-27 17:56:06 +02:00
|
|
|
int nargs, \
|
|
|
|
void *data) \
|
2009-04-27 17:46:15 +02:00
|
|
|
{ \
|
|
|
|
foreach(item, *arr) \
|
2009-04-27 17:56:06 +02:00
|
|
|
if(match(ev, *item, data)) \
|
2009-04-27 17:46:15 +02:00
|
|
|
switch(ev->response_type) \
|
|
|
|
{ \
|
|
|
|
case xcbeventprefix##_PRESS: \
|
|
|
|
if((*item)->press != LUA_REFNIL) \
|
|
|
|
{ \
|
|
|
|
for(int i = 0; i < nargs; i++) \
|
|
|
|
lua_pushvalue(globalconf.L, - nargs); \
|
|
|
|
luaA_dofunction(globalconf.L, (*item)->press, nargs, 0); \
|
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
case xcbeventprefix##_RELEASE: \
|
|
|
|
if((*item)->release != LUA_REFNIL) \
|
|
|
|
{ \
|
|
|
|
for(int i = 0; i < nargs; i++) \
|
|
|
|
lua_pushvalue(globalconf.L, - nargs); \
|
|
|
|
luaA_dofunction(globalconf.L, (*item)->release, nargs, 0); \
|
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
lua_pop(globalconf.L, nargs); \
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2009-04-27 17:56:06 +02:00
|
|
|
event_button_match(xcb_button_press_event_t *ev, button_t *b, void *data)
|
2007-11-11 16:33:59 +01:00
|
|
|
{
|
2009-04-27 17:46:15 +02:00
|
|
|
return ((!b->button || ev->detail == b->button)
|
|
|
|
&& (b->mod == XCB_BUTTON_MASK_ANY || b->mod == ev->state));
|
2007-11-11 16:33:59 +01:00
|
|
|
}
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2009-04-27 17:52:36 +02:00
|
|
|
static bool
|
2009-04-27 17:56:06 +02:00
|
|
|
event_key_match(xcb_key_press_event_t *ev, keyb_t *k, void *data)
|
2009-04-27 17:52:36 +02:00
|
|
|
{
|
2009-04-27 17:56:06 +02:00
|
|
|
assert(data);
|
|
|
|
xcb_keysym_t keysym = *(xcb_keysym_t *) data;
|
2009-04-27 17:52:36 +02:00
|
|
|
return (((k->keycode && ev->detail == k->keycode)
|
|
|
|
|| (k->keysym && keysym == k->keysym))
|
|
|
|
&& (k->mod == XCB_BUTTON_MASK_ANY || k->mod == ev->state));
|
|
|
|
}
|
|
|
|
|
2009-04-27 17:46:15 +02:00
|
|
|
DO_EVENT_HOOK_CALLBACK(button, XCB_BUTTON, button_t, button_array_t, event_button_match)
|
2009-04-27 17:52:36 +02:00
|
|
|
DO_EVENT_HOOK_CALLBACK(key, XCB_KEY, keyb_t, key_array_t, event_key_match)
|
2009-04-27 17:46:15 +02:00
|
|
|
|
2008-11-13 16:08:34 +01:00
|
|
|
/** Handle an event with mouse grabber if needed
|
|
|
|
* \param x The x coordinate.
|
|
|
|
* \param y The y coordinate.
|
|
|
|
* \param mask The mask buttons.
|
2009-04-29 13:59:13 +02:00
|
|
|
* \return True if the event was handled.
|
2008-11-13 16:08:34 +01:00
|
|
|
*/
|
2009-04-29 13:59:13 +02:00
|
|
|
static bool
|
2008-11-13 16:08:34 +01:00
|
|
|
event_handle_mousegrabber(int x, int y, uint16_t mask)
|
|
|
|
{
|
|
|
|
if(globalconf.mousegrabber != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.mousegrabber);
|
|
|
|
mousegrabber_handleevent(globalconf.L, x, y, mask);
|
|
|
|
if(lua_pcall(globalconf.L, 1, 1, 0))
|
|
|
|
{
|
|
|
|
warn("error running function: %s", lua_tostring(globalconf.L, -1));
|
|
|
|
luaA_mousegrabber_stop(globalconf.L);
|
|
|
|
}
|
|
|
|
else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1))
|
|
|
|
luaA_mousegrabber_stop(globalconf.L);
|
|
|
|
lua_pop(globalconf.L, 1); /* pop returned value */
|
2009-04-29 13:59:13 +02:00
|
|
|
return true;
|
2008-11-13 16:08:34 +01:00
|
|
|
}
|
2009-04-29 13:59:13 +02:00
|
|
|
return false;
|
2008-11-13 16:08:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The button press event handler.
|
2008-08-12 13:23:10 +02:00
|
|
|
* \param data The type of mouse event.
|
2008-06-13 18:20:20 +02:00
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-08-12 13:23:10 +02:00
|
|
|
event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-08-25 13:40:55 +02:00
|
|
|
int screen;
|
2008-05-20 20:30:07 +02:00
|
|
|
const int nb_screen = xcb_setup_roots_length(xcb_get_setup(connection));
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_t *wibox;
|
2008-04-09 18:27:25 +02:00
|
|
|
|
2008-08-12 13:23:10 +02:00
|
|
|
/* ev->state is
|
|
|
|
* button status (8 bits) + modifiers status (8 bits)
|
|
|
|
* we don't care for button status that we get, especially on release, so
|
|
|
|
* drop them */
|
|
|
|
ev->state &= 0x00ff;
|
|
|
|
|
2009-04-29 13:59:13 +02:00
|
|
|
if(event_handle_mousegrabber(ev->root_x, ev->root_y, ev->state))
|
|
|
|
return 0;
|
2008-11-13 16:08:34 +01:00
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
if((wibox = wibox_getbywin(ev->event))
|
|
|
|
|| (wibox = wibox_getbywin(ev->child)))
|
|
|
|
{
|
|
|
|
/* If the wibox is child, then x,y are
|
|
|
|
* relative to root window */
|
|
|
|
if(wibox->sw.window == ev->child)
|
2008-09-20 16:45:43 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
ev->event_x -= wibox->sw.geometry.x;
|
|
|
|
ev->event_y -= wibox->sw.geometry.y;
|
2008-09-20 16:45:43 +02:00
|
|
|
}
|
2008-12-10 18:05:08 +01:00
|
|
|
|
2009-04-27 17:46:15 +02:00
|
|
|
wibox_push(globalconf.L, wibox);
|
2009-04-27 17:56:06 +02:00
|
|
|
event_button_callback(ev, &wibox->buttons, 1, NULL);
|
2008-12-10 18:05:08 +01:00
|
|
|
|
|
|
|
/* then try to match a widget binding */
|
2009-04-09 15:12:17 +02:00
|
|
|
widget_t *w = widget_getbycoords(wibox->position, &wibox->widgets,
|
|
|
|
wibox->sw.geometry.width,
|
|
|
|
wibox->sw.geometry.height,
|
|
|
|
&ev->event_x, &ev->event_y);
|
|
|
|
if(w)
|
2009-04-27 17:46:15 +02:00
|
|
|
{
|
|
|
|
widget_push(globalconf.L, w);
|
2009-04-29 14:59:29 +02:00
|
|
|
wibox_push(globalconf.L, wibox);
|
|
|
|
event_button_callback(ev, &w->buttons, 2, NULL);
|
2009-04-27 17:46:15 +02:00
|
|
|
}
|
2008-06-03 18:41:54 +02:00
|
|
|
}
|
2009-02-24 17:32:48 +01:00
|
|
|
else if((c = client_getbywin(ev->event)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2009-04-27 17:46:15 +02:00
|
|
|
client_push(globalconf.L, c);
|
2009-04-27 17:56:06 +02:00
|
|
|
event_button_callback(ev, &c->buttons, 1, NULL);
|
2008-08-12 13:23:10 +02:00
|
|
|
xcb_allow_events(globalconf.connection,
|
|
|
|
XCB_ALLOW_REPLAY_POINTER,
|
|
|
|
XCB_CURRENT_TIME);
|
2007-10-16 01:24:04 +02:00
|
|
|
}
|
2009-02-24 17:32:48 +01:00
|
|
|
else if(ev->child == XCB_NONE)
|
2008-05-20 20:30:07 +02:00
|
|
|
for(screen = 0; screen < nb_screen; screen++)
|
2008-06-17 16:55:24 +02:00
|
|
|
if(xutil_screen_get(connection, screen)->root == ev->event)
|
2007-09-16 00:17:05 +02:00
|
|
|
{
|
2009-04-27 17:56:06 +02:00
|
|
|
event_button_callback(ev, &globalconf.buttons, 0, NULL);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-09-16 00:17:05 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 15:20:04 +01:00
|
|
|
static void
|
|
|
|
event_handle_configurerequest_configure_window(xcb_configure_request_event_t *ev)
|
|
|
|
{
|
|
|
|
uint16_t config_win_mask = 0;
|
|
|
|
uint32_t config_win_vals[7];
|
|
|
|
unsigned short i = 0;
|
|
|
|
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_X)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_X;
|
|
|
|
config_win_vals[i++] = ev->x;
|
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_Y;
|
|
|
|
config_win_vals[i++] = ev->y;
|
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_WIDTH;
|
|
|
|
config_win_vals[i++] = ev->width;
|
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_HEIGHT;
|
|
|
|
config_win_vals[i++] = ev->height;
|
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_BORDER_WIDTH;
|
|
|
|
config_win_vals[i++] = ev->border_width;
|
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_SIBLING)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_SIBLING;
|
|
|
|
config_win_vals[i++] = ev->sibling;
|
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_STACK_MODE)
|
|
|
|
{
|
|
|
|
config_win_mask |= XCB_CONFIG_WINDOW_STACK_MODE;
|
|
|
|
config_win_vals[i++] = ev->stack_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_configure_window(globalconf.connection, ev->window, config_win_mask, config_win_vals);
|
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The configure event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_configurerequest(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_configure_request_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t geometry;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
if((c = client_getbywin(ev->window)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2009-02-02 20:09:44 +01:00
|
|
|
geometry = titlebar_geometry_remove(c->titlebar, c->border, c->geometry);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_X)
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry.x = ev->x;
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry.y = ev->y;
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry.width = ev->width;
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry.height = ev->height;
|
|
|
|
|
2009-03-29 20:26:39 +02:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH)
|
2009-02-14 20:41:54 +01:00
|
|
|
client_setborder(c, ev->border_width);
|
|
|
|
|
2009-02-14 20:41:55 +01:00
|
|
|
/* Clients are not allowed to directly mess with stacking parameters. */
|
|
|
|
ev->value_mask &= ~(XCB_CONFIG_WINDOW_SIBLING |
|
|
|
|
XCB_CONFIG_WINDOW_STACK_MODE);
|
|
|
|
|
2009-02-02 20:09:44 +01:00
|
|
|
if(c->isbanned)
|
|
|
|
{
|
|
|
|
/* We'll be sending protocol geometry, so don't readd borders and titlebar. */
|
|
|
|
/* We do have to ensure the windows don't end up in the visible screen. */
|
2009-02-14 20:41:53 +01:00
|
|
|
ev->x = geometry.x = - (geometry.width + 2*c->border);
|
|
|
|
ev->y = geometry.y = - (geometry.height + 2*c->border);
|
2009-02-08 13:48:17 +01:00
|
|
|
window_configure(c->win, geometry, c->border);
|
|
|
|
event_handle_configurerequest_configure_window(ev);
|
2009-02-02 20:09:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/** Configure request are sent with size relative to real (internal)
|
|
|
|
* window size, i.e. without titlebars and borders. */
|
|
|
|
geometry = titlebar_geometry_add(c->titlebar, c->border, geometry);
|
2009-01-10 10:01:51 +01:00
|
|
|
|
2009-02-08 13:48:17 +01:00
|
|
|
if(client_resize(c, geometry, false))
|
2009-01-30 15:20:04 +01:00
|
|
|
{
|
|
|
|
/* All the wiboxes (may) need to be repositioned. */
|
|
|
|
if(client_hasstrut(c))
|
|
|
|
wibox_update_positions();
|
|
|
|
client_need_arrange(c);
|
2009-02-08 13:48:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Resize wasn't officially needed, but we don't want to break expectations. */
|
|
|
|
geometry = titlebar_geometry_remove(c->titlebar, c->border, c->geometry);
|
|
|
|
window_configure(c->win, geometry, c->border);
|
2009-01-30 15:20:04 +01:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-01-30 15:20:04 +01:00
|
|
|
event_handle_configurerequest_configure_window(ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The configure notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_configurenotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_configure_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
int screen_nbr;
|
|
|
|
const xcb_screen_t *screen;
|
|
|
|
|
2008-03-22 14:29:15 +01:00
|
|
|
for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length(xcb_get_setup (connection)); screen_nbr++)
|
2008-06-17 16:55:24 +02:00
|
|
|
if((screen = xutil_screen_get(connection, screen_nbr)) != NULL
|
2008-03-27 16:05:37 +01:00
|
|
|
&& ev->window == screen->root
|
2008-03-21 16:50:17 +01:00
|
|
|
&& (ev->width != screen->width_in_pixels
|
|
|
|
|| ev->height != screen->height_in_pixels))
|
2008-01-25 23:15:27 +01:00
|
|
|
/* it's not that we panic, but restart */
|
2008-09-02 17:12:10 +02:00
|
|
|
awesome_restart();
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The destroy notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_destroynotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection __attribute__ ((unused)),
|
|
|
|
xcb_destroy_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
if((c = client_getbywin(ev->window)))
|
2008-01-06 21:57:53 +01:00
|
|
|
client_unmanage(c);
|
2008-12-01 16:43:44 +01:00
|
|
|
else
|
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
|
|
|
if(globalconf.embedded.tab[i].win == ev->window)
|
|
|
|
{
|
|
|
|
xembed_window_array_take(&globalconf.embedded, i);
|
2009-04-17 16:14:09 +02:00
|
|
|
foreach(screen, globalconf.screens)
|
|
|
|
widget_invalidate_bytype(screen, widget_systray);
|
2008-12-01 16:43:44 +01:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-08-25 14:34:56 +02:00
|
|
|
/** Handle a motion notify over widgets.
|
|
|
|
* \param object The object.
|
|
|
|
* \param mouse_over The pointer to the registered mouse over widget.
|
2008-11-12 14:37:22 +01:00
|
|
|
* \param widget The new widget the mouse is over.
|
2008-08-25 14:34:56 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
event_handle_widget_motionnotify(void *object,
|
2008-10-21 17:21:21 +02:00
|
|
|
widget_t **mouse_over,
|
2008-11-12 14:37:22 +01:00
|
|
|
widget_t *widget)
|
2008-08-25 14:34:56 +02:00
|
|
|
{
|
2008-11-12 14:37:22 +01:00
|
|
|
if(widget != *mouse_over)
|
2008-08-25 14:34:56 +02:00
|
|
|
{
|
|
|
|
if(*mouse_over)
|
|
|
|
{
|
2008-11-20 17:48:23 +01:00
|
|
|
if((*mouse_over)->mouse_leave != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
/* call mouse leave function on old widget */
|
2009-04-11 00:27:06 +02:00
|
|
|
widget_push(globalconf.L, *mouse_over);
|
2008-11-20 17:48:23 +01:00
|
|
|
luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
|
|
|
|
}
|
2008-08-25 14:34:56 +02:00
|
|
|
}
|
2008-11-12 14:37:22 +01:00
|
|
|
if(widget)
|
2008-08-25 14:34:56 +02:00
|
|
|
{
|
|
|
|
/* call mouse enter function on new widget and register it */
|
2008-11-12 14:37:22 +01:00
|
|
|
*mouse_over = widget;
|
|
|
|
if(widget->mouse_enter != LUA_REFNIL)
|
2008-11-20 17:48:23 +01:00
|
|
|
{
|
2009-04-11 00:27:06 +02:00
|
|
|
widget_push(globalconf.L, widget);
|
2008-11-12 14:37:22 +01:00
|
|
|
luaA_dofunction(globalconf.L, widget->mouse_enter, 1, 0);
|
2008-11-20 17:48:23 +01:00
|
|
|
}
|
2008-08-25 14:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The motion notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
event_handle_motionnotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
xcb_motion_notify_event_t *ev)
|
|
|
|
{
|
2009-02-14 20:41:56 +01:00
|
|
|
wibox_t *wibox;
|
2008-08-25 14:34:56 +02:00
|
|
|
|
2009-04-29 13:59:13 +02:00
|
|
|
if(event_handle_mousegrabber(ev->root_x, ev->root_y, ev->state))
|
|
|
|
return 0;
|
2008-11-13 16:08:34 +01:00
|
|
|
|
2009-04-09 15:12:17 +02:00
|
|
|
if((wibox = wibox_getbywin(ev->event)))
|
|
|
|
{
|
|
|
|
widget_t *w = widget_getbycoords(wibox->position, &wibox->widgets,
|
|
|
|
wibox->sw.geometry.width,
|
|
|
|
wibox->sw.geometry.height,
|
|
|
|
&ev->event_x, &ev->event_y);
|
|
|
|
if(w)
|
|
|
|
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
|
|
|
|
}
|
2008-08-25 14:34:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The leave notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
event_handle_leavenotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
xcb_leave_notify_event_t *ev)
|
|
|
|
{
|
2008-12-01 15:43:16 +01:00
|
|
|
wibox_t *wibox;
|
2009-02-14 20:41:56 +01:00
|
|
|
client_t *c;
|
2008-08-25 14:34:56 +02:00
|
|
|
|
2009-04-04 16:16:02 +02:00
|
|
|
if(ev->mode != XCB_NOTIFY_MODE_NORMAL)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-12 14:32:36 +02:00
|
|
|
if((c = client_getbytitlebarwin(ev->event)) || (c = client_getbywin(ev->event)))
|
2008-12-01 15:43:16 +01:00
|
|
|
if(globalconf.hooks.mouse_leave != LUA_REFNIL)
|
|
|
|
{
|
2009-04-10 15:23:55 +02:00
|
|
|
client_push(globalconf.L, c);
|
2008-12-01 15:43:16 +01:00
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.mouse_leave, 1, 0);
|
|
|
|
}
|
2009-04-12 14:32:36 +02:00
|
|
|
|
|
|
|
if((wibox = wibox_getbywin(ev->event)))
|
2008-08-25 14:34:56 +02:00
|
|
|
{
|
2008-12-01 15:43:16 +01:00
|
|
|
if(wibox->mouse_over)
|
2008-11-20 17:48:23 +01:00
|
|
|
{
|
2008-12-01 15:43:16 +01:00
|
|
|
if(wibox->mouse_over->mouse_leave != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
/* call mouse leave function on widget the mouse was over */
|
2009-04-11 00:27:06 +02:00
|
|
|
wibox_push(globalconf.L, wibox);
|
2008-12-01 15:43:16 +01:00
|
|
|
luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
|
|
|
|
}
|
|
|
|
wibox->mouse_over = NULL;
|
2008-11-20 17:48:23 +01:00
|
|
|
}
|
2009-02-13 21:19:14 +01:00
|
|
|
|
|
|
|
if(wibox->mouse_leave != LUA_REFNIL)
|
|
|
|
luaA_dofunction(globalconf.L, wibox->mouse_leave, 0, 0);
|
2008-08-25 14:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The enter notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-04 10:14:13 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_enternotify(void *data __attribute__ ((unused)),
|
2008-06-14 18:12:16 +02:00
|
|
|
xcb_connection_t *connection,
|
2008-05-20 15:39:47 +02:00
|
|
|
xcb_enter_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-14 18:12:16 +02:00
|
|
|
client_t *c;
|
2009-02-14 20:41:56 +01:00
|
|
|
wibox_t *wibox;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2009-03-06 14:01:29 +01:00
|
|
|
if(ev->mode != XCB_NOTIFY_MODE_NORMAL)
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2008-01-24 18:31:44 +01:00
|
|
|
|
2009-02-14 20:41:56 +01:00
|
|
|
if((wibox = wibox_getbywin(ev->event)))
|
2008-10-25 15:35:14 +02:00
|
|
|
{
|
2009-04-09 15:12:17 +02:00
|
|
|
widget_t *w = widget_getbycoords(wibox->position, &wibox->widgets,
|
|
|
|
wibox->sw.geometry.width,
|
|
|
|
wibox->sw.geometry.height,
|
|
|
|
&ev->event_x, &ev->event_y);
|
|
|
|
if(w)
|
2009-02-13 21:19:14 +01:00
|
|
|
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
|
|
|
|
|
|
|
|
if(wibox->mouse_enter != LUA_REFNIL)
|
|
|
|
luaA_dofunction(globalconf.L, wibox->mouse_enter, 0, 0);
|
2008-10-25 15:35:14 +02:00
|
|
|
}
|
2009-04-12 14:29:53 +02:00
|
|
|
|
|
|
|
if((c = client_getbytitlebarwin(ev->event))
|
2008-06-05 09:25:38 +02:00
|
|
|
|| (c = client_getbywin(ev->event)))
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.mouse_enter != LUA_REFNIL)
|
|
|
|
{
|
2009-04-10 15:23:55 +02:00
|
|
|
client_push(globalconf.L, c);
|
2008-11-20 17:48:23 +01:00
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
|
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2008-03-04 10:14:13 +01:00
|
|
|
}
|
|
|
|
|
2009-02-28 21:08:41 +01:00
|
|
|
/** The focus in event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
event_handle_focusin(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
xcb_focus_in_event_t *ev)
|
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
2009-04-07 14:20:22 +02:00
|
|
|
/* Events that we are interested in: */
|
|
|
|
switch(ev->detail)
|
|
|
|
{
|
2009-04-28 10:54:10 +02:00
|
|
|
/* These are events that jump between root windows.
|
2009-04-07 14:20:22 +02:00
|
|
|
*/
|
|
|
|
case XCB_NOTIFY_DETAIL_ANCESTOR:
|
|
|
|
case XCB_NOTIFY_DETAIL_INFERIOR:
|
|
|
|
|
|
|
|
/* These are events that jump between clients.
|
|
|
|
* Virtual events ensure we always get an event on our top-level window.
|
|
|
|
*/
|
|
|
|
case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL:
|
|
|
|
case XCB_NOTIFY_DETAIL_NONLINEAR:
|
|
|
|
if((c = client_getbytitlebarwin(ev->event))
|
|
|
|
|| (c = client_getbywin(ev->event)))
|
|
|
|
client_focus_update(c);
|
|
|
|
/* all other events are ignored */
|
|
|
|
default:
|
2009-04-28 10:54:10 +02:00
|
|
|
break;
|
2009-04-07 14:20:22 +02:00
|
|
|
}
|
2009-04-28 10:54:10 +02:00
|
|
|
return 0;
|
2009-02-28 21:08:41 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The expose event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_expose(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection __attribute__ ((unused)),
|
|
|
|
xcb_expose_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2009-02-14 20:41:56 +01:00
|
|
|
wibox_t *wibox;
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2009-02-14 20:41:56 +01:00
|
|
|
if((wibox = wibox_getbywin(ev->window)))
|
2008-09-24 12:13:21 +02:00
|
|
|
simplewindow_refresh_pixmap_partial(&wibox->sw,
|
|
|
|
ev->x, ev->y,
|
|
|
|
ev->width, ev->height);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The key press event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-12-16 12:00:51 +01:00
|
|
|
event_handle_key(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection __attribute__ ((unused)),
|
|
|
|
xcb_key_press_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-10 16:50:55 +02:00
|
|
|
if(globalconf.keygrabber != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.keygrabber);
|
2008-06-10 22:37:45 +02:00
|
|
|
if(keygrabber_handlekpress(globalconf.L, ev))
|
2008-06-10 16:50:55 +02:00
|
|
|
{
|
2008-12-16 15:02:54 +01:00
|
|
|
if(lua_pcall(globalconf.L, 3, 1, 0))
|
2008-06-10 22:37:45 +02:00
|
|
|
{
|
|
|
|
warn("error running function: %s", lua_tostring(globalconf.L, -1));
|
2008-11-10 17:26:38 +01:00
|
|
|
luaA_keygrabber_stop(globalconf.L);
|
2008-06-10 22:37:45 +02:00
|
|
|
}
|
|
|
|
else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1))
|
2008-11-10 17:26:38 +01:00
|
|
|
luaA_keygrabber_stop(globalconf.L);
|
2008-06-10 16:50:55 +02:00
|
|
|
}
|
2008-06-10 22:37:45 +02:00
|
|
|
lua_pop(globalconf.L, 1); /* pop returned value or function if not called */
|
2008-06-10 16:50:55 +02:00
|
|
|
}
|
2009-04-27 17:56:06 +02:00
|
|
|
else
|
2009-01-05 16:59:20 +01:00
|
|
|
{
|
2009-04-28 17:26:15 +02:00
|
|
|
/* get keysym ignoring all modifiers */
|
|
|
|
xcb_keysym_t keysym = key_getkeysym(ev->detail, 0);
|
2009-04-27 17:56:06 +02:00
|
|
|
client_t *c;
|
|
|
|
if((c = client_getbywin(ev->event)))
|
|
|
|
{
|
|
|
|
client_push(globalconf.L, c);
|
|
|
|
event_key_callback(ev, &c->keys, 1, &keysym);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
event_key_callback(ev, &globalconf.keys, 0, &keysym);
|
2009-01-05 16:59:20 +01:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The map request event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_maprequest(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_map_request_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-12-29 12:26:01 +01:00
|
|
|
int phys_screen, ret = 0;
|
2008-05-20 20:30:07 +02:00
|
|
|
client_t *c;
|
2008-04-09 18:27:25 +02:00
|
|
|
xcb_get_window_attributes_cookie_t wa_c;
|
|
|
|
xcb_get_window_attributes_reply_t *wa_r;
|
|
|
|
xcb_get_geometry_cookie_t geom_c;
|
|
|
|
xcb_get_geometry_reply_t *geom_r;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-06-21 12:56:51 +02:00
|
|
|
wa_c = xcb_get_window_attributes_unchecked(connection, ev->window);
|
2008-04-09 18:27:25 +02:00
|
|
|
|
|
|
|
if(!(wa_r = xcb_get_window_attributes_reply(connection, wa_c, NULL)))
|
2008-03-21 16:50:17 +01:00
|
|
|
return -1;
|
2008-04-09 18:27:25 +02:00
|
|
|
|
|
|
|
if(wa_r->override_redirect)
|
2008-06-05 18:13:11 +02:00
|
|
|
goto bailout;
|
2008-03-30 15:46:58 +02:00
|
|
|
|
2008-12-01 16:43:44 +01:00
|
|
|
if(xembed_getbywin(&globalconf.embedded, ev->window))
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
|
|
|
xcb_map_window(connection, ev->window);
|
|
|
|
xembed_window_activate(connection, ev->window);
|
|
|
|
}
|
2008-06-27 22:50:10 +02:00
|
|
|
else if((c = client_getbywin(ev->window)))
|
|
|
|
{
|
2008-09-06 13:52:05 +02:00
|
|
|
/* Check that it may be visible, but not asked to be hidden */
|
|
|
|
if(client_maybevisible(c, c->screen) && !c->ishidden)
|
2008-06-28 11:47:29 +02:00
|
|
|
{
|
2008-09-18 13:51:10 +02:00
|
|
|
client_setminimized(c, false);
|
2008-06-28 11:47:29 +02:00
|
|
|
/* it will be raised, so just update ourself */
|
|
|
|
client_raise(c);
|
|
|
|
}
|
2008-06-27 22:50:10 +02:00
|
|
|
}
|
|
|
|
else
|
2008-05-20 20:30:07 +02:00
|
|
|
{
|
2008-06-21 12:56:51 +02:00
|
|
|
geom_c = xcb_get_geometry_unchecked(connection, ev->window);
|
2008-05-20 20:30:07 +02:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
if(!(geom_r = xcb_get_geometry_reply(connection, geom_c, NULL)))
|
2008-05-20 20:30:07 +02:00
|
|
|
{
|
2008-06-30 13:06:23 +02:00
|
|
|
ret = -1;
|
|
|
|
goto bailout;
|
2008-05-20 20:30:07 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-10-06 11:42:02 +02:00
|
|
|
phys_screen = xutil_root2screen(connection, geom_r->root);
|
2008-09-03 22:25:24 +02:00
|
|
|
|
2008-12-29 12:26:01 +01:00
|
|
|
client_manage(ev->window, geom_r, phys_screen, false);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
p_delete(&geom_r);
|
2007-09-16 00:11:10 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-06-05 18:13:11 +02:00
|
|
|
bailout:
|
|
|
|
p_delete(&wa_r);
|
2008-06-30 13:06:23 +02:00
|
|
|
return ret;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The unmap notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_unmapnotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_unmap_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-06-29 13:38:02 +02:00
|
|
|
if((c = client_getbywin(ev->window)))
|
|
|
|
{
|
|
|
|
if(ev->event == xutil_screen_get(connection, c->phys_screen)->root
|
2008-09-16 15:36:44 +02:00
|
|
|
&& XCB_EVENT_SENT(ev)
|
2008-09-09 16:14:36 +02:00
|
|
|
&& window_state_get_reply(window_state_get_unchecked(c->win)) == XCB_WM_STATE_NORMAL)
|
2008-06-29 13:38:02 +02:00
|
|
|
client_unmanage(c);
|
|
|
|
}
|
2008-12-01 16:43:44 +01:00
|
|
|
else
|
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
|
|
|
if(globalconf.embedded.tab[i].win == ev->window)
|
|
|
|
{
|
|
|
|
xembed_window_array_take(&globalconf.embedded, i);
|
2009-04-17 16:14:09 +02:00
|
|
|
foreach(screen, globalconf.screens)
|
|
|
|
widget_invalidate_bytype(screen, widget_systray);
|
2008-12-01 16:43:44 +01:00
|
|
|
}
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The randr screen change notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_randr_screen_change_notify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection __attribute__ ((unused)),
|
|
|
|
xcb_randr_screen_change_notify_event_t *ev)
|
2007-09-13 16:00:03 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
if(!globalconf.have_randr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Code of XRRUpdateConfiguration Xlib function ported to XCB
|
|
|
|
* (only the code relevant to RRScreenChangeNotify) as the latter
|
|
|
|
* doesn't provide this kind of function */
|
|
|
|
if(ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270))
|
|
|
|
xcb_randr_set_screen_size(connection, ev->root, ev->height, ev->width,
|
|
|
|
ev->mheight, ev->mwidth);
|
|
|
|
else
|
|
|
|
xcb_randr_set_screen_size(connection, ev->root, ev->width, ev->height,
|
|
|
|
ev->mwidth, ev->mheight);
|
|
|
|
|
2008-03-28 22:59:05 +01:00
|
|
|
/* XRRUpdateConfiguration also executes the following instruction
|
|
|
|
* but it's not useful because SubpixelOrder is not used at all at
|
|
|
|
* the moment
|
2008-03-21 16:50:17 +01:00
|
|
|
*
|
|
|
|
* XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order);
|
|
|
|
*/
|
|
|
|
|
2008-09-02 17:12:10 +02:00
|
|
|
awesome_restart();
|
2008-07-18 20:08:03 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-09-13 16:00:03 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The client message event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-06-26 22:42:58 +02:00
|
|
|
static int
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_clientmessage(void *data __attribute__ ((unused)),
|
2008-06-14 18:12:16 +02:00
|
|
|
xcb_connection_t *connection,
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_client_message_event_t *ev)
|
2007-12-27 20:49:38 +01:00
|
|
|
{
|
2009-04-03 16:30:18 +02:00
|
|
|
/* check for startup notification messages */
|
|
|
|
if(sn_xcb_display_process_event(globalconf.sndisplay, (xcb_generic_event_t *) ev))
|
|
|
|
return 0;
|
2008-07-28 17:13:30 +02:00
|
|
|
|
|
|
|
if(ev->type == WM_CHANGE_STATE)
|
|
|
|
{
|
2009-04-03 16:30:18 +02:00
|
|
|
client_t *c;
|
2008-07-28 17:13:30 +02:00
|
|
|
if((c = client_getbywin(ev->window))
|
|
|
|
&& ev->format == 32
|
2008-09-09 16:14:36 +02:00
|
|
|
&& ev->data.data32[0] == XCB_WM_STATE_ICONIC)
|
2008-09-18 13:51:10 +02:00
|
|
|
client_setminimized(c, true);
|
2008-07-28 17:13:30 +02:00
|
|
|
}
|
|
|
|
else if(ev->type == _XEMBED)
|
2008-06-14 18:12:16 +02:00
|
|
|
return xembed_process_client_message(ev);
|
2008-06-30 18:55:14 +02:00
|
|
|
else if(ev->type == _NET_SYSTEM_TRAY_OPCODE)
|
2008-06-14 18:12:16 +02:00
|
|
|
return systray_process_client_message(ev);
|
|
|
|
return ewmh_process_client_message(ev);
|
2007-12-27 20:49:38 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 23:22:53 +02:00
|
|
|
/** The keymap change notify event handler.
|
|
|
|
* \param data Unused data.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
|
|
|
* \return Status code, 0 if everything's fine.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
event_handle_mappingnotify(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
xcb_mapping_notify_event_t *ev)
|
|
|
|
{
|
|
|
|
if(ev->request == XCB_MAPPING_MODIFIER
|
|
|
|
|| ev->request == XCB_MAPPING_KEYBOARD)
|
|
|
|
{
|
2009-04-28 18:17:16 +02:00
|
|
|
xcb_get_modifier_mapping_cookie_t xmapping_cookie =
|
|
|
|
xcb_get_modifier_mapping_unchecked(globalconf.connection);
|
|
|
|
|
2008-09-07 23:22:53 +02:00
|
|
|
/* Free and then allocate the key symbols */
|
|
|
|
xcb_key_symbols_free(globalconf.keysyms);
|
|
|
|
globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection);
|
|
|
|
|
2009-04-28 18:17:16 +02:00
|
|
|
xutil_lock_mask_get(globalconf.connection, xmapping_cookie,
|
|
|
|
globalconf.keysyms, &globalconf.numlockmask,
|
|
|
|
&globalconf.shiftlockmask, &globalconf.capslockmask,
|
|
|
|
&globalconf.modeswitchmask);
|
|
|
|
|
2009-01-05 16:59:20 +01:00
|
|
|
int nscreen = xcb_setup_roots_length(xcb_get_setup(connection));
|
|
|
|
|
|
|
|
/* regrab everything */
|
|
|
|
for(int phys_screen = 0; phys_screen < nscreen; phys_screen++)
|
2008-10-31 19:22:24 +01:00
|
|
|
{
|
|
|
|
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
|
2009-01-05 16:59:20 +01:00
|
|
|
/* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
|
2008-10-31 19:22:24 +01:00
|
|
|
xcb_ungrab_key(connection, XCB_GRAB_ANY, s->root, XCB_BUTTON_MASK_ANY);
|
2009-01-05 16:59:20 +01:00
|
|
|
window_grabkeys(s->root, &globalconf.keys);
|
|
|
|
}
|
2008-10-31 19:22:24 +01:00
|
|
|
|
2009-04-09 17:17:10 +02:00
|
|
|
foreach(_c, globalconf.clients)
|
2009-01-05 16:59:20 +01:00
|
|
|
{
|
2009-04-09 17:17:10 +02:00
|
|
|
client_t *c = *_c;
|
2009-01-05 16:59:20 +01:00
|
|
|
xcb_ungrab_key(connection, XCB_GRAB_ANY, c->win, XCB_BUTTON_MASK_ANY);
|
|
|
|
window_grabkeys(c->win, &c->keys);
|
|
|
|
}
|
2008-09-07 23:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 23:43:40 +02:00
|
|
|
static int
|
|
|
|
event_handle_reparentnotify(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
xcb_reparent_notify_event_t *ev)
|
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
|
|
|
if((c = client_getbywin(ev->window)))
|
|
|
|
client_unmanage(c);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:42:58 +02:00
|
|
|
void a_xcb_set_event_handlers(void)
|
|
|
|
{
|
|
|
|
const xcb_query_extension_reply_t *randr_query;
|
|
|
|
|
2008-08-12 13:23:10 +02:00
|
|
|
xcb_event_set_button_press_handler(&globalconf.evenths, event_handle_button, NULL);
|
|
|
|
xcb_event_set_button_release_handler(&globalconf.evenths, event_handle_button, NULL);
|
2008-09-16 15:36:44 +02:00
|
|
|
xcb_event_set_configure_request_handler(&globalconf.evenths, event_handle_configurerequest, NULL);
|
|
|
|
xcb_event_set_configure_notify_handler(&globalconf.evenths, event_handle_configurenotify, NULL);
|
|
|
|
xcb_event_set_destroy_notify_handler(&globalconf.evenths, event_handle_destroynotify, NULL);
|
|
|
|
xcb_event_set_enter_notify_handler(&globalconf.evenths, event_handle_enternotify, NULL);
|
2008-08-25 14:34:56 +02:00
|
|
|
xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL);
|
2009-02-28 21:08:41 +01:00
|
|
|
xcb_event_set_focus_in_handler(&globalconf.evenths, event_handle_focusin, NULL);
|
2008-08-25 14:34:56 +02:00
|
|
|
xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL);
|
2008-09-16 15:36:44 +02:00
|
|
|
xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL);
|
2008-12-16 12:00:51 +01:00
|
|
|
xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_key, NULL);
|
|
|
|
xcb_event_set_key_release_handler(&globalconf.evenths, event_handle_key, NULL);
|
2008-09-16 15:36:44 +02:00
|
|
|
xcb_event_set_map_request_handler(&globalconf.evenths, event_handle_maprequest, NULL);
|
|
|
|
xcb_event_set_unmap_notify_handler(&globalconf.evenths, event_handle_unmapnotify, NULL);
|
|
|
|
xcb_event_set_client_message_handler(&globalconf.evenths, event_handle_clientmessage, NULL);
|
|
|
|
xcb_event_set_mapping_notify_handler(&globalconf.evenths, event_handle_mappingnotify, NULL);
|
2008-09-07 23:43:40 +02:00
|
|
|
xcb_event_set_reparent_notify_handler(&globalconf.evenths, event_handle_reparentnotify, NULL);
|
2008-06-26 22:42:58 +02:00
|
|
|
|
|
|
|
/* check for randr extension */
|
|
|
|
randr_query = xcb_get_extension_data(globalconf.connection, &xcb_randr_id);
|
|
|
|
if((globalconf.have_randr = randr_query->present))
|
2008-09-16 15:36:44 +02:00
|
|
|
xcb_event_set_handler(&globalconf.evenths,
|
|
|
|
randr_query->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY,
|
2008-06-26 22:42:58 +02:00
|
|
|
(xcb_generic_event_handler_t) event_handle_randr_screen_change_notify,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|