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 x
, y
, ocx
, ocy
, di
, phys_screen
, newscreen
;
50 Client
*c
= globalconf
.focus
->client
, *target
;
51 Layout
*layout
= get_current_layout(screen
);
56 /* go above everybody */
57 XMapRaised(globalconf
.display
, c
->win
);
59 area
= get_screen_area(c
->screen
,
60 globalconf
.screens
[screen
].statusbar
,
61 &globalconf
.screens
[screen
].padding
);
63 ocx
= geometry
.x
= c
->geometry
.x
;
64 ocy
= geometry
.y
= c
->geometry
.y
;
65 phys_screen
= get_phys_screen(c
->screen
);
66 if(XGrabPointer(globalconf
.display
,
67 RootWindow(globalconf
.display
, phys_screen
),
68 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
69 RootWindow(globalconf
.display
, phys_screen
),
70 globalconf
.cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
72 XQueryPointer(globalconf
.display
,
73 RootWindow(globalconf
.display
, phys_screen
),
74 &dummy
, &dummy
, &x
, &y
, &di
, &di
, &dui
);
78 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
82 XUngrabPointer(globalconf
.display
, CurrentTime
);
84 case ConfigureRequest
:
85 handle_event_configurerequest(&ev
);
88 handle_event_expose(&ev
);
91 handle_event_maprequest(&ev
);
94 handle_event_enternotify(&ev
);
97 if(c
->isfloating
|| layout
->arrange
== layout_floating
)
99 geometry
.x
= ocx
+ (ev
.xmotion
.x
- x
);
100 geometry
.y
= ocy
+ (ev
.xmotion
.y
- y
);
101 if(abs(geometry
.x
) < globalconf
.screens
[screen
].snap
+ area
.x
&& geometry
.x
> area
.x
)
103 else if(abs((area
.x
+ area
.width
) - (geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
))
104 < globalconf
.screens
[screen
].snap
)
105 geometry
.x
= area
.x
+ area
.width
- c
->geometry
.width
- 2 * c
->border
;
106 if(abs(geometry
.y
) < globalconf
.screens
[screen
].snap
+ area
.y
&& geometry
.y
> area
.y
)
108 else if(abs((area
.y
+ area
.height
) - (geometry
.y
+ c
->geometry
.height
+ 2 * c
->border
))
109 < 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
));
118 XQueryPointer(globalconf
.display
,
119 RootWindow(globalconf
.display
, phys_screen
),
120 &dummy
, &child
, &x
, &y
, &di
, &di
, &dui
);
121 if((newscreen
= get_screen_bycoord(x
, y
)) != c
->screen
)
123 move_client_to_screen(c
, newscreen
, True
);
124 globalconf
.screens
[c
->screen
].need_arrange
= True
;
125 globalconf
.screens
[newscreen
].need_arrange
= True
;
128 if((target
= get_client_bywin(globalconf
.clients
, child
))
131 client_list_swap(&globalconf
.clients
, c
, target
);
132 globalconf
.screens
[c
->screen
].need_arrange
= True
;
141 /** Resize client with mouse
142 * \param screen Screen ID
144 * \ingroup ui_callback
147 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
149 int ocx
= 0, ocy
= 0, n
;
151 Client
*c
= globalconf
.focus
->client
;
152 Tag
**curtags
= get_current_tags(screen
);
153 Layout
*layout
= curtags
[0]->layout
;
154 Area area
= { 0, 0, 0, 0 }, geometry
;
157 /* only handle floating and tiled layouts */
160 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
166 else if (layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
167 || layout
->arrange
== layout_tilebottom
|| layout
->arrange
== layout_tiletop
)
169 for(n
= 0, c
= globalconf
.clients
; c
; c
= c
->next
)
170 if(IS_TILED(c
, screen
))
173 if(n
<= curtags
[0]->nmaster
) return;
175 for(c
= globalconf
.clients
; c
&& !IS_TILED(c
, screen
); c
= c
->next
);
178 area
= get_screen_area(screen
,
179 globalconf
.screens
[c
->screen
].statusbar
,
180 &globalconf
.screens
[c
->screen
].padding
);
186 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
,
187 get_phys_screen(c
->screen
)),
188 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
189 RootWindow(globalconf
.display
,get_phys_screen(c
->screen
)),
190 globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
193 if(curtags
[0]->layout
->arrange
== layout_tileleft
)
194 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, 0, c
->geometry
.height
+ c
->border
- 1);
195 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
196 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
197 else if(curtags
[0]->layout
->arrange
== layout_tiletop
)
198 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, 0);
200 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
204 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
208 XUngrabPointer(globalconf
.display
, CurrentTime
);
210 case ConfigureRequest
:
211 handle_event_configurerequest(&ev
);
214 handle_event_expose(&ev
);
217 handle_event_maprequest(&ev
);
220 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
222 if((geometry
.width
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
224 if((geometry
.height
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
226 geometry
.x
= c
->geometry
.x
;
227 geometry
.y
= c
->geometry
.y
;
228 client_resize(c
, geometry
, True
);
230 else if(layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
231 || layout
->arrange
== layout_tiletop
|| layout
->arrange
== layout_tilebottom
)
233 if(layout
->arrange
== layout_tile
)
234 mwfact
= (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
235 else if(curtags
[0]->layout
->arrange
== layout_tileleft
)
236 mwfact
= 1 - (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
237 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
238 mwfact
= (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
240 mwfact
= 1 - (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
241 if(mwfact
< 0.1) mwfact
= 0.1;
242 else if(mwfact
> 0.9) mwfact
= 0.9;
243 if(fabs(curtags
[0]->mwfact
- mwfact
) >= 0.01)
245 curtags
[0]->mwfact
= mwfact
;
246 globalconf
.screens
[screen
].need_arrange
= True
;
248 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
258 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80