simply add draw_rectangle instead of drawtext
[awesome.git] / mouse.c
blob616b04e7ec55d337986ee7cb568b342e387894d3
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 "util.h"
29 #include "event.h"
30 #include "window.h"
31 #include "statusbar.h"
32 #include "client.h"
33 #include "layouts/floating.h"
34 #include "layouts/tile.h"
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 x1, y, ocx, ocy, di, nx, ny, phys_screen;
47 unsigned int dui;
48 Window dummy;
49 XEvent ev;
50 Area area;
51 Client *c = globalconf.focus->client;
52 Tag **curtags = get_current_tags(screen);
54 if(!c)
55 return;
57 if((curtags[0]->layout->arrange != layout_floating)
58 && !c->isfloating)
59 uicb_client_togglefloating(screen, NULL);
60 else
61 restack(screen);
63 p_delete(&curtags);
65 area = get_screen_area(c->screen,
66 globalconf.screens[screen].statusbar,
67 &globalconf.screens[screen].padding);
69 ocx = nx = c->x;
70 ocy = ny = c->y;
71 phys_screen = get_phys_screen(c->screen);
72 if(XGrabPointer(globalconf.display,
73 RootWindow(globalconf.display, phys_screen),
74 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
75 None, globalconf.cursor[CurMove], CurrentTime) != GrabSuccess)
76 return;
77 XQueryPointer(globalconf.display,
78 RootWindow(globalconf.display, phys_screen),
79 &dummy, &dummy, &x1, &y, &di, &di, &dui);
80 c->ismax = False;
81 statusbar_draw_all(c->screen);
82 for(;;)
84 XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
85 switch (ev.type)
87 case ButtonRelease:
88 XUngrabPointer(globalconf.display, CurrentTime);
89 return;
90 case ConfigureRequest:
91 handle_event_configurerequest(&ev);
92 break;
93 case Expose:
94 handle_event_expose(&ev);
95 break;
96 case MapRequest:
97 handle_event_maprequest(&ev);
98 break;
99 case MotionNotify:
100 nx = ocx + (ev.xmotion.x - x1);
101 ny = ocy + (ev.xmotion.y - y);
102 if(abs(nx) < globalconf.screens[screen].snap + area.x && nx > area.x)
103 nx = area.x;
104 else if(abs((area.x + area.width) - (nx + c->w + 2 * c->border)) < globalconf.screens[screen].snap)
105 nx = area.x + area.width - c->w - 2 * c->border;
106 if(abs(ny) < globalconf.screens[screen].snap + area.y && ny > area.y)
107 ny = area.y;
108 else if(abs((area.y + area.height) - (ny + c->h + 2 * c->border)) < globalconf.screens[screen].snap)
109 ny = area.y + area.height - c->h - 2 * c->border;
110 client_resize(c, nx, ny, c->w, c->h, False, False);
111 while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
112 break;
117 /** Resize client with mouse
118 * \param screen Screen ID
119 * \param arg Unused
120 * \ingroup ui_callback
122 void
123 uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
125 int ocx, ocy, nw, nh, n;
126 XEvent ev;
127 Client *c = globalconf.focus->client;
128 Tag **curtags = get_current_tags(screen);
129 Area area;
130 double mwfact;
132 /* only handle floating and tiled layouts */
133 if(c && !c->isfixed)
135 if((curtags[0]->layout->arrange == layout_floating) || c->isfloating)
137 restack(screen);
138 ocx = c->x;
139 ocy = c->y;
140 c->ismax = False;
142 else if (curtags[0]->layout->arrange == layout_tile
143 || curtags[0]->layout->arrange == layout_tileleft)
145 for(n = 0, c = globalconf.clients; c; c = c->next)
146 if(IS_TILED(c, screen))
147 n++;
149 if(n <= curtags[0]->nmaster) return;
151 for(c = globalconf.clients; c && !IS_TILED(c, screen); c = c->next);
152 if(!c) return;
154 area = get_screen_area(screen,
155 globalconf.screens[c->screen].statusbar,
156 &globalconf.screens[c->screen].padding);
159 else
160 return;
162 if(XGrabPointer(globalconf.display, RootWindow(globalconf.display,
163 get_phys_screen(c->screen)),
164 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
165 None, globalconf.cursor[CurResize], CurrentTime) != GrabSuccess)
166 return;
168 if(curtags[0]->layout->arrange == layout_tileleft)
169 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, 0, c->h + c->border - 1);
170 else
171 XWarpPointer(globalconf.display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
173 for(;;)
175 XMaskEvent(globalconf.display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
176 switch (ev.type)
178 case ButtonRelease:
179 XUngrabPointer(globalconf.display, CurrentTime);
180 while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
181 return;
182 case ConfigureRequest:
183 handle_event_configurerequest(&ev);
184 break;
185 case Expose:
186 handle_event_expose(&ev);
187 break;
188 case MapRequest:
189 handle_event_maprequest(&ev);
190 break;
191 case MotionNotify:
192 if(curtags[0]->layout->arrange == layout_floating || c->isfloating)
194 if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
195 nw = 1;
196 if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
197 nh = 1;
198 client_resize(c, c->x, c->y, nw, nh, True, False);
200 else if(curtags[0]->layout->arrange == layout_tile
201 || curtags[0]->layout->arrange == layout_tileleft)
203 if(curtags[0]->layout->arrange == layout_tile)
204 mwfact = (double) (ev.xmotion.x - area.x) / area.width;
205 else
206 mwfact = 1 - (double) (ev.xmotion.x - area.x) / area.width;
207 if(mwfact < 0.1) mwfact = 0.1;
208 else if(mwfact > 0.9) mwfact = 0.9;
209 if(fabs(curtags[0]->mwfact - mwfact) >= 0.05)
211 curtags[0]->mwfact = mwfact;
212 arrange(screen);
213 /* drop possibly arrived events while we where arrange()ing */
214 while(XCheckMaskEvent(globalconf.display, PointerMotionMask, &ev));
218 break;
221 p_delete(&curtags);
225 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80