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"
34 #define MOUSEMASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
36 extern AwesomeConf globalconf
;
38 /** Move client with mouse
39 * \param screen Screen ID
41 * \ingroup ui_callback
44 uicb_client_movemouse(int screen
, char *arg
__attribute__ ((unused
)))
46 int x
, y
, ocx
, ocy
, di
, phys_screen
, newscreen
;
51 Client
*c
= globalconf
.focus
->client
, *target
;
52 Layout
*layout
= layout_get_current(screen
);
57 area
= screen_get_area(c
->screen
,
58 globalconf
.screens
[screen
].statusbar
,
59 &globalconf
.screens
[screen
].padding
);
61 ocx
= geometry
.x
= c
->geometry
.x
;
62 ocy
= geometry
.y
= c
->geometry
.y
;
63 phys_screen
= get_phys_screen(c
->screen
);
64 if(XGrabPointer(globalconf
.display
,
65 RootWindow(globalconf
.display
, phys_screen
),
66 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
67 RootWindow(globalconf
.display
, phys_screen
),
68 globalconf
.cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
70 XQueryPointer(globalconf
.display
,
71 RootWindow(globalconf
.display
, phys_screen
),
72 &dummy
, &dummy
, &x
, &y
, &di
, &di
, &dui
);
76 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
80 XUngrabPointer(globalconf
.display
, CurrentTime
);
82 case ConfigureRequest
:
83 handle_event_configurerequest(&ev
);
86 handle_event_expose(&ev
);
89 handle_event_maprequest(&ev
);
92 handle_event_enternotify(&ev
);
95 if(c
->isfloating
|| layout
->arrange
== layout_floating
)
97 geometry
.x
= ocx
+ (ev
.xmotion
.x
- x
);
98 geometry
.y
= ocy
+ (ev
.xmotion
.y
- y
);
99 if(abs(geometry
.x
) < globalconf
.screens
[screen
].snap
+ area
.x
&& geometry
.x
> area
.x
)
101 else if(abs((area
.x
+ area
.width
) - (geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
))
102 < globalconf
.screens
[screen
].snap
)
103 geometry
.x
= area
.x
+ area
.width
- c
->geometry
.width
- 2 * c
->border
;
104 if(abs(geometry
.y
) < globalconf
.screens
[screen
].snap
+ area
.y
&& geometry
.y
> area
.y
)
106 else if(abs((area
.y
+ area
.height
) - (geometry
.y
+ c
->geometry
.height
+ 2 * c
->border
))
107 < globalconf
.screens
[screen
].snap
)
108 geometry
.y
= area
.y
+ area
.height
- c
->geometry
.height
- 2 * c
->border
;
109 geometry
.width
= c
->geometry
.width
;
110 geometry
.height
= c
->geometry
.height
;
111 client_resize(c
, geometry
, False
);
112 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
116 XQueryPointer(globalconf
.display
,
117 RootWindow(globalconf
.display
, phys_screen
),
118 &dummy
, &child
, &x
, &y
, &di
, &di
, &dui
);
119 if((newscreen
= screen_get_bycoord(c
->screen
, x
, y
)) != c
->screen
)
121 move_client_to_screen(c
, newscreen
, True
);
122 globalconf
.screens
[c
->screen
].need_arrange
= True
;
123 globalconf
.screens
[newscreen
].need_arrange
= True
;
126 if((target
= client_get_bywin(globalconf
.clients
, child
))
127 && target
!= c
&& !target
->isfloating
)
129 client_list_swap(&globalconf
.clients
, c
, target
);
130 globalconf
.screens
[c
->screen
].need_arrange
= True
;
139 /** Resize client with mouse
140 * \param screen Screen ID
142 * \ingroup ui_callback
145 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
147 int ocx
= 0, ocy
= 0, n
;
149 Client
*c
= globalconf
.focus
->client
;
150 Tag
**curtags
= tags_get_current(screen
);
151 Layout
*layout
= curtags
[0]->layout
;
152 Area area
= { 0, 0, 0, 0 , NULL
}, geometry
;
155 /* only handle floating and tiled layouts */
158 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
164 else if (layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
165 || layout
->arrange
== layout_tilebottom
|| layout
->arrange
== layout_tiletop
)
167 for(n
= 0, c
= globalconf
.clients
; c
; c
= c
->next
)
168 if(IS_TILED(c
, screen
))
171 if(n
<= curtags
[0]->nmaster
) return;
173 for(c
= globalconf
.clients
; c
&& !IS_TILED(c
, screen
); c
= c
->next
);
176 area
= screen_get_area(screen
,
177 globalconf
.screens
[c
->screen
].statusbar
,
178 &globalconf
.screens
[c
->screen
].padding
);
184 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
,
185 get_phys_screen(c
->screen
)),
186 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
187 RootWindow(globalconf
.display
,get_phys_screen(c
->screen
)),
188 globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
191 if(curtags
[0]->layout
->arrange
== layout_tileleft
)
192 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, 0, c
->geometry
.height
+ c
->border
- 1);
193 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
194 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
195 else if(curtags
[0]->layout
->arrange
== layout_tiletop
)
196 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, 0);
198 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
202 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
206 XUngrabPointer(globalconf
.display
, CurrentTime
);
208 case ConfigureRequest
:
209 handle_event_configurerequest(&ev
);
212 handle_event_expose(&ev
);
215 handle_event_maprequest(&ev
);
218 if(layout
->arrange
== layout_floating
|| c
->isfloating
)
220 if((geometry
.width
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
222 if((geometry
.height
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
224 geometry
.x
= c
->geometry
.x
;
225 geometry
.y
= c
->geometry
.y
;
226 client_resize(c
, geometry
, True
);
228 else if(layout
->arrange
== layout_tile
|| layout
->arrange
== layout_tileleft
229 || layout
->arrange
== layout_tiletop
|| layout
->arrange
== layout_tilebottom
)
231 if(layout
->arrange
== layout_tile
)
232 mwfact
= (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
233 else if(curtags
[0]->layout
->arrange
== layout_tileleft
)
234 mwfact
= 1 - (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
235 else if(curtags
[0]->layout
->arrange
== layout_tilebottom
)
236 mwfact
= (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
238 mwfact
= 1 - (double) (ev
.xmotion
.y
- area
.y
) / area
.height
;
239 if(mwfact
< 0.1) mwfact
= 0.1;
240 else if(mwfact
> 0.9) mwfact
= 0.9;
241 if(fabs(curtags
[0]->mwfact
- mwfact
) >= 0.01)
243 curtags
[0]->mwfact
= mwfact
;
244 globalconf
.screens
[screen
].need_arrange
= True
;
246 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
256 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80