windows that start in Withdrawstate are skipped in focus list
[awesome.git] / mouse.c
blobaac59dece7a3c59e395d34b6e2b52d0cf5c97058
1 /*
2 * mouse.c - mouse managing
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "mouse.h"
23 #include "screen.h"
24 #include "layout.h"
25 #include "tag.h"
26 #include "util.h"
27 #include "event.h"
28 #include "window.h"
29 #include "statusbar.h"
30 #include "layouts/floating.h"
32 extern AwesomeConf globalconf;
34 /** Move client with mouse
35 * \param screen Screen ID
36 * \param arg Unused
37 * \ingroup ui_callback
39 void
40 uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
42 int x1, y1, ocx, ocy, di, nx, ny;
43 unsigned int dui;
44 Window dummy;
45 XEvent ev;
46 Area area;
47 Client *c = globalconf.focus->client;
48 Tag **curtags = get_current_tags(screen);
50 if(!c)
51 return;
53 if((curtags[0]->layout->arrange != layout_floating)
54 && !c->isfloating)
55 uicb_client_togglefloating(screen, NULL);
56 else
57 restack(screen);
59 p_delete(&curtags);
61 area = get_screen_area(c->screen,
62 globalconf.screens[screen].statusbar,
63 &globalconf.screens[screen].padding);
65 ocx = nx = c->x;
66 ocy = ny = c->y;
67 if(XGrabPointer(globalconf.display,
68 RootWindow(globalconf.display, c->phys_screen),
69 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
70 None, globalconf.cursor[CurMove], CurrentTime) != GrabSuccess)
71 return;
72 XQueryPointer(globalconf.display,
73 RootWindow(globalconf.display, c->phys_screen),
74 &dummy, &dummy, &x1, &y1, &di, &di, &dui);
75 c->ismax = False;
76 statusbar_draw(c->screen);
77 for(;;)
79 XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
80 switch (ev.type)
82 case ButtonRelease:
83 XUngrabPointer(globalconf.display, CurrentTime);
84 return;
85 case ConfigureRequest:
86 handle_event_configurerequest(&ev);
87 break;
88 case Expose:
89 handle_event_expose(&ev);
90 break;
91 case MapRequest:
92 handle_event_maprequest(&ev);
93 break;
94 case MotionNotify:
95 nx = ocx + (ev.xmotion.x - x1);
96 ny = ocy + (ev.xmotion.y - y1);
97 if(abs(nx) < globalconf.screens[screen].snap + area.x && nx > area.x)
98 nx = area.x;
99 else if(abs((area.x + area.width) - (nx + c->w + 2 * c->border)) < globalconf.screens[screen].snap)
100 nx = area.x + area.width - c->w - 2 * c->border;
101 if(abs(ny) < globalconf.screens[screen].snap + area.y && ny > area.y)
102 ny = area.y;
103 else if(abs((area.y + area.height) - (ny + c->h + 2 * c->border)) < globalconf.screens[screen].snap)
104 ny = area.y + area.height - c->h - 2 * c->border;
105 client_resize(c, nx, ny, c->w, c->h, False, False);
106 break;
111 /** Resize client with mouse
112 * \param screen Screen ID
113 * \param arg Unused
114 * \ingroup ui_callback
116 void
117 uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
119 int ocx, ocy, nw, nh;
120 XEvent ev;
121 Client *c = globalconf.focus->client;
122 Tag **curtags = get_current_tags(screen);
124 if(!c)
125 return;
127 if((curtags[0]->layout->arrange != layout_floating)
128 && !c->isfloating)
129 uicb_client_togglefloating(screen, NULL);
130 else
131 restack(screen);
133 p_delete(&curtags);
135 ocx = c->x;
136 ocy = c->y;
137 if(XGrabPointer(globalconf.display, RootWindow(globalconf.display, c->phys_screen),
138 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
139 None, globalconf.cursor[CurResize], CurrentTime) != GrabSuccess)
140 return;
141 c->ismax = False;
142 statusbar_draw(c->screen);
143 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
144 for(;;)
146 XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
147 switch (ev.type)
149 case ButtonRelease:
150 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
151 XUngrabPointer(globalconf.display, CurrentTime);
152 while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
153 return;
154 case ConfigureRequest:
155 handle_event_configurerequest(&ev);
156 break;
157 case Expose:
158 handle_event_expose(&ev);
159 break;
160 case MapRequest:
161 handle_event_maprequest(&ev);
162 break;
163 case MotionNotify:
164 if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
165 nw = 1;
166 if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
167 nh = 1;
168 client_resize(c, c->x, c->y, nw, nh, True, False);
169 break;
175 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80