remove focustitle widget
[awesome.git] / mouse.c
blobcd09588397651adcbf055811d0dd6a33ef0d2420
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 <math.h>
24 #include "mouse.h"
25 #include "screen.h"
26 #include "layout.h"
27 #include "tag.h"
28 #include "event.h"
29 #include "window.h"
30 #include "client.h"
31 #include "layouts/floating.h"
32 #include "layouts/tile.h"
34 #define MOUSEMASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
36 extern AwesomeConf globalconf;
38 /** Move client with mouse
39 * \param screen Screen ID
40 * \param arg Unused
41 * \ingroup ui_callback
43 void
44 uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
46 int x, y, ocx, ocy, di, phys_screen, newscreen;
47 unsigned int dui;
48 Window dummy, child;
49 XEvent ev;
50 Area area, geometry;
51 Client *c = globalconf.focus->client, *target;
52 Layout *layout = get_current_layout(screen);
54 if(!c)
55 return;
57 /* go above everybody */
58 XMapRaised(globalconf.display, c->win);
60 area = screen_get_area(c->screen,
61 globalconf.screens[screen].statusbar,
62 &globalconf.screens[screen].padding);
64 ocx = geometry.x = c->geometry.x;
65 ocy = geometry.y = c->geometry.y;
66 phys_screen = get_phys_screen(c->screen);
67 if(XGrabPointer(globalconf.display,
68 RootWindow(globalconf.display, phys_screen),
69 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
70 RootWindow(globalconf.display, phys_screen),
71 globalconf.cursor[CurMove], CurrentTime) != GrabSuccess)
72 return;
73 XQueryPointer(globalconf.display,
74 RootWindow(globalconf.display, phys_screen),
75 &dummy, &dummy, &x, &y, &di, &di, &dui);
76 c->ismax = False;
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 EnterNotify:
95 handle_event_enternotify(&ev);
96 break;
97 case MotionNotify:
98 if(c->isfloating || layout->arrange == layout_floating)
100 geometry.x = ocx + (ev.xmotion.x - x);
101 geometry.y = ocy + (ev.xmotion.y - y);
102 if(abs(geometry.x) < globalconf.screens[screen].snap + area.x && geometry.x > area.x)
103 geometry.x = area.x;
104 else if(abs((area.x + area.width) - (geometry.x + c->geometry.width + 2 * c->border))
105 < globalconf.screens[screen].snap)
106 geometry.x = area.x + area.width - c->geometry.width - 2 * c->border;
107 if(abs(geometry.y) < globalconf.screens[screen].snap + area.y && geometry.y > area.y)
108 geometry.y = area.y;
109 else if(abs((area.y + area.height) - (geometry.y + c->geometry.height + 2 * c->border))
110 < globalconf.screens[screen].snap)
111 geometry.y = area.y + area.height - c->geometry.height - 2 * c->border;
112 geometry.width = c->geometry.width;
113 geometry.height = c->geometry.height;
114 client_resize(c, geometry, False);
115 while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
117 else
119 XQueryPointer(globalconf.display,
120 RootWindow(globalconf.display, phys_screen),
121 &dummy, &child, &x, &y, &di, &di, &dui);
122 if((newscreen = screen_get_bycoord(x, y)) != c->screen)
124 move_client_to_screen(c, newscreen, True);
125 globalconf.screens[c->screen].need_arrange = True;
126 globalconf.screens[newscreen].need_arrange = True;
127 layout_refresh();
129 if((target = client_get_bywin(globalconf.clients, child))
130 && target != c)
132 client_list_swap(&globalconf.clients, c, target);
133 globalconf.screens[c->screen].need_arrange = True;
134 layout_refresh();
137 break;
142 /** Resize client with mouse
143 * \param screen Screen ID
144 * \param arg Unused
145 * \ingroup ui_callback
147 void
148 uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
150 int ocx = 0, ocy = 0, n;
151 XEvent ev;
152 Client *c = globalconf.focus->client;
153 Tag **curtags = tags_get_current(screen);
154 Layout *layout = curtags[0]->layout;
155 Area area = { 0, 0, 0, 0 , NULL}, geometry;
156 double mwfact;
158 /* only handle floating and tiled layouts */
159 if(c && !c->isfixed)
161 if(layout->arrange == layout_floating || c->isfloating)
163 ocx = c->geometry.x;
164 ocy = c->geometry.y;
165 c->ismax = False;
167 else if (layout->arrange == layout_tile || layout->arrange == layout_tileleft
168 || layout->arrange == layout_tilebottom || layout->arrange == layout_tiletop)
170 for(n = 0, c = globalconf.clients; c; c = c->next)
171 if(IS_TILED(c, screen))
172 n++;
174 if(n <= curtags[0]->nmaster) return;
176 for(c = globalconf.clients; c && !IS_TILED(c, screen); c = c->next);
177 if(!c) return;
179 area = screen_get_area(screen,
180 globalconf.screens[c->screen].statusbar,
181 &globalconf.screens[c->screen].padding);
184 else
185 return;
187 if(XGrabPointer(globalconf.display, RootWindow(globalconf.display,
188 get_phys_screen(c->screen)),
189 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
190 RootWindow(globalconf.display,get_phys_screen(c->screen)),
191 globalconf.cursor[CurResize], CurrentTime) != GrabSuccess)
192 return;
194 if(curtags[0]->layout->arrange == layout_tileleft)
195 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0, c->geometry.height + c->border - 1);
196 else if(curtags[0]->layout->arrange == layout_tilebottom)
197 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1);
198 else if(curtags[0]->layout->arrange == layout_tiletop)
199 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, 0);
200 else
201 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->geometry.width + c->border - 1, c->geometry.height + c->border - 1);
203 for(;;)
205 XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
206 switch (ev.type)
208 case ButtonRelease:
209 XUngrabPointer(globalconf.display, CurrentTime);
210 return;
211 case ConfigureRequest:
212 handle_event_configurerequest(&ev);
213 break;
214 case Expose:
215 handle_event_expose(&ev);
216 break;
217 case MapRequest:
218 handle_event_maprequest(&ev);
219 break;
220 case MotionNotify:
221 if(layout->arrange == layout_floating || c->isfloating)
223 if((geometry.width = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
224 geometry.width = 1;
225 if((geometry.height = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
226 geometry.height = 1;
227 geometry.x = c->geometry.x;
228 geometry.y = c->geometry.y;
229 client_resize(c, geometry, True);
231 else if(layout->arrange == layout_tile || layout->arrange == layout_tileleft
232 || layout->arrange == layout_tiletop || layout->arrange == layout_tilebottom)
234 if(layout->arrange == layout_tile)
235 mwfact = (double) (ev.xmotion.x - area.x) / area.width;
236 else if(curtags[0]->layout->arrange == layout_tileleft)
237 mwfact = 1 - (double) (ev.xmotion.x - area.x) / area.width;
238 else if(curtags[0]->layout->arrange == layout_tilebottom)
239 mwfact = (double) (ev.xmotion.y - area.y) / area.height;
240 else
241 mwfact = 1 - (double) (ev.xmotion.y - area.y) / area.height;
242 if(mwfact < 0.1) mwfact = 0.1;
243 else if(mwfact > 0.9) mwfact = 0.9;
244 if(fabs(curtags[0]->mwfact - mwfact) >= 0.01)
246 curtags[0]->mwfact = mwfact;
247 globalconf.screens[screen].need_arrange = True;
248 layout_refresh();
249 while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
253 break;
256 p_delete(&curtags);
259 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80