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
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* 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 <X11/keysym.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xutil.h>
|
2007-10-03 17:26:14 +02:00
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
#include <X11/extensions/Xrandr.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 "layout.h"
|
|
|
|
#include "tag.h"
|
2007-09-15 15:16:53 +02:00
|
|
|
#include "draw.h"
|
|
|
|
#include "statusbar.h"
|
2007-09-15 15:26:51 +02:00
|
|
|
#include "util.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "layouts/tile.h"
|
|
|
|
#include "layouts/floating.h"
|
|
|
|
|
2007-09-16 12:13:34 +02:00
|
|
|
#define CLEANMASK(mask, screen) (mask & ~(awesomeconf[screen].numlockmask | LockMask))
|
|
|
|
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-10-15 16:27:48 +02:00
|
|
|
Client *
|
|
|
|
get_client_bywin(Client **list, Window w)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
|
2007-10-11 21:50:32 +02:00
|
|
|
for(c = *list; c && c->win != w; c = c->next);
|
2007-09-05 20:15:00 +02:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-19 11:19:43 +02:00
|
|
|
movemouse(Client * c, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-01 15:23:05 +02:00
|
|
|
int x1, y1, ocx, ocy, di, nx, ny;
|
2007-09-05 20:15:00 +02:00
|
|
|
unsigned int dui;
|
|
|
|
Window dummy;
|
|
|
|
XEvent ev;
|
2007-09-14 12:01:39 +02:00
|
|
|
ScreenInfo *si;
|
|
|
|
|
2007-10-10 18:19:57 +02:00
|
|
|
si = get_screen_info(c->display, c->screen, &awesomeconf[c->screen].statusbar);
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
ocx = nx = c->x;
|
|
|
|
ocy = ny = c->y;
|
2007-10-01 15:23:05 +02:00
|
|
|
if(XGrabPointer(c->display, RootWindow(c->display, c->phys_screen), False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
2007-10-10 13:29:46 +02:00
|
|
|
None, awesomeconf[c->screen].cursor[CurMove], CurrentTime) != GrabSuccess)
|
2007-09-05 20:15:00 +02:00
|
|
|
return;
|
2007-10-01 15:23:05 +02:00
|
|
|
XQueryPointer(c->display, RootWindow(c->display, c->phys_screen), &dummy, &dummy, &x1, &y1, &di, &di, &dui);
|
2007-09-05 20:15:00 +02:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
XMaskEvent(c->display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonRelease:
|
|
|
|
XUngrabPointer(c->display, CurrentTime);
|
2007-10-15 14:20:45 +02:00
|
|
|
p_delete(&si);
|
2007-09-05 20:15:00 +02:00
|
|
|
return;
|
|
|
|
case ConfigureRequest:
|
2007-10-11 10:28:43 +02:00
|
|
|
handle_event_configurerequest(&ev,awesomeconf);
|
|
|
|
break;
|
2007-09-05 20:15:00 +02:00
|
|
|
case Expose:
|
2007-10-11 10:28:43 +02:00
|
|
|
handle_event_expose(&ev, awesomeconf);
|
|
|
|
break;
|
2007-09-05 20:15:00 +02:00
|
|
|
case MapRequest:
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_maprequest(&ev, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
XSync(c->display, False);
|
|
|
|
nx = ocx + (ev.xmotion.x - x1);
|
|
|
|
ny = ocy + (ev.xmotion.y - y1);
|
2007-10-10 18:19:57 +02:00
|
|
|
if(abs(nx) < awesomeconf[c->screen].snap + si[c->screen].x_org && nx > si[c->screen].x_org)
|
2007-10-01 16:25:45 +02:00
|
|
|
nx = si[c->screen].x_org;
|
2007-10-10 18:19:57 +02:00
|
|
|
else if(abs((si[c->screen].x_org + si[c->screen].width) - (nx + c->w + 2 * c->border)) < awesomeconf[c->screen].snap)
|
2007-10-01 16:25:45 +02:00
|
|
|
nx = si[c->screen].x_org + si[c->screen].width - c->w - 2 * c->border;
|
2007-10-10 18:19:57 +02:00
|
|
|
if(abs(ny) < awesomeconf[c->screen].snap + si[c->screen].y_org && ny > si[c->screen].y_org)
|
2007-10-01 16:25:45 +02:00
|
|
|
ny = si[c->screen].y_org;
|
2007-10-10 18:19:57 +02:00
|
|
|
else if(abs((si[c->screen].y_org + si[c->screen].height) - (ny + c->h + 2 * c->border)) < awesomeconf[c->screen].snap)
|
2007-10-01 16:25:45 +02:00
|
|
|
ny = si[c->screen].y_org + si[c->screen].height - c->h - 2 * c->border;
|
2007-10-10 18:19:57 +02:00
|
|
|
resize(c, nx, ny, c->w, c->h, &awesomeconf[c->screen], False);
|
2007-09-05 20:15:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-10 12:06:54 +02:00
|
|
|
resizemouse(Client * c, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-28 11:55:08 +02:00
|
|
|
int ocx, ocy, nw, nh;
|
2007-09-05 20:15:00 +02:00
|
|
|
XEvent ev;
|
|
|
|
|
|
|
|
ocx = c->x;
|
|
|
|
ocy = c->y;
|
2007-10-01 15:23:05 +02:00
|
|
|
if(XGrabPointer(c->display, RootWindow(c->display, c->phys_screen),
|
2007-09-28 11:55:08 +02:00
|
|
|
False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
2007-10-10 13:29:46 +02:00
|
|
|
None, awesomeconf[c->screen].cursor[CurResize], CurrentTime) != GrabSuccess)
|
2007-09-05 20:15:00 +02:00
|
|
|
return;
|
|
|
|
c->ismax = False;
|
|
|
|
XWarpPointer(c->display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
XMaskEvent(c->display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case ButtonRelease:
|
|
|
|
XWarpPointer(c->display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
|
|
|
|
XUngrabPointer(c->display, CurrentTime);
|
|
|
|
while(XCheckMaskEvent(c->display, EnterWindowMask, &ev));
|
|
|
|
return;
|
|
|
|
case ConfigureRequest:
|
2007-10-11 10:28:43 +02:00
|
|
|
handle_event_configurerequest(&ev,awesomeconf);
|
|
|
|
break;
|
2007-09-05 20:15:00 +02:00
|
|
|
case Expose:
|
2007-10-11 10:28:43 +02:00
|
|
|
handle_event_expose(&ev, awesomeconf);
|
|
|
|
break;
|
2007-09-05 20:15:00 +02:00
|
|
|
case MapRequest:
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_maprequest(&ev, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
XSync(c->display, False);
|
|
|
|
if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
|
|
|
|
nw = 1;
|
|
|
|
if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
|
|
|
|
nh = 1;
|
2007-10-10 18:21:48 +02:00
|
|
|
resize(c, c->x, c->y, nw, nh, &awesomeconf[c->screen], True);
|
2007-09-05 20:15:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-03 17:17:46 +02:00
|
|
|
int i, screen, x = 0, y = 0;
|
|
|
|
unsigned int udummy;
|
2007-09-05 20:15:00 +02:00
|
|
|
Client *c;
|
2007-10-03 17:17:46 +02:00
|
|
|
Window wdummy;
|
2007-09-05 20:15:00 +02:00
|
|
|
XButtonPressedEvent *ev = &e->xbutton;
|
|
|
|
|
2007-09-27 16:34:51 +02:00
|
|
|
for(screen = 0; screen < get_screen_count(e->xany.display); screen++)
|
2007-09-16 12:13:34 +02:00
|
|
|
if(awesomeconf[screen].statusbar.window == ev->window)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-16 12:13:34 +02:00
|
|
|
for(i = 0; i < awesomeconf[screen].ntags; i++)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-10 13:34:25 +02:00
|
|
|
x += textwidth(e->xany.display, awesomeconf[screen].font, awesomeconf[screen].tags[i].name, a_strlen(awesomeconf[screen].tags[i].name)) + awesomeconf[screen].font->height;
|
2007-09-16 12:13:34 +02:00
|
|
|
if(ev->x < x)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-16 12:13:34 +02:00
|
|
|
if(ev->button == Button1)
|
|
|
|
{
|
|
|
|
if(ev->state & awesomeconf[screen].modkey)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_tag(&awesomeconf[screen], awesomeconf[screen].tags[i].name);
|
2007-09-16 12:13:34 +02:00
|
|
|
else
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_view(&awesomeconf[screen], awesomeconf[screen].tags[i].name);
|
2007-09-16 12:13:34 +02:00
|
|
|
}
|
|
|
|
else if(ev->button == Button3)
|
|
|
|
{
|
|
|
|
if(ev->state & awesomeconf[screen].modkey)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_toggletag(&awesomeconf[screen], awesomeconf[screen].tags[i].name);
|
2007-09-16 12:13:34 +02:00
|
|
|
else
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_toggleview(&awesomeconf[screen], awesomeconf[screen].tags[i].name);
|
2007-09-16 12:13:34 +02:00
|
|
|
}
|
2007-10-05 10:53:39 +02:00
|
|
|
else if(ev->button == Button4)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_tag_viewnext(&awesomeconf[screen], NULL);
|
2007-10-05 10:53:39 +02:00
|
|
|
else if(ev->button == Button5)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_tag_viewprev(&awesomeconf[screen], NULL);
|
2007-09-16 12:13:34 +02:00
|
|
|
return;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-12 14:36:36 +02:00
|
|
|
x += awesomeconf[screen].statusbar.txtlayoutwidth;
|
2007-10-05 13:51:19 +02:00
|
|
|
if(ev->x < x && (ev->button == Button1 || ev->button == Button4))
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_setlayout(&awesomeconf[screen], "+1");
|
2007-10-05 13:51:19 +02:00
|
|
|
else if(ev->x < x && (ev->button == Button3 || ev->button == Button5))
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_setlayout(&awesomeconf[screen], "-1");
|
2007-10-05 12:08:20 +02:00
|
|
|
else if(ev->button == Button4)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_focusnext(&awesomeconf[screen], NULL);
|
2007-10-05 12:08:20 +02:00
|
|
|
else if(ev->button == Button5)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_focusprev(&awesomeconf[screen], NULL);
|
2007-09-16 12:32:17 +02:00
|
|
|
return;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-09-16 12:13:34 +02:00
|
|
|
|
2007-10-15 16:27:48 +02:00
|
|
|
if((c = get_client_bywin(awesomeconf->clients, ev->window)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-10 14:09:36 +02:00
|
|
|
focus(c->display, c, ev->same_screen, &awesomeconf[c->screen]);
|
2007-10-11 11:33:40 +02:00
|
|
|
if(CLEANMASK(ev->state, c->screen) != awesomeconf[c->screen].modkey)
|
|
|
|
{
|
|
|
|
if (ev->button == Button1)
|
|
|
|
{
|
2007-10-11 15:23:33 +02:00
|
|
|
restack(c->display, &awesomeconf[c->screen]);
|
|
|
|
grabbuttons(c, True, True, awesomeconf->modkey, awesomeconf->numlockmask);
|
2007-10-11 06:46:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(ev->button == Button1)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-11 11:33:40 +02:00
|
|
|
if(!IS_ARRANGE(c->screen, layout_floating) && !c->isfloating)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_togglefloating(&awesomeconf[c->screen], NULL);
|
2007-09-16 15:55:37 +02:00
|
|
|
else
|
2007-10-10 14:09:36 +02:00
|
|
|
restack(e->xany.display, &awesomeconf[c->screen]);
|
2007-10-10 18:19:57 +02:00
|
|
|
movemouse(c, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else if(ev->button == Button2)
|
|
|
|
{
|
2007-10-11 11:33:40 +02:00
|
|
|
if(!IS_ARRANGE(c->screen, layout_floating) && !c->isfixed && c->isfloating)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_togglefloating(&awesomeconf[c->screen], NULL);
|
2007-09-16 15:55:37 +02:00
|
|
|
else
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_zoom(&awesomeconf[c->screen], NULL);
|
2007-09-16 15:55:37 +02:00
|
|
|
}
|
|
|
|
else if(ev->button == Button3)
|
|
|
|
{
|
2007-10-11 11:33:40 +02:00
|
|
|
if(!IS_ARRANGE(c->screen, layout_floating) && !c->isfloating)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_togglefloating(&awesomeconf[c->screen], NULL);
|
2007-09-16 15:55:37 +02:00
|
|
|
else
|
2007-10-10 14:09:36 +02:00
|
|
|
restack(e->xany.display, &awesomeconf[c->screen]);
|
2007-10-10 18:21:48 +02:00
|
|
|
resizemouse(c, awesomeconf);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-10-09 23:47:45 +02:00
|
|
|
else if(ev->button == Button4)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_settrans(&awesomeconf[c->screen], "+5");
|
2007-10-09 23:47:45 +02:00
|
|
|
else if(ev->button == Button5)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_settrans(&awesomeconf[c->screen], "-5");
|
2007-10-09 23:47:45 +02:00
|
|
|
}
|
2007-10-11 23:12:05 +02:00
|
|
|
else if(!*awesomeconf->client_sel)
|
2007-09-16 15:04:40 +02:00
|
|
|
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
2007-10-03 17:17:46 +02:00
|
|
|
if(RootWindow(e->xany.display, screen) == ev->window
|
|
|
|
&& XQueryPointer(e->xany.display, ev->window, &wdummy, &wdummy, &x, &y, &i, &i, &udummy))
|
2007-09-16 00:17:05 +02:00
|
|
|
{
|
2007-10-03 17:17:46 +02:00
|
|
|
screen = get_screen_bycoord(e->xany.display, x, y);
|
2007-09-16 00:17:05 +02:00
|
|
|
if(ev->button == Button4)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_tag_viewnext(&awesomeconf[screen], NULL);
|
2007-09-16 00:17:05 +02:00
|
|
|
else if(ev->button == Button5)
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_tag_viewprev(&awesomeconf[screen], NULL);
|
2007-10-03 17:17:46 +02:00
|
|
|
break;
|
2007-09-16 00:17:05 +02:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-17 23:57:16 +02:00
|
|
|
handle_event_configurerequest(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
|
|
|
XWindowChanges wc;
|
|
|
|
|
2007-10-15 16:27:48 +02:00
|
|
|
if((c = get_client_bywin(awesomeconf->clients, ev->window)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->ismax = False;
|
|
|
|
if(ev->value_mask & CWBorderWidth)
|
|
|
|
c->border = ev->border_width;
|
2007-10-11 11:33:40 +02:00
|
|
|
if(c->isfixed || c->isfloating || IS_ARRANGE(c->screen, layout_floating))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
if(ev->value_mask & CWX)
|
|
|
|
c->x = ev->x;
|
|
|
|
if(ev->value_mask & CWY)
|
|
|
|
c->y = ev->y;
|
|
|
|
if(ev->value_mask & CWWidth)
|
|
|
|
c->w = ev->width;
|
|
|
|
if(ev->value_mask & CWHeight)
|
|
|
|
c->h = ev->height;
|
2007-10-01 15:23:05 +02:00
|
|
|
if((c->x + c->w) > DisplayWidth(c->display, c->phys_screen) && c->isfloating)
|
|
|
|
c->x = DisplayWidth(c->display, c->phys_screen) / 2 - c->w / 2; /* center in x direction */
|
|
|
|
if((c->y + c->h) > DisplayHeight(c->display, c->phys_screen) && c->isfloating)
|
|
|
|
c->y = DisplayHeight(c->display, c->phys_screen) / 2 - c->h / 2; /* center in y direction */
|
2007-09-05 20:15:00 +02:00
|
|
|
if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight)))
|
|
|
|
configure(c);
|
2007-09-24 15:37:52 +02:00
|
|
|
if(isvisible(c, c->screen, awesomeconf[c->screen].tags, awesomeconf[c->screen].ntags))
|
2007-09-05 20:15:00 +02:00
|
|
|
XMoveResizeWindow(e->xany.display, c->win, c->x, c->y, c->w, c->h);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
configure(c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wc.x = ev->x;
|
|
|
|
wc.y = ev->y;
|
|
|
|
wc.width = ev->width;
|
|
|
|
wc.height = ev->height;
|
|
|
|
wc.border_width = ev->border_width;
|
|
|
|
wc.sibling = ev->above;
|
|
|
|
wc.stack_mode = ev->detail;
|
|
|
|
XConfigureWindow(e->xany.display, ev->window, ev->value_mask, &wc);
|
|
|
|
}
|
|
|
|
XSync(e->xany.display, False);
|
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_configurenotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
XConfigureEvent *ev = &e->xconfigure;
|
2007-10-01 20:58:29 +02:00
|
|
|
int screen;
|
2007-09-27 21:22:35 +02:00
|
|
|
ScreenInfo *si;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-16 00:11:10 +02:00
|
|
|
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
|
|
|
if(ev->window == RootWindow(e->xany.display, screen)
|
|
|
|
&& (ev->width != DisplayWidth(e->xany.display, screen)
|
|
|
|
|| ev->height != DisplayHeight(e->xany.display, screen)))
|
|
|
|
{
|
|
|
|
DisplayWidth(e->xany.display, screen) = ev->width;
|
|
|
|
DisplayHeight(e->xany.display, screen) = ev->height;
|
2007-09-27 21:22:35 +02:00
|
|
|
|
2007-10-11 23:44:35 +02:00
|
|
|
/* update statusbar */
|
2007-09-16 12:13:34 +02:00
|
|
|
XFreePixmap(e->xany.display, awesomeconf[screen].statusbar.drawable);
|
2007-10-11 23:44:35 +02:00
|
|
|
|
|
|
|
si = get_screen_info(e->xany.display, screen, NULL);
|
|
|
|
awesomeconf[screen].statusbar.width = si[screen].width;
|
|
|
|
p_delete(&si);
|
|
|
|
|
2007-09-16 12:13:34 +02:00
|
|
|
awesomeconf[screen].statusbar.drawable = XCreatePixmap(e->xany.display, RootWindow(e->xany.display, screen),
|
2007-10-11 23:44:35 +02:00
|
|
|
awesomeconf[screen].statusbar.width,
|
2007-09-16 12:13:34 +02:00
|
|
|
awesomeconf[screen].statusbar.height,
|
|
|
|
DefaultDepth(e->xany.display, screen));
|
2007-10-11 23:44:35 +02:00
|
|
|
XResizeWindow(e->xany.display,
|
|
|
|
awesomeconf[screen].statusbar.window,
|
|
|
|
awesomeconf[screen].statusbar.width,
|
|
|
|
awesomeconf[screen].statusbar.height);
|
|
|
|
|
2007-09-16 12:13:34 +02:00
|
|
|
updatebarpos(e->xany.display, awesomeconf[screen].statusbar);
|
2007-10-10 14:09:36 +02:00
|
|
|
arrange(e->xany.display, &awesomeconf[screen]);
|
2007-09-16 00:11:10 +02:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_destroynotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
|
|
|
|
2007-10-15 16:27:48 +02:00
|
|
|
if((c = get_client_bywin(awesomeconf->clients, ev->window)))
|
2007-10-10 14:09:36 +02:00
|
|
|
unmanage(c, WithdrawnState, &awesomeconf[c->screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_enternotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
XCrossingEvent *ev = &e->xcrossing;
|
2007-09-16 00:11:10 +02:00
|
|
|
int screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
|
|
|
|
return;
|
2007-10-15 16:27:48 +02:00
|
|
|
if((c = get_client_bywin(awesomeconf->clients, ev->window)))
|
2007-10-11 11:33:40 +02:00
|
|
|
{
|
2007-10-11 23:12:05 +02:00
|
|
|
if(!*awesomeconf->client_sel || *awesomeconf->client_sel != c)
|
2007-10-11 11:41:40 +02:00
|
|
|
{
|
|
|
|
focus(c->display, c, ev->same_screen, &awesomeconf[c->screen]);
|
2007-10-11 23:12:05 +02:00
|
|
|
if (*awesomeconf->client_sel && ((*awesomeconf->client_sel)->isfloating || IS_ARRANGE((*awesomeconf->client_sel)->screen, layout_floating)))
|
|
|
|
grabbuttons(*awesomeconf->client_sel, True, False, awesomeconf->modkey, awesomeconf->numlockmask);
|
2007-10-11 11:41:40 +02:00
|
|
|
}
|
2007-10-11 06:46:28 +02:00
|
|
|
}
|
2007-09-16 00:11:10 +02:00
|
|
|
else
|
|
|
|
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
|
|
|
if(ev->window == RootWindow(e->xany.display, screen))
|
2007-10-10 14:09:36 +02:00
|
|
|
focus(e->xany.display, NULL, True, &awesomeconf[screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_expose(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
XExposeEvent *ev = &e->xexpose;
|
2007-09-16 12:13:34 +02:00
|
|
|
int screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-16 12:13:34 +02:00
|
|
|
if(!ev->count)
|
2007-09-27 16:34:51 +02:00
|
|
|
for(screen = 0; screen < get_screen_count(e->xany.display); screen++)
|
2007-09-16 12:13:34 +02:00
|
|
|
if(awesomeconf[screen].statusbar.window == ev->window)
|
2007-10-10 14:09:36 +02:00
|
|
|
drawstatusbar(e->xany.display, &awesomeconf[screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_keypress(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-01 12:43:05 +02:00
|
|
|
int i, screen, x, y, d;
|
2007-09-16 01:05:43 +02:00
|
|
|
unsigned int m;
|
2007-09-05 20:15:00 +02:00
|
|
|
KeySym keysym;
|
|
|
|
XKeyEvent *ev = &e->xkey;
|
2007-09-16 01:05:43 +02:00
|
|
|
Window dummy;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
keysym = XKeycodeToKeysym(e->xany.display, (KeyCode) ev->keycode, 0);
|
2007-09-16 12:13:34 +02:00
|
|
|
|
2007-09-24 14:20:04 +02:00
|
|
|
/* find the right screen for this event */
|
2007-10-01 12:43:05 +02:00
|
|
|
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
|
|
|
if(XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), &dummy, &dummy, &x, &y, &d, &d, &m))
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
* number with get_screen_bycoord: we'll get 0 in Zaphod mode
|
|
|
|
* so it's the same, or maybe the real Xinerama screen */
|
2007-10-10 21:48:31 +02:00
|
|
|
if(screen == 0)
|
|
|
|
screen = get_screen_bycoord(e->xany.display, x, y);
|
|
|
|
break;
|
2007-10-01 12:43:05 +02:00
|
|
|
}
|
2007-09-24 14:20:04 +02:00
|
|
|
|
|
|
|
for(i = 0; i < awesomeconf[screen].nkeys; i++)
|
|
|
|
if(keysym == awesomeconf[screen].keys[i].keysym
|
|
|
|
&& CLEANMASK(awesomeconf[screen].keys[i].mod, screen) == CLEANMASK(ev->state, screen) && awesomeconf[screen].keys[i].func)
|
2007-10-11 23:32:29 +02:00
|
|
|
awesomeconf[screen].keys[i].func(&awesomeconf[screen], awesomeconf[screen].keys[i].arg);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_leavenotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
XCrossingEvent *ev = &e->xcrossing;
|
2007-09-16 00:11:10 +02:00
|
|
|
int screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-09-16 00:11:10 +02:00
|
|
|
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
|
|
|
if((ev->window == RootWindow(e->xany.display, screen)) && !ev->same_screen)
|
2007-10-10 14:09:36 +02:00
|
|
|
focus(e->xany.display, NULL, ev->same_screen, &awesomeconf[screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_mappingnotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
XMappingEvent *ev = &e->xmapping;
|
2007-09-16 13:51:27 +02:00
|
|
|
int screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
XRefreshKeyboardMapping(ev);
|
|
|
|
if(ev->request == MappingKeyboard)
|
2007-09-16 13:51:27 +02:00
|
|
|
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
|
2007-10-15 18:17:33 +02:00
|
|
|
grabkeys(&awesomeconf[screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_maprequest(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
static XWindowAttributes wa;
|
|
|
|
XMapRequestEvent *ev = &e->xmaprequest;
|
2007-10-12 10:49:03 +02:00
|
|
|
int screen, x, y, d;
|
|
|
|
unsigned int m;
|
|
|
|
Window dummy;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
if(!XGetWindowAttributes(e->xany.display, ev->window, &wa))
|
|
|
|
return;
|
|
|
|
if(wa.override_redirect)
|
|
|
|
return;
|
2007-10-15 16:27:48 +02:00
|
|
|
if(!get_client_bywin(awesomeconf->clients, ev->window))
|
2007-09-16 00:11:10 +02:00
|
|
|
{
|
|
|
|
for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++);
|
2007-09-27 18:57:22 +02:00
|
|
|
if(screen == 0)
|
2007-10-12 10:49:03 +02:00
|
|
|
{
|
2007-09-27 18:57:22 +02:00
|
|
|
screen = get_screen_bycoord(e->xany.display, wa.x, wa.y);
|
2007-10-12 10:49:03 +02:00
|
|
|
if(screen == 0 &&
|
|
|
|
XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen),
|
|
|
|
&dummy, &dummy, &x, &y, &d, &d, &m))
|
|
|
|
screen = get_screen_bycoord(e->xany.display, x, y);
|
|
|
|
|
|
|
|
}
|
2007-10-10 14:09:36 +02:00
|
|
|
manage(e->xany.display, ev->window, &wa, &awesomeconf[screen]);
|
2007-09-16 00:11:10 +02:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_propertynotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
Window trans;
|
|
|
|
XPropertyEvent *ev = &e->xproperty;
|
|
|
|
|
|
|
|
if(ev->state == PropertyDelete)
|
|
|
|
return; /* ignore */
|
2007-10-15 16:27:48 +02:00
|
|
|
if((c = get_client_bywin(awesomeconf->clients, ev->window)))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
switch (ev->atom)
|
|
|
|
{
|
|
|
|
case XA_WM_TRANSIENT_FOR:
|
|
|
|
XGetTransientForHint(e->xany.display, c->win, &trans);
|
2007-10-15 16:27:48 +02:00
|
|
|
if(!c->isfloating && (c->isfloating = (get_client_bywin(awesomeconf->clients, trans) != NULL)))
|
2007-10-10 14:09:36 +02:00
|
|
|
arrange(e->xany.display, &awesomeconf[c->screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
break;
|
|
|
|
case XA_WM_NORMAL_HINTS:
|
|
|
|
updatesizehints(c);
|
|
|
|
break;
|
|
|
|
}
|
2007-09-10 16:49:54 +02:00
|
|
|
if(ev->atom == XA_WM_NAME || ev->atom == XInternAtom(c->display, "_NET_WM_NAME", False))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
updatetitle(c);
|
2007-10-11 23:12:05 +02:00
|
|
|
if(c == *awesomeconf->client_sel)
|
2007-10-10 14:09:36 +02:00
|
|
|
drawstatusbar(e->xany.display, &awesomeconf[c->screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-07 12:29:54 +02:00
|
|
|
void
|
2007-09-10 12:06:54 +02:00
|
|
|
handle_event_unmapnotify(XEvent * e, awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
XUnmapEvent *ev = &e->xunmap;
|
|
|
|
|
2007-10-15 16:27:48 +02:00
|
|
|
if((c = get_client_bywin(awesomeconf->clients, ev->window))
|
2007-10-03 20:46:03 +02:00
|
|
|
&& ev->event == RootWindow(e->xany.display, c->phys_screen) && (ev->send_event || !c->unmapped))
|
2007-10-10 14:09:36 +02:00
|
|
|
unmanage(c, WithdrawnState, &awesomeconf[c->screen]);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-13 15:57:35 +02:00
|
|
|
void
|
|
|
|
handle_event_shape(XEvent * e,
|
|
|
|
awesome_config *awesomeconf __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
XShapeEvent *ev = (XShapeEvent *) e;
|
2007-10-15 16:27:48 +02:00
|
|
|
Client *c = get_client_bywin(awesomeconf->clients, ev->window);
|
2007-09-13 15:57:35 +02:00
|
|
|
|
|
|
|
if(c)
|
|
|
|
set_shape(c);
|
|
|
|
}
|
|
|
|
|
2007-09-13 16:00:03 +02:00
|
|
|
void
|
|
|
|
handle_event_randr_screen_change_notify(XEvent *e,
|
|
|
|
awesome_config *awesomeconf __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
XRRUpdateConfiguration(e);
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2007-10-15 18:17:33 +02:00
|
|
|
grabkeys(awesome_config *awesomeconf)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
KeyCode code;
|
|
|
|
|
2007-10-15 18:17:33 +02:00
|
|
|
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
|
2007-09-10 12:06:54 +02:00
|
|
|
for(i = 0; i < awesomeconf->nkeys; i++)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-10-15 18:17:33 +02:00
|
|
|
if((code = XKeysymToKeycode(awesomeconf->display, awesomeconf->keys[i].keysym)) == NoSymbol)
|
2007-09-16 02:14:37 +02:00
|
|
|
continue;
|
2007-10-15 18:17:33 +02:00
|
|
|
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
|
|
|
|
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
|
|
|
|
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod | awesomeconf->numlockmask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
|
|
|
|
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod | awesomeconf->numlockmask | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True,
|
2007-09-05 20:15:00 +02:00
|
|
|
GrabModeAsync, GrabModeAsync);
|
|
|
|
}
|
|
|
|
}
|
2007-10-15 13:56:24 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|