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 "statusbar.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
41 * \ingroup ui_callback
44 uicb_client_movemouse(int screen
, char *arg
__attribute__ ((unused
)))
46 int x1
, y
, ocx
, ocy
, di
, phys_screen
;
51 Client
*c
= globalconf
.focus
->client
;
52 Tag
**curtags
= get_current_tags(screen
);
57 if((curtags
[0]->layout
->arrange
!= layout_floating
)
59 uicb_client_togglefloating(screen
, NULL
);
65 area
= get_screen_area(c
->screen
,
66 globalconf
.screens
[screen
].statusbar
,
67 &globalconf
.screens
[screen
].padding
);
69 ocx
= geometry
.x
= c
->geometry
.x
;
70 ocy
= geometry
.y
= c
->geometry
.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
)
77 XQueryPointer(globalconf
.display
,
78 RootWindow(globalconf
.display
, phys_screen
),
79 &dummy
, &dummy
, &x1
, &y
, &di
, &di
, &dui
);
81 statusbar_draw_all(c
->screen
);
84 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
88 XUngrabPointer(globalconf
.display
, CurrentTime
);
90 case ConfigureRequest
:
91 handle_event_configurerequest(&ev
);
94 handle_event_expose(&ev
);
97 handle_event_maprequest(&ev
);
100 geometry
.x
= ocx
+ (ev
.xmotion
.x
- x1
);
101 geometry
.y
= ocy
+ (ev
.xmotion
.y
- y
);
102 if(abs(geometry
.x
) < globalconf
.screens
[screen
].snap
+ area
.x
&& geometry
.x
> area
.x
)
104 else if(abs((area
.x
+ area
.width
) - (geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
)) < 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
)) < globalconf
.screens
[screen
].snap
)
109 geometry
.y
= area
.y
+ area
.height
- c
->geometry
.height
- 2 * c
->border
;
110 geometry
.width
= c
->geometry
.width
;
111 geometry
.height
= c
->geometry
.height
;
112 client_resize(c
, geometry
, False
);
113 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
119 /** Resize client with mouse
120 * \param screen Screen ID
122 * \ingroup ui_callback
125 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
127 int ocx
= 0, ocy
= 0, n
;
129 Client
*c
= globalconf
.focus
->client
;
130 Tag
**curtags
= get_current_tags(screen
);
131 Area area
= { 0, 0, 0, 0 }, geometry
;
134 /* only handle floating and tiled layouts */
137 if((curtags
[0]->layout
->arrange
== layout_floating
) || c
->isfloating
)
144 else if (curtags
[0]->layout
->arrange
== layout_tile
145 || curtags
[0]->layout
->arrange
== layout_tileleft
)
147 for(n
= 0, c
= globalconf
.clients
; c
; c
= c
->next
)
148 if(IS_TILED(c
, screen
))
151 if(n
<= curtags
[0]->nmaster
) return;
153 for(c
= globalconf
.clients
; c
&& !IS_TILED(c
, screen
); c
= c
->next
);
156 area
= get_screen_area(screen
,
157 globalconf
.screens
[c
->screen
].statusbar
,
158 &globalconf
.screens
[c
->screen
].padding
);
164 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
,
165 get_phys_screen(c
->screen
)),
166 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
167 None
, globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
170 if(curtags
[0]->layout
->arrange
== layout_tileleft
)
171 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, 0, c
->geometry
.height
+ c
->border
- 1);
173 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->geometry
.width
+ c
->border
- 1, c
->geometry
.height
+ c
->border
- 1);
177 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
181 XUngrabPointer(globalconf
.display
, CurrentTime
);
182 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
184 case ConfigureRequest
:
185 handle_event_configurerequest(&ev
);
188 handle_event_expose(&ev
);
191 handle_event_maprequest(&ev
);
194 if(curtags
[0]->layout
->arrange
== layout_floating
|| c
->isfloating
)
196 if((geometry
.width
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
198 if((geometry
.height
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
200 geometry
.x
= c
->geometry
.x
;
201 geometry
.y
= c
->geometry
.y
;
202 client_resize(c
, geometry
, True
);
204 else if(curtags
[0]->layout
->arrange
== layout_tile
205 || curtags
[0]->layout
->arrange
== layout_tileleft
)
207 if(curtags
[0]->layout
->arrange
== layout_tile
)
208 mwfact
= (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
210 mwfact
= 1 - (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
211 if(mwfact
< 0.1) mwfact
= 0.1;
212 else if(mwfact
> 0.9) mwfact
= 0.9;
213 if(fabs(curtags
[0]->mwfact
- mwfact
) >= 0.05)
215 curtags
[0]->mwfact
= mwfact
;
217 /* drop possibly arrived events while we where arrange()ing */
218 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
228 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80