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"
32 #include "layouts/floating.h"
33 #include "layouts/tile.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
, nx
, ny
;
50 Client
*c
= globalconf
.focus
->client
;
51 Tag
**curtags
= get_current_tags(screen
);
53 if(!c
|| (c
&& c
->isfixed
))
56 if((curtags
[0]->layout
->arrange
!= layout_floating
)
58 uicb_client_togglefloating(screen
, NULL
);
64 area
= get_screen_area(c
->screen
,
65 globalconf
.screens
[screen
].statusbar
,
66 &globalconf
.screens
[screen
].padding
);
70 if(XGrabPointer(globalconf
.display
,
71 RootWindow(globalconf
.display
, c
->phys_screen
),
72 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
73 None
, globalconf
.cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
75 XQueryPointer(globalconf
.display
,
76 RootWindow(globalconf
.display
, c
->phys_screen
),
77 &dummy
, &dummy
, &x1
, &y
, &di
, &di
, &dui
);
79 statusbar_draw_all(c
->screen
);
82 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
86 XUngrabPointer(globalconf
.display
, CurrentTime
);
88 case ConfigureRequest
:
89 handle_event_configurerequest(&ev
);
92 handle_event_expose(&ev
);
95 handle_event_maprequest(&ev
);
98 nx
= ocx
+ (ev
.xmotion
.x
- x1
);
99 ny
= ocy
+ (ev
.xmotion
.y
- y
);
100 if(abs(nx
) < globalconf
.screens
[screen
].snap
+ area
.x
&& nx
> area
.x
)
102 else if(abs((area
.x
+ area
.width
) - (nx
+ c
->w
+ 2 * c
->border
)) < globalconf
.screens
[screen
].snap
)
103 nx
= area
.x
+ area
.width
- c
->w
- 2 * c
->border
;
104 if(abs(ny
) < globalconf
.screens
[screen
].snap
+ area
.y
&& ny
> area
.y
)
106 else if(abs((area
.y
+ area
.height
) - (ny
+ c
->h
+ 2 * c
->border
)) < globalconf
.screens
[screen
].snap
)
107 ny
= area
.y
+ area
.height
- c
->h
- 2 * c
->border
;
108 client_resize(c
, nx
, ny
, c
->w
, c
->h
, False
, False
);
109 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
115 /** Resize client with mouse
116 * \param screen Screen ID
118 * \ingroup ui_callback
121 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
123 int ocx
, ocy
, nw
, nh
, n
;
125 Client
*c
= globalconf
.focus
->client
;
126 Tag
**curtags
= get_current_tags(screen
);
130 /* only handle floating and tiled layouts */
133 if((curtags
[0]->layout
->arrange
== layout_floating
) || c
->isfloating
)
140 else if (curtags
[0]->layout
->arrange
== layout_tile
141 || curtags
[0]->layout
->arrange
== layout_tileleft
)
143 for(n
= 0, c
= globalconf
.clients
; c
; c
= c
->next
)
144 if(IS_TILED(c
, screen
))
147 if(n
<= curtags
[0]->nmaster
) return;
149 for(c
= globalconf
.clients
; c
&& !IS_TILED(c
, screen
); c
= c
->next
);
152 area
= get_screen_area(screen
,
153 globalconf
.screens
[c
->screen
].statusbar
,
154 &globalconf
.screens
[c
->screen
].padding
);
160 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
, c
->phys_screen
),
161 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
162 None
, globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
165 if(curtags
[0]->layout
->arrange
== layout_tileleft
)
166 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, 0, c
->h
+ c
->border
- 1);
168 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
172 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
176 XUngrabPointer(globalconf
.display
, CurrentTime
);
177 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
179 case ConfigureRequest
:
180 handle_event_configurerequest(&ev
);
183 handle_event_expose(&ev
);
186 handle_event_maprequest(&ev
);
189 if(curtags
[0]->layout
->arrange
== layout_floating
|| c
->isfloating
)
191 if((nw
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
193 if((nh
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
195 client_resize(c
, c
->x
, c
->y
, nw
, nh
, True
, False
);
197 else if(curtags
[0]->layout
->arrange
== layout_tile
198 || curtags
[0]->layout
->arrange
== layout_tileleft
)
200 if(curtags
[0]->layout
->arrange
== layout_tile
)
201 mwfact
= (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
203 mwfact
= 1 - (double) (ev
.xmotion
.x
- area
.x
) / area
.width
;
204 if(mwfact
< 0.1) mwfact
= 0.1;
205 else if(mwfact
> 0.9) mwfact
= 0.9;
206 if(fabs(curtags
[0]->mwfact
- mwfact
) >= 0.05)
208 curtags
[0]->mwfact
= mwfact
;
210 /* drop possibly arrived events while we where arrange()ing */
211 while(XCheckMaskEvent(globalconf
.display
, PointerMotionMask
, &ev
));
222 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80