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.
31 #include "layouts/floating.h"
32 #include "layouts/tile.h"
33 #include "common/util.h"
35 extern AwesomeConf globalconf
;
37 /** Move client with mouse
38 * \param screen Screen ID
40 * \ingroup ui_callback
43 uicb_client_movemouse(int screen
, char *arg
__attribute__ ((unused
)))
45 int x1
, y
, ocx
, ocy
, di
, phys_screen
;
50 Client
*c
= globalconf
.focus
->client
;
51 Layout
*layout
= get_current_layout(screen
);
56 if(layout
->arrange
!= layout_floating
&& !c
->isfloating
)
58 /* ugly hack: copy current geom to be floating
59 * because mouse will be far away from window otherwise */
60 c
->f_geometry
= c
->geometry
;
61 client_setfloating(c
, True
);
64 /* go above everybody */
65 XMapRaised(globalconf
.display
, c
->win
);
67 area
= get_screen_area(c
->screen
,
68 globalconf
.screens
[screen
].statusbar
,
69 &globalconf
.screens
[screen
].padding
);
71 ocx
= geometry
.x
= c
->geometry
.x
;
72 ocy
= geometry
.y
= c
->geometry
.y
;
73 phys_screen
= get_phys_screen(c
->screen
);
74 if(XGrabPointer(globalconf
.display
,
75 RootWindow(globalconf
.display
, phys_screen
),
76 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
77 None
, globalconf
.cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
79 XQueryPointer(globalconf
.display
,
80 RootWindow(globalconf
.display
, phys_screen
),
81 &dummy
, &dummy
, &x1
, &y
, &di
, &di
, &dui
);
85 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
89 XUngrabPointer(globalconf
.display
, CurrentTime
);
91 case ConfigureRequest
:
92 handle_event_configurerequest(&ev
);
95 handle_event_expose(&ev
);
98 handle_event_maprequest(&ev
);
101 geometry
.x
= ocx
+ (ev
.xmotion
.x
- x1
);
102 geometry
.y
= ocy
+ (ev
.xmotion
.y
- y
);
103 if(abs(geometry
.x
) < globalconf
.screens
[screen
].snap
+ area
.x
&& geometry
.x
> area
.x
)
105 else if(abs((area
.x
+ area
.width
) - (geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
)) < 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
)
109 else if(abs((area
.y
+ area
.height
) - (geometry
.y
+ c
->geometry
.height
+ 2 * c
->border
)) < globalconf
.screens
[screen
].snap
)
110 geometry
.y
= area
.y
+ area
.height
- c
->geometry
.height
- 2 * c
->border
;
111 geometry
.width
= c
->geometry
.width
;
112 geometry
.height
= c
->geometry
.height
;
113 client_resize(c
, geometry
, False
);
114 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
120 /** Resize client with mouse
121 * \param screen Screen ID
123 * \ingroup ui_callback
126 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
128 int ocx
= 0, ocy
= 0, n
;
130 Client
*c
= globalconf
.focus
->client
;
131 Tag
**curtags
= get_current_tags(screen
);
132 Layout
*layout
= curtags
[0]->layout
;
133 Area area
= { 0, 0, 0, 0 }, geometry
;
136 /* only handle floating and tiled layouts */
139 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
145 else if (layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
146 || layout
->arrange
== layout_tilebottom
|| layout
->arrange
== layout_tiletop
)
148 for(n
= 0, c
= globalconf
.clients
; c
; c
= c
->next
)
149 if(IS_TILED(c
, screen
))
152 if(n
<= curtags
[0]->nmaster
) return;
154 for(c
= globalconf
.clients
; c
&& !IS_TILED(c
, screen
); c
= c
->next
);
157 area
= get_screen_area(screen
,
158 globalconf
.screens
[c
->screen
].statusbar
,
159 &globalconf
.screens
[c
->screen
].padding
);
165 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
,
166 get_phys_screen(c
->screen
)),
167 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
168 None
, globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
171 if(curtags
[0]->layout
->arrange
== layout_tileleft
)
172 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, 0, c
->geometry
.height
+ c
->border
- 1);
173 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
174 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
175 else if(curtags
[0]->layout
->arrange
== layout_tiletop
)
176 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, 0);
178 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
182 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
186 XUngrabPointer(globalconf
.display
, CurrentTime
);
188 case ConfigureRequest
:
189 handle_event_configurerequest(&ev
);
192 handle_event_expose(&ev
);
195 handle_event_maprequest(&ev
);
198 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
200 if((geometry
.width
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
202 if((geometry
.height
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
204 geometry
.x
= c
->geometry
.x
;
205 geometry
.y
= c
->geometry
.y
;
206 client_resize(c
, geometry
, True
);
208 else if(layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
209 || layout
->arrange
== layout_tiletop
|| layout
->arrange
== layout_tilebottom
)
211 if(layout
->arrange
== layout_tile
)
212 mwfact
= (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
213 else if(curtags
[0]->layout
->arrange
== layout_tileleft
)
214 mwfact
= 1 - (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
215 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
216 mwfact
= (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
218 mwfact
= 1 - (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
219 if(mwfact
< 0.1) mwfact
= 0.1;
220 else if(mwfact
> 0.9) mwfact
= 0.9;
221 if(fabs(curtags
[0]->mwfact
- mwfact
) >= 0.05)
223 curtags
[0]->mwfact
= mwfact
;
224 globalconf
.screens
[screen
].need_arrange
= True
;
234 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80