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 if(!c
->isfloating
&& layout
->arrange
!= layout_floating
)
84 XQueryPointer(globalconf
.display
, RootWindow(globalconf
.display
, phys_screen
),
85 &dummy
, &child
, &x
, &y
, &di
, &di
, &dui
);
86 if((newscreen
= get_screen_bycoord(x
, y
)) != screen
)
88 move_client_to_screen(c
, newscreen
, True
);
89 globalconf
.screens
[screen
].need_arrange
= True
;
90 globalconf
.screens
[newscreen
].need_arrange
= True
;
92 if((target
= get_client_bywin(globalconf
.clients
, child
)) && target
!= c
)
94 client_list_swap(&globalconf
.clients
, c
, target
);
95 globalconf
.screens
[screen
].need_arrange
= True
;
98 XUngrabPointer(globalconf
.display
, CurrentTime
);
100 case ConfigureRequest
:
101 handle_event_configurerequest(&ev
);
104 handle_event_expose(&ev
);
107 handle_event_maprequest(&ev
);
110 handle_event_enternotify(&ev
);
113 if(c
->isfloating
|| layout
->arrange
== layout_floating
)
115 geometry
.x
= ocx
+ (ev
.xmotion
.x
- x
);
116 geometry
.y
= ocy
+ (ev
.xmotion
.y
- y
);
117 if(abs(geometry
.x
) < globalconf
.screens
[screen
].snap
+ area
.x
&& geometry
.x
> area
.x
)
119 else if(abs((area
.x
+ area
.width
) - (geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
))
120 < globalconf
.screens
[screen
].snap
)
121 geometry
.x
= area
.x
+ area
.width
- c
->geometry
.width
- 2 * c
->border
;
122 if(abs(geometry
.y
) < globalconf
.screens
[screen
].snap
+ area
.y
&& geometry
.y
> area
.y
)
124 else if(abs((area
.y
+ area
.height
) - (geometry
.y
+ c
->geometry
.height
+ 2 * c
->border
))
125 < globalconf
.screens
[screen
].snap
)
126 geometry
.y
= area
.y
+ area
.height
- c
->geometry
.height
- 2 * c
->border
;
127 geometry
.width
= c
->geometry
.width
;
128 geometry
.height
= c
->geometry
.height
;
129 client_resize(c
, geometry
, False
);
130 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
137 /** Resize client with mouse
138 * \param screen Screen ID
140 * \ingroup ui_callback
143 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
145 int ocx
= 0, ocy
= 0, n
;
147 Client
*c
= globalconf
.focus
->client
;
148 Tag
**curtags
= get_current_tags(screen
);
149 Layout
*layout
= curtags
[0]->layout
;
150 Area area
= { 0, 0, 0, 0 }, geometry
;
153 /* only handle floating and tiled layouts */
156 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
162 else if (layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
163 || layout
->arrange
== layout_tilebottom
|| layout
->arrange
== layout_tiletop
)
165 for(n
= 0, c
= globalconf
.clients
; c
; c
= c
->next
)
166 if(IS_TILED(c
, screen
))
169 if(n
<= curtags
[0]->nmaster
) return;
171 for(c
= globalconf
.clients
; c
&& !IS_TILED(c
, screen
); c
= c
->next
);
174 area
= get_screen_area(screen
,
175 globalconf
.screens
[c
->screen
].statusbar
,
176 &globalconf
.screens
[c
->screen
].padding
);
182 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
,
183 get_phys_screen(c
->screen
)),
184 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
185 RootWindow(globalconf
.display
,get_phys_screen(c
->screen
)),
186 globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
189 if(curtags
[0]->layout
->arrange
== layout_tileleft
)
190 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, 0, c
->geometry
.height
+ c
->border
- 1);
191 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
192 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
193 else if(curtags
[0]->layout
->arrange
== layout_tiletop
)
194 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, 0);
196 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
200 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
204 XUngrabPointer(globalconf
.display
, CurrentTime
);
206 case ConfigureRequest
:
207 handle_event_configurerequest(&ev
);
210 handle_event_expose(&ev
);
213 handle_event_maprequest(&ev
);
216 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
218 if((geometry
.width
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
220 if((geometry
.height
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
222 geometry
.x
= c
->geometry
.x
;
223 geometry
.y
= c
->geometry
.y
;
224 client_resize(c
, geometry
, True
);
226 else if(layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
227 || layout
->arrange
== layout_tiletop
|| layout
->arrange
== layout_tilebottom
)
229 if(layout
->arrange
== layout_tile
)
230 mwfact
= (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
231 else if(curtags
[0]->layout
->arrange
== layout_tileleft
)
232 mwfact
= 1 - (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
233 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
234 mwfact
= (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
236 mwfact
= 1 - (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
237 if(mwfact
< 0.1) mwfact
= 0.1;
238 else if(mwfact
> 0.9) mwfact
= 0.9;
239 if(fabs(curtags
[0]->mwfact
- mwfact
) >= 0.01)
241 curtags
[0]->mwfact
= mwfact
;
242 globalconf
.screens
[screen
].need_arrange
= True
;
244 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
254 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80