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
|
|
|
*/
|
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "event.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "awesome.h"
|
2010-08-08 17:35:48 +02:00
|
|
|
#include "property.h"
|
2009-09-14 20:20:27 +02:00
|
|
|
#include "objects/tag.h"
|
2019-02-07 16:20:02 +01:00
|
|
|
#include "objects/selection_getter.h"
|
2010-10-06 13:35:14 +02:00
|
|
|
#include "objects/drawin.h"
|
2019-02-10 17:03:00 +01:00
|
|
|
#include "objects/selection_acquire.h"
|
2019-02-06 09:30:16 +01:00
|
|
|
#include "objects/selection_watcher.h"
|
2009-09-17 17:51:06 +02:00
|
|
|
#include "xwindow.h"
|
2007-12-27 20:49:38 +01:00
|
|
|
#include "ewmh.h"
|
2009-09-14 20:22:12 +02:00
|
|
|
#include "objects/client.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"
|
2015-02-23 17:08:24 +01:00
|
|
|
#include "xkb.h"
|
2014-03-30 15:12:47 +02:00
|
|
|
#include "objects/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
|
|
|
|
2014-03-30 20:07:48 +02:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/randr.h>
|
|
|
|
#include <xcb/shape.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
#include <xcb/xcb_event.h>
|
2015-02-23 17:08:24 +01:00
|
|
|
#include <xcb/xkb.h>
|
2019-02-06 09:30:16 +01:00
|
|
|
#include <xcb/xfixes.h>
|
2014-03-30 20:07:48 +02:00
|
|
|
|
2009-06-29 11:02:13 +02:00
|
|
|
#define DO_EVENT_HOOK_CALLBACK(type, xcbtype, xcbeventprefix, arraytype, match) \
|
2009-08-14 16:52:22 +02:00
|
|
|
static void \
|
2009-05-25 14:42:41 +02:00
|
|
|
event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
|
2009-08-14 16:46:35 +02:00
|
|
|
arraytype *arr, \
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L, \
|
2009-05-25 14:42:41 +02:00
|
|
|
int oud, \
|
|
|
|
int nargs, \
|
|
|
|
void *data) \
|
2009-04-27 17:46:15 +02:00
|
|
|
{ \
|
2014-12-06 11:56:58 +01:00
|
|
|
int abs_oud = oud < 0 ? ((lua_gettop(L) + 1) + oud) : oud; \
|
2009-08-14 16:52:22 +02:00
|
|
|
int item_matching = 0; \
|
2009-08-14 16:46:35 +02:00
|
|
|
foreach(item, *arr) \
|
|
|
|
if(match(ev, *item, data)) \
|
2009-05-25 14:42:41 +02:00
|
|
|
{ \
|
2009-08-14 16:46:35 +02:00
|
|
|
if(oud) \
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push_item(L, abs_oud, *item); \
|
2009-08-14 16:46:35 +02:00
|
|
|
else \
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, *item); \
|
2009-05-25 14:42:41 +02:00
|
|
|
item_matching++; \
|
|
|
|
} \
|
2009-08-14 16:52:22 +02:00
|
|
|
for(; item_matching > 0; item_matching--) \
|
2009-05-25 14:42:41 +02:00
|
|
|
{ \
|
|
|
|
switch(ev->response_type) \
|
|
|
|
{ \
|
|
|
|
case xcbeventprefix##_PRESS: \
|
2009-06-25 16:32:15 +02:00
|
|
|
for(int i = 0; i < nargs; i++) \
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_pushvalue(L, - nargs - item_matching); \
|
|
|
|
luaA_object_emit_signal(L, - nargs - 1, "press", nargs); \
|
2009-05-25 14:42:41 +02:00
|
|
|
break; \
|
|
|
|
case xcbeventprefix##_RELEASE: \
|
2009-06-25 16:32:15 +02:00
|
|
|
for(int i = 0; i < nargs; i++) \
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_pushvalue(L, - nargs - item_matching); \
|
|
|
|
luaA_object_emit_signal(L, - nargs - 1, "release", nargs); \
|
2009-05-25 14:42:41 +02:00
|
|
|
break; \
|
|
|
|
} \
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_pop(L, 1); \
|
2009-05-25 14:42:41 +02:00
|
|
|
} \
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_pop(L, nargs); \
|
2009-04-27 17:46:15 +02: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))
|
2009-06-24 17:44:06 +02:00
|
|
|
&& (k->modifiers == XCB_BUTTON_MASK_ANY || k->modifiers == ev->state));
|
2009-04-27 17:52:36 +02:00
|
|
|
}
|
|
|
|
|
2009-08-17 14:10:03 +02:00
|
|
|
static bool
|
|
|
|
event_button_match(xcb_button_press_event_t *ev, button_t *b, void *data)
|
|
|
|
{
|
|
|
|
return ((!b->button || ev->detail == b->button)
|
|
|
|
&& (b->modifiers == XCB_BUTTON_MASK_ANY || b->modifiers == ev->state));
|
|
|
|
}
|
|
|
|
|
2009-06-29 11:02:13 +02:00
|
|
|
DO_EVENT_HOOK_CALLBACK(button_t, button, XCB_BUTTON, button_array_t, event_button_match)
|
|
|
|
DO_EVENT_HOOK_CALLBACK(keyb_t, key, XCB_KEY, 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)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
mousegrabber_handleevent(L, x, y, mask);
|
2015-07-13 19:52:06 +02:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.mousegrabber);
|
|
|
|
if(!luaA_dofunction(L, 1, 1))
|
2008-11-13 16:08:34 +01:00
|
|
|
{
|
2015-07-13 19:52:06 +02:00
|
|
|
warn("Stopping mousegrabber.");
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_mousegrabber_stop(L);
|
2016-03-06 10:43:23 +01:00
|
|
|
} else {
|
|
|
|
if(!lua_isboolean(L, -1) || !lua_toboolean(L, -1))
|
|
|
|
luaA_mousegrabber_stop(L);
|
|
|
|
lua_pop(L, 1); /* pop returned value */
|
2008-11-13 16:08:34 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2010-10-06 10:53:05 +02:00
|
|
|
/** Emit a button signal.
|
|
|
|
* The top of the lua stack has to be the object on which to emit the event.
|
2014-12-06 11:56:58 +01:00
|
|
|
* \param L The Lua VM state.
|
2010-10-06 10:53:05 +02:00
|
|
|
* \param ev The event to handle.
|
|
|
|
*/
|
|
|
|
static void
|
2014-12-06 11:56:58 +01:00
|
|
|
event_emit_button(lua_State *L, xcb_button_press_event_t *ev)
|
2010-10-06 10:53:05 +02:00
|
|
|
{
|
|
|
|
const char *name;
|
2012-05-19 20:20:46 +02:00
|
|
|
switch(XCB_EVENT_RESPONSE_TYPE(ev))
|
2010-10-06 10:53:05 +02:00
|
|
|
{
|
|
|
|
case XCB_BUTTON_PRESS:
|
|
|
|
name = "button::press";
|
|
|
|
break;
|
|
|
|
case XCB_BUTTON_RELEASE:
|
|
|
|
name = "button::release";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fatal("Invalid event type");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push the event's info */
|
2016-02-06 13:46:46 +01:00
|
|
|
lua_pushinteger(L, ev->event_x);
|
|
|
|
lua_pushinteger(L, ev->event_y);
|
|
|
|
lua_pushinteger(L, ev->detail);
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_pushmodifiers(L, ev->state);
|
2010-10-06 10:53:05 +02:00
|
|
|
/* And emit the signal */
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_emit_signal(L, -5, name, 4);
|
2010-10-06 10:53:05 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The button press event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_button(xcb_button_press_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2010-10-06 13:35:14 +02:00
|
|
|
drawin_t *drawin;
|
2008-04-09 18:27:25 +02:00
|
|
|
|
2010-08-12 14:37:39 +02:00
|
|
|
globalconf.timestamp = ev->time;
|
|
|
|
|
2015-07-05 16:14:41 +02:00
|
|
|
{
|
|
|
|
/* ev->state contains the state before the event. Compute the state
|
|
|
|
* after the event for the mousegrabber.
|
|
|
|
*/
|
|
|
|
uint16_t state = ev->state, change = 1 << (ev->detail - 1 + 8);
|
|
|
|
if (XCB_EVENT_RESPONSE_TYPE(ev) == XCB_BUTTON_PRESS)
|
|
|
|
state |= change;
|
|
|
|
else
|
|
|
|
state &= ~change;
|
|
|
|
if(event_handle_mousegrabber(ev->root_x, ev->root_y, state))
|
|
|
|
return;
|
|
|
|
}
|
2009-04-29 17:20:12 +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;
|
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
if((drawin = drawin_getbywin(ev->event))
|
|
|
|
|| (drawin = drawin_getbywin(ev->child)))
|
2008-09-24 12:13:21 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
/* If the drawin is child, then x,y are
|
2008-09-24 12:13:21 +02:00
|
|
|
* relative to root window */
|
2010-10-06 13:35:14 +02:00
|
|
|
if(drawin->window == ev->child)
|
2008-09-20 16:45:43 +02:00
|
|
|
{
|
2012-12-16 18:17:03 +01:00
|
|
|
ev->event_x -= drawin->geometry.x + drawin->border_width;
|
|
|
|
ev->event_y -= drawin->geometry.y + drawin->border_width;
|
2008-09-20 16:45:43 +02:00
|
|
|
}
|
2008-12-10 18:05:08 +01:00
|
|
|
|
2012-10-14 17:20:24 +02:00
|
|
|
/* Push the drawable */
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, drawin);
|
|
|
|
luaA_object_push_item(L, -1, drawin->drawable);
|
2010-10-10 13:32:47 +02:00
|
|
|
/* and handle the button raw button event */
|
2014-12-06 11:56:58 +01:00
|
|
|
event_emit_button(L, ev);
|
|
|
|
lua_pop(L, 1);
|
2010-10-10 13:32:47 +02:00
|
|
|
/* check if any button object matches */
|
2014-12-06 11:56:58 +01:00
|
|
|
event_button_callback(ev, &drawin->buttons, L, -1, 1, NULL);
|
2014-04-21 10:41:07 +02:00
|
|
|
/* Either we are receiving this due to ButtonPress/Release on the root
|
|
|
|
* window or because we grabbed the button on the window. In the later
|
|
|
|
* case we have to call AllowEvents.
|
|
|
|
* Use AsyncPointer instead of ReplayPointer so that the event is
|
|
|
|
* "eaten" instead of being handled again on the root window.
|
|
|
|
*/
|
|
|
|
if(ev->child == XCB_NONE)
|
|
|
|
xcb_allow_events(globalconf.connection,
|
|
|
|
XCB_ALLOW_ASYNC_POINTER,
|
2017-04-15 12:05:42 +02:00
|
|
|
ev->time);
|
2008-06-03 18:41:54 +02:00
|
|
|
}
|
2016-05-14 16:16:24 +02:00
|
|
|
else if((c = client_getbyframewin(ev->event)) || (c = client_getbywin(ev->event)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2016-05-14 16:16:24 +02:00
|
|
|
/* For clicks inside of c->window, we get two events. Once because of a
|
|
|
|
* passive grab on c->window and then again for c->frame_window.
|
|
|
|
* Ignore the second event (identifiable by ev->child != XCB_NONE).
|
|
|
|
*/
|
|
|
|
if (ev->event != c->frame_window || ev->child == XCB_NONE)
|
2012-10-14 17:20:24 +02:00
|
|
|
{
|
2016-05-14 16:16:24 +02:00
|
|
|
luaA_object_push(L, c);
|
|
|
|
if (c->window == ev->event)
|
|
|
|
{
|
|
|
|
/* Button event into the client itself (not titlebar), translate
|
|
|
|
* into the frame window.
|
|
|
|
*/
|
|
|
|
ev->event_x += c->titlebar[CLIENT_TITLEBAR_LEFT].size;
|
|
|
|
ev->event_y += c->titlebar[CLIENT_TITLEBAR_TOP].size;
|
|
|
|
}
|
|
|
|
/* And handle the button raw button event */
|
|
|
|
event_emit_button(L, ev);
|
|
|
|
/* then check if a titlebar was "hit" */
|
|
|
|
if (c->frame_window == ev->event)
|
|
|
|
{
|
|
|
|
int x = ev->event_x, y = ev->event_y;
|
|
|
|
drawable_t *d = client_get_drawable_offset(c, &x, &y);
|
|
|
|
if (d)
|
|
|
|
{
|
|
|
|
/* Copy the event so that we can fake x/y */
|
|
|
|
xcb_button_press_event_t event = *ev;
|
|
|
|
event.event_x = x;
|
|
|
|
event.event_y = y;
|
|
|
|
luaA_object_push_item(L, -1, d);
|
|
|
|
event_emit_button(L, &event);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* then check if any button objects match */
|
|
|
|
event_button_callback(ev, &c->buttons, L, -1, 1, NULL);
|
2012-10-14 17:20:24 +02:00
|
|
|
}
|
2008-08-12 13:23:10 +02:00
|
|
|
xcb_allow_events(globalconf.connection,
|
|
|
|
XCB_ALLOW_REPLAY_POINTER,
|
2017-04-15 12:05:42 +02:00
|
|
|
ev->time);
|
2007-10-16 01:24:04 +02:00
|
|
|
}
|
2009-02-24 17:32:48 +01:00
|
|
|
else if(ev->child == XCB_NONE)
|
2010-08-16 14:10:58 +02:00
|
|
|
if(globalconf.screen->root == ev->event)
|
2010-08-16 13:47:40 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
event_button_callback(ev, &globalconf.buttons, L, 0, 0, NULL);
|
2010-08-16 13:47:40 +02:00
|
|
|
return;
|
|
|
|
}
|
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 ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_configurerequest(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;
|
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
|
|
|
{
|
2018-08-20 10:33:06 +02:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH)
|
|
|
|
{
|
|
|
|
luaA_object_push(L, c);
|
|
|
|
window_set_border_width(L, -1, ev->border_width);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2009-10-07 14:24:39 +02:00
|
|
|
area_t geometry = c->geometry;
|
2015-10-10 17:41:05 +02:00
|
|
|
uint16_t bw = c->border_width;
|
|
|
|
uint16_t tb_left = c->titlebar[CLIENT_TITLEBAR_LEFT].size;
|
|
|
|
uint16_t tb_right = c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
|
|
|
|
uint16_t tb_top = c->titlebar[CLIENT_TITLEBAR_TOP].size;
|
|
|
|
uint16_t tb_bottom = c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
|
|
|
|
uint16_t deco_left = bw + tb_left;
|
|
|
|
uint16_t deco_right = bw + tb_right;
|
|
|
|
uint16_t deco_top = bw + tb_top;
|
|
|
|
uint16_t deco_bottom = bw + tb_bottom;
|
2018-08-20 10:33:06 +02:00
|
|
|
int16_t diff_w = 0, diff_h = 0;
|
2017-02-26 07:47:15 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
|
2013-04-07 11:57:40 +02:00
|
|
|
{
|
|
|
|
uint16_t old_w = geometry.width;
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry.width = ev->width;
|
2013-04-07 11:57:40 +02:00
|
|
|
/* The ConfigureRequest specifies the size of the client window, we want the frame */
|
2015-10-10 17:42:25 +02:00
|
|
|
geometry.width += tb_left + tb_right;
|
2013-04-07 11:57:40 +02:00
|
|
|
diff_w = geometry.width - old_w;
|
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
|
2013-04-07 11:57:40 +02:00
|
|
|
{
|
|
|
|
uint16_t old_h = geometry.height;
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry.height = ev->height;
|
2013-04-07 11:57:40 +02:00
|
|
|
/* The ConfigureRequest specifies the size of the client window, we want the frame */
|
2015-10-10 17:42:25 +02:00
|
|
|
geometry.height += tb_top + tb_bottom;
|
2013-04-07 11:57:40 +02:00
|
|
|
diff_h = geometry.height - old_h;
|
|
|
|
}
|
2009-02-14 20:41:54 +01:00
|
|
|
|
2013-04-07 11:57:40 +02:00
|
|
|
/* If the client resizes without moving itself, apply window gravity */
|
|
|
|
if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
|
|
|
|
{
|
2018-08-20 10:33:06 +02:00
|
|
|
xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, 0, diff_w, diff_h, &geometry.x, &geometry.y);
|
2018-08-20 10:28:21 +02:00
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_X)
|
|
|
|
{
|
|
|
|
geometry.x = ev->x;
|
2018-08-20 10:40:58 +02:00
|
|
|
if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
|
|
|
|
xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL);
|
2018-08-20 10:28:21 +02:00
|
|
|
}
|
|
|
|
if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
|
|
|
|
{
|
|
|
|
geometry.y = ev->y;
|
2018-08-20 10:40:58 +02:00
|
|
|
if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
|
|
|
|
xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y);
|
2013-04-07 11:57:40 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 11:19:01 +01:00
|
|
|
c->got_configure_request = true;
|
2017-02-26 07:47:15 +01:00
|
|
|
|
|
|
|
/* Request the changes to be applied */
|
|
|
|
luaA_object_push(L, c);
|
|
|
|
lua_pushstring(L, "ewmh"); /* context */
|
|
|
|
lua_newtable(L); /* props */
|
|
|
|
|
|
|
|
/* area, it needs to be directly in the `hints` table to comply with
|
|
|
|
the "protocol"
|
|
|
|
*/
|
|
|
|
lua_pushstring(L, "x");
|
|
|
|
lua_pushinteger(L, geometry.x);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "y");
|
|
|
|
lua_pushinteger(L, geometry.y);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "width");
|
|
|
|
lua_pushinteger(L, geometry.width);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "height");
|
|
|
|
lua_pushinteger(L, geometry.height);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
luaA_object_emit_signal(L, -3, "request::geometry", 2);
|
|
|
|
lua_pop(L, 1);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2015-10-10 20:34:43 +02:00
|
|
|
else if (xembed_getbywin(&globalconf.embedded, ev->window))
|
|
|
|
{
|
|
|
|
/* Ignore this so that systray icons cannot resize themselves.
|
|
|
|
* We decide their size!
|
2016-07-07 21:38:34 +02:00
|
|
|
* However, Xembed says that we act like a WM to the embedded window and
|
|
|
|
* thus we have to send a synthetic configure notify informing the
|
|
|
|
* window that its configure request was denied.
|
2015-10-10 20:34:43 +02:00
|
|
|
*/
|
2016-07-07 21:38:34 +02:00
|
|
|
xcb_get_geometry_cookie_t geom_cookie =
|
|
|
|
xcb_get_geometry_unchecked(globalconf.connection, ev->window);
|
|
|
|
xcb_translate_coordinates_cookie_t coords_cookie =
|
|
|
|
xcb_translate_coordinates_unchecked(globalconf.connection,
|
|
|
|
ev->window, globalconf.screen->root, 0, 0);
|
|
|
|
xcb_get_geometry_reply_t *geom =
|
|
|
|
xcb_get_geometry_reply(globalconf.connection, geom_cookie, NULL);
|
|
|
|
xcb_translate_coordinates_reply_t *coords =
|
|
|
|
xcb_translate_coordinates_reply(globalconf.connection, coords_cookie, NULL);
|
|
|
|
|
|
|
|
if (geom && coords)
|
|
|
|
{
|
|
|
|
xwindow_configure(ev->window,
|
|
|
|
(area_t) { .x = coords->dst_x,
|
|
|
|
.y = coords->dst_y,
|
|
|
|
.width = geom->width,
|
|
|
|
.height = geom->height },
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
p_delete(&geom);
|
|
|
|
p_delete(&coords);
|
2015-10-10 20:34:43 +02:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
2009-01-30 15:20:04 +01:00
|
|
|
event_handle_configurerequest_configure_window(ev);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The configure notify event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_configurenotify(xcb_configure_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2016-04-09 15:56:44 +02:00
|
|
|
xcb_screen_t *screen = globalconf.screen;
|
2010-08-16 13:47:40 +02:00
|
|
|
|
2016-04-13 01:32:58 +02:00
|
|
|
if(ev->window == screen->root)
|
2016-04-15 20:29:08 +02:00
|
|
|
globalconf.screen_need_refresh = true;
|
2016-04-09 15:56:44 +02:00
|
|
|
|
|
|
|
/* Copy what XRRUpdateConfiguration() would do: Update the configuration */
|
|
|
|
if(ev->window == screen->root) {
|
|
|
|
screen->width_in_pixels = ev->width;
|
|
|
|
screen->height_in_pixels = ev->height;
|
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The destroy notify event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_destroynotify(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)))
|
2010-10-07 12:05:43 +02:00
|
|
|
client_unmanage(c, false);
|
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);
|
2010-10-06 15:38:44 +02:00
|
|
|
luaA_systray_invalidate();
|
2008-12-01 16:43:44 +01:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 16:32:56 +02:00
|
|
|
/** Record that the given drawable contains the pointer.
|
|
|
|
*/
|
2016-01-10 19:27:55 +01:00
|
|
|
void
|
2015-09-17 16:32:56 +02:00
|
|
|
event_drawable_under_mouse(lua_State *L, int ud)
|
|
|
|
{
|
|
|
|
void *d;
|
|
|
|
|
|
|
|
lua_pushvalue(L, ud);
|
|
|
|
d = luaA_object_ref(L, -1);
|
|
|
|
|
|
|
|
if (d == globalconf.drawable_under_mouse)
|
|
|
|
{
|
|
|
|
/* Nothing to do */
|
|
|
|
luaA_object_unref(L, d);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globalconf.drawable_under_mouse != NULL)
|
|
|
|
{
|
|
|
|
/* Emit leave on previous drawable */
|
|
|
|
luaA_object_push(L, globalconf.drawable_under_mouse);
|
|
|
|
luaA_object_emit_signal(L, -1, "mouse::leave", 0);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
/* Unref the previous drawable */
|
|
|
|
luaA_object_unref(L, globalconf.drawable_under_mouse);
|
|
|
|
globalconf.drawable_under_mouse = NULL;
|
|
|
|
}
|
|
|
|
if (d != NULL)
|
|
|
|
{
|
|
|
|
/* Reference the drawable for leave event later */
|
|
|
|
globalconf.drawable_under_mouse = d;
|
|
|
|
|
|
|
|
/* Emit enter */
|
|
|
|
luaA_object_emit_signal(L, ud, "mouse::enter", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-25 14:34:56 +02:00
|
|
|
/** The motion notify event handler.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_motionnotify(xcb_motion_notify_event_t *ev)
|
2008-08-25 14:34:56 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2010-10-06 20:43:33 +02:00
|
|
|
drawin_t *w;
|
|
|
|
client_t *c;
|
|
|
|
|
2010-08-12 14:37:39 +02:00
|
|
|
globalconf.timestamp = ev->time;
|
|
|
|
|
2009-04-29 13:59:13 +02:00
|
|
|
if(event_handle_mousegrabber(ev->root_x, ev->root_y, ev->state))
|
2010-08-08 17:54:13 +02:00
|
|
|
return;
|
2008-11-13 16:08:34 +01:00
|
|
|
|
2010-10-06 20:43:33 +02:00
|
|
|
if((c = client_getbyframewin(ev->event)))
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, c);
|
2016-02-06 13:46:46 +01:00
|
|
|
lua_pushinteger(L, ev->event_x);
|
|
|
|
lua_pushinteger(L, ev->event_y);
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_emit_signal(L, -3, "mouse::move", 2);
|
2012-10-14 17:20:24 +02:00
|
|
|
|
|
|
|
/* now check if a titlebar was "hit" */
|
|
|
|
int x = ev->event_x, y = ev->event_y;
|
|
|
|
drawable_t *d = client_get_drawable_offset(c, &x, &y);
|
|
|
|
if (d)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push_item(L, -1, d);
|
2015-09-17 16:32:56 +02:00
|
|
|
event_drawable_under_mouse(L, -1);
|
2016-02-06 13:46:46 +01:00
|
|
|
lua_pushinteger(L, x);
|
|
|
|
lua_pushinteger(L, y);
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_emit_signal(L, -3, "mouse::move", 2);
|
|
|
|
lua_pop(L, 1);
|
2012-10-14 17:20:24 +02:00
|
|
|
}
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_pop(L, 1);
|
2010-10-06 20:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if((w = drawin_getbywin(ev->event)))
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, w);
|
|
|
|
luaA_object_push_item(L, -1, w->drawable);
|
2015-09-17 16:32:56 +02:00
|
|
|
event_drawable_under_mouse(L, -1);
|
2016-02-06 13:46:46 +01:00
|
|
|
lua_pushinteger(L, ev->event_x);
|
|
|
|
lua_pushinteger(L, ev->event_y);
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_emit_signal(L, -3, "mouse::move", 2);
|
|
|
|
lua_pop(L, 2);
|
2010-10-06 20:43:33 +02:00
|
|
|
}
|
2008-08-25 14:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** The leave notify event handler.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_leavenotify(xcb_leave_notify_event_t *ev)
|
2008-08-25 14:34:56 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2009-02-14 20:41:56 +01:00
|
|
|
client_t *c;
|
2008-08-25 14:34:56 +02:00
|
|
|
|
2010-08-12 14:37:39 +02:00
|
|
|
globalconf.timestamp = ev->time;
|
|
|
|
|
2019-01-26 18:26:35 +01:00
|
|
|
/*
|
|
|
|
* Ignore events with non-normal modes. Those are because a grab
|
|
|
|
* activated/deactivated. Everything will be "back to normal" after the
|
|
|
|
* grab.
|
|
|
|
*/
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
if(ev->mode != XCB_NOTIFY_MODE_NORMAL)
|
2010-08-08 17:54:13 +02:00
|
|
|
return;
|
2009-04-04 16:16:02 +02:00
|
|
|
|
2019-01-26 18:26:35 +01:00
|
|
|
if((c = client_getbyframewin(ev->event)))
|
2009-08-19 15:45:56 +02:00
|
|
|
{
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
/* The window was left in some way, so definitely no titlebar has the
|
|
|
|
* mouse cursor.
|
|
|
|
*/
|
|
|
|
lua_pushnil(L);
|
|
|
|
event_drawable_under_mouse(L, -1);
|
2016-02-17 18:52:35 +01:00
|
|
|
lua_pop(L, 1);
|
2009-04-12 14:32:36 +02:00
|
|
|
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
/* If detail is inferior, it means that the cursor is now in some child
|
|
|
|
* window of our window. Thus, the titlebar was left, but now the cursor
|
|
|
|
* is in the actual child window. Thus, ignore detail=Inferior for
|
|
|
|
* leaving client windows.
|
|
|
|
*/
|
|
|
|
if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR) {
|
|
|
|
luaA_object_push(L, c);
|
|
|
|
luaA_object_emit_signal(L, -1, "mouse::leave", 0);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
} else if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR) {
|
|
|
|
/* Some window was left. This must be a drawin. Ignore detail=Inferior,
|
|
|
|
* because this means that some child window now contains the mouse
|
|
|
|
* cursor, i.e. a systray window. Everything else is a real 'leave'.
|
|
|
|
*/
|
|
|
|
lua_pushnil(L);
|
|
|
|
event_drawable_under_mouse(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2008-08-25 14:34:56 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The enter notify event handler.
|
|
|
|
* \param ev The event.
|
2008-03-04 10:14:13 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_enternotify(xcb_enter_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2008-06-14 18:12:16 +02:00
|
|
|
client_t *c;
|
2010-10-06 13:35:14 +02:00
|
|
|
drawin_t *drawin;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2010-08-12 14:37:39 +02:00
|
|
|
globalconf.timestamp = ev->time;
|
|
|
|
|
2019-01-26 18:26:35 +01:00
|
|
|
/*
|
|
|
|
* Ignore events with non-normal modes. Those are because a grab
|
|
|
|
* activated/deactivated. Everything will be "back to normal" after the
|
|
|
|
* grab.
|
|
|
|
*/
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
if(ev->mode != XCB_NOTIFY_MODE_NORMAL)
|
2010-08-08 17:54:13 +02:00
|
|
|
return;
|
2008-01-24 18:31:44 +01:00
|
|
|
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
/*
|
|
|
|
* We ignore events with detail "inferior". This detail means that the
|
|
|
|
* cursor was previously inside of a child window and now left that child
|
|
|
|
* window. For our purposes, the cursor was already inside our window
|
|
|
|
* before.
|
|
|
|
* One exception are titlebars: They are not their own window, but are
|
|
|
|
* "outside of the actual client window".
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR && (drawin = drawin_getbywin(ev->event)))
|
2008-10-25 15:35:14 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, drawin);
|
|
|
|
luaA_object_push_item(L, -1, drawin->drawable);
|
2015-09-17 16:32:56 +02:00
|
|
|
event_drawable_under_mouse(L, -1);
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_pop(L, 2);
|
2008-10-25 15:35:14 +02:00
|
|
|
}
|
2009-04-12 14:29:53 +02:00
|
|
|
|
2010-07-30 22:07:24 +02:00
|
|
|
if((c = client_getbyframewin(ev->event)))
|
2009-08-19 15:45:56 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, c);
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
/* Detail=Inferior means that a child of the frame window now contains
|
|
|
|
* the mouse cursor, i.e. the actual client now has the cursor. All
|
|
|
|
* other details mean that the client itself was really left.
|
|
|
|
*/
|
|
|
|
if(ev->detail != XCB_NOTIFY_DETAIL_INFERIOR) {
|
|
|
|
luaA_object_emit_signal(L, -1, "mouse::enter", 0);
|
|
|
|
}
|
Handle enter/leave events with detail=Inferior correctly
There is a client window C. Around this window, awesome adds a frame window F.
When the pointer is inside of C and then moves inside of F, we get a LeaveNotify
with detail=Inferior, but from our point of view, the pointer is still inside of
C, because F is contained in C.
Similarly, if the pointer is in F and moves to C, we get an EnterNotify with
detail=Inferior that we should ignore. However, for an EnterNotify the pointer
can now be inside of a titlebar, so this case has to be handled now.
The above explains the enter/leave behavior for clients. Let's now think about
titlebars: When the pointer moves from C to F, it cannot be in any titlebar any
more, so we must generate a leave event on that titlebar. Similar when the
pointer moves from F to C, but in this case we also have to figure out which
titlebar now contains the pointer.
This patch makes the code handle these events with detail=Inferior correctly.
Closes https://github.com/awesomeWM/awesome/pull/461.
Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-09-17 17:03:36 +02:00
|
|
|
|
2012-10-14 17:20:24 +02:00
|
|
|
drawable_t *d = client_get_drawable(c, ev->event_x, ev->event_y);
|
|
|
|
if (d)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push_item(L, -1, d);
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
} else {
|
|
|
|
lua_pushnil(L);
|
2012-10-14 17:20:24 +02:00
|
|
|
}
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
event_drawable_under_mouse(L, -1);
|
|
|
|
lua_pop(L, 2);
|
2009-08-19 15:45:56 +02:00
|
|
|
}
|
Honor *some* Enter/Leave events with detail==Inferior
Commit 19086d70fa9eb made AwesomeWM ignore all Enter/Leave events with
detail==Inferior. However, when leaving a titlebar by moving the cursor
into the actual client window, the corresponding event actually has
detail==Inferior. The same is true for the opposite direction: Leaving a
client window by entering the titlebar.
Thus, this commit fixes the code to handle theses cases again.
This was tested with the following in rc.lua (and with a systray icon
and a client with titlebars).
screen[1].mywibox:connect_signal("mouse::enter", function() print("enter mywibox") end)
screen[1].mywibox:connect_signal("mouse::leave", function() print("leave mywibox") end)
client.connect_signal("mouse::enter", function() print("enter client") end)
client.connect_signal("mouse::leave", function() print("leave client") end)
client.connect_signal("manage", function(c)
local d = c:titlebar_top()
d:connect_signal("mouse::enter", function() print("enter titlebar") end)
d:connect_signal("mouse::leave", function() print("leave titlebar") end)
end)
Fixes: https://github.com/awesomeWM/awesome/pull/2611#issuecomment-457892746
Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-27 16:21:31 +01:00
|
|
|
else if (ev->detail != XCB_NOTIFY_DETAIL_INFERIOR && ev->event == globalconf.screen->root) {
|
2015-12-23 06:46:17 +01:00
|
|
|
/* When there are multiple X screens with awesome running separate
|
|
|
|
* instances, reset focus.
|
|
|
|
*/
|
|
|
|
globalconf.focus.need_update = true;
|
|
|
|
}
|
2008-03-04 10:14:13 +01:00
|
|
|
}
|
|
|
|
|
2009-02-28 21:08:41 +01:00
|
|
|
/** The focus in event handler.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_focusin(xcb_focus_in_event_t *ev)
|
2009-02-28 21:08:41 +01:00
|
|
|
{
|
2012-07-08 15:41:16 +02:00
|
|
|
if (ev->mode == XCB_NOTIFY_MODE_GRAB
|
|
|
|
|| ev->mode == XCB_NOTIFY_MODE_UNGRAB)
|
|
|
|
/* Ignore focus changes due to keyboard grabs */
|
|
|
|
return;
|
|
|
|
|
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:
|
2009-09-17 15:05:53 +02:00
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
2013-02-11 16:19:28 +01:00
|
|
|
if((c = client_getbywin(ev->event))) {
|
|
|
|
/* If there is still a pending focus change, do it now. */
|
|
|
|
client_focus_refresh();
|
2009-04-07 14:20:22 +02:00
|
|
|
client_focus_update(c);
|
2013-02-11 16:19:28 +01:00
|
|
|
}
|
2009-09-17 15:05:53 +02:00
|
|
|
}
|
2009-04-07 14:20:22 +02:00
|
|
|
/* all other events are ignored */
|
|
|
|
default:
|
2009-04-28 10:54:10 +02:00
|
|
|
break;
|
2009-04-07 14:20:22 +02:00
|
|
|
}
|
2009-02-28 21:08:41 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The expose event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_expose(xcb_expose_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
drawin_t *drawin;
|
2012-10-14 17:20:24 +02:00
|
|
|
client_t *client;
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
if((drawin = drawin_getbywin(ev->window)))
|
|
|
|
drawin_refresh_pixmap_partial(drawin,
|
|
|
|
ev->x, ev->y,
|
|
|
|
ev->width, ev->height);
|
2012-10-14 17:20:24 +02:00
|
|
|
if ((client = client_getbyframewin(ev->window)))
|
2014-03-16 15:29:11 +01:00
|
|
|
client_refresh_partial(client, ev->x, ev->y, ev->width, ev->height);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The key press event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_key(xcb_key_press_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2010-08-12 14:37:39 +02:00
|
|
|
globalconf.timestamp = ev->time;
|
|
|
|
|
2008-06-10 16:50:55 +02:00
|
|
|
if(globalconf.keygrabber != LUA_REFNIL)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
if(keygrabber_handlekpress(L, ev))
|
2008-06-10 16:50:55 +02:00
|
|
|
{
|
2015-07-13 19:52:06 +02:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.keygrabber);
|
|
|
|
|
2016-03-06 10:35:49 +01:00
|
|
|
if(!luaA_dofunction(L, 3, 0))
|
2008-06-10 22:37:45 +02:00
|
|
|
{
|
2015-07-13 19:52:06 +02:00
|
|
|
warn("Stopping keygrabber.");
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_keygrabber_stop(L);
|
2008-06-10 22:37:45 +02:00
|
|
|
}
|
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 */
|
2015-05-20 22:00:06 +02:00
|
|
|
xcb_keysym_t keysym = xcb_key_symbols_get_keysym(globalconf.keysyms, ev->detail, 0);
|
2009-04-27 17:56:06 +02:00
|
|
|
client_t *c;
|
2016-02-28 13:29:25 +01:00
|
|
|
if((c = client_getbywin(ev->event)) || (c = client_getbynofocuswin(ev->event)))
|
2009-04-27 17:56:06 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_push(L, c);
|
|
|
|
event_key_callback(ev, &c->keys, L, -1, 1, &keysym);
|
2009-04-27 17:56:06 +02:00
|
|
|
}
|
|
|
|
else
|
2014-12-06 11:56:58 +01:00
|
|
|
event_key_callback(ev, &globalconf.keys, L, 0, 0, &keysym);
|
2009-01-05 16:59:20 +01:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The map request event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_maprequest(xcb_map_request_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-05-20 20:30:07 +02:00
|
|
|
client_t *c;
|
2016-05-14 14:30:22 +02:00
|
|
|
xembed_window_t *em;
|
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
|
|
|
|
2010-08-08 17:54:13 +02:00
|
|
|
wa_c = xcb_get_window_attributes_unchecked(globalconf.connection, ev->window);
|
2008-04-09 18:27:25 +02:00
|
|
|
|
2010-08-08 17:54:13 +02:00
|
|
|
if(!(wa_r = xcb_get_window_attributes_reply(globalconf.connection, wa_c, NULL)))
|
|
|
|
return;
|
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
|
|
|
|
2016-05-14 14:30:22 +02:00
|
|
|
if((em = xembed_getbywin(&globalconf.embedded, ev->window)))
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2010-08-08 17:54:13 +02:00
|
|
|
xcb_map_window(globalconf.connection, ev->window);
|
2017-04-15 12:04:57 +02:00
|
|
|
xembed_window_activate(globalconf.connection, ev->window, globalconf.timestamp);
|
2016-05-14 14:30:22 +02:00
|
|
|
/* The correct way to set this is via the _XEMBED_INFO property. Neither
|
|
|
|
* of the XEMBED not the systray spec talk about mapping windows.
|
|
|
|
* Apparently, Qt doesn't care and does not set an _XEMBED_INFO
|
|
|
|
* property. Let's simulate the XEMBED_MAPPED bit.
|
|
|
|
*/
|
|
|
|
em->info.flags |= XEMBED_MAPPED;
|
|
|
|
luaA_systray_invalidate();
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
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 */
|
2015-09-25 00:43:52 +02:00
|
|
|
if(client_on_selected_tags(c) && !c->hidden)
|
2008-06-28 11:47:29 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
luaA_object_push(L, c);
|
|
|
|
client_set_minimized(L, -1, false);
|
|
|
|
lua_pop(L, 1);
|
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
|
|
|
{
|
2010-08-08 17:54:13 +02:00
|
|
|
geom_c = xcb_get_geometry_unchecked(globalconf.connection, ev->window);
|
2008-05-20 20:30:07 +02:00
|
|
|
|
2010-08-08 17:54:13 +02:00
|
|
|
if(!(geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL)))
|
2008-05-20 20:30:07 +02:00
|
|
|
{
|
2008-06-30 13:06:23 +02:00
|
|
|
goto bailout;
|
2008-05-20 20:30:07 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2014-03-16 20:15:02 +01:00
|
|
|
client_manage(ev->window, geom_r, wa_r);
|
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);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The unmap notify event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_unmapnotify(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)))
|
2010-10-07 12:05:43 +02:00
|
|
|
client_unmanage(c, true);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The randr screen change notify event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t *ev)
|
2007-09-13 16:00:03 +02:00
|
|
|
{
|
2016-04-09 16:06:21 +02:00
|
|
|
/* Ignore events for other roots (do we get them at all?) */
|
|
|
|
if (ev->root != globalconf.screen->root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Do (part of) what XRRUpdateConfiguration() would do (update our state) */
|
|
|
|
if (ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270)) {
|
|
|
|
globalconf.screen->width_in_pixels = ev->height;
|
2017-01-26 18:46:14 +01:00
|
|
|
globalconf.screen->width_in_millimeters = ev->mheight;
|
2016-04-09 16:06:21 +02:00
|
|
|
globalconf.screen->height_in_pixels = ev->width;
|
2017-01-26 18:46:14 +01:00
|
|
|
globalconf.screen->height_in_millimeters = ev->mwidth;
|
2016-04-09 16:06:21 +02:00
|
|
|
} else {
|
|
|
|
globalconf.screen->width_in_pixels = ev->width;
|
2017-01-26 18:46:14 +01:00
|
|
|
globalconf.screen->width_in_millimeters = ev->mwidth;
|
2016-04-09 16:06:21 +02:00
|
|
|
globalconf.screen->height_in_pixels = ev->height;
|
2017-01-26 18:46:14 +01:00
|
|
|
globalconf.screen->height_in_millimeters = ev->mheight;;
|
2016-04-09 16:06:21 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2016-04-15 20:29:08 +02:00
|
|
|
globalconf.screen_need_refresh = true;
|
2007-09-13 16:00:03 +02:00
|
|
|
}
|
|
|
|
|
2016-01-27 20:40:04 +01:00
|
|
|
/** XRandR event handler for RRNotify subtype XRROutputChangeNotifyEvent
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
event_handle_randr_output_change_notify(xcb_randr_notify_event_t *ev)
|
|
|
|
{
|
|
|
|
if(ev->subCode == XCB_RANDR_NOTIFY_OUTPUT_CHANGE) {
|
|
|
|
xcb_randr_output_t output = ev->u.oc.output;
|
|
|
|
uint8_t connection = ev->u.oc.connection;
|
|
|
|
const char *connection_str = NULL;
|
2017-11-17 10:31:50 +01:00
|
|
|
xcb_randr_get_output_info_reply_t *info;
|
2016-01-27 20:40:04 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
|
2017-04-15 12:05:42 +02:00
|
|
|
/* The following explicitly uses XCB_CURRENT_TIME since we want to know
|
|
|
|
* the final state of the connection. There could be more notification
|
|
|
|
* events underway and using some "old" timestamp causes problems.
|
|
|
|
*/
|
2016-01-27 20:40:04 +01:00
|
|
|
info = xcb_randr_get_output_info_reply(globalconf.connection,
|
|
|
|
xcb_randr_get_output_info_unchecked(globalconf.connection,
|
|
|
|
output,
|
|
|
|
XCB_CURRENT_TIME),
|
|
|
|
NULL);
|
|
|
|
if(!info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(connection) {
|
|
|
|
case XCB_RANDR_CONNECTION_CONNECTED:
|
|
|
|
connection_str = "Connected";
|
|
|
|
break;
|
|
|
|
case XCB_RANDR_CONNECTION_DISCONNECTED:
|
|
|
|
connection_str = "Disconnected";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
connection_str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-27 11:26:04 +02:00
|
|
|
lua_pushlstring(L, (char *)xcb_randr_get_output_info_name(info), xcb_randr_get_output_info_name_length(info));
|
2016-01-27 20:40:04 +01:00
|
|
|
lua_pushstring(L, connection_str);
|
|
|
|
signal_object_emit(L, &global_signals, "screen::change", 2);
|
|
|
|
|
|
|
|
p_delete(&info);
|
2016-02-27 15:57:57 +01:00
|
|
|
|
|
|
|
/* The docs for RRSetOutputPrimary say we get this signal */
|
|
|
|
screen_update_primary();
|
2016-01-27 20:40:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-03 16:51:16 +01:00
|
|
|
/** The shape notify event handler.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
event_handle_shape_notify(xcb_shape_notify_event_t *ev)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(ev->affected_window);
|
|
|
|
if (c)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
luaA_object_push(L, c);
|
2014-01-03 16:51:16 +01:00
|
|
|
if (ev->shape_kind == XCB_SHAPE_SK_BOUNDING)
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_emit_signal(L, -1, "property::shape_client_bounding", 0);
|
2014-01-03 16:51:16 +01:00
|
|
|
if (ev->shape_kind == XCB_SHAPE_SK_CLIP)
|
2014-12-06 11:56:58 +01:00
|
|
|
luaA_object_emit_signal(L, -1, "property::shape_client_clip", 0);
|
|
|
|
lua_pop(L, 1);
|
2014-01-03 16:51:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 18:20:20 +02:00
|
|
|
/** The client message event handler.
|
|
|
|
* \param ev The event.
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_clientmessage(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))
|
2010-08-08 17:54:13 +02:00
|
|
|
return;
|
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
|
2011-04-27 06:49:56 +02:00
|
|
|
&& ev->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC)
|
2009-08-17 17:02:45 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
luaA_object_push(L, c);
|
|
|
|
client_set_minimized(L, -1, true);
|
|
|
|
lua_pop(L, 1);
|
2009-08-17 17:02:45 +02:00
|
|
|
}
|
2008-07-28 17:13:30 +02:00
|
|
|
}
|
|
|
|
else if(ev->type == _XEMBED)
|
2010-08-08 17:54:13 +02:00
|
|
|
xembed_process_client_message(ev);
|
2008-06-30 18:55:14 +02:00
|
|
|
else if(ev->type == _NET_SYSTEM_TRAY_OPCODE)
|
2010-08-08 17:54:13 +02:00
|
|
|
systray_process_client_message(ev);
|
|
|
|
else
|
|
|
|
ewmh_process_client_message(ev);
|
2007-12-27 20:49:38 +01:00
|
|
|
}
|
|
|
|
|
2010-08-08 17:54:13 +02:00
|
|
|
static void
|
|
|
|
event_handle_reparentnotify(xcb_reparent_notify_event_t *ev)
|
2008-09-07 23:43:40 +02:00
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
2010-07-30 22:25:19 +02:00
|
|
|
if((c = client_getbywin(ev->window)) && c->frame_window != ev->parent)
|
2010-08-11 11:56:47 +02:00
|
|
|
{
|
|
|
|
/* Ignore reparents to the root window, they *might* be caused by
|
|
|
|
* ourselves if a client quickly unmaps and maps itself again. */
|
2010-08-16 14:10:58 +02:00
|
|
|
if (ev->parent != globalconf.screen->root)
|
2010-10-07 12:05:43 +02:00
|
|
|
client_unmanage(c, true);
|
2010-08-11 11:56:47 +02:00
|
|
|
}
|
2016-05-14 14:20:08 +02:00
|
|
|
else if (ev->parent != globalconf.systray.window) {
|
|
|
|
/* Embedded window moved elsewhere, end of embedding */
|
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
|
|
|
if(globalconf.embedded.tab[i].win == ev->window)
|
|
|
|
{
|
|
|
|
xembed_window_array_take(&globalconf.embedded, i);
|
|
|
|
xcb_change_save_set(globalconf.connection, XCB_SET_MODE_DELETE, ev->window);
|
|
|
|
luaA_systray_invalidate();
|
|
|
|
}
|
|
|
|
}
|
2008-09-07 23:43:40 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 21:59:12 +02:00
|
|
|
static void
|
|
|
|
event_handle_selectionclear(xcb_selection_clear_event_t *ev)
|
|
|
|
{
|
|
|
|
if(ev->selection == globalconf.selection_atom)
|
|
|
|
{
|
|
|
|
warn("Lost WM_Sn selection, exiting...");
|
|
|
|
g_main_loop_quit(globalconf.loop);
|
2019-02-10 17:03:00 +01:00
|
|
|
} else
|
|
|
|
selection_handle_selectionclear(ev);
|
2015-10-10 21:59:12 +02:00
|
|
|
}
|
|
|
|
|
2010-08-08 17:35:48 +02:00
|
|
|
/** \brief awesome xerror function.
|
|
|
|
* There's no way to check accesses to destroyed windows, thus those cases are
|
|
|
|
* ignored (especially on UnmapNotify's).
|
|
|
|
* \param e The error event.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
xerror(xcb_generic_error_t *e)
|
|
|
|
{
|
|
|
|
/* ignore this */
|
2010-09-15 21:30:45 +02:00
|
|
|
if(e->error_code == XCB_WINDOW
|
|
|
|
|| (e->error_code == XCB_MATCH
|
2010-08-08 17:35:48 +02:00
|
|
|
&& e->major_code == XCB_SET_INPUT_FOCUS)
|
2010-09-15 21:30:45 +02:00
|
|
|
|| (e->error_code == XCB_VALUE
|
2010-08-08 17:35:48 +02:00
|
|
|
&& e->major_code == XCB_KILL_CLIENT)
|
2010-09-15 21:30:45 +02:00
|
|
|
|| (e->error_code == XCB_MATCH
|
|
|
|
&& e->major_code == XCB_CONFIGURE_WINDOW))
|
2010-08-08 17:35:48 +02:00
|
|
|
return;
|
|
|
|
|
2012-06-15 10:02:25 +02:00
|
|
|
warn("X error: request=%s (major %d, minor %d), error=%s (%d)",
|
2010-08-08 17:35:48 +02:00
|
|
|
xcb_event_get_request_label(e->major_code),
|
2012-06-15 10:02:25 +02:00
|
|
|
e->major_code, e->minor_code,
|
|
|
|
xcb_event_get_error_label(e->error_code),
|
|
|
|
e->error_code);
|
2010-08-08 17:35:48 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-25 07:04:47 +02:00
|
|
|
static bool
|
|
|
|
should_ignore(xcb_generic_event_t *event)
|
|
|
|
{
|
|
|
|
uint8_t response_type = XCB_EVENT_RESPONSE_TYPE(event);
|
|
|
|
|
|
|
|
/* Remove completed sequences */
|
|
|
|
uint32_t sequence = event->full_sequence;
|
|
|
|
while (globalconf.ignore_enter_leave_events.len > 0) {
|
|
|
|
uint32_t end = globalconf.ignore_enter_leave_events.tab[0].end.sequence;
|
|
|
|
/* Do if (end >= sequence) break;, but handle wrap-around: The above is
|
|
|
|
* equivalent to end-sequence > 0 (assuming unlimited precision). With
|
|
|
|
* int32_t, this would mean that the sign bit is cleared, which means:
|
|
|
|
*/
|
|
|
|
if (end - sequence < UINT32_MAX / 2)
|
|
|
|
break;
|
|
|
|
sequence_pair_array_take(&globalconf.ignore_enter_leave_events, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this event should be ignored */
|
|
|
|
if ((response_type == XCB_ENTER_NOTIFY || response_type == XCB_LEAVE_NOTIFY)
|
|
|
|
&& globalconf.ignore_enter_leave_events.len > 0) {
|
|
|
|
uint32_t begin = globalconf.ignore_enter_leave_events.tab[0].begin.sequence;
|
|
|
|
uint32_t end = globalconf.ignore_enter_leave_events.tab[0].end.sequence;
|
|
|
|
if (sequence >= begin && sequence <= end)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-08 17:35:48 +02:00
|
|
|
void event_handle(xcb_generic_event_t *event)
|
2008-06-26 22:42:58 +02:00
|
|
|
{
|
2010-08-08 17:35:48 +02:00
|
|
|
uint8_t response_type = XCB_EVENT_RESPONSE_TYPE(event);
|
|
|
|
|
2016-09-25 07:04:47 +02:00
|
|
|
if (should_ignore(event))
|
|
|
|
return;
|
|
|
|
|
2010-08-08 17:35:48 +02:00
|
|
|
if(response_type == 0)
|
|
|
|
{
|
|
|
|
/* This is an error, not a event */
|
|
|
|
xerror((xcb_generic_error_t *) event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(response_type)
|
|
|
|
{
|
2010-08-08 17:54:13 +02:00
|
|
|
#define EVENT(type, callback) case type: callback((void *) event); return
|
2010-08-08 17:35:48 +02:00
|
|
|
EVENT(XCB_BUTTON_PRESS, event_handle_button);
|
|
|
|
EVENT(XCB_BUTTON_RELEASE, event_handle_button);
|
|
|
|
EVENT(XCB_CONFIGURE_REQUEST, event_handle_configurerequest);
|
|
|
|
EVENT(XCB_CONFIGURE_NOTIFY, event_handle_configurenotify);
|
|
|
|
EVENT(XCB_DESTROY_NOTIFY, event_handle_destroynotify);
|
|
|
|
EVENT(XCB_ENTER_NOTIFY, event_handle_enternotify);
|
|
|
|
EVENT(XCB_CLIENT_MESSAGE, event_handle_clientmessage);
|
|
|
|
EVENT(XCB_EXPOSE, event_handle_expose);
|
|
|
|
EVENT(XCB_FOCUS_IN, event_handle_focusin);
|
|
|
|
EVENT(XCB_KEY_PRESS, event_handle_key);
|
|
|
|
EVENT(XCB_KEY_RELEASE, event_handle_key);
|
|
|
|
EVENT(XCB_LEAVE_NOTIFY, event_handle_leavenotify);
|
|
|
|
EVENT(XCB_MAP_REQUEST, event_handle_maprequest);
|
|
|
|
EVENT(XCB_MOTION_NOTIFY, event_handle_motionnotify);
|
|
|
|
EVENT(XCB_PROPERTY_NOTIFY, property_handle_propertynotify);
|
|
|
|
EVENT(XCB_REPARENT_NOTIFY, event_handle_reparentnotify);
|
|
|
|
EVENT(XCB_UNMAP_NOTIFY, event_handle_unmapnotify);
|
2015-10-10 21:59:12 +02:00
|
|
|
EVENT(XCB_SELECTION_CLEAR, event_handle_selectionclear);
|
2019-02-07 16:20:02 +01:00
|
|
|
EVENT(XCB_SELECTION_NOTIFY, event_handle_selectionnotify);
|
2019-02-10 17:42:34 +01:00
|
|
|
EVENT(XCB_SELECTION_REQUEST, selection_handle_selectionrequest);
|
2010-08-08 17:35:48 +02:00
|
|
|
#undef EVENT
|
|
|
|
}
|
|
|
|
|
2016-04-09 15:44:54 +02:00
|
|
|
#define EXTENSION_EVENT(base, offset, callback) \
|
|
|
|
if (globalconf.event_base_ ## base != 0 \
|
|
|
|
&& response_type == globalconf.event_base_ ## base + (offset)) \
|
|
|
|
callback((void *) event)
|
|
|
|
EXTENSION_EVENT(randr, XCB_RANDR_SCREEN_CHANGE_NOTIFY, event_handle_randr_screen_change_notify);
|
|
|
|
EXTENSION_EVENT(randr, XCB_RANDR_NOTIFY, event_handle_randr_output_change_notify);
|
|
|
|
EXTENSION_EVENT(shape, XCB_SHAPE_NOTIFY, event_handle_shape_notify);
|
|
|
|
EXTENSION_EVENT(xkb, 0, event_handle_xkb_notify);
|
2019-02-06 09:30:16 +01:00
|
|
|
EXTENSION_EVENT(xfixes, XCB_XFIXES_SELECTION_NOTIFY, event_handle_xfixes_selection_notify);
|
2016-04-09 15:44:54 +02:00
|
|
|
#undef EXTENSION_EVENT
|
|
|
|
}
|
2010-08-08 17:35:48 +02:00
|
|
|
|
2016-04-09 15:44:54 +02:00
|
|
|
void event_init(void)
|
|
|
|
{
|
|
|
|
const xcb_query_extension_reply_t *reply;
|
2016-01-27 20:40:04 +01:00
|
|
|
|
2016-04-09 15:44:54 +02:00
|
|
|
reply = xcb_get_extension_data(globalconf.connection, &xcb_randr_id);
|
2016-04-10 13:39:27 +02:00
|
|
|
if (reply && reply->present)
|
2016-04-09 15:44:54 +02:00
|
|
|
globalconf.event_base_randr = reply->first_event;
|
2008-06-26 22:42:58 +02:00
|
|
|
|
2016-04-09 15:44:54 +02:00
|
|
|
reply = xcb_get_extension_data(globalconf.connection, &xcb_shape_id);
|
|
|
|
if (reply && reply->present)
|
|
|
|
globalconf.event_base_shape = reply->first_event;
|
2015-02-23 17:08:24 +01:00
|
|
|
|
2016-04-09 15:44:54 +02:00
|
|
|
reply = xcb_get_extension_data(globalconf.connection, &xcb_xkb_id);
|
|
|
|
if (reply && reply->present)
|
|
|
|
globalconf.event_base_xkb = reply->first_event;
|
2019-02-06 09:30:16 +01:00
|
|
|
|
|
|
|
reply = xcb_get_extension_data(globalconf.connection, &xcb_xfixes_id);
|
|
|
|
if (reply && reply->present)
|
|
|
|
globalconf.event_base_xfixes = reply->first_event;
|
2008-06-26 22:42:58 +02:00
|
|
|
}
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|