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-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb_keysyms.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
#include <xcb/shape.h>
|
|
|
|
#include <xcb/randr.h>
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-14 12:01:39 +02:00
|
|
|
#include "screen.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "event.h"
|
|
|
|
#include "tag.h"
|
2007-09-15 15:16:53 +02:00
|
|
|
#include "statusbar.h"
|
2007-10-26 18:23:15 +02:00
|
|
|
#include "window.h"
|
2007-11-13 22:57:57 +01:00
|
|
|
#include "mouse.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-01-13 16:30:43 +01:00
|
|
|
#include "rules.h"
|
2008-03-15 16:38:51 +01:00
|
|
|
#include "titlebar.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "layouts/tile.h"
|
|
|
|
#include "layouts/floating.h"
|
2008-03-13 09:05:34 +01:00
|
|
|
#include "common/xscreen.h"
|
2008-03-21 16:50:17 +01:00
|
|
|
#include "common/xutil.h"
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle mouse button click
|
|
|
|
* \param screen screen number
|
|
|
|
* \param button button number
|
|
|
|
* \param state modkeys state
|
|
|
|
* \param buttons buttons list to check for
|
|
|
|
* \param arg optional arg passed to uicb, otherwise buttons' arg are used
|
|
|
|
*/
|
2007-11-11 16:33:59 +01:00
|
|
|
static void
|
2008-04-09 18:27:25 +02:00
|
|
|
event_handle_mouse_button_press(int screen, unsigned int button,
|
|
|
|
unsigned int state,
|
2008-03-21 16:50:17 +01:00
|
|
|
Button *buttons, char *arg)
|
2007-11-11 16:33:59 +01:00
|
|
|
{
|
2007-11-12 13:21:28 +01:00
|
|
|
Button *b;
|
2007-11-11 16:33:59 +01:00
|
|
|
|
2007-11-12 13:21:28 +01:00
|
|
|
for(b = buttons; b; b = b->next)
|
2007-12-16 02:45:38 +01:00
|
|
|
if(button == b->button && CLEANMASK(state) == b->mod && b->func)
|
2007-11-11 16:33:59 +01:00
|
|
|
{
|
|
|
|
if(arg)
|
2007-12-16 02:45:38 +01:00
|
|
|
b->func(screen, arg);
|
2007-11-11 16:33:59 +01:00
|
|
|
else
|
2007-12-16 02:45:38 +01:00
|
|
|
b->func(screen, b->arg);
|
2007-11-11 16:33:59 +01:00
|
|
|
}
|
|
|
|
}
|
2007-11-13 22:57:57 +01:00
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XButtonPressed events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev ButtonPress event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_buttonpress(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_button_press_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
int screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
Client *c;
|
2007-12-27 15:49:00 +01:00
|
|
|
Widget *widget;
|
2007-12-30 21:00:34 +01:00
|
|
|
Statusbar *statusbar;
|
2008-04-09 18:27:25 +02:00
|
|
|
xcb_query_pointer_cookie_t qc;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_query_pointer_reply_t *qr;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
qc = xcb_query_pointer(connection, ev->event);
|
|
|
|
|
2008-03-13 09:28:21 +01:00
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
2007-12-30 21:00:34 +01:00
|
|
|
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(statusbar->sw->window == ev->event || statusbar->sw->window == ev->child)
|
2008-01-24 20:28:45 +01:00
|
|
|
{
|
2008-01-05 11:57:24 +01:00
|
|
|
switch(statusbar->position)
|
2008-01-04 13:04:15 +01:00
|
|
|
{
|
2008-01-05 11:57:24 +01:00
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2007-12-30 21:00:34 +01:00
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->event_x >= widget->area.x && ev->event_x < widget->area.x + widget->area.width
|
|
|
|
&& ev->event_y >= widget->area.y && ev->event_y < widget->area.y + widget->area.height)
|
2007-12-30 21:00:34 +01:00
|
|
|
{
|
|
|
|
widget->button_press(widget, ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-12-30 21:00:34 +01:00
|
|
|
}
|
2008-01-05 11:57:24 +01:00
|
|
|
break;
|
|
|
|
case Right:
|
2007-12-30 21:00:34 +01:00
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->event_y >= widget->area.x && ev->event_y < widget->area.x + widget->area.width
|
|
|
|
&& statusbar->sw->geometry.width - ev->event_x >= widget->area.y
|
|
|
|
&& statusbar->sw->geometry.width - ev->event_x
|
2008-01-23 16:05:52 +01:00
|
|
|
< widget->area.y + widget->area.height)
|
2007-12-30 21:00:34 +01:00
|
|
|
{
|
|
|
|
widget->button_press(widget, ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-12-30 21:00:34 +01:00
|
|
|
}
|
2008-01-05 11:57:24 +01:00
|
|
|
break;
|
2008-01-24 20:22:39 +01:00
|
|
|
case Left:
|
2007-12-30 21:00:34 +01:00
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(statusbar->sw->geometry.height - ev->event_y >= widget->area.x
|
|
|
|
&& statusbar->sw->geometry.height - ev->event_y
|
2008-01-23 16:05:52 +01:00
|
|
|
< widget->area.x + widget->area.width
|
2008-04-09 18:27:25 +02:00
|
|
|
&& ev->event_x >= widget->area.y
|
|
|
|
&& ev->event_x < widget->area.y + widget->area.height)
|
2007-12-30 21:00:34 +01:00
|
|
|
{
|
|
|
|
widget->button_press(widget, ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-12-30 21:00:34 +01:00
|
|
|
}
|
2008-01-05 11:57:24 +01:00
|
|
|
break;
|
2008-03-14 17:33:10 +01:00
|
|
|
default:
|
2008-01-24 20:22:39 +01:00
|
|
|
break;
|
2008-01-04 13:04:15 +01:00
|
|
|
}
|
2008-01-24 20:28:45 +01:00
|
|
|
/* return if no widget match */
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2008-01-24 20:28:45 +01:00
|
|
|
}
|
2007-09-16 12:13:34 +02:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
/* Check for titlebar first */
|
2008-04-08 16:11:13 +02:00
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(c->titlebar.sw && c->titlebar.sw->window == ev->event)
|
2008-04-08 16:11:13 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
if(!client_focus(c, c->screen, true))
|
2008-04-08 16:11:13 +02:00
|
|
|
client_stack(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
if(CLEANMASK(ev->state) == XCB_NO_SYMBOL
|
|
|
|
&& ev->detail == XCB_BUTTON_INDEX_1)
|
2008-04-08 16:11:13 +02:00
|
|
|
window_grabbuttons(c->win, c->phys_screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_mouse_button_press(c->screen, ev->detail, ev->state,
|
2008-04-08 16:11:13 +02:00
|
|
|
globalconf.buttons.titlebar, NULL);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2008-04-08 16:11:13 +02:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->event)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
if(!client_focus(c, c->screen, true))
|
2008-03-25 11:28:56 +01:00
|
|
|
client_stack(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
if(CLEANMASK(ev->state) == XCB_NO_SYMBOL
|
|
|
|
&& ev->detail == XCB_BUTTON_INDEX_1)
|
2007-10-11 11:33:40 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_allow_events(globalconf.connection, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME);
|
2008-03-21 11:33:50 +01:00
|
|
|
window_grabbuttons(c->win, c->phys_screen);
|
2007-09-16 15:55:37 +02:00
|
|
|
}
|
2007-11-14 17:18:16 +01:00
|
|
|
else
|
2008-03-21 16:50:17 +01:00
|
|
|
event_handle_mouse_button_press(c->screen, ev->detail, ev->state, globalconf.buttons.client, NULL);
|
2007-10-16 01:24:04 +02:00
|
|
|
}
|
2007-10-29 20:21:13 +01:00
|
|
|
else
|
2008-03-27 16:05:37 +01:00
|
|
|
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
|
|
|
if(xcb_aux_get_screen(connection, screen)->root == ev->event
|
2008-04-09 18:27:25 +02:00
|
|
|
&& (qr = xcb_query_pointer_reply(connection, qc, NULL)))
|
2007-09-16 00:17:05 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
screen = screen_get_bycoord(globalconf.screens_info, screen, qr->root_x, qr->root_y);
|
|
|
|
event_handle_mouse_button_press(screen, ev->detail, ev->state,
|
|
|
|
globalconf.buttons.root, NULL);
|
|
|
|
|
|
|
|
p_delete(&qr);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XConfigureRequest events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev ConfigureRequest event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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
|
|
|
{
|
|
|
|
Client *c;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t geometry;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-01-29 08:21:05 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-06 14:40:23 +01:00
|
|
|
geometry = c->geometry;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(geometry.x != c->geometry.x || geometry.y != c->geometry.y
|
|
|
|
|| geometry.width != c->geometry.width || geometry.height != c->geometry.height)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-26 09:52:54 +01:00
|
|
|
if(c->isfloating || layout_get_current(c->screen)->arrange == layout_floating)
|
2008-03-21 16:50:17 +01:00
|
|
|
client_resize(c, geometry, false);
|
2008-03-24 14:37:57 +01:00
|
|
|
else
|
2008-03-26 09:52:54 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
2008-03-26 09:52:54 +01:00
|
|
|
/* If we do not resize the client, at least tell it that it
|
|
|
|
* has its new configuration. That fixes at least
|
|
|
|
* gnome-terminal */
|
|
|
|
window_configure(c->win, c->geometry, c->border);
|
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-01-05 18:31:01 +01:00
|
|
|
else
|
2008-03-15 16:38:51 +01:00
|
|
|
{
|
|
|
|
titlebar_update_geometry_floating(c);
|
2008-01-06 14:40:23 +01:00
|
|
|
window_configure(c->win, geometry, c->border);
|
2008-03-15 16:38:51 +01:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-22 19:48:58 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
xcb_configure_window(connection, ev->window, config_win_mask, config_win_vals);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XConfigure events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev ConfigureNotify event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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-03-27 16:05:37 +01:00
|
|
|
if((screen = xcb_aux_get_screen(connection, screen_nbr)) != NULL
|
|
|
|
&& 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-03-23 21:57:07 +01:00
|
|
|
uicb_restart(0, NULL);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XDestroyWindow events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev DestroyNotify event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
|
2008-01-29 08:21:05 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
2008-01-06 21:57:53 +01:00
|
|
|
client_unmanage(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
/** Handle XCrossing events
|
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev Crossing event
|
2008-03-04 10:14:13 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_enternotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_enter_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
2007-09-16 00:11:10 +02:00
|
|
|
int screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->mode != XCB_NOTIFY_MODE_NORMAL
|
|
|
|
|| (ev->root_x == globalconf.pointer_x
|
|
|
|
&& ev->root_y == globalconf.pointer_y))
|
|
|
|
return 0;
|
2008-01-24 18:31:44 +01:00
|
|
|
|
2008-03-14 16:56:41 +01:00
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(c->titlebar.sw && c->titlebar.sw->window == ev->event)
|
2008-03-14 16:56:41 +01:00
|
|
|
break;
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(c || (c = client_get_bywin(globalconf.clients, ev->event)))
|
2007-10-11 11:33:40 +02:00
|
|
|
{
|
2008-03-21 11:33:50 +01:00
|
|
|
window_grabbuttons(c->win, c->phys_screen);
|
2008-03-28 17:49:11 +01:00
|
|
|
/* the idea behind saving pointer_x and pointer_y is Bob Marley powered
|
|
|
|
* this will allow us top drop some EnterNotify events and thus not giving
|
|
|
|
* focus to windows appering under the cursor without a cursor move */
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.pointer_x = ev->root_x;
|
|
|
|
globalconf.pointer_y = ev->root_y;
|
2008-03-28 17:49:11 +01:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
if(globalconf.screens[c->screen].sloppy_focus)
|
2008-02-09 23:12:40 +01:00
|
|
|
client_focus(c, c->screen,
|
2008-03-24 16:34:41 +01:00
|
|
|
globalconf.screens[c->screen].sloppy_focus_raise);
|
2007-10-11 06:46:28 +02:00
|
|
|
}
|
2008-01-11 11:41:38 +01:00
|
|
|
else
|
2008-03-21 16:50:17 +01:00
|
|
|
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
2008-03-27 16:05:37 +01:00
|
|
|
if(ev->event == xcb_aux_get_screen(connection, screen)->root)
|
2008-03-14 16:56:41 +01:00
|
|
|
{
|
2008-01-25 12:55:44 +01:00
|
|
|
window_root_grabbuttons(screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2008-03-14 16:56:41 +01:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2008-03-04 10:14:13 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XExpose events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param ev Expose event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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
|
|
|
{
|
2007-09-16 12:13:34 +02:00
|
|
|
int screen;
|
2007-12-30 21:00:34 +01:00
|
|
|
Statusbar *statusbar;
|
2008-03-14 14:27:56 +01:00
|
|
|
Client *c;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-16 12:13:34 +02:00
|
|
|
if(!ev->count)
|
2008-03-14 14:27:56 +01:00
|
|
|
{
|
2008-03-13 09:28:21 +01:00
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
2007-12-30 21:00:34 +01:00
|
|
|
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
|
2008-04-09 19:44:27 +02:00
|
|
|
if(statusbar->sw->window == ev->window
|
|
|
|
&& statusbar->position)
|
2007-12-30 21:00:34 +01:00
|
|
|
{
|
2008-04-09 19:44:27 +02:00
|
|
|
simplewindow_refresh_drawable(statusbar->sw);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-12-30 21:00:34 +01:00
|
|
|
}
|
2008-03-14 14:27:56 +01:00
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-03-14 18:20:00 +01:00
|
|
|
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
|
2008-03-14 14:27:56 +01:00
|
|
|
{
|
2008-04-09 19:40:32 +02:00
|
|
|
simplewindow_refresh_drawable(c->titlebar.sw);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2008-03-14 14:27:56 +01:00
|
|
|
}
|
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XKey events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev KeyPress event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_keypress(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_key_press_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
int screen;
|
|
|
|
xcb_query_pointer_reply_t *qpr = NULL;
|
|
|
|
xcb_keysym_t keysym;
|
2007-11-12 17:22:40 +01:00
|
|
|
Key *k;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-24 14:20:04 +02:00
|
|
|
/* find the right screen for this event */
|
2008-03-21 16:50:17 +01:00
|
|
|
for(screen = 0; screen < xcb_setup_roots_length (xcb_get_setup (connection)); screen++)
|
|
|
|
if((qpr = xcb_query_pointer_reply(connection,
|
|
|
|
xcb_query_pointer(connection,
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_aux_get_screen(connection, screen)->root),
|
2008-03-21 16:50:17 +01:00
|
|
|
NULL)) != NULL)
|
2007-10-01 12:43:05 +02:00
|
|
|
{
|
|
|
|
/* if screen is 0, we are on first Zaphod screen or on the
|
|
|
|
* only screen in Xinerama, so we can ask for a better screen
|
2008-01-29 19:06:44 +01:00
|
|
|
* number with screen_get_bycoord: we'll get 0 in Zaphod mode
|
2007-10-01 12:43:05 +02:00
|
|
|
* so it's the same, or maybe the real Xinerama screen */
|
2008-03-21 16:50:17 +01:00
|
|
|
screen = screen_get_bycoord(globalconf.screens_info, screen, qpr->root_x, qpr->root_y);
|
2008-03-30 15:46:58 +02:00
|
|
|
p_delete(&qpr);
|
2007-10-10 21:48:31 +02:00
|
|
|
break;
|
2007-10-01 12:43:05 +02:00
|
|
|
}
|
2007-09-24 14:20:04 +02:00
|
|
|
|
2008-03-24 00:48:42 +01:00
|
|
|
keysym = xcb_key_symbols_get_keysym(globalconf.keysyms, ev->detail, 0);
|
2008-04-18 14:57:52 +02:00
|
|
|
|
2007-12-16 02:45:38 +01:00
|
|
|
for(k = globalconf.keys; k; k = k->next)
|
2008-03-21 16:50:17 +01:00
|
|
|
if(((k->keycode && ev->detail == k->keycode) || (k->keysym && keysym == k->keysym))
|
|
|
|
&& k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state))
|
2007-12-16 02:45:38 +01:00
|
|
|
k->func(screen, k->arg);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XMapping events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev MappingNotify event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_mappingnotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_mapping_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-16 13:51:27 +02:00
|
|
|
int screen;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-03-24 00:48:42 +01:00
|
|
|
xcb_refresh_keyboard_mapping(globalconf.keysyms, ev);
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->request == XCB_MAPPING_KEYBOARD)
|
|
|
|
for(screen = 0; screen < xcb_setup_roots_length(xcb_get_setup(connection)); screen++)
|
2008-03-06 16:16:39 +01:00
|
|
|
window_root_grabkeys(screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XMapRequest events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev MapRequest event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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-03-21 16:50:17 +01:00
|
|
|
int screen_nbr = 0;
|
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_query_pointer_cookie_t qp_c;
|
|
|
|
xcb_query_pointer_reply_t *qp_r = NULL;
|
|
|
|
xcb_get_geometry_cookie_t geom_c;
|
|
|
|
xcb_get_geometry_reply_t *geom_r;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_screen_iterator_t iter;
|
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
wa_c = xcb_get_window_attributes(connection, ev->window);
|
|
|
|
geom_c = xcb_get_geometry(connection, ev->window);
|
|
|
|
qp_c = xcb_query_pointer(connection, xcb_aux_get_screen(globalconf.connection, screen_nbr)->root);
|
|
|
|
|
|
|
|
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-03-21 16:50:17 +01:00
|
|
|
{
|
2008-04-09 18:27:25 +02:00
|
|
|
p_delete(&wa_r);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2008-03-30 15:46:58 +02:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
p_delete(&wa_r);
|
2008-03-30 15:46:58 +02:00
|
|
|
|
2008-01-29 08:21:05 +01:00
|
|
|
if(!client_get_bywin(globalconf.clients, ev->window))
|
2007-09-16 00:11:10 +02:00
|
|
|
{
|
2008-04-09 18:27:25 +02:00
|
|
|
if(!(geom_r = xcb_get_geometry_reply(connection, geom_c, NULL)))
|
2008-03-21 16:50:17 +01:00
|
|
|
return -1;
|
|
|
|
|
2008-03-13 09:31:35 +01:00
|
|
|
if(globalconf.screens_info->xinerama_is_active
|
2008-04-09 18:27:25 +02:00
|
|
|
&& (qp_r = xcb_query_pointer_reply(connection, qp_c, NULL)))
|
2008-03-30 15:46:58 +02:00
|
|
|
{
|
|
|
|
screen_nbr = screen_get_bycoord(globalconf.screens_info, screen_nbr,
|
2008-04-09 18:27:25 +02:00
|
|
|
qp_r->root_x, qp_r->root_y);
|
|
|
|
p_delete(&qp_r);
|
2008-03-30 15:46:58 +02:00
|
|
|
}
|
|
|
|
else
|
2008-04-09 18:27:25 +02:00
|
|
|
for(iter = xcb_setup_roots_iterator(xcb_get_setup(connection)), screen_nbr = 0;
|
|
|
|
iter.rem && iter.data->root != geom_r->root; xcb_screen_next (&iter), ++screen_nbr);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
client_manage(ev->window, geom_r, screen_nbr);
|
|
|
|
p_delete(&geom_r);
|
2007-09-16 00:11:10 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XProperty events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev PropertyNotify event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_propertynotify(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection, xcb_property_notify_event_t *ev)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_window_t trans;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->state == XCB_PROPERTY_DELETE)
|
|
|
|
return 0; /* ignore */
|
2008-01-29 08:21:05 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->atom == WM_TRANSIENT_FOR)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-26 19:58:30 +01:00
|
|
|
xutil_get_transient_for_hint(connection, c->win, &trans);
|
2008-01-17 19:17:53 +01:00
|
|
|
if(!c->isfloating
|
2008-01-29 08:21:05 +01:00
|
|
|
&& (c->isfloating = (client_get_bywin(globalconf.clients, trans) != NULL)))
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
}
|
|
|
|
else if (ev->atom == WM_NORMAL_HINTS)
|
2007-12-14 16:05:10 +01:00
|
|
|
client_updatesizehints(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
else if (ev->atom == WM_HINTS)
|
2007-12-23 15:16:10 +01:00
|
|
|
client_updatewmhints(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-04-09 18:27:25 +02:00
|
|
|
if(ev->atom == WM_NAME
|
|
|
|
|| ev->atom == xutil_intern_atom(globalconf.connection, "_NET_WM_NAME"))
|
2007-12-14 16:05:10 +01:00
|
|
|
client_updatetitle(c);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XUnmap events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param connection connection to the X server
|
|
|
|
* \param ev UnmapNotify event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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
|
|
|
{
|
|
|
|
Client *c;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* event->send_event (Xlib) is quivalent to (ev->response_type &
|
|
|
|
* 0x80) in XCB because the SendEvent bit is available in the
|
|
|
|
* response_type field
|
|
|
|
*/
|
2008-04-10 17:19:34 +02:00
|
|
|
bool send_event = ((ev->response_type & 0x7f) >> 7);
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-01-29 08:21:05 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->window))
|
2008-03-27 16:05:37 +01:00
|
|
|
&& ev->event == xcb_aux_get_screen(connection, c->phys_screen)->root
|
2008-03-21 16:50:17 +01:00
|
|
|
&& send_event && window_getstate(c->win) == XCB_WM_NORMAL_STATE)
|
2008-01-06 21:57:53 +01:00
|
|
|
client_unmanage(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XShape events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param ev Shape event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_shape(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection __attribute__ ((unused)),
|
|
|
|
xcb_shape_notify_event_t *ev)
|
2007-09-13 15:57:35 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
Client *c = client_get_bywin(globalconf.clients, ev->affected_window);
|
2007-09-13 15:57:35 +02:00
|
|
|
|
|
|
|
if(c)
|
2008-03-21 11:33:50 +01:00
|
|
|
window_setshape(c->win, c->phys_screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
return 0;
|
2007-09-13 15:57:35 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XRandR events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param ev RandrScreenChangeNotify event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
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-03-23 21:57:07 +01:00
|
|
|
uicb_restart(0, NULL);
|
2008-03-21 16:50:17 +01:00
|
|
|
return 0;
|
2007-09-13 16:00:03 +02:00
|
|
|
}
|
|
|
|
|
2008-03-06 09:05:15 +01:00
|
|
|
/** Handle XClientMessage events
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param ev ClientMessage event
|
2008-03-06 09:05:15 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
int
|
|
|
|
event_handle_clientmessage(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection __attribute__ ((unused)),
|
|
|
|
xcb_client_message_event_t *ev)
|
2007-12-27 20:49:38 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
ewmh_process_client_message(ev);
|
|
|
|
return 0;
|
2007-12-27 20:49:38 +01:00
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|